test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
JetBProbabilityComputer.h
Go to the documentation of this file.
1 #ifndef ImpactParameter_JetBProbabilityComputer_h
2 #define ImpactParameter_JetBProbabilityComputer_h
3 
8 #include "Math/GenVector/VectorUtil.h"
10 #include <algorithm>
11 #include <iostream>
12 
14 {
15  public:
17  {
18  m_ipType = parameters.getParameter<int>("impactParameterType");
19  m_minTrackProb = parameters.getParameter<double>("minimumProbability");
20  m_deltaR = parameters.getParameter<double>("deltaR");
21  m_trackSign = parameters.getParameter<int>("trackIpSign");
22  m_nbTracks = parameters.getParameter<unsigned int>("numberOfBTracks");
23  m_cutMaxDecayLen = parameters.getParameter<double>("maximumDecayLength");
24  m_cutMaxDistToAxis = parameters.getParameter<double>("maximumDistanceToJetAxis");
25 
26  //
27  // access track quality class; "any" takes everything
28  //
29  std::string trackQualityType = parameters.getParameter<std::string>("trackQualityClass"); //used
31  m_useAllQualities = false;
32  if (trackQualityType == "any" ||
33  trackQualityType == "Any" ||
34  trackQualityType == "ANY" ) m_useAllQualities = true;
35 
36  useVariableJTA_ = parameters.getParameter<bool>("useVariableJTA");
37  if(useVariableJTA_)
38  varJTApars = {
39  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
53  {
54  const reco::TrackIPTagInfo & tkip = ti.get<reco::TrackIPTagInfo>();
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  std::vector<float> probabilitiesB;
65  int i=0;
66  for(std::vector<float>::const_iterator it = allProbabilities.begin(); it!=allProbabilities.end(); ++it, i++)
67  {
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 || (*tracks[i]).quality(m_trackQuality)) // use selected track qualities
71  )
72  {
73  // Use only positive(or negative) tracks for B
74  float p=fabs(*it);
75  if (useVariableJTA_) {
76  if (tkip.variableJTA( varJTApars )[i]) {
77  if(m_trackSign>0 || *it <0 ) probabilities.push_back(p); //Use all tracks for positive tagger and only negative for negative tagger
78  if(m_trackSign>0 && *it >=0){probabilitiesB.push_back(*it);} //Use only positive tracks for positive tagger
79  if(m_trackSign<0 && *it <=0){probabilitiesB.push_back(- *it);} //Use only negative tracks for negative tagger
80  }
81  }
82  else
83  if( m_deltaR < 0 || ROOT::Math::VectorUtil::DeltaR((*tkip.jet()).p4().Vect(), (*tracks[i]).momentum()) < m_deltaR)
84  {
85  //if(m_trackSign>0 || *it >0 ) probabilities.push_back(p); //Use all tracks for positive tagger and only negative for negative tagger
86  if(m_trackSign>0 || *it <0 ) probabilities.push_back(p); //Use all tracks for positive tagger and only negative for negative tagger
87 
88  if(m_trackSign>0 && *it >=0){probabilitiesB.push_back(*it);} //Use only positive tracks for positive tagger
89  if(m_trackSign<0 && *it <=0){probabilitiesB.push_back(- *it);} //Use only negative tracks for negative tagger
90  }
91  }
92  }
93 
94  float all = jetProbability(probabilities);
95  std::sort(probabilitiesB.begin(), probabilitiesB.end());
96  if(probabilitiesB.size() > m_nbTracks ) probabilitiesB.resize(m_nbTracks);
97  float b = jetProbability(probabilitiesB);
98 
99  return -log(b)/4-log(all)/4;
100  }
101 
102 double jetProbability( const std::vector<float> & v ) const
103 {
104  int ngoodtracks=v.size();
105  double SumJet=0.;
106 
107  for(std::vector<float>::const_iterator q = v.begin(); q != v.end(); q++){
108  SumJet+=(*q>m_minTrackProb)?log(*q):log(m_minTrackProb);
109  }
110 
111  double ProbJet;
112  double Loginvlog=0;
113 
114  if(SumJet<0.){
115  if(ngoodtracks>=2){
116  Loginvlog=log(-SumJet);
117  }
118  double Prob=1.;
119  double lfact=1.;
120  for(int l=1; l!=ngoodtracks; l++){
121  lfact*=l;
122  Prob+=exp(l*Loginvlog-log(1.*lfact));
123  }
124  double LogProb=log(Prob);
125  ProbJet=
126  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 ProbJet;
136  }
137  private:
141  int m_ipType;
142  double m_deltaR;
144  unsigned int m_nbTracks;
149 
150 };
151 
152 #endif // ImpactParameter_JetBProbabilityComputer_h
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
dictionary parameters
Definition: Parameters.py:2
JetBProbabilityComputer(const edm::ParameterSet &parameters)
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
reco::TrackBase::TrackQuality m_trackQuality
bool isNull() const
Checks for null.
Definition: Ref.h:247
float discriminator(const TagInfoHelper &ti) const
double p4[4]
Definition: TauolaWrapper.h:92
std::vector< bool > variableJTA(const variableJTAParameters &params) const
void uses(unsigned int id, const std::string &label)
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
reco::TrackIPTagInfo::variableJTAParameters varJTApars
static TrackQuality qualityByName(const std::string &name)
Definition: TrackBase.cc:46
tuple tracks
Definition: testEve_cfg.py:39
double b
Definition: hdecay.h:120
const std::vector< TrackIPData > & impactParameterData() const
tuple cout
Definition: gather_cfg.py:121
const edm::RefVector< TrackCollection > & selectedTracks() const