ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
Revision: 1.62
Committed: Mon Dec 17 17:12:21 2012 UTC (12 years, 5 months ago) by dkralph
Content type: text/plain
Branch: MAIN
CVS Tags: compiled
Changes since 1.61: +180 -128 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 khahn 1.1 //
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 khahn 1.13 #include <bitset>
8 khahn 1.19 #include <map>
9 khahn 1.1 using namespace std;
10    
11     //
12 khahn 1.13 // root headers
13 khahn 1.1 //
14 dkralph 1.60 #include <TFile.h>
15     #include <TRegexp.h>
16 khahn 1.13 #include <TTree.h>
17     #include <TChain.h>
18     #include <TBranch.h>
19     #include <TClonesArray.h>
20 khahn 1.1
21 khahn 1.11
22 khahn 1.1 //
23 khahn 1.13 // TMVA
24     //
25     #include "TMVA/Reader.h"
26     #include "TMVA/Tools.h"
27     #include "TMVA/Config.h"
28     #include "TMVA/MethodBDT.h"
29    
30 dkralph 1.60 #include "FactorizedJetCorrector.h"
31     #include "JetCorrectorParameters.h"
32    
33 khahn 1.13 //
34 khahn 1.1 // ntuple format headers
35     //
36 khahn 1.13 #include "EventHeader.h"
37     #include "Electron.h"
38     #include "Muon.h"
39     #include "Vertex.h"
40 dkralph 1.48 #include "PFMet.h"
41 dkralph 1.60 #include "PFJetCol.h"
42 khahn 1.13 #include "PFCandidate.h"
43     #include "PFCandidateCol.h"
44 khahn 1.16 #include "PileupInfoCol.h"
45     #include "PileupEnergyDensity.h"
46 khahn 1.23 #include "MCParticle.h"
47 khahn 1.13 #include "TriggerMask.h"
48     #include "TriggerTable.h"
49 khahn 1.41 #include "TriggerObject.h"
50     #include "TriggerObjectRel.h"
51 khahn 1.13 #include "Names.h"
52     #include "BaseMod.h"
53 dkralph 1.44 #include "TriggerObjectsTable.h"
54 dkralph 1.60 #include "JetIDMVA.h"
55 khahn 1.43
56 khahn 1.1 //
57 khahn 1.13 // our headers
58 khahn 1.1 //
59     #include "ParseArgs.h"
60 khahn 1.13 #include "MuonSelection.h"
61     #include "ElectronSelection.h"
62 anlevin 1.56 #include "ElectronMomentumCorrection.h"
63 dkralph 1.60 #include "JetSelection.h"
64 khahn 1.13 #include "IsolationSelection.h"
65 khahn 1.29 #include "ReferenceSelection.h"
66 dkralph 1.60 #include "MuonMomentumCorrection.h"
67 khahn 1.14
68 khahn 1.13 #include "TriggerUtils.h"
69     #include "PassHLT.h"
70     #include "Angles.h"
71     #include "KinematicsStruct.h"
72     #include "InfoStruct.h"
73 khahn 1.28 #include "GenInfoStruct.h"
74 khahn 1.13 #include "WeightStruct.h"
75     #include "AngleTuple.h"
76 dkralph 1.62 #include "JetInfoStruct.h"
77 khahn 1.15 #include "FOTuple.h"
78 khahn 1.13
79 khahn 1.33 #include "RunLumiRangeMap.h"
80 dkralph 1.2 #include "SampleWeight.h"
81 khahn 1.13 #include "EfficiencyWeightsInterface.h"
82 dkralph 1.38 #include "SelectionFuncs.h"
83 khahn 1.1
84 khahn 1.16 #include "SimpleLepton.h"
85    
86 khahn 1.13 #ifndef CMSSW_BASE
87     #define CMSSW_BASE "../"
88     #endif
89 khahn 1.1
90 khahn 1.13 using namespace mithep;
91 khahn 1.11
92 khahn 1.16 //
93     // globals
94     //----------------------------------------------------------------------------
95 khahn 1.47 TH1D *hpu_2011, *hpu_2012;
96 khahn 1.16 RunLumiRangeMap rlrm;
97     vector<SimpleLepton> failingLeptons ; // for fake estimation
98     vector<SimpleLepton> passingLeptons; // for fake estimation
99 khahn 1.19 vector<unsigned> cutvec;
100     vector<vector<unsigned> > zcutvec;
101     vector<vector<unsigned> > zzcutvec;
102     map<unsigned,float> evtrhoMap;
103 dkralph 1.62 TrigInfo ti;
104 khahn 1.19 vector<string> cutstrs;
105 dkralph 1.60 bool passes_HLT;
106 khahn 1.22 vector<bool> PFnoPUflag;;
107 anlevin 1.57 map<TString, map<TString,int>* > counts;
108 dkralph 1.60 ElectronMomentumCorrection electron_momentum_correction;
109     MuCorr *muCorr;
110 dkralph 1.62 void addDummyZ2Lepotons(EventData &ret4l);
111     void setNtupleVals(ControlFlags &ctrl, EventData &ret4l, InfoStruct &evtinfo, Angles &angles, KinematicsStruct &kine,
112     JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<PFJet> *jetArr, Array<PFMet> *metArr,
113     vector<SimpleLepton> &simpleLeptonJets, FactorizedJetCorrector *fJetCorrector, Array<PileupInfo> *puArr,
114     Array<PileupEnergyDensity> *puDArr, JetIDMVA *fJetIDMVA, Array<Vertex> *vtxArr, bitset<1024> &triggerBits,
115     TriggerTable *hltTable, Array<TriggerObject> *hltObjArr, TriggerObjectsTable *fTrigObjs, AngleTuple *nt);
116 dkralph 1.60 //----------------------------------------------------------------------------
117     void initRunLumiRangeMap(ControlFlags &ctrl)
118     //----------------------------------------------------------------------------
119     {
120     if(ctrl.jsonFile==""){
121     cout << "WARNING: running with empty jsonFile, so setting noJSON to true" << endl;
122     ctrl.noJSON = true;
123     }
124     rlrm.AddJSONFile(string(ctrl.jsonFile));
125     }
126 khahn 1.11
127 khahn 1.16 //
128     // prototypes
129 khahn 1.13 //----------------------------------------------------------------------------
130 khahn 1.11
131 khahn 1.16 //
132     // MAIN
133     //----------------------------------------------------------------------------
134 khahn 1.1 int main(int argc, char** argv)
135 khahn 1.16 //----------------------------------------------------------------------------
136 khahn 1.1 {
137 anlevin 1.57 vector<TString> cuts;
138 dkralph 1.60 cuts.push_back("start"); // NOTE: is incremented in ReferenceSelection, so if you turn on JSONS be careful
139 anlevin 1.57 cuts.push_back("trigger");
140     cuts.push_back("sfOsHiPt");
141     cuts.push_back("4<mZ2<120");
142     cuts.push_back("pt>20,10");
143     cuts.push_back("mll>4");
144     cuts.push_back("m4l>70");
145 dkralph 1.60 cuts.push_back("mZ2>12");
146     cuts.push_back("m4l>100");
147 anlevin 1.57
148     for(unsigned icut=0; icut<cuts.size(); icut++)
149     counts[cuts[icut]] = new map<TString,int>;
150    
151     map<TString,map<TString,int>* >::iterator cit;
152     for(cit=counts.begin(); cit!=counts.end(); cit++) {
153     map<TString,int> *cts = (*cit).second;
154     (*cts)["all"] = int(0);
155     (*cts)["4e"] = int(0);
156     (*cts)["4m"] = int(0);
157     (*cts)["2e2m"] = int(0);
158     }
159 dkralph 1.60
160 khahn 1.13 string cmsswpath(CMSSW_BASE);
161     cmsswpath.append("/src");
162 dkralph 1.60 bitset<1024> triggerBits;
163 khahn 1.1 vector<vector<string> > inputFiles;
164     inputFiles.push_back(vector<string>());
165 khahn 1.16 map<string,unsigned> entrymap; // number of unskimmed entries in each file
166 khahn 1.1
167     //
168     // args
169     //--------------------------------------------------------------------------------------------------------------
170     ControlFlags ctrl;
171     parse_args( argc, argv, ctrl );
172     ctrl.dump();
173 dkralph 1.60 cout << "\n\nNOTE: now setting era with arguments... double check this doesnt mess something else up\n\n" << endl;
174     assert(ctrl.doFSR);
175 dkralph 1.4
176 khahn 1.1 //
177     // File I/O
178     //--------------------------------------------------------------------------------------------------------------
179     TChain * chain = new TChain("Events");
180 khahn 1.13 TChain * hltchain = new TChain("HLT");
181 dkralph 1.53 TChain * runchain = new TChain(Names::gkRunTreeName);
182 khahn 1.13
183 khahn 1.1 string fname;
184 dkralph 1.44 unsigned total_unskimmed=0;
185 khahn 1.13 if( !ctrl.inputfiles.empty() ) {
186     ifstream f(ctrl.inputfiles.c_str());
187 dkralph 1.60 while (f >> fname) {
188 khahn 1.13 if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
189 dkralph 1.60 if(fname.find("/store/") != string::npos) fname = "root://eoscms//"+fname;
190 khahn 1.13 cout << "adding inputfile : " << fname.c_str() << endl;
191     entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
192 dkralph 1.62 cerr << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl;
193 dkralph 1.44 total_unskimmed += entrymap[string(fname.c_str())];
194 khahn 1.13 chain->AddFile(fname.c_str());
195     hltchain->AddFile(fname.c_str());
196 dkralph 1.53 runchain->AddFile(fname.c_str());
197 khahn 1.13 }
198     } else {
199 dkralph 1.60 if(ctrl.inputfile.find("/store/") != string::npos) ctrl.inputfile = "root://eoscms//"+ctrl.inputfile;
200 khahn 1.13 cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
201 dkralph 1.44 unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str());
202     entrymap[string(ctrl.inputfile.c_str())] = unsk_ents;
203 dkralph 1.62 cerr << "unskimmed entries: " << unsk_ents << endl;
204 dkralph 1.44 total_unskimmed += unsk_ents;
205 khahn 1.13 chain->AddFile(ctrl.inputfile.c_str());
206     hltchain->AddFile(ctrl.inputfile.c_str());
207 dkralph 1.53 runchain->AddFile(ctrl.inputfile.c_str());
208 khahn 1.1 }
209 dkralph 1.60 // write the total number of unskimmed events that went into making this output file to a text file
210 dkralph 1.53 writeEntries(ctrl,total_unskimmed);
211 dkralph 1.60 ctrl.totalMC = total_unskimmed;
212 khahn 1.1
213 dkralph 1.10 const char * ofname;
214     if( strcmp( ctrl.outputfile.c_str(), "") ) {
215     ofname = ctrl.outputfile.c_str();
216     } else {
217     ofname = "tmp.root";
218     }
219 khahn 1.13 // table of cross section values
220     string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat"));
221     cout << "xspath: " << xspath.c_str() << endl;
222     SimpleTable xstab(xspath.c_str());
223 dkralph 1.62 if(ctrl.mc) {
224     getWeight(xstab,entrymap,chain); // test *now* whether we've got the xs in here, so it fails before it creates the output
225     }
226 khahn 1.11
227 khahn 1.1 //
228 khahn 1.13 // Setup
229 khahn 1.1 //--------------------------------------------------------------------------------------------------------------
230 khahn 1.13 Angles angles;
231 anlevin 1.57 KinematicsStruct kine;
232 khahn 1.13 InfoStruct evtinfo;
233     WeightStruct weights;
234 khahn 1.28 GenInfoStruct geninfo;
235 dkralph 1.60 JetInfoStruct ji;
236     vector<SimpleLepton> simpleLeptonJets;
237 khahn 1.13
238     AngleTuple nt( (const char*)ofname, (const char*)"zznt");
239     nt.makeAngleBranch(angles);
240 anlevin 1.57 nt.makeKinematicsBranch(kine);
241 khahn 1.13 nt.makeInfoBranch(evtinfo);
242 dkralph 1.62 nt.makeJetInfoBranch(ji);
243     nt.makeJetAngleBranches("DataStruct/data/jetAngleVars.txt");
244    
245     FOTuple *foTree=0;
246     if(ctrl.fakeScheme != "none") {
247     foTree = new FOTuple( nt.getFile(), (const char*)"FOtree");
248     foTree->makeInfoBranch(evtinfo);
249     foTree->makeFailedLeptonBranch(failingLeptons);
250     foTree->makePassedLeptonBranch(passingLeptons);
251     }
252 khahn 1.17
253 dkralph 1.60 int genSampleType(0);
254 khahn 1.13 if(ctrl.mc) {
255     nt.makeWeightBranch(weights);
256 dkralph 1.60 if(ctrl.fillGen) {
257     genSampleType = getGenSampleType(ofname);
258     if(genSampleType == -1) {
259     cout << "\ngenSampleType returned as -1, setting fillGen to false" << endl;
260     ctrl.fillGen = false;
261     } else
262     nt.makeGenInfoBranch(geninfo);
263 khahn 1.13 }
264 dkralph 1.60 initEfficiencyWeights();
265     // initPUWeights();
266 khahn 1.13 } else {
267 dkralph 1.60 if(!(ctrl.noJSON) )
268     initRunLumiRangeMap(ctrl);
269 khahn 1.13 }
270    
271 khahn 1.33 initElectronIDMVAV1();
272 khahn 1.13 initTrigger();
273 dkralph 1.53 initAnalysisTriggers(ti);
274 dkralph 1.62 ti.dump();
275    
276 dkralph 1.60 if(ctrl.do_escale) {
277 dkralph 1.62 string regPath("EGamma/EGammaAnalysisTools/data/eleEnergyRegWeights_V1.root");
278     // if(TString(getenv("HOSTNAME")).Contains(TRegexp("t3[bd][te][cs][hk]")))
279     regPath = cmsswpath + "/" + regPath;
280     electron_momentum_correction.initialize_regression(regPath);
281 dkralph 1.60 if(ctrl.mc) {
282 anlevin 1.61 if(ctrl.era == 2011) ctrl.smearing_scaling_dataset = "Fall11";
283 dkralph 1.60 else ctrl.smearing_scaling_dataset = "Summer12_DR53X_HCP2012";
284     } else {
285 anlevin 1.61 if(ctrl.era == 2011) ctrl.smearing_scaling_dataset = "Jan16ReReco";
286 dkralph 1.60 else ctrl.smearing_scaling_dataset = "2012Jul13ReReco";
287     }
288     }
289     if(ctrl.correct_muon_momentum) {
290     muCorr = new MuCorr;
291     muCorr->corr2011 = new rochcor;
292     muCorr->corr2012 = new rochcor2012;
293     }
294    
295     vector<TString> fJetCorrParsv;
296     vector<JetCorrectorParameters> correctionParameters;
297     FactorizedJetCorrector *fJetCorrector;
298     JetIDMVA *fJetIDMVA;
299 dkralph 1.62 initJets(ctrl, cmsswpath, fJetCorrParsv, correctionParameters, fJetCorrector, fJetIDMVA);
300 khahn 1.19
301 khahn 1.16 //
302 khahn 1.13 // Setup tree I/O
303 khahn 1.16 //--------------------------------------------------------------------------------------------------------------
304 khahn 1.1 TFile *inputFile=0;
305     TTree *eventTree=0;
306 khahn 1.13 string currentFile("");
307    
308 dkralph 1.60 UInt_t fNMaxTriggers = TRIGGER_BIG_NUMBER;
309     EventHeader *info = new EventHeader();
310     Array<PFMet> *metArr = new Array<PFMet>();
311     Array<Electron> *electronArr = new Array<Electron>();
312     Array<Muon> *muonArr = new Array<Muon>();
313     Array<Vertex> *vtxArr = new Array<Vertex>();
314     Array<PFCandidate> *pfArr = new Array<PFCandidate>();
315     Array<PFJet> *jetArr = new Array<PFJet>();
316     Array<PileupInfo> *puArr = new Array<PileupInfo>();
317     Array<PileupEnergyDensity> *puDArr = new Array<PileupEnergyDensity>();
318     Array<Track> *trkArr = new Array<Track>();
319     Array<MCParticle> *mcArr = new Array<MCParticle>();
320     MCEventInfo *mcEvtInfo = new MCEventInfo();
321     TriggerMask *trigMask = new TriggerMask();
322     TriggerTable *hltTable = new TriggerTable(fNMaxTriggers);
323     vector<string> *hltTableStrings = new vector<string>();
324     vector<string> *hltLabelStrings = new vector<string>();
325     Array<TriggerObject> *hltObjArr = new Array<TriggerObject>();
326     Array<TriggerObjectRel> *hltRelsArr = new Array<TriggerObjectRel>();
327     TriggerObjectsTable *fTrigObjs = new TriggerObjectsTable(hltTable,fNMaxTriggers);
328     RunInfo *runInfo = new RunInfo();
329 dkralph 1.44
330 dkralph 1.60 chain->SetBranchAddress(Names::gkEvtHeaderBrn, &info);
331     chain->SetBranchAddress("PFMet", &metArr);
332     chain->SetBranchAddress(Names::gkElectronBrn, &electronArr);
333     chain->SetBranchAddress(Names::gkMuonBrn, &muonArr);
334     chain->SetBranchAddress(Names::gkPVBrn, &vtxArr);
335     chain->SetBranchAddress(Names::gkPFCandidatesBrn, &pfArr);
336     chain->SetBranchAddress(Names::gkPFJetBrn, &jetArr);
337 khahn 1.23 if( ctrl.mc ) {
338 dkralph 1.60 chain->SetBranchAddress(Names::gkPileupInfoBrn, &puArr);
339     chain->SetBranchAddress(Names::gkMCPartBrn, &mcArr);
340     chain->SetBranchAddress(Names::gkMCEvtInfoBrn, &mcEvtInfo);
341 khahn 1.23 }
342 dkralph 1.60 chain->SetBranchAddress(Names::gkPileupEnergyDensityBrn, &puDArr);
343     chain->SetBranchAddress(Names::gkTrackBrn, &trkArr);
344     chain->SetBranchAddress(Names::gkHltBitBrn, &trigMask);
345     chain->SetBranchAddress(Names::gkHltObjBrn, &hltObjArr);
346     chain->SetBranchAddress("HLTObjectsRelation", &hltRelsArr);
347     hltchain->SetBranchAddress(Names::gkHltTableBrn, &hltTableStrings);
348     hltchain->SetBranchAddress(Names::gkHltLabelBrn, &hltLabelStrings);
349 khahn 1.1
350 dkralph 1.53 runchain->SetBranchAddress(Names::gkRunInfoBrn, &runInfo);
351    
352 dkralph 1.60 Vertex vtx; // best primary vertex in the event
353 khahn 1.11
354 khahn 1.13 hltchain->GetEntry(0);
355    
356 dkralph 1.60 int imax = (ctrl.n_events_to_process < 0) ? chain->GetEntries() : ctrl.n_events_to_process;
357     cerr << "processing: " << imax << " ( / " << chain->GetEntries() << " )" << endl;
358 anlevin 1.54
359 dkralph 1.60 if(ctrl.mc && ctrl.debugOffMc) // necessary for batch mode -- we need debug output for, data but size is too large to store MC output
360     ctrl.debug = false;
361 khahn 1.11
362 dkralph 1.53 int lastHltEntry=-2;
363 dkralph 1.62 for(UInt_t ientry=0; ientry<imax; ientry++) {
364     chain->GetEntry(ientry);
365     if(!(ientry%1000)) cerr << "entry: " << ientry << " ( / " << imax << " )" << endl;
366    
367     increment(counts,"start");
368     if( ctrl.debug ) {
369     cout << "-----------------------------------------------------------------" << endl;
370     cout << "-----------------------------------------------------------------" << endl;
371     cout << "Run: " << info->RunNum()
372     << "\tEvt: " << info->EvtNum()
373     << "\tLumi: " << info->LumiSec()
374     << endl;
375     cerr << "Run: " << info->RunNum()
376     << "\tEvt: " << info->EvtNum()
377     << "\tLumi: " << info->LumiSec()
378     << endl;
379     cout << "-----------------------------------------------------------------" << endl;
380     }
381 khahn 1.41
382 dkralph 1.62 runchain->GetEvent(info->RunEntry());
383     hltchain->GetEntry(runInfo->HltEntry());
384     hltTable->Clear();
385     fillTriggerNames(hltTable, hltTableStrings );
386     // if(ctrl.debug && (lastHltEntry != runInfo->HltEntry())) hltTable->Print();
387     lastHltEntry = runInfo->HltEntry();
388     fillTriggerBits( hltTable, trigMask, triggerBits );
389     setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs );
390     // printTriggerObjs( hltTable, fTrigObjs);
391 dkralph 1.53
392 dkralph 1.62 string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
393     if(ctrl.debug) cout << "era is " << ctrl.era << endl;
394     if( ctrl.era == 0 ) {
395     setEra( fname, ctrl );
396     if(ctrl.debug) cout << "era is now " << ctrl.era << endl;
397     }
398 khahn 1.41
399 dkralph 1.62 // pfNoPU
400     PFnoPUflag.clear();
401     int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
402     assert(pfnopu_size == pfArr->GetEntries());
403    
404     // trigger
405     if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
406     currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
407     }
408     if( ctrl.debug ) cout << "file is : " << currentFile << endl;
409     passes_HLT = passHLT(ctrl, triggerBits, ti, info->RunNum(), hltTable, fTrigObjs); // NOTE: run value is not used if it's MC
410 anlevin 1.58
411 dkralph 1.62 // data/MC
412     if(ctrl.mc) {
413     if(ctrl.fillGen) fillGenInfo( mcArr, mcEvtInfo, geninfo, genSampleType, ctrl);
414     // NOTE: xs weight and npuw are reset in merge.cc
415     weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
416     if(ctrl.debug) cout ;
417     weights.npu = getNPU(puArr, 0);
418     weights.npuw = getPUWeight(ctrl.era, fname, weights.npu);
419     } else {
420     // JSON
421     if(!(ctrl.noJSON) ) {
422     RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());
423     if( !(rlrm.HasRunLumi(rl)) ) {
424     if( ctrl.debug ) cout << "fails JSON" << endl;
425     continue;
426 khahn 1.16 }
427 khahn 1.13 }
428 dkralph 1.62 }
429 khahn 1.16
430 dkralph 1.62 //
431     // lepton/kinematic selection ...
432     //
433     failingLeptons.clear();
434     passingLeptons.clear();
435     EventData ret4l = apply_HZZ4L_reference_selection(ctrl, info,
436     vtxArr,
437     pfArr,
438     puDArr,
439     electronArr,
440     &electronReferencePreSelection,
441     &electronReferenceIDMVASelectionV1, // not used anymore! (Blame the damn regression implementation, not me!)
442     &electronReferenceIsoSelection,
443     muonArr,
444     &muonReferencePreSelection,
445     &muonIDPFSelection,
446     &muonReferenceIsoSelection);
447 khahn 1.33
448 dkralph 1.62 if( ctrl.debug ) cout << endl;
449 khahn 1.14
450 dkralph 1.62 if(ctrl.fakeScheme == "none") { // fill angletuple if event passes full selection
451     if( ret4l.status.pass() ) {
452     setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt);
453     nt.Fill();
454     } else {
455     if(ctrl.debug) cout << "failing with code : " << ret4l.status.selectionBits << endl;
456     }
457     } else { // fill FOtuple and angletuple if event has a good Z and one or two extra leptons
458     assert(ctrl.fakeScheme=="ZPlusF" || ctrl.fakeScheme=="ZPlusFF");
459     if(ret4l.status.selectionBits.test(PASS_GOODZ1) ) {
460     unsigned nleps = passingLeptons.size() + failingLeptons.size();
461     if( (nleps>=3 && ctrl.fakeScheme=="ZPlusF" ) || (nleps>=4 && ctrl.fakeScheme=="ZPlusFF" ) ) {
462     addDummyZ2Lepotons(ret4l);
463     setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt);
464     nt.Fill();
465     foTree->Fill();
466 dkralph 1.60 }
467 dkralph 1.62 } else {
468     if(ctrl.debug) cout << "failing PASS_GOODZ1" << endl;
469 khahn 1.15 }
470 dkralph 1.53 }
471 dkralph 1.62 }
472 khahn 1.1
473 dkralph 1.62 if(ctrl.fakeScheme != "none") {
474     foTree->getFile()->cd();
475     foTree->getTree()->Write();
476     }
477 khahn 1.13 nt.WriteClose();
478 khahn 1.19
479 anlevin 1.57 for(unsigned icut=0; icut<cuts.size(); icut++) {
480 dkralph 1.60 map<TString,int> thisCount(*(counts[cuts[icut]]));
481 dkralph 1.62 cerr << setw(20) << cuts[icut] << "\t" << setw(9) << thisCount["all"] << " ("
482 dkralph 1.60 << setw(9) << thisCount["4e"] << setw(9) << thisCount["4m"] << setw(9) << thisCount["2e2m"] << ")" << endl;
483 anlevin 1.57 }
484 dkralph 1.62 }
485     //----------------------------------------------------------------------------------------
486     void addDummyZ2Lepotons(EventData &ret4l)
487     // for fake ntuples, we don't know which are the Z2 leptons yet, but need to fill something so we don't seg fault
488     {
489     SimpleLepton dum1,dum2;
490     dum1.vec.SetPtEtaPhiM(1,2,3,4);
491     dum2.vec.SetPtEtaPhiM(5,6,7,8);
492     ret4l.Z2leptons.push_back(dum1);
493     ret4l.Z2leptons.push_back(dum2);
494     }
495     //----------------------------------------------------------------------------------------
496     void setNtupleVals(ControlFlags &ctrl, EventData &ret4l, InfoStruct &evtinfo, Angles &angles, KinematicsStruct &kine,
497     JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<PFJet> *jetArr, Array<PFMet> *metArr,
498     vector<SimpleLepton> &simpleLeptonJets, FactorizedJetCorrector *fJetCorrector, Array<PileupInfo> *puArr,
499     Array<PileupEnergyDensity> *puDArr, JetIDMVA *fJetIDMVA, Array<Vertex> *vtxArr, bitset<1024> &triggerBits,
500     TriggerTable *hltTable, Array<TriggerObject> *hltObjArr, TriggerObjectsTable *fTrigObjs, AngleTuple *nt)
501     {
502     fillKinematics(ret4l,kine);
503     // fillMassErrors(ret4l,muonArr,electronArr,kine);
504     TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
505     fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0, vtxArr->GetEntries());
506     fillJets(ctrl, jetArr, simpleLeptonJets, fJetCorrector, puDArr, fJetIDMVA, vtxArr, ret4l);
507     fillJetInfo(simpleLeptonJets, ji, ctrl);
508     fillJetAngleBranches(ji, ret4l, nt, ctrl);
509     evtinfo.status = 0;
510     evtinfo.status = setHltBits(ti, triggerBits);
511    
512     if(ctrl.fakeScheme == "none") {
513     fillAngles(ret4l,angles);
514    
515     if( ctrl.mc) {
516     setEfficiencyWeights(ctrl, ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights);
517     if(ctrl.debug)
518     cout << "w: " << weights.w << "\t" << "npuw: " << weights.npuw << "\t" << "won: " << weights.won << "\t" << "woff: " << weights.woff << endl;
519     }
520    
521     if(ctrl.debug) {
522     stringstream ss;
523     ss << "PASS:: " << "\trun: " << evtinfo.run << "\tevt: " << evtinfo.evt << "\tlumi: " << evtinfo.lumi << "\tchannel: "
524     << kine.channel << "\tm4l: " << kine.m4l << "\tmZ1: " << kine.mZ1 << "\tmZ2: " << kine.mZ2 << endl;
525     cerr << ss.str();
526     cout << ss.str();
527     }
528     } else {
529     // fillAngles(ret4l,angles); // at this point we don't know which four leptons will constitute the ZZ system, so doesn't make sense to fill the angles
530     }
531     }