ATLAS Offline Software
Loading...
Searching...
No Matches
L1CaloTTIdTools.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include <cmath>
7namespace LVL1{
8
9 const double L1CaloTTIdTools::BASEDETA = 0.1;
10 const double L1CaloTTIdTools::BASEDPHI = 0.098175;
11 const double L1CaloTTIdTools::FCALDETA = 0.425;
12
13 const double L1CaloTTIdTools::ETAMAXREGION0 = 2.5;
14 const double L1CaloTTIdTools::ETAMAXREGION1 = 3.1;
15 const double L1CaloTTIdTools::ETAMAXREGION2 = 3.2;
16 const double L1CaloTTIdTools::ETAMAXREGION3 = 4.9;
17
18 const double L1CaloTTIdTools::ETAMIN = -4.9;
19 const double L1CaloTTIdTools::PHIMIN = 0.;
20
21 L1CaloTTIdTools::L1CaloTTIdTools( const std::string& name) :
22 asg::AsgTool( name ),
25 m_bInitialized(false)
26 {
27 }
28
30
31 ATH_MSG_INFO("Initializing LVL1::L1CaloTTIdTools");
32
33 StatusCode sc ;
34
35 const TTOnlineID* l1ttonline_id = nullptr;
36 sc = detStore()->retrieve(l1ttonline_id, "TTOnlineID");
37 if(sc.isFailure()){
38 ATH_MSG_ERROR("Could not get TTOnlineID helper !");
39 return sc;
40 } else {
41 m_l1ttonlineHelper = l1ttonline_id;
42 ATH_MSG_DEBUG(" Found the TTOnlineID helper. ");
43 }
44
45 const CaloLVL1_ID* l1ttoffline_id;
46 sc = detStore()->retrieve(l1ttoffline_id, "CaloLVL1_ID");
47 if(sc.isFailure()) {
48 ATH_MSG_DEBUG("Could not get CaloLVL1_ID helper !");
49 return sc;
50 } else {
51 m_l1ttofflineHelper = l1ttoffline_id;
52 ATH_MSG_DEBUG(" Found the CaloLVL1_ID helper. ");
53 }
54
55 m_bInitialized = true;
56 return sc;
57 }
58
60 return StatusCode::SUCCESS;
61 }
62
63
64 // return 1 for z>0 and 0 for z<0
66 int crate = m_l1ttonlineHelper->crate(id);
67 if(crate==0 || crate==2 || crate==4 || crate==6) return 1;
68 else if(crate==1 || crate==3 || crate==5 || crate==7) return 0;
69 else return 999;
70 }
71
73 int crate = m_l1ttonlineHelper->crate(id);
74 if(crate==0 || crate==1 || crate==2 || crate==3) return 0; //EM -> 0
75 else if(crate==6 || crate ==7 ) return 1; //HAd -> 1
76 else if (crate==4 || crate ==5) {
77 int module = m_l1ttonlineHelper->module(id);
78 if (module==5) return 0; //EM
79 else return 1; //HAD
80 } else return 999;
81 }
82
84 int ppm_type = PPM_type(id);
85
86 if ( ppm_type<=6 ) {
87 return 0;
88 } else if ( ppm_type==7 && this->side(id)==1 ) {
89
90 int submodule = m_l1ttonlineHelper->submodule(id);
91 int normalized_submodule_number = submodule%4;
92
93 // Module 1 & 2 -> region 1
94 if( normalized_submodule_number==1 || normalized_submodule_number ==2) return 1;
95
96 // Module 0 & 3
97 else {
98 int channel = m_l1ttonlineHelper->channel(id);
99 // channel 2 of modules 0&3 ->region 1
100 if( channel==2 ) return 1;
101 // channel 1&2 of modules 1&4 ->region 0
102 else if ( channel==0 || channel ==1 ) return 0;
103 else return -1;
104 }
105 } else if ( ppm_type==7 && this->side(id)==0 ) {
106
107 int submodule = m_l1ttonlineHelper->submodule(id);
108 int normalized_submodule_number = submodule%4;
109
110 // Module 0 & 3 -> region 1
111 if( normalized_submodule_number==0 || normalized_submodule_number ==3) return 1;
112
113 // Module 1 & 2
114 else {
115 int channel = m_l1ttonlineHelper->channel(id);
116 // channel 0 of modules 1&2 ->region 1
117 if( channel==0 ) return 1;
118 // channel 2&3 of modules 1&2 ->region 0
119 else if ( channel==2 || channel ==3 ) return 0;
120 else return -1;
121 }
122 } else if ( ppm_type==8 && this->side(id)==1 ) {
123 int channel = m_l1ttonlineHelper->channel(id);
124 // channel 0 -> region 1
125 if(channel==0) return 1;
126 // channel 3 ->region 2
127 else if(channel==2) return 2;
128 else return -1;
129 } else if ( ppm_type==8 && this->side(id)==0 ) {
130 int channel = m_l1ttonlineHelper->channel(id);
131 // channel 2 -> region 1
132 if(channel==2) return 1;
133 // channel 3 ->region 2
134 else if(channel==0) return 2;
135 else return -1;
136 } else if ( ppm_type==9 ) {
137 return 3;
138 } else return -1;
139 }
140
141 // return PPM type from 1 to 9
142 // PPM 1 to 6 are "standard"
143 // The cabling of PPMs 7, 8 & 9 is different
145 int crate = m_l1ttonlineHelper->crate(id);
146 int module = m_l1ttonlineHelper->module(id);
147 if(crate==0 || crate==6 ) return (module-5)%4+1;
148 if(crate==1 || crate==7 ) return 4-(module-5)%4;
149 if(crate==2 || crate==4 ) {
150 if(module==5 || module==13) return 9;
151 else return (module-6)%4+5;
152 }
153 if(crate==3 || crate==5 ) {
154 if(module==5 || module==13) return 9;
155 else return 8-(module-5)%4;
156 }
157 return -1;
158 }
159
161 int region = this->region(id);
162
163 //int pos_neg = m_l1ttonlineHelper->pos_neg(id);
164 int pos_neg = this->side(id);
165 //int module = m_l1ttonlineHelper->module(id);
166 int submodule = m_l1ttonlineHelper->submodule(id);
167 int channel = m_l1ttonlineHelper->channel(id);
168
169 int ppm_type = PPM_type(id);
170
171 //-- REGION 0 --//
172 if(region==0) {
173 if(ppm_type==7) return 24;
174 else {
175 int module_eta_offset = 0;
176 int submodule_eta_offset = 0;
177 int channel_eta_offset = 0;
178
179 module_eta_offset = (ppm_type-1)*4;
180
181 if(pos_neg==1) {
182 if( (submodule%4)==0 || (submodule%4)==3 ) submodule_eta_offset = 0;
183 else submodule_eta_offset = 2;
184 channel_eta_offset = channel/2;
185 } else {
186 if( (submodule%4)==0 || (submodule%4)==3 ) submodule_eta_offset = 2;
187 else submodule_eta_offset = 0;
188 channel_eta_offset = 1-channel/2;
189 }
190 return module_eta_offset + submodule_eta_offset + channel_eta_offset;
191 }
192
193 //-- REGION 1 --//
194 } else if (region==1) {
195 if(ppm_type==8) return 2;
196 else {
197 if(pos_neg==1) {
198 if(submodule%4==1 || submodule%4 ==2) return 1;
199 else return 0;
200 } else {
201 if(submodule%4==0 || submodule%4 ==3) return 1;
202 else return 0;
203 }
204 }
205
206 //-- REGION 2 --//
207 } else if (region==2) {
208 return 0;
209
210 //-- REGION 3 --//
211 } else if (region==3) {
212 //int em_had = m_l1ttonlineHelper->em_had(id);
213 int em_had = this->sampling(id);
214 if(pos_neg==1) {
215 if(em_had==0) { //Em
216 if(channel%4==0) return 0;
217 else if(channel%4==1) return 3;
218 else if(channel%4==2) return 1;
219 else if(channel%4==3) return 2;
220 else return -1;
221 } else { //Had
222 // these fcal had channels have the same eta position, but belong to different layers (FCAL_2&FCAL_3)
223 // if(channel%4==0 || channel%4==2) return 0;
224 // else if(channel%4==1 || channel%4==3) return 1;
225 // else return -1;
226
227 //the following assignation to eta indexes is FALSE for FCAL3 channels (3&1),
228 //but necessary to match with the way offline Ids are designed
229
230 // this mapping is not correct in regard of the one used in the bytestream decoder
231 // if(channel%4==0) return 0;
232 // else if(channel%4==1) return 3;
233 // else if(channel%4==2) return 2;
234 // else if(channel%4==3) return 1;
235 // else return -1;
236
237 // This mapping follow the BS decoder channel ordering for FCal
238 if(channel%4==0) return 0;
239 else if(channel%4==1) return 3;
240 else if(channel%4==2) return 1;
241 else if(channel%4==3) return 2;
242 else return -1;
243
244 }
245 } else {
246 if(em_had==0) { //Em
247 if(channel%4==0) return 3;
248 else if(channel%4==1) return 0;
249 else if(channel%4==2) return 2;
250 else if(channel%4==3) return 1;
251 else return -1;
252 } else { //Had
253 // these fcal had channels have the same eta position, but belong to different layers (FCAL_2&FCAL_3)
254 // if(channel%4==0 || channel%4==2) return 1;
255 // else if(channel%4==1 || channel%4==3) return 0;
256 // else return -1;
257
258 //the following assignation to eta indexes is FALSE for FCAL3 channels (3&1),
259 //but necessary to match with the way offline Ids are designed
260
261 // this mapping is not correct in regard of the one used in the bytestream decoder
262 // if(channel%4==0) return 1;
263 // else if(channel%4==1) return 2;
264 // else if(channel%4==2) return 3;
265 // else if(channel%4==3) return 0;
266 // else return -1;
267
268 // This mapping follow the BS decoder channel ordering for FCal
269 if(channel%4==0) return 3;
270 else if(channel%4==1) return 0;
271 else if(channel%4==2) return 2;
272 else if(channel%4==3) return 1;
273 else return -1;
274
275
276 }
277 }
278 }
279 return -1;
280 }
281
283 int region = this->region(id);
284
285 //int crate = m_l1ttonlineHelper->crate(id);
286 int module = m_l1ttonlineHelper->module(id);
287 int submodule = m_l1ttonlineHelper->submodule(id);
288 int channel = m_l1ttonlineHelper->channel(id);
289
290 int ppm_type = PPM_type(id);
291
292 int module_phi_offset = 0;
293 int submodule_phi_offset = 0;
294 int channel_phi_offset = 0;
295
296
297 //-- REGION 0 --//
298 if(region==0) {
299 module_phi_offset = int((module-5)/4)*16;
300 submodule_phi_offset = int(submodule/2)*2;
301 channel_phi_offset = channel%2;
302
303 return module_phi_offset + submodule_phi_offset + channel_phi_offset;
304
305 //-- REGION 1 --//
306 } else if (region==1) {
307 if(ppm_type==7) {
308 module_phi_offset = int((module-5)/4)*8;
309 submodule_phi_offset = int(submodule/2)*1;
310 channel_phi_offset = 0;
311
312 } else if(ppm_type==8) {
313 if(module==9) module_phi_offset = 0;
314 if(module==17) module_phi_offset = 16;
315 submodule_phi_offset = submodule;
316 channel_phi_offset = 0;
317 } else return -1;
318
319 return module_phi_offset + submodule_phi_offset + channel_phi_offset;
320
321 //-- REGION 2 --//
322 } else if (region==2) {
323 if(module==9) module_phi_offset = 0;
324 if(module==17) module_phi_offset = 16;
325 submodule_phi_offset = submodule;
326 channel_phi_offset = 0;
327
328 return module_phi_offset + submodule_phi_offset + channel_phi_offset;
329
330 //-- REGION 3 --//
331 } else if (region==3) {
332 module_phi_offset = 0;
333 submodule_phi_offset = submodule;
334 channel_phi_offset = 0;
335
336 return module_phi_offset + submodule_phi_offset + channel_phi_offset;
337 }
338 return -1;
339 }
340
341 // for had fcal (PPM9), 0== FCAL2, 1== FCAL3
343 int region = this->region(id);
344 int channel = m_l1ttonlineHelper->channel(id);
345
346 if(region==3 && this->sampling(id)==1 ) {
347 if(channel%4== 0 || channel%4==3) return 0; // FCAL_2
348 else if(channel%4== 2 || channel%4==1) return 1; // FCAL_3
349 else return -1;
350 } else return -1;
351 }
352
354 int crate = m_l1ttonlineHelper->crate(id);
355
356 if(crate==0 || crate==1 || crate==6 || crate==7) return 0; // barrel
357 else if(crate==2 || crate==3) return 1; //endcap
358 else if(crate==4 || crate==5) {
359 int ppm_type = PPM_type(id);
360 if(ppm_type == 9) return 2; // fcal
361 else if (ppm_type>=5 && ppm_type<=8) return 1; //endcap
362 else return 999;
363 } else return 999;
364 }
365
367 int crate = m_l1ttonlineHelper->crate(id);
368 int module = m_l1ttonlineHelper->module(id);
369
370 if(crate==0) {
371 if(module>=5 && module<=20) return 1; // PPM
372 else return 999;
373
374 } else if(crate==1) {
375 if(module>=5 && module<=20) return 1; // PPM
376 else return 999;
377
378 } else if(crate==2) {
379 if( (module>=6 && module<=20) && module!=13) return 1; // PPM
380 else return 999;
381
382 } else if(crate==3) {
383 if( (module>=6 && module<=20) && module!=13) return 1; // PPM
384 else return 999;
385
386 } else if(crate==4) {
387 if(module>=5 && module<=20) return 1; // PPM
388 else return 999;
389
390 } else if(crate==5) {
391 if(module>=5 && module<=20) return 1; // PPM
392 else return 999;
393
394 } else if(crate==6) {
395 if(module>=5 && module<=20) return 1; // PPM
396 else return 999;
397
398 } else if(crate==7) {
399 if(module>=5 && module<=20) return 1; // PPM
400 else return 999;
401
402 } else if(crate==8) {
403 if(module>=5 && module<=18) return 2; // CPM
404 else return 999;
405
406 } else if(crate==9) {
407 if(module>=5 && module<=18) return 2; // CPM
408 else return 999;
409
410 } else if(crate==10) {
411 if(module>=5 && module<=18) return 2; // CPM
412 else return 999;
413
414 } else if(crate==11) {
415 if(module>=5 && module<=18) return 2; // CPM
416 else return 999;
417
418 } else if(crate==12) {
419 if(module>=4 && module<=19) return 3; // JEM
420 else return 999;
421
422 } else if(crate==13) {
423 if(module>=4 && module<=19) return 3; // JEM
424 else return 999;
425
426 } else return 999;
427 }
428
429 double L1CaloTTIdTools::IDeta(const Identifier& id) const {
430 int region = m_l1ttofflineHelper->region(id);
431 int ieta = m_l1ttofflineHelper->eta(id);
432 int sign = m_l1ttofflineHelper->pos_neg_z(id);
433
434 double gran[4] = {0.1, 0.2, 0.1, 0.425};
435 double offset[4] = {0., 2.5, 3.1, 3.2};
436 double eta;
437
438 if (region>=0 && region<=3) {
439 eta = sign* ( ( (ieta+0.5) * gran[region] ) + offset[region] );
440 }
441 else {
442 eta = 0.;
443 }
444 return eta;
445 }
446
447 double L1CaloTTIdTools::IDphi(const Identifier& id) const {
448 Identifier regId = m_l1ttofflineHelper->region_id(id);
449
450 double phiMax = m_l1ttofflineHelper->phi_max(regId);
451 int iphi = m_l1ttofflineHelper->phi(id);
452 double phi = (iphi+0.5)*2.*M_PI/(phiMax+1.);
453 return phi;
454 }
455
456 LVL1::InternalTriggerTower* L1CaloTTIdTools::findInternalTriggerTower(std::map<unsigned int, LVL1::InternalTriggerTower*>* pIntTTContainer, const Identifier& towerId, bool bCreate) {
457 // Create tower key from towerId
458 double tower_eta = this->IDeta(towerId);
459 double tower_phi = this->IDphi(towerId);
460 LVL1::TriggerTowerKey towerKey;
461 unsigned int key = towerKey.ttKey(tower_phi,tower_eta);
462 double tt_phi = towerKey.phi();
463 double tt_eta = towerKey.eta();
464
465 return this->findInternalTriggerTower(pIntTTContainer, tt_phi, tt_eta, key, bCreate);
466 }
467
468 LVL1::InternalTriggerTower* L1CaloTTIdTools::findInternalTriggerTower(std::map<unsigned int, LVL1::InternalTriggerTower*>* pIntTTContainer, double tt_phi, double tt_eta, unsigned int key, bool bCreate) {
469 std::map<unsigned int, LVL1::InternalTriggerTower*>::iterator it = pIntTTContainer->find( key );
471 if (it == pIntTTContainer->end()){
472 if(bCreate) {
473 // no TT yet. Create it!
474 TT = new LVL1::InternalTriggerTower(tt_phi,tt_eta, key);
475 pIntTTContainer->insert(std::map<unsigned int, LVL1::InternalTriggerTower*>::value_type(key,TT)); //and put it in the map.
476 }
477 }else{
478 TT = (it->second);
479 } // end else
480 return TT;
481 }
482
483 double L1CaloTTIdTools::etaWidth(const double eta) const {
484 double abseta = fabs(eta);
485 if(abseta<ETAMAXREGION0) {
486 return BASEDETA;
487
488 } else if(abseta<ETAMAXREGION1) {
489 return BASEDETA*2.;
490
491 } else if (abseta<ETAMAXREGION2) {
492 return BASEDETA;
493
494 } else {
495 return FCALDETA;
496 }
497 }
498
499 double L1CaloTTIdTools::phiWidth(const double eta) const {
500 double abseta = fabs(eta);
501 if(abseta<ETAMAXREGION0) {
502 return BASEDPHI;
503
504 } else if(abseta<ETAMAXREGION1) {
505 return BASEDPHI*2.;
506
507 } else if (abseta<ETAMAXREGION2) {
508 return BASEDPHI*2.;
509
510 } else {
511 return BASEDPHI*4.;
512 }
513 }
514
515 int L1CaloTTIdTools::pos_neg_z(const double eta) const {
516 return (eta>=0) ? +1 : -1;
517 }
518
519 int L1CaloTTIdTools::etaIndex(const double eta) const {
520 int etacenter = -1;
521 double deta = this->etaWidth(eta);
522 double abseta = fabs(eta);
523
524 if(abseta<ETAMAXREGION0) {
525 etacenter = (int) floor(abseta/deta);
526
527 } else if(abseta<ETAMAXREGION1) {
528 etacenter = (int) (floor((abseta-ETAMAXREGION0)/deta));
529
530 } else if (abseta<ETAMAXREGION2) {
531 etacenter = (int) (floor((abseta-ETAMAXREGION1)/deta));
532
533 } else if (abseta<ETAMAXREGION3){
534 etacenter = (int) (floor((abseta-ETAMAXREGION2)/deta));
535 }
536 return etacenter;
537 }
538
539 int L1CaloTTIdTools::phiIndex(const double eta, const double phi) const {
540 double dphi = this->phiWidth(eta);
541 int phicenter = (int) floor(phi/dphi);
542 return phicenter;
543 }
544
545 int L1CaloTTIdTools::regionIndex(const double eta) const {
546 int region = -1;
547 double abseta = fabs(eta);
548
549 if(abseta<ETAMAXREGION0) {
550 region = 0;
551
552 } else if(abseta<ETAMAXREGION1) {
553 region = 1;
554
555 } else if (abseta<ETAMAXREGION2) {
556 region = 2;
557
558 } else if (abseta<ETAMAXREGION3) {
559 region = 3;
560
561 }
562 return region;
563 }
564} // end of namespace
565
#define M_PI
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
static Double_t sc
int sign(int a)
const ServiceHandle< StoreGateSvc > & detStore() const
Helper class for offline TT identifiers.
Definition CaloLVL1_ID.h:66
A version of the TriggerTower that contains information that would not be availiable during datatakin...
virtual double eta() const
returns the centre of the TT at eta_coord:
virtual double phi() const
returns phi coordinate of centre of relevant trigger tower.
L1CaloTTIdTools()=delete
delete the big 4
int region(const HWIdentifier &id)
const CaloLVL1_ID * m_l1ttofflineHelper
int regionIndex(const double eta) const
const TTOnlineID * m_l1ttonlineHelper
virtual StatusCode finalize()
static const double PHIMIN
int side(const HWIdentifier &id)
Declare the interface that the class provides.
static const double ETAMAXREGION1
int phi(const HWIdentifier &id)
int sampling(const HWIdentifier &id)
int PPM_type(const HWIdentifier &id)
double phiWidth(const double eta) const
int layer(const HWIdentifier &id)
int eta(const HWIdentifier &id)
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
int module_type(const HWIdentifier &id)
static const double BASEDETA
static const double BASEDPHI
int phiIndex(const double eta, const double phi) const
static const double ETAMIN
double etaWidth(const double eta) const
int pos_neg_z(const double eta) const
double IDphi(const Identifier &id) const
LVL1::InternalTriggerTower * findInternalTriggerTower(std::map< unsigned int, LVL1::InternalTriggerTower * > *pIntTTContainer, const Identifier &towerId, bool bCreate=true)
static const double ETAMAXREGION3
int barrel_endcap_fcal(const HWIdentifier &id)
int etaIndex(const double eta) const
static const double ETAMAXREGION2
double IDeta(const Identifier &id) const
static const double FCALDETA
static const double ETAMAXREGION0
The TriggerTowerKey object provides the key for each trigger tower depending on its eta-phi coords.
virtual unsigned int ttKey(const TriggerTower &tower)
returns the key of the passed tower
Helper class for Calo TT online identifiers.
Definition TTOnlineID.h:29
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
eFexTowerBuilder creates xAOD::eFexTowerContainer from supercells (LATOME) and triggerTowers (TREX) i...