test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloTowerTopology.cc
Go to the documentation of this file.
3 #include <assert.h>
4 
6 
7  //get number of towers in each hcal subdet from hcaltopo
8  int nEtaHB, nEtaHE, nEtaHO, nEtaHF;
9  nEtaHB = hcaltopo->lastHBRing() - hcaltopo->firstHBRing() + 1;
10  nEtaHE = hcaltopo->lastHERing() - hcaltopo->firstHERing() + 1;
11  nEtaHO = hcaltopo->lastHORing() - hcaltopo->firstHORing() + 1;
12  nEtaHF = hcaltopo->lastHFRing() - hcaltopo->firstHFRing() + 1;
13 
14  //setup continuous ieta
15  firstHBRing_ = 1;
16  lastHBRing_ = firstHBRing_ + nEtaHB - 1;
17  firstHERing_ = lastHBRing_; //crossover
18  lastHERing_ = firstHERing_ + nEtaHE - 1;
19  firstHFRing_ = lastHERing_ + 1; //no crossover for CaloTowers; HF crossover cells go in the subsequent non-crossover HF tower
20  lastHFRing_ = firstHFRing_ + (nEtaHF - 1) - 1; //nEtaHF - 1 to account for no crossover
21  firstHORing_ = 1;
22  lastHORing_ = firstHORing_ + nEtaHO - 1;
23 
24  //translate phi segmentation boundaries into continuous ieta
29 
30  //number of etas per phi segmentation type
31  int nEtaSinglePhi_, nEtaDoublePhi_, nEtaQuadPhi_;
32  nEtaSinglePhi_ = firstHEDoublePhiRing_ - firstHBRing_;
33  nEtaDoublePhi_ = firstHFQuadPhiRing_ - firstHEDoublePhiRing_;
34  nEtaQuadPhi_ = lastHFRing_ - firstHFQuadPhiRing_ + 1; //include lastHFRing
35 
36  //total number of towers per phi segmentation type
37  nSinglePhi_ = nEtaSinglePhi_*72;
38  nDoublePhi_ = nEtaDoublePhi_*36;
39  nQuadPhi_ = nEtaQuadPhi_*18;
40 
41  //calculate maximum dense index size
43 
44 }
45 
46 //convert CaloTowerTopology ieta to HcalTopology ieta
47 int CaloTowerTopology::convertCTtoHcal(int ct_ieta) const {
48  if(ct_ieta <= lastHBRing_) return ct_ieta - firstHBRing_ + hcaltopo->firstHBRing();
49  else if(ct_ieta <= lastHERing_) return ct_ieta - firstHERing_ + hcaltopo->firstHERing();
50  else if(ct_ieta <= lastHFRing_) return ct_ieta - firstHFRing_ + hcaltopo->firstHFRing() + 1; //account for no HF crossover
51  else return 0; //if ct_ieta outside range
52 }
53 
54 //convert HcalTopology ieta to CaloTowerTopology ieta
55 int CaloTowerTopology::convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const {
56  if(subdet == HcalBarrel && hcal_ieta >= hcaltopo->firstHBRing() && hcal_ieta <= hcaltopo->lastHBRing()){
57  return hcal_ieta - hcaltopo->firstHBRing() + firstHBRing_;
58  }
59  else if(subdet == HcalEndcap && hcal_ieta >= hcaltopo->firstHERing() && hcal_ieta <= hcaltopo->lastHERing()){
60  return hcal_ieta - hcaltopo->firstHERing() + firstHERing_;
61  }
62  else if(subdet == HcalForward && hcal_ieta >= hcaltopo->firstHFRing() && hcal_ieta <= hcaltopo->lastHFRing()) {
63  if(hcal_ieta == hcaltopo->firstHFRing()) hcal_ieta++; //account for no HF crossover
64  return hcal_ieta - hcaltopo->firstHFRing() + firstHFRing_ - 1;
65  }
66  else if(subdet == HcalOuter && hcal_ieta >= hcaltopo->firstHORing() && hcal_ieta <= hcaltopo->lastHORing()) {
67  return hcal_ieta - hcaltopo->firstHORing() + firstHORing_;
68  }
69  else return 0; //if hcal_ieta outside range, or unknown subdet
70 }
71 
72 bool CaloTowerTopology::valid(const DetId& id) const {
73  assert(id.det()==DetId::Calo && id.subdetId()==CaloTowerDetId::SubdetId);
74  return validDetId(id);
75 }
76 
78  int ia = id.ietaAbs();
79  int ip = id.iphi();
80 
81  return ( (ia >= firstHBRing_) && (ia <= lastHFRing_) //eta range
82  && (ip >= 1) && (ip <= 72) //phi range
83  && ( (ia < firstHEDoublePhiRing_) //72 phi segments
84  || (ia < firstHFQuadPhiRing_ && (ip-1)%2 == 0) //36 phi segments, numbered 1,3,...,33,35
85  || (ia >= firstHFQuadPhiRing_ && (ip-3)%4 == 0) ) //18 phi segments, numbered 71,3,7,11,...
86  );
87 }
88 
89 //decreasing ieta
90 std::vector<DetId> CaloTowerTopology::east(const DetId& id) const {
91  std::vector<DetId> dd;
92  CaloTowerDetId tid(id);
93  int ieta=tid.ieta();
94  int iphi=tid.iphi();
95 
96  if (ieta==1) { //no ieta=0
97  ieta=-1;
98  } else if (ieta==firstHEDoublePhiRing_) { //currently double phi, going to single phi (positive eta) -> extra neighbor
99  ieta--;
100  dd.push_back(CaloTowerDetId(ieta,iphi+1));
101  } else if (ieta-1==-firstHEDoublePhiRing_) { //currently single phi, going to double phi (negative eta) -> change numbering
102  if ((iphi%2)==0) iphi--;
103  ieta--;
104  } else if (ieta==firstHFQuadPhiRing_) { //currently quad phi, going to double phi (positive eta) -> extra neighbor
105  ieta--;
106  dd.push_back(CaloTowerDetId(ieta,((iphi+1)%72)+1));
107  } else if (ieta-1==-firstHFQuadPhiRing_) { //currently double phi, going to quad phi (negative eta) -> change numbering
108  if (((iphi-1)%4)==0) {
109  if (iphi==1) iphi=71;
110  else iphi-=2;
111  }
112  ieta--;
113  } else { //general case
114  ieta--;
115  }
116 
117  if (ieta>=-lastHFRing_) dd.push_back(CaloTowerDetId(ieta,iphi));
118  return dd;
119 }
120 
121 //increasing ieta
122 std::vector<DetId> CaloTowerTopology::west(const DetId& id) const {
123  std::vector<DetId> dd;
124  CaloTowerDetId tid(id);
125 
126  int ieta=tid.ieta();
127  int iphi=tid.iphi();
128 
129  if (ieta==-1) { //no ieta=0
130  ieta=1;
131  } else if (ieta==-firstHEDoublePhiRing_) { //currently double phi, going to single phi (negative eta) -> extra neighbor
132  ieta++;
133  dd.push_back(CaloTowerDetId(ieta,iphi+1));
134  } else if (ieta+1==firstHEDoublePhiRing_) { //currently single phi, going to double phi (positive eta) -> change numbering
135  if ((iphi%2)==0) iphi--;
136  ieta++;
137  } else if (ieta==-firstHFQuadPhiRing_) { //currently quad phi, going to double phi (negative eta) -> extra neighbor
138  ieta++;
139  dd.push_back(CaloTowerDetId(ieta,((iphi+1)%72)+1));
140  } else if (ieta+1==firstHFQuadPhiRing_) { //currently double phi, going to quad phi (positive eta) -> change numbering
141  if (((iphi-1)%4)==0) {
142  if (iphi==1) iphi=71;
143  else iphi-=2;
144  }
145  ieta++;
146  } else {
147  ieta++;
148  }
149 
150  if (ieta<=lastHFRing_) dd.push_back(CaloTowerDetId(ieta,iphi));
151 
152  return dd;
153 }
154 
155 //increasing iphi
156 std::vector<DetId> CaloTowerTopology::north(const DetId& id) const {
157  CaloTowerDetId tid(id);
158  int iphi_n=tid.iphi()+1;
159  if (iphi_n>72) iphi_n=1;
160  if (tid.ietaAbs()>=firstHFQuadPhiRing_) { //18 phi segments, numbered 71,3,7,11,...
161  iphi_n+=3;
162  if (iphi_n>72) iphi_n-=72;
163  } else if (tid.ietaAbs()>=firstHEDoublePhiRing_ && (iphi_n%2)==0) { //36 phi segments, numbered 1,3,...,33,35
164  iphi_n++;
165  if (iphi_n>72) iphi_n-=72;
166  }
167 
168  std::vector<DetId> dd;
169  dd.push_back(CaloTowerDetId(tid.ieta(),iphi_n));
170  return dd;
171 }
172 
173 //decreasing iphi
174 std::vector<DetId> CaloTowerTopology::south(const DetId& id) const {
175  CaloTowerDetId tid(id);
176  int iphi_s=tid.iphi()-1;
177  if (iphi_s==0) iphi_s=72;
178  if (tid.ietaAbs()>=firstHFQuadPhiRing_) { //18 phi segments, numbered 71,3,7,11,...
179  iphi_s-=3;
180  if (iphi_s<=0) iphi_s+=72;
181  } else if (tid.ietaAbs()>=firstHEDoublePhiRing_ && (iphi_s%2)==0) { //36 phi segments, numbered 1,3,...,33,35
182  iphi_s--;
183  }
184 
185  std::vector<DetId> dd;
186  dd.push_back(CaloTowerDetId(tid.ieta(),iphi_s));
187  return dd;
188 }
189 
190 std::vector<DetId> CaloTowerTopology::up(const DetId& /*id*/) const {
191  return std::vector<DetId>();
192 }
193 
194 std::vector<DetId> CaloTowerTopology::down(const DetId& /*id*/) const {
195  return std::vector<DetId>();
196 }
197 
198 uint32_t CaloTowerTopology::denseIndex(const DetId& id) const {
199  CaloTowerDetId tid(id);
200  const int ie ( tid.ietaAbs() );
201  const int ip ( tid.iphi() - 1 ) ;
202 
203  return ( ( 0 > tid.zside() ? 0 : kSizeForDenseIndexing/2 ) +
204  ( ( firstHEDoublePhiRing_ > ie ? ( ie - 1 )*72 + ip :
205  ( firstHFQuadPhiRing_ > ie ? nSinglePhi_ + ( ie - firstHEDoublePhiRing_ )*36 + ip/2 :
206  nSinglePhi_ + nDoublePhi_ + ( ie - firstHFQuadPhiRing_ )*18 + ip/4 ) ) ) );
207 }
208 
210  const int iz ( din < kSizeForDenseIndexing/2 ? -1 : 1 ) ;
211  din %= kSizeForDenseIndexing/2 ;
212  const int ie ( nSinglePhi_ + nDoublePhi_ - 1 < (int)(din) ?
214  ( nSinglePhi_ - 1 < (int)din ?
215  firstHEDoublePhiRing_ + ( din - nSinglePhi_ )/36 :
216  din/72 + 1 ) ) ;
217 
218  const int ip ( nSinglePhi_ + nDoublePhi_ - 1 < (int)(din) ?
219  ( ( din - nSinglePhi_ - nDoublePhi_ )%18 )*4 + 3 :
220  ( nSinglePhi_ - 1 < (int)(din) ?
221  ( ( din - nSinglePhi_ )%36 )*2 + 1 :
222  din%72 + 1 ) ) ;
223 
224  return ( validDenseIndex( din ) ? CaloTowerDetId( iz*ie, ip ) : CaloTowerDetId() ) ;
225 }
int firstHFRing() const
Definition: HcalTopology.h:87
virtual std::vector< DetId > down(const DetId &id) const
virtual std::vector< DetId > south(const DetId &id) const
int convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const
virtual bool valid(const DetId &id) const
is this detid present in the Topology?
int ietaAbs() const
get the absolute value of the tower ieta
CaloTopology const * topology(0)
assert(m_qm.get())
int firstHBRing() const
Definition: HcalTopology.h:83
int lastHBRing() const
Definition: HcalTopology.h:84
uint32_t kSizeForDenseIndexing
CaloTowerTopology(const HcalTopology *topology)
standard constructor
CaloTowerDetId detIdFromDenseIndex(uint32_t din) const
static const int SubdetId
virtual std::vector< DetId > north(const DetId &id) const
int lastHFRing() const
Definition: HcalTopology.h:88
int iphi() const
get the tower iphi
HcalSubdetector
Definition: HcalAssistant.h:31
int firstHORing() const
Definition: HcalTopology.h:89
int firstHEDoublePhiRing() const
Definition: HcalTopology.h:92
const HcalTopology * hcaltopo
uint32_t denseIndex(const DetId &id) const
Definition: DetId.h:18
virtual std::vector< DetId > west(const DetId &id) const
int firstHERing() const
Definition: HcalTopology.h:85
int zside() const
get the z-side of the tower (1/-1)
int firstHFQuadPhiRing() const
Definition: HcalTopology.h:94
virtual std::vector< DetId > east(const DetId &id) const
int convertCTtoHcal(int ct_ieta) const
int firstHEQuadPhiRing() const
Definition: HcalTopology.h:93
virtual std::vector< DetId > up(const DetId &id) const
int ieta() const
get the tower ieta
int lastHORing() const
Definition: HcalTopology.h:90
bool validDenseIndex(uint32_t din) const
virtual bool validDetId(const CaloTowerDetId &id) const
int lastHERing() const
Definition: HcalTopology.h:86