ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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. More...
 
virtual StatusCode mergeEvent (const EventContext &ctx) override final
 called at the end of the subevts loop. More...
 
virtual StatusCode processBunchXing (int, 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
 return false if not interested in certain xing times (in ns) implemented by default in PileUpToolBase as FirstXing<=bunchXing<=LastXing More...
 

Private Member Functions

StatusCode saveHeavyIonInfo (const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection)
 Common methods. More...
 
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 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

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

◆ 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  }
86  return StatusCode::SUCCESS;
87 }

◆ 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 
45  m_outputMcEventCollection = nullptr;
46  return StatusCode::SUCCESS;
47 }

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

◆ processAllSubEvents() [1/2]

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));
120  ATH_CHECK(this->processEvent(
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 }

◆ 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 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  }
65  ATH_CHECK(this->processEvent(
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 }

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

◆ 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(hinew);
145 #else
146  outputMcEventCollection->at(0)->set_heavy_ion(*(pMcEvtColl->at(0)->heavy_ion()));
147 #endif
148  }
149  return StatusCode::SUCCESS;
150 }

◆ 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_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_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_nBkgEventsReadSoFar

unsigned int SimpleMergeMcEventCollTool::m_nBkgEventsReadSoFar {0}
private

Definition at line 72 of file SimpleMergeMcEventCollTool.h.

◆ m_newevent

bool SimpleMergeMcEventCollTool::m_newevent {true}
private

Definition at line 68 of file SimpleMergeMcEventCollTool.h.

◆ m_nInputMcEventColls

unsigned int SimpleMergeMcEventCollTool::m_nInputMcEventColls {0}
private

Definition at line 70 of file SimpleMergeMcEventCollTool.h.

◆ m_onlySaveSignalTruth

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

Definition at line 66 of file SimpleMergeMcEventCollTool.h.

◆ m_outputMcEventCollection

McEventCollection* SimpleMergeMcEventCollTool::m_outputMcEventCollection {}
private

Definition at line 60 of file SimpleMergeMcEventCollTool.h.

◆ m_overrideEventNumbers

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

Definition at line 64 of file SimpleMergeMcEventCollTool.h.

◆ m_pMergeSvc

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

Definition at line 58 of file SimpleMergeMcEventCollTool.h.

◆ m_truthCollInputKey

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

Definition at line 62 of file SimpleMergeMcEventCollTool.h.

◆ m_truthCollOutputKey

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

Definition at line 59 of file SimpleMergeMcEventCollTool.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:
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
SimpleMergeMcEventCollTool::m_truthCollOutputKey
StringProperty m_truthCollOutputKey
Definition: SimpleMergeMcEventCollTool.h:59
SimpleMergeMcEventCollTool::m_nInputMcEventColls
unsigned int m_nInputMcEventColls
Definition: SimpleMergeMcEventCollTool.h:70
SimpleMergeMcEventCollTool::m_pMergeSvc
ServiceHandle< PileUpMergeSvc > m_pMergeSvc
Definition: SimpleMergeMcEventCollTool.h:58
PileUpToolBase::m_filterPassed
bool m_filterPassed
Definition: PileUpToolBase.h:60
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
HepMC::signal_process_id
int signal_process_id(const GenEvent &e)
Definition: GenEvent.h:513
LB_AnalMapSplitter.of
of
Definition: LB_AnalMapSplitter.py:48
SimpleMergeMcEventCollTool::m_onlySaveSignalTruth
BooleanProperty m_onlySaveSignalTruth
Definition: SimpleMergeMcEventCollTool.h:66
McEventCollection
McEventCollection
Definition: GeneratorObjectsTPCnv.cxx:60
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
PileUpToolBase::m_lastXing
Gaudi::Property< int > m_lastXing
Definition: PileUpToolBase.h:56
HepMC::Print::line
void line(std::ostream &os, const GenEvent &e)
Definition: GenEvent.h:554
SimpleMergeMcEventCollTool::saveHeavyIonInfo
StatusCode saveHeavyIonInfo(const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection)
Common methods.
Definition: SimpleMergeMcEventCollTool.cxx:136
HepMC::fillBarcodesAttribute
void fillBarcodesAttribute(GenEvent *)
Definition: GenEvent.h:504
SimpleMergeMcEventCollTool::m_outputMcEventCollection
McEventCollection * m_outputMcEventCollection
Definition: SimpleMergeMcEventCollTool.h:60
PileUpMergeSvc::TimedList::type
std::list< value_t > type
type of the collection of timed data object
Definition: PileUpMergeSvc.h:75
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
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
SimpleMergeMcEventCollTool::processEvent
StatusCode processEvent(const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection, const int currentBkgEventIndex, int bunchCrossingTime, int pileupType)
Definition: SimpleMergeMcEventCollTool.cxx:152
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
SimpleMergeMcEventCollTool::m_truthCollInputKey
StringProperty m_truthCollInputKey
Definition: SimpleMergeMcEventCollTool.h:62
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
SimpleMergeMcEventCollTool::m_nBkgEventsReadSoFar
unsigned int m_nBkgEventsReadSoFar
Definition: SimpleMergeMcEventCollTool.h:72
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
SG::WriteHandle< McEventCollection >
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
PileUpToolBase::m_firstXing
Gaudi::Property< int > m_firstXing
Definition: PileUpToolBase.h:54
SimpleMergeMcEventCollTool::printDetailsOfMergedMcEventCollection
void printDetailsOfMergedMcEventCollection(McEventCollection *outputMcEventCollection) const
Definition: SimpleMergeMcEventCollTool.cxx:189
SubEventIterator
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition: IPileUpTool.h:22
python.Constants.VERBOSE
int VERBOSE
Definition: Control/AthenaCommon/python/Constants.py:14
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
PileUpTimeEventIndex
a struct encapsulating the identifier of a pile-up event
Definition: PileUpTimeEventIndex.h:12
SimpleMergeMcEventCollTool::m_overrideEventNumbers
BooleanProperty m_overrideEventNumbers
Definition: SimpleMergeMcEventCollTool.h:64
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
SimpleMergeMcEventCollTool::m_newevent
bool m_newevent
Definition: SimpleMergeMcEventCollTool.h:68
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.