CMS 3D CMS Logo

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