CMS 3D CMS Logo

MuonMvaEstimator.cc
Go to the documentation of this file.
8 
9 using namespace pat;
10 
12  tmvaReader_("!Color:!Silent:Error"),
13  initialized_(false),
14  mva_(0),
15  dRmax_(0)
16 {}
17 
19  float dRmax)
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 };
38 
40  const reco::Candidate::LorentzVector& jetP4,
41  bool subtractMuon=true)
42 {
44  if (subtractMuon) jp4-=muP4;
45  float dot = muP4.Vect().Dot( jp4.Vect() );
46  float ptrel = muP4.P2() - dot*dot/jp4.P2();
47  ptrel = ptrel>0 ? sqrt(ptrel) : 0.0;
48  return ptrel;
49 }
50 
52  const reco::Vertex& vertex,
54  const reco::JetCorrector* correctorL1,
55  const reco::JetCorrector* correctorL1L2L3Res)
56 {
57  if (not initialized_)
58  throw cms::Exception("FatalError") << "MuonMVA is not initialized";
59  pt_ = muon.pt();
60  eta_ = muon.eta();
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 };
double eta() const final
momentum pseudorapidity
double dB(IPTYPE type) const
double pt() const final
transverse momentum
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
Definition: HeavyIon.h:7
const PFIsolation & miniPFIsolation() const
Definition: Lepton.h:196
double segmentCompatibility(reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration) const
Returns the segment compatibility, using muon::segmentCompatibility (DataFormats/MuonReco/interface/M...
T sqrt(T t)
Definition: SSEVec.h:18
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
double edB(IPTYPE type) const
float pt_
MVA VAriables.
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
void initialize(std::string weightsfile, float dRmax)
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
void computeMva(const pat::Muon &imuon, const reco::Vertex &vertex, const reco::JetTagCollection &bTags, const reco::JetCorrector *correctorL1=0, const reco::JetCorrector *correctorL1L2L3Res=0)
T dot(const Basic3DVector &v) const
Scalar product, or "dot" product, with a vector of same type.
reco::TrackRef muonBestTrack() const override
Track selected to be the best measurement of the muon parameters (including PFlow global information)...
float chargedHadronIso() const
Definition: PFIsolation.h:33
Analysis-level muon class.
Definition: Muon.h:50
const reco::Track * bestTrack() const override
Definition: PFCandidate.h:162
float neutralHadronIso() const
Definition: PFIsolation.h:34