ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
LArCalorimeter
LArDigitization
src
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
"
12
#include "
LArSimEvent/LArHitContainer.h
"
13
#include "
LArSimEvent/LArHit.h
"
14
#include "
LArSimEvent/LArIndexEnum.h
"
15
#include "
CaloIdentifier/LArID.h
"
16
#include "
Identifier/IdentifierHash.h
"
17
#include "GaudiKernel/MsgStream.h"
18
//#include "LArDigitization/LArHitEMap.h"
19
#include "
CaloIdentifier/CaloIdManager.h
"
20
21
LArHitMerger::LArHitMerger
(
const
std::string& name, ISvcLocator* pSvcLocator)
22
:
AthAlgorithm
(name, pSvcLocator)
23
{
24
}
25
26
27
StatusCode
LArHitMerger::initialize
()
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
{
44
m_HitContainer
.push_back(
m_EmBarrelHitContainerName
);
45
m_CaloType
.push_back(
LArIndex::EMBARREL_INDEX
);
46
m_SubDetFlag
[
LArIndex::EMBARREL_INDEX
] =
true
;
47
48
m_HitContainer
.push_back(
m_EmEndCapHitContainerName
);
49
m_CaloType
.push_back(
LArIndex::EMENDCAP_INDEX
);
50
m_SubDetFlag
[
LArIndex::EMENDCAP_INDEX
] =
true
;
51
52
m_HitContainer
.push_back(
m_HecHitContainerName
);
53
m_CaloType
.push_back(
LArIndex::HADENDCAP_INDEX
);
54
m_SubDetFlag
[
LArIndex::HADENDCAP_INDEX
] =
true
;
55
56
m_HitContainer
.push_back(
m_ForWardHitContainerName
);
57
m_CaloType
.push_back(
LArIndex::FORWARD_INDEX
);
58
m_SubDetFlag
[
LArIndex::FORWARD_INDEX
] =
true
;
59
}
60
else
if
(
m_SubDetectors
==
"LAr_Em"
)
61
{
62
m_HitContainer
.push_back(
m_EmBarrelHitContainerName
);
63
m_CaloType
.push_back(
LArIndex::EMBARREL_INDEX
);
64
m_SubDetFlag
[
LArIndex::EMBARREL_INDEX
] =
true
;
65
66
m_HitContainer
.push_back(
m_EmEndCapHitContainerName
);
67
m_CaloType
.push_back(
LArIndex::EMENDCAP_INDEX
);
68
m_SubDetFlag
[
LArIndex::EMENDCAP_INDEX
] =
true
;
69
}
70
else
if
(
m_SubDetectors
==
"LAr_EmBarrel"
)
71
{
72
m_HitContainer
.push_back(
m_EmBarrelHitContainerName
);
73
m_CaloType
.push_back(
LArIndex::EMBARREL_INDEX
);
74
m_SubDetFlag
[
LArIndex::EMBARREL_INDEX
] =
true
;
75
}
76
else
if
(
m_SubDetectors
==
"LAr_EmEndCap"
)
77
{
78
m_HitContainer
.push_back(
m_EmEndCapHitContainerName
);
79
m_CaloType
.push_back(
LArIndex::EMBARREL_INDEX
);
80
m_SubDetFlag
[
LArIndex::EMENDCAP_INDEX
] =
true
;
81
}
82
else
if
(
m_SubDetectors
==
"LAr_HEC"
)
83
{
84
m_HitContainer
.push_back(
m_HecHitContainerName
);
85
m_CaloType
.push_back(
LArIndex::HADENDCAP_INDEX
);
86
m_SubDetFlag
[
LArIndex::HADENDCAP_INDEX
] =
true
;
87
}
88
else
if
(
m_SubDetectors
==
"LAr_Fcal"
)
89
{
90
m_HitContainer
.push_back(
m_ForWardHitContainerName
);
91
m_CaloType
.push_back(
LArIndex::FORWARD_INDEX
);
92
m_SubDetFlag
[
LArIndex::FORWARD_INDEX
] =
true
;
93
}
94
else
if
(
m_SubDetectors
==
"LAr_EndCap"
)
95
{
96
m_HitContainer
.push_back(
m_EmEndCapHitContainerName
);
97
m_CaloType
.push_back(
LArIndex::EMBARREL_INDEX
);
98
m_SubDetFlag
[
LArIndex::EMENDCAP_INDEX
] =
true
;
99
100
m_HitContainer
.push_back(
m_HecHitContainerName
);
101
m_CaloType
.push_back(
LArIndex::HADENDCAP_INDEX
);
102
m_SubDetFlag
[
LArIndex::HADENDCAP_INDEX
] =
true
;
103
104
m_HitContainer
.push_back(
m_ForWardHitContainerName
);
105
m_CaloType
.push_back(
LArIndex::FORWARD_INDEX
);
106
m_SubDetFlag
[
LArIndex::FORWARD_INDEX
] =
true
;
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
138
StatusCode
LArHitMerger::execute
(
const
EventContext&
/*ctx*/
)
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
151
if
(
m_SubDetFlag
[
LArIndex::EMBARREL_INDEX
] ||
m_SubDetFlag
[
LArIndex::EMENDCAP_INDEX
] )
152
eCells_EM.resize(ncells_em,0.);
153
if
(
m_SubDetFlag
[
LArIndex::HADENDCAP_INDEX
] )
154
eCells_HEC.resize(ncells_hec,0.);
155
if
(
m_SubDetFlag
[
LArIndex::FORWARD_INDEX
] )
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
168
if
(
m_SubDetFlag
[
LArIndex::EMBARREL_INDEX
]) {
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
}
176
if
(
m_SubDetFlag
[
LArIndex::EMENDCAP_INDEX
]) {
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
185
if
(
m_SubDetFlag
[
LArIndex::HADENDCAP_INDEX
]) {
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
}
193
if
(
m_SubDetFlag
[
LArIndex::FORWARD_INDEX
]) {
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
282
if
(
m_SubDetFlag
[
LArIndex::EMBARREL_INDEX
] ||
m_SubDetFlag
[
LArIndex::EMENDCAP_INDEX
]) {
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
306
if
(
m_SubDetFlag
[
LArIndex::HADENDCAP_INDEX
]) {
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
322
if
(
m_SubDetFlag
[
LArIndex::FORWARD_INDEX
]) {
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
378
StatusCode
LArHitMerger::finalize
()
379
{
380
//
381
ATH_MSG_DEBUG
(
" LArHitMerger finalize completed successfully"
);
382
383
//
384
return
StatusCode::SUCCESS;
385
386
}
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x,...)
Definition
AthMsgStreamMacros.h:43
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
CaloIdManager.h
IdentifierHash.h
hit
bool hit(const Container &ids, int pdgId)
Definition
JetIRCSafeLabelTool.cxx:64
LArHitContainer.h
LArHitMerger.h
LArHit.h
LArID.h
LArIndexEnum.h
HADENDCAP_INDEX
@ HADENDCAP_INDEX
Definition
LArIndexEnum.h:10
EMBARREL_INDEX
@ EMBARREL_INDEX
Definition
LArIndexEnum.h:8
FORWARD_INDEX
@ FORWARD_INDEX
Definition
LArIndexEnum.h:11
NUMDET
@ NUMDET
Definition
LArIndexEnum.h:12
EMENDCAP_INDEX
@ EMENDCAP_INDEX
Definition
LArIndexEnum.h:9
sc
static Double_t sc
Definition
LArPhysWaveHECTool.cxx:37
LArHitContainer
LArHitContainer
Definition
LArSimEventTPCnv.cxx:28
AthAlgorithm::AthAlgorithm
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
Definition
AthAlgorithm.cxx:10
AthCommonAlgorithm< Gaudi::Algorithm >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
Definition
AthCommonDataStore.h:85
AthCommonAlgorithm< Gaudi::Algorithm >::detStore
const ServiceHandle< StoreGateSvc > & detStore() const
Definition
AthCommonDataStore.h:95
AthenaHitsVector::end
const_iterator end() const
Definition
AthenaHitsVector.h:191
AthenaHitsVector::begin
const_iterator begin() const
Definition
AthenaHitsVector.h:187
AthenaHitsVector< LArHit >::const_iterator
boost::transform_iterator< make_const, typename CONT::const_iterator > const_iterator
Definition
AthenaHitsVector.h:105
AthenaHitsVector::push_back
void push_back(T *t)
Definition
AthenaHitsVector.h:201
CaloIdManager
This class initializes the Calo (LAr and Tile) offline identifiers.
Definition
CaloIdManager.h:45
CaloIdManager::getHEC_ID
const LArHEC_ID * getHEC_ID(void) const
Definition
CaloIdManager.cxx:95
CaloIdManager::getFCAL_ID
const LArFCAL_ID * getFCAL_ID(void) const
Definition
CaloIdManager.cxx:85
CaloIdManager::getEM_ID
const LArEM_ID * getEM_ID(void) const
Definition
CaloIdManager.cxx:80
IdentifierHash
This is a "hash" representation of an Identifier.
Definition
IdentifierHash.h:25
LArHitContainer
Hit collection.
Definition
LArHitContainer.h:26
LArHitMerger::initialize
virtual StatusCode initialize()
Definition
LArHitMerger.cxx:27
LArHitMerger::m_HitContainer
std::vector< std::string > m_HitContainer
Definition
LArHitMerger.h:36
LArHitMerger::m_ForWardHitContainerName
StringProperty m_ForWardHitContainerName
Definition
LArHitMerger.h:43
LArHitMerger::finalize
virtual StatusCode finalize()
Definition
LArHitMerger.cxx:378
LArHitMerger::m_EmEndCapHitContainerName
StringProperty m_EmEndCapHitContainerName
Definition
LArHitMerger.h:41
LArHitMerger::m_EmBarrelHitContainerName
StringProperty m_EmBarrelHitContainerName
Definition
LArHitMerger.h:40
LArHitMerger::m_larem_id
const LArEM_ID * m_larem_id
Definition
LArHitMerger.h:45
LArHitMerger::m_SubDetFlag
std::vector< bool > m_SubDetFlag
Definition
LArHitMerger.h:35
LArHitMerger::m_larfcal_id
const LArFCAL_ID * m_larfcal_id
Definition
LArHitMerger.h:47
LArHitMerger::m_HecHitContainerName
StringProperty m_HecHitContainerName
Definition
LArHitMerger.h:42
LArHitMerger::m_SubDetectors
StringProperty m_SubDetectors
Definition
LArHitMerger.h:39
LArHitMerger::m_mergeSvc
ServiceHandle< PileUpMergeSvc > m_mergeSvc
Definition
LArHitMerger.h:33
LArHitMerger::execute
virtual StatusCode execute(const EventContext &ctx)
Execute method.
Definition
LArHitMerger.cxx:138
LArHitMerger::LArHitMerger
LArHitMerger(const std::string &name, ISvcLocator *pSvcLocator)
Definition
LArHitMerger.cxx:21
LArHitMerger::m_larhec_id
const LArHEC_ID * m_larhec_id
Definition
LArHitMerger.h:46
LArHitMerger::m_CaloType
std::vector< int > m_CaloType
Definition
LArHitMerger.h:37
LArHit
Class to store hit energy and time in LAr cell from G4 simulation.
Definition
LArHit.h:25
Identifier
Definition
IdentifierFieldParser.cxx:14
PileUpMergeSvc::TimedList::type
std::list< value_t > type
type of the collection of timed data object
Definition
PileUpMergeSvc.h:73
Generated on
for ATLAS Offline Software by
1.17.0