CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalTrigTowerGeometry.cc
Go to the documentation of this file.
5 
6 #include <iostream>
7 #include <cassert>
8 
10  useShortFibers_=true;
11  useHFQuadPhiRings_=true;
12 }
13 
14 void HcalTrigTowerGeometry::setupHF(bool useShortFibers, bool useQuadRings) {
15  useShortFibers_=useShortFibers;
16  useHFQuadPhiRings_=useQuadRings;
17 }
18 
19 std::vector<HcalTrigTowerDetId>
21 
22  std::vector<HcalTrigTowerDetId> results;
23 
24  if(cellId.subdet() == HcalForward) {
25  // short fibers don't count
26  if(cellId.depth() == 1 || useShortFibers_) {
27  // first do eta
28  int hfRing = cellId.ietaAbs();
29  int ieta = firstHFTower();
30  // find the tower that contains this ring
31  while(hfRing >= firstHFRingInTower(ieta+1)) {
32  ++ieta;
33  }
34 
35  ieta *= cellId.zside();
36 
37  // now for phi
38  // HF towers are quad, 18 in phi.
39  // go two cells per trigger tower.
40  int iphi = (((cellId.iphi()+1)/4) * 4 + 1)%72; // 71+1 --> 1, 3+5 --> 5
42  results.push_back( HcalTrigTowerDetId(ieta, iphi) );
43  }
44 
45  } else {
46  // the first twenty rings are one-to-one
47  if(cellId.ietaAbs() < theTopology.firstHEDoublePhiRing()) {
48  results.push_back( HcalTrigTowerDetId(cellId.ieta(), cellId.iphi()) );
49  } else {
50  // the remaining rings are two-to-one in phi
51  int iphi1 = cellId.iphi();
52  int ieta = cellId.ieta();
53  // the last eta ring in HE is split. Recombine.
54  if(ieta == theTopology.lastHERing()) --ieta;
55  if(ieta == -theTopology.lastHERing()) ++ieta;
56 
57  results.push_back( HcalTrigTowerDetId(ieta, iphi1) );
58  results.push_back( HcalTrigTowerDetId(ieta, iphi1+1) );
59  }
60  }
61 
62  return results;
63 }
64 
65 
66 std::vector<HcalDetId>
67 HcalTrigTowerGeometry::detIds(const HcalTrigTowerDetId & hcalTrigTowerDetId) const {
68  // Written, tested by E. Berry (Princeton)
69  std::vector<HcalDetId> results;
70 
71  int tower_ieta = hcalTrigTowerDetId.ieta();
72  int tower_iphi = hcalTrigTowerDetId.iphi();
73 
74  int cell_ieta = tower_ieta;
75  int cell_iphi = tower_iphi;
76 
77  int min_depth, n_depths;
78 
79  // HB
80 
81  if (abs(cell_ieta) <= theTopology.lastHBRing()){
82  theTopology.depthBinInformation(HcalBarrel, abs(tower_ieta), n_depths, min_depth);
83  for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
84  results.push_back(HcalDetId(HcalBarrel,cell_ieta,cell_iphi,cell_depth));
85  }
86 
87  // HO
88 
89  if (abs(cell_ieta) <= theTopology.lastHORing()){
90  theTopology.depthBinInformation(HcalOuter , abs(tower_ieta), n_depths, min_depth);
91  for (int ho_depth = min_depth; ho_depth <= min_depth + n_depths - 1; ho_depth++)
92  results.push_back(HcalDetId(HcalOuter, cell_ieta,cell_iphi,ho_depth));
93  }
94 
95  // HE
96 
97  if (abs(cell_ieta) >= theTopology.firstHERing() &&
98  abs(cell_ieta) < theTopology.lastHERing()){
99 
100  theTopology.depthBinInformation(HcalEndcap, abs(tower_ieta), n_depths, min_depth);
101 
102  // Special for double-phi cells
103  if (abs(cell_ieta) >= theTopology.firstHEDoublePhiRing())
104  if (tower_iphi%2 == 0) cell_iphi = tower_iphi - 1;
105 
106  for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
107  results.push_back(HcalDetId(HcalEndcap, cell_ieta, cell_iphi, cell_depth));
108 
109  // Special for split-eta cells
110  if (abs(tower_ieta) == 28){
111  theTopology.depthBinInformation(HcalEndcap, abs(tower_ieta)+1, n_depths, min_depth);
112  for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++){
113  if (tower_ieta < 0) results.push_back(HcalDetId(HcalEndcap, tower_ieta - 1, cell_iphi, cell_depth));
114  if (tower_ieta > 0) results.push_back(HcalDetId(HcalEndcap, tower_ieta + 1, cell_iphi, cell_depth));
115  }
116  }
117 
118  }
119 
120  // HF
121 
122  if (abs(cell_ieta) >= theTopology.firstHFRing()){
123 
124  int HfTowerPhiSize = 72 / nPhiBins(tower_ieta);
125  int HfTowerEtaSize = hfTowerEtaSize(tower_ieta);
126  int FirstHFRingInTower = firstHFRingInTower(abs(tower_ieta));
127 
128  for (int iHFTowerPhiSegment = 0; iHFTowerPhiSegment < HfTowerPhiSize; iHFTowerPhiSegment++){
129 
130  cell_iphi = (tower_iphi / HfTowerPhiSize) * HfTowerPhiSize; // Find the minimum phi segment
131  cell_iphi -= 2; // The first trigger tower starts at HCAL iphi = 71, not HCAL iphi = 1
132  cell_iphi += iHFTowerPhiSegment; // Get all of the HCAL iphi values in this trigger tower
133  cell_iphi += 72; // Don't want to take the mod of a negative number
134  cell_iphi = cell_iphi % 72; // There are, at most, 72 cells.
135  cell_iphi += 1; // There is no cell at iphi = 0
136 
137  if (cell_iphi%2 == 0) continue; // These cells don't exist.
138 
139  for (int iHFTowerEtaSegment = 0; iHFTowerEtaSegment < HfTowerEtaSize; iHFTowerEtaSegment++){
140 
141  cell_ieta = FirstHFRingInTower + iHFTowerEtaSegment;
142 
143  if (cell_ieta >= 40 && cell_iphi%4 == 1) continue; // These cells don't exist.
144 
145  theTopology.depthBinInformation(HcalForward, cell_ieta, n_depths, min_depth);
146 
147  // Negative tower_ieta -> negative cell_ieta
148  if (tower_ieta < 0) cell_ieta *= -1;
149 
150  for (int cell_depth = min_depth; cell_depth <= min_depth + n_depths - 1; cell_depth++)
151  results.push_back(HcalDetId(HcalForward, cell_ieta, cell_iphi, cell_depth));
152 
153  }
154  }
155  }
156 
157  return results;
158 }
159 
160 
162  int ietaAbs = abs(ieta);
163  assert(ietaAbs >= firstHFTower() && ietaAbs <= nTowers());
164  // the first three come from rings 29-31, 32-34, 35-37. The last has 4 rings: 38-41
165  return (ietaAbs == nTowers()) ? 4 : 3;
166 }
167 
168 
170  // count up to the correct HF ring
171  int inputTower = abs(ietaTower);
173  for(int iTower = firstHFTower(); iTower != inputTower; ++iTower) {
174  result += hfTowerEtaSize(iTower);
175  }
176 
177  // negative in, negative out.
178  if(ietaTower < 0) result *= -1;
179  return result;
180 }
181 
182 
183 void HcalTrigTowerGeometry::towerEtaBounds(int ieta, double & eta1, double & eta2) const {
184  int ietaAbs = abs(ieta);
185  if(ietaAbs < firstHFTower()) {
186  eta1 = theHBHEEtaBounds[ietaAbs-1];
187  eta2 = theHBHEEtaBounds[ietaAbs];
188  // the last tower is split, so get tower 29, too
189  if(ietaAbs == theTopology.lastHERing()-1) {
190  eta2 = theHBHEEtaBounds[ietaAbs+1];
191  }
192  } else {
193  // count from 0
194  int hfIndex = firstHFRingInTower(ietaAbs) - theTopology.firstHFRing();
195  eta1 = theHFEtaBounds[hfIndex];
196  eta2 = theHFEtaBounds[hfIndex + hfTowerEtaSize(ieta)];
197  }
198 
199  // get the signs and order right
200  if(ieta < 0) {
201  double tmp = eta1;
202  eta1 = -eta2;
203  eta2 = -tmp;
204  }
205 }
int firstHFRing() const
Definition: HcalTopology.h:65
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:32
std::vector< HcalTrigTowerDetId > towerIds(const HcalDetId &cellId) const
the mapping to and from DetIds
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:34
#define abs(x)
Definition: mlp_lapack.h:159
int lastHBRing() const
Definition: HcalTopology.h:62
int ieta() const
get the tower ieta
int hfTowerEtaSize(int ieta) const
int nPhiBins(int ieta) const
an interface for CaloSubdetectorGeometry
int depth() const
get the tower depth
Definition: HcalDetId.h:42
tuple result
Definition: query.py:137
int ieta() const
get the cell ieta
Definition: HcalDetId.h:38
void depthBinInformation(HcalSubdetector subdet, int etaRing, int &nDepthBins, int &startingBin) const
finds the number of depth bins and which is the number to start with
int firstHEDoublePhiRing() const
Definition: HcalTopology.h:70
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:36
int iphi() const
get the cell iphi
Definition: HcalDetId.h:40
void towerEtaBounds(int ieta, double &eta1, double &eta2) const
where this tower begins and ends in eta
int firstHFRingInTower(int ietaTower) const
since the towers are irregular in eta in HF
static const double theHFEtaBounds[]
int firstHERing() const
Definition: HcalTopology.h:63
int firstHFQuadPhiRing() const
Definition: HcalTopology.h:71
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
static const double theHBHEEtaBounds[]
int lastHORing() const
Definition: HcalTopology.h:68
int iphi() const
get the tower iphi
int lastHERing() const
Definition: HcalTopology.h:64
void setupHF(bool useShortFibers, bool useQuadRings)
std::vector< HcalDetId > detIds(const HcalTrigTowerDetId &) const