test
CMS 3D CMS Logo

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