ATLAS Offline Software
Loading...
Searching...
No Matches
PileupFilterTool Class Reference

#include <PileupFilterTool.h>

Inheritance diagram for PileupFilterTool:
Collaboration diagram for PileupFilterTool:

Public Member Functions

 PileupFilterTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor with parameters:
virtual ~PileupFilterTool ()
 Destructor:
StatusCode buildMcAod (const McEventCollection *in, McEventCollection *out)
 This method will check the validity of the input McEventCollection and build a filtered one from the strategy implemented by this concrete tool.
StatusCode initialize ()
 Athena Algorithm's Hooks.
StatusCode execute ()
StatusCode finalize ()
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Inline methods:

Protected Types

typedef ToolHandle< IMcVtxFilterToolMcVtxFilterTool_t
typedef ToolHandle< ITruthIsolationToolIsolTool_t

Protected Member Functions

 PileupFilterTool ()
 Default constructor:
StatusCode selectSpclMcBarcodes ()
 Retrieve the GenParticles from the GenEvent object (located into the McEventCollection container), filter them and store their barcode into the list of barcodes of particles to keep.
StatusCode shapeGenEvent (McEventCollection *outEvt)
 Build the out McEventCollection by removing all the GenParticles whose barcode is not in the list of barcodes to keep.
StatusCode reconnectParticles (const McEventCollection *inEvt, McEventCollection *out)
 Reconnect the particles of the filtered McEventCollection.
StatusCode rebuildLinks (const HepMC::GenEvent *mcEvent, HepMC::GenEvent *outEvt, const HepMC::GenParticlePtr &mcPart)
 Rebuild the links between particles which were connected, eg by a long FSR chain.
StatusCode initializeTool ()
 to get tesIO
virtual StatusCode finalizeTool ()
void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Protected Attributes

std::set< HepMC::ConstGenParticlePtrm_particles
 List of particles which have been labelled as "special".
DoubleProperty m_rIsol
 deltaR isolation energy cut for electrons, muons, taus and photons
DoubleProperty m_ptGamMin
 Minimum threshold for transverse momentum of photons.
DoubleProperty m_ptMin
 Minimum threshold for transverse momentum for all particles.
DoubleProperty m_etaRange
 Eta acceptance cut applied on all stable particles.
DoubleProperty m_rRange
 Radius acceptance cut on all stable particles.
BooleanProperty m_includeSimul
 Switch to include or not particles from detector simulation (Geant4).
BooleanProperty m_includePartonShowers
 Switch to include or not parton showers.
TruthHelper::GenAccessIOm_tesIO
 Pointer to a StoreGateSvc helper (Mc particle retrieval with predicates).
BooleanProperty m_removeDecayToSelf
 Switch to remove particles which decay into themselves (t->tg) but only for generated particles, not the ones from the Geant4 interactions.
McVtxFilterTool_t m_mcVtxFilterTool
 Pointer to the McVtxFilterTool to be able to select additional vertices on some decay pattern criterion.
IsolTool_t m_isolationTool
 Pointer to the TruthIsolationTool to be able to compute transverse energy isolations for various isolation cones cuts.
BooleanProperty m_doEtIsolation
 Switch to compute or not the Et-isolations for TruthParticle (and their underlying HepMC::GenParticle).
SG::ReadHandleKey< McEventCollectionm_mcEventsReadHandleKey {this,"McEvents","TruthEvent","ReadHandleKey for input McEventCollection one wants to filter"}
 ReadHandleKey for the input McEventCollection one wants to filter.
SG::WriteHandleKey< McEventCollectionm_mcEventsOutputWriteHandleKey {this,"McEventsOutput","GEN_AOD","WriteHandleKey for the output McEventCollection which has been filtered"}
 Location of the output McEventCollection which has been filtered.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default).
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default).
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 28 of file PileupFilterTool.h.

Member Typedef Documentation

◆ IsolTool_t

typedef ToolHandle<ITruthIsolationTool> TruthParticleFilterBaseTool::IsolTool_t
protectedinherited

Definition at line 80 of file TruthParticleFilterBaseTool.h.

◆ McVtxFilterTool_t

typedef ToolHandle<IMcVtxFilterTool> TruthParticleFilterBaseTool::McVtxFilterTool_t
protectedinherited

Definition at line 74 of file TruthParticleFilterBaseTool.h.

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ PileupFilterTool() [1/2]

PileupFilterTool::PileupFilterTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Constructor with parameters:

Definition at line 41 of file PileupFilterTool.cxx.

43 :
44 TruthParticleFilterBaseTool( type, name, parent ),
45 m_particles ( ),
46 m_tesIO ( nullptr )
47{
48
49 declareProperty( "rIsolation",
50 m_rIsol = 0.45,
51 "DeltaR isolation energy cut for electrons, muons, "
52 "taus and photons" );
53
54 declareProperty( "ptGammaMin",
55 m_ptGamMin = 0.5*GeV,
56 "Minimum threshold for transverse momentum of photons" );
57
58 declareProperty( "ptMin",
59 m_ptMin = 0.5*GeV,
60 "Minimum threshold for transverse momentum for all particles.\n"
61 "Warning: this cut is applied *before* Pt photon cut !" );
62
63 declareProperty( "etaRange",
64 m_etaRange = 5.0,
65 "Eta acceptance cut applied on all stable particles" );
66
67 declareProperty( "rRange",
68 m_rRange = 500.0,
69 "radius acceptance - in milimeters - cut applied on all stable "
70 "particles" );
71
72 // switches
73
74 declareProperty( "IncludeSimul",
75 m_includeSimul = true,
76 "Switch to include or not particles from detector simulation "
77 "(Geant 4)" );
78
79 declareProperty( "IncludePartonShowers",
81 "Switch to include or not parton showers" );
82
83 declareProperty( "RemoveDecayToSelf",
85 "Switch to remove particles which decay into themselves (t->tg) "
86 "*but* only for generated particles, not the ones from the "
87 "Geant4 interactions" );
88
89}
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
DoubleProperty m_rIsol
deltaR isolation energy cut for electrons, muons, taus and photons
TruthHelper::GenAccessIO * m_tesIO
Pointer to a StoreGateSvc helper (Mc particle retrieval with predicates).
DoubleProperty m_etaRange
Eta acceptance cut applied on all stable particles.
BooleanProperty m_removeDecayToSelf
Switch to remove particles which decay into themselves (t->tg) but only for generated particles,...
DoubleProperty m_rRange
Radius acceptance cut on all stable particles.
DoubleProperty m_ptGamMin
Minimum threshold for transverse momentum of photons.
BooleanProperty m_includeSimul
Switch to include or not particles from detector simulation (Geant4).
BooleanProperty m_includePartonShowers
Switch to include or not parton showers.
DoubleProperty m_ptMin
Minimum threshold for transverse momentum for all particles.
std::set< HepMC::ConstGenParticlePtr > m_particles
List of particles which have been labelled as "special".
TruthParticleFilterBaseTool()
Default constructor:

◆ ~PileupFilterTool()

PileupFilterTool::~PileupFilterTool ( )
virtual

Destructor:

Definition at line 93 of file PileupFilterTool.cxx.

94{
95 ATH_MSG_DEBUG("Calling destructor");
96 delete m_tesIO;
97}
#define ATH_MSG_DEBUG(x)

◆ PileupFilterTool() [2/2]

PileupFilterTool::PileupFilterTool ( )
protected

Default constructor:

Member Function Documentation

◆ buildMcAod()

StatusCode PileupFilterTool::buildMcAod ( const McEventCollection * in,
McEventCollection * out )
virtual

This method will check the validity of the input McEventCollection and build a filtered one from the strategy implemented by this concrete tool.

Implements ITruthParticleFilterTool.

Definition at line 103 of file PileupFilterTool.cxx.

105{
106 if ( nullptr == in || nullptr == out ) {
107 ATH_MSG_ERROR("Invalid pointer to McEventCollection !" << endmsg
108 << " in: " << in << endmsg
109 << " out: " << out);
110 return StatusCode::FAILURE;
111 }
112
113 // we just copy the input McEventCollection and put it into the output one
114 out->operator=( *in );
115
116 // select the barcodes of the "special" particles from the input GenEvent
117 if ( selectSpclMcBarcodes().isFailure() ) {
118 ATH_MSG_ERROR("Could not select the \"special\" barcodes !!");
119 return StatusCode::FAILURE;
120 }
121
122 // remove the not "special" particles from the filtered McEventCollection
123 if ( shapeGenEvent(out).isFailure() ) {
124 ATH_MSG_ERROR("Could not remove the not \"special\" particles from the "\
125 "filtered McEventCollection !!");
126 return StatusCode::FAILURE;
127 }
128
129 // reconnect the particles
130 if ( reconnectParticles(in, out).isFailure() ) {
131 ATH_MSG_ERROR("Could not reconnect the particles in the filtered "\
132 "McEventCollection !!");
133 return StatusCode::FAILURE;
134 }
135
136 return StatusCode::SUCCESS;
137}
#define endmsg
#define ATH_MSG_ERROR(x)
StatusCode reconnectParticles(const McEventCollection *inEvt, McEventCollection *out)
Reconnect the particles of the filtered McEventCollection.
StatusCode shapeGenEvent(McEventCollection *outEvt)
Build the out McEventCollection by removing all the GenParticles whose barcode is not in the list of ...
StatusCode selectSpclMcBarcodes()
Retrieve the GenParticles from the GenEvent object (located into the McEventCollection container),...

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ execute()

StatusCode TruthParticleFilterBaseTool::execute ( )
virtualinherited

Implements ITruthParticleFilterTool.

Definition at line 120 of file TruthParticleFilterBaseTool.cxx.

121{
122 ATH_MSG_DEBUG("Executing " << name() << "...");
123
124 //Setup Handle to read input container
125 SG::ReadHandle<McEventCollection> mcEventsReadHandle(m_mcEventsReadHandleKey);
126
127 if (!mcEventsReadHandle.isValid()){
128 ATH_MSG_ERROR("Invalid ReadHandle to McEventColleciton with key: " << m_mcEventsReadHandleKey.key());
129 return StatusCode::FAILURE;
130 }
131
132 //Setup WriteHandle, and then record new McEventCollection.
133 SG::WriteHandle<McEventCollection> mcEventsOutputWriteHandle(m_mcEventsOutputWriteHandleKey);
134 ATH_CHECK(mcEventsOutputWriteHandle.record(std::make_unique<McEventCollection>()));
135
136 if (!mcEventsOutputWriteHandle.isValid()){
137 ATH_MSG_ERROR("Invalid WriteHamdle for McEventCollection with key ["
138 <<m_mcEventsOutputWriteHandleKey.key() << "] !!");
139 return StatusCode::FAILURE;
140 }
141
142 // Compute isolation for gamma/lepton.
143 if ( m_doEtIsolation.value() ) {
144 ATH_MSG_VERBOSE("Computing Et isolations...");
145 if ( m_isolationTool->buildEtIsolations(m_mcEventsReadHandleKey.key()).isFailure() ) {
146 ATH_MSG_ERROR("Could not compute Et isolations !!");
147 return StatusCode::FAILURE;
148 }
149 } //> end do Et-isolation
150
151 if ( this->buildMcAod( mcEventsReadHandle.ptr(), mcEventsOutputWriteHandle.ptr() ).isFailure() ) {
152 ATH_MSG_ERROR("Could not buildMcAod(in,out) !!");
153 return StatusCode::FAILURE;
154 }
155
156 // We have slimmed the mcEventsOutputWriteHandle.
157 // To not bias the map of isolation energies for this GenEvent, we alias
158 // it to its original one
159 if ( m_doEtIsolation.value() &&
160 !m_isolationTool->registerAlias( m_mcEventsOutputWriteHandleKey.key(),
162 ).isSuccess() ) {
163 ATH_MSG_WARNING("Could not create an alias in the map of "\
164 "isolation energies !");
165 }
166
167 return StatusCode::SUCCESS;
168}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
virtual StatusCode buildMcAod(const McEventCollection *in, McEventCollection *filtered)=0
This method will check the validity of the input McEventCollection and build a filtered one from the ...
BooleanProperty m_doEtIsolation
Switch to compute or not the Et-isolations for TruthParticle (and their underlying HepMC::GenParticle...
SG::ReadHandleKey< McEventCollection > m_mcEventsReadHandleKey
ReadHandleKey for the input McEventCollection one wants to filter.
SG::WriteHandleKey< McEventCollection > m_mcEventsOutputWriteHandleKey
Location of the output McEventCollection which has been filtered.
IsolTool_t m_isolationTool
Pointer to the TruthIsolationTool to be able to compute transverse energy isolations for various isol...

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ finalize()

StatusCode TruthParticleFilterBaseTool::finalize ( )
virtualinherited

Implements ITruthParticleFilterTool.

Definition at line 105 of file TruthParticleFilterBaseTool.cxx.

106{
107 ATH_MSG_INFO("Finalizing " << name() << "...");
108
109 m_mcVtxFilterTool->stats();
110
111 // Give the concrete (derived) tool a chance to finalize itself
112 if ( finalizeTool().isFailure() ) {
113 ATH_MSG_ERROR("Could not finalize concrete tool !");
114 return StatusCode::FAILURE;
115 }
116
117 return StatusCode::SUCCESS;
118}
#define ATH_MSG_INFO(x)
McVtxFilterTool_t m_mcVtxFilterTool
Pointer to the McVtxFilterTool to be able to select additional vertices on some decay pattern criteri...

◆ finalizeTool()

StatusCode TruthParticleFilterBaseTool::finalizeTool ( )
inlineprotectedvirtualinherited

Definition at line 124 of file TruthParticleFilterBaseTool.h.

125{
126 return StatusCode::SUCCESS;
127}

◆ initialize()

StatusCode TruthParticleFilterBaseTool::initialize ( )
virtualinherited

Athena Algorithm's Hooks.

Retrieves a private AlgTool to filter a McEventCollection

Retrieves the isolation tool (public, to be used also in TruthParticleCnvTool)

Implements ITruthParticleFilterTool.

Definition at line 65 of file TruthParticleFilterBaseTool.cxx.

66{
67 ATH_MSG_INFO("Initializing " << name() << "...");
68
70 if ( !m_mcVtxFilterTool.retrieve().isSuccess() ) {
71 ATH_MSG_ERROR("Creation of algTool IMcVtxFilterTool FAILED !");
72 return StatusCode::FAILURE;
73 }
74
76 if( m_doEtIsolation.value()) {
77 ATH_CHECK(m_isolationTool.retrieve());
78 }
79 else {
80 m_isolationTool.disable();
81 }
82
83 //initialize DataHandleKeys
86
88 (" DoEtIsolations: [" << std::boolalpha << m_doEtIsolation.value()
89 << "]" << endmsg
90 << " McEvents: [" << m_mcEventsReadHandleKey.key() << "]" << endmsg
91 << " McEventsOutput: [" << m_mcEventsOutputWriteHandleKey.key() << "]");
92
93 // Give the concrete (derived) tool a chance to initialize itself
94 if ( initializeTool().isFailure() ) {
95 ATH_MSG_ERROR("Could not initialize concrete tool !");
96 return StatusCode::FAILURE;
97 }
98
99 ATH_MSG_INFO("Options of the McVtxFilterTool:");
100 m_mcVtxFilterTool->displayOptions();
101
102 return StatusCode::SUCCESS;
103}
virtual StatusCode initializeTool()
I/O operators.

◆ initializeTool()

StatusCode PileupFilterTool::initializeTool ( )
protectedvirtual

to get tesIO

Reimplemented from TruthParticleFilterBaseTool.

Definition at line 475 of file PileupFilterTool.cxx.

476{
477 ATH_MSG_DEBUG("Calling initializeTool");
478 // accessor for particles
479 delete m_tesIO;
480 m_tesIO = new TruthHelper::GenAccessIO();
481 if( nullptr == m_tesIO ) {
482 ATH_MSG_ERROR("Unable to retrieve GenAccessIO pointer");
483 return StatusCode::FAILURE;
484 }
485 return StatusCode::SUCCESS;
486}

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ interfaceID()

const InterfaceID & ITruthParticleFilterTool::interfaceID ( )
inlinestaticinherited

Inline methods:

Definition at line 70 of file ITruthParticleFilterTool.h.

71{
73}
static const InterfaceID IID_ITruthParticleFilterTool("ITruthParticleFilterTool", 1, 0)

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ rebuildLinks()

StatusCode PileupFilterTool::rebuildLinks ( const HepMC::GenEvent * mcEvent,
HepMC::GenEvent * outEvt,
const HepMC::GenParticlePtr & mcPart )
protected

Rebuild the links between particles which were connected, eg by a long FSR chain.

Definition at line 366 of file PileupFilterTool.cxx.

369{
370 if ( !mcPart ) {
371 ATH_MSG_WARNING("Null GenParticle: can not rebuildLinks");
372 return StatusCode::FAILURE;
373 }
374
375 if ( mcPart->end_vertex() ) {
376 ATH_MSG_VERBOSE("GenParticle has already a decay vertex : nothing to do");
377 return StatusCode::SUCCESS;
378 }
379
380 if ( !mcEvt ) {
381 ATH_MSG_WARNING("Null input HepMC::GenEvent : can not rebuildLinks");
382 return StatusCode::FAILURE;
383 }
384
385 if ( !outEvt ) {
386 ATH_MSG_WARNING("Null output HepMC::GenEvent: can not rebuildLinks");
387 return StatusCode::FAILURE;
388 }
389
390 // Cache some useful infos
391 const int pdgId = mcPart->pdg_id();
392 const int bc = HepMC::barcode(mcPart);
394 HepMC::ConstGenVertexPtr dcyVtx = inPart->end_vertex();
395
396 if ( !dcyVtx ) {
397 ATH_MSG_VERBOSE("No decay vertex for the particle #" << bc << " : " << "No link to rebuild...");
398 return StatusCode::SUCCESS;
399 }
400
401 std::list<int> bcChildPart;
402 std::list<int> bcChildVert;
403
404 //
405 // Loop over all descendants of the GenParticle
406 // Store the barcode of the GenParticles entering into each GenVertex
407 //
408 auto descendants=HepMC::descendant_vertices(dcyVtx);
409 for ( const auto& itrVtx: descendants) {
410 bool foundPdgId = false;
411 for ( const auto& itrPart: itrVtx->particles_in()) {
412 // because the vertices are traversed in POST ORDER !!
413 bcChildPart.push_front( HepMC::barcode(itrPart));
414 if ( itrPart->pdg_id() == pdgId ) {
415 foundPdgId = true;
416 }
417 }//> loop over in-going particles of this vertex
418 if ( foundPdgId ) {
419 bcChildVert.push_front( HepMC::barcode(itrVtx));
420 }
421 }//> loop over descendants of decay vertex
422
423 //
424 // Now we loop over the previously stored barcodes and
425 // we connect our GenParticle to the first found barcode
426 //
427 std::list<int>::const_iterator bcVtxEnd = bcChildVert.end();
428 for ( std::list<int>::const_iterator itrBcVtx = bcChildVert.begin(); itrBcVtx != bcVtxEnd; ++itrBcVtx ) {
429 HepMC::GenVertexPtr childVtx = HepMC::barcode_to_vertex(outEvt,*itrBcVtx);
430 if ( childVtx ) {
431 if ( !childVtx->particles_in().empty() ) {
432 for ( const auto& itrPart: childVtx->particles_in()) {
433 if ( itrPart->pdg_id() == pdgId ) {
434 HepMC::GenVertexPtr prodVtx = itrPart->production_vertex();
435 if ( prodVtx ) {
436 if ( !prodVtx->particles_in().empty() ) {
437 // Humm... This is not what we'd have expected
438 // so we skip it
439 if ( msgLvl(MSG::VERBOSE) ) {
440 msg(MSG::VERBOSE)<< "found a particle = "<< itrPart << ", "<< "but its production vertex has incoming particles !" << endmsg;
441 continue;
442 }
443 // create a GenVertex which will be the decay vertex of our
444 // GenParticle and the production vertex of the GenParticle
445 // we just found
447 outEvt->add_vertex( linkVtx );
448 linkVtx->add_particle_in( mcPart );
449 linkVtx->add_particle_out( itrPart );
450
451 msg(MSG::ERROR)<< "=====================================================" << endmsg << "Created a GenVertex - link !" << std::endl;
452 std::stringstream vtxLink("");
453 HepMC::Print::line(vtxLink,std::move(linkVtx));
454 msg(MSG::ERROR)<< vtxLink.str()<< endmsg<< "====================================================="<< endmsg;
455 }
456 }
457 }
458 }//> loop over incoming particles
459 } else {
460 // no incoming particle : so we just add this particle
461 // a bit odd though : FIXME ?
462 childVtx->add_particle_in(mcPart);
463 msg(MSG::WARNING) << "Odd situation:" << std::endl;
464 std::stringstream vtxDump( "" );
465 HepMC::Print::line(vtxDump,std::move(childVtx));
466 msg(MSG::WARNING) << vtxDump.str() << endmsg;
467 return StatusCode::SUCCESS;
468 }//> end if incoming particles
469 }//> found a child-vertex
470 }
471
472 return StatusCode::FAILURE;
473}
bool msgLvl(const MSG::Level lvl) const
ConstGenVertexPtr barcode_to_vertex(const GenEvent *e, int id)
Definition GenEvent.h:403
int barcode(const T *p)
Definition Barcode.h:15
ConstGenParticlePtr barcode_to_particle(const GenEvent *e, int id)
Definition GenEvent.h:443
GenVertexPtr newGenVertexPtr(const HepMC3::FourVector &pos=HepMC3::FourVector::ZERO_VECTOR(), const int i=0)
Definition GenVertex.h:25
HepMC3::GenVertexPtr GenVertexPtr
Definition GenVertex.h:23
HepMC3::ConstGenParticlePtr ConstGenParticlePtr
Definition GenParticle.h:20
HepMC3::ConstGenVertexPtr ConstGenVertexPtr
Definition GenVertex.h:24
MsgStream & msg
Definition testRead.cxx:32

◆ reconnectParticles()

StatusCode PileupFilterTool::reconnectParticles ( const McEventCollection * inEvt,
McEventCollection * out )
protected

Reconnect the particles of the filtered McEventCollection.

We need the original McEventCollection to know if 2 particles were connected

Definition at line 321 of file PileupFilterTool.cxx.

322{
323 if ( nullptr == in || nullptr == out ) {
324 ATH_MSG_ERROR("Invalid pointer to McEventCollection !!" << endmsg << " in: " << in << endmsg << " out: " << out);
325 return StatusCode::FAILURE;
326 }
327
328 for ( unsigned int iEvt = 0; iEvt != in->size(); ++iEvt) {
329 const HepMC::GenEvent * evt = (*in)[iEvt];
330 HepMC::GenEvent * outEvt = (*out)[iEvt];
331
332 // Reconnect the particles
333 ATH_MSG_VERBOSE("Reconnecting particles...");
334 for ( const auto& itrPart: *outEvt) {
335 if ( itrPart->end_vertex() ) {
336 continue;
337 }
338 if ( rebuildLinks( evt, outEvt, itrPart ).isFailure() ) {
339 ATH_MSG_WARNING("Could not rebuild links for this particle [pdgId,particle]= "<< itrPart->pdg_id() << ", " << itrPart);
340 } else if ( msgLvl(MSG::VERBOSE) ) {
341 msg(MSG::VERBOSE)<< "==========================================================="<< endmsg<< "Production vertex for particle " << itrPart << " : ";
342 if ( itrPart->production_vertex() ) {
343 std::stringstream prodVtx("");
344 HepMC::Print::line(prodVtx,itrPart->production_vertex());
345 msg(MSG::VERBOSE) << std::endl<< prodVtx.str()<< endmsg;
346 } else {
347 msg(MSG::VERBOSE) << "[No production vertex]" << endmsg;
348 }
349
350 msg(MSG::VERBOSE) << "Decay vertex for particle " << itrPart << " : ";
351 if ( itrPart->end_vertex() ) {
352 std::stringstream dcyVtx("");
353 HepMC::Print::line(dcyVtx,itrPart->end_vertex());
354 msg(MSG::VERBOSE) << std::endl<< dcyVtx.str() << endmsg;
355 } else {
356 msg(MSG::VERBOSE) << endmsg << "[No decay vertex]" << endmsg;
357 }
358 }//> end VERBOSE messages
359
360 }//> loop over particles
361 }//> loop over GenEvents
362
363 return StatusCode::SUCCESS;
364}
StatusCode rebuildLinks(const HepMC::GenEvent *mcEvent, HepMC::GenEvent *outEvt, const HepMC::GenParticlePtr &mcPart)
Rebuild the links between particles which were connected, eg by a long FSR chain.
HepMC3::GenEvent GenEvent
Definition GenEvent.h:39

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ selectSpclMcBarcodes()

StatusCode PileupFilterTool::selectSpclMcBarcodes ( )
protected

Retrieve the GenParticles from the GenEvent object (located into the McEventCollection container), filter them and store their barcode into the list of barcodes of particles to keep.

skip stuff with no end-vertex

stable particles

Definition at line 142 of file PileupFilterTool.cxx.

143{
144 StatusCode sc = StatusCode::SUCCESS;
145
146 // Get all of the generated particles (does not have Geant secondaries)
147
148 std::vector<HepMC::ConstGenParticlePtr> particles;
149 if ( m_includeSimul ) {
150 sc = m_tesIO->getMC(particles, false, m_mcEventsReadHandleKey.key());
151 } else {
152 sc = m_tesIO->getMC(particles, true, m_mcEventsReadHandleKey.key());
153 }
154 if ( sc.isFailure() ) {
155 ATH_MSG_ERROR("Could not get Monte Carlo particles from TDS at : "<< m_mcEventsReadHandleKey.key());
156 return StatusCode::FAILURE;
157 }
158
159 m_particles.clear();
160
161 //+++ Get True Vertices from Storegate
162 const McEventCollection* mcTruth(nullptr);
163 sc = evtStore()->retrieve(mcTruth, m_mcEventsReadHandleKey.key());
164 if( sc.isFailure() ) {
165 ATH_MSG_WARNING("MC Event " << m_mcEventsReadHandleKey.key() << " not found.");
166 return StatusCode::SUCCESS;
167 }
168 ATH_MSG_DEBUG("McEventCollection successfully retrieved" << endmsg << "Number of truth particles: " << mcTruth->size());
169
170 McEventCollection::const_iterator mcEventItr = mcTruth->begin();
171 McEventCollection::const_iterator mcEventItrE = mcTruth->end();
172
173 for ( ; mcEventItr != mcEventItrE; ++mcEventItr ) {
174
175 const HepMC::GenEvent* genEvent = (*mcEventItr);
176
177 auto vxp = genEvent->vertices().begin();
178 const float xp = (*vxp)->position().x();
179 const float yp = (*vxp)->position().y();
180 const float zp = (*vxp)->position().z();
181
182 // Loop over all particles, selecting special ones
183 // keep track of them using their barcodes
184 for (const auto& part: *genEvent) {
185 const int id = part->pdg_id();
186 const HepMC::FourVector hlv = part->momentum();
187 const double pt = hlv.perp();
188 const HepMC::ConstGenVertexPtr& decayVtx = part->end_vertex();
189 const HepMC::ConstGenVertexPtr& prodVtx = part->production_vertex();
190 bool isSpcl = false;
192 if( !MC::isStable(part) && !decayVtx ) continue;
193
194 float xi = (prodVtx->position()).x();
195 float yi = (prodVtx->position()).y();
196 float zi = (prodVtx->position()).z();
197
198 ATH_MSG_DEBUG("Primary Vertex = " << xp << " " << yp << " " << zp << " " << "Production Vertex = " << xi << " " << yi << " " << zi << " " << "Particle ID = " << id);
199
200 float deltaR = std::sqrt( (xp-xi)*(xp-xi) + (yp-yi)*(yp-yi) );
201
202 const bool accept = (pt > m_ptMin) && (deltaR < m_rRange);
204 // Select special particles
207 if (m_includeSimul ) {
208 if ( MC::isSimStable(part) && accept ) isSpcl = true;
209 } else {
210 if ( MC::isGenStable(part) && accept ) isSpcl = true;
211 }
212
214 // Save special particles and children
216 if( !isSpcl ) continue;
217 m_particles.insert(part); // add it to list
218
219 // Children
220 if( isSpcl && decayVtx ) {
221 for(const auto& child: *(part->end_vertex())) {
223 m_particles.insert(child);// its not there already
224 }
225 }
226 }
227 }
228 }
229 ATH_MSG_DEBUG("Read " << particles.size() << " and selected " << m_particles.size() << " particles");
230
231 return StatusCode::SUCCESS;
232}
Scalar deltaR(const MatrixBase< Derived > &vec) const
static Double_t sc
ServiceHandle< StoreGateSvc > & evtStore()
DataModel_detail::const_iterator< DataVector > const_iterator
Definition DataVector.h:838
StatusCode accept(const xAOD::Muon *mu)
::StatusCode StatusCode
StatusCode definition for legacy code.
HepMC3::FourVector FourVector
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
bool isStable(const T &p)
Identify if the particle is stable, i.e. has not decayed.
bool isGenStable(const T &p)
Determine if the particle is stable at the generator (not det-sim) level,.
bool isSimStable(const T &p)
Identify if the particle is considered stable at the post-detector-sim stage.

◆ shapeGenEvent()

StatusCode PileupFilterTool::shapeGenEvent ( McEventCollection * outEvt)
protected

Build the out McEventCollection by removing all the GenParticles whose barcode is not in the list of barcodes to keep.

Remove also the dead vertices.

Definition at line 234 of file PileupFilterTool.cxx.

235{
236 //now remove all the particles except those whose barcodes are marked
237 for ( McEventCollection::iterator evt = genAod->begin(); evt != genAod->end();++evt) {
238 std::vector<HepMC::GenParticlePtr> going_out;
239 std::list<int> evtBarcodes;
240 const auto &barcodes = (*evt)->attribute<HepMC::GenEventBarcodes> (HepMCStr::barcodes);
241 std::map<int,int> id_to_barcode_map;
242 if (barcodes) id_to_barcode_map = barcodes->id_to_barcode_map();
243 for (const auto& keyval: id_to_barcode_map) evtBarcodes.push_back(keyval.second);
244
245 for ( std::list<int>::const_iterator itrBc = evtBarcodes.begin(); itrBc != evtBarcodes.end(); ++itrBc ) {
246//AV: We modify the event!
248 ATH_MSG_DEBUG("[pdg,particle]= " << p->pdg_id() << ", " << p);
249 if ( m_particles.count(p) == 0) {
250 going_out.push_back(p); // list of useless particles
251 HepMC::GenVertexPtr pvtx = p->production_vertex();
252 HepMC::GenVertexPtr evtx = p->end_vertex();
253
254 std::pair<int,int> bcNext( 0, 0 );
255 if ( msgLvl(MSG::DEBUG) ) {
256 msg(MSG::DEBUG) << "Removing [" <<p << "]" << "\tprod/endVtx: " << pvtx << "/" << evtx << endmsg;
257 std::list<int>::const_iterator pNext = itrBc;
258 ++pNext;
259 if ( pNext != evtBarcodes.end() ) {
260 bcNext.first = HepMC::barcode(HepMC::barcode_to_particle(*evt,*pNext));
261 }
262 }
263 if (pvtx) pvtx->remove_particle_out(p); //remove from production vertex from useless particle
264 if (evtx) { // if it has end vertex, may need to move the out partilces
265 if(pvtx){ // move the partilces back
266 if ( msgLvl(MSG::DEBUG) ) {
267 msg(MSG::DEBUG) << "\tin endVtx "<< endmsg;
268 }
269 while ( evtx->particles_out().begin() != evtx->particles_out().end()) {
270 pvtx->add_particle_out(evtx->particles_out().front());
271 }
272 }//> end if [prod vertex]
273 evtx->remove_particle_out(std::move(p)); // disconnect from end vertex
274 }//> end if [decay vertex]
275
276 if ( msgLvl(MSG::DEBUG) ) {
277 std::list<int>::const_iterator pNext = itrBc;
278 ++pNext;
279 if ( pNext != evtBarcodes.end() ) {
280 bcNext.second = HepMC::barcode(HepMC::barcode_to_particle(*evt,*pNext));
281 }
282
283 if ( bcNext.first != bcNext.second ) {
284 ATH_MSG_WARNING("\tIterator has been CORRUPTED !!" << endmsg << "\tbcNext: " << bcNext.first << " --> " << bcNext.second);
285 } else {
286 ATH_MSG_DEBUG("\tIterator OK:" << endmsg << "\tbcNext: " << bcNext.first << " --> " << bcNext.second);
287 }
288 }
289
290 }//> particle has to be removed
291 }//> loop over particles
292
293
294 // there may be a bunch of vertices with no particles connected to them:
295 // ==> Get rid of them
296 std::vector<HepMC::ConstGenVertexPtr> going_out_again;
297 for ( auto& v: (*evt)->vertices() ) {
298 if ( v->particles_in().empty() && v->particles_out().empty() ){
299 going_out_again.push_back(v);
300 }
301 }//> loop over vertices
302
303 }//> loop over GenEvents in McEventCollection
304
305 // Set the signal_process_vertex to NULL if not to be recorded
306 for ( McEventCollection::iterator evt = genAod->begin(); evt != genAod->end(); ++evt) {
307 auto sigProcVtx = HepMC::signal_process_vertex(*evt);
308 if ( !sigProcVtx ) continue;
309 const int sigProcBC = HepMC::barcode(sigProcVtx);
310 bool isInColl = false;
311 if (HepMC::barcode_to_vertex(*evt, sigProcBC)) isInColl = true;
312//AV: We don't set nullptr as signal vertex in HepMC3
313 if ( !isInColl ) {
314 (*evt)->remove_attribute("signal_process_vertex");
315 }
316 }//> loop over GenEvent's
317
318 return StatusCode::SUCCESS;
319}
DataModel_detail::iterator< DataVector > iterator
Definition DataVector.h:842
const std::string barcodes
ConstGenVertexPtr signal_process_vertex(const GenEvent *e)
Definition GenEvent.h:597
HepMC3::GenParticlePtr GenParticlePtr
Definition GenParticle.h:19

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, and AthCheckedComponent<::AthAlgTool >.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default).

Definition at line 393 of file AthCommonDataStore.h.

◆ m_doEtIsolation

BooleanProperty TruthParticleFilterBaseTool::m_doEtIsolation
protectedinherited

Switch to compute or not the Et-isolations for TruthParticle (and their underlying HepMC::GenParticle).

Default is to not compute these Et-isolations (and save CPU)

Definition at line 94 of file TruthParticleFilterBaseTool.h.

◆ m_etaRange

DoubleProperty PileupFilterTool::m_etaRange
protected

Eta acceptance cut applied on all stable particles.

Definition at line 118 of file PileupFilterTool.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default).

Definition at line 390 of file AthCommonDataStore.h.

◆ m_includePartonShowers

BooleanProperty PileupFilterTool::m_includePartonShowers
protected

Switch to include or not parton showers.

Definition at line 130 of file PileupFilterTool.h.

◆ m_includeSimul

BooleanProperty PileupFilterTool::m_includeSimul
protected

Switch to include or not particles from detector simulation (Geant4).

Definition at line 126 of file PileupFilterTool.h.

◆ m_isolationTool

IsolTool_t TruthParticleFilterBaseTool::m_isolationTool
protectedinherited

Pointer to the TruthIsolationTool to be able to compute transverse energy isolations for various isolation cones cuts.

See McParticleEvent/TruthParticleParameters.h for cone cuts.

Definition at line 85 of file TruthParticleFilterBaseTool.h.

◆ m_mcEventsOutputWriteHandleKey

SG::WriteHandleKey<McEventCollection> TruthParticleFilterBaseTool::m_mcEventsOutputWriteHandleKey {this,"McEventsOutput","GEN_AOD","WriteHandleKey for the output McEventCollection which has been filtered"}
protectedinherited

Location of the output McEventCollection which has been filtered.

Definition at line 104 of file TruthParticleFilterBaseTool.h.

104{this,"McEventsOutput","GEN_AOD","WriteHandleKey for the output McEventCollection which has been filtered"};

◆ m_mcEventsReadHandleKey

SG::ReadHandleKey<McEventCollection> TruthParticleFilterBaseTool::m_mcEventsReadHandleKey {this,"McEvents","TruthEvent","ReadHandleKey for input McEventCollection one wants to filter"}
protectedinherited

ReadHandleKey for the input McEventCollection one wants to filter.

Definition at line 100 of file TruthParticleFilterBaseTool.h.

100{this,"McEvents","TruthEvent","ReadHandleKey for input McEventCollection one wants to filter"};

◆ m_mcVtxFilterTool

McVtxFilterTool_t TruthParticleFilterBaseTool::m_mcVtxFilterTool
protectedinherited

Pointer to the McVtxFilterTool to be able to select additional vertices on some decay pattern criterion.

Definition at line 78 of file TruthParticleFilterBaseTool.h.

◆ m_particles

std::set<HepMC::ConstGenParticlePtr> PileupFilterTool::m_particles
protected

List of particles which have been labelled as "special".

Definition at line 101 of file PileupFilterTool.h.

◆ m_ptGamMin

DoubleProperty PileupFilterTool::m_ptGamMin
protected

Minimum threshold for transverse momentum of photons.

Definition at line 109 of file PileupFilterTool.h.

◆ m_ptMin

DoubleProperty PileupFilterTool::m_ptMin
protected

Minimum threshold for transverse momentum for all particles.

Warning: this cut is applied before Pt photon cut !

Definition at line 114 of file PileupFilterTool.h.

◆ m_removeDecayToSelf

BooleanProperty PileupFilterTool::m_removeDecayToSelf
protected

Switch to remove particles which decay into themselves (t->tg) but only for generated particles, not the ones from the Geant4 interactions.

Definition at line 139 of file PileupFilterTool.h.

◆ m_rIsol

DoubleProperty PileupFilterTool::m_rIsol
protected

deltaR isolation energy cut for electrons, muons, taus and photons

Definition at line 105 of file PileupFilterTool.h.

◆ m_rRange

DoubleProperty PileupFilterTool::m_rRange
protected

Radius acceptance cut on all stable particles.

Definition at line 122 of file PileupFilterTool.h.

◆ m_tesIO

TruthHelper::GenAccessIO* PileupFilterTool::m_tesIO
protected

Pointer to a StoreGateSvc helper (Mc particle retrieval with predicates).

Definition at line 134 of file PileupFilterTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.


The documentation for this class was generated from the following files: