CMS 3D CMS Logo

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