CMS 3D CMS Logo

eECALMatrix.cc
Go to the documentation of this file.
4 #include<iostream>
5 
6 //#define EDM_ML_DEBUG
7 
8 namespace spr{
9 
10  std::pair<double,bool> eECALmatrix(const DetId& detId,
13  const EcalChannelStatus& chStatus,
14  const CaloGeometry* geo,
15  const CaloTopology* caloTopology,
16  const EcalSeverityLevelAlgo* sevlv,
17  int ieta, int iphi, double ebThr,
18  double eeThr, double tMin, double tMax,
19  bool debug) {
20 
21  std::vector<DetId> vdets;
22  spr::matrixECALIds(detId, ieta, iphi, geo, caloTopology, vdets, debug);
23 
24  const EcalRecHitCollection * recHitsEB = 0;
25  if (hitsEB.isValid()) recHitsEB = hitsEB.product();
26  bool flag = true;
27 #ifdef EDM_ML_DEBUG
28  if (debug) {
29  std::cout << "Inside eECALmatrix " << 2*ieta+1 << "X" << 2*iphi+1
30  << " nXtals " << vdets.size() << std::endl;
31  }
32 #endif
33  double energySum = 0.0;
34  for (unsigned int i1=0; i1<vdets.size(); i1++) {
35  if (vdets[i1] != DetId(0)) {
36  bool ok = true;
37  std::vector<EcalRecHitCollection::const_iterator> hit;
38  if (vdets[i1].subdetId()==EcalBarrel) {
39  spr::findHit(hitsEB,vdets[i1],hit,debug);
40 
41  ok = (sevlv->severityLevel(vdets[i1], (*recHitsEB)) != EcalSeverityLevel::kWeird);
42  } else if (vdets[i1].subdetId()==EcalEndcap) {
43  spr::findHit(hitsEE,vdets[i1],hit,debug);
44  }
45 #ifdef EDM_ML_DEBUG
46  if (debug) std::cout << "Xtal 0x" <<std::hex << vdets[i1]() <<std::dec;
47 #endif
48  double ener=0, ethr=ebThr;
49  if (vdets[i1].subdetId() !=EcalBarrel) ethr = eeThr;
50  for (unsigned int ihit=0; ihit<hit.size(); ihit++) {
51  double en=0, tt=0;
52  if (vdets[i1].subdetId()==EcalBarrel) {
53  if (hit[ihit] != hitsEB->end()) {
54  en = hit[ihit]->energy();
55  tt = hit[ihit]->time();
56  }
57  } else if (vdets[i1].subdetId()==EcalEndcap) {
58  if (hit[ihit] != hitsEE->end()) {
59  en = hit[ihit]->energy();
60  tt = hit[ihit]->time();
61  }
62  }
63 #ifdef EDM_ML_DEBUG
64  if (debug) std::cout << " " << ihit << " " << en;
65 #endif
66  if (tt > tMin && tt < tMax) ener += en;
67  }
68  if (!ok) {
69  flag = false;
70 #ifdef EDM_ML_DEBUG
71  if (debug) std::cout << " detected to be a spike";
72 #endif
73  }
74 #ifdef EDM_ML_DEBUG
75  if (debug) std::cout << std::endl;
76 #endif
77  if (ener > ethr) energySum += ener;
78  }
79  }
80 #ifdef EDM_ML_DEBUG
81  if (debug) std::cout << "energyECAL: energySum = " << energySum << " flag = " << flag << std::endl;
82 #endif
83  return std::pair<double,bool>(energySum,flag);
84  }
85 
86  std::pair<double,bool> eECALmatrix(const DetId& detId,
89  const EcalChannelStatus& chStatus,
90  const CaloGeometry* geo,
91  const CaloTopology* caloTopology,
92  const EcalSeverityLevelAlgo* sevlv,
93  const EcalTrigTowerConstituentsMap& ttMap,
94  int ieta, int iphi, double ebThr,
95  double eeThr, double tMin, double tMax,
96  bool debug) {
97 
98  std::vector<DetId> vdets;
99  spr::matrixECALIds(detId, ieta, iphi, geo, caloTopology, vdets, debug);
100 
101  const EcalRecHitCollection * recHitsEB = 0;
102  if (hitsEB.isValid()) recHitsEB = hitsEB.product();
103  bool flag = true;
104 #ifdef EDM_ML_DEBUG
105  if (debug) {
106  std::cout << "Inside eECALmatrix " << 2*ieta+1 << "X" << 2*iphi+1
107  << " nXtals " << vdets.size() << std::endl;
108  }
109 #endif
110  double energySum = 0.0;
111  for (unsigned int i1=0; i1<vdets.size(); i1++) {
112  if (vdets[i1] != DetId(0)) {
113  double eTower = spr::energyECALTower(vdets[i1], hitsEB, hitsEE, ttMap, debug);
114  bool ok = true;
115  if (vdets[i1].subdetId()==EcalBarrel) ok = (eTower > ebThr);
116  else if (vdets[i1].subdetId()==EcalEndcap) ok = (eTower > eeThr);
117 #ifdef EDM_ML_DEBUG
118  if (debug) std::cout << "Crystal 0x" <<std::hex << vdets[i1]()
119  <<std::dec << " Flag " << ok;
120 #endif
121  if (ok) {
122  std::vector<EcalRecHitCollection::const_iterator> hit;
123  if (vdets[i1].subdetId()==EcalBarrel) {
124  spr::findHit(hitsEB,vdets[i1],hit,debug);
125 
126  ok = (sevlv->severityLevel(vdets[i1], (*recHitsEB)) != EcalSeverityLevel::kWeird);
127  } else if (vdets[i1].subdetId()==EcalEndcap) {
128  spr::findHit(hitsEE,vdets[i1],hit,debug);
129  }
130  double ener=0;
131  for (unsigned int ihit=0; ihit<hit.size(); ihit++) {
132  double en=0, tt=0;
133  if (vdets[i1].subdetId()==EcalBarrel) {
134  if (hit[ihit] != hitsEB->end()) {
135  en = hit[ihit]->energy();
136  tt = hit[ihit]->time();
137  }
138  } else if (vdets[i1].subdetId()==EcalEndcap) {
139  if (hit[ihit] != hitsEE->end()) {
140  en = hit[ihit]->energy();
141  tt = hit[ihit]->time();
142  }
143  }
144 #ifdef EDM_ML_DEBUG
145  if (debug) std::cout << " " << ihit << " E " << en << " T " << tt;
146 #endif
147  if (tt > tMin && tt < tMax) ener += en;
148  }
149  if (!ok) {
150  flag = false;
151 #ifdef EDM_ML_DEBUG
152  if (debug) std::cout << " detected to be a spike";
153 #endif
154  }
155  energySum += ener;
156  }
157 #ifdef EDM_ML_DEBUG
158  if (debug) std::cout << std::endl;
159 #endif
160  }
161  }
162 #ifdef EDM_ML_DEBUG
163  if (debug) std::cout << "energyECAL: energySum = " << energySum << " flag = " << flag << std::endl;
164 #endif
165  return std::pair<double,bool>(energySum,flag);
166  }
167 }
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
std::vector< typename T::const_iterator > findHit(edm::Handle< T > &hits, DetId thisDet, bool debug=false)
void matrixECALIds(const DetId &det, int ieta, int iphi, const CaloGeometry *geo, const CaloTopology *caloTopology, std::vector< DetId > &vdets, bool debug=false, bool igNoreTransition=true)
bool isValid() const
Definition: HandleBase.h:74
const_iterator end() const
Definition: DetId.h:18
#define debug
Definition: HDRShower.cc:19
T const * product() const
Definition: Handle.h:81
double energySum(const DataFrame &df, int fs, int ls)
double energyECALTower(const DetId &detId, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, const EcalTrigTowerConstituentsMap &ttMap, bool debug=false)
double eECALmatrix(const DetId &detId, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, const CaloGeometry *geo, const CaloTopology *caloTopology, int ieta, int iphi, double ebThr=-100, double eeThr=-100, double tMin=-500, double tMax=500, bool debug=false)