CMS 3D CMS Logo

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 {
17  public:
19 
21  {
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" ||
35  trackQualityType == "Any" ||
36  trackQualityType == "ANY" ) m_useAllQualities = true;
37 
38  useVariableJTA_ = parameters.getParameter<bool>("useVariableJTA");
39  if(useVariableJTA_)
40  varJTApars = {
41  parameters.getParameter<double>("a_dR"),
42  parameters.getParameter<double>("b_dR"),
43  parameters.getParameter<double>("a_pT"),
44  parameters.getParameter<double>("b_pT"),
45  parameters.getParameter<double>("min_pT"),
46  parameters.getParameter<double>("max_pT"),
47  parameters.getParameter<double>("min_pT_dRcut"),
48  parameters.getParameter<double>("max_pT_dRcut"),
49  parameters.getParameter<double>("max_pT_trackPTcut") };
50 
51  uses("ipTagInfos");
52  }
53 
54  float discriminator(const TagInfoHelper & ti) const override
55  {
56  const TagInfo & tkip = ti.get<TagInfo>();
57  const Container & tracks(tkip.selectedTracks());
58  const std::vector<float> & allProbabilities((tkip.probabilities(m_ipType)));
59  const std::vector<reco::btag::TrackIPData> & impactParameters((tkip.impactParameterData()));
60 
61  if (tkip.primaryVertex().isNull()) return 0 ;
62 
63  GlobalPoint pv(tkip.primaryVertex()->position().x(),tkip.primaryVertex()->position().y(),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  {
69  if ( fabs(impactParameters[i].distanceToJetAxis.value()) < m_cutMaxDistToAxis && // distance to JetAxis
70  (impactParameters[i].closestToJetAxis - pv).mag() < m_cutMaxDecayLen && // max decay len
71  (m_useAllQualities == true || reco::btag::toTrack(tracks[i])->quality(m_trackQuality)) // use selected track qualities
72  )
73  {
74  float p;
75  if(m_trackSign ==0 )
76  {
77  if (*it >=0){p=*it/2.;}else{p=1.+*it/2.;}
78  }
79  else if(m_trackSign > 0)
80  {
81  if(*it >=0 ) p=*it; else continue;
82  } else
83  {
84  if(*it <=0 ) p= -*it; else continue;
85  }
86  if (useVariableJTA_) {
87  if (tkip.variableJTA( varJTApars )[i])
88  probabilities.push_back(p);
89  }else{
90  if(m_deltaR <= 0 || ROOT::Math::VectorUtil::DeltaR((*tkip.jet()).p4().Vect(), (*tracks[i]).momentum()) < m_deltaR )
91  probabilities.push_back(p);
92  }
93  }
94  }
95  return jetProbability(probabilities);
96  }
97 
98 double jetProbability( const std::vector<float> & v ) const
99 {
100  int ngoodtracks=v.size();
101  double SumJet=0.;
102 
103  for(std::vector<float>::const_iterator q = v.begin(); q != v.end(); q++){
104  SumJet+=(*q>m_minTrackProb)?log(*q):log(m_minTrackProb);
105  }
106 
107  double ProbJet;
108  double Loginvlog=0;
109 
110  if(SumJet<0.){
111  if(ngoodtracks>=2){
112  Loginvlog=log(-SumJet);
113  }
114  double Prob=1.;
115  double lfact=1.;
116  for(int l=1; l!=ngoodtracks; l++){
117  lfact*=l;
118  Prob+=exp(l*Loginvlog-log(1.*lfact));
119  }
120  double LogProb=log(Prob);
121  ProbJet=
122  std::min(exp(std::max(LogProb+SumJet,-30.)),1.);
123  }else{
124  ProbJet=1.;
125  }
126  if(ProbJet>1)
127  std::cout << "ProbJet too high: " << ProbJet << std::endl;
128 
129  //double LogProbJet=-log(ProbJet);
130  // //return 1.-ProbJet;
131  return -log10(ProbJet)/4.;
132  }
133  private:
137  int m_ipType;
138  double m_deltaR;
144 
145 
146 };
147 
148 #endif // ImpactParameter_TemplatedJetProbabilityComputer_h
T getParameter(std::string const &) const
const std::vector< float > & probabilities(int ip) const
Definition: IPTagInfo.h:103
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:212
TrackQuality
track quality
Definition: TrackBase.h:151
TemplatedJetProbabilityComputer(const edm::ParameterSet &parameters)
const Container & selectedTracks() const
Definition: IPTagInfo.h:101
const reco::Track * toTrack(const reco::TrackBaseRef &t)
Definition: IPTagInfo.h:24
reco::IPTagInfo< Container, Base > TagInfo
const edm::Ref< VertexCollection > & primaryVertex() const
Definition: IPTagInfo.h:133
double jetProbability(const std::vector< float > &v) const
double p4[4]
Definition: TauolaWrapper.h:92
void uses(unsigned int id, const std::string &label)
def pv(vc)
Definition: MetAnalyzer.py:7
T min(T a, T b)
Definition: MathUtil.h:58
reco::btag::variableJTAParameters varJTApars
bool isNull() const
Checks for null.
Definition: Ref.h:248
const std::vector< btag::TrackIPData > & impactParameterData() const
Definition: IPTagInfo.h:91
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:134
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:549
float discriminator(const TagInfoHelper &ti) const override
edm::AssociationVector< reco::JetRefBaseProd, Values > Container