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,
19  double tMin,
20  double tMax,
21  bool debug) {
22  std::vector<EcalRecHitCollection::const_iterator> hits;
23  spr::findHit(hitsEC, id, hits, debug);
24 #ifdef EDM_ML_DEBUG
25  if (debug)
26  std::cout << "Xtal 0x" << std::hex << id() << std::dec;
27 #endif
28  const EcalRecHitCollection* recHitsEC = (hitsEC.isValid()) ? hitsEC.product() : nullptr;
29  bool flag = (!testSpike) ? true : (sevlv->severityLevel(id, (*recHitsEC)) != EcalSeverityLevel::kWeird);
30  double ener(0);
31  for (const auto& hit : hits) {
32  double en(0), tt(0);
33  if (hit != hitsEC->end()) {
34  en = hit->energy();
35  tt = hit->time();
36  }
37 #ifdef EDM_ML_DEBUG
38  if (debug)
39  std::cout << " " << tt << " " << en;
40 #endif
41  if (tt > tMin && tt < tMax)
42  ener += en;
43  }
44 #ifdef EDM_ML_DEBUG
45  if (!flag && debug)
46  std::cout << " detected to be a spike";
47  if (debug)
48  std::cout << std::endl;
49 #endif
50  return std::pair<double, bool>(ener, flag);
51  }
52 
53  std::pair<double, bool> energyECAL(const std::vector<DetId>& vdets,
55  const EcalSeverityLevelAlgo* sevlv,
56  bool noThrCut,
57  bool testSpike,
58  double eThr,
59  double tMin,
60  double tMax,
61  bool debug) {
62  bool flag(true);
63  double energySum(0.0);
64  for (const auto& id : vdets) {
65  if (id != DetId(0)) {
66  std::pair<double, bool> ecalEn = spr::energyECAL(id, hitsEC, sevlv, testSpike, tMin, tMax, debug);
67  if (!ecalEn.second)
68  flag = false;
69  if ((ecalEn.first > eThr) || noThrCut)
70  energySum += ecalEn.first;
71  }
72  }
73 #ifdef EDM_ML_DEBUG
74  if (debug)
75  std::cout << "energyECAL: energySum = " << energySum << " flag = " << flag << std::endl;
76 #endif
77  return std::pair<double, bool>(energySum, flag);
78  }
79 
80  std::pair<double, bool> eECALmatrix(const DetId& detId,
83  const EcalChannelStatus& chStatus,
84  const CaloGeometry* geo,
85  const CaloTopology* caloTopology,
86  const EcalSeverityLevelAlgo* sevlv,
87  int ieta,
88  int iphi,
89  double ebThr,
90  double eeThr,
91  double tMin,
92  double tMax,
93  bool debug) {
94  std::vector<DetId> vdets;
95  spr::matrixECALIds(detId, ieta, iphi, geo, caloTopology, vdets, debug);
96 #ifdef EDM_ML_DEBUG
97  if (debug) {
98  std::cout << "Inside eECALmatrix " << 2 * ieta + 1 << "X" << 2 * iphi + 1 << " nXtals " << vdets.size()
99  << std::endl;
100  }
101 #endif
102  bool flag(true);
103  for (const auto& id : vdets) {
104  if ((id.det() == DetId::Ecal) && (id.subdetId() == EcalBarrel)) {
105  if (sevlv->severityLevel(id, (*hitsEB)) == EcalSeverityLevel::kWeird)
106  flag = false;
107  } else if ((id.det() == DetId::Ecal) && (id.subdetId() == EcalEndcap)) {
108  if (sevlv->severityLevel(id, (*hitsEE)) == EcalSeverityLevel::kWeird)
109  flag = false;
110  }
111  }
112  return std::pair<double, bool>(spr::energyECAL(vdets, hitsEB, hitsEE, ebThr, eeThr, tMin, tMax, debug), flag);
113  }
114 
115  std::pair<double, bool> eECALmatrix(const DetId& detId,
118  const EcalChannelStatus& chStatus,
119  const CaloGeometry* geo,
120  const CaloTopology* caloTopology,
121  const EcalSeverityLevelAlgo* sevlv,
122  const EcalTrigTowerConstituentsMap& ttMap,
123  int ieta,
124  int iphi,
125  double ebThr,
126  double eeThr,
127  double tMin,
128  double tMax,
129  bool debug) {
130  std::vector<DetId> vdets;
131  spr::matrixECALIds(detId, ieta, iphi, geo, caloTopology, vdets, debug);
132 #ifdef EDM_ML_DEBUG
133  if (debug) {
134  std::cout << "Inside eECALmatrix " << 2 * ieta + 1 << "X" << 2 * iphi + 1 << " nXtals " << vdets.size()
135  << std::endl;
136  }
137 #endif
138 
139  bool flag(true);
140  double energySum = 0.0;
141  for (const auto& id : vdets) {
142  if ((id != DetId(0)) && (id.det() == DetId::Ecal) &&
143  ((id.subdetId() == EcalBarrel) || (id.subdetId() == EcalEndcap))) {
144  double eTower = spr::energyECALTower(id, hitsEB, hitsEE, ttMap, debug);
145  bool ok = (id.subdetId() == EcalBarrel) ? (eTower > ebThr) : (eTower > eeThr);
146 #ifdef EDM_ML_DEBUG
147  if (debug && (!ok))
148  std::cout << "Crystal 0x" << std::hex << id() << std::dec << " Flag " << ok << std::endl;
149 #endif
150  if (ok) {
151  std::pair<double, bool> ecalEn = (id.subdetId() == EcalBarrel)
152  ? spr::energyECAL(id, hitsEB, sevlv, true, tMin, tMax, debug)
153  : spr::energyECAL(id, hitsEE, sevlv, false, tMin, tMax, debug);
154  if (!ecalEn.second)
155  flag = false;
156  energySum += ecalEn.first;
157  }
158  }
159  }
160 #ifdef EDM_ML_DEBUG
161  if (debug)
162  std::cout << "energyECAL: energySum = " << energySum << " flag = " << flag << std::endl;
163 #endif
164  return std::pair<double, bool>(energySum, flag);
165  }
166 
167  std::pair<double, bool> eECALmatrix(const HcalDetId& detId,
170  const CaloGeometry* geo,
171  const CaloTowerConstituentsMap* ctmap,
172  const EcalSeverityLevelAlgo* sevlv,
173  double ebThr,
174  double eeThr,
175  double tMin,
176  double tMax,
177  bool debug) {
178  CaloTowerDetId tower = ctmap->towerOf(detId);
179  std::vector<DetId> ids = ctmap->constituentsOf(tower);
180 #ifdef EDM_ML_DEBUG
181  if (debug) {
182  std::cout << "eECALmatrix: " << detId << " belongs to " << tower << " which has " << ids.size() << " constituents"
183  << std::endl;
184  for (unsigned int i = 0; i < ids.size(); ++i) {
185  std::cout << "[" << i << "] " << std::hex << ids[i].rawId() << std::dec;
186  if (ids[i].det() == DetId::Ecal && ids[i].subdetId() == EcalBarrel) {
187  std::cout << " " << EBDetId(ids[i]) << std::endl;
188  } else if (ids[i].det() == DetId::Ecal && ids[i].subdetId() == EcalEndcap) {
189  std::cout << " " << EEDetId(ids[i]) << std::endl;
190  } else if (ids[i].det() == DetId::Ecal && ids[i].subdetId() == EcalPreshower) {
191  std::cout << " " << ESDetId(ids[i]) << std::endl;
192  } else if (ids[i].det() == DetId::Hcal) {
193  std::cout << " " << HcalDetId(ids[i]) << std::endl;
194  } else {
195  std::cout << std::endl;
196  }
197  }
198  }
199 #endif
200  std::vector<DetId> idEBEE;
201  bool flag(true);
202  for (const auto& id : ids) {
203  if ((id.det() == DetId::Ecal) && (id.subdetId() == EcalBarrel)) {
204  idEBEE.emplace_back(id);
205  if (sevlv->severityLevel(id, (*hitsEB)) == EcalSeverityLevel::kWeird)
206  flag = false;
207  } else if ((id.det() == DetId::Ecal) && (id.subdetId() == EcalEndcap)) {
208  idEBEE.emplace_back(id);
209  if (sevlv->severityLevel(id, (*hitsEE)) == EcalSeverityLevel::kWeird)
210  flag = false;
211  }
212  }
213 #ifdef EDM_ML_DEBUG
214  if (debug)
215  std::cout << "eECALmatrix: with " << idEBEE.size() << " EB+EE hits and "
216  << "spike flag " << flag << std::endl;
217 #endif
218  double etot = (!idEBEE.empty()) ? spr::energyECAL(idEBEE, hitsEB, hitsEE, ebThr, eeThr, tMin, tMax, debug) : 0;
219  return std::pair<double, bool>(etot, flag);
220  }
221 } // namespace spr
EcalSeverityLevelAlgo
Definition: EcalSeverityLevelAlgo.h:33
mps_fire.i
i
Definition: mps_fire.py:428
spr
Definition: CaloConstants.h:6
edm::Handle::product
T const * product() const
Definition: Handle.h:70
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
EcalSeverityLevelAlgo::severityLevel
EcalSeverityLevel::SeverityLevel severityLevel(const DetId &id) const
Evaluate status from id use channelStatus from DB.
Definition: EcalSeverityLevelAlgo.cc:85
groupFilesInBlocks.tt
int tt
Definition: groupFilesInBlocks.py:144
CaloTowerConstituentsMap::constituentsOf
std::vector< DetId > constituentsOf(const CaloTowerDetId &id) const
Get the constituent detids for this tower id ( not yet implemented )
Definition: CaloTowerConstituentsMap.cc:69
EBDetId
Definition: EBDetId.h:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EBDetId.h
EEDetId.h
DetId::Hcal
Definition: DetId.h:28
hgcalTowerProducer_cfi.tower
tower
Definition: hgcalTowerProducer_cfi.py:4
edm::SortedCollection
Definition: SortedCollection.h:49
ESDetId
Definition: ESDetId.h:15
ESDetId.h
spr::matrixECALIds
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)
Definition: MatrixECALDetIds.cc:16
EcalCondObjectContainer
Definition: EcalCondObjectContainer.h:13
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
edm::Handle
Definition: AssociativeIterator.h:50
CaloTopology
Definition: CaloTopology.h:19
EcalBarrel
Definition: EcalSubdetector.h:10
EcalSeverityLevel::kWeird
Definition: EcalSeverityLevel.h:23
CastorDataFrameFilter_impl::energySum
double energySum(const DataFrame &df, int fs, int ls)
Definition: CastorDataFrameFilter.cc:22
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
DetId
Definition: DetId.h:17
CaloGeometry
Definition: CaloGeometry.h:21
FindCaloHit.h
debug
#define debug
Definition: HDRShower.cc:19
spr::eECALmatrix
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)
CaloTowerConstituentsMap
Definition: CaloTowerConstituentsMap.h:18
spr::energyECALTower
double energyECALTower(const DetId &detId, edm::Handle< T > &hitsEB, edm::Handle< T > &hitsEE, const EcalTrigTowerConstituentsMap &ttMap, bool debug=false)
eECALMatrix.h
EcalSeverityLevelAlgo.h
spr::energyECAL
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)
EEDetId
Definition: EEDetId.h:14
EcalSubdetector.h
EcalEndcap
Definition: EcalSubdetector.h:10
EcalTrigTowerConstituentsMap
Definition: EcalTrigTowerConstituentsMap.h:19
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
HcalDetId
Definition: HcalDetId.h:12
spr::findHit
std::vector< typename T::const_iterator > findHit(edm::Handle< T > &hits, DetId thisDet, bool debug=false)
CaloTowerDetId.h
CaloTowerConstituentsMap::towerOf
CaloTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
Definition: CaloTowerConstituentsMap.cc:26
DetId::Ecal
Definition: DetId.h:27
EcalPreshower
Definition: EcalSubdetector.h:10
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
hit
Definition: SiStripHitEffFromCalibTree.cc:88
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
CaloTowerDetId
Definition: CaloTowerDetId.h:12