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

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

#include <NewMergeMcEventCollTool.h>

Inheritance diagram for NewMergeMcEventCollTool:
Collaboration diagram for NewMergeMcEventCollTool:

Public Member Functions

 NewMergeMcEventCollTool (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
 Algorithm Approach.

Private Member Functions

StatusCode processEvent (const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection, int pileupType, long timeOffset=0)
void printDetailsOfMergedMcEventCollection (McEventCollection *outputMcEventCollection) const

Private Attributes

ServiceHandle< PileUpMergeSvcm_pMergeSvc {this, "PileUpMergeSvc", "PileUpMergeSvc", ""}
StringProperty m_truthCollInputKey {this,"TruthCollInputKey", "TruthEvent", ""}
Gaudi::Property< int > m_pileUpType {this, "PileUpType", -1, ""}
SG::WriteHandle< McEventCollectionm_outputMcEventCollection {}
SG::WriteHandleKey< McEventCollectionm_truthCollOutputKey {this, "TruthCollOutputKey","TruthEvent",""}

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

Definition at line 24 of file NewMergeMcEventCollTool.h.

Constructor & Destructor Documentation

◆ NewMergeMcEventCollTool()

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

Definition at line 8 of file NewMergeMcEventCollTool.cxx.

10 :
11 PileUpToolBase(type, name, parent)
12{
13}
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 NewMergeMcEventCollTool::initialize ( )
finaloverridevirtual

Reimplemented from PileUpToolBase.

Definition at line 15 of file NewMergeMcEventCollTool.cxx.

16{
17 ATH_CHECK(m_pMergeSvc.retrieve());
18
19 ATH_CHECK( m_truthCollOutputKey.initialize() );
20 return StatusCode::SUCCESS;
21}
#define ATH_CHECK
Evaluate an expression and check for errors.
SG::WriteHandleKey< McEventCollection > m_truthCollOutputKey
ServiceHandle< PileUpMergeSvc > m_pMergeSvc

◆ mergeEvent()

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

called at the end of the subevts loop.

Not (necessarily) able to access SubEvents

Definition at line 72 of file NewMergeMcEventCollTool.cxx.

73{
74 ATH_MSG_VERBOSE( this->name()<<"::mergeEvent()" );
75 if(msgLvl(MSG::VERBOSE)) { this->printDetailsOfMergedMcEventCollection(m_outputMcEventCollection.ptr()); }
76 return StatusCode::SUCCESS;
77}
#define ATH_MSG_VERBOSE(x)
SG::WriteHandle< McEventCollection > m_outputMcEventCollection
void printDetailsOfMergedMcEventCollection(McEventCollection *outputMcEventCollection) const

◆ prepareEvent()

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

called before the subevts loop.

PileUpTools Approach.

Not (necessarily) able to access SubEvents

Definition at line 24 of file NewMergeMcEventCollTool.cxx.

25{
26 ATH_MSG_VERBOSE( this->name()<<"::prepareEvent()" );
27
28 //Check we are getting at least one event
29 if (0 == nInputEvents) {
30 ATH_MSG_ERROR("prepareEvent: TimedTruthList with key "
31 << m_truthCollInputKey.value() << " is empty");
32 return StatusCode::RECOVERABLE;
33 }
34 ATH_MSG_VERBOSE( this->name()<<"::prepareEvent: there are " << nInputEvents << " subevents in this event.");
35
36 if (!m_outputMcEventCollection.isValid()) {
37 // Would be nice to avoid having the WriteHandle as a member
38 // variable, but this is the only way to allow multiple function
39 // calls to add information to the version of the
40 // McEventCollection in the output StoreGate
42 ATH_CHECK(m_outputMcEventCollection.record(std::make_unique<McEventCollection>()));
43 }
44 else {
45 ATH_MSG_ERROR("WriteHandle already valid??");
46 return StatusCode::FAILURE;
47 }
48
49 return StatusCode::SUCCESS;
50}
#define ATH_MSG_ERROR(x)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())

◆ printDetailsOfMergedMcEventCollection()

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

Definition at line 153 of file NewMergeMcEventCollTool.cxx.

154{
155 DataVector<HepMC::GenEvent>::const_iterator outputEventItr(outputMcEventCollection->begin());
156 const DataVector<HepMC::GenEvent>::const_iterator endOfEvents(outputMcEventCollection->end());
157 ATH_MSG_INFO ( "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" );
158 ATH_MSG_INFO ( "pileUpType: " << m_pileUpType);
159 ATH_MSG_INFO ( "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" );
160 ATH_MSG_INFO ( "Current OUTPUT GenEvent: " );
161 while(outputEventItr!=endOfEvents) {
162 const int signal_process_id(HepMC::signal_process_id((*outputEventItr)));
163 const int event_number((*outputEventItr)->event_number());
164 ATH_MSG_INFO ( "GenEvent #"<<event_number<<", signal_process_id="<<signal_process_id<</*", category="<<event->second<<*/", number of Vertices="<<(*outputEventItr)->vertices_size() );
165 char fname[80];
166 sprintf(fname,"%s.event%d.txt",m_truthCollInputKey.value().c_str(),event_number);
167 std::ofstream of(fname);
168 const HepMC::GenEvent *evt=(*outputEventItr);
169 HepMC::Print::line(of,*evt); // verbose output
170 of.close();
171 ++outputEventItr;
172 }
173 ATH_MSG_INFO ( "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$" );
174 return;
175}
#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.
Gaudi::Property< int > m_pileUpType
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 NewMergeMcEventCollTool::processAllSubEvents ( const EventContext & ctx)
finaloverridevirtual

Algorithm Approach.

Reimplemented from PileUpToolBase.

Definition at line 80 of file NewMergeMcEventCollTool.cxx.

81{
82 ATH_MSG_VERBOSE ( this->name()<<"::processAllSubEvents()" );
83 SG::WriteHandle<McEventCollection> outputMcEventCollection(m_truthCollOutputKey, ctx);
84 ATH_CHECK(outputMcEventCollection.record(std::make_unique<McEventCollection>()));
85
86 //first get the list of McEventCollections
88 TimedTruthList truthList;
89 ATH_CHECK(m_pMergeSvc->retrieveSubEvtsData(m_truthCollInputKey.value(), truthList));
90
91 //Check we are getting at least one event
92 const unsigned int nInputMcEventColls=truthList.size();
93 if (0 == nInputMcEventColls) {
94 ATH_MSG_WARNING("TimedTruthList with key " << m_truthCollInputKey.value() << " is empty.");
95 return StatusCode::SUCCESS;
96 }
97
98 ATH_MSG_DEBUG( "execute: there are " << nInputMcEventColls << " subevents in this event.");
99 //TODO can we make this into an auto for loop?
100 TimedTruthList::iterator timedTruthListIter(truthList.begin()), endOfTimedTruthList(truthList.end());
101 //loop over the McEventCollections (each one assumed to containing exactly one GenEvent) of the various input events
102 while (timedTruthListIter != endOfTimedTruthList) {
103 ATH_MSG_VERBOSE( this->name()<<"::processBunchXing: SubEvt McEventCollection of PileUpType " << timedTruthListIter->first.type() );
104 if(m_pileUpType==timedTruthListIter->first.type()) {
105 const McEventCollection *pBackgroundMcEvtColl(&*(timedTruthListIter->second));
106 ATH_CHECK(this->processEvent(pBackgroundMcEvtColl, outputMcEventCollection.ptr(), static_cast<int>(timedTruthListIter->first.type()), timedTruthListIter->first.time()));
107 }
108 ++timedTruthListIter;
109 } //timed colls
110
111 if(msgLvl(MSG::VERBOSE)) { this->printDetailsOfMergedMcEventCollection(outputMcEventCollection.ptr()); }
112 return StatusCode::SUCCESS;
113}
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
StatusCode processEvent(const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection, int pileupType, long timeOffset=0)
std::list< value_t > type
type of the collection of timed data object

◆ processBunchXing()

StatusCode NewMergeMcEventCollTool::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 52 of file NewMergeMcEventCollTool.cxx.

55{
56 SubEventIterator iEvt(bSubEvents);
57 //loop over the McEventCollections (each one assumed to containing exactly one GenEvent) of the various input events
58 while (iEvt != eSubEvents){
59 StoreGateSvc& seStore(*iEvt->ptr()->evtStore());
60 const McEventCollection *pMEC(nullptr);
61 ATH_CHECK(seStore.retrieve(pMEC, m_truthCollInputKey.value()));
62 ATH_MSG_VERBOSE( this->name()<<"::processBunchXing: SubEvt McEventCollection from StoreGate " << seStore.name() << " of PileUpType " << iEvt->type() );
63 if(m_pileUpType==iEvt->type()) {
65 static_cast<int>(iEvt->type()), iEvt->time()));
66 }
67 ++iEvt;
68 }
69 return StatusCode::SUCCESS;
70}
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition IPileUpTool.h:22

◆ processEvent()

StatusCode NewMergeMcEventCollTool::processEvent ( const McEventCollection * pMcEvtColl,
McEventCollection * outputMcEventCollection,
int pileupType,
long timeOffset = 0 )
private

Definition at line 115 of file NewMergeMcEventCollTool.cxx.

116{
117 ATH_MSG_VERBOSE( this->name()<<"::processEvent() Event Type: " << pileupType );
118 if (!outputMcEventCollection) {
119 ATH_MSG_ERROR( this->name()<<"::processEvent() was passed an null output McEventCollection pointer." );
120 return StatusCode::FAILURE;
121 }
122 if (!pMcEvtColl) {
123 ATH_MSG_ERROR( this->name()<<"::processEvent() was passed an null input McEventCollection pointer." );
124 return StatusCode::FAILURE;
125 }
126 if (!pMcEvtColl->empty()) {
127 for (unsigned int iEv=0; iEv<pMcEvtColl->size(); iEv++) {
128 const HepMC::GenEvent& c_evt(*((*pMcEvtColl)[iEv]));
129#ifdef HEPMC3
130 HepMC::GenEvent * evt = new HepMC::GenEvent(c_evt);
132 const int bunchCrossingTime=static_cast<int>(timeOffset);
133 evt->add_attribute("BunchCrossingTime",std::make_shared<HepMC3::IntAttribute>(bunchCrossingTime));
134 evt->add_attribute("PileUpType",std::make_shared<HepMC3::IntAttribute>(pileupType));
135 for (const auto& itVer: evt->vertices()) {
136 HepMC::FourVector newPos(itVer->position().x(),itVer->position().y(),itVer->position().z(),itVer->position().t()+timeOffset);
137 itVer->set_position(newPos);
138 }
139 outputMcEventCollection->push_back(evt);
140#else
141 HepMC::GenEvent * evt = new HepMC::GenEvent(c_evt);
142 for (HepMC::GenEvent::vertex_iterator itVer=evt->vertices_begin(); itVer!=evt->vertices_end(); ++itVer) {
143 HepMC::FourVector newPos((*itVer)->position().x(),(*itVer)->position().y(),(*itVer)->position().z(),(*itVer)->position().t()+timeOffset);
144 (*itVer)->set_position(newPos);
145 }
146 outputMcEventCollection->push_back(evt);
147#endif
148 }
149 }
150 return StatusCode::SUCCESS;
151}
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
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; }

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

SG::WriteHandle<McEventCollection> NewMergeMcEventCollTool::m_outputMcEventCollection {}
private

Definition at line 57 of file NewMergeMcEventCollTool.h.

57{};

◆ m_pileUpType

Gaudi::Property<int> NewMergeMcEventCollTool::m_pileUpType {this, "PileUpType", -1, ""}
private

Definition at line 55 of file NewMergeMcEventCollTool.h.

55{this, "PileUpType", -1, ""}; // initialise to PileUpTimeEventIndex::PileUpType::Unknown

◆ m_pMergeSvc

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

Definition at line 51 of file NewMergeMcEventCollTool.h.

51{this, "PileUpMergeSvc", "PileUpMergeSvc", ""};

◆ m_truthCollInputKey

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

Definition at line 53 of file NewMergeMcEventCollTool.h.

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

◆ m_truthCollOutputKey

SG::WriteHandleKey<McEventCollection> NewMergeMcEventCollTool::m_truthCollOutputKey {this, "TruthCollOutputKey","TruthEvent",""}
private

Definition at line 59 of file NewMergeMcEventCollTool.h.

59{this, "TruthCollOutputKey","TruthEvent",""};

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