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, int depthHE, 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 #ifdef EDM_ML_DEBUG
129  if (debug)
130  std::cout << "energyHCALCell: input ID " << detId << " MaxDepth " << maxDepth << " Threshold (E) " << eThr << " (T) " << tMin << ":" << tMax << std::endl;
131 #endif
132  for (int i=0; i<maxDepth; i++) {
133  HcalSubdetector subdet0 = (hbhe) ? ((i+1 >= depthHE) ? HcalEndcap : HcalBarrel) : detId.subdet();
134  HcalDetId hcid(subdet0,detId.ieta(),detId.iphi(),i+1);
135  DetId det(hcid.rawId());
136  std::vector<std::vector<PCaloHit>::const_iterator> hit = spr::findHit(hits, det);
137  double energy(0);
138  for (unsigned int ihit=0; ihit<hit.size(); ++ihit) {
139  if (hit[ihit]->time() > tMin && hit[ihit]->time() < tMax)
140  energy += hit[ihit]->energy();
141 #ifdef EDM_ML_DEBUG
142  if (debug)
143  std::cout << "energyHCALCell:: Hit[" << ihit << "] " << hcid << " E " << hit[ihit]->energy() << " t " << hit[ihit]->time() << std::endl;
144 #endif
145  }
146 #ifdef EDM_ML_DEBUG
147  if (debug)
148  std::cout << "energyHCALCell:: Cell " << hcid << " E " << energy << " from " << hit.size() << " threshold " << eThr << std::endl;
149 #endif
150  if (energy>eThr && !hit.empty()) {
151  energyCell.push_back(std::pair<double,int>(energy,i+1));
152  }
153  }
154 #ifdef EDM_ML_DEBUG
155  if (debug) {
156  std::cout << "energyHCALCell:: " << energyCell.size() << " entries from "
157  << maxDepth << " depths:";
158  for (unsigned int i=0; i<energyCell.size(); ++i) {
159  std::cout << " [" << i << "] (" << energyCell[i].first << ":"
160  << energyCell[i].second << ")";
161  }
162  std::cout << std::endl;
163  }
164 #endif
165  }
166 
167  HcalDetId getHotCell(std::vector<HBHERecHitCollection::const_iterator>& hit, bool includeHO, bool useRaw, bool) {
168 
169  std::vector<HcalDetId> dets;
170  std::vector<double> energies;
171  for (unsigned int ihit=0; ihit<hit.size(); ihit++) {
172  double energy = getRawEnergy(hit.at(ihit), useRaw);
173  HcalDetId id0 = hit.at(ihit)->id();
174  if ((id0.subdet() != HcalOuter) || includeHO) {
175  HcalDetId id1(id0.subdet(),id0.ieta(),id0.iphi(),1);
176  bool found(false);
177  for (unsigned int idet=0; idet<dets.size(); ++idet) {
178  if (id1 == dets[idet]) {
179  energies[idet] += energy;
180  found = true;
181  break;
182  }
183  }
184  if (!found) {
185  dets.push_back(id1);
186  energies.push_back(energy);
187  }
188  }
189  }
190  double energyMax(-99.);
191  HcalDetId hotCell;
192  for (unsigned int ihit=0; ihit<dets.size(); ihit++) {
193  if (energies[ihit] > energyMax) {
194  energyMax = energies[ihit];
195  hotCell = dets[ihit];
196  }
197  }
198  return hotCell;
199  }
200 
201  HcalDetId getHotCell(std::vector<std::vector<PCaloHit>::const_iterator>& hit, bool includeHO, bool useRaw, bool) {
202 
203  std::vector<HcalDetId> dets;
204  std::vector<double> energies;
205  for (unsigned int ihit=0; ihit<hit.size(); ihit++) {
206  double energy = hit.at(ihit)->energy();
207  HcalDetId id0 = getRawEnergy(hit.at(ihit),useRaw);
208  if ((id0.subdet() != HcalOuter) || includeHO) {
209  HcalDetId id1(id0.subdet(),id0.ieta(),id0.iphi(),1);
210  bool found(false);
211  for (unsigned int idet=0; idet<dets.size(); ++idet) {
212  if (id1 == dets[idet]) {
213  energies[idet] += energy;
214  found = true;
215  break;
216  }
217  }
218  if (!found) {
219  dets.push_back(id1);
220  energies.push_back(energy);
221  }
222  }
223  }
224  double energyMax(-99.);
225  HcalDetId hotCell;
226  for (unsigned int ihit=0; ihit<dets.size(); ihit++) {
227  if (energies[ihit] > energyMax) {
228  energyMax = energies[ihit];
229  hotCell = dets[ihit];
230  }
231  }
232  return hotCell;
233  }
234 
235  double eHCALThreshold(int subdet, double hbThr, double heThr, double hfThr,
236  double hoThr) {
237  double eThr = hbThr;
238  if (subdet == (int)(HcalEndcap)) eThr = heThr;
239  else if (subdet == (int)(HcalForward)) eThr = hfThr;
240  else if (subdet == (int)(HcalOuter)) eThr = hoThr;
241  return eThr;
242  }
243 }
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:235
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
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, int depthHE=3, bool debug=false)
HcalSubdetector
Definition: HcalAssistant.h:31
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)
#define EDM_ML_DEBUG
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:167