ATLAS Offline Software
LArHitMerger.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 //
6 // algorithm to merge LArHit from different subevents from pileup service to
7 // a single event, assuming all subevents are at the same time and neglecting the
8 // individual hit times
9 // This is aimed to run at first stage for very large luminosity pileup
10 
11 #include "LArHitMerger.h"
13 #include "LArSimEvent/LArHit.h"
15 #include "CaloIdentifier/LArID.h"
17 #include "GaudiKernel/MsgStream.h"
18 //#include "LArDigitization/LArHitEMap.h"
20 
21 LArHitMerger::LArHitMerger(const std::string& name, ISvcLocator* pSvcLocator)
22  : AthAlgorithm(name, pSvcLocator)
23 {
24 }
25 
26 
28 {
29 //
30 // ......... make the Sub-detector flag vector
31 //
32 
33  for (int i=0; i < LArIndex::NUMDET ; i++)
34  {
35  m_SubDetFlag.push_back(false);
36  }
37 
38 //
39 // ......... make the digit container name list
40 //
41 
42  if ( m_SubDetectors == "LAr_All" )
43  {
47 
51 
55 
59  }
60  else if ( m_SubDetectors == "LAr_Em" )
61  {
65 
69  }
70  else if ( m_SubDetectors == "LAr_EmBarrel" )
71  {
75  }
76  else if ( m_SubDetectors == "LAr_EmEndCap" )
77  {
81  }
82  else if ( m_SubDetectors == "LAr_HEC" )
83  {
87  }
88  else if ( m_SubDetectors == "LAr_Fcal" )
89  {
93  }
94  else if (m_SubDetectors == "LAr_EndCap")
95  {
99 
103 
107  }
108  else
109  {
110  ATH_MSG_ERROR("Invalid SubDetector propertie");
111  return(StatusCode::FAILURE);
112  }
113 
114 
115 //
116 // locate the PileUpMergeSvc and initialize our local ptr
117 //
118  ATH_CHECK(m_mergeSvc.retrieve());
119  ATH_MSG_DEBUG("PileUpMergeSvc successfully initialized");
120 
121 
122 
123  //retrieve ID helpers
124  const CaloIdManager* caloIdMgr = nullptr;
125  StatusCode sc = detStore()->retrieve(caloIdMgr);
126  if (sc.isFailure()) {
127  ATH_MSG_ERROR("Unable to retrieve CaloIdManager from DetectoreStore");
128  return StatusCode::FAILURE;
129  }
130  m_larem_id = caloIdMgr->getEM_ID();
131  m_larhec_id = caloIdMgr->getHEC_ID();
132  m_larfcal_id = caloIdMgr->getFCAL_ID();
133 
134  return StatusCode::SUCCESS;
135 
136 }
137 
139 {
140 
141  std::vector<double> eCells_EM;
142  std::vector<double> eCells_HEC;
143  std::vector<double> eCells_FCAL;
144 
145  unsigned int ncells_em = m_larem_id->channel_hash_max();
146  unsigned int ncells_hec = m_larhec_id->channel_hash_max();
147  unsigned int ncells_fcal = m_larfcal_id->channel_hash_max();
148 
149  ATH_MSG_INFO(" ncells " << ncells_em << " " << ncells_hec << " " << ncells_fcal);
150 
152  eCells_EM.resize(ncells_em,0.);
154  eCells_HEC.resize(ncells_hec,0.);
156  eCells_FCAL.resize(ncells_fcal,0.);
157 
158 //
159 // ....... create the new LAr Hit containers
160 //
161  LArHitContainer* larhit_emb=nullptr;
162  LArHitContainer* larhit_emec=nullptr;
163  LArHitContainer* larhit_hec=nullptr;
164  LArHitContainer* larhit_fcal=nullptr;
165 
166  StatusCode sc;
167 
169  larhit_emb = new LArHitContainer();
170  sc = evtStore()->record(larhit_emb,m_EmBarrelHitContainerName);
171  if (sc.isFailure()) {
172  ATH_MSG_ERROR(" cannot record LArHitEMB container ");
173  return sc;
174  }
175  }
177  larhit_emec = new LArHitContainer();
178  sc = evtStore()->record(larhit_emec,m_EmEndCapHitContainerName);
179  if (sc.isFailure()) {
180  ATH_MSG_ERROR(" cannot record LArHitEMEC container ");
181  return sc;
182  }
183  }
184 
186  larhit_hec = new LArHitContainer();
187  sc = evtStore()->record(larhit_hec,m_HecHitContainerName);
188  if (sc.isFailure()) {
189  ATH_MSG_ERROR("cannot record LArHitHEC container ");
190  return sc;
191  }
192  }
194  larhit_fcal = new LArHitContainer();
195  sc = evtStore()->record(larhit_fcal,m_ForWardHitContainerName);
196  if (sc.isFailure()) {
197  ATH_MSG_ERROR("cannot record LArHitEMEC container ");
198  return sc;
199  }
200  }
201 
202 //
203 // ............ loop over the wanted hit containers
204 //
205  int nhit_tot=0;
206 
207  for (unsigned int iHitContainer=0;iHitContainer<m_HitContainer.size();iHitContainer++)
208  {
209 
210  ATH_MSG_DEBUG(" asking for: " << m_HitContainer[iHitContainer]);
211 
212  int ical=0;
213  if (m_CaloType[iHitContainer] == LArIndex::EMBARREL_INDEX ||
214  m_CaloType[iHitContainer] == LArIndex::EMENDCAP_INDEX)
215  {
216  ical=1;
217  }
218  else if (m_CaloType[iHitContainer] == LArIndex::HADENDCAP_INDEX)
219  {
220  ical=2;
221  }
222  else if (m_CaloType[iHitContainer] == LArIndex::FORWARD_INDEX)
223  {
224  ical=3;
225  }
226  else
227  {
228  ATH_MSG_ERROR("unknown calo type ! " );
229  return StatusCode::FAILURE;
230  }
231 
232  typedef PileUpMergeSvc::TimedList<LArHitContainer>::type TimedHitContList;
233  TimedHitContList hitContList;
234 //
235 // retrieve list of pairs (time,container) from PileUp service
236 
237  if (!(m_mergeSvc->retrieveSubEvtsData(m_HitContainer[iHitContainer]
238  ,hitContList).isSuccess()) && hitContList.empty()) {
239  ATH_MSG_ERROR(" Could not fill TimedHitContList" );
240  return StatusCode::FAILURE;
241  }
242 
243 // loop over this list
244  TimedHitContList::iterator iFirstCont(hitContList.begin());
245  TimedHitContList::iterator iEndCont(hitContList.end());
246  while (iFirstCont != iEndCont) {
247 // get LArHitContainer for this subevent
248  const LArHitContainer& firstCont = *(iFirstCont->second);
249 // Loop over cells in this LArHitContainer
250  LArHitContainer::const_iterator f_cell=firstCont.begin();
251  LArHitContainer::const_iterator l_cell=firstCont.end();
252 
253  while (f_cell != l_cell) {
254  double energy = (*f_cell)->energy();
255  Identifier cellId = (*f_cell)->cellID();
256  ++f_cell;
257  nhit_tot++;
258  IdentifierHash idHash;
259  if (ical==1) {
260  idHash=m_larem_id->channel_hash(cellId);
261  if (idHash<ncells_em) eCells_EM[idHash] += energy;
262  }
263  else if(ical==2) {
264  idHash=m_larhec_id->channel_hash(cellId);
265  if (idHash<ncells_hec) eCells_HEC[idHash] += energy;
266  }
267  else if(ical==3) {
268  idHash=m_larfcal_id->channel_hash(cellId);
269  if (idHash<ncells_fcal) eCells_FCAL[idHash] += energy;
270  }
271  } // loop over hits
272  ++iFirstCont;
273  } // loop over subevent list
274 
275  } // .... end of loop over containers
276 
277  ATH_MSG_INFO(" total number of hits found " << nhit_tot);
278 
279 
280  double time=0.;
281 
283  int nhit=0;
284  for (unsigned int i=0;i<ncells_em;i++) {
285  IdentifierHash idHash = i;
286  Identifier cellId = m_larem_id->channel_id(idHash);
287  double energy = eCells_EM[i];
288  if (energy>1e-6) {
290  LArHit* hit = new LArHit(cellId,energy,time);
291  hit->finalize();
292  larhit_emb->push_back(hit);
293  nhit++;
294  }
296  LArHit* hit = new LArHit(cellId,energy,time);
297  hit->finalize();
298  larhit_emec->push_back(hit);
299  nhit++;
300  }
301  }
302  }
303  ATH_MSG_INFO(" Number of hits filled in LArHitEM containers " << nhit);
304  }
305 
307  int nhit=0;
308  for (unsigned int i=0;i<ncells_hec;i++) {
309  IdentifierHash idHash = i;
310  Identifier cellId = m_larhec_id->channel_id(idHash);
311  double energy = eCells_HEC[i];
312  if (energy>1e-6) {
313  LArHit* hit = new LArHit(cellId,energy,time);
314  hit->finalize();
315  larhit_hec->push_back(hit);
316  nhit++;
317  }
318  }
319  ATH_MSG_INFO(" Number of hits filled in LArHitHEC container " << nhit);
320  }
321 
323  int nhit=0;
324  for (unsigned int i=0;i<ncells_fcal;i++) {
325  IdentifierHash idHash = i;
326  Identifier cellId = m_larfcal_id->channel_id(idHash);
327  double energy = eCells_FCAL[i];
328  if (energy>1e-6) {
329  LArHit* hit = new LArHit(cellId,energy,time);
330  hit->finalize();
331  larhit_fcal->push_back(hit);
332  nhit++;
333  }
334  }
335  ATH_MSG_INFO(" Number of hits filled in LArHitFCAL container " << nhit);
336  }
337 
338 
339 
340  // lock container in StoreGate
341  if (larhit_emb) {
342  sc = evtStore()->setConst(larhit_emb);
343  if (sc.isFailure()) {
344  ATH_MSG_ERROR(" Cannot lock LArHitContainer ");
345  return(StatusCode::FAILURE);
346  }
347  }
348 
349  if (larhit_emec) {
350  sc = evtStore()->setConst(larhit_emec);
351  if (sc.isFailure()) {
352  ATH_MSG_ERROR(" Cannot lock LArHitContainer ");
353  return(StatusCode::FAILURE);
354  }
355  }
356 
357  if (larhit_hec) {
358  sc = evtStore()->setConst(larhit_hec);
359  if (sc.isFailure()) {
360  ATH_MSG_ERROR(" Cannot lock LArHitContainer ");
361  return(StatusCode::FAILURE);
362  }
363  }
364 
365  if (larhit_fcal) {
366  sc = evtStore()->setConst(larhit_fcal);
367  if (sc.isFailure()) {
368  ATH_MSG_ERROR(" Cannot lock LArHitContainer ");
369  return(StatusCode::FAILURE);
370  }
371  }
372 
373 
374  return StatusCode::SUCCESS;
375 
376 }
377 
379 {
380 //
381  ATH_MSG_DEBUG(" LArHitMerger finalize completed successfully");
382 
383 //
384  return StatusCode::SUCCESS;
385 
386 }
LArHitMerger::initialize
virtual StatusCode initialize()
Definition: LArHitMerger.cxx:27
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
EMENDCAP_INDEX
@ EMENDCAP_INDEX
Definition: LArIndexEnum.h:9
FORWARD_INDEX
@ FORWARD_INDEX
Definition: LArIndexEnum.h:11
CaloIDHelper::channel_hash_max
size_type channel_hash_max() const
One more than the largest channel (cell) hash code.
LArHitMerger::m_larem_id
const LArEM_ID * m_larem_id
Definition: LArHitMerger.h:45
LArHit::finalize
void finalize()
The method to be called at the end of event by SD.
Definition: LArHit.h:143
LArHitMerger::m_larhec_id
const LArHEC_ID * m_larhec_id
Definition: LArHitMerger.h:46
CaloIdManager::getEM_ID
const LArEM_ID * getEM_ID(void) const
Definition: CaloIdManager.cxx:80
LArHitMerger::m_SubDetectors
StringProperty m_SubDetectors
Definition: LArHitMerger.h:39
LArFCAL_Base_ID::channel_hash
IdentifierHash channel_hash(Identifier channelId) const
Convert a connected channel (cell) Identifier to a hash code.
LArHitContainer
Hit collection.
Definition: LArHitContainer.h:26
LArHitMerger::LArHitMerger
LArHitMerger(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArHitMerger.cxx:21
LArEM_Base_ID::channel_id
Identifier channel_id(const ExpandedIdentifier &exp_id) const
Build a cell identifier from an expanded identifier.
AthenaPoolTestRead.sc
sc
Definition: AthenaPoolTestRead.py:27
AthCommonDataStore< AthCommonMsg< Algorithm > >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:95
AthenaHitsVector< LArHit >::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition: AthenaHitsVector.h:58
PileUpMergeSvc::TimedList::type
std::list< value_t > type
type of the collection of timed data object
Definition: PileUpMergeSvc.h:75
NUMDET
@ NUMDET
Definition: LArIndexEnum.h:12
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
LArEM_Base_ID::channel_hash
IdentifierHash channel_hash(Identifier channelId) const
create hash id from channel id
CaloIdManager::getHEC_ID
const LArHEC_ID * getHEC_ID(void) const
Definition: CaloIdManager.cxx:95
AthenaHitsVector::push_back
void push_back(T *t)
Definition: AthenaHitsVector.h:153
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ParticleGun_FastCalo_ChargeFlip_Config.energy
energy
Definition: ParticleGun_FastCalo_ChargeFlip_Config.py:78
CaloIdManager
This class initializes the Calo (LAr and Tile) offline identifiers.
Definition: CaloIdManager.h:45
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
LArIndexEnum.h
LArFCAL_Base_ID::channel_id
Identifier channel_id(const ExpandedIdentifier &exp_id) const
cell identifier for a channel from ExpandedIdentifier
CaloIdManager::getFCAL_ID
const LArFCAL_ID * getFCAL_ID(void) const
Definition: CaloIdManager.cxx:85
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
LArHitMerger::m_larfcal_id
const LArFCAL_ID * m_larfcal_id
Definition: LArHitMerger.h:47
LArHEC_Base_ID::channel_hash
IdentifierHash channel_hash(Identifier channelId) const
create hash id from channel id
LArHitContainer
LArHitContainer
Definition: LArSimEventTPCnv.cxx:28
HADENDCAP_INDEX
@ HADENDCAP_INDEX
Definition: LArIndexEnum.h:10
AthAlgorithm
Definition: AthAlgorithm.h:47
LArHitMerger::m_mergeSvc
ServiceHandle< PileUpMergeSvc > m_mergeSvc
Definition: LArHitMerger.h:33
LArHitMerger.h
LArHitMerger::execute
virtual StatusCode execute()
Definition: LArHitMerger.cxx:138
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
IdentifierHash.h
LArHitMerger::m_EmEndCapHitContainerName
StringProperty m_EmEndCapHitContainerName
Definition: LArHitMerger.h:41
LArHEC_Base_ID::channel_id
Identifier channel_id(const ExpandedIdentifier &exp_id) const
channel identifier for a channel from ExpandedIdentifier
LArHit
Class to store hit energy and time in LAr cell from G4 simulation.
Definition: LArHit.h:25
LArHitMerger::finalize
virtual StatusCode finalize()
Definition: LArHitMerger.cxx:378
LArID.h
LArHit.h
LArHitMerger::m_SubDetFlag
std::vector< bool > m_SubDetFlag
Definition: LArHitMerger.h:35
LArHitMerger::m_ForWardHitContainerName
StringProperty m_ForWardHitContainerName
Definition: LArHitMerger.h:43
EMBARREL_INDEX
@ EMBARREL_INDEX
Definition: LArIndexEnum.h:8
LArHitMerger::m_HecHitContainerName
StringProperty m_HecHitContainerName
Definition: LArHitMerger.h:42
CaloSwCorrections.time
def time(flags, cells_name, *args, **kw)
Definition: CaloSwCorrections.py:242
LArEM_Base_ID::is_em_barrel
bool is_em_barrel(const Identifier id) const
test if the id belongs to the EM barrel
LArHitContainer.h
LArHitMerger::m_HitContainer
std::vector< std::string > m_HitContainer
Definition: LArHitMerger.h:36
CaloIdManager.h
AthenaHitsVector::end
const_iterator end() const
Definition: AthenaHitsVector.h:143
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
LArHitMerger::m_EmBarrelHitContainerName
StringProperty m_EmBarrelHitContainerName
Definition: LArHitMerger.h:40
AthenaHitsVector::begin
const_iterator begin() const
Definition: AthenaHitsVector.h:139
LArEM_Base_ID::is_em_endcap
bool is_em_endcap(const Identifier id) const
test if the id belongs to the EM Endcap
LArHitMerger::m_CaloType
std::vector< int > m_CaloType
Definition: LArHitMerger.h:37
Identifier
Definition: IdentifierFieldParser.cxx:14