1 |
dkralph |
1.2 |
//
|
2 |
|
|
// System headers
|
3 |
|
|
//
|
4 |
|
|
#include <vector> // STL vector class
|
5 |
|
|
#include <iostream> // standard I/O
|
6 |
|
|
#include <iomanip> // functions to format standard I/O
|
7 |
|
|
#include <bitset>
|
8 |
|
|
#include <map>
|
9 |
|
|
using namespace std;
|
10 |
|
|
|
11 |
|
|
//
|
12 |
|
|
// root headers
|
13 |
|
|
//
|
14 |
|
|
#include <TFile.h>
|
15 |
|
|
#include <TTree.h>
|
16 |
|
|
#include <TChain.h>
|
17 |
|
|
#include <TBranch.h>
|
18 |
|
|
#include <TClonesArray.h>
|
19 |
|
|
|
20 |
|
|
//
|
21 |
|
|
// TMVA
|
22 |
|
|
//
|
23 |
|
|
#include "TMVA/Reader.h"
|
24 |
|
|
#include "TMVA/Tools.h"
|
25 |
|
|
#include "TMVA/Config.h"
|
26 |
|
|
#include "TMVA/MethodBDT.h"
|
27 |
|
|
|
28 |
|
|
//
|
29 |
|
|
// ntuple format headers
|
30 |
|
|
//
|
31 |
|
|
#include "EventHeader.h"
|
32 |
|
|
#include "PFMet.h"
|
33 |
|
|
#include "Electron.h"
|
34 |
|
|
#include "Muon.h"
|
35 |
|
|
#include "Vertex.h"
|
36 |
|
|
#include "PFCandidate.h"
|
37 |
|
|
#include "PFCandidateCol.h"
|
38 |
|
|
#include "PileupInfoCol.h"
|
39 |
|
|
#include "PileupEnergyDensity.h"
|
40 |
|
|
#include "MCParticle.h"
|
41 |
|
|
#include "MCEventInfo.h"
|
42 |
|
|
#include "TriggerMask.h"
|
43 |
|
|
#include "TriggerTable.h"
|
44 |
|
|
#include "Names.h"
|
45 |
|
|
#include "BaseMod.h"
|
46 |
|
|
|
47 |
|
|
//
|
48 |
|
|
// our headers
|
49 |
|
|
//
|
50 |
|
|
#include "ParseArgs.h"
|
51 |
|
|
#include "MuonSelection.h"
|
52 |
|
|
#include "ElectronSelection.h"
|
53 |
|
|
#include "IsolationSelection.h"
|
54 |
dkralph |
1.3 |
#include "SelectionFuncs.h"
|
55 |
dkralph |
1.2 |
|
56 |
|
|
#include "TriggerUtils.h"
|
57 |
|
|
#include "PassHLT.h"
|
58 |
|
|
#include "RunLumiRangeMap.h"
|
59 |
dkralph |
1.3 |
#include "fake_defs.h"
|
60 |
dkralph |
1.5 |
#include "Various.h"
|
61 |
dkralph |
1.2 |
#include "CommonDefs.h"
|
62 |
|
|
|
63 |
|
|
#ifndef CMSSW_BASE
|
64 |
|
|
#define CMSSW_BASE "../"
|
65 |
|
|
#endif
|
66 |
|
|
|
67 |
|
|
using namespace mithep;
|
68 |
|
|
//
|
69 |
|
|
// globals
|
70 |
|
|
//----------------------------------------------------------------------------
|
71 |
khahn |
1.6 |
TH1D *hpu_2011, *hpu_2012;
|
72 |
dkralph |
1.2 |
mithep::RunLumiRangeMap rlrm;
|
73 |
|
|
vector<SimpleLepton> failingLeptons ; // for fake estimation
|
74 |
|
|
vector<SimpleLepton> passingLeptons; // for fake estimation
|
75 |
|
|
vector<unsigned> cutvec;
|
76 |
|
|
vector<vector<unsigned> > zcutvec;
|
77 |
|
|
vector<vector<unsigned> > zzcutvec;
|
78 |
|
|
map<unsigned,float> evtrhoMap;
|
79 |
|
|
vector<string> cutstrs;
|
80 |
|
|
bool passes_HLT_MC;
|
81 |
|
|
vector<bool> PFnoPUflag;;
|
82 |
|
|
|
83 |
|
|
//
|
84 |
|
|
// prototypes
|
85 |
|
|
//----------------------------------------------------------------------------
|
86 |
dkralph |
1.7 |
void initRunLumiRangeMap(ControlFlags &ctrl);
|
87 |
dkralph |
1.2 |
|
88 |
|
|
mithep::MuonTools::EMuonEffectiveAreaTarget eraMu;
|
89 |
|
|
mithep::ElectronTools::EElectronEffectiveAreaTarget eraEle;
|
90 |
|
|
vector<const mithep::PFCandidate*> photonsToVeto;
|
91 |
|
|
//
|
92 |
|
|
// globals
|
93 |
|
|
//----------------------------------------------------------------------------
|
94 |
|
|
|
95 |
|
|
void fill_muon_fakes(ControlFlags &ctrl,
|
96 |
|
|
mithep::Array<mithep::Muon> *muonArr,
|
97 |
dkralph |
1.4 |
mithep::Array<mithep::Electron> *electronArr,
|
98 |
dkralph |
1.2 |
mithep::Array<mithep::PFJet> *jetArr,
|
99 |
|
|
mithep::Array<mithep::PFCandidate> *pfArr,
|
100 |
dkralph |
1.7 |
mithep::Array<mithep::PileupInfo> *puArr,
|
101 |
dkralph |
1.2 |
mithep::Array<mithep::PileupEnergyDensity> *puDArr,
|
102 |
dkralph |
1.8 |
mithep::Array<mithep::Vertex> *vtxArr,
|
103 |
dkralph |
1.2 |
const mithep::Vertex *vtx,
|
104 |
|
|
foinfo &foi,
|
105 |
|
|
const mithep::Muon *zmu1,
|
106 |
|
|
const mithep::Muon *zmu2,
|
107 |
|
|
const mithep::Electron *zele1,
|
108 |
|
|
const mithep::Electron *zele2);
|
109 |
|
|
void fill_electron_fakes(ControlFlags &ctrl,
|
110 |
dkralph |
1.4 |
mithep::Array<mithep::Muon> *muonArr,
|
111 |
dkralph |
1.2 |
mithep::Array<mithep::Electron> *electronArr,
|
112 |
|
|
mithep::Array<mithep::PFJet> *jetArr,
|
113 |
|
|
mithep::Array<mithep::PFCandidate> *pfArr,
|
114 |
dkralph |
1.7 |
mithep::Array<mithep::PileupInfo> *puArr,
|
115 |
dkralph |
1.2 |
mithep::Array<mithep::PileupEnergyDensity> *puDArr,
|
116 |
dkralph |
1.8 |
mithep::Array<mithep::Vertex> *vtxArr,
|
117 |
dkralph |
1.2 |
const mithep::Vertex *vtx,
|
118 |
|
|
foinfo &foi,
|
119 |
|
|
const mithep::Muon *zmu1,
|
120 |
|
|
const mithep::Muon *zmu2,
|
121 |
|
|
const mithep::Electron *zele1,
|
122 |
|
|
const mithep::Electron *zele2);
|
123 |
dkralph |
1.1 |
|
124 |
|
|
//=== MAIN =================================================================================================
|
125 |
|
|
int main(int argc, char** argv)
|
126 |
|
|
{
|
127 |
dkralph |
1.2 |
|
128 |
|
|
string cmsswpath(CMSSW_BASE);
|
129 |
|
|
cmsswpath.append("/src");
|
130 |
|
|
std::bitset<1024> triggerBits;
|
131 |
dkralph |
1.1 |
vector<vector<string> > inputFiles;
|
132 |
|
|
inputFiles.push_back(vector<string>());
|
133 |
dkralph |
1.2 |
map<string,unsigned> entrymap; // number of unskimmed entries in each file
|
134 |
dkralph |
1.1 |
|
135 |
|
|
//
|
136 |
|
|
// args
|
137 |
|
|
//--------------------------------------------------------------------------------------------------------------
|
138 |
|
|
ControlFlags ctrl;
|
139 |
|
|
parse_args( argc, argv, ctrl );
|
140 |
|
|
ctrl.dump();
|
141 |
|
|
|
142 |
|
|
//
|
143 |
|
|
// File I/O
|
144 |
|
|
//--------------------------------------------------------------------------------------------------------------
|
145 |
|
|
TChain * chain = new TChain("Events");
|
146 |
dkralph |
1.2 |
TChain * hltchain = new TChain("HLT");
|
147 |
|
|
|
148 |
dkralph |
1.1 |
string fname;
|
149 |
dkralph |
1.2 |
unsigned total_unskimmed=0;
|
150 |
|
|
if( !ctrl.inputfiles.empty() ) {
|
151 |
|
|
ifstream f(ctrl.inputfiles.c_str());
|
152 |
|
|
while (f >> fname) {
|
153 |
|
|
if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
|
154 |
|
|
cout << "adding inputfile : " << fname.c_str() << endl;
|
155 |
|
|
entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
|
156 |
|
|
total_unskimmed += entrymap[string(fname.c_str())];
|
157 |
|
|
chain->AddFile(fname.c_str());
|
158 |
|
|
hltchain->AddFile(fname.c_str());
|
159 |
|
|
}
|
160 |
|
|
} else {
|
161 |
|
|
cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
|
162 |
|
|
unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str());
|
163 |
|
|
entrymap[string(ctrl.inputfile.c_str())] = unsk_ents;
|
164 |
|
|
total_unskimmed += unsk_ents;
|
165 |
|
|
chain->AddFile(ctrl.inputfile.c_str());
|
166 |
|
|
hltchain->AddFile(ctrl.inputfile.c_str());
|
167 |
dkralph |
1.1 |
}
|
168 |
dkralph |
1.2 |
// write the total number of unskimmed events that went into making this output file to a text file
|
169 |
|
|
writeEntries(ctrl,total_unskimmed);
|
170 |
dkralph |
1.1 |
|
171 |
dkralph |
1.2 |
foinfo foi;
|
172 |
|
|
foi.nEvents=0;
|
173 |
|
|
foi.nDenom=0;
|
174 |
|
|
foi.nNumer=0;
|
175 |
dkralph |
1.1 |
|
176 |
dkralph |
1.2 |
double metMax = 25;
|
177 |
dkralph |
1.1 |
|
178 |
|
|
//
|
179 |
|
|
// Setup
|
180 |
|
|
//--------------------------------------------------------------------------------------------------------------
|
181 |
|
|
const char * ofname;
|
182 |
|
|
if( strcmp( ctrl.outputfile.c_str(), "") ) {
|
183 |
|
|
ofname = ctrl.outputfile.c_str();
|
184 |
|
|
} else {
|
185 |
|
|
ofname = "fo.root";
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
TFile *outFile = new TFile(ofname, "RECREATE");
|
189 |
|
|
TTree *outTree = new TTree("FO","FO");
|
190 |
dkralph |
1.2 |
foi.outTree = outTree;
|
191 |
|
|
outTree->Branch("pt", &foi.fopt, "pt/F");
|
192 |
|
|
outTree->Branch("eta", &foi.foeta, "eta/F");
|
193 |
|
|
outTree->Branch("phi", &foi.fophi, "phi/F");
|
194 |
|
|
outTree->Branch("pass", &foi.fopass,"pass/F");
|
195 |
dkralph |
1.7 |
outTree->Branch("jpt", &foi.jpt, "jpt/F");
|
196 |
|
|
outTree->Branch("npu", &foi.npu, "npu/I");
|
197 |
dkralph |
1.8 |
outTree->Branch("npv", &foi.npv, "npv/I");
|
198 |
dkralph |
1.2 |
|
199 |
|
|
// initMuonIDMVA();
|
200 |
|
|
getEATargets(ctrl,eraMu,eraEle);
|
201 |
|
|
initElectronIDMVAV1();
|
202 |
|
|
initMuonIsoMVA();
|
203 |
|
|
initElectronIDMVA();
|
204 |
|
|
initElectronIsoMVA();
|
205 |
|
|
initTrigger();
|
206 |
|
|
if(!ctrl.mc)
|
207 |
dkralph |
1.7 |
initRunLumiRangeMap(ctrl);
|
208 |
dkralph |
1.1 |
|
209 |
|
|
//
|
210 |
|
|
// Access samples and fill histograms
|
211 |
|
|
TFile *inputFile=0;
|
212 |
|
|
TTree *eventTree=0;
|
213 |
dkralph |
1.2 |
string currentFile("");
|
214 |
dkralph |
1.1 |
|
215 |
dkralph |
1.2 |
mithep::EventHeader *info = new mithep::EventHeader();
|
216 |
|
|
mithep::Array<mithep::PFMet> *metArr = new mithep::Array<mithep::PFMet>();
|
217 |
|
|
mithep::Array<mithep::Electron> *electronArr = new mithep::Array<mithep::Electron>();
|
218 |
|
|
mithep::Array<mithep::Muon> *muonArr = new mithep::Array<mithep::Muon>();
|
219 |
|
|
mithep::Array<mithep::Vertex> *vtxArr = new mithep::Array<mithep::Vertex>();
|
220 |
|
|
mithep::Array<mithep::PFCandidate> *pfArr = new mithep::Array<mithep::PFCandidate>();
|
221 |
|
|
mithep::Array<mithep::PFJet> *jetArr = new mithep::Array<mithep::PFJet>();
|
222 |
|
|
mithep::Array<mithep::PileupInfo> *puArr = new mithep::Array<mithep::PileupInfo>();
|
223 |
|
|
mithep::Array<mithep::PileupEnergyDensity> *puDArr = new mithep::Array<mithep::PileupEnergyDensity>();
|
224 |
|
|
mithep::Array<mithep::Track> *trkArr = new mithep::Array<mithep::Track>();
|
225 |
|
|
mithep::Array<mithep::MCParticle> *mcArr = new mithep::Array<mithep::MCParticle>();
|
226 |
|
|
mithep::MCEventInfo *mcEvtInfo = new mithep::MCEventInfo();
|
227 |
|
|
mithep::TriggerMask *trigMask = new mithep::TriggerMask();
|
228 |
|
|
mithep::TriggerTable *hltTable = new mithep::TriggerTable();
|
229 |
|
|
vector<string> *hltTableStrings = new vector<string>();
|
230 |
|
|
|
231 |
|
|
TString fElectronName(Names::gkElectronBrn);
|
232 |
|
|
TString fMuonName(Names::gkMuonBrn);
|
233 |
|
|
TString fInfoName(Names::gkEvtHeaderBrn);
|
234 |
|
|
TString fPFMetName("PFMet");
|
235 |
|
|
TString fPrimVtxName(Names::gkPVBrn);
|
236 |
|
|
TString fPFCandidateName(Names::gkPFCandidatesBrn);
|
237 |
|
|
TString fPFJetName(Names::gkPFJetBrn);
|
238 |
|
|
TString fPileupInfoName(Names::gkPileupInfoBrn);
|
239 |
|
|
TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
|
240 |
|
|
TString fTrackName(Names::gkTrackBrn);
|
241 |
|
|
TString fMCParticleName(Names::gkMCPartBrn);
|
242 |
|
|
TString fMCEvtInfoName(Names::gkMCEvtInfoBrn);
|
243 |
|
|
TString fTriggerMaskName(Names::gkHltBitBrn);
|
244 |
|
|
TString fTriggerTableName(Names::gkHltTableBrn);
|
245 |
|
|
|
246 |
|
|
chain->SetBranchAddress(fInfoName, &info);
|
247 |
|
|
chain->SetBranchAddress(fPFMetName, &metArr);
|
248 |
|
|
chain->SetBranchAddress(fElectronName, &electronArr);
|
249 |
|
|
chain->SetBranchAddress(fMuonName, &muonArr);
|
250 |
|
|
chain->SetBranchAddress(fPrimVtxName, &vtxArr);
|
251 |
|
|
chain->SetBranchAddress(fPFCandidateName, &pfArr);
|
252 |
|
|
chain->SetBranchAddress(fPFJetName, &jetArr);
|
253 |
|
|
if( ctrl.mc ) {
|
254 |
|
|
chain->SetBranchAddress(fPileupInfoName, &puArr);
|
255 |
|
|
chain->SetBranchAddress(fMCParticleName, &mcArr);
|
256 |
|
|
chain->SetBranchAddress(fMCEvtInfoName, &mcEvtInfo);
|
257 |
|
|
}
|
258 |
|
|
chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
|
259 |
|
|
chain->SetBranchAddress(fTrackName, &trkArr);
|
260 |
|
|
chain->SetBranchAddress(fTriggerMaskName, &trigMask);
|
261 |
|
|
cout << "hlttable: " << fTriggerTableName << endl;
|
262 |
|
|
hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
|
263 |
|
|
|
264 |
|
|
const mithep::Vertex *vtx; // best primary vertex in the event
|
265 |
dkralph |
1.1 |
|
266 |
dkralph |
1.2 |
// ginfo = NULL;
|
267 |
|
|
// if( ctrl.mc ) { chain->SetBranchAddress("Gen", &ginfo);}
|
268 |
|
|
|
269 |
|
|
// only 1 HLT table / file ???
|
270 |
|
|
hltchain->GetEntry(0);
|
271 |
|
|
|
272 |
|
|
int imax = chain->GetEntries();
|
273 |
|
|
cout << "nEntries: " << imax << endl;
|
274 |
dkralph |
1.1 |
for(UInt_t ientry=0; ientry<imax; ientry++) {
|
275 |
|
|
chain->GetEntry(ientry);
|
276 |
dkralph |
1.2 |
if(!(ientry%10000)) cout << "entry: " << ientry << "\tfrac: " << setw(15) << float(ientry)/chain->GetEntries() << endl;
|
277 |
|
|
|
278 |
|
|
// pfNoPU
|
279 |
|
|
PFnoPUflag.clear();
|
280 |
|
|
int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
|
281 |
|
|
assert(pfnopu_size == pfArr->GetEntries());
|
282 |
|
|
|
283 |
dkralph |
1.7 |
if(!(ctrl.noJSON) ) {
|
284 |
|
|
RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());
|
285 |
|
|
if( !(rlrm.HasRunLumi(rl)) ) continue;
|
286 |
|
|
}
|
287 |
dkralph |
1.2 |
|
288 |
|
|
foi.nEvents++;
|
289 |
dkralph |
1.1 |
|
290 |
dkralph |
1.2 |
setPV( ctrl, vtxArr, vtx);
|
291 |
dkralph |
1.1 |
|
292 |
dkralph |
1.2 |
TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
|
293 |
|
|
if(pfmet.Pt() > metMax) continue;
|
294 |
dkralph |
1.1 |
|
295 |
dkralph |
1.2 |
// good lepton selection
|
296 |
|
|
vector<const mithep::Muon*> goodMuons;
|
297 |
|
|
vector<const mithep::Electron*> goodElectrons;
|
298 |
|
|
for(int imu=0; imu<muonArr->GetEntries(); imu++) {
|
299 |
|
|
const mithep::Muon *mu = (*muonArr)[imu];
|
300 |
|
|
SelectionStatus status = muonReferencePreSelection(ctrl,mu,vtx,pfArr);
|
301 |
|
|
if( !status.passPre() ) continue;
|
302 |
|
|
goodMuons.push_back(mu);
|
303 |
|
|
}
|
304 |
|
|
int NElectrons=0;
|
305 |
dkralph |
1.1 |
for(Int_t i=0; i<electronArr->GetEntries(); i++) {
|
306 |
dkralph |
1.2 |
const mithep::Electron *ele = (*electronArr)[i];
|
307 |
|
|
if(ele->Pt() > 5) NElectrons++;
|
308 |
|
|
SelectionStatus status = electronReferencePreSelection(ctrl,ele,vtx);
|
309 |
|
|
if( !status.passPre() ) continue;
|
310 |
dkralph |
1.4 |
bool muonMatch=false;
|
311 |
|
|
for(unsigned imu=0; imu<muonArr->GetEntries(); imu++) {
|
312 |
|
|
const mithep::Muon *mu = (*muonArr)[imu];
|
313 |
|
|
if(dr(mu,ele) < 0.05) muonMatch = true;
|
314 |
|
|
}
|
315 |
dkralph |
1.7 |
if(muonMatch) { if(ctrl.debug) cout << "matched to muon in lepton counter!" << endl; continue; }
|
316 |
dkralph |
1.2 |
//????????????????????????????????????????????????????????????????????????????????????????
|
317 |
|
|
// add in iso here?
|
318 |
|
|
//????????????????????????????????????????????????????????????????????????????????????????
|
319 |
|
|
goodElectrons.push_back(ele);
|
320 |
dkralph |
1.1 |
}
|
321 |
|
|
|
322 |
dkralph |
1.2 |
// look for z pairs
|
323 |
|
|
int NZCandidates=0;
|
324 |
|
|
const mithep::Muon *zmu1=0,*zmu2=0;
|
325 |
|
|
const mithep::Electron *zele1=0,*zele2=0;
|
326 |
|
|
for(unsigned imu=0; imu<goodMuons.size(); imu++) {
|
327 |
|
|
TLorentzVector mu1;
|
328 |
|
|
mu1.SetPtEtaPhiM(goodMuons[imu]->Pt(),goodMuons[imu]->Eta(),goodMuons[imu]->Phi(),MUON_MASS);
|
329 |
|
|
for(unsigned jmu=imu+1; jmu<goodMuons.size(); jmu++) {
|
330 |
|
|
TLorentzVector mu2;
|
331 |
|
|
mu2.SetPtEtaPhiM(goodMuons[jmu]->Pt(),goodMuons[jmu]->Eta(),goodMuons[jmu]->Phi(),MUON_MASS);
|
332 |
|
|
TLorentzVector dimu(mu1+mu2);
|
333 |
|
|
if(dimu.M() < 75 || dimu.M() > 105) continue;
|
334 |
|
|
if(goodMuons[imu]->Charge() == goodMuons[jmu]->Charge()) continue;
|
335 |
|
|
|
336 |
|
|
zmu1 = goodMuons[imu];
|
337 |
|
|
zmu2 = goodMuons[jmu];
|
338 |
|
|
NZCandidates++;
|
339 |
|
|
}
|
340 |
|
|
}
|
341 |
|
|
for(unsigned iele=0; iele<goodElectrons.size(); iele++) {
|
342 |
|
|
TLorentzVector ele1;
|
343 |
|
|
ele1.SetPtEtaPhiM(goodElectrons[iele]->Pt(),goodElectrons[iele]->Eta(),goodElectrons[iele]->Phi(),ELECTRON_MASS);
|
344 |
|
|
for(unsigned jele=iele+1; jele<goodElectrons.size(); jele++) {
|
345 |
|
|
TLorentzVector ele2;
|
346 |
|
|
ele2.SetPtEtaPhiM(goodElectrons[jele]->Pt(),goodElectrons[jele]->Eta(),goodElectrons[jele]->Phi(),ELECTRON_MASS);
|
347 |
|
|
TLorentzVector diele(ele1+ele2);
|
348 |
|
|
if(diele.M() < 75 || diele.M() > 105) continue;
|
349 |
|
|
if(goodElectrons[iele]->Charge() == goodElectrons[jele]->Charge()) continue;
|
350 |
|
|
|
351 |
|
|
zele1 = goodElectrons[iele];
|
352 |
|
|
zele2 = goodElectrons[jele];
|
353 |
|
|
NZCandidates++;
|
354 |
dkralph |
1.1 |
}
|
355 |
dkralph |
1.2 |
}
|
356 |
|
|
|
357 |
|
|
if(NZCandidates!=1) continue;
|
358 |
|
|
int ZDecayType = (zmu1 && zmu2) ? 13 : 11;
|
359 |
|
|
|
360 |
|
|
// we want only one jet...
|
361 |
|
|
if(ZDecayType==11 && NElectrons > 3) continue;
|
362 |
|
|
if(ZDecayType==13 && NElectrons > 1) continue;
|
363 |
|
|
|
364 |
|
|
// pointless...
|
365 |
|
|
if(zele1) assert(zele2 && !zmu1 && !zmu2);
|
366 |
|
|
if(zele2) assert(zele1 && !zmu1 && !zmu2);
|
367 |
|
|
if(zmu1) assert(zmu2 && !zele1 && !zele2);
|
368 |
|
|
if(zmu2) assert(zmu1 && !zele1 && !zele2);
|
369 |
|
|
|
370 |
|
|
if(ctrl.fakeScheme.Contains("mu_")) {
|
371 |
dkralph |
1.8 |
fill_muon_fakes(ctrl,muonArr,electronArr,jetArr,pfArr,puArr,puDArr,vtxArr,vtx,foi,zmu1,zmu2,zele1,zele2);
|
372 |
dkralph |
1.2 |
} else if(ctrl.fakeScheme.Contains("ele_")) {
|
373 |
dkralph |
1.8 |
fill_electron_fakes(ctrl,muonArr,electronArr,jetArr,pfArr,puArr,puDArr,vtxArr,vtx,foi,zmu1,zmu2,zele1,zele2);
|
374 |
dkralph |
1.2 |
} else assert(0);
|
375 |
dkralph |
1.1 |
|
376 |
|
|
|
377 |
dkralph |
1.2 |
}
|
378 |
|
|
|
379 |
dkralph |
1.1 |
outFile->Write();
|
380 |
|
|
outFile->Close();
|
381 |
dkralph |
1.2 |
|
382 |
dkralph |
1.1 |
//--------------------------------------------------------------------------------------------------------------
|
383 |
|
|
// Summary print out
|
384 |
|
|
//==============================================================================================================
|
385 |
|
|
cout << endl;
|
386 |
|
|
cout << "*" << endl;
|
387 |
|
|
cout << "* SUMMARY" << endl;
|
388 |
|
|
cout << "*--------------------------------------------------" << endl;
|
389 |
|
|
cout << endl;
|
390 |
|
|
|
391 |
dkralph |
1.2 |
cout << " >>> No. of events processed: " << foi.nEvents << endl;
|
392 |
|
|
cout << " >>> No. of denominator objects: " << foi.nDenom << endl;
|
393 |
|
|
cout << " >>> No. of numerator objects: " << foi.nNumer << endl;
|
394 |
|
|
cout << " >>> ratio: " << float(foi.nNumer)/foi.nDenom << endl;
|
395 |
dkralph |
1.1 |
cout << endl;
|
396 |
|
|
|
397 |
dkralph |
1.2 |
TString outputDir(ofname);
|
398 |
|
|
outputDir = outputDir(0,outputDir.Last('/'));
|
399 |
dkralph |
1.1 |
ofstream txtfile;
|
400 |
|
|
char txtfname[100];
|
401 |
dkralph |
1.2 |
TString txtname(ctrl.outputfile);
|
402 |
|
|
txtname.ReplaceAll(".root",".txt");
|
403 |
|
|
cout << "writing text to: " << txtname << endl;
|
404 |
|
|
txtfile.open(txtname);
|
405 |
dkralph |
1.1 |
txtfile << "*" << endl;
|
406 |
|
|
txtfile << "* SUMMARY" << endl;
|
407 |
|
|
txtfile << "*--------------------------------------------------" << endl;
|
408 |
|
|
txtfile << endl;
|
409 |
|
|
|
410 |
dkralph |
1.2 |
txtfile << " >>> No. of events processed: " << foi.nEvents << endl;
|
411 |
|
|
txtfile << " >>> No. of denominator objects: " << foi.nDenom << endl;
|
412 |
|
|
txtfile << " >>> No. of numerator objects: " << foi.nNumer << endl;
|
413 |
|
|
txtfile << " >>> ratio: " << float(foi.nNumer)/foi.nDenom << endl;
|
414 |
dkralph |
1.1 |
txtfile << endl;
|
415 |
|
|
txtfile.close();
|
416 |
|
|
|
417 |
|
|
cout << " <> Output saved in " << outputDir << "/" << endl;
|
418 |
|
|
cout << endl;
|
419 |
|
|
|
420 |
|
|
cout << "done!" << endl;
|
421 |
dkralph |
1.2 |
}
|
422 |
|
|
//----------------------------------------------------------------------------------------
|
423 |
|
|
void fill_muon_fakes(ControlFlags &ctrl,
|
424 |
|
|
mithep::Array<mithep::Muon> *muonArr,
|
425 |
dkralph |
1.4 |
mithep::Array<mithep::Electron> *electronArr,
|
426 |
dkralph |
1.2 |
mithep::Array<mithep::PFJet> *jetArr,
|
427 |
|
|
mithep::Array<mithep::PFCandidate> *pfArr,
|
428 |
dkralph |
1.7 |
mithep::Array<mithep::PileupInfo> *puArr,
|
429 |
dkralph |
1.2 |
mithep::Array<mithep::PileupEnergyDensity> *puDArr,
|
430 |
dkralph |
1.8 |
mithep::Array<mithep::Vertex> *vtxArr,
|
431 |
dkralph |
1.2 |
const mithep::Vertex *vtx,
|
432 |
|
|
foinfo &foi,
|
433 |
|
|
const mithep::Muon *zmu1,
|
434 |
|
|
const mithep::Muon *zmu2,
|
435 |
|
|
const mithep::Electron *zele1,
|
436 |
|
|
const mithep::Electron *zele2)
|
437 |
|
|
{
|
438 |
|
|
|
439 |
|
|
// count denominator and numerator objects
|
440 |
|
|
for(Int_t imu=0; imu<muonArr->GetEntries(); imu++) {
|
441 |
|
|
const mithep::Muon* mu = (*muonArr)[imu];
|
442 |
|
|
if(ctrl.debug) cout << "\t\timu: " << imu << endl;
|
443 |
|
|
|
444 |
|
|
if(mu==zmu1 || mu==zmu2) { if(ctrl.debug) cout << "\t\tdecayed from the z..." << endl; continue; }
|
445 |
|
|
if(zele1 && dr(mu,zele1) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zele1" << endl; continue; }
|
446 |
|
|
if(zele2 && dr(mu,zele2) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zele2" << endl; continue; }
|
447 |
|
|
if(zmu1 && dr(mu,zmu1) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zmu1" << endl; continue; }
|
448 |
|
|
if(zmu2 && dr(mu,zmu2) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zmu2" << endl; continue; }
|
449 |
|
|
|
450 |
|
|
//find leading jet in the event
|
451 |
|
|
Double_t leadingJetPt = -1;
|
452 |
|
|
for(Int_t j=0; j<jetArr->GetEntries(); j++) {
|
453 |
|
|
const mithep::PFJet *jet = (*jetArr)[j];
|
454 |
|
|
if (jet->Pt() > leadingJetPt && dr(jet,mu) > 1) {
|
455 |
|
|
leadingJetPt = jet->Pt();
|
456 |
|
|
}
|
457 |
|
|
}
|
458 |
dkralph |
1.1 |
|
459 |
dkralph |
1.2 |
// denominator definition
|
460 |
dkralph |
1.7 |
SelectionStatus denomsel;
|
461 |
dkralph |
1.8 |
denomsel |= muonPreSelectionNoD0DzIP(ctrl,mu,vtx,pfArr);;
|
462 |
|
|
if( !denomsel.passPre() ) continue;
|
463 |
dkralph |
1.2 |
|
464 |
|
|
foi.nDenom++;
|
465 |
|
|
|
466 |
|
|
// numerator definition
|
467 |
dkralph |
1.7 |
SelectionStatus musel;
|
468 |
|
|
musel |= muonReferencePreSelection(ctrl,mu,vtx,pfArr);;
|
469 |
dkralph |
1.2 |
musel |= muonIDPFSelection(ctrl,mu,vtx,pfArr);
|
470 |
|
|
musel |= muonReferenceIsoSelection(ctrl,mu,vtx,pfArr,puDArr,eraMu,photonsToVeto);
|
471 |
|
|
|
472 |
|
|
bool pass = musel.loose();
|
473 |
|
|
|
474 |
dkralph |
1.8 |
if(pass)
|
475 |
dkralph |
1.2 |
foi.nNumer++;
|
476 |
dkralph |
1.8 |
|
477 |
dkralph |
1.2 |
// fill output TTree
|
478 |
|
|
foi.fopt = mu->Pt();
|
479 |
|
|
foi.foeta = mu->Eta();
|
480 |
|
|
foi.fophi = mu->Phi();
|
481 |
|
|
foi.fopass = pass ? 1 : 0;
|
482 |
|
|
foi.jpt = leadingJetPt;
|
483 |
dkralph |
1.8 |
foi.npv = vtxArr->GetEntries(); // note: should maybe apply some selection here
|
484 |
dkralph |
1.7 |
foi.npu = ctrl.mc ? getNPU(puArr) : 0;
|
485 |
dkralph |
1.2 |
foi.outTree->Fill();
|
486 |
|
|
}
|
487 |
|
|
}
|
488 |
|
|
//----------------------------------------------------------------------------------------
|
489 |
|
|
void fill_electron_fakes(ControlFlags &ctrl,
|
490 |
dkralph |
1.4 |
mithep::Array<mithep::Muon> *muonArr,
|
491 |
dkralph |
1.2 |
mithep::Array<mithep::Electron> *electronArr,
|
492 |
|
|
mithep::Array<mithep::PFJet> *jetArr,
|
493 |
|
|
mithep::Array<mithep::PFCandidate> *pfArr,
|
494 |
dkralph |
1.7 |
mithep::Array<mithep::PileupInfo> *puArr,
|
495 |
dkralph |
1.2 |
mithep::Array<mithep::PileupEnergyDensity> *puDArr,
|
496 |
dkralph |
1.8 |
mithep::Array<mithep::Vertex> *vtxArr,
|
497 |
dkralph |
1.2 |
const mithep::Vertex *vtx,
|
498 |
|
|
foinfo &foi,
|
499 |
|
|
const mithep::Muon *zmu1,
|
500 |
|
|
const mithep::Muon *zmu2,
|
501 |
|
|
const mithep::Electron *zele1,
|
502 |
|
|
const mithep::Electron *zele2)
|
503 |
|
|
{
|
504 |
|
|
|
505 |
|
|
// count denominator and numerator objects
|
506 |
|
|
for(Int_t iele=0; iele<electronArr->GetEntries(); iele++) {
|
507 |
|
|
const mithep::Electron* ele = (*electronArr)[iele];
|
508 |
|
|
|
509 |
dkralph |
1.4 |
bool muonMatch=false;
|
510 |
|
|
for(unsigned imu=0; imu<muonArr->GetEntries(); imu++) {
|
511 |
|
|
const mithep::Muon *mu = (*muonArr)[imu];
|
512 |
|
|
if(dr(mu,ele) < 0.05) muonMatch = true;
|
513 |
|
|
}
|
514 |
|
|
if(muonMatch) { cout << "matched to muon in filler!" << endl; continue; }
|
515 |
|
|
|
516 |
dkralph |
1.2 |
if(ele==zele1 || ele==zele2) { if(ctrl.debug) cout << "\t\tdecayed from the z..." << endl; continue; }
|
517 |
|
|
if(zele1 && dr(ele,zele1) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zele1" << endl; continue; }
|
518 |
|
|
if(zele2 && dr(ele,zele2) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zele2" << endl; continue; }
|
519 |
|
|
if(zmu1 && dr(zmu1,ele) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zmu1" << endl; continue; }
|
520 |
|
|
if(zmu2 && dr(zmu2,ele) < 0.3) { if(ctrl.debug) cout << "\t\tdr-matched to zmu2" << endl; continue; }
|
521 |
|
|
|
522 |
|
|
//find leading jet in the event
|
523 |
|
|
Double_t leadingJetPt = -1;
|
524 |
|
|
for(Int_t j=0; j<jetArr->GetEntries(); j++) {
|
525 |
|
|
const mithep::PFJet *jet = (*jetArr)[j];
|
526 |
|
|
if (jet->Pt() > leadingJetPt && dr(jet,ele) > 1) {
|
527 |
|
|
leadingJetPt = jet->Pt();
|
528 |
|
|
}
|
529 |
|
|
}
|
530 |
|
|
|
531 |
|
|
// denominator definition
|
532 |
dkralph |
1.7 |
SelectionStatus denomsel;
|
533 |
dkralph |
1.8 |
denomsel |= electronPreSelectionNoD0DzIP(ctrl,ele,vtx);
|
534 |
|
|
if( !denomsel.passPre() ) continue;
|
535 |
dkralph |
1.2 |
|
536 |
|
|
foi.nDenom++;
|
537 |
dkralph |
1.8 |
|
538 |
dkralph |
1.2 |
// numerator definition
|
539 |
dkralph |
1.7 |
SelectionStatus elsel;
|
540 |
|
|
elsel |= electronReferencePreSelection(ctrl,ele,vtx);
|
541 |
dkralph |
1.2 |
elsel |= electronReferenceIDMVASelectionV1(ctrl,ele,vtx);
|
542 |
|
|
elsel |= electronReferenceIsoSelection(ctrl,ele,vtx,pfArr,puDArr,eraEle,photonsToVeto);
|
543 |
|
|
|
544 |
|
|
bool pass = elsel.loose();
|
545 |
dkralph |
1.8 |
|
546 |
|
|
if(pass)
|
547 |
|
|
foi.nNumer++;
|
548 |
dkralph |
1.2 |
|
549 |
|
|
// fill output TTree
|
550 |
|
|
foi.fopt = ele->Pt();
|
551 |
|
|
foi.foeta = ele->Eta();
|
552 |
|
|
foi.fophi = ele->Phi();
|
553 |
|
|
foi.fopass = pass ? 1 : 0;
|
554 |
|
|
foi.jpt = leadingJetPt;
|
555 |
dkralph |
1.7 |
foi.npu = ctrl.mc ? getNPU(puArr) : 0;
|
556 |
dkralph |
1.8 |
foi.npv = vtxArr->GetEntries(); // note: should maybe apply some selection here
|
557 |
dkralph |
1.2 |
foi.outTree->Fill();
|
558 |
|
|
}
|
559 |
dkralph |
1.1 |
}
|
560 |
dkralph |
1.2 |
//----------------------------------------------------------------------------
|
561 |
dkralph |
1.7 |
void initRunLumiRangeMap(ControlFlags &ctrl)
|
562 |
dkralph |
1.2 |
//----------------------------------------------------------------------------
|
563 |
|
|
{
|
564 |
|
|
/*
|
565 |
|
|
rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
|
566 |
|
|
// rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
|
567 |
|
|
rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
|
568 |
|
|
rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));
|
569 |
|
|
rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));
|
570 |
|
|
// r11b
|
571 |
|
|
rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));
|
572 |
|
|
*/
|
573 |
|
|
|
574 |
|
|
// 2012 only for now ...
|
575 |
dkralph |
1.7 |
rlrm.AddJSONFile(string(ctrl.jsonFile));
|
576 |
dkralph |
1.2 |
|
577 |
|
|
};
|