CMS 3D CMS Logo

LowPtGsfElectronSeedHeavyObjectCache.cc
Go to the documentation of this file.
9 
11 
12 #include <string>
13 
14 namespace lowptgsfeleseed {
15 
17  //
18  std::vector<float> Features::get() {
19  std::vector<float> output = {trk_pt_,
20  trk_eta_,
21  trk_phi_,
22  trk_p_,
23  trk_nhits_,
26  rho_,
43  trk_dxy_sig_};
44  return output;
45  }
46 
48  //
50  const reco::PreId& hcal,
51  double rho,
52  const reco::BeamSpot& spot,
54  // Tracks
55  reco::TrackRef trk = ecal.trackRef();
56  if (trk.isNonnull()) {
57  trk_pt_ = trk->pt();
58  trk_eta_ = trk->eta();
59  trk_phi_ = trk->phi();
60  trk_p_ = trk->p();
61  trk_nhits_ = static_cast<float>(trk->found());
62  trk_high_quality_ = static_cast<float>(trk->quality(reco::TrackBase::qualityByName("highPurity")));
63  trk_chi2red_ = trk->normalizedChi2();
64  if (trk->dxy(spot) > 0.) {
65  trk_dxy_sig_ = trk->dxyError() / trk->dxy(spot); //@@ to be consistent with the training based on 94X MC
66  }
67  ktf_ecal_cluster_dphi_ *= trk->charge(); //@@ to be consistent with the training based on 94X MC
68  }
69 
70  // Rho
71  rho_ = static_cast<float>(rho);
72 
73  // ECAL clusters
74  reco::PFClusterRef ecal_clu = ecal.clusterRef();
75  if (ecal_clu.isNonnull()) {
76  ktf_ecal_cluster_e_ = ecal_clu->energy();
79  ktf_ecal_cluster_e3x3_ = tools.e3x3(*ecal_clu);
80  ktf_ecal_cluster_e5x5_ = tools.e5x5(*ecal_clu);
81  auto covs = tools.localCovariances(*ecal_clu);
85  if (ktf_ecal_cluster_e_ > 0.) {
87  }
88  if (ktf_ecal_cluster_e5x5_ > 0.) {
90  } else {
92  }
93  }
94 
95  // HCAL clusters
96  reco::PFClusterRef hcal_clu = hcal.clusterRef();
97  if (hcal_clu.isNonnull()) {
98  ktf_hcal_cluster_e_ = hcal_clu->energy();
101  }
102 
103  // PreId
104  preid_gsf_dpt_ = ecal.dpt();
106  preid_gsf_chi2red_ = ecal.gsfChi2();
107  };
108 
110  //
112  for (auto& name : conf.getParameter<std::vector<std::string> >("ModelNames")) {
113  names_.push_back(name);
114  }
115  for (auto& weights : conf.getParameter<std::vector<std::string> >("ModelWeights")) {
116  models_.push_back(createGBRForest(edm::FileInPath(weights)));
117  }
118  for (auto& thresh : conf.getParameter<std::vector<double> >("ModelThresholds")) {
119  thresholds_.push_back(thresh);
120  }
121  if (names_.size() != models_.size()) {
122  throw cms::Exception("Incorrect configuration")
123  << "'ModelNames' size (" << names_.size() << ") != 'ModelWeights' size (" << models_.size() << ").\n";
124  }
125  if (models_.size() != thresholds_.size()) {
126  throw cms::Exception("Incorrect configuration")
127  << "'ModelWeights' size (" << models_.size() << ") != 'ModelThresholds' size (" << thresholds_.size()
128  << ").\n";
129  }
130  }
131 
133  //
135  reco::PreId& ecal,
136  reco::PreId& hcal,
137  double rho,
138  const reco::BeamSpot& spot,
139  noZS::EcalClusterLazyTools& ecalTools) const {
140  std::vector<std::string>::const_iterator iter = std::find(names_.begin(), names_.end(), name);
141  if (iter != names_.end()) {
142  int index = std::distance(names_.begin(), iter);
144  features.set(ecal, hcal, rho, spot, ecalTools);
145  std::vector<float> inputs = features.get();
146  float output = models_.at(index)->GetResponse(inputs.data());
147  bool pass = output > thresholds_.at(index);
148  ecal.setMVA(pass, output, index);
149  return pass;
150  } else {
151  throw cms::Exception("Unknown model name")
152  << "'Name given: '" << name << "'. Check against configuration file.\n";
153  }
154  }
155 
156 } // namespace lowptgsfeleseed
T getParameter(std::string const &) const
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
reco::TrackRef trackRef() const
Definition: PreId.h:99
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
float e1x5(const reco::BasicCluster &cluster)
float e5x5(const reco::BasicCluster &cluster)
void setMVA(bool accepted, float mva, unsigned n=0)
Definition: PreId.h:63
void set(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
Definition: tools.py:1
bool eval(const std::string &name, reco::PreId &ecal, reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools) const
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
float e3x3(const reco::BasicCluster &cluster)
PFClusterRef clusterRef() const
Definition: PreId.h:100
float gsfChi2() const
Definition: PreId.h:89
const std::vector< float > & geomMatching() const
Access methods.
Definition: PreId.h:78
float dpt() const
Definition: PreId.h:98
float chi2Ratio() const
Definition: PreId.h:88
std::vector< float > localCovariances(const reco::BasicCluster &cluster, float w0=4.7)
std::unique_ptr< const GBRForest > createGBRForest(const std::string &weightsFile)