ATLAS Offline Software
Loading...
Searching...
No Matches
CaloDetDescrManager.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5/***************************************************************************
6 Calorimeter detector description package
7 -----------------------------------------
8 ***************************************************************************/
9
10//<doc><file> $Id: CaloDetDescrManager.cxx,v 1.69 2009-03-03 14:34:12 gunal Exp $
11//<version> $Name: not supported by cvs2svn $
12
13
14// Calo includes
16#include "CaloDetDescr/CaloDetDescrElement.h"
20
21// Athena/Gaudi includes
22#include "GaudiKernel/Bootstrap.h"
23#include "GaudiKernel/ISvcLocator.h"
24#include "GaudiKernel/IMessageSvc.h"
26
27#include <cmath>
28
34
36{
37 unsigned tile_min = m_subCalo_min[CaloCell_ID::TILE];
38 unsigned tile_max = m_subCalo_max[CaloCell_ID::TILE];
39 for (size_t i = 0; i < m_element_vec.size(); i++) {
40 // Tile elements are deleted by TileDetDescrManager.
41 if (i >= tile_min && i < tile_max) continue;
42 delete m_element_vec[i];
43 }
44
45 for (size_t i = 0; i < m_descr_vec.size(); i++)
46 delete m_descr_vec[i];
47}
48
50{
51 // set sizes :
52 m_element_vec.resize(m_cell_id->calo_cell_hash_max());
53 m_descr_vec.resize(m_cell_id->calo_region_hash_max());
54
55 // --- --- Temporary, for testing only --- ---
56 for(unsigned int i=0; i<m_element_vec.size(); i++)
57 m_element_vec[i] = nullptr;
58
59 for(unsigned int i=0; i<m_descr_vec.size(); i++)
60 m_descr_vec[i] = nullptr;
61 // --- --- Temporary, for testing only --- ---
62
63 // cache offsets :
64 int nb = CaloCell_ID::NSUBCALO;
65
66 m_subCalo_min.resize(nb);
67 m_subCalo_max.resize(nb);
68 m_subCalo_begin.resize(nb);
69 m_subCalo_end.resize(nb);
70
71 for(int i = 0; i < nb; i++) {
72 m_cell_id->calo_cell_hash_range(i,m_subCalo_min[i],m_subCalo_max[i]);
73
76 }
77}
78
80{
81 std::cout << " CaloDetDescrManager_Base: \n";
82
83 std::cout << " Number of Calo descriptors : " << m_descr_vec.size() << "\n";
84
85 int ntot = m_descr_vec.size();
86 for(int i=0 ; i<ntot; i++ )
87 {
88 std::cout << "\n ------ Calo descriptor number " << i << "\n";
89 if(m_descr_vec[i])
90 m_descr_vec[i]->print();
91 }
92}
93
98
103
106{
107 return m_element_vec.size();
108}
109
112{
113 return m_element_vec.begin();
114}
115
118{
119 return m_element_vec.end();
120}
121
124{
125 return {m_element_vec.begin(),
126 m_element_vec.end()};
127}
128
135
138{
139 int sCal = (int)subCalo;
140 return m_subCalo_begin[sCal];
141}
142
145{
146 int sCal = (int) subCalo;
147 return m_subCalo_end[sCal];
148}
149
152{
153 int sCal = (int) subCalo;
154 return {m_subCalo_begin[sCal],
155 m_subCalo_end[sCal]};
156}
157
160{
161 IdentifierHash hash = m_cell_id->calo_cell_hash(cellId);
162 return get_element(hash);
163}
164
167{
168 IdentifierHash hash = m_cell_id->calo_cell_hash(cellId);
169 return get_element_nonconst(hash);
170}
171
174 IdentifierHash subCaloCellHash) const
175{
176 // meaningless interface for Tiles, will only work for LAr
177
178 int sCal = (int) subCalo;
179 if ( subCaloCellHash + m_subCalo_min[sCal] < m_element_vec.size() )
180 return m_element_vec[subCaloCellHash + m_subCalo_min[sCal]] ;
181 else return nullptr ;
182}
183
186 int sampling_or_module,
187 bool barrel,
188 double eta,
189 double phi) const
190{
191
192 bool inCell=false;
193 int niter=0;
194 const CaloDetDescrElement* elt=nullptr ;
195 const CaloDetDescrElement* elt_best=nullptr ;
196
197 double eta2=eta;
198 double phi2=phi;
199 double deltabest=9999.;
200 //std::cout << " in get_element0 " << subCalo << " " << sampling_or_module << " " << barrel << " " << eta << " " << phi << std::endl;
201
202
203 while (!inCell && niter<3) {
204
205 const CaloDetDescriptor* reg = get_descriptor(subCalo,sampling_or_module,barrel,eta2,phi2);
206 if (!reg) return nullptr;
207
208 if (reg->is_lar_fcal()) return get_element_FCAL(reg,eta,phi);
209
210 int ieta = reg->eta_channel(eta2);
211 int iphi = reg->phi_channel(phi2);
212 //std::cout << " ieta,iphi " << ieta << " " << iphi << std::endl;
213
214 if(ieta < 0) return elt;
215 if(iphi < 0) return elt;
216
217 Identifier regId = reg->identify();
218 Identifier cellId = m_cell_id->cell_id(regId, ieta, iphi);
219 IdentifierHash caloCellHash = m_cell_id->calo_cell_hash(cellId);
220 // Check for invalid identifier.
221 if (m_cell_id->cell_id (caloCellHash) != cellId) return elt;
222 elt = get_element(caloCellHash);
223 //std::cout << " element " << elt->eta() << " " << elt->phi() << " " << elt->deta() << " " << elt->dphi() << std::endl;
224 double deta=std::fabs(eta-elt->eta())-0.5*elt->deta();
225 double dphi = std::fabs(CaloPhiRange::fix(phi-elt->phi())) - 0.5*elt->dphi();
226 if (deta>0. || dphi > 0.) {
227 double delta=0.;
228 if (deta>0.) {
229 eta2=eta2 + (eta-elt->eta());
230 delta = delta + deta;
231 }
232 if (dphi>0.) {
233 phi2=CaloPhiRange::fix(phi2+(phi-elt->phi()));
234 delta = delta + dphi;
235 }
236 //std::cout << " need to iteration => eta2,phi2 " << eta2 << " " << phi2 << std::endl;
237 if (delta<deltabest) {
238 deltabest=delta;
239 elt_best = elt;
240 }
241 niter++;
242 }
243 else inCell=true;
244 }
245 if (!inCell) {
246 elt = elt_best;
247 // std::cout << " after iteration get_element0 " << inCell << " " << eta << " " << phi << " " << elt->eta() << " " << elt->phi() << " " << deltabest << std::endl;
248 }
249
250
251
252 return elt;
253}
254
257 double eta,
258 double phi) const
259{
260 const CaloDetDescrElement* elt=nullptr;
261
262 // For LAr loop on regions :
263
264 if ( sample != CaloCell_ID::TileBar0 && sample != CaloCell_ID::TileBar1 &&
265 sample != CaloCell_ID::TileBar2 && sample != CaloCell_ID::TileGap1 &&
266 sample != CaloCell_ID::TileGap2 && sample != CaloCell_ID::TileGap3 &&
267 sample != CaloCell_ID::TileExt0 && sample != CaloCell_ID::TileExt1 &&
268 sample != CaloCell_ID::TileExt2 ) {
269
270 bool inCell=false;
271 int niter=0;
272 const CaloDetDescrElement* elt_best=nullptr;
273
274 double eta2=eta;
275 double phi2=phi;
276 double deltabest=9999.;
277
278 while (!inCell && niter<3) {
279
280 const CaloDetDescriptor* reg = get_descriptor(sample,eta2,phi2);
281 if ( ! reg ) return elt;
282
283 if (reg->is_lar_fcal()) return get_element_FCAL(reg,eta2,phi2);
284
285 int ieta = reg->eta_channel(eta2);
286 int iphi = reg->phi_channel(phi2);
287
288 if(ieta < 0) return elt;
289 if(iphi < 0) return elt;
290
291 Identifier regId = reg->identify();
292 Identifier cellId = m_cell_id->cell_id(regId, ieta, iphi);
293 IdentifierHash caloCellHash = m_cell_id->calo_cell_hash(cellId);
294 // Check for invalid identifier.
295 if (m_cell_id->cell_id (caloCellHash) != cellId) return elt;
296 elt = get_element(caloCellHash);
297 double deta=std::fabs(eta-elt->eta())-0.5*elt->deta();
298 double dphi = std::fabs(CaloPhiRange::fix(phi-elt->phi())) - 0.5*elt->dphi();
299 if (deta>0. || dphi > 0.) {
300 double delta=0.;
301 if (deta>0.) {
302 eta2=eta2 + (eta-elt->eta());
303 delta = delta + deta;
304 }
305 if (dphi>0.) {
306 phi2=CaloPhiRange::fix(phi2+(phi-elt->phi()));
307 delta = delta + dphi;
308 }
309 if (delta<deltabest) {
310 deltabest=delta;
311 elt_best = elt;
312 }
313 niter++;
314 }
315 else inCell=true;
316 }
317 if (!inCell) {
318 elt = elt_best;
319 //std::cout << " after iteration get_element " << inCell << " " << eta << " " << phi << " " << elt->eta() << " " << elt->phi() << " " << deltabest << std::endl;
320 }
321
322
323 } else {
324
325 // For Tiles loop on elements :
326
327 for ( unsigned int i = m_subCalo_min[CaloCell_ID::TILE];
329 {
330 const CaloDetDescrElement* pt = m_element_vec[i];
331 if (pt) {
332 const double dphi = std::fabs(CaloPhiRange::fix(phi-pt->phi()));
333 if ( pt->getSampling() == sample &&
334 pt->eta()+pt->deta()/2 >= eta &&
335 pt->eta()-pt->deta()/2 <= eta &&
336 dphi <= pt->dphi()/2 )
337 {
338 elt = pt;
339 break;
340 }
341 }
342 }
343 }
344 return elt;
345}
346
347// Cut and paste, but from raw eta,phi
350 double eta,
351 double phi) const
352{
353 //std::cout << " ----- in get_element_raw for eta,phi raw " << eta << " " << phi << std::endl;
354 const CaloDetDescrElement* elt=nullptr;
355
356 // For LAr loop on regions :
357
358 if ( sample != CaloCell_ID::TileBar0 && sample != CaloCell_ID::TileBar1 &&
359 sample != CaloCell_ID::TileBar2 && sample != CaloCell_ID::TileGap1 &&
360 sample != CaloCell_ID::TileGap2 && sample != CaloCell_ID::TileGap3 &&
361 sample != CaloCell_ID::TileExt0 && sample != CaloCell_ID::TileExt1 &&
362 sample != CaloCell_ID::TileExt2 ) {
363
364 bool inCell=false;
365 int niter=0;
366 const CaloDetDescrElement* elt_best=nullptr ;
367
368 double eta2=eta;
369 double phi2=phi;
370 double deltabest=9999.;
371
372 while (!inCell && niter<3) {
373
374 const CaloDetDescriptor* reg = get_descriptor_raw(sample,eta2,phi2);
375 if ( ! reg ) return elt;
376 //std::cout << " get_element_raw: found region calo etamin,etamax " << reg->calo_eta_min() << " " << reg->calo_eta_max() << std::endl;
377
378 if (reg->is_lar_fcal()) return get_element_FCAL_raw(reg,eta,phi);
379
380 int ieta = reg->eta_channel_raw(eta2);
381 int iphi = reg->phi_channel_raw(phi2);
382
383 if(ieta < 0) return elt;
384 if(iphi < 0) return elt;
385
386 Identifier regId = reg->identify();
387 Identifier cellId = m_cell_id->cell_id(regId, ieta, iphi);
388 IdentifierHash caloCellHash = m_cell_id->calo_cell_hash(cellId);
389 // Check for invalid identifier.
390 if (m_cell_id->cell_id (caloCellHash) != cellId) return elt;
391 elt = get_element(caloCellHash);
392 //std::cout << " elt raw,phi raw " << elt->eta_raw() << " " << elt->phi_raw() << std::endl;
393 double deta=std::fabs(eta-elt->eta_raw())-0.5*elt->deta();
394 double dphi = std::fabs(CaloPhiRange::fix(phi-elt->phi_raw())) - 0.5*elt->dphi();
395 if (deta>0. || dphi > 0.) {
396 double delta=0.;
397 if (deta>0.) {
398 eta2=eta2 + (eta-elt->eta_raw());
399 delta = delta + deta;
400 }
401 if (dphi>0.) {
402 phi2=CaloPhiRange::fix(phi2+(phi-elt->phi_raw()));
403 delta = delta + dphi;
404 }
405 if (delta<deltabest) {
406 deltabest=delta;
407 elt_best = elt;
408 }
409 niter++;
410 }
411 else {
412 //std::cout << " found cell " << elt->eta_raw() << " " << elt->phi_raw() << std::endl;
413 inCell=true;
414 }
415 }
416 if (!inCell) {
417 elt=elt_best;
418 //std::cout << " after iteration raw " << inCell << " " << eta << " " << phi << " " << elt->eta_raw() << " " << elt->phi_raw() << " " << deltabest << std::endl;
419 }
420
421
422 } else {
423
424 // For Tiles loop on elements :
425
426 for ( unsigned int i = m_subCalo_min[CaloCell_ID::TILE];
427 i < m_subCalo_max[CaloCell_ID::TILE]; i++ ) {
428 const CaloDetDescrElement* pt = m_element_vec[i];
429 if (pt)
430 if ( pt->getSampling() == sample &&
431 pt->eta()+pt->deta()/2 <= eta &&
432 pt->eta()-pt->deta()/2 >= eta &&
433 pt->phi()+pt->phi()/2 <= phi &&
434 pt->phi()-pt->phi()/2 >= phi ) elt = pt ;
435 }
436 }
437 return elt;
438}
439
440
441
444 double eta,
445 double phi) const
446{
447 const CaloDetDescrElement* elt=nullptr;
448
449 //std::cout << " in get_element_FCAL " << descr->reg_min() << " " << descr->reg_max() << " eta,phi " << eta << " " << phi << std::endl;
450 if (eta < (descr->reg_min()-0.01) || eta > (descr->reg_max()+0.01) ) return elt;
451
452 Identifier regId = descr->identify();
453 Identifier cellId;
454 IdentifierHash caloCellHash;
455 const CaloDetDescrElement* elt2;
456 double drmax=9999.;
457 for (int ieta=0; ieta<descr->n_eta(); ieta++) {
458 for (int iphi=0; iphi<descr->n_phi(); iphi++) {
459 cellId = m_cell_id->cell_id(regId, ieta, iphi);
460 caloCellHash = m_cell_id->calo_cell_hash(cellId);
461 elt2 = get_element (caloCellHash);
462 double deta = (eta-elt2->eta());
463 double dphi = CaloPhiRange::diff(phi,elt2->phi());
464 double dr = (deta*deta+dphi*dphi);
465 if (dr<drmax) {
466 drmax=dr;
467 elt = elt2;
468 }
469 }
470 }
471
472 //if (elt) std::cout << " element found " << elt->eta() << " " << elt->phi() << std::endl;
473 //else std::cout <<" element not found " << std::endl;
474
475 return elt;
476}
477
480 double eta,
481 double phi) const
482{
483 const CaloDetDescrElement* elt=nullptr;
484
485 //std::cout << " in get_element_FCAL " << descr->reg_min() << " " << descr->reg_max() << " eta,phi " << eta << " " << phi << std::endl;
486 if (std::fabs(eta) < (descr->calo_eta_min()-0.01) || std::fabs(eta) > (descr->calo_eta_max()+0.01) ) return elt;
487
488 Identifier regId = descr->identify();
489 Identifier cellId;
490 IdentifierHash caloCellHash;
491 const CaloDetDescrElement* elt2;
492 double drmax=9999.;
493 for (int ieta=0; ieta<descr->n_eta(); ieta++) {
494 for (int iphi=0; iphi<descr->n_phi(); iphi++) {
495 cellId = m_cell_id->cell_id(regId, ieta, iphi);
496 caloCellHash = m_cell_id->calo_cell_hash(cellId);
497 elt2 = get_element (caloCellHash);
498 double deta = (eta-elt2->eta_raw());
499 double dphi = CaloPhiRange::diff(phi,elt2->phi_raw());
500 double dr = (deta*deta+dphi*dphi);
501 if (dr<drmax) {
502 drmax=dr;
503 elt = elt2;
504 }
505 }
506 }
507
508 //if (elt) std::cout << " element found " << elt->eta() << " " << elt->phi() << std::endl;
509 //else std::cout <<" element not found " << std::endl;
510
511 return elt;
512}
513
514
515
521
527
533
536{
537 return {m_descr_vec.begin(), m_descr_vec.end()};
538}
539
545
551
557
563
570
577
580{
581 IdentifierHash hash = m_cell_id->calo_region_hash(regionId);
582 if(hash < m_descr_vec.size())
583 return m_descr_vec[hash] ;
584 else
585 return nullptr;
586}
587
590{
591 IdentifierHash hash = m_cell_id->calo_region_hash(regionId);
592 if(hash < m_descr_vec.size())
593 return m_descr_vec[hash] ;
594 else
595 return nullptr;
596}
597
600 int sampling_or_module,
601 bool barrel,
602 double eta,
603 double phi) const
604{
605 const CaloDetDescriptor* desc0 = nullptr;
606 const CaloDetDescriptor* desc1 = nullptr;
607 const CaloDetDescriptor* desc2 = nullptr;
608 const CaloDetDescriptor* desc3 = nullptr;
609
610 if(subCalo == CaloCell_ID::TILE) return nullptr;
611 if(subCalo == CaloCell_ID::LARHEC && barrel) return nullptr;
612 if(subCalo == CaloCell_ID::LARFCAL && barrel) return nullptr;
613
614 for (unsigned int i=0; i<m_descr_vec.size(); i++)
615 {
616 const CaloDetDescriptor* reg = m_descr_vec[i];
617
618 if(reg)
619 {
620
621 // for em differentiate barrel from endcap :
622 if ((subCalo != CaloCell_ID::LAREM
623 || (!barrel && reg->is_lar_em_endcap())
624 || (barrel && reg->is_lar_em_barrel())
625 )
626 && ((subCalo == CaloCell_ID::LAREM && reg->is_lar_em())
627 || (subCalo == CaloCell_ID::LARHEC && reg->is_lar_hec())
628 || (subCalo == CaloCell_ID::LARFCAL && reg->is_lar_fcal())
629 )
630 )
631 {
632
633 if(reg->eta_channel(eta) >=0 && reg->phi_channel(phi) >=0)
634 {
635 // this works only for LAr, for Tiles the sampling depends on the
636 // cell
637 int reg_sampl = reg->getSampling(0);
638 // using enums as running indices is not safe! Therefore ask
639 // for each sampling explicitly
640 if(reg->is_lar_em_barrel())
641 {
642 if(reg_sampl == CaloCell_ID::PreSamplerB) desc0 = reg;
643 else if(reg_sampl == CaloCell_ID::EMB1) desc1 = reg;
644 else if(reg_sampl == CaloCell_ID::EMB2) desc2 = reg;
645 else if(reg_sampl == CaloCell_ID::EMB3) desc3 = reg;
646 }
647 else if(reg->is_lar_em_endcap())
648 {
649 if(reg_sampl == CaloCell_ID::PreSamplerE) desc0 = reg;
650 else if(reg_sampl == CaloCell_ID::EME1) desc1 = reg;
651 else if(reg_sampl == CaloCell_ID::EME2) desc2 = reg;
652 else if(reg_sampl == CaloCell_ID::EME3) desc3 = reg;
653 }
654 else if(reg->is_lar_hec())
655 {
656 if(reg_sampl == CaloCell_ID::HEC0) desc0 = reg;
657 else if(reg_sampl == CaloCell_ID::HEC1) desc1 = reg;
658 else if(reg_sampl == CaloCell_ID::HEC2) desc2 = reg;
659 else if(reg_sampl == CaloCell_ID::HEC3) desc3 = reg;
660 }
661 else if(reg->is_lar_fcal())
662 {
663 if(reg_sampl == CaloCell_ID::FCAL0) desc0 = reg;
664 else if(reg_sampl == CaloCell_ID::FCAL1) desc1 = reg;
665 else if(reg_sampl == CaloCell_ID::FCAL2) desc2 = reg;
666 }
667 } //if(reg->eta_channel(eta) >=0 && reg->phi_channel(phi) >=0)
668 }
669 } //if(reg)
670 } // iteration over descriptors
671
672 if(sampling_or_module == 0) return desc0;
673 else if(sampling_or_module == 1) return desc1;
674 else if(sampling_or_module == 2) return desc2;
675 else if(sampling_or_module == 3) return desc3;
676 else return nullptr;
677}
678
681 double eta, double phi) const
682{
683 // note that this code does not work in the FCal as eta indices depend
684 // on eta and phi
685
686 const CaloDetDescriptor* desc = nullptr;
687
688 if ( sample == CaloCell_ID::TileBar0 ||
689 sample == CaloCell_ID::TileBar1 ||
690 sample == CaloCell_ID::TileBar2 ||
691 sample == CaloCell_ID::TileGap1 ||
692 sample == CaloCell_ID::TileGap2 ||
693 sample == CaloCell_ID::TileGap3 ||
694 sample == CaloCell_ID::TileExt0 ||
695 sample == CaloCell_ID::TileExt1 ||
696 sample == CaloCell_ID::TileExt2 ) return desc;
697
698 for ( unsigned int i=0; i<m_descr_vec.size(); i++ ) {
699 const CaloDetDescriptor* reg = m_descr_vec[i];
700
701 if (reg) {
702 if ( reg->eta_channel(eta) >=0 && reg->phi_channel(phi) >=0) {
703 // this works only for LAr EM and HEC, for Tiles the sampling
704 // depends on the cell
705 int reg_sampl = reg->getSampling(0);
706 if ( reg_sampl == sample ) desc = reg;
707 }
708 }
709 }
710
711 return desc;
712}
713
716 double eta, double phi) const
717{
718 // note that this code does not work in the FCal as eta indices depend
719 // on eta and phi
720
721 //std::cout << " in CaloDetDescrManager_Base::get_descriptor_raw " << std::endl;
722
723 const CaloDetDescriptor* desc = nullptr;
724
725 if ( sample == CaloCell_ID::TileBar0 ||
726 sample == CaloCell_ID::TileBar1 ||
727 sample == CaloCell_ID::TileBar2 ||
728 sample == CaloCell_ID::TileGap1 ||
729 sample == CaloCell_ID::TileGap2 ||
730 sample == CaloCell_ID::TileGap3 ||
731 sample == CaloCell_ID::TileExt0 ||
732 sample == CaloCell_ID::TileExt1 ||
733 sample == CaloCell_ID::TileExt2 ) return desc;
734
735 for ( unsigned int i=0; i<m_descr_vec.size(); i++ ) {
736 const CaloDetDescriptor* reg = m_descr_vec[i];
737
738 if (reg) {
739 int reg_sampl = reg->getSampling(0);
740 if ( reg_sampl == sample ) {
741 if ( reg->eta_channel_raw(eta) >=0 && reg->phi_channel_raw(phi) >=0) {
742 // this works only for LAr EM and HEC, for Tiles the sampling
743 // depends on the cell
744 desc=reg;
745 return desc;
746 }
747 }
748 }
749 }
750
751 return desc;
752}
753
754
756{
757 m_element_vec[element->calo_hash()] = element;
758}
759
761{
762 m_descr_vec[descr->calo_hash()] = descr;
763}
764
765void CaloDetDescrManager_Base::add(std::unique_ptr<CaloDetDescriptor> descr)
766{
767 IdentifierHash idhash = descr->calo_hash();
768 m_descr_vec[idhash] = descr.release();
769}
770
772{
773 m_tile_descr_vec.push_back(descr);
774}
775
782
784{
785 m_cell_id = idHelper;
786}
787
789{
790 m_calo_mgr = idHelper;
791}
792
793void CaloDetDescrManager_Base::cellsInZone(double eta_min, double eta_max,
794 double phi_min, double phi_max,
795 std::vector<IdentifierHash> & cell_list ) const
796{
797 cell_list.clear();
798 if ( eta_min >= eta_max ) return;
799 if ( phi_min >= phi_max ) return;
800
801 std::vector<IdentifierHash> one_list;
802
803 // For LAr use the descriptors :
804 for ( unsigned int i=0; i<m_descr_vec.size(); i++ ) {
805 const CaloDetDescriptor* reg = m_descr_vec[i];
806 if ( reg ) {
807 cellsInZone(eta_min, eta_max, phi_min, phi_max, reg, one_list);
808 if (cell_list.empty())
809 cell_list.swap (one_list);
810 else
811 cell_list.insert (cell_list.end(), one_list.begin(), one_list.end());
812 }
813 }
814
815 // Now Tiles :
816 cellsInZone(eta_min, eta_max, phi_min, phi_max, CaloCell_ID::TILE, one_list);
817 cell_list.insert (cell_list.end(), one_list.begin(), one_list.end());
818}
819
820void CaloDetDescrManager_Base::cellsInZone(double eta_min, double eta_max,
821 double phi_min, double phi_max,
822 CaloCell_ID::SUBCALO subCalo,
823 std::vector<IdentifierHash> & cell_list) const
824{
825 cell_list.clear();
826 if ( eta_min >= eta_max ) return;
827 if ( phi_min >= phi_max ) return;
828
829 std::vector<IdentifierHash> one_list;
830
831
832 if ( subCalo != CaloCell_ID::TILE ) {
833
834 for ( unsigned int i=0; i<m_descr_vec.size(); i++ ) {
835 const CaloDetDescriptor* reg = m_descr_vec[i];
836 if ( reg )
837 if ( subCalo == reg->getSubCalo() ) {
838 cellsInZone(eta_min, eta_max, phi_min, phi_max, reg, one_list);
839 if (cell_list.empty())
840 cell_list.swap (one_list);
841 else
842 cell_list.insert (cell_list.end(),
843 one_list.begin(), one_list.end());
844 }
845 }
846
847 } else {
848
849 // For Tiles loop on elements :
850 const CaloDetDescrElement* tile_elt;
851 for ( unsigned int i = m_subCalo_min[subCalo];
852 i < m_subCalo_max[subCalo]; i++ ) {
853 tile_elt = m_element_vec[i];
854 if (tile_elt) {
855
856 if ( tile_elt->eta()+tile_elt->deta()/2. > eta_min &&
857 tile_elt->eta()-tile_elt->deta()/2. < eta_max) {
858
859 double dphi1 = CaloPhiRange::diff(tile_elt->phi()+tile_elt->dphi()/2.,phi_min);
860 double dphi2 = CaloPhiRange::diff(phi_max,tile_elt->phi()-tile_elt->dphi()/2);
861
862 if(dphi1 >=0. && dphi2 >= 0.) {
863 if (cell_list.empty()) {
864 // Guess a good size, incl 3 samplings.
865 cell_list.reserve (static_cast<int>(
866 ((eta_max-eta_min) / tile_elt->deta()) *
867 ((phi_max-phi_min) / tile_elt->dphi()) * 3));
868 }
869 cell_list.push_back(tile_elt->calo_hash());
870 } // phi cut
871 } // eta cut
872 } // tile_elt exits
873 }
874 }
875}
876
877void CaloDetDescrManager_Base::cellsInZone(double eta_min, double eta_max,
878 double phi_min, double phi_max,
880 std::vector<IdentifierHash> & cell_list) const
881{
882 cell_list.clear();
883 if ( eta_min >= eta_max ) return;
884 if ( phi_min >= phi_max ) return;
885
886 std::vector<IdentifierHash> one_list;
887
888 if ( sample != CaloCell_ID::TileBar0 &&
889 sample != CaloCell_ID::TileBar1 &&
890 sample != CaloCell_ID::TileBar2 &&
891 sample != CaloCell_ID::TileGap1 &&
892 sample != CaloCell_ID::TileGap2 &&
893 sample != CaloCell_ID::TileGap3 &&
894 sample != CaloCell_ID::TileExt0 &&
895 sample != CaloCell_ID::TileExt1 &&
896 sample != CaloCell_ID::TileExt2 ) {
897
898 for ( unsigned int i=0; i<m_descr_vec.size(); i++ ) {
899 const CaloDetDescriptor* reg = m_descr_vec[i];
900 if ( reg )
901 // this works only for LAr, for Tiles the sampling depends on the
902 // cell
903 if ( sample == reg->getSampling(0) ) {
904 cellsInZone(eta_min, eta_max, phi_min, phi_max, reg, one_list);
905 if (cell_list.empty())
906 cell_list.swap (one_list);
907 else
908 cell_list.insert (cell_list.end(),
909 one_list.begin(), one_list.end());
910 }
911 }
912
913 } else {
914
915 // For Tiles loop on elements :
916 int nb = CaloCell_ID::TILE;
917 const CaloDetDescrElement* tile_elt;
918
919 for ( unsigned int i = m_subCalo_min[nb]; i < m_subCalo_max[nb]; i++ ) {
920 tile_elt = m_element_vec[i];
921 if (tile_elt ){
922 if (tile_elt->getSampling() == sample) {
923
924 if ( tile_elt->eta()+tile_elt->deta()/2. > eta_min &&
925 tile_elt->eta()-tile_elt->deta()/2. < eta_max) {
926
927 double dphi1 = CaloPhiRange::diff(tile_elt->phi()+tile_elt->dphi()/2.,phi_min);
928 double dphi2 = CaloPhiRange::diff(phi_max,tile_elt->phi()-tile_elt->dphi()/2);
929
930 if(dphi1 >=0. && dphi2 >= 0.) {
931 if (cell_list.empty()) {
932 // Guess a good size, incl 3 samplings.
933 cell_list.reserve (static_cast<int>(
934 ((eta_max-eta_min) / tile_elt->deta()) *
935 ((phi_max-phi_min) / tile_elt->dphi()) * 3));
936 }
937 cell_list.push_back(tile_elt->calo_hash());
938 } // phi cut
939 } // eta cut
940 } // sampling cut
941 } // tile_elt exists
942 }
943 }
944}
945
946void CaloDetDescrManager_Base::cellsInZone(double eta_min, double eta_max,
947 double phi_min, double phi_max,
948 CaloCell_ID::SUBCALO subCalo,
949 int sampling_or_module,
950 std::vector<IdentifierHash> & cell_list) const
951{
952 cell_list.clear();
953 if ( eta_min >= eta_max ) return;
954 if ( phi_min >= phi_max ) return;
955
956 // sampling_or_module has no meaning for tiles
957 if ( subCalo == CaloCell_ID::TILE ) return;
958
959 std::vector<IdentifierHash> one_list;
960
961 for ( unsigned int i=0; i<m_descr_vec.size(); i++ ) {
962 const CaloDetDescriptor* reg = m_descr_vec[i];
963 if ( reg ) {
964 Identifier regId = reg->identify();
965 if ( subCalo == reg->getSubCalo() &&
966 m_cell_id->sampling(regId) == sampling_or_module ) {
967 cellsInZone(eta_min, eta_max, phi_min, phi_max, reg, one_list);
968 if (cell_list.empty())
969 cell_list.swap (one_list);
970 else
971 cell_list.insert (cell_list.end(),
972 one_list.begin(), one_list.end());
973 }
974 }
975 }
976}
977
978void
979CaloDetDescrManager_Base::cellsInZone(double eta, double phi, int ncell_eta,
980 int ncell_phi, CaloCell_ID::SUBCALO subCalo,
981 int sampling_or_module,
982 bool barrel,
983 std::vector<IdentifierHash> & cell_list) const
984{
985
986 cell_list.clear();
987 double eta_min, eta_max, phi_min, phi_max;
988 double weta = (ncell_eta-1)/2.;
989 double wphi = (ncell_phi-1)/2.;
990
991 std::vector<IdentifierHash> one_list;
992
993 if ( subCalo != CaloCell_ID::TILE ) {
994
995 for ( unsigned int i=0; i<m_descr_vec.size(); i++ ) {
996 const CaloDetDescriptor* reg = m_descr_vec[i];
997 if ( reg ) {
998 Identifier regId = reg->identify();
999 if ( subCalo == reg->getSubCalo() &&
1000 m_cell_id->sampling(regId) == sampling_or_module) {
1001
1002 double eta_gran = m_cell_id->etaGranularity(regId);
1003 double phi_gran = m_cell_id->phiGranularity(regId);
1004
1005 eta_min = eta-weta*eta_gran;
1006 eta_max = eta+weta*eta_gran;
1007 phi_min = phi-wphi*phi_gran;
1008 phi_max = phi+wphi*phi_gran;
1009 cellsInZone(eta_min, eta_max, phi_min, phi_max, reg, one_list);
1010 cell_list.reserve (cell_list.size() + one_list.size());
1011 for ( unsigned int i = 0; i<one_list.size(); i++ ){
1012 // I know that cellsInZone catches more cells than needed
1013 // => look and cut
1014 const CaloDetDescrElement* elt = get_element (one_list[i]);
1015 double elt_eta = elt->eta();
1016 double elt_phi = elt->phi();
1017 if ( barrel == elt->is_lar_em_barrel() )
1018 if ( std::abs(eta - elt_eta) <= weta )
1019 if ( std::abs(phi - elt_phi) <= wphi )
1020 cell_list.push_back(one_list[i]);
1021 }
1022 }
1023 }
1024 }
1025 }
1026 else {
1027
1028 // For Tiles loop on elements :
1029 // loosy logic. since I do not know the grannularity in the
1030 // region, I use the one of each element. Hum...
1031 const CaloDetDescrElement* tile_elt;
1032 for ( unsigned int i = m_subCalo_min[subCalo];
1033 i < m_subCalo_max[subCalo]; i++ ) {
1034 tile_elt = m_element_vec[i];
1035 if (tile_elt) {
1036 eta_min = eta-weta*tile_elt->deta();
1037 eta_max = eta+weta*tile_elt->deta();
1038
1039 if ( tile_elt->eta()+tile_elt->deta()/2. > eta_min &&
1040 tile_elt->eta()-tile_elt->deta()/2. < eta_max) {
1041 phi_min = phi-wphi*tile_elt->dphi();
1042 phi_max = phi+wphi*tile_elt->dphi();
1043 double dphi1 = CaloPhiRange::diff(tile_elt->phi()+tile_elt->dphi()/2.,phi_min);
1044 double dphi2 = CaloPhiRange::diff(phi_max,tile_elt->phi()-tile_elt->dphi()/2);
1045
1046 if(dphi1 >=0. && dphi2 >= 0. ) {
1047 if (cell_list.empty()) {
1048 // Guess a good size, incl 3 samplings.
1049 cell_list.reserve (static_cast<int> (
1050 ((eta_max-eta_min) / tile_elt->deta()) *
1051 ((phi_max-phi_min) / tile_elt->dphi()) * 3));
1052 }
1053 cell_list.push_back(tile_elt->calo_hash());
1054 } // phi cut
1055 } // eta cut
1056 } // tile elt exisits
1057 }
1058 }
1059
1060}
1061
1062void CaloDetDescrManager_Base::cellsInZone(double eta_min, double eta_max,
1063 double phi_min, double phi_max,
1064 const CaloDetDescriptor* descr,
1065 std::vector<IdentifierHash> & cell_list) const
1066{
1067
1068 cell_list.clear();
1069
1070 if ( ! descr ) return;
1071 if ( eta_min >= eta_max ) return;
1072
1073// FCAL case : explicit loop over all cells to account for the fact that eta and phi are not independent
1074
1075 if (descr->is_lar_fcal()) {
1076 // std::cout << " in FCAl case descr etamin/max " << descr->reg_min() << " " << descr->reg_max() <<
1077 // " zone etamin/max " << eta_min << " " << eta_max << std::endl;
1078 if (descr->reg_min() > eta_max || descr->reg_max() < eta_min) return;
1079 Identifier regId = descr->identify();
1080 Identifier cellId;
1081 IdentifierHash caloCellHash;
1082 const CaloDetDescrElement* elt;
1083 IdentifierHash prevHash(0);
1084 // std::cout <<" neta,nphi " << descr->n_eta() << " " << descr->n_phi() << std::endl;
1085 for (int ieta=0; ieta<descr->n_eta(); ieta++) {
1086 for (int iphi=0; iphi<descr->n_phi(); iphi++) {
1087 cellId = m_cell_id->cell_id(regId, ieta, iphi);
1088 caloCellHash = m_cell_id->calo_cell_hash(cellId);
1089 // this is required because otherwise caloCellHash of unconnected channels with be the same as some connected channels (
1090 if (caloCellHash != prevHash) {
1091 prevHash=caloCellHash;
1092 elt = get_element (caloCellHash);
1093 if (elt) {
1094 if ( elt->eta()+elt->deta()/2. > eta_min &&
1095 elt->eta()-elt->deta()/2. < eta_max) {
1096
1097 double dphi1 = CaloPhiRange::diff(elt->phi()+elt->dphi()/2.,phi_min);
1098 double dphi2 = CaloPhiRange::diff(phi_max,elt->phi()-elt->dphi()/2);
1099
1100 if(dphi1 >=0. && dphi2 >= 0.) {
1101 cell_list.push_back(caloCellHash);
1102 //std::cout << " elt in ! eta= " << elt->eta() << " phi= " << elt->phi() << " " << ieta << " " << iphi << "hash Id " << caloCellHash << " id " << cellId << std::endl;
1103 } // phi cut
1104 } // eta cut
1105 } // if(elt)
1106 //else {
1107 // std::cout << " no FCAL elt for this cell " << ieta << " " << iphi << " " << cellId << " " << caloCellHash << std::endl;
1108 // }
1109 }
1110 } // loop over iphi
1111 } // loop over iea
1112 }
1113
1114// everything but FCAL
1115 else {
1116 if ( ! descr->is_in(eta_min,eta_max,phi_min,phi_max)) return;
1117
1118 double zone_min = eta_min;
1119 double zone_max = eta_max;
1120 int ieta_min = 0;
1121 int ieta_max = 0;
1122
1123 // loop will start at ieta_min-1 (included) and finish at ieta_max+1 (included)
1124 // ==> be careful at the edges of the descriptor.
1125 // check on which side we are ( for eta<0 channel ordering is swapped )
1126 if ( descr->calo_sign() > 0 ) {
1127
1128 if ( descr->reg_min() >= zone_min ){
1129 zone_min = descr->reg_min();
1130 ieta_min = 1;
1131 //std::cout << " POS ! setting zone_min to reg_min = " << zone_min << " and ieta_min to " << ieta_min << std::endl;
1132 }
1133 else {
1134 ieta_min = descr->eta_channel(zone_min);
1135 if (ieta_min < 0)
1136 ieta_min = 1;
1137 }
1138
1139 if ( descr->reg_max() <= zone_max ) {
1140 zone_max = descr->reg_max();
1141 ieta_max = descr->n_eta() -1;
1142 //std::cout << " POS ! setting zone_max to reg_max = " << zone_max << " and ieta_max to " << ieta_max << std::endl;
1143 }
1144 else {
1145 ieta_max = descr->eta_channel(zone_max);
1146 if (ieta_max < 1)
1147 ieta_max = descr->n_eta() - 1;
1148 }
1149
1150 }
1151 else {
1152
1153 if ( descr->reg_min() >= zone_min ){
1154 zone_min = descr->reg_min();
1155 ieta_max = descr->n_eta() - 1;
1156 //std::cout << " NEG ! setting zone_min to reg_min = " << zone_min << " and ieta_max to " << ieta_max << std::endl;
1157 }
1158 else {
1159 ieta_max = descr->eta_channel(zone_min);
1160 if (ieta_max < 1)
1161 ieta_max = descr->n_eta() - 1;
1162 }
1163
1164 if ( descr->reg_max() <= zone_max ) {
1165 zone_max = descr->reg_max();
1166 ieta_min = 1 ;
1167 //std::cout << " NEG ! setting zone_max to reg_max = " << zone_max << " and ieta_min to " << ieta_min << std::endl;
1168 }
1169 else {
1170 ieta_min = descr->eta_channel(zone_max - 0.0001);
1171 if (ieta_min < 0)
1172 ieta_min = 1;
1173 }
1174
1175 }
1176
1177
1178 // phi :
1179
1180 // for a full detector, the window limits cannot be outside... BUT :
1181 // for zones where phi_min is < 0 and phi_max > 0 ( around 0 ),
1182 // or phi_max is < 0 ( around M_PI )
1183 // the channel number iphi_min is larger than iphi_max and
1184 // the search will have to be done in 2 steps.
1185
1186 // for a subset ( H8 or H6 testbeams ), if the window is larger than the
1187 // module the min/max channel numbers will be -1 => mess in loops
1188 // ==> reduce the window size to the module size
1189
1190
1191 double zone_phi_min = CaloPhiRange::fix (phi_min);
1192 double zone_phi_max = CaloPhiRange::fix (phi_max);
1193
1194 // *** *** *** TEST BEAM!!! *** *** ***
1195 if (m_lar_geometry == "H8" || m_lar_geometry == "H6") {
1196 double margin = descr->dphi()*0.1;
1197
1198 // FIXME : ideal values are used here, this should NOT be !!!!
1199
1200 if ( descr->calo_phi_min() > zone_phi_min) zone_phi_min = descr->calo_phi_min() + margin;
1201 if ( descr->calo_phi_max() < zone_phi_max) zone_phi_max = descr->calo_phi_max() - margin;
1202 }
1203
1204 int iphi_min = descr->phi_channel(zone_phi_min);
1205 int iphi_max = descr->phi_channel(zone_phi_max);
1206
1207// add more safety in case of strips to protect against misalignment
1208 int reg_sampl=descr->getSampling(0);
1209 if (reg_sampl == CaloCell_ID::EMB1 || reg_sampl == CaloCell_ID::EME1) {
1210 ieta_min = ieta_min -1;
1211 ieta_max = ieta_max +1;
1212 }
1213
1214
1215 Identifier regId = descr->identify();
1216 Identifier cellId;
1217 IdentifierHash caloCellHash;
1218 const CaloDetDescrElement* elt;
1219
1220
1221 /*
1222 std::cout << " cellsInZone : eta ! reg " << descr->reg_min() << " " << descr->reg_max()
1223 << " zone " << zone_min << " " << zone_max
1224 << " channels " << ieta_min << " " << ieta_max << std::endl;
1225
1226 std::cout << " cellsInZone : phi ! reg " << descr->calo_phi_min() << " " << descr->calo_phi_max()
1227 << " zone " << zone_phi_min << " " << zone_phi_max
1228 << " channels " << iphi_min << " " << iphi_max << std::endl;
1229 */
1230
1231
1232 int reg_EtaMin = m_cell_id->eta_min (regId);
1233 int reg_EtaMax = m_cell_id->eta_max (regId);
1234 int reg_PhiMin = m_cell_id->phi_min (regId);
1235 if (reg_PhiMin<0) reg_PhiMin=0; // catch case where it is not defined for Tile
1236 int reg_PhiMax = m_cell_id->phi_max (regId);
1237
1238
1239 if ( iphi_min <= iphi_max && zone_phi_min <= zone_phi_max ) {
1240
1241 // The easy case : just make list a bit larger to avoid rounding effects
1242
1243 for ( int ieta = ieta_min-1 ; ieta <= ieta_max+1; ieta++ )
1244 for ( int iphi = iphi_min-1 ; iphi <= iphi_max+1; iphi++ )
1245 {
1246 if (ieta>=reg_EtaMin && ieta <=reg_EtaMax && iphi>=reg_PhiMin && iphi<=reg_PhiMax) {
1247 cellId = m_cell_id->cell_id(regId, ieta, iphi);
1248 caloCellHash = m_cell_id->calo_cell_hash(cellId);
1249 elt = get_element (caloCellHash);
1250 //std::cout << " case 1 : for ieta = " << ieta << " iphi = " << iphi << std::endl;
1251 if (elt
1252 && ( (elt->eta()+elt->deta()/2.) > zone_min + 0.00001 )
1253 && ( (elt->eta()-elt->deta()/2.) + 0.00001 < zone_max )
1254 && ( (elt->phi()+elt->dphi()/2.) > zone_phi_min + 0.00001 )
1255 && ( (elt->phi()-elt->dphi()/2.) + 0.00001 < zone_phi_max ) )
1256 {
1257 cell_list.push_back(caloCellHash);
1258 //std::cout << " elt in ! eta= " << elt->eta() << " phi= " << elt->phi() << " " << ieta << " " << iphi << std::endl;
1259 }
1260 //else
1261 //std::cout << " elt out ! eta= " << elt->eta() << " phi= " << elt->phi() << std::endl;
1262 }
1263 }
1264 }
1265 else if ( iphi_min <= iphi_max && zone_phi_min > zone_phi_max ) {
1266
1267 // we are around the -M_PI -> +M_PI discontinuity , no zone_phi_max cut
1268
1269 for ( int ieta = ieta_min-1 ; ieta <= ieta_max+1; ieta++ )
1270 for ( int iphi = iphi_min-1 ; iphi <= iphi_max+1; iphi++ )
1271 {
1272 if (ieta>=reg_EtaMin && ieta <=reg_EtaMax && iphi>=reg_PhiMin && iphi<=reg_PhiMax) {
1273 cellId = m_cell_id->cell_id(regId, ieta, iphi);
1274 caloCellHash = m_cell_id->calo_cell_hash(cellId);
1275 elt = get_element (caloCellHash);
1276 //std::cout << " case 2 : for ieta = " << ieta << " iphi = " << iphi << std::endl;
1277 if (elt
1278 && ( (elt->eta()+elt->deta()/2.) > zone_min + 0.00001 )
1279 && ( (elt->eta()-elt->deta()/2.) + 0.00001 < zone_max )
1280 && ( ( (elt->phi()+elt->dphi()/2.) > zone_phi_min + 0.00001 )
1281 || ( (elt->phi()-elt->dphi()/2.) + 0.00001 < zone_phi_max ) )
1282 )
1283 {
1284 cell_list.push_back(caloCellHash);
1285 //std::cout << " elt in ! eta= " << elt->eta() << " phi= " << elt->phi() << " " << ieta << " " << iphi << std::endl;
1286 }
1287 //else
1288 //std::cout << " elt out ! eta= " << elt->eta() << " phi= " << elt->phi() << std::endl;
1289 }
1290 }
1291 }
1292 else {
1293
1294 // iphi_min > iphi_max => we are around phi = 0
1295
1296 int nchmax = m_cell_id->phi_max(regId);
1297 // number of cells = nchmax + 1 ==> 0 to nchmax included
1298
1299 for ( int ieta = ieta_min-1 ; ieta <= ieta_max+1; ieta++ ) {
1300
1301 // first cells from min up to 2*M_PI
1302 for ( int iphi = iphi_min-1 ; iphi <= nchmax; iphi++ )
1303 {
1304 if (ieta>=reg_EtaMin && ieta <=reg_EtaMax && iphi>=reg_PhiMin && iphi<=reg_PhiMax) {
1305 cellId = m_cell_id->cell_id(regId, ieta, iphi);
1306 caloCellHash = m_cell_id->calo_cell_hash(cellId);
1307 elt = get_element (caloCellHash);
1308 //std::cout << " case 3 : for ieta = " << ieta << " iphi = " << iphi << std::endl;
1309 if (elt
1310 && ( (elt->eta()+elt->deta()/2.) > zone_min + 0.00001 )
1311 && ( (elt->eta()-elt->deta()/2.) + 0.00001 < zone_max )
1312 && ( (elt->phi()+elt->dphi()/2.) > zone_phi_min + 0.00001 )
1313 && ( (elt->phi()-elt->dphi()/2.) + 0.00001 < zone_phi_max ) )
1314 {
1315 cell_list.push_back(caloCellHash);
1316 //std::cout << " elt in ! eta= " << elt->eta() << " phi= " << elt->phi() << " " << ieta << " " << iphi << std::endl;
1317 }
1318 //else
1319 //std::cout << " elt out ! eta= " << elt->eta() << " phi= " << elt->phi() << std::endl;
1320 }
1321 }
1322 // now cells from 0 to min
1323 for ( int iphi = 0 ; iphi <= iphi_max+1; iphi++ )
1324 {
1325 if (ieta>=reg_EtaMin && ieta <=reg_EtaMax && iphi>=reg_PhiMin && iphi<=reg_PhiMax) {
1326 cellId = m_cell_id->cell_id(regId, ieta, iphi);
1327 caloCellHash = m_cell_id->calo_cell_hash(cellId);
1328 elt = get_element (caloCellHash);
1329 //std::cout << " case 4 : for ieta = " << ieta << " iphi = " << iphi << std::endl;
1330 if (elt
1331 && ( (elt->eta()+elt->deta()/2.) > zone_min + 0.00001 )
1332 && ( (elt->eta()-elt->deta()/2.) + 0.00001 < zone_max )
1333 && ( (elt->phi()+elt->dphi()/2.) > zone_phi_min + 0.00001 )
1334 && ( (elt->phi()-elt->dphi()/2.) + 0.00001 < zone_phi_max ) )
1335 {
1336 cell_list.push_back(caloCellHash);
1337 //std::cout << " elt in ! eta= " << elt->eta() << " phi= " << elt->phi() << " " << ieta << " " << iphi << std::endl;
1338 }
1339 //else
1340 //std::cout << " elt out ! eta= " << elt->eta() << " phi= " << elt->phi() << std::endl;
1341 }
1342 }
1343 }
1344 }
1345 } // if else FCAL
1346}
1347
1348bool CaloDetDescrManager_Base::is_in (double eta, double phi, CaloCell_ID::CaloSample sample, double& etadist )
1349const
1350{
1351 // note that this code does not work in the FCal as eta indices depend
1352 // on eta and phi
1353
1354 // I'm looking for the distance between the eta direction and the closest edge.
1355 // all in absolute value --> the sign will indicate if it is in or out.
1356
1357 bool result = false;
1358 etadist = 9999999.;
1359 double aeta = std::abs(eta);
1360
1361 // Tile first
1362 // Treat Tile Barrel and End Cap in different ways
1363 // -- Barrel
1364 if(sample == CaloCell_ID::TileBar0 ||
1365 sample == CaloCell_ID::TileBar1 ||
1366 sample == CaloCell_ID::TileBar2)
1367 {
1368 for(unsigned int i=0; i<m_tile_descr_vec.size(); i++)
1369 {
1370 const CaloDetDescriptor* reg = m_tile_descr_vec[i];
1371
1372 if(reg && reg->getSampling(0) == sample)
1373 {
1374 etadist = std::abs(aeta - reg->calo_eta_max());
1375 if(aeta <= reg->calo_eta_max()) result = true;
1376 break;
1377 }
1378 }
1379 }
1380 // End Cap
1381 else if(sample == CaloCell_ID::TileExt0 ||
1382 sample == CaloCell_ID::TileExt1 ||
1383 sample == CaloCell_ID::TileExt2 ||
1384 sample == CaloCell_ID::TileGap1 ||
1385 sample == CaloCell_ID::TileGap2 ||
1386 sample == CaloCell_ID::TileGap3)
1387 {
1388 for(unsigned int i=0; i<m_tile_descr_vec.size(); i++)
1389 {
1390 const CaloDetDescriptor* reg = m_tile_descr_vec[i];
1391
1392 if(reg && reg->getSampling(0) == sample)
1393 {
1394 double edgemin = std::abs(aeta - reg->calo_eta_min());
1395 double edgemax = std::abs(aeta - reg->calo_eta_max());
1396 if(edgemin < etadist) etadist = edgemin;
1397 if(edgemax < etadist) etadist = edgemax;
1398
1399 if(aeta >= reg->calo_eta_min() &&
1400 aeta <= reg->calo_eta_max()) result = true;
1401 break;
1402 }
1403 }
1404 }
1405 else {
1406 for ( unsigned int i=0; i<m_descr_vec.size(); i++ ) {
1407 const CaloDetDescriptor* reg = m_descr_vec[i];
1408 if ( reg ) {
1409 if ( reg->getSampling(0) == sample ) {
1410 if ( reg->eta_channel(eta) >=0 && reg->phi_channel(phi) >=0) result = true;
1411 double edgemin = std::abs( aeta - reg->reg_min() );
1412 double edgemax = std::abs( aeta - reg->reg_max() );
1413 if ( edgemin < etadist ) etadist = edgemin;
1414 if ( edgemax < etadist ) etadist = edgemax;
1415 }
1416 }
1417 }
1418 }
1419
1420 if (result) etadist = etadist*(-1.);
1421
1422 return result;
1423}
1424
1426 const bool barrel,
1427 const int sampling_or_module,
1429{
1430 if ( subCalo == CaloCell_ID::LAREM ) {
1431 if ( barrel ) {
1432 if (sampling_or_module == 0) sample = CaloCell_ID::PreSamplerB;
1433 if (sampling_or_module == 1) sample = CaloCell_ID::EMB1;
1434 if (sampling_or_module == 2) sample = CaloCell_ID::EMB2;
1435 if (sampling_or_module == 3) sample = CaloCell_ID::EMB3;
1436 } else {
1437 if (sampling_or_module == 0) sample = CaloCell_ID::PreSamplerE;
1438 if (sampling_or_module == 1) sample = CaloCell_ID::EME1;
1439 if (sampling_or_module == 2) sample = CaloCell_ID::EME2;
1440 if (sampling_or_module == 3) sample = CaloCell_ID::EME3;
1441 }
1442 return;
1443 }
1444 else if ( subCalo == CaloCell_ID::LARHEC ) {
1445 if (sampling_or_module == 0) sample = CaloCell_ID::HEC0;
1446 if (sampling_or_module == 1) sample = CaloCell_ID::HEC1;
1447 if (sampling_or_module == 2) sample = CaloCell_ID::HEC2;
1448 if (sampling_or_module == 3) sample = CaloCell_ID::HEC3;
1449 }
1450 else if ( subCalo == CaloCell_ID::LARFCAL ) {
1451 if (sampling_or_module == 0) sample = CaloCell_ID::FCAL0;
1452 if (sampling_or_module == 1) sample = CaloCell_ID::FCAL1;
1453 if (sampling_or_module == 2) sample = CaloCell_ID::FCAL2;
1454 }
1455 else if ( subCalo == CaloCell_ID::TILE ) {
1456 // For Tiles sampling_or_module has a different meaning :
1457 // assume the client meant the entrance of the Tiles and ignore the gap
1458 if ( barrel )
1459 sample = CaloCell_ID::TileBar0;
1460 else
1461 sample = CaloCell_ID::TileExt0;
1462 }
1463 else
1464 sample = CaloCell_ID::Unknown;
1465
1466}
1467
1469 bool& barrel,
1470 int& sampling_or_module,
1471 const CaloCell_ID::CaloSample sample)
1472{
1473 if ( sample == CaloCell_ID::PreSamplerB) {
1474 subCalo = CaloCell_ID::LAREM;
1475 barrel = true;
1476 sampling_or_module = 0;
1477 return;
1478 }
1479 else if ( sample == CaloCell_ID::EMB1) {
1480 subCalo = CaloCell_ID::LAREM;
1481 barrel = true;
1482 sampling_or_module = 1;
1483 return;
1484 }
1485 else if ( sample == CaloCell_ID::EMB2) {
1486 subCalo = CaloCell_ID::LAREM;
1487 barrel = true;
1488 sampling_or_module = 2;
1489 return;
1490 }
1491 else if ( sample == CaloCell_ID::EMB3) {
1492 subCalo = CaloCell_ID::LAREM;
1493 barrel = true;
1494 sampling_or_module = 3;
1495 return;
1496 }
1497 else if ( sample == CaloCell_ID::PreSamplerE) {
1498 subCalo = CaloCell_ID::LAREM;
1499 barrel = false;
1500 sampling_or_module = 0;
1501 return;
1502 }
1503 else if ( sample == CaloCell_ID::EME1) {
1504 subCalo = CaloCell_ID::LAREM;
1505 barrel = false;
1506 sampling_or_module = 1;
1507 return;
1508 }
1509 else if ( sample == CaloCell_ID::EME2) {
1510 subCalo = CaloCell_ID::LAREM;
1511 barrel = false;
1512 sampling_or_module = 2;
1513 return;
1514 }
1515 else if ( sample == CaloCell_ID::EME3) {
1516 subCalo = CaloCell_ID::LAREM;
1517 barrel = false;
1518 sampling_or_module = 3;
1519 return;
1520 }
1521 else if ( sample == CaloCell_ID::HEC0) {
1522 subCalo = CaloCell_ID::LARHEC;
1523 barrel = false;
1524 sampling_or_module = 0;
1525 return;
1526 }
1527 else if ( sample == CaloCell_ID::HEC1) {
1528 subCalo = CaloCell_ID::LARHEC;
1529 barrel = false;
1530 sampling_or_module = 1;
1531 return;
1532 }
1533 else if ( sample == CaloCell_ID::HEC2) {
1534 subCalo = CaloCell_ID::LARHEC;
1535 barrel = false;
1536 sampling_or_module = 2;
1537 return;
1538 }
1539 else if ( sample == CaloCell_ID::HEC3) {
1540 subCalo = CaloCell_ID::LARHEC;
1541 barrel = false;
1542 sampling_or_module = 3;
1543 return;
1544 }
1545 else if ( sample == CaloCell_ID::FCAL0) {
1546 subCalo = CaloCell_ID::LARFCAL;
1547 barrel = false;
1548 sampling_or_module = 0;
1549 return;
1550 }
1551 else if ( sample == CaloCell_ID::FCAL1) {
1552 subCalo = CaloCell_ID::LARFCAL;
1553 barrel = false;
1554 sampling_or_module = 1;
1555 return;
1556 }
1557 else if ( sample == CaloCell_ID::FCAL2) {
1558 subCalo = CaloCell_ID::LARFCAL;
1559 barrel = false;
1560 sampling_or_module = 2;
1561 return;
1562 }
1563 else if ( sample == CaloCell_ID::TileBar0 ||
1564 sample == CaloCell_ID::TileBar1 ||
1565 sample == CaloCell_ID::TileBar2 ||
1566 sample == CaloCell_ID::TileGap1 ||
1567 sample == CaloCell_ID::TileGap2 ||
1568 sample == CaloCell_ID::TileGap3 ) {
1569 subCalo = CaloCell_ID::TILE;
1570 barrel = true;
1571 sampling_or_module = 0;
1572 return;
1573 }
1574 else if ( sample == CaloCell_ID::TileExt0 ||
1575 sample == CaloCell_ID::TileExt1 ||
1576 sample == CaloCell_ID::TileExt2 ) {
1577 subCalo = CaloCell_ID::TILE;
1578 barrel = false;
1579 sampling_or_module = 0;
1580 return;
1581 }
1582 else {
1583 subCalo = CaloCell_ID::NOT_VALID;
1584 barrel = true;
1585 sampling_or_module = 0;
1586 }
1587
1588}
1589
1591{
1592 return static_cast<const CaloCell_ID*>
1594}
1595
1600
1601
1606
1607
1613
1618
1619
1624
1625
1626
1628{
1629 // For offline case, the manager does not own the tile elements.
1630 // But for the supercell case, we do.
1631 // So delete them here.
1632
1633 for (const CaloDetDescriptor* d : tile_descriptors_range()) {
1634 delete d;
1635 }
1636
1638 delete d;
1639 }
1640}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
Helper class for offline supercell identifiers.
Definition of CaloDetDescrManager.
Definition of CaloDetDescriptor.
CaloPhiRange class declaration.
Helper base class for offline cell identifiers.
Helper class for offline cell identifiers.
Definition CaloCell_ID.h:34
CaloCell_Base_ID::SUBCALO SUBCALO
Definition CaloCell_ID.h:50
CaloSampling::CaloSample CaloSample
Definition CaloCell_ID.h:53
Helper class for offline supercell identifiers.
This class groups all DetDescr information related to a CaloCell.
CaloCell_ID::CaloSample getSampling() const
cell sampling
bool is_lar_em_barrel() const
cell belongs to EM barrel
const CaloDetDescrElement * get_element_FCAL_raw(const CaloDetDescriptor *reg, double eta, double phi) const
LArFCAl private methode to get element from raw eta,phi.
static void build_sample(CaloCell_ID::SUBCALO subCalo, bool barrel, int sampling_or_module, CaloCell_ID::CaloSample &sample)
translate between the 2 ways to label a sub-detector:
CaloDetDescriptor * get_descriptor_nonconst(const Identifier &regionId)
get descriptor by region identifier, non-const version.
CaloDetDescrElement * get_element_nonconst(const Identifier &cellId)
get element by its identifier, non-const version.
calo_element_const_iterator element_begin() const
first element
std::ranges::subrange< calo_nonconst_element_const_iterator > calo_nonconst_element_range
calo_descr_const_iterator calo_descriptors_end() const
end of descriptors vector
calo_descr_const_iterator tile_descriptors_end() const
end of tile descriptors vector
const CaloDetDescrElement * get_element(const Identifier &cellId) const
get element by its identifier
calo_nonconst_element_range element_range_nonconst()
Range over element vector, with non-const elements.
std::string m_lar_geometry
LAr geometry label (full atlas/TB) for backwards compatibility.
std::vector< calo_element_const_iterator > m_subCalo_begin
offsets for subcalo's elements
void add_tile(CaloDetDescriptor *descr)
add tile descriptor to the tile descriptors vector
calo_descr_const_iterator tile_descriptors_begin() const
first tile descriptor (they are in separate vector)
CaloConstIteratorAdaptor< calo_element_vec::const_iterator > calo_element_const_iterator
std::vector< IdentifierHash > m_subCalo_min
offsets for subcalo's elements
const CaloDetDescriptor * get_descriptor_raw(CaloCell_ID::CaloSample sample, double eta, double phi) const
get descriptor by sample, eta and phi raw
CaloDetDescrElement * release_element(IdentifierHash hash)
calo_element_const_iterator element_end() const
end of element vector
void set_helper(const CaloCell_Base_ID *idHelper)
set calo Cell ID helper
std::vector< calo_element_const_iterator > m_subCalo_end
offsets for subcalo's elements
std::ranges::subrange< calo_element_const_iterator > calo_element_range
const CaloDetDescrElement * get_element_FCAL(const CaloDetDescriptor *reg, double eta, double phi) const
LArFCAl private methode to get element.
const CaloIdManager * m_calo_mgr
Calo ID Manager helper.
calo_descr_size tile_descriptors_size() const
number of tile descriptors
const CaloCell_Base_ID * getCaloCell_ID() const
get calo cell ID helper
calo_nonconst_descr_range calo_descriptors_range_nonconst()
Range over descriptors, with non-const elements.
void add(CaloDetDescrElement *element)
add Calo DD element to the elements vector
calo_descr_size calo_descriptors_size() const
number of descriptors
calo_descr_vec m_descr_vec
vector of descriptors
const CaloIdManager * getCalo_Mgr() const
get calo ID manager
void initialize()
initialization of the manager, used by the Converter when it creates the Manager
calo_nonconst_descr_range tile_descriptors_range_nonconst()
Range over tile descriptors, with non-const elements.
const CaloDetDescriptor * get_descriptor(const Identifier &regionId) const
get descriptor by region identifier
calo_element_vec::size_type calo_element_vec_size
static void decode_sample(CaloCell_ID::SUBCALO &subCalo, bool &barrel, int &sampling_or_module, CaloCell_ID::CaloSample sample)
translate between the 2 ways to label a sub-detector:
calo_element_range element_range() const
Range over element vector.
calo_descr_const_iterator calo_descriptors_begin() const
first descriptor in the vector
std::ranges::subrange< calo_nonconst_descr_const_iterator > calo_nonconst_descr_range
calo_element_vec m_element_vec
vector of Calo DD elements
const CaloDetDescrElement * get_element_raw(CaloCell_ID::CaloSample sample, double eta, double phi) const
Get element from raw quantities (to build real fixed size clusters)
calo_descr_vec::size_type calo_descr_size
const CaloCell_Base_ID * m_cell_id
Calo Cell ID helper.
void cellsInZone(double eta_min, double eta_max, double phi_min, double phi_max, std::vector< IdentifierHash > &cell_list) const
the only client is CaloCellList class
calo_descr_range calo_descriptors_range() const
Range over descriptors.
calo_element_vec_size element_size() const
total number of elements
void print() const
print out the contents
CaloConstIteratorAdaptor< calo_descr_vec::const_iterator > calo_descr_const_iterator
calo_descr_vec m_tile_descr_vec
vector of descriptors
std::ranges::subrange< calo_descr_const_iterator > calo_descr_range
calo_descr_range tile_descriptors_range() const
Range over tile descriptors.
CaloDetDescrManager_Base()
Default Constructor.
bool is_in(double eta, double phi, CaloCell_ID::CaloSample sample, double &etadist) const
return true if direction eta,phi crosses ANY of the corresponding descriptors
std::vector< IdentifierHash > m_subCalo_max
offsets for subcalo's elements
const CaloCell_ID * getCaloCell_ID() const
get calo cell ID helper
void set_helper(const CaloCell_ID *idHelper)
set calo Cell ID helper
This is a base class for LAr and Tile Descriptors The primary goal is to speed up loops over all the ...
This class initializes the Calo (LAr and Tile) offline identifiers.
static double fix(double phi)
static double diff(double phi1, double phi2)
simple phi1 - phi2 calculation, but result is fixed to respect range.
void set_helper(const CaloCell_SuperCell_ID *idHelper)
set calo Cell ID helper
const CaloCell_SuperCell_ID * getCaloCell_ID() const
get calo cell ID helper
This is a "hash" representation of an Identifier.