CMS 3D CMS Logo

EcalRingCalibrationTools.cc
Go to the documentation of this file.
3 
4 //Includes need to read from geometry
8 
10 
11 #include <iostream>
12 
13 //by default is not initialized, gets initialized at first call
16 std::once_flag EcalRingCalibrationTools::once_;
17 
21 
23 
25  if (id.det() != DetId::Ecal)
26  return -1;
27 
28  if (id.subdetId() == EcalBarrel) {
29  if (EBDetId(id).ieta() < 0)
30  return EBDetId(id).ieta() + 85;
31  else
32  return EBDetId(id).ieta() + 84;
33  }
34  if (id.subdetId() == EcalEndcap) {
35  //needed only for the EE, it can be replaced at some point with something smarter
37  throw std::logic_error(
38  "EcalRingCalibrationTools::initializeFromGeometry Ecal Endcap geometry is not initialized");
39 
40  EEDetId eid(id);
41  short endcapRingIndex = endcapRingIndex_[eid.ix() - 1][eid.iy() - 1] + N_RING_BARREL;
42  if (eid.zside() == 1)
43  endcapRingIndex += N_RING_ENDCAP / 2;
44  return endcapRingIndex;
45  }
46  return -1;
47 }
48 
50  if (id.det() != DetId::Ecal)
51  return -1;
52 
53  if (id.subdetId() == EcalBarrel) {
54  short module = 4 * (EBDetId(id).ism() - 1) + EBDetId(id).im() - 1;
55 
56  // std::cout<<"SM construction # : "<<EBDetId(id).ism() <<" SM installation # : "<< installationSMNumber[ EBDetId(id).ism() -1 ]<< "Xtal is Module :"<<module<< std::endl;
57  return module;
58  }
59  if (id.subdetId() == EcalEndcap) {
60  return -1;
61  }
62 
63  return -1;
64 }
65 
66 std::vector<DetId> EcalRingCalibrationTools::getDetIdsInRing(short etaIndex) {
67  std::vector<DetId> ringIds;
68  if (etaIndex < 0)
69  return ringIds;
70 
71  if (etaIndex < N_RING_BARREL) {
72  int k = 0;
73  if (etaIndex < 85)
74  k = -85 + etaIndex;
75  else
76  k = etaIndex - 84;
77 
79 
80  if (EBDetId::validDetId(k, iphi))
81  ringIds.push_back(EBDetId(k, iphi));
82  }
83 
84  else if (etaIndex < N_RING_TOTAL) {
85  //needed only for the EE, it can be replaced at some point maybe with something smarter
87  throw std::logic_error(
88  "EcalRingCalibrationTools::initializeFromGeometry Ecal Endcap geometry is not initialized");
89 
90  int zside = (etaIndex < N_RING_BARREL + (N_RING_ENDCAP / 2)) ? -1 : 1;
91  short eeEtaIndex = (etaIndex - N_RING_BARREL) % (N_RING_ENDCAP / 2);
92 
93  for (int ix = 0; ix < EEDetId::IX_MAX; ++ix)
94  for (int iy = 0; iy < EEDetId::IY_MAX; ++iy)
95  if (endcapRingIndex_[ix][iy] == eeEtaIndex)
96  ringIds.push_back(EEDetId(ix + 1, iy + 1, zside));
97  }
98 
99  return ringIds;
100 }
101 
103  std::vector<DetId> ringIds;
104 
105  for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta)
108  ringIds.push_back(EBDetId(ieta, iphi));
109 
110  //needed only for the EE, it can be replaced at some point maybe with something smarter
112  throw std::logic_error("EcalRingCalibrationTools::initializeFromGeometry Ecal Endcap geometry is not initialized");
113 
114  for (int ix = 0; ix < EEDetId::IX_MAX; ++ix)
115  for (int iy = 0; iy < EEDetId::IY_MAX; ++iy)
116  for (int zside = -1; zside < 2; zside += 2)
117  if (EEDetId::validDetId(ix + 1, iy + 1, zside))
118  ringIds.push_back(EEDetId(ix + 1, iy + 1, zside));
119 
120  // std::cout<<" [EcalRingCalibrationTools::getDetIdsInECAL()] DetId.size() is "<<ringIds.size()<<std::endl;
121 
122  return ringIds;
123 }
124 
125 std::vector<DetId> EcalRingCalibrationTools::getDetIdsInModule(short moduleIndex) {
126  std::vector<DetId> ringIds;
127  if (moduleIndex < 0)
128  return ringIds;
129 
130  short moduleBound[5] = {1, 26, 46, 66, 86};
131  if (moduleIndex < EcalRingCalibrationTools::N_MODULES_BARREL) {
133  short sm, moduleInSm, zsm;
134 
135  short minModuleiphi, maxModuleiphi, minModuleieta = 360, maxModuleieta = 0;
136 
137  // if(moduleIndex%4 != 0 )
138  sm = moduleIndex / 4 + 1;
139  // else
140  //sm = moduleIndex/4;//i.e. module 8 belongs to sm=3, not sm=3
141 
142  //if(moduleIndex%4 != 0 )
143  moduleInSm = moduleIndex % 4;
144  //else
145  //moduleInSm = 4;//moduleInSm is [1,2,3,4]
146 
147  if (moduleIndex > 71)
148  zsm = -1;
149  else
150  zsm = 1;
151 
152  minModuleiphi = ((sm - 1) % 18 + 1) * 20 - 19;
153  maxModuleiphi = ((sm - 1) % 18 + 1) * 20;
154 
155  if (zsm == 1) {
156  minModuleieta = moduleBound[moduleInSm];
157  maxModuleieta = moduleBound[moduleInSm + 1] - 1;
158  } else if (zsm == -1) {
159  minModuleieta = -moduleBound[moduleInSm + 1] + 1;
160  maxModuleieta = -moduleBound[moduleInSm];
161  }
163 
164  std::cout << "Called moduleIndex " << moduleIndex << std::endl;
165  std::cout << "minModuleieta " << minModuleieta << " maxModuleieta " << maxModuleieta << " minModuleiphi "
166  << minModuleiphi << " maxModuleiphi " << maxModuleiphi << std::endl;
167 
168  for (int ieta = minModuleieta; ieta <= maxModuleieta; ++ieta) {
169  for (int iphi = minModuleiphi; iphi <= maxModuleiphi; ++iphi) {
170  ringIds.push_back(EBDetId(ieta, iphi));
171 
172  // std::cout<<"Putting Xtal with ieta: "<<ieta<<" iphi "<<iphi<<" of SM "<<sm<<" into Module "<<moduleIndex<<std::endl;
173 
174  } //close loop on phi
175  } //close loop on eta
176  } //close if ( moduleInstallationNumber < 144)
177 
178  return ringIds;
179 }
180 
182  std::call_once(once_, EcalRingCalibrationTools::initializeFromGeometry, geometry);
183 }
184 
186  if (not geometry)
187  throw std::invalid_argument("EcalRingCalibrationTools::initializeFromGeometry called with a nullptr argument");
188 
189  float cellPosEta[EEDetId::IX_MAX][EEDetId::IY_MAX];
190  for (int ix = 0; ix < EEDetId::IX_MAX; ++ix)
191  for (int iy = 0; iy < EEDetId::IY_MAX; ++iy) {
192  cellPosEta[ix][iy] = -1.;
193  endcapRingIndex_[ix][iy] = -9;
194  }
195 
196  CaloSubdetectorGeometry const* endcapGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
197  if (not endcapGeometry)
198  throw std::logic_error("EcalRingCalibrationTools::initializeFromGeometry Ecal Endcap geometry not found");
199 
200  std::vector<DetId> const& endcapCells = geometry->getValidDetIds(DetId::Ecal, EcalEndcap);
201 
202  for (std::vector<DetId>::const_iterator endcapIt = endcapCells.begin(); endcapIt != endcapCells.end(); ++endcapIt) {
203  EEDetId ee(*endcapIt);
204  if (ee.zside() == -1)
205  continue; //Just using +side to fill absEta x,y map
206  auto cellGeometry = endcapGeometry->getGeometry(*endcapIt);
207  int ics = ee.ix() - 1;
208  int ips = ee.iy() - 1;
209  cellPosEta[ics][ips] = fabs(cellGeometry->getPosition().eta());
210  //std::cout<<"EE Xtal, |eta| is "<<fabs(cellGeometry->getPosition().eta())<<std::endl;
211  }
212 
213  float eta_ring[N_RING_ENDCAP / 2];
214  for (int ring = 0; ring < N_RING_ENDCAP / 2; ++ring)
215  eta_ring[ring] = cellPosEta[ring][50];
216 
217  double etaBoundary[N_RING_ENDCAP / 2 + 1];
218  etaBoundary[0] = 1.47;
219  etaBoundary[N_RING_ENDCAP / 2] = 4.0;
220 
221  for (int ring = 1; ring < N_RING_ENDCAP / 2; ++ring)
222  etaBoundary[ring] = (eta_ring[ring] + eta_ring[ring - 1]) / 2.;
223 
224  for (int ring = 0; ring < N_RING_ENDCAP / 2; ++ring) {
225  // std::cout<<"***********************EE ring: "<<ring<<" eta "<<(etaBoundary[ring] + etaBoundary[ring+1])/2.<<std::endl;
226  for (int ix = 0; ix < EEDetId::IX_MAX; ix++)
227  for (int iy = 0; iy < EEDetId::IY_MAX; iy++)
228  if (cellPosEta[ix][iy] > etaBoundary[ring] && cellPosEta[ix][iy] < etaBoundary[ring + 1]) {
229  endcapRingIndex_[ix][iy] = ring;
230  //std::cout<<"endcapRing_["<<ix+1<<"]["<<iy+1<<"] = "<<ring<<";"<<std::endl;
231  }
232  }
233 
234  std::vector<DetId> const& barrelCells = geometry->getValidDetIds(DetId::Ecal, EcalBarrel);
235 
236  for (std::vector<DetId>::const_iterator barrelIt = barrelCells.begin(); barrelIt != barrelCells.end(); ++barrelIt) {
237  EBDetId eb(*barrelIt);
238  }
239 
240  //EB
241 
243 }
static short endcapRingIndex_[EEDetId::IX_MAX][EEDetId::IY_MAX]
static short getModuleIndex(DetId aDetId)
static const int MIN_IPHI
Definition: EBDetId.h:135
int ix() const
Definition: EEDetId.h:77
static void setCaloGeometry(const CaloGeometry *geometry)
static std::atomic< bool > isInitializedFromGeometry_
static void initializeFromGeometry(CaloGeometry const *geometry)
int zside(DetId const &)
static short getRingIndex(DetId aDetId)
Retrieve the phi-ring index corresponding to a DetId.
static std::vector< DetId > getDetIdsInRing(short aRingIndex)
Retrieve the DetIds in a phi-ring.
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:59
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
int im() const
get the number of module inside the SM (1-4)
Definition: EBDetId.h:64
static constexpr short N_RING_ENDCAP
int zside() const
Definition: EEDetId.h:71
int iy() const
Definition: EEDetId.h:83
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
static std::vector< DetId > getDetIdsInModule(short int)
static const int IX_MAX
Definition: EEDetId.h:298
Definition: DetId.h:17
static constexpr short N_RING_BARREL
static const int MAX_IPHI
Definition: EBDetId.h:137
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
static const int MAX_IETA
Definition: EBDetId.h:136
static std::vector< DetId > getDetIdsInECAL()
static const int IY_MAX
Definition: EEDetId.h:302
static constexpr short N_RING_TOTAL
Definition: vlib.h:198
#define constexpr
static constexpr short N_MODULES_BARREL