ATLAS Offline Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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. 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
 Algorithm Approach. More...
 

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

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  :
12 {
13 }

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 
20  return StatusCode::SUCCESS;
21 }

◆ 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()" );
76  return StatusCode::SUCCESS;
77 }

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

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

◆ processAllSubEvents() [1/2]

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 }

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

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

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

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

Definition at line 57 of file NewMergeMcEventCollTool.h.

◆ m_pileUpType

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

Definition at line 55 of file NewMergeMcEventCollTool.h.

◆ m_pMergeSvc

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

Definition at line 51 of file NewMergeMcEventCollTool.h.

◆ m_truthCollInputKey

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

Definition at line 53 of file NewMergeMcEventCollTool.h.

◆ m_truthCollOutputKey

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

Definition at line 59 of file NewMergeMcEventCollTool.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
NewMergeMcEventCollTool::processEvent
StatusCode processEvent(const McEventCollection *pMcEvtColl, McEventCollection *outputMcEventCollection, int pileupType, long timeOffset=0)
Definition: NewMergeMcEventCollTool.cxx:115
NewMergeMcEventCollTool::m_outputMcEventCollection
SG::WriteHandle< McEventCollection > m_outputMcEventCollection
Definition: NewMergeMcEventCollTool.h:57
NewMergeMcEventCollTool::m_pMergeSvc
ServiceHandle< PileUpMergeSvc > m_pMergeSvc
Definition: NewMergeMcEventCollTool.h:51
NewMergeMcEventCollTool::m_truthCollInputKey
StringProperty m_truthCollInputKey
Definition: NewMergeMcEventCollTool.h:53
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:635
NewMergeMcEventCollTool::printDetailsOfMergedMcEventCollection
void printDetailsOfMergedMcEventCollection(McEventCollection *outputMcEventCollection) const
Definition: NewMergeMcEventCollTool.cxx:153
LArG4FSStartPointFilter.evt
evt
Definition: LArG4FSStartPointFilter.py:42
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:676
HepMC::fillBarcodesAttribute
void fillBarcodesAttribute(GenEvent *)
Definition: GenEvent.h:626
PileUpMergeSvc::TimedList::type
std::list< value_t > type
type of the collection of timed data object
Definition: PileUpMergeSvc.h:75
NewMergeMcEventCollTool::m_pileUpType
Gaudi::Property< int > m_pileUpType
Definition: NewMergeMcEventCollTool.h:55
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:125
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::WriteHandle::ptr
pointer_type ptr()
Dereference the pointer.
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
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
McEventCollection
This defines the McEventCollection, which is really just an ObjectVector of McEvent objects.
Definition: McEventCollection.h:33
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
SG::WriteHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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.
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 >
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
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
NewMergeMcEventCollTool::m_truthCollOutputKey
SG::WriteHandleKey< McEventCollection > m_truthCollOutputKey
Definition: NewMergeMcEventCollTool.h:59
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::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.