CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MuonMvaIDEstimator.cc
Go to the documentation of this file.
9 
10 using namespace pat;
11 using namespace cms::Ort;
12 
14  randomForest_ = std::make_unique<ONNXRuntime>(weightsfile.fullPath());
15  LogDebug("MuonMvaIDEstimator") << randomForest_.get();
16 }
17 
20  desc.add<edm::FileInPath>("mvaIDTrainingFile", edm::FileInPath("RecoMuon/MuonIdentification/data/mvaID.onnx"));
21  desc.add<std::vector<std::string>>("flav_names",
22  std::vector<std::string>{
23  "probBAD",
24  "probGOOD",
25  });
26 
27  descriptions.addWithDefaultLabel(desc);
28 }
29 
32 std::vector<float> MuonMvaIDEstimator::computeMVAID(const pat::Muon &muon) const {
33  const float local_chi2 = muon.combinedQuality().chi2LocalPosition;
34  const float kink = muon.combinedQuality().trkKink;
35  const float segment_comp = muon.segmentCompatibility(arbitrationType);
36  const float n_MatchedStations = muon.numberOfMatchedStations();
37  const float pt = muon.pt();
38  const float eta = muon.eta();
39  const float global_muon = muon.isGlobalMuon();
40  float Valid_pixel;
41  float tracker_layers;
42  float validFraction;
43  if (muon.innerTrack().isNonnull()) {
44  Valid_pixel = muon.innerTrack()->hitPattern().numberOfValidPixelHits();
45  tracker_layers = muon.innerTrack()->hitPattern().trackerLayersWithMeasurement();
46  validFraction = muon.innerTrack()->validFraction();
47  } else {
48  Valid_pixel = -99.;
49  tracker_layers = -99.0;
50  validFraction = -99.0;
51  }
52  float norm_chi2;
53  float n_Valid_hits;
54  if (muon.globalTrack().isNonnull()) {
55  norm_chi2 = muon.globalTrack()->normalizedChi2();
56  n_Valid_hits = muon.globalTrack()->hitPattern().numberOfValidMuonHits();
57  } else if (muon.innerTrack().isNonnull()) {
58  norm_chi2 = muon.innerTrack()->normalizedChi2();
59  n_Valid_hits = muon.innerTrack()->hitPattern().numberOfValidMuonHits();
60  } else {
61  norm_chi2 = -99;
62  n_Valid_hits = -99;
63  }
64  const std::vector<std::string> input_names_{"float_input"};
65  std::vector<float> vars = {global_muon,
66  validFraction,
67  norm_chi2,
68  local_chi2,
69  kink,
70  segment_comp,
71  n_Valid_hits,
72  n_MatchedStations,
73  Valid_pixel,
74  tracker_layers,
75  pt,
76  eta};
77  const std::vector<std::string> flav_names_{"probBAD", "probGOOD"};
78  cms::Ort::FloatArrays input_values_;
79  input_values_.emplace_back(vars);
80  std::vector<float> outputs;
81  LogDebug("MuonMvaIDEstimator") << randomForest_.get();
82  outputs = randomForest_->run(input_names_, input_values_, {}, {"probabilities"})[0];
83  assert(outputs.size() == flav_names_.size());
84  return outputs;
85 }
float chi2LocalPosition
chi2 value for the STA-TK matching of local position
Definition: MuonQuality.h:19
MuonMvaIDEstimator(const edm::FileInPath &weightsfile)
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:238
double pt() const final
transverse momentum
static void globalEndJob(const cms::Ort::ONNXRuntime *)
std::vector< float > computeMVAID(const pat::Muon &imuon) const
float trkKink
value of the kink algorithm applied to the inner track stub
Definition: MuonQuality.h:11
std::vector< std::vector< float > > FloatArrays
Definition: ONNXRuntime.h:23
static void fillDescriptions(edm::ConfigurationDescriptions &)
assert(be >=bs)
double segmentCompatibility(reco::Muon::ArbitrationType arbitrationType=reco::Muon::SegmentAndTrackArbitration) const
Returns the segment compatibility, using muon::segmentCompatibility (DataFormats/MuonReco/interface/M...
ArbitrationType
define arbitration schemes
Definition: Muon.h:187
MuonQuality combinedQuality() const
get energy deposition information
Definition: Muon.h:119
ParameterDescriptionBase * add(U const &iLabel, T const &value)
int numberOfMatchedStations(ArbitrationType type=SegmentAndTrackArbitration) const
const reco::Muon::ArbitrationType arbitrationType
reco::TrackRef globalTrack() const override
reference to Track reconstructed in both tracked and muon detector (reimplemented from reco::Muon) ...
Definition: Muon.h:80
reco::TrackRef innerTrack() const override
reference to Track reconstructed in the tracker only (reimplemented from reco::Muon) ...
Definition: Muon.h:72
std::string fullPath() const
Definition: FileInPath.cc:161
vars
Definition: DeepTauId.cc:164
Analysis-level muon class.
Definition: Muon.h:51
bool isGlobalMuon() const override
Definition: Muon.h:301
def cache
Definition: utilities.py:3
#define LogDebug(id)
double eta() const final
momentum pseudorapidity