CMS 3D CMS Logo

EcalDeadChannelRecoveryBDTG.cc
Go to the documentation of this file.
1 // Original Authors: S. Taroni, N. Marinelli
2 // University of Notre Dame - US
3 // Created:
4 //
5 //
6 //
7 
9 #include "RecoEcal/EgammaCoreTools/interface/EcalClusterTools.h" // can I use a egammatools here?
11 #include <iostream>
12 
13 #include <iostream>
14 #include <ostream>
15 #include <string>
16 #include <fstream>
17 
18 template <>
20  for (int i = 0; i < 9; ++i) {
21  if (i == 4)
22  continue;
23  reader->AddVariable("E" + std::to_string(i + 1) + "/(E1+E2+E3+E4+E6+E7+E8+E9)", &(mx_.rEn[i]));
24  }
25  reader->AddVariable("E1+E2+E3+E4+E6+E7+E8+E9", &(mx_.sumE8));
26  for (int i = 0; i < 9; ++i)
27  reader->AddVariable("iEta" + std::to_string(i + 1), &(mx_.ieta[i]));
28  for (int i = 0; i < 9; ++i)
29  reader->AddVariable("iPhi" + std::to_string(i + 1), &(mx_.iphi[i]));
30 }
31 template <>
33  readerNoCrack = std::unique_ptr<TMVA::Reader>(new TMVA::Reader("!Color:!Silent"));
34  readerCrack = std::unique_ptr<TMVA::Reader>(new TMVA::Reader("!Color:!Silent"));
35 
37  addVariables(readerCrack.get());
38 
40  reco::details::loadTMVAWeights(readerCrack.get(), "BDTG", bdtWeightFileCracks_.fullPath());
41 }
42 
43 template <typename T>
45 
46 template <typename T>
48 
49 template <>
51  bdtWeightFileNoCracks_ = ps.getParameter<edm::FileInPath>("bdtWeightFileNoCracks");
52  bdtWeightFileCracks_ = ps.getParameter<edm::FileInPath>("bdtWeightFileCracks");
53 
54  loadFile();
55 }
56 
57 template <>
59 
60 template <>
62  const EEDetId id, const EcalRecHitCollection &hit_collection, double single8Cut, double sum8Cut, bool *acceptFlag) {
63  return 0;
64 }
65 
66 template <>
68  const EBDetId id, const EcalRecHitCollection &hit_collection, double single8Cut, double sum8Cut, bool *acceptFlag) {
69  bool isCrack = false;
70  int cellIndex = 0.;
71  double neighTotEn = 0.;
72  float val = 0.;
73 
74  //find the matrix around id
75  std::vector<DetId> m3x3aroundDC = EcalClusterTools::matrixDetId(topology_, id, 1);
76  if (m3x3aroundDC.size() < 9) {
77  *acceptFlag = false;
78  return 0;
79  }
80 
81  // Loop over all cells in the vector "NxNaroundDC", and for each cell find it's energy
82  // (from the EcalRecHits collection).
83  for (auto const &theCells : m3x3aroundDC) {
84  EBDetId cell = EBDetId(theCells);
85  if (cell == id) {
86  int iEtaCentral = std::abs(cell.ieta());
87  int iPhiCentral = cell.iphi();
88 
89  if (iEtaCentral < 2 || std::abs(iEtaCentral - 25) < 2 || std::abs(iEtaCentral - 45) < 2 ||
90  std::abs(iEtaCentral - 65) < 2 || iEtaCentral > 83 || (int(iPhiCentral + 0.5) % 20 == 0))
91  isCrack = true;
92  }
93  if (!cell.null()) {
94  EcalRecHitCollection::const_iterator goS_it = hit_collection.find(cell);
95  if (goS_it != hit_collection.end() && cell != id) {
96  if (goS_it->energy() < single8Cut) {
97  *acceptFlag = false;
98  return 0.;
99  } else {
100  neighTotEn += goS_it->energy();
101  mx_.rEn[cellIndex] = goS_it->energy();
102  mx_.iphi[cellIndex] = cell.iphi();
103  mx_.ieta[cellIndex] = cell.ieta();
104  cellIndex++;
105  }
106  } else if (cell == id) { // the cell is the central one
107  mx_.rEn[cellIndex] = 0;
108  cellIndex++;
109  } else { //goS_it is not in the rechitcollection
110  *acceptFlag = false;
111  return 0.;
112  }
113  } else { //cell is null
114  *acceptFlag = false;
115  return 0.;
116  }
117  }
118  if (cellIndex > 0 && neighTotEn >= single8Cut * 8. && neighTotEn >= sum8Cut) {
119  bool allneighs = true;
120  mx_.sumE8 = neighTotEn;
121  for (unsigned int icell = 0; icell < 9; icell++) {
122  if (mx_.rEn[icell] < single8Cut && icell != 4) {
123  allneighs = false;
124  }
125  mx_.rEn[icell] = mx_.rEn[icell] / neighTotEn;
126  }
127  if (allneighs == true) {
128  // evaluate the regression
129  if (isCrack) {
130  val = exp((readerCrack->EvaluateRegression("BDTG"))[0]);
131  } else {
132  val = exp((readerNoCrack->EvaluateRegression("BDTG"))[0]);
133  }
134 
135  *acceptFlag = true;
136  //return the estimated energy
137  return val;
138  } else {
139  *acceptFlag = false;
140  return 0;
141  }
142  } else {
143  *acceptFlag = false;
144  return 0;
145  }
146 }
147 
149 template class EcalDeadChannelRecoveryBDTG<EEDetId>; //not used.
T getParameter(std::string const &) const
void setParameters(const edm::ParameterSet &ps)
constexpr bool null() const
is this a null id ?
Definition: DetId.h:52
std::vector< EcalRecHit >::const_iterator const_iterator
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::unique_ptr< TMVA::Reader > readerCrack
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
const_iterator end() const
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
double recover(const DetIdT id, const EcalRecHitCollection &hit_collection, double single8Cut, double sum8Cut, bool *acceptFlag)
iterator find(key_type k)
std::string fullPath() const
Definition: FileInPath.cc:163
std::unique_ptr< TMVA::Reader > readerNoCrack
void addVariables(TMVA::Reader *reader)