ATLAS Offline Software
Loading...
Searching...
No Matches
L1CaloPedestalGenerator.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7
8
10
11
12
13#include <vector>
14
15#include "CLHEP/Random/RandGaussZiggurat.h"
16
17#include "CLHEP/Random/Randomize.h"
18
19
20
21L1CaloPedestalGenerator::L1CaloPedestalGenerator(const std::string& name, ISvcLocator* pSvcLocator): AthAlgorithm(name, pSvcLocator), m_caloMgr(0), m_lvl1Helper(0), m_towerKey(0), m_IntTTContainer(0)
22
23{
24
25 declareProperty("TriggerTowerLocation", m_TTLocation = "LVL1TriggerTowers");
26
27 declareProperty("PedestalMean", m_pedMean = 10.);
28
29 declareProperty("PedestalRMS", m_pedRMS = 0.);
30
31 declareProperty("NSamples", m_nSamples = 5);
32
33}
34
35
36
42
43
44
45//-------------------------------------------
46
47// Initialize
48
49//-------------------------------------------
50
52
53{
54
55
56 ATH_MSG_INFO("From Initialize...");
57
58 StatusCode sc;
59
60
61
62 // Retrieve CaloIdManager
63
64 sc = detStore()->retrieve(m_caloMgr);
65
66 if (sc.isFailure()) {
67
68 ATH_MSG_ERROR( "Unable to retrieve CaloIdManager from DetectorStore" );
69
70 return StatusCode::FAILURE;
71
72 }
73
74
75
76 m_lvl1Helper = m_caloMgr->getLVL1_ID();
77
78 if (!m_lvl1Helper) {
79
80 ATH_MSG_ERROR( "Could not access CaloLVL1_ID helper" );
81
82 return StatusCode::FAILURE;
83
84 }
85
86
87
89
90
91
92 return StatusCode::SUCCESS;
93
94}
95
96
97
98//----------------------------------------
99
100// Execute
101
102//----------------------------------------
103
105
106{
107
108 ATH_MSG_DEBUG("From Execute...");
109
110
111
112 StatusCode sc;
113
114
115
116 m_IntTTContainer = new std::map<unsigned int, LVL1::InternalTriggerTower*>;
117
118
119
121
122 sc = evtStore()->record(VectorOfTTs, m_TTLocation);
123
124
125
126 if (sc.isSuccess()) ATH_MSG_DEBUG( "Stored TTs in TES at "<< m_TTLocation );
127
128 else {
129
130 ATH_MSG_ERROR( "failed to write TTs to TES at " << m_TTLocation );
131
132 return StatusCode::FAILURE;
133
134 }
135
136
137
138 //---
139
140 // Loop on all Trigger Towers to create the TT objects
141
142 // and store them into containers
143
144
145
146 std::vector<Identifier>::const_iterator tower_it = m_lvl1Helper->tower_begin();
147
148
149
150 // -- Loop on Trigger Tower offline Ids --
151
152 for(;tower_it!=m_lvl1Helper->tower_end();++tower_it) {
153
154 Identifier towerId = (*tower_it);
155
156
157
158 //---
159
160 // Check detector type
161
162 bool bIsTile = m_lvl1Helper->is_tile(towerId);
163
164 bool bIsHadronic = m_lvl1Helper->sampling(towerId); // check if tt is an HEC tt
165
166
167
168 //---
169
170 // Generate pedestal samples
171
172 std::vector<double> vnoise;
173
174 for(unsigned int sample=0;sample<m_nSamples;++sample) vnoise.push_back(CLHEP::RandGaussZiggurat::shoot(0.,m_pedRMS));
175
176
177
178 std::vector< std::vector<double> > vAutoCorrMatrix(m_nSamples, std::vector<double>(m_nSamples,0));
179
180 for(unsigned int sample=0;sample<m_nSamples;++sample) vAutoCorrMatrix[sample][sample] = 1;
181
182
183
184 std::vector<double> vsamples;
185
186 for(unsigned int sample=0;sample<m_nSamples;++sample) {
187
188 double noise = 0;
189
190 for(unsigned int jj=0;jj<m_nSamples;++jj) noise+= vAutoCorrMatrix[sample][jj]*vnoise[jj];
191
192 vsamples.push_back(m_pedMean + noise);
193
194 }
195
196
197
198 //---
199
200 // Seek for an existing or create a new InternalTriggerTower
201
203
204
205
206 if(bIsTile||bIsHadronic) TT->addHadAmps(vsamples);
207
208 else TT->addEMAmps(vsamples);
209
210
211
212 } //-- End Loop on Trigger Tower offline Ids --
213
214
215
216
217
218 //---
219
220 // Loop over Internal Trigger Tower and create fake TT with
221
222 // only the Digits parts filled
223
224
225
226 std::map<unsigned int, LVL1::InternalTriggerTower*>::const_iterator it = m_IntTTContainer->begin();
227
228 for(;it!=m_IntTTContainer->end();++it) {
229
230 double eta = it->second->eta();
231
232 double phi = it->second->phi();
233
234 unsigned int key = it->second->key();
235
236
237
238 std::vector<double> vEmAmps = it->second->EmAmps();
239
240 std::vector<int> emDigits(vEmAmps.size());
241 for (size_t i = 0; i < vEmAmps.size(); i++)
242 emDigits[i] = static_cast<int> (vEmAmps[i]);
243
244
245 std::vector<double> vHadAmps = it->second->HadAmps();
246
247 std::vector<int> hadDigits(vHadAmps.size());
248 for (size_t i = 0; i < vHadAmps.size(); i++)
249 hadDigits[i] = static_cast<int> (vHadAmps[i]);
250
251
252 //need to put some fake push back to be able to use TriggerTowers2Ntuple
253
254 // cause LVL1::TriggerTower::emEnergy() make a m_em_energy[m_em_peak];
255
256 // instead of using m_em_energy.at(m_em_peak);
257
258 std::vector<int> emEt; emEt.push_back(0);
259
260 std::vector<int> hadEt; hadEt.push_back(0);
261
262 std::vector<int> emBCID; emBCID.push_back(0);
263
264 std::vector<int> hadBCID; hadBCID.push_back(0);
265
266 std::vector<int> emExt; emExt.push_back(0);
267
268 std::vector<int> hadExt; hadExt.push_back(0);
269
270 int peak = 0;
271
272 int emADCPeak = 0;
273
274 int hadADCPeak = 0;
275
276
277
278 // Create TT
279
281
282 emDigits, emEt, emExt, emBCID, 0, peak, emADCPeak,
283
284 hadDigits, hadEt, hadExt, hadBCID, 0, peak, hadADCPeak);
285
286
287
288 VectorOfTTs->push_back(tower);
289
290
291
292 } //-- End Loop on InternalTriggerTowers --
293
294
295
296 ATH_MSG_DEBUG( VectorOfTTs->size()<<" TTs have been generated");
297
298
299
300 sc = evtStore()->setConst(VectorOfTTs);
301
302 if (sc.isSuccess()) ATH_MSG_DEBUG( "TT container locked");
303
304 else {
305
306 ATH_MSG_ERROR( "failed to lock TT container");
307
308 return StatusCode::FAILURE;
309
310 }
311
312
313
314 it = m_IntTTContainer->begin();
315
316 for(;it!=m_IntTTContainer->end();++it) delete it->second;
317
318 delete m_IntTTContainer;
319
320
321
322 ATH_MSG_DEBUG("End of Execute...");
323
324 return StatusCode::SUCCESS;
325
326}
327
328
329
330//-----------------------------------------
331
332// Finalize
333
334//-----------------------------------------
335
337
338{
339
340
341 delete m_towerKey;
342
343
344
345 return StatusCode::SUCCESS;
346
347}
348
349
350
352
353 // Create tower key from towerId
354
355 double tower_eta = IDeta(towerId,m_lvl1Helper);
356
357 double tower_phi = IDphi(towerId,m_lvl1Helper);
358
359 unsigned int key = m_towerKey->ttKey(tower_phi,tower_eta);
360
361 double tt_phi = m_towerKey->phi();
362
363 double tt_eta = m_towerKey->eta();
364
365
366
367 return findInternalTriggerTower(tt_phi, tt_eta, key, bCreate);
368
369}
370
371
372
373LVL1::InternalTriggerTower* L1CaloPedestalGenerator::findInternalTriggerTower(double tt_phi, double tt_eta, unsigned int key, bool bCreate) {
374
375 std::map<unsigned int, LVL1::InternalTriggerTower*>::iterator it = m_IntTTContainer->find( key );
376
378
379 if (it == m_IntTTContainer->end()){
380
381 if(bCreate) {
382
383 // no TT yet. Create it!
384
385 TT = new LVL1::InternalTriggerTower(tt_phi,tt_eta, key);
386
387 m_IntTTContainer->insert(std::map<unsigned int, LVL1::InternalTriggerTower*>::value_type(key,TT)); //and put it in the map.
388
389 }
390
391 }else{
392
393 TT = (it->second);
394
395 } // end else
396
397 return TT;
398
399}
400
401
402
404
405 int region = l1id->region(id);
406
407 int ieta = l1id->eta(id);
408
409 int sign = l1id->pos_neg_z(id);
410
411
412
413 double gran[4] = {0.1, 0.2, 0.1, 0.425};
414
415 double offset[4] = {0., 2.5, 3.1, 3.2};
416
417 double eta;
418
419
420
421 if (region>=0 && region<=3) {
422
423 eta = sign* ( ( (ieta+0.5) * gran[region] ) + offset[region] );
424
425 }
426
427 else {
428
429 eta = 0.;
430
431 }
432
433 return eta;
434
435}
436
437
438
440
441 Identifier regId = l1id->region_id(id);
442
443
444
445 double phiMax = l1id->phi_max(regId);
446
447 int iphi = l1id->phi(id);
448
449
450
451 double phi = (iphi+0.5)*2*M_PI/(phiMax+1);
452
453
454
455 return phi;
456
457}
458
459
460
#define M_PI
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
int sign(int a)
DataVector< LVL1::TriggerTower > TriggerTowerCollection
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
const ServiceHandle< StoreGateSvc > & detStore() const
Helper class for offline TT identifiers.
Definition CaloLVL1_ID.h:66
int phi_max(const Identifier regId) const
min value of phi index (-999 == failure)
Identifier region_id(int pos_neg_z, int sampling, int region) const
build a region (of towers) identifier
int region(const Identifier id) const
return region according to :
int pos_neg_z(const Identifier id) const
return pos_neg_z according to :
int eta(const Identifier id) const
return eta according to :
int phi(const Identifier id) const
return phi according to :
value_type push_back(value_type pElem)
Add an element to the end of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
double IDeta(const Identifier &id, const CaloLVL1_ID *l1id)
double IDphi(const Identifier &id, const CaloLVL1_ID *l1id)
L1CaloPedestalGenerator(const std::string &name, ISvcLocator *pSvcLocator)
LVL1::TriggerTowerKey * m_towerKey
LVL1::InternalTriggerTower * findInternalTriggerTower(const Identifier &towerId, bool bCreate=true)
std::map< unsigned int, LVL1::InternalTriggerTower * > * m_IntTTContainer
const CaloIdManager * m_caloMgr
A version of the TriggerTower that contains information that would not be availiable during datatakin...
The TriggerTowerKey object provides the key for each trigger tower depending on its eta-phi coords.
Trigger towers are the inputs to all other parts of the calorimeter trigger.