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 
14 //by default is not initialized, gets initialized at first call
18 
19 
21 {
22  if (id.det() != DetId::Ecal)
23  return -1;
24 
25  if (id.subdetId() == EcalBarrel)
26  {
27  if(EBDetId(id).ieta()<0)
28  return EBDetId(id).ieta() + 85;
29  else
30  return EBDetId(id).ieta() + 84;
31 
32  }
33  if (id.subdetId() == EcalEndcap)
34  {
35  //needed only for the EE, it can be replaced at some point with something smarter
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 
75  std::vector<DetId> ringIds;
76  if (etaIndex < 0)
77  return ringIds;
78 
79  if (etaIndex < N_RING_BARREL)
80  {
81 
82  int k =0;
83  if (etaIndex<85)
84  k=-85 + etaIndex;
85  else
86  k= etaIndex - 84;
87 
88  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi)
89 
90  if (EBDetId::validDetId(k,iphi))
91  ringIds.push_back(EBDetId(k,iphi));
92  }
93 
94  else if (etaIndex < N_RING_TOTAL)
95  {
96  //needed only for the EE, it can be replaced at some point maybe with something smarter
99 
100  int zside= (etaIndex < N_RING_BARREL + (N_RING_ENDCAP/2) ) ? -1 : 1;
101  short eeEtaIndex = (etaIndex - N_RING_BARREL)%(N_RING_ENDCAP/2);
102 
103  for (int ix=0;ix<EEDetId::IX_MAX;++ix)
104  for (int iy=0;iy<EEDetId::IY_MAX;++iy)
105  if (endcapRingIndex_[ix][iy] == eeEtaIndex)
106  ringIds.push_back(EEDetId(ix+1,iy+1,zside));
107 
108  }
109 
110  return ringIds;
111 }
112 
114 {
115 
116  std::vector<DetId> ringIds;
117 
118  for(int ieta= - EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta)
119  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi)
120  if (EBDetId::validDetId(ieta,iphi))
121  ringIds.push_back(EBDetId(ieta,iphi));
122 
123  //needed only for the EE, it can be replaced at some point maybe with something smarter
126 
127  for (int ix=0;ix<EEDetId::IX_MAX;++ix)
128  for (int iy=0;iy<EEDetId::IY_MAX;++iy)
129  for(int zside = -1; zside<2; zside += 2)
130  if ( EEDetId::validDetId(ix+1,iy+1,zside) )
131  ringIds.push_back( EEDetId(ix+1,iy+1,zside) );
132 
133 
134  // std::cout<<" [EcalRingCalibrationTools::getDetIdsInECAL()] DetId.size() is "<<ringIds.size()<<std::endl;
135 
136  return ringIds;
137 }
138 
139 std::vector<DetId> EcalRingCalibrationTools::getDetIdsInModule(short moduleIndex)
140 {
141 
142  std::vector<DetId> ringIds;
143  if (moduleIndex < 0)
144  return ringIds;
145 
146  short moduleBound[5] = {1, 26, 46, 66, 86};
148  {
150  short sm, moduleInSm, zsm;
151 
152  short minModuleiphi, maxModuleiphi, minModuleieta=360,maxModuleieta=0;
153 
154  // if(moduleIndex%4 != 0 )
155  sm = moduleIndex / 4 + 1;
156  // else
157  //sm = moduleIndex/4;//i.e. module 8 belongs to sm=3, not sm=3
158 
159  //if(moduleIndex%4 != 0 )
160  moduleInSm = moduleIndex%4;
161  //else
162  //moduleInSm = 4;//moduleInSm is [1,2,3,4]
163 
164  if(moduleIndex > 71)
165  zsm = -1;
166  else
167  zsm = 1;
168 
169  minModuleiphi = ( (sm - 1) %18 + 1 ) *20 - 19;
170  maxModuleiphi = ( (sm - 1) %18 + 1 ) * 20;
171 
172  if(zsm == 1)
173  {
174  minModuleieta = moduleBound[ moduleInSm ];
175  maxModuleieta = moduleBound[ moduleInSm + 1 ] - 1;
176  }
177  else if(zsm == -1){
178  minModuleieta = - moduleBound[ moduleInSm + 1 ] + 1;
179  maxModuleieta = - moduleBound[ moduleInSm ];
180  }
182 
183 
184  std::cout<<"Called moduleIndex "<<moduleIndex<<std::endl;
185  std::cout<<"minModuleieta "<<minModuleieta<<" maxModuleieta "<<maxModuleieta<<" minModuleiphi "<<minModuleiphi<<" maxModuleiphi "<<maxModuleiphi<<std::endl;
186 
187  for(int ieta = minModuleieta; ieta <= maxModuleieta; ++ieta){
188  for(int iphi = minModuleiphi; iphi<= maxModuleiphi; ++iphi){
189 
190 
191  ringIds.push_back(EBDetId(ieta,iphi));
192 
193  // std::cout<<"Putting Xtal with ieta: "<<ieta<<" iphi "<<iphi<<" of SM "<<sm<<" into Module "<<moduleIndex<<std::endl;
194 
195 
196  }//close loop on phi
197  }//close loop on eta
198  }//close if ( moduleInstallationNumber < 144)
199 
200  return ringIds;
201 }
202 
204 {
205 
206  if (!caloGeometry_)
207  {
208  edm::LogError("EcalRingCalibrationTools") << "BIG ERROR::Initializing without geometry handle" ;
209  return;
210  }
211 
212  float m_cellPosEta[EEDetId::IX_MAX][EEDetId::IY_MAX];
213  for (int ix=0; ix<EEDetId::IX_MAX; ++ix)
214  for (int iy=0; iy<EEDetId::IY_MAX; ++iy)
215  {
216  m_cellPosEta[ix][iy] = -1.;
217  endcapRingIndex_[ix][iy]=-9;
218  }
219 
220 
222 
223  if (!endcapGeometry)
224  {
225  edm::LogError("EcalRingCalibrationTools") << "BIG ERROR::Ecal Endcap geometry not found" ;
226  return;
227  }
228 
229  const std::vector<DetId>& m_endcapCells= caloGeometry_->getValidDetIds(DetId::Ecal, EcalEndcap);
230 
231  for (std::vector<DetId>::const_iterator endcapIt = m_endcapCells.begin();
232  endcapIt!=m_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  const CaloCellGeometry *cellGeometry = endcapGeometry->getGeometry(*endcapIt) ;
238  int ics=ee.ix() - 1 ;
239  int ips=ee.iy() - 1 ;
240  m_cellPosEta[ics][ips] = fabs(cellGeometry->getPosition().eta());
241 
242  //std::cout<<"EE Xtal, |eta| is "<<fabs(cellGeometry->getPosition().eta())<<std::endl;
243 
244  }
245 
246  float eta_ring[N_RING_ENDCAP/2];
247  for (int ring=0; ring<N_RING_ENDCAP/2; ++ring)
248  eta_ring[ring]=m_cellPosEta[ring][50];
249 
250  double etaBoundary[N_RING_ENDCAP/2 + 1];
251  etaBoundary[0]=1.47;
252  etaBoundary[N_RING_ENDCAP/2]=4.0;
253 
254  for (int ring=1; ring<N_RING_ENDCAP/2; ++ring)
255  etaBoundary[ring]=(eta_ring[ring]+eta_ring[ring-1])/2.;
256 
257 
258 
259  for (int ring=0; ring<N_RING_ENDCAP/2; ring++){
260  // std::cout<<"***********************EE ring: "<<ring<<" eta "<<(etaBoundary[ring] + etaBoundary[ring+1])/2.<<std::endl;
261  for (int ix=0; ix<EEDetId::IX_MAX; ix++)
262  for (int iy=0; iy<EEDetId::IY_MAX; iy++)
263  if (m_cellPosEta[ix][iy]>etaBoundary[ring] && m_cellPosEta[ix][iy]<etaBoundary[ring+1])
264  {
265  endcapRingIndex_[ix][iy]=ring;
266  //std::cout<<"endcapRing_["<<ix+1<<"]["<<iy+1<<"] = "<<ring<<";"<<std::endl;
267  }
268  }
269 
270  const std::vector<DetId>& m_barrelCells= caloGeometry_->getValidDetIds(DetId::Ecal, EcalBarrel);
271 
272  for (std::vector<DetId>::const_iterator barrelIt = m_barrelCells.begin();
273  barrelIt!=m_barrelCells.end();
274  ++barrelIt)
275  {
276  EBDetId eb(*barrelIt);
277  }
278 
279 
280  //EB
281 
283 
284 }
285 
286 
static short endcapRingIndex_[EEDetId::IX_MAX][EEDetId::IY_MAX]
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:43
static short getModuleIndex(DetId aDetId)
static const CaloGeometry * caloGeometry_
static const int MIN_IPHI
Definition: EBDetId.h:143
int ix() const
Definition: EEDetId.h:77
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:62
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:125
int im() const
get the number of module inside the SM (1-4)
Definition: EBDetId.h:67
int zside() const
Definition: EEDetId.h:71
int iy() const
Definition: EEDetId.h:83
int ieta() const
get the crystal ieta
Definition: EBDetId.h:52
static std::vector< DetId > getDetIdsInModule(short int)
int k[5][pyjets_maxn]
static const int IX_MAX
Definition: EEDetId.h:303
Definition: DetId.h:20
static const int MAX_IPHI
Definition: EBDetId.h:145
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:249
static const int MAX_IETA
Definition: EBDetId.h:144
static std::vector< DetId > getDetIdsInECAL()
std::vector< DetId > getValidDetIds() const
Get the list of all valid detector ids.
Definition: CaloGeometry.cc:90
T eta() const
Definition: PV3DBase.h:76
tuple cout
Definition: gather_cfg.py:121
static const int IY_MAX
Definition: EEDetId.h:307
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
Definition: vlib.h:209