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