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

a PileUpTool to merge MC truth collection in the overlay store More...

#include <SimpleMergeMcEventCollTool.h>

Inheritance diagram for SimpleMergeMcEventCollTool:
Collaboration diagram for SimpleMergeMcEventCollTool:

Public Member Functions

 SimpleMergeMcEventCollTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual StatusCode initialize () override final
virtual StatusCode prepareEvent (const EventContext &ctx, unsigned int nInputEvents) override final
 called before the subevts loop.
virtual StatusCode mergeEvent (const EventContext &ctx) override final
 called at the end of the subevts loop.
virtual StatusCode processBunchXing (int, SubEventIterator bSubEvents, SubEventIterator eSubEvents) override final
 called for each active bunch-crossing to process current SubEvents bunchXing is in ns
virtual StatusCode processAllSubEvents (const EventContext &ctx) override final
 return false if not interested in certain xing times (in ns) implemented by default in PileUpToolBase as FirstXing<=bunchXing<=LastXing

Private Member Functions

StatusCode saveHeavyIonInfo (const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection)
 Common methods.
StatusCode processEvent (const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection, const int currentBkgEventIndex, int bunchCrossingTime, int pileupType)
void printDetailsOfMergedMcEventCollection (McEventCollection *outputMcEventCollection) const

Private Attributes

ServiceHandle< PileUpMergeSvcm_pMergeSvc {this, "PileUpMergeSvc", "PileUpMergeSvc", ""}
StringProperty m_truthCollOutputKey {this, "TruthCollOutputKey", "TruthEvent", "Name of output McEventCollection"}
McEventCollectionm_outputMcEventCollection {}
StringProperty m_truthCollInputKey {this, "TruthCollInputKey", "TruthEvent", ""}
BooleanProperty m_overrideEventNumbers {this, "OverrideEventNumbers", false, ""}
BooleanProperty m_onlySaveSignalTruth {this, "OnlySaveSignalTruth", false, "Just save the Signal GenEvent"}
bool m_newevent {true}
unsigned int m_nInputMcEventColls {0}
unsigned int m_nBkgEventsReadSoFar {0}

structors and AlgTool implementation

virtual bool toProcess (int bunchXing) const override
 the method this base class helps implementing
virtual bool filterPassed () const override
 dummy implementation of passing filter
virtual void resetFilter () override
 dummy implementation of filter reset
Gaudi::Property< int > m_firstXing
Gaudi::Property< int > m_lastXing
Gaudi::Property< int > m_vetoPileUpTruthLinks
bool m_filterPassed {true}

Detailed Description

a PileUpTool to merge MC truth collection in the overlay store

$Id:

Author
jchap.nosp@m.man@.nosp@m.cern..nosp@m.ch

Definition at line 26 of file SimpleMergeMcEventCollTool.h.

Constructor & Destructor Documentation

◆ SimpleMergeMcEventCollTool()

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

Definition at line 12 of file SimpleMergeMcEventCollTool.cxx.

14 :
15 PileUpToolBase(type, name, parent)
16{
17}
PileUpToolBase(const std::string &type, const std::string &name, const IInterface *parent)

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 SimpleMergeMcEventCollTool::initialize ( )
finaloverridevirtual

Reimplemented from PileUpToolBase.

Definition at line 19 of file SimpleMergeMcEventCollTool.cxx.

20{
21 if(!m_pMergeSvc.empty())
22 {
23 ATH_CHECK(m_pMergeSvc.retrieve());
24 }
25 return StatusCode::SUCCESS;
26}
#define ATH_CHECK
Evaluate an expression and check for errors.
ServiceHandle< PileUpMergeSvc > m_pMergeSvc

◆ mergeEvent()

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

called at the end of the subevts loop.

Not (necessarily) able to access SubEvents

Definition at line 77 of file SimpleMergeMcEventCollTool.cxx.

78{
79 ATH_MSG_DEBUG( "mergeEvent()" );
81 {
82 ATH_MSG_WARNING( "mergeEvent: Expected " << m_nInputMcEventColls << " subevents, but only saw " << m_nBkgEventsReadSoFar+1 << "! The job will probably crash now..." );
83 return StatusCode::FAILURE;
84 }
85 if(msgLvl(MSG::VERBOSE)) { this->printDetailsOfMergedMcEventCollection(m_outputMcEventCollection); }
86 return StatusCode::SUCCESS;
87}
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
McEventCollection * m_outputMcEventCollection
void printDetailsOfMergedMcEventCollection(McEventCollection *outputMcEventCollection) const

◆ prepareEvent()

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

called before the subevts loop.

PileUpTools Approach.

Not (necessarily) able to access SubEvents

Definition at line 29 of file SimpleMergeMcEventCollTool.cxx.

30{
31 ATH_MSG_VERBOSE ( "prepareEvent()" );
33 m_newevent = true;
34
35 //Check we are getting at least one event
36 m_nInputMcEventColls = nInputEvents;
37 if (0 == m_nInputMcEventColls)
38 {
39 ATH_MSG_ERROR("prepareEvent: TimedTruthList with key "
40 << m_truthCollInputKey << " is empty");
41 return StatusCode::RECOVERABLE;
42 }
43 ATH_MSG_DEBUG( "prepareEvent: there are " << m_nInputMcEventColls << " subevents in this event.");
44
46 return StatusCode::SUCCESS;
47}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)

◆ printDetailsOfMergedMcEventCollection()

void SimpleMergeMcEventCollTool::printDetailsOfMergedMcEventCollection ( McEventCollection * outputMcEventCollection) const
private

Definition at line 189 of file SimpleMergeMcEventCollTool.cxx.

190{
191 if (outputMcEventCollection->empty()) { return; }
192 DataVector<HepMC::GenEvent>::const_iterator outputEventItr(outputMcEventCollection->begin());
193 const DataVector<HepMC::GenEvent>::const_iterator endOfEvents(outputMcEventCollection->end());
194 ATH_MSG_INFO ( "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" );
195 ATH_MSG_INFO ( "Current OUTPUT GenEvent: " );
196 while(outputEventItr!=endOfEvents)
197 {
198 const int signal_process_id=HepMC::signal_process_id(*outputEventItr);
199 const int event_number((*outputEventItr)->event_number());
200 ATH_MSG_INFO ( "GenEvent #"<<event_number<<", signal_process_id="<<signal_process_id<</*", category="<<event->second<<*/", number of Vertices="<<(*outputEventItr)->vertices_size() );
201 char fname[80];
202 sprintf(fname,"%s.event%d.txt",m_truthCollInputKey.value().c_str(),event_number);
203 std::ofstream of(fname);
204 HepMC::Print::line(of,*(*outputEventItr)); // verbose output
205 of.close();
206 ++outputEventItr;
207 }
208 ATH_MSG_INFO ( "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" );
209 return;
210}
#define ATH_MSG_INFO(x)
DataModel_detail::const_iterator< DataVector > const_iterator
Standard const_iterator.
Definition DataVector.h:838
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
bool empty() const noexcept
Returns true if the collection is empty.
void line(std::ostream &os, const GenEvent &e)
Definition GenEvent.h:678
int signal_process_id(const GenEvent &e)
Definition GenEvent.h:637

◆ processAllSubEvents()

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

return false if not interested in certain xing times (in ns) implemented by default in PileUpToolBase as FirstXing<=bunchXing<=LastXing

Algorithm Approach.

Reimplemented from PileUpToolBase.

Definition at line 90 of file SimpleMergeMcEventCollTool.cxx.

91{
92 ATH_MSG_VERBOSE ( "processAllSubEvents()" );
93 SG::WriteHandle<McEventCollection> outputMcEventCollection(m_truthCollOutputKey.value());
94 ATH_CHECK(outputMcEventCollection.record(std::make_unique<McEventCollection>()));
95
96 //first get the list of McEventCollections
98 TimedTruthList truthList;
99 ATH_CHECK(m_pMergeSvc->retrieveSubEvtsData(m_truthCollInputKey.value(), truthList));
100
102 m_newevent = true;
103
104 //Check we are getting at least one event
105 m_nInputMcEventColls=truthList.size();
106 if (0 == m_nInputMcEventColls)
107 {
108 ATH_MSG_ERROR("TimedTruthList with key " << m_truthCollInputKey << " is empty.");
109 return StatusCode::RECOVERABLE;
110 }
111
112 ATH_MSG_DEBUG( "execute: there are " << m_nInputMcEventColls << " subevents in this event.");
113 //TODO can we make this into an auto for loop?
114 TimedTruthList::iterator timedTruthListIter(truthList.begin()), endOfTimedTruthList(truthList.end());
115 //loop over the McEventCollections (each one assumed to containing exactly one GenEvent) of the various input events
116 while (timedTruthListIter != endOfTimedTruthList)
117 {
118 const PileUpTimeEventIndex& currentPileUpTimeEventIndex(timedTruthListIter->first); //time() , type()
119 const McEventCollection *pBackgroundMcEvtColl(&*(timedTruthListIter->second));
121 pBackgroundMcEvtColl,
122 outputMcEventCollection.ptr(),
123 currentPileUpTimeEventIndex.index(),
124 static_cast<int>(currentPileUpTimeEventIndex.time()),
125 static_cast<int>(currentPileUpTimeEventIndex.type())
126 ));
127 ++timedTruthListIter;
128 } //timed colls
129
130 if(msgLvl(MSG::VERBOSE)) { this->printDetailsOfMergedMcEventCollection(outputMcEventCollection.ptr()); }
131 return StatusCode::SUCCESS;
132}
StatusCode processEvent(const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection, const int currentBkgEventIndex, int bunchCrossingTime, int pileupType)
std::list< value_t > type
type of the collection of timed data object

◆ processBunchXing()

StatusCode SimpleMergeMcEventCollTool::processBunchXing ( int ,
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 49 of file SimpleMergeMcEventCollTool.cxx.

52{
53 SubEventIterator iEvt(bSubEvents);
54 //loop over the McEventCollections (each one assumed to containing exactly one GenEvent) of the various input events
55 while (iEvt != eSubEvents)
56 {
57 StoreGateSvc& seStore(*iEvt->ptr()->evtStore());
58 const McEventCollection *pMEC(nullptr);
59 ATH_CHECK(seStore.retrieve(pMEC, m_truthCollInputKey));
60 ATH_MSG_DEBUG ("processBunchXing: SubEvt McEventCollection from StoreGate " << seStore.name() );
64 }
66 pMEC,
68 iEvt->index(),
69 static_cast<int>(iEvt->time()),
70 static_cast<int>(iEvt->type())
71 ));
72 ++iEvt;
73 }
74 return StatusCode::SUCCESS;
75}
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition IPileUpTool.h:22

◆ processEvent()

StatusCode SimpleMergeMcEventCollTool::processEvent ( const McEventCollection * pMcEvtColl,
McEventCollection * outputMcEventCollection,
const int currentBkgEventIndex,
int bunchCrossingTime,
int pileupType )
private

Definition at line 152 of file SimpleMergeMcEventCollTool.cxx.

153{
154 ATH_MSG_VERBOSE ( "processEvent() Event Type: " << pileupType << ", BunchCrossingTime: " << bunchCrossingTime );
155 if (!outputMcEventCollection) {
156 ATH_MSG_ERROR( this->name()<<"::processEvent() was passed an null output McEventCollection pointer." );
157 return StatusCode::FAILURE;
158 }
159 if (!pMcEvtColl) {
160 ATH_MSG_ERROR( this->name()<<"::processEvent() was passed an null input McEventCollection pointer." );
161 return StatusCode::FAILURE;
162 }
163
164 if ( pMcEvtColl->empty() || (m_onlySaveSignalTruth && !m_newevent) ) {
166 return StatusCode::SUCCESS;
167 }
168
169 //GenEvt is there
170
171 const HepMC::GenEvent& currentBackgroundEvent(**(pMcEvtColl->begin()));
172 // FIXME no protection against multiple GenEvents having the same event number
173 HepMC::GenEvent* copiedEvent = new HepMC::GenEvent(currentBackgroundEvent);
175 copiedEvent->set_event_number(currentBkgEventIndex);
176 }
177 HepMC::fillBarcodesAttribute(copiedEvent);
178#ifdef HEPMC3
179 copiedEvent->add_attribute("BunchCrossingTime",std::make_shared<HepMC3::IntAttribute>(bunchCrossingTime));
180 copiedEvent->add_attribute("PileUpType",std::make_shared<HepMC3::IntAttribute>(pileupType));
181#endif
182 outputMcEventCollection->push_back(copiedEvent);
183 ATH_CHECK(this->saveHeavyIonInfo(pMcEvtColl, outputMcEventCollection));
184 m_newevent = false;
186 return StatusCode::SUCCESS;
187}
value_type push_back(value_type pElem)
Add an element to the end of the collection.
StatusCode saveHeavyIonInfo(const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection)
Common methods.
void fillBarcodesAttribute(GenEvent *)
Definition GenEvent.h:628

◆ 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; }

◆ saveHeavyIonInfo()

StatusCode SimpleMergeMcEventCollTool::saveHeavyIonInfo ( const McEventCollection * pMcEvtColl,
McEventCollection * outputMcEventCollection )
private

Common methods.

Definition at line 136 of file SimpleMergeMcEventCollTool.cxx.

137{
138 if (outputMcEventCollection->at(0)->heavy_ion()) return StatusCode::SUCCESS;
139 if (pMcEvtColl->at(0)->heavy_ion())
140 {
141//It should be clarified if we want to get a copy or the content
142#ifdef HEPMC3
143 HepMC::GenHeavyIonPtr hinew=std::make_shared<HepMC::GenHeavyIon>(*(pMcEvtColl->at(0)->heavy_ion()));
144 outputMcEventCollection->at(0)->set_heavy_ion(std::move(hinew));
145#else
146 outputMcEventCollection->at(0)->set_heavy_ion(*(pMcEvtColl->at(0)->heavy_ion()));
147#endif
148 }
149 return StatusCode::SUCCESS;
150}
const T * at(size_type n) const
Access an element, as an rvalue.

◆ 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 }
Gaudi::Property< int > m_firstXing
Gaudi::Property< int > m_lastXing

Member Data Documentation

◆ m_filterPassed

bool PileUpToolBase::m_filterPassed {true}
protectedinherited

Definition at line 60 of file PileUpToolBase.h.

60{true};

◆ 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.

54 {this, "FirstXing", -999,
55 "First bunch-crossing in which det is live"};

◆ 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.

56 {this, "LastXing", 999,
57 "Last bunch-crossing in which det is live"};

◆ m_nBkgEventsReadSoFar

unsigned int SimpleMergeMcEventCollTool::m_nBkgEventsReadSoFar {0}
private

Definition at line 72 of file SimpleMergeMcEventCollTool.h.

72{0};

◆ m_newevent

bool SimpleMergeMcEventCollTool::m_newevent {true}
private

Definition at line 68 of file SimpleMergeMcEventCollTool.h.

68{true};

◆ m_nInputMcEventColls

unsigned int SimpleMergeMcEventCollTool::m_nInputMcEventColls {0}
private

Definition at line 70 of file SimpleMergeMcEventCollTool.h.

70{0};

◆ m_onlySaveSignalTruth

BooleanProperty SimpleMergeMcEventCollTool::m_onlySaveSignalTruth {this, "OnlySaveSignalTruth", false, "Just save the Signal GenEvent"}
private

Definition at line 66 of file SimpleMergeMcEventCollTool.h.

66{this, "OnlySaveSignalTruth", false, "Just save the Signal GenEvent"};

◆ m_outputMcEventCollection

McEventCollection* SimpleMergeMcEventCollTool::m_outputMcEventCollection {}
private

Definition at line 60 of file SimpleMergeMcEventCollTool.h.

60{};

◆ m_overrideEventNumbers

BooleanProperty SimpleMergeMcEventCollTool::m_overrideEventNumbers {this, "OverrideEventNumbers", false, ""}
private

Definition at line 64 of file SimpleMergeMcEventCollTool.h.

64{this, "OverrideEventNumbers", false, ""};

◆ m_pMergeSvc

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

Definition at line 58 of file SimpleMergeMcEventCollTool.h.

58{this, "PileUpMergeSvc", "PileUpMergeSvc", ""};

◆ m_truthCollInputKey

StringProperty SimpleMergeMcEventCollTool::m_truthCollInputKey {this, "TruthCollInputKey", "TruthEvent", ""}
private

Definition at line 62 of file SimpleMergeMcEventCollTool.h.

62{this, "TruthCollInputKey", "TruthEvent", ""};

◆ m_truthCollOutputKey

StringProperty SimpleMergeMcEventCollTool::m_truthCollOutputKey {this, "TruthCollOutputKey", "TruthEvent", "Name of output McEventCollection"}
private

Definition at line 59 of file SimpleMergeMcEventCollTool.h.

59{this, "TruthCollOutputKey", "TruthEvent", "Name of output McEventCollection"};

◆ 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.

58 {this, "VetoPileUpTruthLinks", true,
59 "Ignore links to suppressed pile-up truth"};

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