CMS 3D CMS Logo

List of all members | Public Member Functions | Private Attributes
pat::MuonMvaEstimator Class Reference

#include <MuonMvaEstimator.h>

Public Member Functions

float computeMva (const pat::Muon &imuon, const reco::Vertex &vertex, const reco::JetTagCollection &bTags, float &jetPtRatio, float &jetPtRel, const reco::JetCorrector *correctorL1=0, const reco::JetCorrector *correctorL1L2L3Res=0) const
 
 MuonMvaEstimator (const std::string &weightsfile, float dRmax)
 
 ~MuonMvaEstimator ()
 

Private Attributes

float dRmax_
 
float eta_ = 0.0
 
std::unique_ptr< const GBRForestgbrForest_
 
float jetBTagCSV_ = 0.0
 
float jetNDauCharged_ = 0.0
 
float jetPtRatio_ = 0.0
 
float jetPtRel_ = 0.0
 
float log_abs_dxyBS_ = 0.0
 
float log_abs_dzPV_ = 0.0
 
float miniRelIsoCharged_ = 0.0
 
float miniRelIsoNeutral_ = 0.0
 
float pt_ = 0.0
 MVA VAriables. More...
 
float segmentCompatibility_ = 0.0
 
float sip_ = 0.0
 

Detailed Description

Definition at line 21 of file MuonMvaEstimator.h.

Constructor & Destructor Documentation

MuonMvaEstimator::MuonMvaEstimator ( const std::string &  weightsfile,
float  dRmax 
)

Definition at line 22 of file MuonMvaEstimator.cc.

References eta_, gbrForest_, jetBTagCSV_, jetNDauCharged_, jetPtRatio_, jetPtRel_, log_abs_dxyBS_, log_abs_dzPV_, miniRelIsoCharged_, miniRelIsoNeutral_, pt_, segmentCompatibility_, sip_, and groupFilesInBlocks::temp.

22  :
23  dRmax_(dRmax)
24 {
25  TMVA::Reader tmvaReader("!Color:!Silent:Error");
26  tmvaReader.AddVariable("LepGood_pt", &pt_ );
27  tmvaReader.AddVariable("LepGood_eta", &eta_ );
28  tmvaReader.AddVariable("LepGood_jetNDauChargedMVASel", &jetNDauCharged_ );
29  tmvaReader.AddVariable("LepGood_miniRelIsoCharged", &miniRelIsoCharged_);
30  tmvaReader.AddVariable("LepGood_miniRelIsoNeutral", &miniRelIsoNeutral_);
31  tmvaReader.AddVariable("LepGood_jetPtRelv2", &jetPtRel_ );
32  tmvaReader.AddVariable("max(LepGood_jetBTagCSV,0)", &jetBTagCSV_ );
33  tmvaReader.AddVariable("(LepGood_jetBTagCSV>-5)*min(LepGood_jetPtRatiov2,1.5)+(LepGood_jetBTagCSV<-5)/(1+LepGood_relIso04)", &jetPtRatio_ );
34  tmvaReader.AddVariable("LepGood_sip3d", &sip_ );
35  tmvaReader.AddVariable("log(abs(LepGood_dxy))", &log_abs_dxyBS_ );
36  tmvaReader.AddVariable("log(abs(LepGood_dz))", &log_abs_dzPV_ );
37  tmvaReader.AddVariable("LepGood_segmentCompatibility", &segmentCompatibility_);
38 
39  auto temp{ tmvaReader.BookMVA(muon_mva_name, weightsfile.c_str()) };
40  gbrForest_ = std::make_unique<GBRForest>( dynamic_cast<TMVA::MethodBDT*>( temp ) );
41 }
float pt_
MVA VAriables.
std::unique_ptr< const GBRForest > gbrForest_
MuonMvaEstimator::~MuonMvaEstimator ( )

Definition at line 43 of file MuonMvaEstimator.cc.

43 { }

Member Function Documentation

float MuonMvaEstimator::computeMva ( const pat::Muon imuon,
const reco::Vertex vertex,
const reco::JetTagCollection bTags,
float &  jetPtRatio,
float &  jetPtRel,
const reco::JetCorrector correctorL1 = 0,
const reco::JetCorrector correctorL1L2L3Res = 0 
) const

Definition at line 75 of file MuonMvaEstimator.cc.

References reco::PFCandidate::bestTrack(), pat::Muon::BS2D, reco::LeafCandidate::charge(), pat::PFIsolation::chargedHadronIso(), reco::JetCorrector::correction(), pat::Muon::dB(), deltaR(), runTauDisplay::dr, dRmax_, PVValHelper::dz, pat::Muon::edB(), reco::LeafCandidate::eta(), Exception, gbrForest_, reco::TrackBase::highPurity, metsig::jet, JetComb::kEta, kPt, cmsBatch::log, SiStripPI::max, pat::Lepton< LeptonType >::miniPFIsolation(), pat::Muon::muonBestTrack(), pat::PFIsolation::neutralHadronIso(), reco::LeafCandidate::p4(), pfDeepBoostedJetPreprocessParams_cfi::pfcand, reco::Muon::pfIsolationR04(), reco::Vertex::position(), reco::LeafCandidate::pt(), electrons_cff::ptRel, pat::Muon::PV3D, pat::Muon::segmentCompatibility(), reco::MuonPFIsolation::sumChargedHadronPt, reco::MuonPFIsolation::sumNeutralHadronEt, reco::MuonPFIsolation::sumPhotonEt, reco::MuonPFIsolation::sumPUPt, and JetChargeProducer_cfi::var.

82 {
83  float var[kLast]{};
84 
85  var[kPt] = muon.pt();
86  var[kEta] = muon.eta();
87  var[kSegmentCompatibility] = muon.segmentCompatibility();
88  var[kMiniRelIsoCharged] = muon.miniPFIsolation().chargedHadronIso();
89  var[kMiniRelIsoNeutral] = muon.miniPFIsolation().neutralHadronIso();
90 
91  double dB2D = fabs(muon.dB(pat::Muon::BS2D));
92  double dB3D = muon.dB(pat::Muon::PV3D);
93  double edB3D = muon.edB(pat::Muon::PV3D);
94  double dz = fabs(muon.muonBestTrack()->dz(vertex.position()));
95  var[kSip] = edB3D>0?fabs(dB3D/edB3D):0.0;
96  var[kLog_abs_dxyBS] = dB2D>0?log(dB2D):0;
97  var[kLog_abs_dzPV] = dz>0?log(dz):0;
98 
99  //Initialise loop variables
100  double minDr = 9999;
101  double jecL1L2L3Res = 1.;
102  double jecL1 = 1.;
103 
104  // Compute corrected isolation variables
105  double chIso = muon.pfIsolationR04().sumChargedHadronPt;
106  double nIso = muon.pfIsolationR04().sumNeutralHadronEt;
107  double phoIso = muon.pfIsolationR04().sumPhotonEt;
108  double puIso = muon.pfIsolationR04().sumPUPt;
109  double dbCorrectedIsolation = chIso + std::max( nIso + phoIso - .5*puIso, 0. ) ;
110  double dbCorrectedRelIso = dbCorrectedIsolation/muon.pt();
111 
112  var[kJetPtRatio] = 1./(1+dbCorrectedRelIso);
113  var[kJetPtRel] = 0;
114  var[kJetBTagCSV] = -999;
115  var[kJetNDauCharged] = -1;
116 
117 
118  for (const auto& tagI: bTags){
119  // for each muon with the lepton
120  double dr = deltaR(*(tagI.first), muon);
121  if(dr > minDr) continue;
122  minDr = dr;
123 
124  const reco::Candidate::LorentzVector& muP4(muon.p4());
125  reco::Candidate::LorentzVector jetP4(tagI.first->p4());
126 
127  if (correctorL1 && correctorL1L2L3Res){
128  jecL1L2L3Res = correctorL1L2L3Res->correction(*(tagI.first));
129  jecL1 = correctorL1->correction(*(tagI.first));
130  }
131 
132  // Get b-jet info
133  var[kJetBTagCSV] = tagI.second;
134  var[kJetNDauCharged] = 0;
135  for (auto jet: tagI.first->getJetConstituentsQuick()){
136  const reco::PFCandidate *pfcand = dynamic_cast<const reco::PFCandidate*>(jet);
137  if (pfcand==nullptr) throw cms::Exception("ConfigurationError") << "Cannot get jet constituents";
138  if (pfcand->charge()==0) continue;
139  auto bestTrackPtr = pfcand->bestTrack();
140  if (!bestTrackPtr) continue;
141  if (!bestTrackPtr->quality(reco::Track::highPurity)) continue;
142  if (bestTrackPtr->pt()<1.) continue;
143  if (bestTrackPtr->hitPattern().numberOfValidHits()<8) continue;
144  if (bestTrackPtr->hitPattern().numberOfValidPixelHits()<2) continue;
145  if (bestTrackPtr->normalizedChi2()>=5) continue;
146 
147  if (std::fabs(bestTrackPtr->dxy(vertex.position())) > 0.2) continue;
148  if (std::fabs(bestTrackPtr->dz(vertex.position())) > 17) continue;
149  var[kJetNDauCharged]++;
150  }
151 
152  if(minDr < dRmax_){
153  if ((jetP4-muP4).Rho()<0.0001){
154  var[kJetPtRel] = 0;
155  var[kJetPtRatio] = 1;
156  } else {
157  jetP4 -= muP4/jecL1;
158  jetP4 *= jecL1L2L3Res;
159  jetP4 += muP4;
160 
161  var[kJetPtRatio] = muP4.pt()/jetP4.pt();
162  var[kJetPtRel] = ptRel(muP4,jetP4);
163  }
164  }
165  }
166 
167  if (var[kJetPtRatio] > 1.5) var[kJetPtRatio] = 1.5;
168  if (var[kJetBTagCSV] < 0) var[kJetBTagCSV] = 0;
169  jetPtRatio = var[kJetPtRatio];
170  jetPtRel = var[kJetPtRel];
171  return gbrForest_->GetClassifier(var);
172 };
example_track example_track const char *const kPt
Definition: TSelector.cc:34
int charge() const final
electric charge
Definition: LeafCandidate.h:91
double correction(const LorentzVector &fJet) const
get correction using Jet information only
Definition: JetCorrector.h:49
const Point & position() const
position
Definition: Vertex.h:109
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
std::unique_ptr< const GBRForest > gbrForest_
const reco::Track * bestTrack() const override
Definition: PFCandidate.h:162

Member Data Documentation

float pat::MuonMvaEstimator::dRmax_
private

Definition at line 39 of file MuonMvaEstimator.h.

Referenced by computeMva().

float pat::MuonMvaEstimator::eta_ = 0.0
private

Definition at line 43 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

std::unique_ptr<const GBRForest> pat::MuonMvaEstimator::gbrForest_
private

Definition at line 38 of file MuonMvaEstimator.h.

Referenced by computeMva(), and MuonMvaEstimator().

float pat::MuonMvaEstimator::jetBTagCSV_ = 0.0
private

Definition at line 49 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::jetNDauCharged_ = 0.0
private

Definition at line 44 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::jetPtRatio_ = 0.0
private

Definition at line 48 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::jetPtRel_ = 0.0
private

Definition at line 47 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::log_abs_dxyBS_ = 0.0
private

Definition at line 51 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::log_abs_dzPV_ = 0.0
private

Definition at line 52 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::miniRelIsoCharged_ = 0.0
private

Definition at line 45 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::miniRelIsoNeutral_ = 0.0
private

Definition at line 46 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::pt_ = 0.0
private

MVA VAriables.

Definition at line 42 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::segmentCompatibility_ = 0.0
private

Definition at line 53 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().

float pat::MuonMvaEstimator::sip_ = 0.0
private

Definition at line 50 of file MuonMvaEstimator.h.

Referenced by MuonMvaEstimator().