27
Gaudi Framework Tutorial, 2001 6 6 Writing Physics Tools

Writing Physics Tools

  • Upload
    allie

  • View
    34

  • Download
    0

Embed Size (px)

DESCRIPTION

Writing Physics Tools. Objectives. After completing this lesson, you should be able to: Define and implement a tool Retrieve and use tools in an algorithm Use private instances of tools Extend existing tools. Caveat. Things that will be used in the tutorial and are assumed to be know: - PowerPoint PPT Presentation

Citation preview

Page 1: Writing Physics Tools

Gaudi Framework Tutorial, 2001

66

Writing Physics ToolsWriting Physics Tools

Page 2: Writing Physics Tools

6-2 Gaudi Framework Tutorial, 2001

ObjectivesObjectives

After completing this lesson, you should After completing this lesson, you should be able to:be able to:

• Define and implement a tool

• Retrieve and use tools in an algorithm

• Use private instances of tools

• Extend existing tools

After completing this lesson, you should After completing this lesson, you should be able to:be able to:

• Define and implement a tool

• Retrieve and use tools in an algorithm

• Use private instances of tools

• Extend existing tools

Page 3: Writing Physics Tools

6-3 Gaudi Framework Tutorial, 2001

CaveatCaveat

Things that will be used in the tutorial and Things that will be used in the tutorial and are assumed to be know:are assumed to be know:

• How to write a simple algorithm

• How to print

• How to use Job Options

• How to use Particle Properties and Particle Property Service

Things that will be used in the tutorial and Things that will be used in the tutorial and are assumed to be know:are assumed to be know:

• How to write a simple algorithm

• How to print

• How to use Job Options

• How to use Particle Properties and Particle Property Service

Page 4: Writing Physics Tools

6-4 Gaudi Framework Tutorial, 2001

How to write concrete tools: header file

How to write concrete tools: header file

A concrete tool will inherit from the A concrete tool will inherit from the AlgToolAlgTool base class: base class:

– no initialize(), finalize()

– serviceLocator()

– msgSvc()

– has properties

– the IAlgTool interface is implemented

A concrete tool will inherit from the A concrete tool will inherit from the AlgToolAlgTool base class: base class:

– no initialize(), finalize()

– serviceLocator()

– msgSvc()

– has properties

– the IAlgTool interface is implemented

Configured at creationConfigured at creation

Configured via job optionsConfigured via job options

Retrieve necessary servicesRetrieve necessary services

Page 5: Writing Physics Tools

6-5 Gaudi Framework Tutorial, 2001

How to write concrete tools: implementation file

How to write concrete tools: implementation file

Instantiate a static factoryInstantiate a static factory– As for Algorithms but ToolFactory

Declare in constructor specific properties Declare in constructor specific properties and get services necessary to the and get services necessary to the implementationimplementation

– As in constructor and initialize of Algorithms

Implement necessary functionalityImplement necessary functionality– Additional methods specific to the tool

Instantiate a static factoryInstantiate a static factory– As for Algorithms but ToolFactory

Declare in constructor specific properties Declare in constructor specific properties and get services necessary to the and get services necessary to the implementationimplementation

– As in constructor and initialize of Algorithms

Implement necessary functionalityImplement necessary functionality– Additional methods specific to the tool

Page 6: Writing Physics Tools

6-6 Gaudi Framework Tutorial, 2001

Tools Specific InterfacesTools Specific Interfaces

Many tools can perform a similar Many tools can perform a similar operation in different waysoperation in different ways

– Useful to define an additional interface based on tool functionality

– This additional interface has to inherit from the IAlgTool interface

Many tools can perform a similar Many tools can perform a similar operation in different waysoperation in different ways

– Useful to define an additional interface based on tool functionality

– This additional interface has to inherit from the IAlgTool interfaceRememeber: The implementation of the IAlgTool interface is Rememeber: The implementation of the IAlgTool interface is

done by the AlgTool base class, don’t need to worry about itdone by the AlgTool base class, don’t need to worry about it

Rememeber: The implementation of the IAlgTool interface is Rememeber: The implementation of the IAlgTool interface is

done by the AlgTool base class, don’t need to worry about itdone by the AlgTool base class, don’t need to worry about it

Page 7: Writing Physics Tools

6-7 Gaudi Framework Tutorial, 2001

Tools interfaces in practiceTools interfaces in practice

class IMCUtilityTool : virtual public IAlgTool {class IMCUtilityTool : virtual public IAlgTool {

public:public:

} }

class IMCUtilityTool : virtual public IAlgTool {class IMCUtilityTool : virtual public IAlgTool {

public:public:

} }

#include “GaudiKernel/IAlgTool.h”#include “GaudiKernel/IAlgTool.h”#include “GaudiKernel/IAlgTool.h”#include “GaudiKernel/IAlgTool.h”

static const InterfaceID IID_IMCUtilityTool(440, 1, 0)static const InterfaceID IID_IMCUtilityTool(440, 1, 0)static const InterfaceID IID_IMCUtilityTool(440, 1, 0)static const InterfaceID IID_IMCUtilityTool(440, 1, 0)

Necessary for InheritanceNecessary for Inheritance

Unique interface IDUnique interface ID

/// Retrieve interface ID /// Retrieve interface ID

static const InterfaceID& interfaceID() { static const InterfaceID& interfaceID() {

return IID_IMCUtilityTool; return IID_IMCUtilityTool;

}}

/// Retrieve interface ID /// Retrieve interface ID

static const InterfaceID& interfaceID() { static const InterfaceID& interfaceID() {

return IID_IMCUtilityTool; return IID_IMCUtilityTool;

}}

Page 8: Writing Physics Tools

6-8 Gaudi Framework Tutorial, 2001

Requesting and using toolsRequesting and using tools

•Algorithms (or Services) request a Algorithms (or Services) request a specific tool to the ToolSvcspecific tool to the ToolSvc

•All tool management is done by the All tool management is done by the ToolSvcToolSvc

– Creates tools on first request

– Holds all instances and dispatches requested tool

• Algorithm can keep a pointer to a tool and use it when necessary

•Algorithms (or Services) request a Algorithms (or Services) request a specific tool to the ToolSvcspecific tool to the ToolSvc

•All tool management is done by the All tool management is done by the ToolSvcToolSvc

– Creates tools on first request

– Holds all instances and dispatches requested tool

• Algorithm can keep a pointer to a tool and use it when necessary

Page 9: Writing Physics Tools

6-9 Gaudi Framework Tutorial, 2001

How to retrieve a tool via the ToolSvc

How to retrieve a tool via the ToolSvc

In order to retrieve a tool it is necessary to In order to retrieve a tool it is necessary to specify its concrete class and a pointer specify its concrete class and a pointer return typereturn type

In order to retrieve a tool it is necessary to In order to retrieve a tool it is necessary to specify its concrete class and a pointer specify its concrete class and a pointer return typereturn type

MyTool* pMyTool = 0;MyTool* pMyTool = 0;

retrieveTool(“MyToolClass”, pMyTool)retrieveTool(“MyToolClass”, pMyTool)

MyTool* pMyTool = 0;MyTool* pMyTool = 0;

retrieveTool(“MyToolClass”, pMyTool)retrieveTool(“MyToolClass”, pMyTool)

Page 10: Writing Physics Tools

6-10 Gaudi Framework Tutorial, 2001

Hands on: MCUtilityToolHands on: MCUtilityTool

Write a Monte Carlo utility tool that:Write a Monte Carlo utility tool that:

• prints a decay tree given a MCParticleprints a decay tree given a MCParticle– Use what you have done in DecayTreeAlgorithm

• returns true/false if the products of a returns true/false if the products of a MCParticle matches a defined list of MCParticle matches a defined list of daughtersdaughters

– Loop over decay products and verify they have the same particleID as those of the list

Retrieve and use the tool in an AlgorithmRetrieve and use the tool in an Algorithm– Add only relevant parts to skeleton AnalysisAlgorithm

Write a Monte Carlo utility tool that:Write a Monte Carlo utility tool that:

• prints a decay tree given a MCParticleprints a decay tree given a MCParticle– Use what you have done in DecayTreeAlgorithm

• returns true/false if the products of a returns true/false if the products of a MCParticle matches a defined list of MCParticle matches a defined list of daughtersdaughters

– Loop over decay products and verify they have the same particleID as those of the list

Retrieve and use the tool in an AlgorithmRetrieve and use the tool in an Algorithm– Add only relevant parts to skeleton AnalysisAlgorithm

Page 11: Writing Physics Tools

6-11 Gaudi Framework Tutorial, 2001

Hands on: IMCUtilityToolprotocol

Hands on: IMCUtilityToolprotocol

virtual bool virtual bool matchDecayTreematchDecayTree( const MCParticle* mother,( const MCParticle* mother,

std::vector<long> daughtersID )std::vector<long> daughtersID )

= 0;= 0;

virtual bool virtual bool matchDecayTreematchDecayTree( const MCParticle* mother,( const MCParticle* mother,

std::vector<long> daughtersID )std::vector<long> daughtersID )

= 0;= 0;

virtual void virtual void printDecayTreeprintDecayTree( long depth, ( long depth,

const std::string& prefix, const std::string& prefix,

const MCParticle* mother) = 0; const MCParticle* mother) = 0;

virtual void virtual void printDecayTreeprintDecayTree( long depth, ( long depth,

const std::string& prefix, const std::string& prefix,

const MCParticle* mother) = 0; const MCParticle* mother) = 0;

Pure virtual methodsPure virtual methods

Page 12: Writing Physics Tools

6-12 Gaudi Framework Tutorial, 2001

Hands on: MCUtilityTool.hHands on: MCUtilityTool.h

Declare the interface methodsDeclare the interface methods

Remember to include the data membersRemember to include the data members

Declare the interface methodsDeclare the interface methods

Remember to include the data membersRemember to include the data members

void printDecayTree( long depth, void printDecayTree( long depth,

const std::string& prefix, const std::string& prefix,

const MCParticle* mother);const MCParticle* mother);

bool matchDecayTree( const MCPartticle* mother,bool matchDecayTree( const MCPartticle* mother,

sdt::vector<std::long> daugthersID);sdt::vector<std::long> daugthersID);

IParticlePropertySvc* m_ppSvc;IParticlePropertySvc* m_ppSvc;

Long m_depth; Long m_depth;

void printDecayTree( long depth, void printDecayTree( long depth,

const std::string& prefix, const std::string& prefix,

const MCParticle* mother);const MCParticle* mother);

bool matchDecayTree( const MCPartticle* mother,bool matchDecayTree( const MCPartticle* mother,

sdt::vector<std::long> daugthersID);sdt::vector<std::long> daugthersID);

IParticlePropertySvc* m_ppSvc;IParticlePropertySvc* m_ppSvc;

Long m_depth; Long m_depth;

Page 13: Writing Physics Tools

6-13 Gaudi Framework Tutorial, 2001

Hands on: MCUtilityTool.cppHands on: MCUtilityTool.cpp

To handle errors in constructorTo handle errors in constructor

Remember to include the necessary Remember to include the necessary headersheadersRemember to include the necessary Remember to include the necessary headersheaders

#include "GaudiKernel/GaudiException.h"#include "GaudiKernel/GaudiException.h"

#include "GaudiKernel/IParticlePropertySvc.h"#include "GaudiKernel/IParticlePropertySvc.h"

#include "GaudiKernel/ParticleProperty.h"#include "GaudiKernel/ParticleProperty.h"

#include "CLHEP/Units/PhysicalConstants.h"#include "CLHEP/Units/PhysicalConstants.h"

#include "LHCbEvent/MCParticle.h"#include "LHCbEvent/MCParticle.h"

#include "GaudiKernel/GaudiException.h"#include "GaudiKernel/GaudiException.h"

#include "GaudiKernel/IParticlePropertySvc.h"#include "GaudiKernel/IParticlePropertySvc.h"

#include "GaudiKernel/ParticleProperty.h"#include "GaudiKernel/ParticleProperty.h"

#include "CLHEP/Units/PhysicalConstants.h"#include "CLHEP/Units/PhysicalConstants.h"

#include "LHCbEvent/MCParticle.h"#include "LHCbEvent/MCParticle.h"

Page 14: Writing Physics Tools

6-14 Gaudi Framework Tutorial, 2001

ConstructorConstructor

• Retrieve the Particle Property ServiceRetrieve the Particle Property Service

•In case of problems throw a GaudiExceptionIn case of problems throw a GaudiException

•Declare PropertiesDeclare Properties

• Retrieve the Particle Property ServiceRetrieve the Particle Property Service

•In case of problems throw a GaudiExceptionIn case of problems throw a GaudiException

•Declare PropertiesDeclare Properties

m_ppSvc = 0;m_ppSvc = 0;

StatusCode sc=serviceLocator()-StatusCode sc=serviceLocator()->service("ParticlePropertySvc", >service("ParticlePropertySvc",

m_ppSvc)m_ppSvc)

m_ppSvc = 0;m_ppSvc = 0;

StatusCode sc=serviceLocator()-StatusCode sc=serviceLocator()->service("ParticlePropertySvc", >service("ParticlePropertySvc",

m_ppSvc)m_ppSvc)

throw GaudiException( "ParticlePropertySvc not found", throw GaudiException( "ParticlePropertySvc not found",

"MCUtilityToolException", "MCUtilityToolException",

StatusCode::FAILURE );StatusCode::FAILURE );

throw GaudiException( "ParticlePropertySvc not found", throw GaudiException( "ParticlePropertySvc not found",

"MCUtilityToolException", "MCUtilityToolException",

StatusCode::FAILURE );StatusCode::FAILURE );

declareProperty( "PrintDepth", m_depth = 999 );declareProperty( "PrintDepth", m_depth = 999 );declareProperty( "PrintDepth", m_depth = 999 );declareProperty( "PrintDepth", m_depth = 999 );

Page 15: Writing Physics Tools

6-15 Gaudi Framework Tutorial, 2001

queryInterfacequeryInterface

StatusCode MCUtilityTool::queryInterface(const IID& riid, StatusCode MCUtilityTool::queryInterface(const IID& riid,

void** ppvInterface){void** ppvInterface){

if ( IID_IMCUtilityTool == riid ) { if ( IID_IMCUtilityTool == riid ) {

*ppvInterface = (IMCUtilityTool*)this; *ppvInterface = (IMCUtilityTool*)this;

} }

else { else {

// Interface is not directly available: // Interface is not directly available:

// try the AlgTool base class // try the AlgTool base class

return AlgTool::queryInterface(riid, ppvInterface);return AlgTool::queryInterface(riid, ppvInterface);

} }

addRef();addRef();

return StatusCode::SUCCESS;return StatusCode::SUCCESS;

}}

StatusCode MCUtilityTool::queryInterface(const IID& riid, StatusCode MCUtilityTool::queryInterface(const IID& riid,

void** ppvInterface){void** ppvInterface){

if ( IID_IMCUtilityTool == riid ) { if ( IID_IMCUtilityTool == riid ) {

*ppvInterface = (IMCUtilityTool*)this; *ppvInterface = (IMCUtilityTool*)this;

} }

else { else {

// Interface is not directly available: // Interface is not directly available:

// try the AlgTool base class // try the AlgTool base class

return AlgTool::queryInterface(riid, ppvInterface);return AlgTool::queryInterface(riid, ppvInterface);

} }

addRef();addRef();

return StatusCode::SUCCESS;return StatusCode::SUCCESS;

}}

Page 16: Writing Physics Tools

6-16 Gaudi Framework Tutorial, 2001

printDecayTree(identical to DecayTreeAlgorithm)

printDecayTree(identical to DecayTreeAlgorithm)

void MCUtilityTool::printDecayTree(long depth, const std::string& prefix, const MCParticle* mother) { MsgStream log(msgSvc(), name()); const SmartRefVector<MCVertex>& decays = mother->decayMCVertices(); ParticleProperty* p = m_ppSvc->find( mother->particleID().id() ); log << MSG::INFO << depth << prefix.substr(0, prefix.length()-1) << "+--->" << p->particle() << endreq;

if ( depth < m_depth ) { SmartRefVector<MCVertex>::const_iterator iv; for ( iv = decays.begin(); iv != decays.end(); iv++ ) { const SmartRefVector<MCParticle>& daughters = (*iv)->daughterMCParticles(); SmartRefVector<MCParticle>::const_iterator idau; for ( idau = daughters.begin(); idau != daughters.end(); idau++ ) { printDecayTree( depth+1, prefix+" |", *idau ); } } }}

void MCUtilityTool::printDecayTree(long depth, const std::string& prefix, const MCParticle* mother) { MsgStream log(msgSvc(), name()); const SmartRefVector<MCVertex>& decays = mother->decayMCVertices(); ParticleProperty* p = m_ppSvc->find( mother->particleID().id() ); log << MSG::INFO << depth << prefix.substr(0, prefix.length()-1) << "+--->" << p->particle() << endreq;

if ( depth < m_depth ) { SmartRefVector<MCVertex>::const_iterator iv; for ( iv = decays.begin(); iv != decays.end(); iv++ ) { const SmartRefVector<MCParticle>& daughters = (*iv)->daughterMCParticles(); SmartRefVector<MCParticle>::const_iterator idau; for ( idau = daughters.begin(); idau != daughters.end(); idau++ ) { printDecayTree( depth+1, prefix+" |", *idau ); } } }}

Page 17: Writing Physics Tools

6-17 Gaudi Framework Tutorial, 2001

matchDecayTreematchDecayTree

If you don’t have time just return a falseIf you don’t have time just return a falseIf you don’t have time just return a falseIf you don’t have time just return a false

Page 18: Writing Physics Tools

6-18 Gaudi Framework Tutorial, 2001

Using IToolSvc to retrieve a toolUsing IToolSvc to retrieve a tool

...AnalysisAlgorithm.h...AnalysisAlgorithm.h

std::string m_toolName; std::string m_toolName; ///< Tool name///< Tool name

IMCUtilityTool* m_pUtilTool; IMCUtilityTool* m_pUtilTool; ///< Reference to tool///< Reference to tool

...AnalysisAlgorithm::initialize()......AnalysisAlgorithm::initialize()...

IToolSvc* toolsvc = 0;IToolSvc* toolsvc = 0;

StatusCode sc = service("ToolSvc", toolsvc );StatusCode sc = service("ToolSvc", toolsvc );

if ( sc.isFailure() ) {if ( sc.isFailure() ) { // You have to handle the error!// You have to handle the error! }}

sc = toolsvc->retrieveTool( m_toolName, m_pUtilTool );sc = toolsvc->retrieveTool( m_toolName, m_pUtilTool );

if ( sc.isFailure() ) {if ( sc.isFailure() ) { // You have to handle the error!// You have to handle the error! }}

...AnalysisAlgorithm.h...AnalysisAlgorithm.h

std::string m_toolName; std::string m_toolName; ///< Tool name///< Tool name

IMCUtilityTool* m_pUtilTool; IMCUtilityTool* m_pUtilTool; ///< Reference to tool///< Reference to tool

...AnalysisAlgorithm::initialize()......AnalysisAlgorithm::initialize()...

IToolSvc* toolsvc = 0;IToolSvc* toolsvc = 0;

StatusCode sc = service("ToolSvc", toolsvc );StatusCode sc = service("ToolSvc", toolsvc );

if ( sc.isFailure() ) {if ( sc.isFailure() ) { // You have to handle the error!// You have to handle the error! }}

sc = toolsvc->retrieveTool( m_toolName, m_pUtilTool );sc = toolsvc->retrieveTool( m_toolName, m_pUtilTool );

if ( sc.isFailure() ) {if ( sc.isFailure() ) { // You have to handle the error!// You have to handle the error! }}

Page 19: Writing Physics Tools

6-19 Gaudi Framework Tutorial, 2001

Using a toolUsing a tool

...AnalysisAlgorithm::execute()...AnalysisAlgorithm::execute()

// inside loop over MCParticle// inside loop over MCParticle

if ( (*ipart)->particleID().id() == m_partID ) {if ( (*ipart)->particleID().id() == m_partID ) {

log << MSG::INFO << "Found Particle of type " << log << MSG::INFO << "Found Particle of type " << m_partNamem_partName

<< endreq;<< endreq;

// Now use tool to print tree and check if requested tree// Now use tool to print tree and check if requested tree

m_pUtilTool->printDecayTree( 0, " |", *ipart );m_pUtilTool->printDecayTree( 0, " |", *ipart );

bool result = m_pUtilTool->matchDecayTree( *ipart, bool result = m_pUtilTool->matchDecayTree( *ipart,

m_daugID ); m_daugID );

if ( result ) { if ( result ) { // Print a message// Print a message

} else { } else { // Print a different message// Print a different message

}}

...AnalysisAlgorithm::execute()...AnalysisAlgorithm::execute()

// inside loop over MCParticle// inside loop over MCParticle

if ( (*ipart)->particleID().id() == m_partID ) {if ( (*ipart)->particleID().id() == m_partID ) {

log << MSG::INFO << "Found Particle of type " << log << MSG::INFO << "Found Particle of type " << m_partNamem_partName

<< endreq;<< endreq;

// Now use tool to print tree and check if requested tree// Now use tool to print tree and check if requested tree

m_pUtilTool->printDecayTree( 0, " |", *ipart );m_pUtilTool->printDecayTree( 0, " |", *ipart );

bool result = m_pUtilTool->matchDecayTree( *ipart, bool result = m_pUtilTool->matchDecayTree( *ipart,

m_daugID ); m_daugID );

if ( result ) { if ( result ) { // Print a message// Print a message

} else { } else { // Print a different message// Print a different message

}}

Page 20: Writing Physics Tools

6-20 Gaudi Framework Tutorial, 2001

ParentName.ToolNameParentName.ToolName

Configuring a toolConfiguring a tool

A concrete tool can be configured using A concrete tool can be configured using the jobOptions the jobOptions

Follow usual convention:Follow usual convention:IdentifyingNameOfTool.NameOfProperty

A concrete tool can be configured using A concrete tool can be configured using the jobOptions the jobOptions

Follow usual convention:Follow usual convention:IdentifyingNameOfTool.NameOfProperty

Through the base class all tools have the Through the base class all tools have the OutputLevel propertyOutputLevel property

• The default value is that of the parent

Through the base class all tools have the Through the base class all tools have the OutputLevel propertyOutputLevel property

• The default value is that of the parent

ToolSvc.MCUtilityTool.PrinDepth = 0;ToolSvc.MCUtilityTool.PrinDepth = 0;ToolSvc.MCUtilityTool.PrinDepth = 0;ToolSvc.MCUtilityTool.PrinDepth = 0;

Page 21: Writing Physics Tools

6-21 Gaudi Framework Tutorial, 2001

Public and Private toolsPublic and Private tools

• A tool instance can be shared by many A tool instance can be shared by many algorithms: it is public and belong to the algorithms: it is public and belong to the ToolSvcToolSvc

• Algorithm can have private instances of Algorithm can have private instances of tools, that can be configured “ad-hoc”tools, that can be configured “ad-hoc”

• To retrieve a private instance the parent To retrieve a private instance the parent has to pass itself to the retrieve methodhas to pass itself to the retrieve method

• A tool instance can be shared by many A tool instance can be shared by many algorithms: it is public and belong to the algorithms: it is public and belong to the ToolSvcToolSvc

• Algorithm can have private instances of Algorithm can have private instances of tools, that can be configured “ad-hoc”tools, that can be configured “ad-hoc”

• To retrieve a private instance the parent To retrieve a private instance the parent has to pass itself to the retrieve methodhas to pass itself to the retrieve method

toolSvc->retrieveTool(“MyTool”,pMyTool, toolSvc->retrieveTool(“MyTool”,pMyTool, thisthis))toolSvc->retrieveTool(“MyTool”,pMyTool, toolSvc->retrieveTool(“MyTool”,pMyTool, thisthis))

Page 22: Writing Physics Tools

6-22 Gaudi Framework Tutorial, 2001

Hands on: Private ToolsHands on: Private Tools

Use two instances of the Use two instances of the samesame tool in the tool in the AnalysisAlgorithmAnalysisAlgorithm

• A public instance with default configuration

• A private instance with different printing depth

Use two instances of the Use two instances of the samesame tool in the tool in the AnalysisAlgorithmAnalysisAlgorithm

• A public instance with default configuration

• A private instance with different printing depth

Page 23: Writing Physics Tools

6-23 Gaudi Framework Tutorial, 2001

Using a private and a public toolUsing a private and a public tool

...AnalysisAlgorithm.h...AnalysisAlgorithm.h

std::string m_myToolName; std::string m_myToolName; ///< Tool name///< Tool name

IMCUtilityTool* m_pMyUtilTool; IMCUtilityTool* m_pMyUtilTool; ///< Reference to ///< Reference to tooltool

...AnalysisAlgorithm::initialize()......AnalysisAlgorithm::initialize()...

sc = toolsvc->retrieveTool( m_myToolName, m_pMyUtilTool,sc = toolsvc->retrieveTool( m_myToolName, m_pMyUtilTool,

this );this );

...AnalysisAlgorithm::execute()......AnalysisAlgorithm::execute()...

m_pMyUtilToolm_pMyUtilTool->printDecayTree( 0, " |", *ipart );->printDecayTree( 0, " |", *ipart );

bool result = bool result = m_pMyUtilToolm_pMyUtilTool->matchDecayTree( *ipart,->matchDecayTree( *ipart,

m_daugID );m_daugID );

if ( !result ) {if ( !result ) {

m_pUtilToolm_pUtilTool->printDecayTree( 0, " |", *ipart );->printDecayTree( 0, " |", *ipart );

}}

...AnalysisAlgorithm.h...AnalysisAlgorithm.h

std::string m_myToolName; std::string m_myToolName; ///< Tool name///< Tool name

IMCUtilityTool* m_pMyUtilTool; IMCUtilityTool* m_pMyUtilTool; ///< Reference to ///< Reference to tooltool

...AnalysisAlgorithm::initialize()......AnalysisAlgorithm::initialize()...

sc = toolsvc->retrieveTool( m_myToolName, m_pMyUtilTool,sc = toolsvc->retrieveTool( m_myToolName, m_pMyUtilTool,

this );this );

...AnalysisAlgorithm::execute()......AnalysisAlgorithm::execute()...

m_pMyUtilToolm_pMyUtilTool->printDecayTree( 0, " |", *ipart );->printDecayTree( 0, " |", *ipart );

bool result = bool result = m_pMyUtilToolm_pMyUtilTool->matchDecayTree( *ipart,->matchDecayTree( *ipart,

m_daugID );m_daugID );

if ( !result ) {if ( !result ) {

m_pUtilToolm_pUtilTool->printDecayTree( 0, " |", *ipart );->printDecayTree( 0, " |", *ipart );

}}

Page 24: Writing Physics Tools

6-24 Gaudi Framework Tutorial, 2001

Extending existing toolsExtending existing tools

Different tools can implement the same Different tools can implement the same functionalityfunctionality

If the algorithms interacts with them only If the algorithms interacts with them only through the interface they are through the interface they are interchangeableinterchangeable

The choice can be done via the job The choice can be done via the job options at run timeoptions at run time

Different tools can implement the same Different tools can implement the same functionalityfunctionality

If the algorithms interacts with them only If the algorithms interacts with them only through the interface they are through the interface they are interchangeableinterchangeable

The choice can be done via the job The choice can be done via the job options at run timeoptions at run time

Page 25: Writing Physics Tools

6-25 Gaudi Framework Tutorial, 2001

Hand on: A different tool implementation

Hand on: A different tool implementation

Write a NewMCUtilityTool that prints the Write a NewMCUtilityTool that prints the tree with different type of information for tree with different type of information for the MCParticlethe MCParticle

• Inherit from MCUtilityTool

• Override printDecayTree method

• Change name of one of the tools used by AnalysisAlgorithm of previous exercise: only in job options

Write a NewMCUtilityTool that prints the Write a NewMCUtilityTool that prints the tree with different type of information for tree with different type of information for the MCParticlethe MCParticle

• Inherit from MCUtilityTool

• Override printDecayTree method

• Change name of one of the tools used by AnalysisAlgorithm of previous exercise: only in job options

Page 26: Writing Physics Tools

6-26 Gaudi Framework Tutorial, 2001

Hands on: NewMCUtilityToolHands on: NewMCUtilityTool

...NewMCUtility.h...NewMCUtility.h

#include "MCUtilityTool.h"#include "MCUtilityTool.h"

class NewMCUtilityTool : public MCUtilityTool {class NewMCUtilityTool : public MCUtilityTool {

......

void printDecayTree( long depth, const std::string& void printDecayTree( long depth, const std::string& prefix,prefix,

const MCParticle* mother);const MCParticle* mother);

...NewMCUtility.cpp...NewMCUtility.cpp

void NewMCUtilityTool::printDecayTree(long depth,void NewMCUtilityTool::printDecayTree(long depth,

const std::string& prefix,const std::string& prefix,

const MCParticle* mother) {const MCParticle* mother) {

// Change the method as you like// Change the method as you like

...NewMCUtility.h...NewMCUtility.h

#include "MCUtilityTool.h"#include "MCUtilityTool.h"

class NewMCUtilityTool : public MCUtilityTool {class NewMCUtilityTool : public MCUtilityTool {

......

void printDecayTree( long depth, const std::string& void printDecayTree( long depth, const std::string& prefix,prefix,

const MCParticle* mother);const MCParticle* mother);

...NewMCUtility.cpp...NewMCUtility.cpp

void NewMCUtilityTool::printDecayTree(long depth,void NewMCUtilityTool::printDecayTree(long depth,

const std::string& prefix,const std::string& prefix,

const MCParticle* mother) {const MCParticle* mother) {

// Change the method as you like// Change the method as you like

Page 27: Writing Physics Tools

6-27 Gaudi Framework Tutorial, 2001

Hands on: Use different toolsHands on: Use different tools

Once the tool exist you only need to load Once the tool exist you only need to load the modified job options.the modified job options.

An example NewMCUtility.opts is An example NewMCUtility.opts is providedprovided

Once the tool exist you only need to load Once the tool exist you only need to load the modified job options.the modified job options.

An example NewMCUtility.opts is An example NewMCUtility.opts is providedprovided