CMS 3D CMS Logo

SoftMuonMvaEstimator.cc
Go to the documentation of this file.
4 
5 using namespace pat;
6 
8  tmvaReader_("!Color:!Silent:Error"),
9  initialized_(false),
10  mva_(0)
11 {}
12 
14 {
15  if (initialized_) return;
16  tmvaReader_.AddVariable("segComp", &segmentCompatibility_);
17  tmvaReader_.AddVariable("chi2LocMom", &chi2LocalMomentum_);
18  tmvaReader_.AddVariable("chi2LocPos", &chi2LocalPosition_);
19  tmvaReader_.AddVariable("glbTrackTailProb", &glbTrackProbability_);
20  tmvaReader_.AddVariable("iValFrac", &iValidFraction_);
21  tmvaReader_.AddVariable("LWH", &layersWithMeasurement_);
22  tmvaReader_.AddVariable("kinkFinder", &trkKink_);
23  tmvaReader_.AddVariable("TMath::Log(2+glbKinkFinder)", &log2PlusGlbKink_);
24  tmvaReader_.AddVariable("timeAtIpInOutErr", &timeAtIpInOutErr_);
25  tmvaReader_.AddVariable("outerChi2", &outerChi2_);
26  tmvaReader_.AddVariable("innerChi2", &innerChi2_);
27  tmvaReader_.AddVariable("trkRelChi2", &trkRelChi2_);
28  tmvaReader_.AddVariable("vMuonHitComb", &vMuonHitComb_);
29  tmvaReader_.AddVariable("Qprod", &qProd_);
30 
31  tmvaReader_.AddSpectator("pID", &pID_);
32  tmvaReader_.AddSpectator("pt", &pt_);
33  tmvaReader_.AddSpectator("eta", &eta_);
34  tmvaReader_.AddSpectator("MomID", &momID_);
35 
36  tmvaReader_.BookMVA("BDT", weightsfile);
37  initialized_ = true;
38 }
39 
41 {
42  if (not initialized_)
43  throw cms::Exception("FatalError") << "SoftMuonMVA is not initialized";
44 
45  reco::TrackRef gTrack = muon.globalTrack();
46  reco::TrackRef iTrack = muon.innerTrack();
47  reco::TrackRef oTrack = muon.outerTrack();
48 
49  if(!(muon.innerTrack().isNonnull() and
50  muon.outerTrack().isNonnull() and
51  muon.globalTrack().isNonnull()))
52  {
53  mva_ = -1;
54  return;
55  }
56 
57  //VARIABLE EXTRACTION
58  pt_ = muon.pt();
59  eta_ = muon.eta();
60  dummy_ = -1;
61  momID_ = dummy_;
62  pID_ = dummy_;
63 
64 
69 
71  log2PlusGlbKink_ = TMath::Log(2+muon.combinedQuality().glbKink);
73 
75 
76  //TRACK RELATED VARIABLES
77 
78  iValidFraction_ = iTrack->validFraction();
79  innerChi2_ = iTrack->normalizedChi2();
80  layersWithMeasurement_ = iTrack->hitPattern().trackerLayersWithMeasurement();
81 
82  outerChi2_ = oTrack->normalizedChi2();
83 
84  qProd_ = iTrack->charge()*oTrack->charge();
85 
86  //vComb Calculation
87 
88  const reco::HitPattern &gMpattern = gTrack->hitPattern();
89 
90  std::vector<int> fvDThits = {0,0,0,0};
91  std::vector<int> fvRPChits = {0,0,0,0};
92  std::vector<int> fvCSChits = {0,0,0,0};
93 
94  vMuonHitComb_ = 0;
95 
96  for (int i=0;i<gMpattern.numberOfAllHits(reco::HitPattern::TRACK_HITS);i++){
97 
98  uint32_t hit = gMpattern.getHitPattern(reco::HitPattern::TRACK_HITS, i);
99  if ( !gMpattern.validHitFilter(hit) ) continue;
100 
101  int muStation0 = gMpattern.getMuonStation(hit) - 1;
102  if (muStation0 >=0 && muStation0 < 4){
103  if (gMpattern.muonDTHitFilter(hit)) fvDThits[muStation0]++;
104  if (gMpattern.muonRPCHitFilter(hit)) fvRPChits[muStation0]++;
105  if (gMpattern.muonCSCHitFilter(hit)) fvCSChits[muStation0]++;
106  }
107 
108  }
109 
110 
111  for (unsigned int station = 0; station < 4; ++station) {
112 
113  vMuonHitComb_ += (fvDThits[station])/2.;
114  vMuonHitComb_ += fvRPChits[station];
115 
116  if (fvCSChits[station] > 6){
117  vMuonHitComb_ += 6;
118  }else{
119  vMuonHitComb_ += fvCSChits[station];
120  }
121 
122  }
123 
124  if(chi2LocalMomentum_ < 5000 and chi2LocalPosition_ < 2000 and
125  glbTrackProbability_ < 5000 and trkKink_ < 900 and
126  log2PlusGlbKink_ < 50 and timeAtIpInOutErr_ < 4 and
127  outerChi2_ < 1000 and innerChi2_ < 10 and trkRelChi2_ < 3)
128  {
129  mva_ = tmvaReader_.EvaluateMVA("BDT");
130  }else{ mva_ = -1; }
131 
132 }
float chi2LocalPosition
chi2 value for the STA-TK matching of local position
Definition: MuonQuality.h:19
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:253
double eta() const final
momentum pseudorapidity
float chi2LocalMomentum
chi2 value for the STA-TK matching of local momentum
Definition: MuonQuality.h:21
void computeMva(const pat::Muon &imuon)
void initialize(std::string weightsfile)
float glbKink
value of the kink algorithm applied to the global track
Definition: MuonQuality.h:13
float glbTrackProbability
the tail probability (-ln(P)) of the global fit
Definition: MuonQuality.h:29
double pt() const final
transverse momentum
float trkKink
value of the kink algorithm applied to the inner track stub
Definition: MuonQuality.h:11
float trkRelChi2
chi2 value for the inner track stub with respect to the global track
Definition: MuonQuality.h:15
MuonTime time() const
get DT/CSC combined timing information
Definition: Muon.h:131
Definition: HeavyIon.h:7
static bool validHitFilter(uint16_t pattern)
Definition: HitPattern.h:787
double segmentCompatibility(reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration) const
Returns the segment compatibility, using muon::segmentCompatibility (DataFormats/MuonReco/interface/M...
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:73
reco::TrackRef outerTrack() const override
reference to Track reconstructed in the muon detector only (reimplemented from reco::Muon) ...
Definition: Muon.h:77
static bool muonCSCHitFilter(uint16_t pattern)
Definition: HitPattern.h:640
float timeAtIpInOutErr
Definition: MuonTime.h:15
int numberOfAllHits(HitCategory category) const
Definition: HitPattern.h:807
MuonQuality combinedQuality() const
get energy deposition information
Definition: Muon.h:121
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:81
static bool muonDTHitFilter(uint16_t pattern)
Definition: HitPattern.h:630
static uint16_t getMuonStation(uint16_t pattern)
Muon station (1-4). Only valid for muon patterns, of course. only for patterns from muon...
Definition: HitPattern.h:742
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:515
static bool muonRPCHitFilter(uint16_t pattern)
Definition: HitPattern.h:650
Analysis-level muon class.
Definition: Muon.h:50