1 |
#include <iostream>
|
2 |
#include <fstream>
|
3 |
|
4 |
#include "UserCode/HbbAnalysis/interface/HistosElecs.hh"
|
5 |
|
6 |
namespace HbbAnalysis {//namespace
|
7 |
|
8 |
void HistosElecs::FillEventHistograms(const edm::Handle<std::vector<pat::Electron> > & aCol){
|
9 |
|
10 |
if (doGenMatched_) {
|
11 |
unsigned int nMatched = 0;
|
12 |
for (std::vector<pat::Electron>::const_iterator iElec = aCol->begin();
|
13 |
iElec != aCol->end();
|
14 |
iElec++)
|
15 |
{
|
16 |
if (MatchesGenElectron(*iElec)) nMatched++;
|
17 |
}
|
18 |
p_nElectrons->Fill(nMatched);
|
19 |
}
|
20 |
else p_nElectrons->Fill(aCol->size());
|
21 |
|
22 |
}
|
23 |
|
24 |
void HistosElecs::FillHistograms(const pat::Electron & aElec, const edm::Handle<std::vector<reco::Vertex> >& aRecoVertices, bool isLead){//FillHistograms
|
25 |
|
26 |
bool lIsGenMatched = !doGenMatched_ || (doGenMatched_ && MatchesGenElectron(aElec));
|
27 |
if (lIsGenMatched) {//genMatched
|
28 |
if (isLead) {//isLead
|
29 |
FillBaseHistograms(aElec.pt(),aElec.eta(),aElec.phi(),aElec.charge());
|
30 |
|
31 |
if ( aElec.gsfTrack().isAvailable() && !aElec.gsfTrack().isNull() ) {
|
32 |
p_gsfTrk_pT->Fill(aElec.gsfTrack()->pt());
|
33 |
if ( aRecoVertices->size() >= 1 ) {
|
34 |
const reco::Vertex & thePrimaryEventVertex = (*aRecoVertices->begin());
|
35 |
p_gsfTrk_IPxy->Fill(aElec.gsfTrack()->dxy(thePrimaryEventVertex.position()));
|
36 |
p_gsfTrk_IPz->Fill(aElec.gsfTrack()->dz(thePrimaryEventVertex.position()));
|
37 |
}
|
38 |
}
|
39 |
|
40 |
std::vector<std::pair<std::string,float> > lIds = aElec.electronIDs();
|
41 |
if (lIds.size() > 5) std::cout << "--- WARNING: histo will be out-of-range, number of electron IDs = " << lIds.size() << std::endl;
|
42 |
for (unsigned int iId(0); iId<lIds.size(); iId++){
|
43 |
const std::string & lName = lIds.at(iId).first;
|
44 |
//std::cout << "--- ElectronID : Bin " << iId << ", id name = " << lName << std::endl;
|
45 |
if (aElec.isElectronIDAvailable(lName)){
|
46 |
p_electronID->Fill(2*iId+aElec.electronID(lName));
|
47 |
assert (aElec.electronID(lName) == lIds.at(iId).second);
|
48 |
}
|
49 |
}
|
50 |
|
51 |
p_scSigmaEtaEta->Fill(aElec.scSigmaEtaEta());
|
52 |
p_scSigmaIEtaIEta->Fill(aElec.scSigmaIEtaIEta());
|
53 |
p_scE1x5->Fill(aElec.scE1x5());
|
54 |
p_scE2x5Max->Fill(aElec.scE2x5Max());
|
55 |
p_scE5x5->Fill(aElec.scE5x5());
|
56 |
|
57 |
p_eSuperClusterOverP->Fill(aElec.eSuperClusterOverP());
|
58 |
|
59 |
p_HoverE->Fill(aElec.hadronicOverEm());
|
60 |
p_deltaPhiIn->Fill(aElec.deltaPhiSuperClusterTrackAtVtx());
|
61 |
p_deltaEtaIn->Fill(aElec.deltaEtaSuperClusterTrackAtVtx());
|
62 |
|
63 |
if (aElec.scE5x5() > 0) {
|
64 |
p_scE1x5OverscE5x5->Fill(aElec.scE1x5()/aElec.scE5x5());
|
65 |
p_scE2x5MaxOverscE5x5->Fill(aElec.scE2x5Max()/aElec.scE5x5());
|
66 |
}
|
67 |
|
68 |
p_caloIso->Fill(aElec.caloIso());
|
69 |
p_hcalIso->Fill(aElec.hcalIso());
|
70 |
|
71 |
double lIsoVar[6] = {
|
72 |
aElec.trackIso(),
|
73 |
aElec.trackIso()/aElec.et(),
|
74 |
aElec.ecalIso(),
|
75 |
aElec.ecalIso()/aElec.et(),
|
76 |
aElec.trackIso()+aElec.ecalIso()+aElec.hcalIso(),
|
77 |
(aElec.trackIso()+aElec.ecalIso()+aElec.hcalIso())/aElec.et()
|
78 |
};
|
79 |
|
80 |
p_trackIso->Fill(lIsoVar[0]);
|
81 |
p_trackIsoOverEt->Fill(lIsoVar[1]);
|
82 |
p_ecalIso->Fill(lIsoVar[2]);
|
83 |
p_ecalIsoOverEt->Fill(lIsoVar[3]);
|
84 |
p_combIso->Fill(lIsoVar[4]);
|
85 |
p_combIsoOverEt->Fill(lIsoVar[5]);
|
86 |
|
87 |
double lIsoCut[6] = {1.,0.1,4.,0.1,5.,0.2};
|
88 |
|
89 |
for (unsigned int i(0); i<6; i++){//loop on iso variables
|
90 |
|
91 |
for (unsigned int lBin(0); lBin<isoEff_[i].numberOfBins(); lBin++){
|
92 |
double lCut = isoEff_[i].xMin()+isoEff_[i].stepSize()*lBin;
|
93 |
|
94 |
isoEff_[i].incrementTotal(lBin);
|
95 |
if (lIsoVar[i] <= lCut){
|
96 |
isoEff_[i].incrementPass(lBin);
|
97 |
}
|
98 |
}
|
99 |
|
100 |
//eff vs pT
|
101 |
for (unsigned int lBin(0); lBin<isoEffEt_[i].numberOfBins(); lBin++){
|
102 |
double lCutMin = isoEffEt_[i].xMin()+isoEffEt_[i].stepSize()*lBin;
|
103 |
double lCutMax = isoEffEt_[i].xMin()+isoEffEt_[i].stepSize()*(lBin+1);
|
104 |
|
105 |
if (aElec.et() >= lCutMin && aElec.et() < lCutMax){
|
106 |
isoEffEt_[i].incrementTotal(lBin);
|
107 |
|
108 |
if (lIsoVar[i] <= lIsoCut[i]){
|
109 |
isoEffEt_[i].incrementPass(lBin);
|
110 |
}
|
111 |
}
|
112 |
}
|
113 |
|
114 |
//eff vs eta
|
115 |
for (unsigned int lBin(0); lBin<isoEffEta_[i].numberOfBins(); lBin++){
|
116 |
double lCutMin = isoEffEta_[i].xMin()+isoEffEta_[i].stepSize()*lBin;
|
117 |
double lCutMax = isoEffEta_[i].xMin()+isoEffEta_[i].stepSize()*(lBin+1);
|
118 |
|
119 |
if (aElec.eta() >= lCutMin && aElec.eta() < lCutMax){
|
120 |
isoEffEta_[i].incrementTotal(lBin);
|
121 |
|
122 |
if (lIsoVar[i] <= lIsoCut[i]){
|
123 |
isoEffEta_[i].incrementPass(lBin);
|
124 |
}
|
125 |
}
|
126 |
}
|
127 |
|
128 |
|
129 |
}//loop on iso variables
|
130 |
|
131 |
|
132 |
|
133 |
}//isLead
|
134 |
}//genMatched
|
135 |
|
136 |
}//FillHistograms
|
137 |
|
138 |
bool HistosElecs::MatchesGenElectron(const pat::Electron& aPatElec)
|
139 |
{
|
140 |
|
141 |
bool isGenMatched = false;
|
142 |
|
143 |
const std::vector<reco::GenParticleRef> & lVec = aPatElec.genParticleRefs();
|
144 |
for ( std::vector<reco::GenParticleRef>::const_iterator it = lVec.begin();
|
145 |
it != lVec.end(); ++it ) {
|
146 |
if ( it->ref().isNonnull() && it->ref().isValid() ) {
|
147 |
const reco::GenParticleRef & genParticle = (*it);
|
148 |
if ( genParticle->pdgId() == -11 || genParticle->pdgId() == +11 ) isGenMatched = true;
|
149 |
} else {
|
150 |
edm::LogWarning("MatchesGenElectron") << " edm::Ref of genParticle associated to pat::Electron is invalid !!";
|
151 |
}
|
152 |
}
|
153 |
return isGenMatched;
|
154 |
}
|
155 |
|
156 |
}//namespace
|
157 |
|
158 |
|