CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloCellManager.cc
Go to the documentation of this file.
1 /* class CaloCellManager
2  *
3  * Simple eta-phi cell structure manager, mimic calorimetric tower structure
4  *
5  *
6  */
7 
9 
10 #include "CLHEP/Units/defs.h"
11 #include "CLHEP/Units/SystemOfUnits.h"
12 
13 #include <iomanip>
14 
15 CaloCellManager::CaloCellManager(const unsigned int theVerbosity):
16  verbosity(theVerbosity)
17 {
18 
19  //initialize constants
20 
21  init();
22 
23  // build the calo cells identifiers
24 
25  builder();
26 
27 }
28 
30 
31  for (unsigned int i = 0; i < theCellCollection.size(); i++) {
32  delete theCellCollection[i];
33  }
34 
35 }
36 
38 
40  phiLimBar.reserve(nBarrelEta+1);
41  phiLimEnd.reserve(nEndcapEta+1);
42  phiLimFor.reserve(nForwardEta+1);
43 
44  // Barrel ranges
45 
46  double firstEta = 0.;
47  double etaBarrelBin = 0.087;
48  for (unsigned int ietabin = 0; ietabin <= nBarrelEta; ietabin++) {
49  etaLim.push_back(firstEta+ietabin*etaBarrelBin);
50  }
51 
52  double firstPhi = -180.;
53  double phiBarrelBin = (double)360/nBarrelPhi;
54  for (unsigned int iphibin = 0; iphibin <= nBarrelPhi; iphibin++) {
55  phiLimBar.push_back((firstPhi+iphibin*phiBarrelBin)*CLHEP::degree);
56  }
57 
58  // Endcap ranges (compromise wrt real CMS)
59 
60  firstEta = etaBarrelBin*nBarrelEta;
61  double etaEndcapBin = 0.131;
62  for (unsigned int ietabin = 1; ietabin <= nEndcapEta; ietabin++) {
63  etaLim.push_back(firstEta+ietabin*etaEndcapBin);
64  }
65  double phiEndcapBin = (double)360/nEndcapPhi;
66  for (unsigned int iphibin = 0; iphibin <= nEndcapPhi; iphibin++) {
67  phiLimEnd.push_back((firstPhi+iphibin*phiEndcapBin)*CLHEP::degree);
68  }
69 
70  // Forward ranges (compromise wrt real CMS)
71 
72  etaLim.push_back(3.139);
73  etaLim.push_back(3.314);
74  etaLim.push_back(3.489);
75  etaLim.push_back(3.664);
76  etaLim.push_back(3.839);
77  etaLim.push_back(4.013);
78  etaLim.push_back(4.191);
79  etaLim.push_back(4.363);
80  etaLim.push_back(4.538);
81  etaLim.push_back(4.716);
82  etaLim.push_back(4.889);
83  etaLim.push_back(5.191);
84 
85  double phiForwardBin = (double)360/nForwardPhi;
86  for (unsigned int iphibin = 0; iphibin <= nForwardPhi; iphibin++) {
87  phiLimFor.push_back((firstPhi+iphibin*phiForwardBin)*CLHEP::degree);
88  }
89 
90  if ( verbosity > 0 ) {
91  std::cout << "Number of eta ranges = " << nBarrelEta+nEndcapEta+nForwardEta << std::endl;
92  for (unsigned int i = 0; i < etaLim.size(); i++) {
93  std::cout << "Eta range limit # " << i << " = " << etaLim[i] << std::endl;
94  }
95  for (unsigned int i = 0; i < phiLimBar.size(); i++) {
96  std::cout << "Phi barrel range limit # " << i << " = " << phiLimBar[i] << std::endl;
97  }
98  for (unsigned int i = 0; i < phiLimEnd.size(); i++) {
99  std::cout << "Phi endcap range limit # " << i << " = " << phiLimEnd[i] << std::endl;
100  }
101  for (unsigned int i = 0; i < phiLimFor.size(); i++) {
102  std::cout << "Phi forward range limit # " << i << " = " << phiLimFor[i] << std::endl;
103  }
104  }
105 
106 }
107 
109 
110  theCellCollection.reserve(nCaloCell);
111 
112  // Barrel
113 
115 
116  for (unsigned int iphi = 0; iphi < nBarrelPhi; iphi++) {
117  for (unsigned int ieta = 0; ieta < nBarrelEta; ieta++) {
118  CaloCellId* thisCell = new CaloCellId(etaLim[ieta],etaLim[ieta+1],phiLimBar[iphi],phiLimBar[iphi+1],theSys);
119  theCellCollection.push_back(thisCell);
120  }
121  for (unsigned int ieta = 0; ieta < nBarrelEta; ieta++) {
122  CaloCellId* thisCell = new CaloCellId(-1.*etaLim[ieta+1],-1.*etaLim[ieta],phiLimBar[iphi],phiLimBar[iphi+1],theSys);
123  theCellCollection.push_back(thisCell);
124  }
125  }
126 
127  // Endcap
128 
129  theSys = CaloCellId::Endcap;
130 
131  for (unsigned int iphi = 0; iphi < nEndcapPhi; iphi++) {
132  for (unsigned int ieta = nBarrelEta; ieta < nBarrelEta+nEndcapEta; ieta++) {
133  CaloCellId* thisCell = new CaloCellId(etaLim[ieta],etaLim[ieta+1],phiLimEnd[iphi],phiLimEnd[iphi+1],theSys);
134  theCellCollection.push_back(thisCell);
135  }
136  for (unsigned int ieta = nBarrelEta; ieta < nBarrelEta+nEndcapEta; ieta++) {
137  CaloCellId* thisCell = new CaloCellId(-1.*etaLim[ieta+1],-1.*etaLim[ieta],phiLimEnd[iphi],phiLimEnd[iphi+1],theSys);
138  theCellCollection.push_back(thisCell);
139  }
140  }
141 
142  // Forward
143 
144  theSys = CaloCellId::Forward;
145 
146  for (unsigned int iphi = 0; iphi < nForwardPhi; iphi++) {
147  for (unsigned int ieta = nBarrelEta+nEndcapEta; ieta < nBarrelEta+nEndcapEta+nForwardEta; ieta++) {
148  CaloCellId* thisCell = new CaloCellId(etaLim[ieta],etaLim[ieta+1],phiLimFor[iphi],phiLimFor[iphi+1],theSys);
149  theCellCollection.push_back(thisCell);
150  }
151  for (unsigned int ieta = nBarrelEta+nEndcapEta; ieta < nBarrelEta+nEndcapEta+nForwardEta; ieta++) {
152  CaloCellId* thisCell = new CaloCellId(-1.*etaLim[ieta+1],-1.*etaLim[ieta],phiLimFor[iphi],phiLimFor[iphi+1],theSys);
153  theCellCollection.push_back(thisCell);
154  }
155  }
156 
157  if ( verbosity > 0 ) {
158  std::cout << "Number of cells = " << nCaloCell << std::endl;
159  for (unsigned int i = 0; i < theCellCollection.size(); i++) {
160  std::cout << "Cell # " << std::setfill(' ') << std::setw(4) << i << " = " << *(theCellCollection[i]) << std::endl;
161  }
162  }
163 
164 }
165 
166 unsigned int CaloCellManager::getCellIndexFromAngle(double eta, double phi){
167 
168  unsigned int theIndex = 1000000;
169  for ( unsigned int i = 0; i < theCellCollection.size(); i++) {
170  if ( theCellCollection[i]->isInCell(eta, phi) ) { theIndex = i; continue; }
171  }
172  return theIndex;
173 
174 }
175 
177 
178  if ( id < theCellCollection.size() ) { return theCellCollection[id]; }
179  return NULL;
180 
181 }
182 
183 std::vector<double> CaloCellManager::getEtaRanges(){
184 
185  std::vector<double> theEtaRanges(etaLim);
186  return theEtaRanges;
187 
188 }
int i
Definition: DBlmapReader.cc:9
static const unsigned int nForwardPhi
CaloCellManager(unsigned int theVerbosity)
static const unsigned int nForwardEta
#define NULL
Definition: scimark2.h:8
theIndex(0)
std::vector< double > etaLim
static const unsigned int nEndcapEta
unsigned int verbosity
std::vector< double > phiLimBar
std::vector< double > getEtaRanges()
CaloCellId * getCellFromIndex(unsigned int id)
static const unsigned int nCaloCell
std::vector< double > phiLimFor
static const unsigned int nBarrelEta
CaloCellCollection theCellCollection
virtual ~CaloCellManager()
Geom::Phi< T > phi() const
std::vector< double > phiLimEnd
tuple cout
Definition: gather_cfg.py:121
unsigned int getCellIndexFromAngle(double eta, double phi)
static const unsigned int nBarrelPhi
static const unsigned int nEndcapPhi