ATLAS Offline Software
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 
21 L1CaloPedestalGenerator::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 
38 
39 {
40 
41 }
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 
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 
373 LVL1::InternalTriggerTower* L1CaloPedestalGenerator::findInternalTriggerTower(double tt_phi, double tt_eta, unsigned int key, bool bCreate) {
374 
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 
403 double L1CaloPedestalGenerator::IDeta(const Identifier& id, const CaloLVL1_ID* l1id) {
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 
439 double L1CaloPedestalGenerator::IDphi(const Identifier& id, const CaloLVL1_ID* l1id) {
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 
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
LVL1::KeyUtilities::phi
virtual double phi() const
returns phi coordinate of centre of relevant trigger tower.
Definition: KeyUtilities.cxx:159
phi
Scalar phi() const
phi method
Definition: AmgMatrixBasePlugin.h:67
L1CaloPedestalGenerator::L1CaloPedestalGenerator
L1CaloPedestalGenerator(const std::string &name, ISvcLocator *pSvcLocator)
Definition: L1CaloPedestalGenerator.cxx:21
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
L1CaloPedestalGenerator::m_IntTTContainer
std::map< unsigned int, LVL1::InternalTriggerTower * > * m_IntTTContainer
Definition: L1CaloPedestalGenerator.h:55
L1CaloPedestalGenerator::m_lvl1Helper
const CaloLVL1_ID * m_lvl1Helper
Definition: L1CaloPedestalGenerator.h:43
L1CaloPedestalGenerator::~L1CaloPedestalGenerator
virtual ~L1CaloPedestalGenerator()
Definition: L1CaloPedestalGenerator.cxx:37
eta
Scalar eta() const
pseudorapidity method
Definition: AmgMatrixBasePlugin.h:83
AthCommonDataStore< AthCommonMsg< Algorithm > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
CaloLVL1_ID::phi_max
int phi_max(const Identifier regId) const
min value of phi index (-999 == failure)
Definition: CaloLVL1_ID.cxx:495
skel.it
it
Definition: skel.GENtoEVGEN.py:396
L1CaloPedestalGenerator::findInternalTriggerTower
LVL1::InternalTriggerTower * findInternalTriggerTower(const Identifier &towerId, bool bCreate=true)
Definition: L1CaloPedestalGenerator.cxx:351
M_PI
#define M_PI
Definition: ActiveFraction.h:11
CaloLVL1_ID::region
int region(const Identifier id) const
return region according to :
Definition: CaloLVL1_ID.h:647
L1CaloPedestalGenerator::m_towerKey
LVL1::TriggerTowerKey * m_towerKey
Definition: L1CaloPedestalGenerator.h:53
CaloLVL1_ID::region_id
Identifier region_id(int pos_neg_z, int sampling, int region) const
build a region (of towers) identifier
Definition: CaloLVL1_ID.h:502
L1CaloPedestalGenerator::m_caloMgr
const CaloIdManager * m_caloMgr
Definition: L1CaloPedestalGenerator.h:40
L1CaloPedestalGenerator::IDphi
double IDphi(const Identifier &id, const CaloLVL1_ID *l1id)
Definition: L1CaloPedestalGenerator.cxx:439
CaloLVL1_ID::tower_end
id_iterator tower_end() const
end iterator over towers
Definition: CaloLVL1_ID.h:603
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
LVL1::KeyUtilities::eta
virtual double eta() const
returns the centre of the TT at eta_coord:
Definition: KeyUtilities.cxx:150
CaloLVL1_ID::phi
int phi(const Identifier id) const
return phi according to :
Definition: CaloLVL1_ID.h:659
AthCommonDataStore< AthCommonMsg< Algorithm > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
FullCPAlgorithmsTest_eljob.sample
sample
Definition: FullCPAlgorithmsTest_eljob.py:116
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
L1CaloPedestalGenerator::m_pedMean
double m_pedMean
Definition: L1CaloPedestalGenerator.h:48
sign
int sign(int a)
Definition: TRT_StrawNeighbourSvc.h:107
CaloIdManager::getLVL1_ID
const CaloLVL1_ID * getLVL1_ID(void) const
Definition: CaloIdManager.cxx:75
L1CaloPedestalGenerator::m_TTLocation
std::string m_TTLocation
Definition: L1CaloPedestalGenerator.h:46
DataVector< LVL1::TriggerTower >
L1CaloPedestalGenerator::m_pedRMS
double m_pedRMS
Definition: L1CaloPedestalGenerator.h:49
AthAlgorithm
Definition: AthAlgorithm.h:47
LVL1::InternalTriggerTower
A version of the TriggerTower that contains information that would not be availiable during datatakin...
Definition: InternalTriggerTower.h:31
LVL1::TriggerTower
Trigger towers are the inputs to all other parts of the calorimeter trigger.
Definition: Trigger/TrigT1/TrigT1CaloEvent/TrigT1CaloEvent/TriggerTower.h:45
CaloLVL1_ID
Helper class for offline TT identifiers.
Definition: CaloLVL1_ID.h:66
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
CaloLVL1_ID::eta
int eta(const Identifier id) const
return eta according to :
Definition: CaloLVL1_ID.h:653
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
L1CaloPedestalGenerator::execute
virtual StatusCode execute()
Definition: L1CaloPedestalGenerator.cxx:104
CaloLVL1_ID::pos_neg_z
int pos_neg_z(const Identifier id) const
return pos_neg_z according to :
Definition: CaloLVL1_ID.h:635
TriggerTowerCollection
DataVector< LVL1::TriggerTower > TriggerTowerCollection
Definition: TriggerTowerCollection.h:10
L1CaloPedestalGenerator::IDeta
double IDeta(const Identifier &id, const CaloLVL1_ID *l1id)
Definition: L1CaloPedestalGenerator.cxx:403
CaloLVL1_ID::tower_begin
id_iterator tower_begin() const
begin iterator over towers
Definition: CaloLVL1_ID.h:597
CaloLVL1_ID::sampling
int sampling(const Identifier id) const
return sampling according to :
Definition: CaloLVL1_ID.h:641
convertTimingResiduals.offset
offset
Definition: convertTimingResiduals.py:71
TriggerTowerCollection.h
L1CaloPedestalGenerator::finalize
virtual StatusCode finalize()
Definition: L1CaloPedestalGenerator.cxx:336
L1CaloPedestalGenerator.h
LVL1::TriggerTowerKey::ttKey
virtual unsigned int ttKey(const TriggerTower &tower)
returns the key of the passed tower
Definition: TriggerTowerKey.cxx:143
Analysis::TT
@ TT
Definition: JpsiFinder.h:36
CaloLVL1_ID::is_tile
bool is_tile(const Identifier id) const
Test wether given tower or layer is part of the Tile Calorimeter.
Definition: CaloLVL1_ID.h:672
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
LVL1::TriggerTowerKey
The TriggerTowerKey object provides the key for each trigger tower depending on its eta-phi coords.
Definition: TriggerTowerKey.h:56
L1CaloPedestalGenerator::initialize
virtual StatusCode initialize()
Definition: L1CaloPedestalGenerator.cxx:51
WriteCellNoiseToCool.noise
noise
Definition: WriteCellNoiseToCool.py:380
L1CaloPedestalGenerator::m_nSamples
unsigned int m_nSamples
Definition: L1CaloPedestalGenerator.h:50
xAOD::TriggerTower
TriggerTower_v2 TriggerTower
Define the latest version of the TriggerTower class.
Definition: Event/xAOD/xAODTrigL1Calo/xAODTrigL1Calo/TriggerTower.h:16
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
Identifier
Definition: IdentifierFieldParser.cxx:14