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 
38 
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.
EBDetId::ieta
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
mps_fire.i
i
Definition: mps_fire.py:355
edm::SortedCollection< EcalRecHit >::const_iterator
std::vector< EcalRecHit >::const_iterator const_iterator
Definition: SortedCollection.h:80
EcalDeadChannelRecoveryBDTG::XtalMatrix::ieta
std::array< float, 9 > ieta
Definition: EcalDeadChannelRecoveryBDTG.h:38
EcalDeadChannelRecoveryBDTG::bdtWeightFileCracks_
edm::FileInPath bdtWeightFileCracks_
Definition: EcalDeadChannelRecoveryBDTG.h:45
EcalDeadChannelRecoveryBDTG::mx_
XtalMatrix mx_
Definition: EcalDeadChannelRecoveryBDTG.h:42
EBDetId
Definition: EBDetId.h:17
EcalDeadChannelRecoveryBDTG::recover
double recover(const DetIdT id, const EcalRecHitCollection &hit_collection, double single8Cut, double sum8Cut, bool *acceptFlag)
EcalDeadChannelRecoveryBDTG::EcalDeadChannelRecoveryBDTG
EcalDeadChannelRecoveryBDTG()
Definition: EcalDeadChannelRecoveryBDTG.cc:44
edm::SortedCollection< EcalRecHit >
EcalDeadChannelRecoveryBDTG::readerCrack
std::unique_ptr< TMVA::Reader > readerCrack
Definition: EcalDeadChannelRecoveryBDTG.h:48
DetId::null
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
EcalDeadChannelRecoveryBDTG::readerNoCrack
std::unique_ptr< TMVA::Reader > readerNoCrack
Definition: EcalDeadChannelRecoveryBDTG.h:47
EcalDeadChannelRecoveryBDTG::setParameters
void setParameters(const edm::ParameterSet &ps)
FileInPath.h
EcalDeadChannelRecoveryBDTG::loadFile
void loadFile()
EcalDeadChannelRecoveryBDTG< EBDetId >
edm::FileInPath
Definition: FileInPath.h:64
DQM.reader
reader
Definition: DQM.py:105
EcalDeadChannelRecoveryBDTG::~EcalDeadChannelRecoveryBDTG
~EcalDeadChannelRecoveryBDTG()
Definition: EcalDeadChannelRecoveryBDTG.cc:47
EcalDeadChannelRecoveryBDTG::XtalMatrix::iphi
std::array< float, 9 > iphi
Definition: EcalDeadChannelRecoveryBDTG.h:38
EcalDeadChannelRecoveryBDTG::XtalMatrix::sumE8
float sumE8
Definition: EcalDeadChannelRecoveryBDTG.h:39
EEDetId
Definition: EEDetId.h:14
EcalDeadChannelRecoveryBDTG::XtalMatrix::rEn
std::array< float, 9 > rEn
Definition: EcalDeadChannelRecoveryBDTG.h:38
EcalDeadChannelRecoveryBDTG::addVariables
void addVariables(TMVA::Reader *reader)
edm::ParameterSet
Definition: ParameterSet.h:36
edm::SortedCollection::end
const_iterator end() const
Definition: SortedCollection.h:267
EcalClusterTools.h
EcalDeadChannelRecoveryBDTG::bdtWeightFileNoCracks_
edm::FileInPath bdtWeightFileNoCracks_
Definition: EcalDeadChannelRecoveryBDTG.h:44
EcalDeadChannelRecoveryBDTG.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
edm::SortedCollection::find
iterator find(key_type k)
Definition: SortedCollection.h:240
heppy_batch.val
val
Definition: heppy_batch.py:351
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
reco::details::loadTMVAWeights
TMVA::IMethod * loadTMVAWeights(TMVA::Reader *reader, const std::string &method, const std::string &weightFile, bool verbose=false)
Definition: TMVAZipReader.cc:52
EBDetId::iphi
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
JetChargeProducer_cfi.exp
exp
Definition: JetChargeProducer_cfi.py:6
EcalDeadChannelRecoveryBDTG::topology_
const CaloTopology * topology_
Definition: EcalDeadChannelRecoveryBDTG.h:36
edm::FileInPath::fullPath
std::string fullPath() const
Definition: FileInPath.cc:163