ATLAS Offline Software
Loading...
Searching...
No Matches
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"
17#include "GaudiKernel/MsgStream.h"
18//#include "LArDigitization/LArHitEMap.h"
20
21LArHitMerger::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
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) {
289 if ( m_SubDetFlag[LArIndex::EMBARREL_INDEX] && m_larem_id->is_em_barrel(cellId) ) {
290 LArHit* hit = new LArHit(cellId,energy,time);
291 hit->finalize();
292 larhit_emb->push_back(hit);
293 nhit++;
294 }
295 if ( m_SubDetFlag[LArIndex::EMENDCAP_INDEX] && m_larem_id->is_em_endcap(cellId) ) {
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
@ HADENDCAP_INDEX
@ EMBARREL_INDEX
Definition LArIndexEnum.h:8
@ FORWARD_INDEX
@ NUMDET
@ EMENDCAP_INDEX
Definition LArIndexEnum.h:9
static Double_t sc
LArHitContainer
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
const ServiceHandle< StoreGateSvc > & detStore() const
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
const_iterator end() const
const_iterator begin() const
This class initializes the Calo (LAr and Tile) offline identifiers.
const LArHEC_ID * getHEC_ID(void) const
const LArFCAL_ID * getFCAL_ID(void) const
const LArEM_ID * getEM_ID(void) const
This is a "hash" representation of an Identifier.
Hit collection.
virtual StatusCode initialize()
std::vector< std::string > m_HitContainer
StringProperty m_ForWardHitContainerName
virtual StatusCode finalize()
StringProperty m_EmEndCapHitContainerName
StringProperty m_EmBarrelHitContainerName
const LArEM_ID * m_larem_id
std::vector< bool > m_SubDetFlag
const LArFCAL_ID * m_larfcal_id
StringProperty m_HecHitContainerName
StringProperty m_SubDetectors
ServiceHandle< PileUpMergeSvc > m_mergeSvc
LArHitMerger(const std::string &name, ISvcLocator *pSvcLocator)
const LArHEC_ID * m_larhec_id
std::vector< int > m_CaloType
virtual StatusCode execute()
Class to store hit energy and time in LAr cell from G4 simulation.
Definition LArHit.h:25
void finalize()
The method to be called at the end of event by SD.
Definition LArHit.h:143
std::list< value_t > type
type of the collection of timed data object