CMS 3D CMS Logo

SoftMuonMvaEstimator.cc
Go to the documentation of this file.
2 
8 
9 #include "TMVA/Reader.h"
10 #include "TMVA/MethodBDT.h"
11 
12 using namespace pat;
13 
14 namespace {
15  constexpr char softmuon_mva_name[] = "BDT";
16 }
17 
19 {
20  TMVA::Reader tmvaReader("!Color:!Silent:Error");
21  tmvaReader.AddVariable("segComp", &segmentCompatibility_);
22  tmvaReader.AddVariable("chi2LocMom", &chi2LocalMomentum_);
23  tmvaReader.AddVariable("chi2LocPos", &chi2LocalPosition_);
24  tmvaReader.AddVariable("glbTrackTailProb", &glbTrackProbability_);
25  tmvaReader.AddVariable("iValFrac", &iValidFraction_);
26  tmvaReader.AddVariable("LWH", &layersWithMeasurement_);
27  tmvaReader.AddVariable("kinkFinder", &trkKink_);
28  tmvaReader.AddVariable("TMath::Log(2+glbKinkFinder)", &log2PlusGlbKink_);
29  tmvaReader.AddVariable("timeAtIpInOutErr", &timeAtIpInOutErr_);
30  tmvaReader.AddVariable("outerChi2", &outerChi2_);
31  tmvaReader.AddVariable("innerChi2", &innerChi2_);
32  tmvaReader.AddVariable("trkRelChi2", &trkRelChi2_);
33  tmvaReader.AddVariable("vMuonHitComb", &vMuonHitComb_);
34  tmvaReader.AddVariable("Qprod", &qProd_);
35 
36  tmvaReader.AddSpectator("pID", &pID_);
37  tmvaReader.AddSpectator("pt", &pt_);
38  tmvaReader.AddSpectator("eta", &eta_);
39  tmvaReader.AddSpectator("MomID", &momID_);
40 
41  auto temp{ tmvaReader.BookMVA(softmuon_mva_name, weightsfile.c_str()) };
42  gbrForest_ = std::make_unique<GBRForest>( dynamic_cast<TMVA::MethodBDT*>( temp ) );
43 }
44 
46 
47 namespace {
48  enum inputIndexes {
49  kSegmentCompatibility,
50  kChi2LocalMomentum,
51  kChi2LocalPosition,
52  kGlbTrackProbability,
53  kIValidFraction,
54  kLayersWithMeasurement,
55  kTrkKink,
56  kLog2PlusGlbKink,
57  kTimeAtIpInOutErr,
58  kOuterChi2,
59  kInnerChi2,
60  kTrkRelChi2,
61  kVMuonHitComb,
62  kQProd,
63  kPID,
64  kPt,
65  kEta,
66  kMomID,
67  kLast
68  };
69 }
70 
72 {
73  float var[kLast]{};
74 
75  reco::TrackRef gTrack = muon.globalTrack();
76  reco::TrackRef iTrack = muon.innerTrack();
77  reco::TrackRef oTrack = muon.outerTrack();
78 
79  if(!(muon.innerTrack().isNonnull() and
80  muon.outerTrack().isNonnull() and
81  muon.globalTrack().isNonnull()))
82  {
83  return -1;
84  }
85 
86  //VARIABLE EXTRACTION
87  var[kPt] = muon.pt();
88  var[kEta] = muon.eta();
89  var[kMomID] = -1;
90  var[kPID] = -1;
91 
92  var[kChi2LocalMomentum] = muon.combinedQuality().chi2LocalMomentum;
93  var[kChi2LocalPosition] = muon.combinedQuality().chi2LocalPosition;
94  var[kGlbTrackProbability] = muon.combinedQuality().glbTrackProbability;
95  var[kTrkRelChi2] = muon.combinedQuality().trkRelChi2;
96 
97  var[kTrkKink] = muon.combinedQuality().trkKink;
98  var[kLog2PlusGlbKink] = TMath::Log(2+muon.combinedQuality().glbKink);
99  var[kSegmentCompatibility] = muon.segmentCompatibility();
100 
101  var[kTimeAtIpInOutErr] = muon.time().timeAtIpInOutErr;
102 
103  //TRACK RELATED VARIABLES
104 
105  var[kIValidFraction] = iTrack->validFraction();
106  var[kInnerChi2] = iTrack->normalizedChi2();
107  var[kLayersWithMeasurement] = iTrack->hitPattern().trackerLayersWithMeasurement();
108 
109  var[kOuterChi2] = oTrack->normalizedChi2();
110 
111  var[kQProd] = iTrack->charge()*oTrack->charge();
112 
113  //vComb Calculation
114 
115  const reco::HitPattern &gMpattern = gTrack->hitPattern();
116 
117  std::vector<int> fvDThits = {0,0,0,0};
118  std::vector<int> fvRPChits = {0,0,0,0};
119  std::vector<int> fvCSChits = {0,0,0,0};
120 
121  var[kVMuonHitComb] = 0;
122 
123  for (int i=0;i<gMpattern.numberOfAllHits(reco::HitPattern::TRACK_HITS);i++){
124 
125  uint32_t hit = gMpattern.getHitPattern(reco::HitPattern::TRACK_HITS, i);
126  if ( !gMpattern.validHitFilter(hit) ) continue;
127 
128  int muStation0 = gMpattern.getMuonStation(hit) - 1;
129  if (muStation0 >=0 && muStation0 < 4){
130  if (gMpattern.muonDTHitFilter(hit)) fvDThits[muStation0]++;
131  if (gMpattern.muonRPCHitFilter(hit)) fvRPChits[muStation0]++;
132  if (gMpattern.muonCSCHitFilter(hit)) fvCSChits[muStation0]++;
133  }
134 
135  }
136 
137 
138  for (unsigned int station = 0; station < 4; ++station) {
139 
140  var[kVMuonHitComb] += (fvDThits[station])/2.;
141  var[kVMuonHitComb] += fvRPChits[station];
142 
143  if (fvCSChits[station] > 6){
144  var[kVMuonHitComb] += 6;
145  }else{
146  var[kVMuonHitComb] += fvCSChits[station];
147  }
148 
149  }
150 
151  if(var[kChi2LocalMomentum] < 5000 and var[kChi2LocalPosition] < 2000 and
152  var[kGlbTrackProbability] < 5000 and var[kTrkKink] < 900 and
153  var[kLog2PlusGlbKink] < 50 and var[kTimeAtIpInOutErr] < 4 and
154  var[kOuterChi2] < 1000 and var[kInnerChi2] < 10 and var[kTrkRelChi2] < 3)
155  {
156  return gbrForest_->GetAdaBoostClassifier(var);
157  } else {
158  return -1;
159  }
160 }
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
example_track example_track const char *const kPt
Definition: TSelector.cc:34
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
#define constexpr
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:788
inputIndexes
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
SoftMuonMvaEstimator(const std::string &weightsfile)
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:641
float timeAtIpInOutErr
Definition: MuonTime.h:15
int numberOfAllHits(HitCategory category) const
Definition: HitPattern.h:808
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:631
std::unique_ptr< const GBRForest > gbrForest_
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:743
float computeMva(const pat::Muon &imuon) const
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:516
static bool muonRPCHitFilter(uint16_t pattern)
Definition: HitPattern.h:651
Analysis-level muon class.
Definition: Muon.h:50