CMS 3D CMS Logo

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

#include <MuonMvaEstimator.h>

Public Member Functions

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

Private Attributes

float dRmax_
 
float eta_
 
bool initialized_
 
float jetBTagCSV_
 
float jetNDauCharged_
 
float jetPtRatio_
 
float jetPtRel_
 
float log_abs_dxyBS_
 
float log_abs_dzPV_
 
float miniRelIsoCharged_
 
float miniRelIsoNeutral_
 
float mva_
 
float pt_
 MVA VAriables. More...
 
float segmentCompatibility_
 
float sip_
 
TMVA::Reader tmvaReader_
 

Detailed Description

Definition at line 12 of file MuonMvaEstimator.h.

Constructor & Destructor Documentation

MuonMvaEstimator::MuonMvaEstimator ( )

Definition at line 11 of file MuonMvaEstimator.cc.

11  :
12  tmvaReader_("!Color:!Silent:Error"),
13  initialized_(false),
14  mva_(0),
15  dRmax_(0)
16 {}

Member Function Documentation

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

Definition at line 51 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(), eta_, Exception, reco::TrackBase::highPurity, initialized_, metsig::jet, jetBTagCSV_, jetNDauCharged_, jetPtRatio_, jetPtRel_, cmsBatch::log, log_abs_dxyBS_, log_abs_dzPV_, pat::Lepton< LeptonType >::miniPFIsolation(), miniRelIsoCharged_, miniRelIsoNeutral_, pat::Muon::muonBestTrack(), mva_, pat::PFIsolation::neutralHadronIso(), reco::LeafCandidate::p4(), reco::Vertex::position(), reco::LeafCandidate::pt(), pt_, ptRel(), pat::Muon::PV3D, pat::Muon::segmentCompatibility(), segmentCompatibility_, sip_, and tmvaReader_.

Referenced by pat::PATMuonProducer::produce().

56 {
57  if (not initialized_)
58  throw cms::Exception("FatalError") << "MuonMVA is not initialized";
59  pt_ = muon.pt();
60  eta_ = muon.eta();
61  segmentCompatibility_ = muon.segmentCompatibility();
62  miniRelIsoCharged_ = muon.miniPFIsolation().chargedHadronIso();
63  miniRelIsoNeutral_ = muon.miniPFIsolation().neutralHadronIso();
64 
65  double dB2D = fabs(muon.dB(pat::Muon::BS2D));
66  double dB3D = muon.dB(pat::Muon::PV3D);
67  double edB3D = muon.edB(pat::Muon::PV3D);
68  double dz = fabs(muon.muonBestTrack()->dz(vertex.position()));
69  sip_ = edB3D>0?fabs(dB3D/edB3D):0.0;
70  log_abs_dxyBS_ = dB2D>0?log(dB2D):0;
71  log_abs_dzPV_ = dz>0?log(dz):0;
72 
73  //Initialise loop variables
74  double minDr = 9999;
75  double jecL1L2L3Res = 1.;
76  double jecL1 = 1.;
77 
78  jetPtRatio_ = -99;
79  jetPtRel_ = -99;
80  jetBTagCSV_ = -999;
81  jetNDauCharged_ = -1;
82 
83  for (const auto& tagI: bTags){
84  // for each muon with the lepton
85  double dr = deltaR(*(tagI.first), muon);
86  if(dr > minDr) continue;
87  minDr = dr;
88 
89  const reco::Candidate::LorentzVector& muP4(muon.p4());
90  reco::Candidate::LorentzVector jetP4(tagI.first->p4());
91 
92  if (correctorL1 && correctorL1L2L3Res){
93  jecL1L2L3Res = correctorL1L2L3Res->correction(*(tagI.first));
94  jecL1 = correctorL1->correction(*(tagI.first));
95  }
96 
97  // Get b-jet info
98  jetBTagCSV_ = tagI.second;
99  jetNDauCharged_ = 0;
100  for (auto jet: tagI.first->getJetConstituentsQuick()){
101  const reco::PFCandidate *pfcand = dynamic_cast<const reco::PFCandidate*>(jet);
102  if (pfcand==nullptr) throw cms::Exception("ConfigurationError") << "Cannot get jet constituents";
103  if (pfcand->charge()==0) continue;
104  auto bestTrackPtr = pfcand->bestTrack();
105  if (!bestTrackPtr) continue;
106  if (!bestTrackPtr->quality(reco::Track::highPurity)) continue;
107  if (bestTrackPtr->pt()<1.) continue;
108  if (bestTrackPtr->hitPattern().numberOfValidHits()<8) continue;
109  if (bestTrackPtr->hitPattern().numberOfValidPixelHits()<2) continue;
110  if (bestTrackPtr->normalizedChi2()>=5) continue;
111 
112  if (std::fabs(bestTrackPtr->dxy(vertex.position())) > 0.2) continue;
113  if (std::fabs(bestTrackPtr->dz(vertex.position())) > 17) continue;
114  jetNDauCharged_++;
115  }
116 
117  if(minDr < dRmax_){
118  if ((jetP4-muP4).Rho()<0.0001){
119  jetPtRel_ = 0;
120  jetPtRatio_ = 1;
121  } else {
122  jetP4 -= muP4/jecL1;
123  jetP4 *= jecL1L2L3Res;
124  jetP4 += muP4;
125 
126  jetPtRatio_ = muP4.pt()/jetP4.pt();
127  jetPtRel_ = ptRel(muP4,jetP4);
128  }
129  }
130  }
131 
132  if (jetPtRatio_>1.5) jetPtRatio_ = 1.5;
133  if (jetBTagCSV_<0) jetBTagCSV_ = 0;
134  mva_ = tmvaReader_.EvaluateMVA("BDTG");
135 };
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
float pt_
MVA VAriables.
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
float ptRel(const reco::Candidate::LorentzVector &muP4, const reco::Candidate::LorentzVector &jetP4, bool subtractMuon=true)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:40
const reco::Track * bestTrack() const override
Definition: PFCandidate.h:162
void MuonMvaEstimator::initialize ( std::string  weightsfile,
float  dRmax 
)

Definition at line 18 of file MuonMvaEstimator.cc.

References dRmax_, eta_, initialized_, jetBTagCSV_, jetNDauCharged_, jetPtRatio_, jetPtRel_, log_abs_dxyBS_, log_abs_dzPV_, miniRelIsoCharged_, miniRelIsoNeutral_, pt_, segmentCompatibility_, sip_, and tmvaReader_.

Referenced by pat::PATMuonProducer::PATMuonProducer().

20 {
21  if (initialized_) return;
22  tmvaReader_.AddVariable("LepGood_pt", &pt_ );
23  tmvaReader_.AddVariable("LepGood_eta", &eta_ );
24  tmvaReader_.AddVariable("LepGood_jetNDauChargedMVASel", &jetNDauCharged_ );
25  tmvaReader_.AddVariable("LepGood_miniRelIsoCharged", &miniRelIsoCharged_);
26  tmvaReader_.AddVariable("LepGood_miniRelIsoNeutral", &miniRelIsoNeutral_);
27  tmvaReader_.AddVariable("LepGood_jetPtRelv2", &jetPtRel_ );
28  tmvaReader_.AddVariable("min(LepGood_jetPtRatiov2,1.5)", &jetPtRatio_ );
29  tmvaReader_.AddVariable("max(LepGood_jetBTagCSV,0)", &jetBTagCSV_ );
30  tmvaReader_.AddVariable("LepGood_sip3d", &sip_ );
31  tmvaReader_.AddVariable("log(abs(LepGood_dxy))", &log_abs_dxyBS_ );
32  tmvaReader_.AddVariable("log(abs(LepGood_dz))", &log_abs_dzPV_ );
33  tmvaReader_.AddVariable("LepGood_segmentCompatibility", &segmentCompatibility_);
34  tmvaReader_.BookMVA("BDTG",weightsfile);
35  dRmax_ = dRmax;
36  initialized_ = true;
37 };
float pt_
MVA VAriables.
float pat::MuonMvaEstimator::jetPtRatio ( ) const
inline

Definition at line 23 of file MuonMvaEstimator.h.

Referenced by pat::PATMuonProducer::produce().

23 {return jetPtRatio_;}
float pat::MuonMvaEstimator::jetPtRel ( ) const
inline

Definition at line 24 of file MuonMvaEstimator.h.

Referenced by pat::PATMuonProducer::produce().

24 {return jetPtRel_;}
float pat::MuonMvaEstimator::mva ( ) const
inline

Definition at line 22 of file MuonMvaEstimator.h.

Referenced by pat::PATMuonProducer::produce().

22 {return mva_;}

Member Data Documentation

float pat::MuonMvaEstimator::dRmax_
private

Definition at line 29 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::eta_
private

Definition at line 33 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

bool pat::MuonMvaEstimator::initialized_
private

Definition at line 27 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::jetBTagCSV_
private

Definition at line 39 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::jetNDauCharged_
private

Definition at line 34 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::jetPtRatio_
private

Definition at line 38 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::jetPtRel_
private

Definition at line 37 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::log_abs_dxyBS_
private

Definition at line 41 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::log_abs_dzPV_
private

Definition at line 42 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::miniRelIsoCharged_
private

Definition at line 35 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::miniRelIsoNeutral_
private

Definition at line 36 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::mva_
private

Definition at line 28 of file MuonMvaEstimator.h.

Referenced by computeMva().

float pat::MuonMvaEstimator::pt_
private

MVA VAriables.

Definition at line 32 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::segmentCompatibility_
private

Definition at line 43 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

float pat::MuonMvaEstimator::sip_
private

Definition at line 40 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().

TMVA::Reader pat::MuonMvaEstimator::tmvaReader_
private

Definition at line 26 of file MuonMvaEstimator.h.

Referenced by computeMva(), and initialize().