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