ATLAS Offline Software
MergeGenericMuonSimHitCollTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 
10  const std::string& name,
11  const IInterface* parent) :
13  m_pMergeSvc("PileUpMergeSvc", name),
14  m_firstSubEvent(true)
15 {
16  declareProperty("SimHitContainerNames", m_SimHitContainerNamesProp);
17 }
18 
20  ATH_MSG_VERBOSE ( "initialize()" );
21  // list of CaloCalibrationHit containers
22  if (m_SimHitContainerNamesProp.value().empty()) {
23  m_SimHitContainerNames.reserve(2);
24  m_SimHitContainerNames.push_back("MM_Hits");
25  m_SimHitContainerNames.push_back("sTGC_Hits");
26  }
27  else {
29  }
31  return StatusCode::SUCCESS;
32 }
33 
34 StatusCode MergeGenericMuonSimHitCollTool::prepareEvent(const EventContext& /*ctx*/, unsigned int nInputEvents) {
35  ATH_MSG_DEBUG ( "Calling prepareEvent()" );
36  ATH_MSG_DEBUG( "prepareEvent: there are " << nInputEvents << " subevents in this event.");
37  m_firstSubEvent = true;
38  //clean up pointers from the last event
39  m_outputContainers.clear();
40  for (unsigned int iHitContainer=0;iHitContainer<m_SimHitContainerNames.size(); ++iHitContainer) {
41  m_outputContainers.push_back(NULL);
42  }
43  return StatusCode::SUCCESS;
44 }
46  SubEventIterator bSubEvents,
47  SubEventIterator eSubEvents)
48 {
49  StatusCode sc(StatusCode::SUCCESS);
50  //if this is the first SubEvent for this Event then create the hitContainers;
51  ATH_MSG_VERBOSE ( "processBunchXing()" );
52  SubEventIterator iEvt(bSubEvents);
53  while (iEvt != eSubEvents) {
54  // loop over containers
55  for (unsigned int iHitContainer=0;iHitContainer<m_SimHitContainerNames.size();++iHitContainer) {
56  ATH_MSG_VERBOSE ( " Bunch Crossing: " <<bunchXing << ". Process GenericMuonSimHitCollection " << m_SimHitContainerNames[iHitContainer] );
57  const GenericMuonSimHitCollection* hitCont = nullptr;
58  if (!m_pMergeSvc->retrieveSingleSubEvtData(m_SimHitContainerNames[iHitContainer], hitCont,
59  bunchXing, iEvt).isSuccess()){
60  ATH_MSG_ERROR("GenericMuonSimHitCollection not found for event key " << m_SimHitContainerNames[iHitContainer]);
61  return StatusCode::FAILURE;
62  }
63 
64  //if this is the first SubEvent for this Event then create the hitContainers;
65  if(m_firstSubEvent) {
66  m_outputContainers[iHitContainer] = new GenericMuonSimHitCollection(m_SimHitContainerNames[iHitContainer]);
67  }
68  const double timeOfBCID(static_cast<double>(iEvt->time()));
69  this->processGenericMuonSimHitColl(hitCont, m_outputContainers[iHitContainer], timeOfBCID);
70  }
71  ++iEvt;
72  m_firstSubEvent=false;
73  }
74  return sc;
75 }
76 
78  for (unsigned int iHitContainer=0;iHitContainer<m_SimHitContainerNames.size();++iHitContainer) {
79  if ( m_outputContainers[iHitContainer]==0 ) { continue; } //don't bother recording unused containers!
80  if (!(evtStore()->record(m_outputContainers[iHitContainer],m_SimHitContainerNames[iHitContainer]).isSuccess())) {
81  ATH_MSG_ERROR ( " Cannot record new GenericMuonSimHitCollection in overlayed event " );
82  return StatusCode::FAILURE;
83  }
84  } // end of loop over the various types of calo calibration hits
85  return StatusCode::SUCCESS;
86 }
87 
89 {
90  ATH_MSG_VERBOSE ( "processAllSubEvents()" );
91  if(!m_pMergeSvc) {
92  if (!(m_pMergeSvc.retrieve()).isSuccess()) {
93  ATH_MSG_FATAL ( "processAllSubEvents: Could not find PileUpMergeSvc" );
94  return StatusCode::FAILURE;
95  }
96  }
97 
98  // loop over containers
99  for (unsigned int iHitContainer=0;iHitContainer<m_SimHitContainerNames.size();iHitContainer++) {
100 
101  ATH_MSG_DEBUG(" Process CalibrationHit container " << m_SimHitContainerNames[iHitContainer]);
103  SimHitList simHitList;
104  if ( (m_pMergeSvc->retrieveSubEvtsData(m_SimHitContainerNames[iHitContainer], simHitList)).isSuccess() ) {
106  if (!simHitList.empty()) {
107  //now merge all collections into one
108  SimHitList::const_iterator simHitColl_iter(simHitList.begin());
109  const SimHitList::const_iterator endOfSimHitColls(simHitList.end());
110  while (simHitColl_iter!=endOfSimHitColls) {
111  const double timeOfBCID(static_cast<double>((simHitColl_iter)->first.time()));
112  this->processGenericMuonSimHitColl(&(*((simHitColl_iter)->second)), m_outputContainers[iHitContainer], timeOfBCID);
113  }
114  }
115  // record new container in overlayed event
116  if (!(evtStore()->record(newContainer,m_SimHitContainerNames[iHitContainer]).isSuccess())) {
117  ATH_MSG_ERROR(" Cannot record new GenericMuonSimHitCollection in overlayed event ");
118  delete newContainer;
119  return StatusCode::FAILURE;
120  }
121  }
122  } // end of loop over the various types of calo calibration hits
123  return StatusCode::SUCCESS;
124 }
125 
127 {
128  for (GenericMuonSimHitCollection::const_iterator simhitIter = inputCollection->begin(); simhitIter != inputCollection->end(); ++simhitIter) {
129  const int idHit = simhitIter->GenericId();
130  outputCollection->Emplace(idHit, simhitIter->globalTime()+timeOfBCID, simhitIter->globalpreTime()+timeOfBCID, simhitIter->globalPosition(), simhitIter->localPosition(), simhitIter->globalPrePosition(),simhitIter->localPrePosition(), simhitIter->particleEncoding(),simhitIter->kineticEnergy(), simhitIter->globalDirection(),simhitIter->depositEnergy(), simhitIter->StepLength(),simhitIter->truthBarcode() );
131  }
132  return;
133 }
MergeGenericMuonSimHitCollTool::processAllSubEvents
virtual StatusCode processAllSubEvents(const EventContext &ctx) override final
return false if not interested in certain xing times (in ns) implemented by default in PileUpToolBase...
Definition: MergeGenericMuonSimHitCollTool.cxx:88
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
MergeGenericMuonSimHitCollTool::initialize
virtual StatusCode initialize() override final
called before the event loop
Definition: MergeGenericMuonSimHitCollTool.cxx:19
MergeGenericMuonSimHitCollTool::m_outputContainers
std::vector< GenericMuonSimHitCollection * > m_outputContainers
Definition: MergeGenericMuonSimHitCollTool.h:53
MergeGenericMuonSimHitCollTool::MergeGenericMuonSimHitCollTool
MergeGenericMuonSimHitCollTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MergeGenericMuonSimHitCollTool.cxx:9
MergeGenericMuonSimHitCollTool::m_SimHitContainerNamesProp
StringArrayProperty m_SimHitContainerNamesProp
Definition: MergeGenericMuonSimHitCollTool.h:54
GenericMuonSimHitCollection
AtlasHitsVector< GenericMuonSimHit > GenericMuonSimHitCollection
Definition: GenericMuonSimHitCollection.h:15
AtlasHitsVector
Definition: AtlasHitsVector.h:33
MergeGenericMuonSimHitCollTool::mergeEvent
virtual StatusCode mergeEvent(const EventContext &ctx) override final
called at the end of the subevts loop.
Definition: MergeGenericMuonSimHitCollTool.cxx:77
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
SimHitList
std::vector< std::pair< double, SimHitHandleBase * > > SimHitList
Definition: SimHitHandleBase.h:76
AtlasHitsVector::begin
const_iterator begin() const
Definition: AtlasHitsVector.h:131
AtlasHitsVector::const_iterator
CONT::const_iterator const_iterator
Definition: AtlasHitsVector.h:43
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
PileUpMergeSvc::TimedList::type
std::list< value_t > type
type of the collection of timed data object
Definition: PileUpMergeSvc.h:75
MergeGenericMuonSimHitCollTool::processGenericMuonSimHitColl
virtual void processGenericMuonSimHitColl(const GenericMuonSimHitCollection *inputCollection, GenericMuonSimHitCollection *outputCollection, const double &timeOfBCID)
share code between two approaches
Definition: MergeGenericMuonSimHitCollTool.cxx:126
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
MergeGenericMuonSimHitCollTool.h
PileUpToolBase
Definition: PileUpToolBase.h:18
postInclude.outputCollection
outputCollection
Definition: postInclude.SortInput.py:27
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
MergeGenericMuonSimHitCollTool::prepareEvent
virtual StatusCode prepareEvent(const EventContext &ctx, unsigned int nInputEvents) override final
called before the subevts loop.
Definition: MergeGenericMuonSimHitCollTool.cxx:34
PileUpMergeSvc.h
the preferred mechanism to access information from the different event stores in a pileup job.
AtlasHitsVector::end
const_iterator end() const
Definition: AtlasHitsVector.h:134
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:536
MergeGenericMuonSimHitCollTool::m_pMergeSvc
ServiceHandle< PileUpMergeSvc > m_pMergeSvc
Definition: MergeGenericMuonSimHitCollTool.h:51
MergeGenericMuonSimHitCollTool::m_SimHitContainerNames
std::vector< std::string > m_SimHitContainerNames
Definition: MergeGenericMuonSimHitCollTool.h:55
SubEventIterator
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition: IPileUpTool.h:22
MergeGenericMuonSimHitCollTool::processBunchXing
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
Definition: MergeGenericMuonSimHitCollTool.cxx:45
MergeGenericMuonSimHitCollTool::m_firstSubEvent
bool m_firstSubEvent
Definition: MergeGenericMuonSimHitCollTool.h:52