CMS 3D CMS Logo

EcalGeomPhiSymHelper.cc
Go to the documentation of this file.
2 
4 
5 // Geometry
11 
12 //Channel status
13 
16 #include <fstream>
17 
18 void EcalGeomPhiSymHelper::setup(const CaloGeometry* geometry, const EcalChannelStatus* chStatus, int statusThresold) {
19  for (int ieta = 0; ieta < kBarlRings; ieta++)
20  nBads_barl[ieta] = 0;
21  for (int ring = 0; ring < kEndcEtaRings; ring++)
22  nBads_endc[ring] = 0;
23 
24  for (int ix = 0; ix < kEndcWedgesX; ix++) {
25  for (int iy = 0; iy < kEndcWedgesY; iy++) {
26  cellPhi_[ix][iy] = 0.;
27  cellArea_[ix][iy] = 0.;
28  endcapRing_[ix][iy] = -1;
29  }
30  }
31 
32  // loop over all barrel crystals
33  const std::vector<DetId>& barrelCells = geometry->getValidDetIds(DetId::Ecal, EcalBarrel);
34  std::vector<DetId>::const_iterator barrelIt;
35 
36  for (barrelIt = barrelCells.begin(); barrelIt != barrelCells.end(); barrelIt++) {
37  EBDetId eb(*barrelIt);
38 
39  int sign = eb.zside() > 0 ? 1 : 0;
40 
41  int chs = (*chStatus)[*barrelIt].getStatusCode() & 0x001F;
42  if (chs <= statusThresold)
43  goodCell_barl[abs(eb.ieta()) - 1][eb.iphi() - 1][sign] = true;
44 
45  if (!goodCell_barl[abs(eb.ieta()) - 1][eb.iphi() - 1][sign])
46  nBads_barl[abs(eb.ieta()) - 1]++;
47  }
48 
49  const CaloSubdetectorGeometry* endcapGeometry = geometry->getSubdetectorGeometry(DetId::Ecal, EcalEndcap);
50 
51  for (int ix = 0; ix < kEndcWedgesX; ix++) {
52  for (int iy = 0; iy < kEndcWedgesY; iy++) {
53  cellPos_[ix][iy] = GlobalPoint(0., 0., 0.);
54  cellPhi_[ix][iy] = 0.;
55  cellArea_[ix][iy] = 0.;
56  endcapRing_[ix][iy] = -1;
57  }
58  }
59 
60  const std::vector<DetId>& endcapCells = geometry->getValidDetIds(DetId::Ecal, EcalEndcap);
61  std::vector<DetId>::const_iterator endcapIt;
62  for (endcapIt = endcapCells.begin(); endcapIt != endcapCells.end(); endcapIt++) {
63  auto cellGeometry = endcapGeometry->getGeometry(*endcapIt);
64  EEDetId ee(*endcapIt);
65  int ix = ee.ix() - 1;
66  int iy = ee.iy() - 1;
67 
68  int sign = ee.zside() > 0 ? 1 : 0;
69 
70  // store all crystal positions
71  cellPos_[ix][iy] = cellGeometry->getPosition();
72  cellPhi_[ix][iy] = cellGeometry->getPosition().phi();
73 
74  // calculate and store eta-phi area for each crystal front face Shoelace formuls
75  const CaloCellGeometry::CornersVec& cellCorners(cellGeometry->getCorners());
76  cellArea_[ix][iy] = 0.;
77 
78  for (int i = 0; i < 4; i++) {
79  int iplus1 = i == 3 ? 0 : i + 1;
80  cellArea_[ix][iy] += cellCorners[i].eta() * float(cellCorners[iplus1].phi()) -
81  cellCorners[iplus1].eta() * float(cellCorners[i].phi());
82  }
83 
84  cellArea_[ix][iy] = fabs(cellArea_[ix][iy]) / 2.;
85  /*
86  const double deltaPhi =
87  (dynamic_cast<const EcalEndcapGeometry*>(endcapGeometry))->deltaPhi(ee);
88 
89  const double deltaEta =
90  (dynamic_cast<const EcalEndcapGeometry*>(endcapGeometry))->deltaEta(ee) ;
91 
92  cellArea_[ix][iy] = deltaEta*deltaPhi;
93 */
94  int chs = (*chStatus)[*endcapIt].getStatusCode() & 0x001F;
95  if (chs <= statusThresold)
96  goodCell_endc[ix][iy][sign] = true;
97  }
98 
99  // get eta boundaries for each endcap ring
100  etaBoundary_[0] = 1.479;
101  etaBoundary_[39] = 3.; //It was 4. !!!
102  for (int ring = 1; ring < kEndcEtaRings; ring++) {
103  double eta_ring_minus1 = cellPos_[ring - 1][50].eta();
104  double eta_ring = cellPos_[ring][50].eta();
105  etaBoundary_[ring] = (eta_ring + eta_ring_minus1) / 2.;
106  std::cout << "Eta ring " << ring << " : " << eta_ring << std::endl;
107  }
108 
109  // determine to which ring each endcap crystal belongs,
110  // the number of crystals in each ring,
111  // and the mean eta-phi area of the crystals in each ring
112 
113  for (int ring = 0; ring < kEndcEtaRings; ring++) {
114  nRing_[ring] = 0;
115  meanCellArea_[ring] = 0.;
116  for (int ix = 0; ix < kEndcWedgesX; ix++) {
117  for (int iy = 0; iy < kEndcWedgesY; iy++) {
118  if (fabs(cellPos_[ix][iy].eta()) > etaBoundary_[ring] &&
119  fabs(cellPos_[ix][iy].eta()) < etaBoundary_[ring + 1]) {
120  meanCellArea_[ring] += cellArea_[ix][iy];
121  endcapRing_[ix][iy] = ring;
122  nRing_[ring]++;
123 
124  for (int sign = 0; sign < kSides; sign++) {
125  if (!goodCell_endc[ix][iy][sign])
126  nBads_endc[ring]++;
127  } //sign
128 
129  } //if
130  } //ix
131  } //iy
132 
134 
135  } //ring
136 
137  // fill phi_endc[ip][ring] vector
138  for (int ring = 0; ring < kEndcEtaRings; ring++) {
139  for (int i = 0; i < kMaxEndciPhi; i++)
140  phi_endc_[i][ring] = 0.;
141 
142  float philast = -999.;
143  for (int ip = 0; ip < nRing_[ring]; ip++) {
144  float phimin = 999.;
145  for (int ix = 0; ix < kEndcWedgesX; ix++) {
146  for (int iy = 0; iy < kEndcWedgesY; iy++) {
147  if (endcapRing_[ix][iy] == ring) {
148  if (cellPhi_[ix][iy] < phimin && cellPhi_[ix][iy] > philast) {
149  phimin = cellPhi_[ix][iy];
150  } //if edges
151  } //if ring
152  } //iy
153  } //ix
154  phi_endc_[ip][ring] = phimin;
155  philast = phimin;
156  } //ip
157 
158  } //ring
159 
160  // Print out detid->ring association
161  std::fstream eeringsf("endcaprings.dat", std::ios::out);
162  for (endcapIt = endcapCells.begin(); endcapIt != endcapCells.end(); endcapIt++) {
163  EEDetId eedet(*endcapIt);
164  eeringsf << eedet.hashedIndex() << " " << endcapRing_[eedet.ix() - 1][eedet.iy() - 1] << " "
165  << cellPhi_[eedet.ix() - 1][eedet.iy() - 1] << " "
166  << cellArea_[eedet.ix() - 1][eedet.iy() - 1] / meanCellArea_[endcapRing_[eedet.ix() - 1][eedet.iy() - 1]]
167  << std::endl;
168  }
169 }
void setup(const CaloGeometry *geometry, const EcalChannelStatus *chstatus, int statusThreshold)
int nRing_[kEndcEtaRings]
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
int nBads_endc[kEndcEtaRings]
static const int kBarlRings
bool goodCell_barl[kBarlRings][kBarlWedges][kSides]
T eta() const
Definition: PV3DBase.h:73
int ix() const
Definition: EEDetId.h:77
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
GlobalPoint cellPos_[kEndcWedgesX][kEndcWedgesY]
static const int kMaxEndciPhi
static const int kSides
double phi_endc_[kMaxEndciPhi][kEndcEtaRings]
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
static const int kEndcWedgesX
int endcapRing_[kEndcWedgesX][kEndcWedgesY]
static const int kEndcEtaRings
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int zside() const
get the z-side of the crystal (1/-1)
Definition: EBDetId.h:45
virtual std::shared_ptr< const CaloCellGeometry > getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
int zside() const
Definition: EEDetId.h:71
double cellPhi_[kEndcWedgesX][kEndcWedgesY]
double meanCellArea_[kEndcEtaRings]
double cellArea_[kEndcWedgesX][kEndcWedgesY]
int hashedIndex() const
Definition: EEDetId.h:183
int nBads_barl[kBarlRings]
bool goodCell_endc[kEndcWedgesX][kEndcWedgesX][kSides]
int iy() const
Definition: EEDetId.h:83
double etaBoundary_[kEndcEtaRings+1]
static const int kEndcWedgesY