CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TemplatedJetProbabilityComputer.h
Go to the documentation of this file.
1 #ifndef ImpactParameter_TemplatedJetProbabilityComputer_h
2 #define ImpactParameter_TemplatedJetProbabilityComputer_h
3 
9 #include "Math/GenVector/VectorUtil.h"
11 
12 #include <iostream>
13 
14 template <class Container, class Base>
16 public:
17  using Tokens = void;
18 
20 
22  m_ipType = parameters.getParameter<int>("impactParameterType");
23  m_minTrackProb = parameters.getParameter<double>("minimumProbability");
24  m_deltaR = parameters.getParameter<double>("deltaR");
25  m_trackSign = parameters.getParameter<int>("trackIpSign");
26  m_cutMaxDecayLen = parameters.getParameter<double>("maximumDecayLength");
27  m_cutMaxDistToAxis = parameters.getParameter<double>("maximumDistanceToJetAxis");
28  //
29  // access track quality class; "any" takes everything
30  //
31  std::string trackQualityType = parameters.getParameter<std::string>("trackQualityClass"); //used
33  m_useAllQualities = false;
34  if (trackQualityType == "any" || trackQualityType == "Any" || trackQualityType == "ANY")
35  m_useAllQualities = true;
36 
37  useVariableJTA_ = parameters.getParameter<bool>("useVariableJTA");
38  if (useVariableJTA_)
39  varJTApars = {parameters.getParameter<double>("a_dR"),
40  parameters.getParameter<double>("b_dR"),
41  parameters.getParameter<double>("a_pT"),
42  parameters.getParameter<double>("b_pT"),
43  parameters.getParameter<double>("min_pT"),
44  parameters.getParameter<double>("max_pT"),
45  parameters.getParameter<double>("min_pT_dRcut"),
46  parameters.getParameter<double>("max_pT_dRcut"),
47  parameters.getParameter<double>("max_pT_trackPTcut")};
48 
49  uses("ipTagInfos");
50  }
51 
52  float discriminator(const TagInfoHelper& ti) const override {
53  const TagInfo& tkip = ti.get<TagInfo>();
54  const Container& tracks(tkip.selectedTracks());
55  const std::vector<float>& allProbabilities((tkip.probabilities(m_ipType)));
56  const std::vector<reco::btag::TrackIPData>& impactParameters((tkip.impactParameterData()));
57 
58  if (tkip.primaryVertex().isNull())
59  return 0;
60 
61  GlobalPoint pv(tkip.primaryVertex()->position().x(),
62  tkip.primaryVertex()->position().y(),
63  tkip.primaryVertex()->position().z());
64 
65  std::vector<float> probabilities;
66  int i = 0;
67  for (std::vector<float>::const_iterator it = allProbabilities.begin(); it != allProbabilities.end(); ++it, i++) {
68  if (fabs(impactParameters[i].distanceToJetAxis.value()) < m_cutMaxDistToAxis && // distance to JetAxis
69  (impactParameters[i].closestToJetAxis - pv).mag() < m_cutMaxDecayLen && // max decay len
70  (m_useAllQualities == true ||
71  reco::btag::toTrack(tracks[i])->quality(m_trackQuality)) // use selected track qualities
72  ) {
73  float p;
74  if (m_trackSign == 0) {
75  if (*it >= 0) {
76  p = *it / 2.;
77  } else {
78  p = 1. + *it / 2.;
79  }
80  } else if (m_trackSign > 0) {
81  if (*it >= 0)
82  p = *it;
83  else
84  continue;
85  } else {
86  if (*it <= 0)
87  p = -*it;
88  else
89  continue;
90  }
91  if (useVariableJTA_) {
92  if (tkip.variableJTA(varJTApars)[i])
93  probabilities.push_back(p);
94  } else {
95  if (m_deltaR <= 0 ||
96  ROOT::Math::VectorUtil::DeltaR((*tkip.jet()).p4().Vect(), (*tracks[i]).momentum()) < m_deltaR)
97  probabilities.push_back(p);
98  }
99  }
100  }
101  return jetProbability(probabilities);
102  }
103 
104  double jetProbability(const std::vector<float>& v) const {
105  int ngoodtracks = v.size();
106  double SumJet = 0.;
107 
108  for (std::vector<float>::const_iterator q = v.begin(); q != v.end(); q++) {
109  SumJet += (*q > m_minTrackProb) ? log(*q) : log(m_minTrackProb);
110  }
111 
112  double ProbJet;
113  double Loginvlog = 0;
114 
115  if (SumJet < 0.) {
116  if (ngoodtracks >= 2) {
117  Loginvlog = log(-SumJet);
118  }
119  double Prob = 1.;
120  double lfact = 1.;
121  for (int l = 1; l != ngoodtracks; l++) {
122  lfact *= l;
123  Prob += exp(l * Loginvlog - log(1. * lfact));
124  }
125  double LogProb = log(Prob);
126  ProbJet = std::min(exp(std::max(LogProb + SumJet, -30.)), 1.);
127  } else {
128  ProbJet = 1.;
129  }
130  if (ProbJet > 1)
131  std::cout << "ProbJet too high: " << ProbJet << std::endl;
132 
133  //double LogProbJet=-log(ProbJet);
134  // //return 1.-ProbJet;
135  return -log10(ProbJet) / 4.;
136  }
137 
138 private:
142  int m_ipType;
143  double m_deltaR;
149 };
150 
151 #endif // ImpactParameter_TemplatedJetProbabilityComputer_h
const std::vector< float > & probabilities(int ip) const
Definition: IPTagInfo.h:101
static std::vector< std::string > checklist log
const T & get(unsigned int index=0) const
reco::TrackBase::TrackQuality m_trackQuality
std::vector< bool > variableJTA(const btag::variableJTAParameters &params) const
Definition: IPTagInfo.h:210
TrackQuality
track quality
Definition: TrackBase.h:150
TemplatedJetProbabilityComputer(const edm::ParameterSet &parameters)
const Container & selectedTracks() const
Definition: IPTagInfo.h:99
auto const & tracks
cannot be loose
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
const reco::Track * toTrack(const reco::TrackBaseRef &t)
Definition: IPTagInfo.h:24
const edm::Ref< VertexCollection > & primaryVertex() const
Definition: IPTagInfo.h:133
reco::IPTagInfo< Container, Base > TagInfo
double jetProbability(const std::vector< float > &v) const
float discriminator(const TagInfoHelper &ti) const override
void uses(unsigned int id, const std::string &label)
reco::btag::variableJTAParameters varJTApars
bool isNull() const
Checks for null.
Definition: Ref.h:235
const std::vector< btag::TrackIPData > & impactParameterData() const
Definition: IPTagInfo.h:90
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:126
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:552
tuple cout
Definition: gather_cfg.py:144
edm::AssociationVector< reco::JetRefBaseProd, Values > Container