ATLAS Offline Software
MergeCalibHitsTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "MergeCalibHitsTool.h"
6 
9 
11  const std::string& name,
12  const IInterface* parent) :
14 {
15 }
16 
18  ATH_MSG_VERBOSE ( "initialize()" );
19 
20  ATH_CHECK(m_pMergeSvc.retrieve());
21 
22  // list of CaloCalibrationHit containers
23  if(m_oldFormat) {
24  m_CalibrationHitContainer.reserve(5);
25  m_CalibrationHitContainer.push_back("LArCalibrationHitActive");
26  m_CalibrationHitContainer.push_back("LArCalibrationHitDeadMaterial");
27  m_CalibrationHitContainer.push_back("LArCalibrationHitInactive");
28  m_CalibrationHitContainer.push_back("TileCalibrationCellHitCnt");
29  m_CalibrationHitContainer.push_back("TileCalibrationDMHitCnt");
30  }
31  else {
32  m_CalibrationHitContainer.reserve(6);
33  m_CalibrationHitContainer.push_back("LArCalibrationHitActive");
34  m_CalibrationHitContainer.push_back("LArCalibrationHitDeadMaterial");
35  m_CalibrationHitContainer.push_back("LArCalibrationHitInactive");
36  m_CalibrationHitContainer.push_back("TileCalibHitActiveCell");
37  m_CalibrationHitContainer.push_back("TileCalibHitInactiveCell");
38  m_CalibrationHitContainer.push_back("TileCalibHitDeadMaterial");
39  }
41  return StatusCode::SUCCESS;
42 }
43 
44 
45 StatusCode MergeCalibHitsTool::prepareEvent(const EventContext& /*ctx*/,unsigned int nInputEvents) {
46  ATH_MSG_VERBOSE ( "Calling prepareEvent()" );
47  ATH_MSG_VERBOSE( "prepareEvent: there are " << nInputEvents << " subevents in this event.");
48  m_firstSubEvent = true;
49  //clean up pointers from the last event
50  m_outputContainers.clear();
51  for (unsigned int iHitContainer=0;iHitContainer<m_CalibrationHitContainer.size(); ++iHitContainer) {
52  m_outputContainers.push_back(NULL);
53  }
54  return StatusCode::SUCCESS;
55 }
56 
58  SubEventIterator bSubEvents,
59  SubEventIterator eSubEvents)
60 {
61  SubEventIterator iEvt(bSubEvents);
62  while (iEvt != eSubEvents) {
63  // MergeCalibHitsTool should only write out the hits from the signal event.
64  if(!m_firstSubEvent) {
65  ATH_MSG_VERBOSE ( " Have already seen a SubEvent marked as Signal! Don't need to look at any others! " );
66  break;
67  }
68 
69  if( iEvt->type()==xAOD::EventInfo_v1::PileUpType::Signal ) {
70  ATH_MSG_DEBUG ( " Found the Signal event! " );
71  }
72  else {
73  // this is not the signal event, so we should skip it.
74  ++iEvt;
75  continue;
76  }
77 
78  // loop over containers
79  for (unsigned int iHitContainer=0;iHitContainer<m_CalibrationHitContainer.size();++iHitContainer) {
80  ATH_MSG_VERBOSE ( " Bunch Crossing: " <<bunchXing << ". Process CalibrationHit container " << m_CalibrationHitContainer[iHitContainer] );
81  const CaloCalibrationHitContainer* hitCont;
82  if (!m_pMergeSvc->retrieveSingleSubEvtData(m_CalibrationHitContainer[iHitContainer], hitCont,
83  bunchXing, iEvt).isSuccess()){
84  ATH_MSG_VERBOSE("CaloCalibrationHitContainer not found for event key " << m_CalibrationHitContainer[iHitContainer]);
85  continue;
86  }
87 
88  //if this is the first SubEvent for this Event then create the hitContainers;
89  if(m_firstSubEvent) {
91  }
92  // loop over this container, perform a deep brute-force copy
93  int nhit=0;
94  ATH_MSG_VERBOSE ( " Start loop over calibration hits of signal event " );
95  CaloCalibrationHitContainer::const_iterator calibhititer = hitCont->begin();
96  CaloCalibrationHitContainer::const_iterator calibhitend = hitCont->end();
97  while(calibhititer != calibhitend) {
98  ++nhit;
99  m_outputContainers[iHitContainer]->push_back(new CaloCalibrationHit(**calibhititer));
100  ++calibhititer;
101  } // end of loop over calibration hits
102 
103  ATH_MSG_DEBUG ( " Number of hits found in this " << m_CalibrationHitContainer[iHitContainer]
104  << " container = " << nhit );
105  }
106  //we must have seen at least one event by now...
107  m_firstSubEvent = false;
108  ++iEvt;
109  }
110 
111  return StatusCode::SUCCESS;
112 }
113 StatusCode MergeCalibHitsTool::mergeEvent(const EventContext& /*ctx*/) {
114  for (unsigned int iHitContainer=0;iHitContainer<m_CalibrationHitContainer.size();++iHitContainer) {
115  if ( m_outputContainers[iHitContainer]==0 ) { continue; } //don't bother recording unused containers!
116  if (!(evtStore()->record(m_outputContainers[iHitContainer],m_CalibrationHitContainer[iHitContainer]).isSuccess())) {
117  ATH_MSG_ERROR ( " Cannot record new calibration hit in overlayed event " );
118  return StatusCode::FAILURE;
119  }
120  } // end of loop over the various types of calo calibration hits
121  return StatusCode::SUCCESS;
122 }
123 
125  ATH_MSG_VERBOSE ( "processAllSubEvents()" );
126 
127  // loop over containers
128  for (unsigned int iHitContainer=0;iHitContainer<m_CalibrationHitContainer.size();iHitContainer++) {
129 
130  ATH_MSG_DEBUG ( " Process CalibrationHit container " << m_CalibrationHitContainer[iHitContainer] );
131 
132  const CaloCalibrationHitContainer* hitCont;
133 
134  // if container not there from pileupservice, do nothing
135  if (!(m_pMergeSvc->retrieveOriginal(m_CalibrationHitContainer[iHitContainer]
136  ,hitCont).isSuccess()) || !hitCont) {
137  ATH_MSG_DEBUG ( " Cannot find calibrationHit from PileUp service " );
138  continue;
139  }
140 
141  // create new container for overlayed event
143 
144  // loop over this container, perform a deep brute-force copy
145  int nhit=0;
146  ATH_MSG_DEBUG ( " Start loop over calibration hits of signal event " );
147  for (const CaloCalibrationHit* hit : *hitCont) {
148  nhit++;
149  newContainer->push_back(new CaloCalibrationHit(*hit));
150  } // end of loop over calibration hits
151 
152  ATH_MSG_DEBUG ( " Number of hits found in this container " << nhit );
153 
154  // record new container in overlayed event
155  if (!(evtStore()->record(newContainer,m_CalibrationHitContainer[iHitContainer]).isSuccess())) {
156  ATH_MSG_ERROR ( " Cannot record new calibration hit in overlayed event " );
157  return StatusCode::FAILURE;
158  }
159 
160  } // end of loop over the various types of calo calibration hits
161 
162  return StatusCode::SUCCESS;
163 }
MergeCalibHitsTool::mergeEvent
virtual StatusCode mergeEvent(const EventContext &ctx) override final
called at the end of the subevts loop.
Definition: MergeCalibHitsTool.cxx:113
CaloCalibrationHitContainer
Definition: CaloCalibrationHitContainer.h:25
MergeCalibHitsTool.h
CaloCalibrationHit.h
MergeCalibHitsTool::m_pMergeSvc
ServiceHandle< PileUpMergeSvc > m_pMergeSvc
Definition: MergeCalibHitsTool.h:54
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
CaloCalibrationHitContainer
CaloCalibrationHitContainer
Definition: CaloSimEventTPCnv.cxx:17
CaloCalibrationHitContainer.h
AthenaHitsVector< CaloCalibrationHit >::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition: AthenaHitsVector.h:58
MergeCalibHitsTool::m_outputContainers
std::vector< CaloCalibrationHitContainer * > m_outputContainers
Definition: MergeCalibHitsTool.h:56
MergeCalibHitsTool::initialize
virtual StatusCode initialize() override final
called before the event loop
Definition: MergeCalibHitsTool.cxx:17
AthenaHitsVector::push_back
void push_back(T *t)
Definition: AthenaHitsVector.h:153
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
python.PileUpEventType.Signal
int Signal
Definition: PileUpEventType.py:3
MergeCalibHitsTool::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: MergeCalibHitsTool.cxx:124
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
MergeCalibHitsTool::m_firstSubEvent
bool m_firstSubEvent
Definition: MergeCalibHitsTool.h:55
PileUpToolBase
Definition: PileUpToolBase.h:18
CaloCalibrationHit
Class to store calorimeter calibration hit.
Definition: CaloCalibrationHit.h:23
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
MergeCalibHitsTool::MergeCalibHitsTool
MergeCalibHitsTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: MergeCalibHitsTool.cxx:10
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
MergeCalibHitsTool::m_oldFormat
Gaudi::Property< bool > m_oldFormat
Definition: MergeCalibHitsTool.h:53
SubEventIterator
std::vector< xAOD::EventInfo::SubEvent >::const_iterator SubEventIterator
Definition: IPileUpTool.h:22
AthenaHitsVector::end
const_iterator end() const
Definition: AthenaHitsVector.h:143
AthenaHitsVector::begin
const_iterator begin() const
Definition: AthenaHitsVector.h:139
MergeCalibHitsTool::prepareEvent
virtual StatusCode prepareEvent(const EventContext &ctx, unsigned int nInputEvents) override final
called before the subevts loop.
Definition: MergeCalibHitsTool.cxx:45
MergeCalibHitsTool::m_CalibrationHitContainer
std::vector< std::string > m_CalibrationHitContainer
Definition: MergeCalibHitsTool.h:57
MergeCalibHitsTool::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: MergeCalibHitsTool.cxx:57