CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/RecoBTag/ImpactParameter/interface/JetBProbabilityComputer.h

Go to the documentation of this file.
00001 #ifndef ImpactParameter_JetBProbabilityComputer_h
00002 #define ImpactParameter_JetBProbabilityComputer_h
00003 
00004 #include "DataFormats/TrackReco/interface/Track.h"
00005 #include "DataFormats/BTauReco/interface/TrackProbabilityTagInfo.h"
00006 #include "DataFormats/BTauReco/interface/TrackIPTagInfo.h"
00007 #include "DataFormats/VertexReco/interface/Vertex.h"
00008 #include "Math/GenVector/VectorUtil.h"
00009 #include "RecoBTau/JetTagComputer/interface/JetTagComputer.h"
00010 #include <algorithm>
00011 #include <iostream>
00012 
00013 class JetBProbabilityComputer : public JetTagComputer
00014 {
00015  public:
00016   JetBProbabilityComputer(const edm::ParameterSet  & parameters )
00017   { 
00018      m_ipType           = parameters.getParameter<int>("impactParameterType");
00019      m_minTrackProb     = parameters.getParameter<double>("minimumProbability");
00020      m_deltaR           = parameters.getParameter<double>("deltaR");
00021      m_trackSign        = parameters.getParameter<int>("trackIpSign");
00022      m_nbTracks         = parameters.getParameter<unsigned int>("numberOfBTracks");
00023      m_cutMaxDecayLen   = parameters.getParameter<double>("maximumDecayLength");
00024      m_cutMaxDistToAxis = parameters.getParameter<double>("maximumDistanceToJetAxis");
00025  
00026      //
00027      // access track quality class; "any" takes everything
00028      //
00029      std::string trackQualityType = parameters.getParameter<std::string>("trackQualityClass"); //used
00030      m_trackQuality =  reco::TrackBase::qualityByName(trackQualityType);
00031      m_useAllQualities = false;
00032      if (trackQualityType == "any" || 
00033          trackQualityType == "Any" || 
00034          trackQualityType == "ANY" ) m_useAllQualities = true;
00035 
00036      uses("ipTagInfos");
00037   }
00038  
00039   float discriminator(const TagInfoHelper & ti) const 
00040    {
00041       const reco::TrackIPTagInfo & tkip = ti.get<reco::TrackIPTagInfo>();
00042       const edm::RefVector<reco::TrackCollection> & tracks(tkip.selectedTracks());
00043       const std::vector<float> & allProbabilities((tkip.probabilities(m_ipType)));
00044       const std::vector<reco::TrackIPTagInfo::TrackIPData> & impactParameters((tkip.impactParameterData()));
00045 
00046       if(tkip.primaryVertex().isNull()) return 0;
00047 
00048       GlobalPoint pv(tkip.primaryVertex()->position().x(),tkip.primaryVertex()->position().y(),tkip.primaryVertex()->position().z());
00049 
00050       std::vector<float> probabilities;
00051       std::vector<float> probabilitiesB;
00052       int i=0;
00053       for(std::vector<float>::const_iterator it = allProbabilities.begin(); it!=allProbabilities.end(); ++it, i++)
00054        {
00055         if (fabs(impactParameters[i].distanceToJetAxis.value()) < m_cutMaxDistToAxis  &&        // distance to JetAxis
00056             (impactParameters[i].closestToJetAxis - pv).mag() < m_cutMaxDecayLen  &&      // max decay len
00057             (m_useAllQualities  == true || (*tracks[i]).quality(m_trackQuality)) // use selected track qualities
00058            )
00059          {
00060     // Use only positive(or negative) tracks for B
00061            float p=fabs(*it);
00062            if( m_deltaR < 0 || ROOT::Math::VectorUtil::DeltaR((*tkip.jet()).p4().Vect(), (*tracks[i]).momentum()) < m_deltaR)
00063              {
00064                //if(m_trackSign>0 || *it >0 ) probabilities.push_back(p); //Use all tracks for positive tagger and only negative for negative tagger
00065                if(m_trackSign>0 || *it <0 ) probabilities.push_back(p); //Use all tracks for positive tagger and only negative for negative tagger
00066 
00067                if(m_trackSign>0 && *it >=0){probabilitiesB.push_back(*it);} //Use only positive tracks for positive tagger
00068                if(m_trackSign<0 && *it <=0){probabilitiesB.push_back(- *it);} //Use only negative tracks for negative tagger 
00069              }
00070          }
00071        }
00072 
00073       float all = jetProbability(probabilities); 
00074       std::sort(probabilitiesB.begin(), probabilitiesB.end());
00075       if(probabilitiesB.size() > m_nbTracks )  probabilitiesB.resize(m_nbTracks);
00076       float b = jetProbability(probabilitiesB);
00077         
00078       return -log(b)/4-log(all)/4; 
00079    }
00080 
00081 double jetProbability( const std::vector<float> & v ) const
00082 {
00083    int ngoodtracks=v.size();
00084    double SumJet=0.;
00085 
00086   for(std::vector<float>::const_iterator q = v.begin(); q != v.end(); q++){
00087     SumJet+=(*q>m_minTrackProb)?log(*q):log(m_minTrackProb);
00088   }
00089 
00090   double ProbJet;
00091   double Loginvlog=0;
00092 
00093   if(SumJet<0.){
00094     if(ngoodtracks>=2){
00095       Loginvlog=log(-SumJet);
00096     }
00097     double Prob=1.;
00098     double lfact=1.;
00099     for(int l=1; l!=ngoodtracks; l++){
00100        lfact*=l;
00101       Prob+=exp(l*Loginvlog-log(1.*lfact));
00102     }
00103     double LogProb=log(Prob);
00104     ProbJet=
00105       std::min(exp(std::max(LogProb+SumJet,-30.)),1.);
00106   }else{
00107     ProbJet=1.;
00108   }
00109   if(ProbJet>1)
00110    std::cout << "ProbJet too high: "  << ProbJet << std::endl;
00111 
00112   //double LogProbJet=-log(ProbJet);
00113   //  //return 1.-ProbJet;
00114       return ProbJet;
00115   }
00116  private:
00117    double m_minTrackProb;
00118    int m_ipType;
00119    double m_deltaR;
00120    int m_trackSign;
00121    unsigned int m_nbTracks;
00122    double  m_cutMaxDecayLen;
00123    double m_cutMaxDistToAxis;
00124    reco::TrackBase::TrackQuality   m_trackQuality;
00125    bool m_useAllQualities;
00126 
00127 };
00128 
00129 #endif // ImpactParameter_JetBProbabilityComputer_h