babymaker  e95a6a9342d4604277fe7cc6149b6b5b24447d89
photon_tools.cc
Go to the documentation of this file.
1 // photon_tools: Functions related to RA2/b photons
2 // Copied from RA2/b's TreeMaker
3 // https://github.com/TreeMaker/TreeMaker/blob/74848c2a9fd16acaaf8d711842c6e2dc1d5bd56b/Utils/src/PhotonIDisoProducer.cc
4 
5 // System include files
6 #include <iostream>
7 #include <string>
8 #include <cmath>
9 #include <stdlib.h>
10 
11 // FW physics include files
12 #include "RecoEgamma/EgammaTools/interface/ConversionTools.h"
13 
14 // User include files
17 
18 
19 using namespace std;
20 
21 bool photon_tools::idPhoton(const pat::Photon &photon, edm::Handle<std::vector<pat::Electron> > &electrons,
22  edm::Handle<reco::ConversionCollection> &conversions,
23  edm::Handle<reco::BeamSpot> &beamspot, double rho){
24  double eta(fabs(photon.eta()));
25  bool barrel(eta<1.4442), endcap(eta>1.566 && eta<2.5);
26 
27  // Barrel cuts
28  double hadTowOverEmCut(0.028), sigmaIetaIetaCut(0.0107);
29  double chIsoCut(2.67), nuIsoCut(7.23 + exp(0.0028*(photon.pt()+0.5408))), gamIsoCut(2.11 + 0.0014*(photon.pt()));
30  if(endcap) { // Endcap cuts
31  hadTowOverEmCut = 0.093;
32  sigmaIetaIetaCut = 0.0272;
33  chIsoCut = 1.79;
34  nuIsoCut = 8.89 + 0.01725*(photon.pt());
35  gamIsoCut = 3.09 + 0.0091*(photon.pt());
36  }
37 
39  if(!barrel && !endcap) return false;
41  if(photon.hadTowOverEm() >= hadTowOverEmCut || photon.sigmaIetaIeta() >= sigmaIetaIetaCut) return false;
42  if(electronMatch(photon.superCluster(), electrons, conversions, beamspot->position())) return false;
44  double chIso = rhoCorrectedIso(pfCh , photon.chargedHadronIso(), photon.eta(), rho);
45  double nuIso = rhoCorrectedIso(pfNu , photon.neutralHadronIso(), photon.eta(), rho);
46  double gamIso = rhoCorrectedIso(pfGam, photon.photonIso() , photon.eta(), rho);
47  if(chIso >= chIsoCut || nuIso >= nuIsoCut || gamIso >= gamIsoCut) return false;
48 
49  return true;
50 }
51 
52 // From https://github.com/RazorCMS/SUSYBSMAnalysis-RazorTuplizer/blob/6072ffb43bbeb3f6b34cf8a96426c7f104c5b902/plugins/RazorAux.cc#L127
53 //check if a given SuperCluster matches to at least one GsfElectron having zero expected inner hits
54 //and not matching any conversion in the collection passing the quality cuts
55 bool photon_tools::electronMatch(const reco::SuperClusterRef &sc, const edm::Handle<std::vector<pat::Electron> > &electrons,
56  const edm::Handle<reco::ConversionCollection> &conversions, const math::XYZPoint &beamspot,
57  double lxyMin, double probMin, unsigned int nHitsBeforeVtxMax) {
58 
59  if (sc.isNull()) return false;
60  for (std::vector<pat::Electron>::const_iterator it = electrons->begin(); it!=electrons->end(); ++it) {
61  //match electron to supercluster
62  if (it->superCluster()!=sc) continue;
63  //check expected inner hits
64 #ifdef POST_CMSSW_9_4
65  if (it->gsfTrack()->hitPattern().numberOfAllHits(reco::HitPattern::MISSING_INNER_HITS) > 0) continue;
66 #else
67  if (it->gsfTrack()->hitPattern().numberOfHits(reco::HitPattern::MISSING_INNER_HITS) > 0) continue;
68 #endif
69  //check if electron is matching to a conversion
70  if (ConversionTools::hasMatchedConversion(*it,conversions,beamspot,lxyMin,probMin,nHitsBeforeVtxMax)) continue;
71  return true;
72  }
73  return false;
74 }
75 
76 double photon_tools::rhoCorrectedIso(isoType isoType_, double isoVal, double eta, double rho){
77  int iEta = -1;
78  for(unsigned int i = 0; i < etaHigh.size(); i++)
79  if(fabs(eta) < etaHigh[i] && fabs(eta) > etaLow[i]){
80  iEta = i;
81  break;
82  }
83 
84  if(iEta < 0){
85  std::cout << "AHHHHH: couldn't match eta region... eta = " << fabs(eta) << std::endl;
86  return 99999. ;
87  } else return max(isoVal - effA[iEta][isoType_]*rho , 0.);
88 };
89 
90 void photon_tools::addEffA(double etaLow_,double etaHigh_,double effA_pfCh_,double effA_pfNu_,double effA_pfGa_){
91  etaHigh.push_back( etaHigh_ );
92  etaLow.push_back( etaLow_ );
93  vector<double> temp;
94  temp.push_back(effA_pfCh_);
95  temp.push_back(effA_pfNu_);
96  temp.push_back(effA_pfGa_);
97  effA.push_back( temp );
98 
99 };
100 
102  addEffA( 0.0, 1.0, 0.0234, 0.0053, 0.078 );
103  addEffA( 1.0, 1.479, 0.0189, 0.0130, 0.0629 );
104  addEffA( 1.479, 2.0, 0.0171, 0.0057, 0.0264 );
105  addEffA( 2.0, 2.2, 0.0129, 0.0070, 0.0462 );
106  addEffA( 2.2, 2.3, 0.0110, 0.0152, 0.0740 );
107  addEffA( 2.3, 2.4, 0.0074, 0.0232, 0.0924 );
108  addEffA( 2.4, 99., 0.0035, 0.1709, 0.1484 );
109 }
110 
112 }
113 
bool idPhoton(const pat::Photon &photon, edm::Handle< std::vector< pat::Electron > > &electrons, edm::Handle< reco::ConversionCollection > &conversions, edm::Handle< reco::BeamSpot > &beamspot, double rho)
Definition: photon_tools.cc:21
STL namespace.
double rhoCorrectedIso(isoType isoType_, double isoVal, double eta, double rho)
Definition: photon_tools.cc:76
bool electronMatch(const reco::SuperClusterRef &sc, const edm::Handle< std::vector< pat::Electron > > &electrons, const edm::Handle< reco::ConversionCollection > &conversions, const math::XYZPoint &beamspot, double lxyMin=2.0, double probMin=1e-6, unsigned int nHitsBeforeVtxMax=0)
Definition: photon_tools.cc:55
void addEffA(double etaLow_, double etaHigh_, double effA_pfCh_, double effA_pfNu_, double effA_pfGa_)
Definition: photon_tools.cc:90