ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
MergeTruthParticlesTool Class Reference

an algorithm to merge truth particles collections in the overlay store More...

#include <MergeTruthParticlesTool.h>

Inheritance diagram for MergeTruthParticlesTool:
Collaboration diagram for MergeTruthParticlesTool:

Public Member Functions

 MergeTruthParticlesTool (const std::string &type, const std::string &name, const IInterface *parent)
 
StatusCode initialize () override final
 Initialize. More...
 
virtual StatusCode prepareEvent (const EventContext &ctx, unsigned int nInputEvents) override final
 called before the subevts loop. More...
 
virtual StatusCode mergeEvent (const EventContext &ctx) override final
 called at the end of the subevts loop. More...
 
virtual StatusCode processBunchXing (int bunchXing, SubEventIterator bSubEvents, SubEventIterator eSubEvents) override final
 called for each active bunch-crossing to process current SubEvents bunchXing is in ns More...
 
virtual StatusCode processAllSubEvents (const EventContext &ctx) override final
 Merge the Truth TruthParticleContainers using the PileUpMergeSvc. More...
 

Private Member Functions

virtual StatusCode processTruthParticleContainer (const xAOD::TruthParticleContainer *inputTruthParticleContainer, xAOD::TruthParticleContainer *outputTruthParticleContainer, int eventNumber)
 TruthParticleContainer Loop. More...
 
StatusCode record (const xAOD::TruthParticleContainer *pTruthParticles, const std::string &truthParticleContainerName) const
 

Private Attributes

ServiceHandle< PileUpMergeSvcm_pMergeSvc {this, "PileUpMergeSvc", "PileUpMergeSvc", ""}
 
Gaudi::Property< std::string > m_inputTruthParticleCollKey {this, "InputTruthParticleCollKey", "TruthPileupParticles", ""}
 
Gaudi::Property< std::string > m_inTimeOutputTruthParticleCollKey {this, "InTimeOutputTruthParticleCollKey", "TruthPileupParticles", ""}
 
Gaudi::Property< bool > m_includeSignalTruthParticles {this, "IncludeSignalTruthParticles", false, ""}
 
xAOD::TruthParticleContainerm_inTimeOutputTruthParticleContainer {}
 
bool m_first_event {true}
 

structors and AlgTool implementation

virtual bool toProcess (int bunchXing) const override
 the method this base class helps implementing More...
 
virtual StatusCode processAllSubEvents (const EventContext &ctx)=0
 dummy implementation to allow compilation while all Digitization packages are migrated to use this new interface. More...
 
virtual bool filterPassed () const override
 dummy implementation of passing filter More...
 
virtual void resetFilter () override
 dummy implementation of filter reset More...
 
Gaudi::Property< int > m_firstXing
 
Gaudi::Property< int > m_lastXing
 
Gaudi::Property< int > m_vetoPileUpTruthLinks
 
bool m_filterPassed {true}
 

Detailed Description

an algorithm to merge truth particles collections in the overlay store

Definition at line 23 of file MergeTruthParticlesTool.h.

Constructor & Destructor Documentation

◆ MergeTruthParticlesTool()

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

Definition at line 12 of file MergeTruthParticlesTool.cxx.

16 {
17 }

Member Function Documentation

◆ filterPassed()

virtual bool PileUpToolBase::filterPassed ( ) const
inlineoverridevirtualinherited

dummy implementation of passing filter

Definition at line 49 of file PileUpToolBase.h.

49 { return m_filterPassed; }

◆ initialize()

StatusCode MergeTruthParticlesTool::initialize ( )
finaloverridevirtual

Initialize.

Reimplemented from PileUpToolBase.

Definition at line 19 of file MergeTruthParticlesTool.cxx.

20 {
21  ATH_MSG_DEBUG ( "Initializing " << name());
22  ATH_CHECK(m_pMergeSvc.retrieve());
23  return StatusCode::SUCCESS;
24 }

◆ mergeEvent()

StatusCode MergeTruthParticlesTool::mergeEvent ( const EventContext &  ctx)
finaloverridevirtual

called at the end of the subevts loop.

Not (necessarily) able to access SubEvents

Definition at line 70 of file MergeTruthParticlesTool.cxx.

71 {
72  ATH_MSG_VERBOSE ( "mergeEvent" );
73 
74  if(this->record(m_inTimeOutputTruthParticleContainer, m_inTimeOutputTruthParticleCollKey).isFailure()) { // This call also records the xAOD::TruthParticleAuxContainer.
75  ATH_MSG_ERROR("mergeEvent: Failed to record InTimeOutputTruthParticleContainer");
76  return StatusCode::FAILURE;
77  }
78  else {
79  ATH_MSG_DEBUG ( "mergeEvent: Recorded " << m_inTimeOutputTruthParticleCollKey << " TruthParticleContainer with "
80  << m_inTimeOutputTruthParticleContainer->size() <<" entries." );
81  }
82  return StatusCode::SUCCESS;
83 }

◆ prepareEvent()

StatusCode MergeTruthParticlesTool::prepareEvent ( const EventContext &  ctx,
unsigned int  nInputEvents 
)
finaloverridevirtual

called before the subevts loop.

Not (necessarily) able to access SubEvents

Definition at line 26 of file MergeTruthParticlesTool.cxx.

27 {
28  ATH_MSG_VERBOSE ( "prepareEvent()" );
29  ATH_MSG_DEBUG ( "prepareEvent: there are " << nInputEvents << " subevents in this event." );
30  m_first_event = true;
33  return StatusCode::SUCCESS;
34 }

◆ processAllSubEvents() [1/2]

StatusCode MergeTruthParticlesTool::processAllSubEvents ( const EventContext &  ctx)
finaloverridevirtual

Merge the Truth TruthParticleContainers using the PileUpMergeSvc.

Reimplemented from PileUpToolBase.

Definition at line 109 of file MergeTruthParticlesTool.cxx.

110 {
111  ATH_MSG_VERBOSE ( "processAllSubEvents()" );
112 
113  m_first_event = true;
116 
118  TruthParticleList truthList;
119  if ( (m_pMergeSvc->retrieveSubEvtsData(m_inputTruthParticleCollKey.value(), truthList)).isSuccess() ) {
120  if (!truthList.empty()) {
121  //now merge all collections into one
122  TruthParticleList::const_iterator truthParticleColl_iter(truthList.begin());
123  const TruthParticleList::const_iterator endOfTruthParticleColls(truthList.end());
124  while (truthParticleColl_iter!=endOfTruthParticleColls) {
125  const int eventNumber{static_cast<int>((truthParticleColl_iter)->first.index())}; // casting from long unsigned int to int
126  //const float timeOfBCID(static_cast<float>((truthParticleColl_iter)->first.time()));
127  if( static_cast<int>((truthParticleColl_iter)->first.time())!=0 || !m_first_event || m_includeSignalTruthParticles ) {
129  }
130  //signal is always the first event, so if the first event
131  //wasn't in-time, then the signal collection was missing and
132  //we should skip further checks.
133  if(m_first_event) {m_first_event=false;}
134  ++truthParticleColl_iter;
135  }
136  }
137  else {
138  ATH_MSG_DEBUG ( "processAllSubEvents: TruthParticleList is empty" );
139  }
140  }
141  else {
142  ATH_MSG_ERROR ( "processAllSubEvents: Can not find TruthParticleList" );
143  }
144 
145  if( this->record(m_inTimeOutputTruthParticleContainer, m_inTimeOutputTruthParticleCollKey).isFailure() ) { // This call also records the xAOD::TruthParticleAuxContainer.
146  ATH_MSG_ERROR ( "processAllSubEvents: Failed to record InTimeOutputTruthParticleContainer" );
147  return StatusCode::FAILURE;
148  }
149  else {
150  ATH_MSG_DEBUG ( "processAllSubEvents: Recorded " << m_inTimeOutputTruthParticleCollKey << " xAOD::TruthParticleContainer with "
151  << m_inTimeOutputTruthParticleContainer->size() <<" entries." );
152  }
153 
154  return StatusCode::SUCCESS;
155 }

◆ processAllSubEvents() [2/2]

virtual StatusCode IPileUpTool::processAllSubEvents
inherited

dummy implementation to allow compilation while all Digitization packages are migrated to use this new interface.

◆ processBunchXing()

StatusCode MergeTruthParticlesTool::processBunchXing ( int  bunchXing,
SubEventIterator  bSubEvents,
SubEventIterator  eSubEvents 
)
finaloverridevirtual

called for each active bunch-crossing to process current SubEvents bunchXing is in ns

Reimplemented from PileUpToolBase.

Definition at line 36 of file MergeTruthParticlesTool.cxx.

39 {
40  ATH_MSG_VERBOSE ( "processBunchXing()" );
41  SubEventIterator iEvt(bSubEvents);
42  while (iEvt != eSubEvents) {
43  const xAOD::TruthParticleContainer* inputTruthParticleContainer{};
44  if (m_pMergeSvc->retrieveSingleSubEvtData(m_inputTruthParticleCollKey.value(), inputTruthParticleContainer,
45  bunchXing, iEvt).isSuccess()) {
46  ATH_MSG_VERBOSE("Found an xAOD::TruthParticleContainer in storeGate.");
47  if ( !inputTruthParticleContainer ) {
48  ATH_MSG_ERROR("Unable to retrieve input xAOD::TruthParticleContainer: " << m_inputTruthParticleCollKey);
49  return StatusCode::FAILURE;
50  }
51  ATH_MSG_DEBUG ( "processBunchXing: bunch Crossing = " << bunchXing << " xAOD::TruthParticleContainer size = " << inputTruthParticleContainer->size());
52  const int eventNumber{iEvt->index()};
53  // const float timeOfBCID{static_cast<float>(iEvt->time())};
56  }
57  }
58  else {
59  ATH_MSG_DEBUG ( "processBunchXing: No TruthParticleContainer found." );
60  }
61  m_first_event=false;
62  ++iEvt;
63  }
64  //signal is always the first event, so even if we didn't see
65  //anything should set this to false here.
66  if(m_first_event) {m_first_event=false;}
67  return StatusCode::SUCCESS;
68 }

◆ processTruthParticleContainer()

StatusCode MergeTruthParticlesTool::processTruthParticleContainer ( const xAOD::TruthParticleContainer inputTruthParticleContainer,
xAOD::TruthParticleContainer outputTruthParticleContainer,
int  eventNumber 
)
privatevirtual

TruthParticleContainer Loop.

Definition at line 158 of file MergeTruthParticlesTool.cxx.

159 {
160  if (!inputTruthParticleContainer || !outputTruthParticleContainer) { return StatusCode::FAILURE; }
161 
162  // Set up decorators
163  const static SG::AuxElement::Accessor< int > eventNumberAccessor("pileupEventNumber");
164 
165  for (const xAOD::TruthParticle *theParticle : *inputTruthParticleContainer) {
166  xAOD::TruthParticle* xTruthParticle = new xAOD::TruthParticle();
167  outputTruthParticleContainer->push_back(xTruthParticle);
168  *xTruthParticle = *theParticle; // deep-copy
169  // add the pile-up event number
170  eventNumberAccessor(*xTruthParticle) = eventNumber;
171  }
172  return StatusCode::SUCCESS;
173 }

◆ record()

StatusCode MergeTruthParticlesTool::record ( const xAOD::TruthParticleContainer pTruthParticles,
const std::string &  truthParticleContainerName 
) const
private

Definition at line 85 of file MergeTruthParticlesTool.cxx.

86 {
87  const xAOD::TruthParticleAuxContainer* pTruthParticlesAux =
88  dynamic_cast<const xAOD::TruthParticleAuxContainer*>(pTruthParticles->getConstStore());
89  ATH_MSG_DEBUG("Check Aux store: " << pTruthParticles << " ... " << &pTruthParticles->auxbase() << " ... " << pTruthParticlesAux );
90  if ( !pTruthParticlesAux ) {
91  ATH_MSG_ERROR("Unable to retrieve xAOD::TruthParticleAuxContainer");
92  return StatusCode::FAILURE;
93  }
94  ATH_MSG_VERBOSE("Recording new xAOD::TruthParticleAuxContainer.");
95  if ( evtStore()->record(pTruthParticlesAux, truthParticleContainerName+"Aux.").isFailure() ) {
96  ATH_MSG_ERROR("Unable to write new xAOD::TruthParticleAuxContainer to event store: " << truthParticleContainerName);
97  return StatusCode::FAILURE;
98  }
99  ATH_MSG_VERBOSE("Recording new xAOD::TruthParticleContainer.");
100  if ( evtStore()->record(pTruthParticles, truthParticleContainerName).isFailure() ) {
101  ATH_MSG_ERROR("Unable to write new xAOD::TruthParticleContainer to event store: " << truthParticleContainerName);
102  return StatusCode::FAILURE;
103  }
104  ATH_MSG_DEBUG("Created new xAOD::TruthParticleContainer in event store: " << truthParticleContainerName);
105  return StatusCode::SUCCESS;
106 }

◆ resetFilter()

virtual void PileUpToolBase::resetFilter ( )
inlineoverridevirtualinherited

dummy implementation of filter reset

Reimplemented in MergeTruthJetsTool.

Definition at line 51 of file PileUpToolBase.h.

51 { m_filterPassed=true; }

◆ toProcess()

virtual bool PileUpToolBase::toProcess ( int  bunchXing) const
inlineoverridevirtualinherited

the method this base class helps implementing

Reimplemented in MergeHijingParsTool, and MergeTrackRecordCollTool.

Definition at line 32 of file PileUpToolBase.h.

32  {
33  //closed interval [m_firstXing,m_lastXing]
34  return !((m_firstXing > bunchXing) || (bunchXing > m_lastXing));
35  }

Member Data Documentation

◆ m_filterPassed

bool PileUpToolBase::m_filterPassed {true}
protectedinherited

Definition at line 60 of file PileUpToolBase.h.

◆ m_first_event

bool MergeTruthParticlesTool::m_first_event {true}
private

Definition at line 55 of file MergeTruthParticlesTool.h.

◆ m_firstXing

Gaudi::Property<int> PileUpToolBase::m_firstXing
protectedinherited
Initial value:
{this, "FirstXing", -999,
"First bunch-crossing in which det is live"}

Definition at line 54 of file PileUpToolBase.h.

◆ m_includeSignalTruthParticles

Gaudi::Property<bool> MergeTruthParticlesTool::m_includeSignalTruthParticles {this, "IncludeSignalTruthParticles", false, ""}
private

Definition at line 53 of file MergeTruthParticlesTool.h.

◆ m_inputTruthParticleCollKey

Gaudi::Property<std::string> MergeTruthParticlesTool::m_inputTruthParticleCollKey {this, "InputTruthParticleCollKey", "TruthPileupParticles", ""}
private

Definition at line 51 of file MergeTruthParticlesTool.h.

◆ m_inTimeOutputTruthParticleCollKey

Gaudi::Property<std::string> MergeTruthParticlesTool::m_inTimeOutputTruthParticleCollKey {this, "InTimeOutputTruthParticleCollKey", "TruthPileupParticles", ""}
private

Definition at line 52 of file MergeTruthParticlesTool.h.

◆ m_inTimeOutputTruthParticleContainer

xAOD::TruthParticleContainer* MergeTruthParticlesTool::m_inTimeOutputTruthParticleContainer {}
private

Definition at line 54 of file MergeTruthParticlesTool.h.

◆ m_lastXing

Gaudi::Property<int> PileUpToolBase::m_lastXing
protectedinherited
Initial value:
{this, "LastXing", 999,
"Last bunch-crossing in which det is live"}

Definition at line 56 of file PileUpToolBase.h.

◆ m_pMergeSvc

ServiceHandle<PileUpMergeSvc> MergeTruthParticlesTool::m_pMergeSvc {this, "PileUpMergeSvc", "PileUpMergeSvc", ""}
private

Definition at line 50 of file MergeTruthParticlesTool.h.

◆ m_vetoPileUpTruthLinks

Gaudi::Property<int> PileUpToolBase::m_vetoPileUpTruthLinks
protectedinherited
Initial value:
{this, "VetoPileUpTruthLinks", true,
"Ignore links to suppressed pile-up truth"}

Definition at line 58 of file PileUpToolBase.h.


The documentation for this class was generated from the following files:
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
PileUpToolBase::m_filterPassed
bool m_filterPassed
Definition: PileUpToolBase.h:60
SG::Accessor
Helper class to provide type-safe access to aux data.
Definition: Control/AthContainers/AthContainers/Accessor.h:68
MergeTruthParticlesTool::m_includeSignalTruthParticles
Gaudi::Property< bool > m_includeSignalTruthParticles
Definition: MergeTruthParticlesTool.h:53
MergeTruthParticlesTool::m_inputTruthParticleCollKey
Gaudi::Property< std::string > m_inputTruthParticleCollKey
Definition: MergeTruthParticlesTool.h:51
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
PileUpToolBase::m_lastXing
Gaudi::Property< int > m_lastXing
Definition: PileUpToolBase.h:56
MergeTruthParticlesTool::m_pMergeSvc
ServiceHandle< PileUpMergeSvc > m_pMergeSvc
Definition: MergeTruthParticlesTool.h:50
DataVector::auxbase
const SG::AuxVectorBase & auxbase() const
Convert to AuxVectorBase.
PileUpMergeSvc::TimedList::type
std::list< value_t > type
type of the collection of timed data object
Definition: PileUpMergeSvc.h:75
xAOD::TruthParticleAuxContainer_v1
Auxiliary store for the truth vertices.
Definition: TruthParticleAuxContainer_v1.h:27
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
xAOD::TruthParticle
TruthParticle_v1 TruthParticle
Typedef to implementation.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticle.h:15
test_pyathena.parent
parent
Definition: test_pyathena.py:15
PileUpToolBase::PileUpToolBase
PileUpToolBase(const std::string &type, const std::string &name, const IInterface *parent)
Definition: PileUpToolBase.cxx:7
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
MergeTruthParticlesTool::processTruthParticleContainer
virtual StatusCode processTruthParticleContainer(const xAOD::TruthParticleContainer *inputTruthParticleContainer, xAOD::TruthParticleContainer *outputTruthParticleContainer, int eventNumber)
TruthParticleContainer Loop.
Definition: MergeTruthParticlesTool.cxx:158
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
xAOD::TruthParticleContainer
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
Definition: Event/xAOD/xAODTruth/xAODTruth/TruthParticleContainer.h:17
MergeTruthParticlesTool::record
StatusCode record(const xAOD::TruthParticleContainer *pTruthParticles, const std::string &truthParticleContainerName) const
Definition: MergeTruthParticlesTool.cxx:85
MergeTruthParticlesTool::m_inTimeOutputTruthParticleContainer
xAOD::TruthParticleContainer * m_inTimeOutputTruthParticleContainer
Definition: MergeTruthParticlesTool.h:54
MergeTruthParticlesTool::m_first_event
bool m_first_event
Definition: MergeTruthParticlesTool.h:55
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:536
PileUpToolBase::m_firstXing
Gaudi::Property< int > m_firstXing
Definition: PileUpToolBase.h:54
SubEventIterator
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition: IPileUpTool.h:22
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
MergeTruthParticlesTool::m_inTimeOutputTruthParticleCollKey
Gaudi::Property< std::string > m_inTimeOutputTruthParticleCollKey
Definition: MergeTruthParticlesTool.h:52