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 
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 
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 }
EBDetId::ieta
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
MessageLogger.h
EcalRingCalibrationTools::getRingIndex
static short getRingIndex(DetId aDetId)
Retrieve the phi-ring index corresponding to a DetId.
Definition: EcalRingCalibrationTools.cc:24
ecaldqm::zside
int zside(DetId const &)
Definition: EcalDQMCommonUtils.cc:189
EBDetId
Definition: EBDetId.h:17
geometry
Definition: geometry.py:1
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EBDetId::im
int im() const
get the number of module inside the SM (1-4)
Definition: EBDetId.h:64
EcalRingCalibrationTools::N_RING_BARREL
static constexpr short N_RING_BARREL
Definition: EcalRingCalibrationTools.h:38
EcalRingCalibrationTools::isInitializedFromGeometry_
static std::atomic< bool > isInitializedFromGeometry_
Definition: EcalRingCalibrationTools.h:48
EEDetId::ix
int ix() const
Definition: EEDetId.h:77
EcalBarrel
Definition: EcalSubdetector.h:10
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
DetId
Definition: DetId.h:17
CaloGeometry
Definition: CaloGeometry.h:21
EcalRingCalibrationTools::N_RING_ENDCAP
static constexpr short N_RING_ENDCAP
Definition: EcalRingCalibrationTools.h:39
EcalRingCalibrationTools::initializeFromGeometry
static void initializeFromGeometry(CaloGeometry const *geometry)
Definition: EcalRingCalibrationTools.cc:185
EBDetId::MAX_IPHI
static const int MAX_IPHI
Definition: EBDetId.h:137
EEDetId::IY_MAX
static const int IY_MAX
Definition: EEDetId.h:302
dqmdumpme.k
k
Definition: dqmdumpme.py:60
EEDetId::zside
int zside() const
Definition: EEDetId.h:71
EcalRingCalibrationTools::getDetIdsInRing
static std::vector< DetId > getDetIdsInRing(short aRingIndex)
Retrieve the DetIds in a phi-ring.
Definition: EcalRingCalibrationTools.cc:66
EEDetId
Definition: EEDetId.h:14
EcalEndcap
Definition: EcalSubdetector.h:10
EcalRingCalibrationTools::N_RING_TOTAL
static constexpr short N_RING_TOTAL
Definition: EcalRingCalibrationTools.h:37
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
CaloSubdetectorGeometry.h
EEDetId::IX_MAX
static const int IX_MAX
Definition: EEDetId.h:298
runTauDisplay.eid
eid
Definition: runTauDisplay.py:298
DetId::Ecal
Definition: DetId.h:27
EEDetId::iy
int iy() const
Definition: EEDetId.h:83
EBDetId::validDetId
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
CaloCellGeometry.h
EcalRingCalibrationTools::getDetIdsInModule
static std::vector< DetId > getDetIdsInModule(short int)
Definition: EcalRingCalibrationTools.cc:125
EcalRingCalibrationTools::once_
static std::once_flag once_
Definition: EcalRingCalibrationTools.h:53
DetId.h
EcalRingCalibrationTools::endcapRingIndex_
static short endcapRingIndex_[EEDetId::IX_MAX][EEDetId::IY_MAX]
Definition: EcalRingCalibrationTools.h:51
CaloGeometry.h
relativeConstraints.ring
ring
Definition: relativeConstraints.py:68
EcalRingCalibrationTools::getModuleIndex
static short getModuleIndex(DetId aDetId)
Definition: EcalRingCalibrationTools.cc:49
CaloSubdetectorGeometry
Definition: CaloSubdetectorGeometry.h:22
Ecal07UnpackerData_cfi.ics
ics
Definition: Ecal07UnpackerData_cfi.py:55
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
EBDetId::ism
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:59
EcalRingCalibrationTools::N_MODULES_BARREL
static constexpr short N_MODULES_BARREL
Definition: EcalRingCalibrationTools.h:41
EcalRingCalibrationTools.h
EcalRingCalibrationTools::setCaloGeometry
static void setCaloGeometry(const CaloGeometry *geometry)
Definition: EcalRingCalibrationTools.cc:181
EcalRingCalibrationTools::getDetIdsInECAL
static std::vector< DetId > getDetIdsInECAL()
Definition: EcalRingCalibrationTools.cc:102
EBDetId::MAX_IETA
static const int MAX_IETA
Definition: EBDetId.h:136
EBDetId::MIN_IPHI
static const int MIN_IPHI
Definition: EBDetId.h:135