Fork me on GitHub

Changeset d77b51d in git for modules/BTagging.cc


Ignore:
Timestamp:
Sep 29, 2015, 2:08:10 PM (9 years ago)
Author:
Michele Selvaggi <michele.selvaggi@…>
Branches:
ImprovedOutputFile, Timing, dual_readout, llp, master
Children:
a98c7ef
Parents:
d870fc5 (diff), 06ec139 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'upstream/master'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/BTagging.cc

    rd870fc5 rd77b51d  
    2222 *  Determines origin of jet,
    2323 *  applies b-tagging efficiency (miss identification rate) formulas
    24  *  and sets b-tagging flags 
     24 *  and sets b-tagging flags
    2525 *
    2626 *  \author P. Demin - UCL, Louvain-la-Neuve
     
    3434#include "classes/DelphesFormula.h"
    3535
    36 #include "ExRootAnalysis/ExRootResult.h"
    37 #include "ExRootAnalysis/ExRootFilter.h"
    38 #include "ExRootAnalysis/ExRootClassifier.h"
    39 
    4036#include "TMath.h"
    4137#include "TString.h"
     
    4642#include "TLorentzVector.h"
    4743
    48 #include <algorithm> 
     44#include <algorithm>
    4945#include <stdexcept>
    5046#include <iostream>
     
    5551//------------------------------------------------------------------------------
    5652
    57 class BTaggingPartonClassifier : public ExRootClassifier
     53BTagging::BTagging() :
     54  fItJetInputArray(0)
    5855{
    59 public:
    60 
    61   BTaggingPartonClassifier() {}
    62 
    63   Int_t GetCategory(TObject *object);
    64  
    65   Double_t fEtaMax, fPTMin;
    66 };
    67 
    68 //------------------------------------------------------------------------------
    69 
    70 Int_t BTaggingPartonClassifier::GetCategory(TObject *object)
    71 {
    72   Candidate *parton = static_cast<Candidate*>(object);
    73   const TLorentzVector &momentum = parton->Momentum;
    74   Int_t pdgCode;
    75 
    76   if(momentum.Pt() <= fPTMin || TMath::Abs(momentum.Eta()) > fEtaMax) return -1;
    77  
    78   pdgCode = TMath::Abs(parton->PID);
    79   if(pdgCode != 21 && pdgCode > 5) return -1;
    80 
    81   return 0;
    82 }
    83 
    84 //------------------------------------------------------------------------------
    85 
    86 BTagging::BTagging() :
    87   fClassifier(0), fFilter(0),
    88   fItPartonInputArray(0), fItJetInputArray(0)
    89 {
    90   fClassifier = new BTaggingPartonClassifier;
    9156}
    9257
     
    9560BTagging::~BTagging()
    9661{
    97   if(fClassifier) delete fClassifier;
    9862}
    9963
     
    10973  fBitNumber = GetInt("BitNumber", 0);
    11074
    111   fDeltaR = GetDouble("DeltaR", 0.5);
    112 
    113   fClassifier->fPTMin = GetDouble("PartonPTMin", 1.0);
    114   fClassifier->fEtaMax = GetDouble("PartonEtaMax", 2.5);
    115 
    11675  // read efficiency formulas
    11776  param = GetParam("EfficiencyFormula");
    11877  size = param.GetSize();
    119  
     78
    12079  fEfficiencyMap.clear();
    12180  for(i = 0; i < size/2; ++i)
     
    13998  // import input array(s)
    14099
    141   fPartonInputArray = ImportArray(GetString("PartonInputArray", "Delphes/partons"));
    142   fItPartonInputArray = fPartonInputArray->MakeIterator();
    143 
    144   fFilter = new ExRootFilter(fPartonInputArray);
    145  
    146100  fJetInputArray = ImportArray(GetString("JetInputArray", "FastJetFinder/jets"));
    147101  fItJetInputArray = fJetInputArray->MakeIterator();
     
    155109  DelphesFormula *formula;
    156110
    157   if(fFilter) delete fFilter;
    158111  if(fItJetInputArray) delete fItJetInputArray;
    159   if(fItPartonInputArray) delete fItPartonInputArray;
    160112
    161113  for(itEfficiencyMap = fEfficiencyMap.begin(); itEfficiencyMap != fEfficiencyMap.end(); ++itEfficiencyMap)
     
    170122void BTagging::Process()
    171123{
    172   Candidate *jet, *parton;
    173   Double_t pt, eta, phi;
    174   TObjArray *partonArray;
     124  Candidate *jet;
     125  Double_t pt, eta, phi, e;
    175126  map< Int_t, DelphesFormula * >::iterator itEfficiencyMap;
    176127  DelphesFormula *formula;
    177   Int_t pdgCode, pdgCodeMax;
    178128
    179   // select quark and gluons
    180   fFilter->Reset();
    181   partonArray = fFilter->GetSubArray(fClassifier, 0);
    182  
    183   if(partonArray == 0) return;
    184 
    185   TIter itPartonArray(partonArray);
    186  
    187129  // loop over all input jets
    188130  fItJetInputArray->Reset();
     
    190132  {
    191133    const TLorentzVector &jetMomentum = jet->Momentum;
    192     pdgCodeMax = -1;
    193134    eta = jetMomentum.Eta();
    194135    phi = jetMomentum.Phi();
    195136    pt = jetMomentum.Pt();
     137    e = jetMomentum.E();
    196138
    197     // loop over all input partons
    198     itPartonArray.Reset();
    199     while((parton = static_cast<Candidate*>(itPartonArray.Next())))
    200     {
    201       pdgCode = TMath::Abs(parton->PID);
    202       if(pdgCode == 21) pdgCode = 0;
    203       if(jetMomentum.DeltaR(parton->Momentum) <= fDeltaR)
    204       {
    205         if(pdgCodeMax < pdgCode) pdgCodeMax = pdgCode;
    206       }
    207     }
    208     if(pdgCodeMax == 0) pdgCodeMax = 21;
    209     if(pdgCodeMax == -1) pdgCodeMax = 0;
    210 
    211     // find an efficency formula
    212     itEfficiencyMap = fEfficiencyMap.find(pdgCodeMax);
     139    // find an efficiency formula
     140    itEfficiencyMap = fEfficiencyMap.find(jet->Flavor);
    213141    if(itEfficiencyMap == fEfficiencyMap.end())
    214142    {
     
    217145    formula = itEfficiencyMap->second;
    218146
    219     // apply an efficency formula
    220     jet->BTag |= (gRandom->Uniform() <= formula->Eval(pt, eta)) << fBitNumber;
     147    // apply an efficiency formula
     148    jet->BTag |= (gRandom->Uniform() <= formula->Eval(pt, eta, phi, e)) << fBitNumber;
     149
     150    // find an efficiency formula for algo flavor definition
     151    itEfficiencyMap = fEfficiencyMap.find(jet->FlavorAlgo);
     152    if(itEfficiencyMap == fEfficiencyMap.end())
     153    {
     154      itEfficiencyMap = fEfficiencyMap.find(0);
     155    }
     156    formula = itEfficiencyMap->second;
     157
     158    // apply an efficiency formula
     159    jet->BTagAlgo |= (gRandom->Uniform() <= formula->Eval(pt, eta, phi, e)) << fBitNumber;
     160
     161    // find an efficiency formula for phys flavor definition
     162    itEfficiencyMap = fEfficiencyMap.find(jet->FlavorPhys);
     163    if(itEfficiencyMap == fEfficiencyMap.end())
     164    {
     165      itEfficiencyMap = fEfficiencyMap.find(0);
     166    }
     167    formula = itEfficiencyMap->second;
     168
     169    // apply an efficiency formula
     170    jet->BTagPhys |= (gRandom->Uniform() <= formula->Eval(pt, eta, phi, e)) << fBitNumber;
    221171  }
    222172}
Note: See TracChangeset for help on using the changeset viewer.