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  uses("ipTagInfos");
37  }
38 
39  float discriminator(const TagInfoHelper & ti) const
40  {
41  const reco::TrackIPTagInfo & tkip = ti.get<reco::TrackIPTagInfo>();
43  const std::vector<float> & allProbabilities((tkip.probabilities(m_ipType)));
44  const std::vector<reco::TrackIPTagInfo::TrackIPData> & impactParameters((tkip.impactParameterData()));
45 
46  if(tkip.primaryVertex().isNull()) return 0;
47 
48  GlobalPoint pv(tkip.primaryVertex()->position().x(),tkip.primaryVertex()->position().y(),tkip.primaryVertex()->position().z());
49 
50  std::vector<float> probabilities;
51  std::vector<float> probabilitiesB;
52  int i=0;
53  for(std::vector<float>::const_iterator it = allProbabilities.begin(); it!=allProbabilities.end(); ++it, i++)
54  {
55  if (fabs(impactParameters[i].distanceToJetAxis.value()) < m_cutMaxDistToAxis && // distance to JetAxis
56  (impactParameters[i].closestToJetAxis - pv).mag() < m_cutMaxDecayLen && // max decay len
57  (m_useAllQualities == true || (*tracks[i]).quality(m_trackQuality)) // use selected track qualities
58  )
59  {
60  // Use only positive(or negative) tracks for B
61  float p=fabs(*it);
62  if( m_deltaR < 0 || ROOT::Math::VectorUtil::DeltaR((*tkip.jet()).p4().Vect(), (*tracks[i]).momentum()) < m_deltaR)
63  {
64  //if(m_trackSign>0 || *it >0 ) probabilities.push_back(p); //Use all tracks for positive tagger and only negative for negative tagger
65  if(m_trackSign>0 || *it <0 ) probabilities.push_back(p); //Use all tracks for positive tagger and only negative for negative tagger
66 
67  if(m_trackSign>0 && *it >=0){probabilitiesB.push_back(*it);} //Use only positive tracks for positive tagger
68  if(m_trackSign<0 && *it <=0){probabilitiesB.push_back(- *it);} //Use only negative tracks for negative tagger
69  }
70  }
71  }
72 
73  float all = jetProbability(probabilities);
74  std::sort(probabilitiesB.begin(), probabilitiesB.end());
75  if(probabilitiesB.size() > m_nbTracks ) probabilitiesB.resize(m_nbTracks);
76  float b = jetProbability(probabilitiesB);
77 
78  return -log(b)/4-log(all)/4;
79  }
80 
81 double jetProbability( const std::vector<float> & v ) const
82 {
83  int ngoodtracks=v.size();
84  double SumJet=0.;
85 
86  for(std::vector<float>::const_iterator q = v.begin(); q != v.end(); q++){
87  SumJet+=(*q>m_minTrackProb)?log(*q):log(m_minTrackProb);
88  }
89 
90  double ProbJet;
91  double Loginvlog=0;
92 
93  if(SumJet<0.){
94  if(ngoodtracks>=2){
95  Loginvlog=log(-SumJet);
96  }
97  double Prob=1.;
98  double lfact=1.;
99  for(int l=1; l!=ngoodtracks; l++){
100  lfact*=l;
101  Prob+=exp(l*Loginvlog-log(1.*lfact));
102  }
103  double LogProb=log(Prob);
104  ProbJet=
105  std::min(exp(std::max(LogProb+SumJet,-30.)),1.);
106  }else{
107  ProbJet=1.;
108  }
109  if(ProbJet>1)
110  std::cout << "ProbJet too high: " << ProbJet << std::endl;
111 
112  //double LogProbJet=-log(ProbJet);
113  // //return 1.-ProbJet;
114  return ProbJet;
115  }
116  private:
118  int m_ipType;
119  double m_deltaR;
121  unsigned int m_nbTracks;
126 
127 };
128 
129 #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:95
#define min(a, b)
Definition: mlp_lapack.h:161
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
const T & max(const T &a, const T &b)
double p4[4]
Definition: TauolaWrapper.h:92
void uses(unsigned int id, const std::string &label)
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
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
mathSSE::Vec4< T > v