CMS 3D CMS Logo

eECALMatrix.cc
Go to the documentation of this file.
9 #include<iostream>
10 
11 //#define EDM_ML_DEBUG
12 
13 namespace spr{
14 
15  std::pair<double,bool> energyECAL(const DetId& id,
17  const EcalSeverityLevelAlgo* sevlv,
18  bool testSpike, double tMin, double tMax,
19  bool debug) {
20  std::vector<EcalRecHitCollection::const_iterator> hits;
21  spr::findHit(hitsEC,id,hits,debug);
22 #ifdef EDM_ML_DEBUG
23  if (debug) std::cout << "Xtal 0x" << std::hex << id() <<std::dec;
24 #endif
25  const EcalRecHitCollection* recHitsEC = (hitsEC.isValid()) ? hitsEC.product() : nullptr;
26  bool flag = (!testSpike) ? true :
27  (sevlv->severityLevel(id,(*recHitsEC)) != EcalSeverityLevel::kWeird);
28  double ener(0);
29  for (const auto& hit : hits) {
30  double en(0), tt(0);
31  if (hit != hitsEC->end()) {
32  en = hit->energy();
33  tt = hit->time();
34  }
35 #ifdef EDM_ML_DEBUG
36  if (debug) std::cout << " " << tt << " " << en;
37 #endif
38  if (tt > tMin && tt < tMax) ener += en;
39  }
40 #ifdef EDM_ML_DEBUG
41  if (!flag && debug) std::cout << " detected to be a spike";
42  if (debug) std::cout << std::endl;
43 #endif
44  return std::pair<double,bool>(ener,flag);
45  }
46 
47  std::pair<double,bool> energyECAL(const std::vector<DetId>& vdets,
49  const EcalSeverityLevelAlgo* sevlv,
50  bool noThrCut, bool testSpike, double eThr,
51  double tMin, double tMax, bool debug) {
52 
53  bool flag(true);
54  double energySum(0.0);
55  for (const auto& id : vdets) {
56  if (id != DetId(0)) {
57  std::pair<double,bool> ecalEn = spr::energyECAL(id,hitsEC,sevlv,
58  testSpike,tMin,tMax,
59  debug);
60  if (!ecalEn.second) flag = false;
61  if ((ecalEn.first>eThr) || noThrCut) energySum += ecalEn.first;
62  }
63  }
64 #ifdef EDM_ML_DEBUG
65  if (debug) std::cout << "energyECAL: energySum = " << energySum
66  << " flag = " << flag << std::endl;
67 #endif
68  return std::pair<double,bool>(energySum,flag);
69  }
70 
71  std::pair<double,bool> eECALmatrix(const DetId& detId,
74  const EcalChannelStatus& chStatus,
75  const CaloGeometry* geo,
76  const CaloTopology* caloTopology,
77  const EcalSeverityLevelAlgo* sevlv,
78  int ieta, int iphi, double ebThr,
79  double eeThr, double tMin, double tMax,
80  bool debug) {
81 
82  std::vector<DetId> vdets;
83  spr::matrixECALIds(detId, ieta, iphi, geo, caloTopology, vdets, debug);
84 #ifdef EDM_ML_DEBUG
85  if (debug) {
86  std::cout << "Inside eECALmatrix " << 2*ieta+1 << "X" << 2*iphi+1
87  << " nXtals " << vdets.size() << std::endl;
88  }
89 #endif
90 
91  if (detId.det() == DetId::Ecal && detId.subdetId() == EcalBarrel) {
92  return spr::energyECAL(vdets,hitsEB,sevlv,false,true,ebThr,tMin,tMax,debug);
93  } else if (detId.det() == DetId::Ecal && detId.subdetId() == EcalEndcap) {
94  return spr::energyECAL(vdets,hitsEE,sevlv,false,false,eeThr,tMin,tMax,debug);
95  } else {
96  return std::pair<double,bool>(0,true);
97  }
98  }
99 
100  std::pair<double,bool> eECALmatrix(const DetId& detId,
103  const EcalChannelStatus& chStatus,
104  const CaloGeometry* geo,
105  const CaloTopology* caloTopology,
106  const EcalSeverityLevelAlgo* sevlv,
107  const EcalTrigTowerConstituentsMap& ttMap,
108  int ieta, int iphi, double ebThr,
109  double eeThr, double tMin, double tMax,
110  bool debug) {
111 
112  std::vector<DetId> vdets;
113  spr::matrixECALIds(detId, ieta, iphi, geo, caloTopology, vdets, debug);
114 #ifdef EDM_ML_DEBUG
115  if (debug) {
116  std::cout << "Inside eECALmatrix " << 2*ieta+1 << "X" << 2*iphi+1
117  << " nXtals " << vdets.size() << std::endl;
118  }
119 #endif
120 
121  bool flag(true);
122  double energySum = 0.0;
123  for (const auto & id : vdets) {
124  if ((id != DetId(0)) && (id.det() == DetId::Ecal) &&
125  ((id.subdetId()==EcalBarrel) || (id.subdetId()==EcalEndcap))) {
126  double eTower = spr::energyECALTower(id, hitsEB, hitsEE, ttMap, debug);
127  bool ok = (id.subdetId()==EcalBarrel) ? (eTower > ebThr) : (eTower > eeThr);
128 #ifdef EDM_ML_DEBUG
129  if (debug && (!ok)) std::cout << "Crystal 0x" << std::hex << id()
130  << std::dec << " Flag " << ok <<std::endl;
131 #endif
132  if (ok) {
133  std::pair<double,bool> ecalEn = (id.subdetId()==EcalBarrel) ?
134  spr::energyECAL(id,hitsEB,sevlv,true,tMin,tMax,debug) :
135  spr::energyECAL(id,hitsEE,sevlv,false,tMin,tMax,debug);
136  if (!ecalEn.second) flag = false;
137  energySum += ecalEn.first;
138  }
139  }
140  }
141 #ifdef EDM_ML_DEBUG
142  if (debug) std::cout << "energyECAL: energySum = " << energySum
143  << " flag = " << flag << std::endl;
144 #endif
145  return std::pair<double,bool>(energySum,flag);
146  }
147 
148  std::pair<double,bool> eECALmatrix(const HcalDetId& detId,
151  const CaloGeometry* geo,
152  const CaloTowerConstituentsMap* ctmap,
153  const EcalSeverityLevelAlgo* sevlv,
154  double ebThr, double eeThr, double tMin,
155  double tMax, bool debug) {
156 
157  CaloTowerDetId tower = ctmap->towerOf(detId);
158  std::vector<DetId> ids = ctmap->constituentsOf(tower);
159 #ifdef EDM_ML_DEBUG
160  if (debug) {
161  std::cout << "eECALmatrix: " << detId << " belongs to " << tower
162  << " which has " << ids.size() << " constituents" << std::endl;
163  for (unsigned int i=0; i<ids.size(); ++i) {
164  std::cout << "[" << i << "] " << std::hex << ids[i].rawId() <<std::dec;
165  if (ids[i].det()==DetId::Ecal && ids[i].subdetId()==EcalBarrel){
166  std::cout << " " << EBDetId(ids[i]) << std::endl;
167  } else if (ids[i].det()==DetId::Ecal && ids[i].subdetId()==EcalEndcap){
168  std::cout << " " << EEDetId(ids[i]) << std::endl;
169  } else if (ids[i].det()==DetId::Ecal && ids[i].subdetId()==EcalPreshower) {
170  std::cout << " " << ESDetId(ids[i]) << std::endl;
171  } else if (ids[i].det()==DetId::Hcal) {
172  std::cout << " " << HcalDetId(ids[i]) << std::endl;
173  } else {
174  std::cout << std::endl;
175  }
176  }
177  }
178 #endif
179 
180  if (detId.det() == DetId::Ecal && detId.subdetId() == EcalBarrel) {
181  return spr::energyECAL(ids,hitsEB,sevlv,false,true,ebThr,tMin,tMax,debug);
182  } else if (detId.det() == DetId::Ecal && detId.subdetId() == EcalEndcap) {
183  return spr::energyECAL(ids,hitsEE,sevlv,false,false,eeThr,tMin,tMax,debug);
184  } else {
185  return std::pair<double,bool>(0,true);
186  }
187  }
188 }
189 
double energyECAL(std::vector< DetId > &vdets, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, double ebThr=-100, double eeThr=-100, double tMin=-500, double tMax=500, bool debug=false)
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)
std::vector< DetId > constituentsOf(const CaloTowerDetId &id) const
Get the constituent detids for this tower id ( not yet implemented )
CaloTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
bool isValid() const
Definition: HandleBase.h:74
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
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)
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
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)