CMS 3D CMS Logo

eHCALMatrix.cc
Go to the documentation of this file.
4 
5 #include<algorithm>
6 #include<iostream>
7 
8 //#define EDM_ML_DEBUG
9 
10 namespace spr{
11  double eHCALmatrix(const HcalTopology* topology, const DetId& det0,
12  std::vector<PCaloHit>& hits, int ieta, int iphi,
13  bool includeHO, double hbThr, double heThr,
14  double hfThr, double hoThr, double tMin, double tMax, bool
15 #ifdef EDM_ML_DEBUG
16  debug
17 #endif
18  ) {
19 
20  HcalDetId hcid0(det0.rawId());
21  HcalDetId hcid(hcid0.subdet(),hcid0.ieta(),hcid0.iphi(),1);
22  DetId det(hcid.rawId());
23 #ifdef EDM_ML_DEBUG
24  if (debug) std::cout << "Inside eHCALmatrix " << 2*ieta+1 << "X" << 2*iphi+1 << " Inclusion of HO Flag " << includeHO << std::endl;
25 #endif
26  double energySum(0);
27  std::vector<DetId> dets(1,det);
28  std::vector<DetId> vdets = spr::matrixHCALIds(dets, topology, ieta, iphi, includeHO, false);
29 #ifdef EDM_ML_DEBUG
30  if (debug) {
31  std::cout << "matrixHCALIds::Total number of cells found is "
32  << vdets.size() << std::endl;
33  spr::debugHcalDets(0, vdets);
34  }
35 #endif
36  int khit(0);
37  for (unsigned int i=0; i<vdets.size(); i++) {
38  std::vector<std::vector<PCaloHit>::const_iterator> hit = spr::findHit(hits, vdets[i]);
39  double energy = 0;
40  int subdet = ((HcalDetId)(vdets[i].rawId())).subdet();
41  double eThr = spr::eHCALThreshold(subdet, hbThr, heThr, hfThr, hoThr);
42  for (unsigned int ihit=0; ihit<hit.size(); ihit++) {
43  if (hit[ihit] != hits.end()) {
44  khit++;
45 #ifdef EDM_ML_DEBUG
46  if (debug) std::cout << "energyHCAL:: Hit " << khit << " " << (HcalDetId)vdets[i] << " E " << hit[ihit]->energy() << " t " << hit[ihit]->time() << std::endl;
47 #endif
48  if (hit[ihit]->time() > tMin && hit[ihit]->time() < tMax) {
49  energy += hit[ihit]->energy();
50  }
51  }
52  }
53  if (energy>eThr) energySum += energy;
54  }
55 
56 #ifdef EDM_ML_DEBUG
57  if (debug) std::cout << "eHCALmatrix::Total energy " << energySum << std::endl;
58 #endif
59  return energySum;
60  }
61 
62  double eHCALmatrix(const CaloGeometry* geo, const HcalTopology* topology,
63  const DetId& det0, std::vector<PCaloHit>& hits, int ieta,
64  int iphi, HcalDetId& hotCell, bool includeHO, bool debug) {
65 
66  HcalDetId hcid0(det0.rawId());
67  HcalDetId hcid(hcid0.subdet(),hcid0.ieta(),hcid0.iphi(),1);
68  DetId det(hcid.rawId());
69  std::vector<DetId> dets(1,det);
70  std::vector<DetId> vdets = spr::matrixHCALIds(dets, topology, ieta, iphi, includeHO, debug);
71  hotCell = hcid0;
72 
73  std::vector<std::vector<PCaloHit>::const_iterator> hitlist;
74  for (unsigned int i=0; i<vdets.size(); i++) {
75  std::vector<std::vector<PCaloHit>::const_iterator> hit = spr::findHit(hits, vdets[i]);
76  hitlist.insert(hitlist.end(), hit.begin(), hit.end());
77  }
78 
79  double energySum(0);
80  for (unsigned int ihit=0; ihit<hitlist.size(); ihit++)
81  energySum += hitlist[ihit]->energy();
82 
83  // Get hotCell ID
84  dets.clear();
85  std::vector<double> energies;
86  for (unsigned int ihit=0; ihit<hitlist.size(); ihit++) {
87  double energy = hitlist[ihit]->energy();
88  HcalDetId id0 = HcalDetId(hitlist[ihit]->id());
89  if ((id0.subdet() != HcalOuter) || includeHO) {
90  HcalDetId id1(id0.subdet(),id0.ieta(),id0.iphi(),1);
91  bool found(false);
92  for (unsigned int idet=0; idet<dets.size(); ++idet) {
93  if (id1 == HcalDetId(dets[idet])) {
94  energies[idet] += energy;
95  found = true;
96  break;
97  }
98  }
99  if (!found) {
100  dets.push_back(DetId(id1));
101  energies.push_back(energy);
102  }
103  }
104  }
105  double energyMax(-99.);
106  for (unsigned int ihit=0; ihit<dets.size(); ihit++) {
107  if (energies[ihit] > energyMax) {
108  energyMax = energies[ihit];
109  hotCell = HcalDetId(dets[ihit]);
110  }
111  }
112  return energySum;
113  }
114 
115  void energyHCALCell(HcalDetId detId, std::vector<PCaloHit>& hits,
116  std::vector<std::pair<double,int> >& energyCell,
117  int maxDepth, double hbThr, double heThr, double hfThr,
118  double hoThr, double tMin, double tMax, bool
119 #ifdef EDM_ML_DEBUG
120  debug
121 #endif
122  ) {
123 
124  energyCell.clear();
125  int subdet = detId.subdet();
126  double eThr = spr::eHCALThreshold(subdet, hbThr, heThr, hfThr, hoThr);
127  bool hbhe = (detId.ietaAbs() == 16);
128  int depthHE = (maxDepth <= 6) ? 3 : 4;
129 #ifdef EDM_ML_DEBUG
130  if (debug)
131  std::cout << "energyHCALCell: input ID " << detId << " MaxDepth " << maxDepth << " Threshold (E) " << eThr << " (T) " << tMin << ":" << tMax << std::endl;
132 #endif
133  for (int i=0; i<maxDepth; i++) {
134  HcalSubdetector subdet0 = (hbhe) ? ((i+1 >= depthHE) ? HcalEndcap : HcalBarrel) : detId.subdet();
135  HcalDetId hcid(subdet0,detId.ieta(),detId.iphi(),i+1);
136  DetId det(hcid.rawId());
137  std::vector<std::vector<PCaloHit>::const_iterator> hit = spr::findHit(hits, det);
138  double energy(0);
139  for (unsigned int ihit=0; ihit<hit.size(); ++ihit) {
140  if (hit[ihit]->time() > tMin && hit[ihit]->time() < tMax)
141  energy += hit[ihit]->energy();
142 #ifdef EDM_ML_DEBUG
143  if (debug)
144  std::cout << "energyHCALCell:: Hit[" << ihit << "] " << hcid << " E " << hit[ihit]->energy() << " t " << hit[ihit]->time() << std::endl;
145 #endif
146  }
147 #ifdef EDM_ML_DEBUG
148  if (debug)
149  std::cout << "energyHCALCell:: Cell " << hcid << " E " << energy << " from " << hit.size() << " threshold " << eThr << std::endl;
150 #endif
151  if (energy>eThr && hit.size() > 0) {
152  energyCell.push_back(std::pair<double,int>(energy,i+1));
153  }
154  }
155 #ifdef EDM_ML_DEBUG
156  if (debug) {
157  std::cout << "energyHCALCell:: " << energyCell.size() << " entries from "
158  << maxDepth << " depths:";
159  for (unsigned int i=0; i<energyCell.size(); ++i) {
160  std::cout << " [" << i << "] (" << energyCell[i].first << ":"
161  << energyCell[i].second << ")";
162  }
163  std::cout << std::endl;
164  }
165 #endif
166  }
167 
168  HcalDetId getHotCell(std::vector<HBHERecHitCollection::const_iterator>& hit, bool includeHO, bool useRaw, bool) {
169 
170  std::vector<HcalDetId> dets;
171  std::vector<double> energies;
172  for (unsigned int ihit=0; ihit<hit.size(); ihit++) {
173  double energy = getRawEnergy(hit.at(ihit), useRaw);
174  HcalDetId id0 = hit.at(ihit)->id();
175  if ((id0.subdet() != HcalOuter) || includeHO) {
176  HcalDetId id1(id0.subdet(),id0.ieta(),id0.iphi(),1);
177  bool found(false);
178  for (unsigned int idet=0; idet<dets.size(); ++idet) {
179  if (id1 == dets[idet]) {
180  energies[idet] += energy;
181  found = true;
182  break;
183  }
184  }
185  if (!found) {
186  dets.push_back(id1);
187  energies.push_back(energy);
188  }
189  }
190  }
191  double energyMax(-99.);
192  HcalDetId hotCell;
193  for (unsigned int ihit=0; ihit<dets.size(); ihit++) {
194  if (energies[ihit] > energyMax) {
195  energyMax = energies[ihit];
196  hotCell = dets[ihit];
197  }
198  }
199  return hotCell;
200  }
201 
202  HcalDetId getHotCell(std::vector<std::vector<PCaloHit>::const_iterator>& hit, bool includeHO, bool useRaw, bool) {
203 
204  std::vector<HcalDetId> dets;
205  std::vector<double> energies;
206  for (unsigned int ihit=0; ihit<hit.size(); ihit++) {
207  double energy = hit.at(ihit)->energy();
208  HcalDetId id0 = getRawEnergy(hit.at(ihit),useRaw);
209  if ((id0.subdet() != HcalOuter) || includeHO) {
210  HcalDetId id1(id0.subdet(),id0.ieta(),id0.iphi(),1);
211  bool found(false);
212  for (unsigned int idet=0; idet<dets.size(); ++idet) {
213  if (id1 == dets[idet]) {
214  energies[idet] += energy;
215  found = true;
216  break;
217  }
218  }
219  if (!found) {
220  dets.push_back(id1);
221  energies.push_back(energy);
222  }
223  }
224  }
225  double energyMax(-99.);
226  HcalDetId hotCell;
227  for (unsigned int ihit=0; ihit<dets.size(); ihit++) {
228  if (energies[ihit] > energyMax) {
229  energyMax = energies[ihit];
230  hotCell = dets[ihit];
231  }
232  }
233  return hotCell;
234  }
235 
236  double eHCALThreshold(int subdet, double hbThr, double heThr, double hfThr,
237  double hoThr) {
238  double eThr = hbThr;
239  if (subdet == (int)(HcalEndcap)) eThr = heThr;
240  else if (subdet == (int)(HcalForward)) eThr = hfThr;
241  else if (subdet == (int)(HcalOuter)) eThr = hoThr;
242  return eThr;
243  }
244 }
#define EDM_ML_DEBUG
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
std::vector< typename T::const_iterator > findHit(edm::Handle< T > &hits, DetId thisDet, bool debug=false)
CaloTopology const * topology(0)
double eHCALmatrix(const HcalTopology *topology, const DetId &det, edm::Handle< T > &hits, int ieta, int iphi, bool includeHO=false, bool algoNew=true, double hbThr=-100, double heThr=-100, double hfThr=-100, double hoThr=-100, double tMin=-500, double tMax=500, bool useRaw=false, bool debug=false)
void debugHcalDets(unsigned int, std::vector< DetId > &)
Definition: DebugInfo.cc:42
double eHCALThreshold(int subdet, double hbThr=-100, double heThr=-100, double hfThr=-100, double hoThr=-100)
Definition: eHCALMatrix.cc:236
double getRawEnergy(HBHERecHitCollection::const_iterator hit, bool useRaw=false)
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
HcalSubdetector
Definition: HcalAssistant.h:31
void energyHCALCell(HcalDetId detId, edm::Handle< T > &hits, std::vector< std::pair< double, int > > &energyCell, int maxDepth=1, double hbThr=-100, double heThr=-100, double hfThr=-100, double hoThr=-100, double tMin=-500, double tMax=500, bool useRaw=false, bool debug=false)
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.cc:98
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
Definition: DetId.h:18
#define debug
Definition: HDRShower.cc:19
std::vector< DetId > matrixHCALIds(std::vector< DetId > &dets, const HcalTopology *topology, int ieta, int iphi, bool includeHO=false, bool debug=false)
double energySum(const DataFrame &df, int fs, int ls)
HcalDetId getHotCell(std::vector< HBHERecHitCollection::const_iterator > &hit, bool includeHO, bool useRaw=false, bool debug=false)
Definition: eHCALMatrix.cc:168