ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
Revision: 1.76
Committed: Sun Feb 24 12:59:58 2013 UTC (12 years, 2 months ago) by anlevin
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.75: +0 -2 lines
Log Message:
made changes to synchronize on 2011 monte carlo

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 "KinematicsStruct.h"
71     #include "InfoStruct.h"
72 khahn 1.28 #include "GenInfoStruct.h"
73 khahn 1.13 #include "WeightStruct.h"
74     #include "AngleTuple.h"
75 khahn 1.15 #include "FOTuple.h"
76 khahn 1.13
77 khahn 1.33 #include "RunLumiRangeMap.h"
78 dkralph 1.2 #include "SampleWeight.h"
79 khahn 1.13 #include "EfficiencyWeightsInterface.h"
80 dkralph 1.38 #include "SelectionFuncs.h"
81 khahn 1.1
82 khahn 1.16 #include "SimpleLepton.h"
83    
84 anlevin 1.72 #include "Cintex/Cintex.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 anlevin 1.70 JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<Muon> *muonArr, Array<Electron> *electronArr, Array<PFJet> *jetArr, Array<PFMet> *metArr,
113 dkralph 1.62 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.72
138 anlevin 1.57 vector<TString> cuts;
139 dkralph 1.60 cuts.push_back("start"); // NOTE: is incremented in ReferenceSelection, so if you turn on JSONS be careful
140 anlevin 1.57 cuts.push_back("trigger");
141     cuts.push_back("sfOsHiPt");
142     cuts.push_back("4<mZ2<120");
143     cuts.push_back("pt>20,10");
144     cuts.push_back("mll>4");
145     cuts.push_back("m4l>70");
146 dkralph 1.60 cuts.push_back("mZ2>12");
147     cuts.push_back("m4l>100");
148 anlevin 1.68 cuts.push_back("m4l > 100 && >= 1 jets");
149     cuts.push_back("m4l > 100 && 2 jets");
150     cuts.push_back("m4l > 100 && fisher > 0.4");
151 anlevin 1.57
152     for(unsigned icut=0; icut<cuts.size(); icut++)
153     counts[cuts[icut]] = new map<TString,int>;
154    
155     map<TString,map<TString,int>* >::iterator cit;
156     for(cit=counts.begin(); cit!=counts.end(); cit++) {
157     map<TString,int> *cts = (*cit).second;
158     (*cts)["all"] = int(0);
159     (*cts)["4e"] = int(0);
160     (*cts)["4m"] = int(0);
161     (*cts)["2e2m"] = int(0);
162     }
163 dkralph 1.60
164 khahn 1.13 string cmsswpath(CMSSW_BASE);
165     cmsswpath.append("/src");
166 dkralph 1.60 bitset<1024> triggerBits;
167 khahn 1.1 vector<vector<string> > inputFiles;
168     inputFiles.push_back(vector<string>());
169 khahn 1.16 map<string,unsigned> entrymap; // number of unskimmed entries in each file
170 khahn 1.1
171     //
172     // args
173     //--------------------------------------------------------------------------------------------------------------
174     ControlFlags ctrl;
175     parse_args( argc, argv, ctrl );
176     ctrl.dump();
177 dkralph 1.60 cout << "\n\nNOTE: now setting era with arguments... double check this doesnt mess something else up\n\n" << endl;
178     assert(ctrl.doFSR);
179 dkralph 1.4
180 khahn 1.1 //
181     // File I/O
182     //--------------------------------------------------------------------------------------------------------------
183     TChain * chain = new TChain("Events");
184 khahn 1.13 TChain * hltchain = new TChain("HLT");
185 dkralph 1.53 TChain * runchain = new TChain(Names::gkRunTreeName);
186 khahn 1.13
187 khahn 1.1 string fname;
188 dkralph 1.44 unsigned total_unskimmed=0;
189 khahn 1.13 if( !ctrl.inputfiles.empty() ) {
190     ifstream f(ctrl.inputfiles.c_str());
191 dkralph 1.60 while (f >> fname) {
192 khahn 1.13 if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
193 anlevin 1.75 //if(fname.find("/store/") != string::npos) fname = "root://eoscms//"+fname;
194 khahn 1.13 cout << "adding inputfile : " << fname.c_str() << endl;
195     entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
196 dkralph 1.62 cerr << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl;
197 dkralph 1.44 total_unskimmed += entrymap[string(fname.c_str())];
198 khahn 1.13 chain->AddFile(fname.c_str());
199     hltchain->AddFile(fname.c_str());
200 dkralph 1.53 runchain->AddFile(fname.c_str());
201 khahn 1.13 }
202     } else {
203 anlevin 1.75 //if(ctrl.inputfile.find("/store/") != string::npos) ctrl.inputfile = "root://eoscms//"+ctrl.inputfile;
204 khahn 1.13 cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
205 dkralph 1.44 unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str());
206     entrymap[string(ctrl.inputfile.c_str())] = unsk_ents;
207 dkralph 1.62 cerr << "unskimmed entries: " << unsk_ents << endl;
208 dkralph 1.44 total_unskimmed += unsk_ents;
209 khahn 1.13 chain->AddFile(ctrl.inputfile.c_str());
210     hltchain->AddFile(ctrl.inputfile.c_str());
211 dkralph 1.53 runchain->AddFile(ctrl.inputfile.c_str());
212 khahn 1.1 }
213 dkralph 1.60 // write the total number of unskimmed events that went into making this output file to a text file
214 dkralph 1.53 writeEntries(ctrl,total_unskimmed);
215 dkralph 1.60 ctrl.totalMC = total_unskimmed;
216 khahn 1.1
217 dkralph 1.10 const char * ofname;
218     if( strcmp( ctrl.outputfile.c_str(), "") ) {
219     ofname = ctrl.outputfile.c_str();
220     } else {
221     ofname = "tmp.root";
222     }
223 khahn 1.13 // table of cross section values
224     string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat"));
225     cout << "xspath: " << xspath.c_str() << endl;
226     SimpleTable xstab(xspath.c_str());
227 dkralph 1.62 if(ctrl.mc) {
228 anlevin 1.66 if(ctrl.use_xs_weights) getWeight(xstab,entrymap,chain); // test *now* whether we've got the xs in here, so it fails before it creates the output
229 dkralph 1.62 }
230 khahn 1.11
231 anlevin 1.72 //root will write to this temporary file instead of to memory and the selection will run faster
232    
233 khahn 1.1 //
234 khahn 1.13 // Setup
235 khahn 1.1 //--------------------------------------------------------------------------------------------------------------
236 khahn 1.13 Angles angles;
237 anlevin 1.57 KinematicsStruct kine;
238 khahn 1.13 InfoStruct evtinfo;
239     WeightStruct weights;
240 khahn 1.28 GenInfoStruct geninfo;
241 dkralph 1.60 JetInfoStruct ji;
242     vector<SimpleLepton> simpleLeptonJets;
243 khahn 1.13
244     AngleTuple nt( (const char*)ofname, (const char*)"zznt");
245     nt.makeAngleBranch(angles);
246 anlevin 1.57 nt.makeKinematicsBranch(kine);
247 khahn 1.13 nt.makeInfoBranch(evtinfo);
248 dkralph 1.67 nt.makeJetInfoBranch(ji);
249 anlevin 1.70 //nt.makeJetAngleBranches("DataStruct/data/jetAngleVars.txt");
250 dkralph 1.62
251     FOTuple *foTree=0;
252     if(ctrl.fakeScheme != "none") {
253     foTree = new FOTuple( nt.getFile(), (const char*)"FOtree");
254     foTree->makeInfoBranch(evtinfo);
255     foTree->makeFailedLeptonBranch(failingLeptons);
256     foTree->makePassedLeptonBranch(passingLeptons);
257     }
258 khahn 1.17
259 dkralph 1.60 int genSampleType(0);
260 khahn 1.13 if(ctrl.mc) {
261     nt.makeWeightBranch(weights);
262 dkralph 1.60 if(ctrl.fillGen) {
263     genSampleType = getGenSampleType(ofname);
264     if(genSampleType == -1) {
265     cout << "\ngenSampleType returned as -1, setting fillGen to false" << endl;
266     ctrl.fillGen = false;
267     } else
268     nt.makeGenInfoBranch(geninfo);
269 khahn 1.13 }
270 anlevin 1.66 if(ctrl.use_eff_weights) initEfficiencyWeights();
271 khahn 1.13 } else {
272 dkralph 1.60 if(!(ctrl.noJSON) )
273     initRunLumiRangeMap(ctrl);
274 khahn 1.13 }
275    
276 khahn 1.33 initElectronIDMVAV1();
277 khahn 1.13 initTrigger();
278 dkralph 1.53 initAnalysisTriggers(ti);
279 anlevin 1.70 initMela(ctrl);
280     initMassErrors();
281 dkralph 1.62 ti.dump();
282    
283 anlevin 1.75 {
284     TFile tmp_file("tmp_file.root","RECREATE");
285     }
286 anlevin 1.72
287     if(ctrl.do_eregression) {
288 dkralph 1.62 string regPath("EGamma/EGammaAnalysisTools/data/eleEnergyRegWeights_V1.root");
289     // if(TString(getenv("HOSTNAME")).Contains(TRegexp("t3[bd][te][cs][hk]")))
290 anlevin 1.72 regPath = cmsswpath + "/" + regPath;
291 dkralph 1.62 electron_momentum_correction.initialize_regression(regPath);
292 anlevin 1.72 }
293    
294 dkralph 1.60 if(ctrl.correct_muon_momentum) {
295     muCorr = new MuCorr;
296     muCorr->corr2011 = new rochcor;
297     muCorr->corr2012 = new rochcor2012;
298     }
299    
300     vector<TString> fJetCorrParsv;
301     vector<JetCorrectorParameters> correctionParameters;
302     FactorizedJetCorrector *fJetCorrector;
303     JetIDMVA *fJetIDMVA;
304 dkralph 1.67 initJets(ctrl, cmsswpath, fJetCorrParsv, correctionParameters, fJetCorrector, fJetIDMVA);
305 khahn 1.19
306 khahn 1.16 //
307 khahn 1.13 // Setup tree I/O
308 khahn 1.16 //--------------------------------------------------------------------------------------------------------------
309 khahn 1.1 TFile *inputFile=0;
310     TTree *eventTree=0;
311 khahn 1.13 string currentFile("");
312    
313 dkralph 1.60 UInt_t fNMaxTriggers = TRIGGER_BIG_NUMBER;
314     EventHeader *info = new EventHeader();
315     Array<PFMet> *metArr = new Array<PFMet>();
316     Array<Electron> *electronArr = new Array<Electron>();
317     Array<Muon> *muonArr = new Array<Muon>();
318     Array<Vertex> *vtxArr = new Array<Vertex>();
319     Array<PFCandidate> *pfArr = new Array<PFCandidate>();
320     Array<PFJet> *jetArr = new Array<PFJet>();
321     Array<PileupInfo> *puArr = new Array<PileupInfo>();
322     Array<PileupEnergyDensity> *puDArr = new Array<PileupEnergyDensity>();
323     Array<Track> *trkArr = new Array<Track>();
324     Array<MCParticle> *mcArr = new Array<MCParticle>();
325     MCEventInfo *mcEvtInfo = new MCEventInfo();
326     TriggerMask *trigMask = new TriggerMask();
327     TriggerTable *hltTable = new TriggerTable(fNMaxTriggers);
328     vector<string> *hltTableStrings = new vector<string>();
329     vector<string> *hltLabelStrings = new vector<string>();
330     Array<TriggerObject> *hltObjArr = new Array<TriggerObject>();
331     Array<TriggerObjectRel> *hltRelsArr = new Array<TriggerObjectRel>();
332     TriggerObjectsTable *fTrigObjs = new TriggerObjectsTable(hltTable,fNMaxTriggers);
333     RunInfo *runInfo = new RunInfo();
334 dkralph 1.44
335 dkralph 1.60 chain->SetBranchAddress(Names::gkEvtHeaderBrn, &info);
336     chain->SetBranchAddress("PFMet", &metArr);
337     chain->SetBranchAddress(Names::gkElectronBrn, &electronArr);
338     chain->SetBranchAddress(Names::gkMuonBrn, &muonArr);
339     chain->SetBranchAddress(Names::gkPVBrn, &vtxArr);
340     chain->SetBranchAddress(Names::gkPFCandidatesBrn, &pfArr);
341     chain->SetBranchAddress(Names::gkPFJetBrn, &jetArr);
342 khahn 1.23 if( ctrl.mc ) {
343 dkralph 1.60 chain->SetBranchAddress(Names::gkPileupInfoBrn, &puArr);
344     chain->SetBranchAddress(Names::gkMCPartBrn, &mcArr);
345     chain->SetBranchAddress(Names::gkMCEvtInfoBrn, &mcEvtInfo);
346 khahn 1.23 }
347 dkralph 1.60 chain->SetBranchAddress(Names::gkPileupEnergyDensityBrn, &puDArr);
348     chain->SetBranchAddress(Names::gkTrackBrn, &trkArr);
349     chain->SetBranchAddress(Names::gkHltBitBrn, &trigMask);
350     chain->SetBranchAddress(Names::gkHltObjBrn, &hltObjArr);
351     chain->SetBranchAddress("HLTObjectsRelation", &hltRelsArr);
352     hltchain->SetBranchAddress(Names::gkHltTableBrn, &hltTableStrings);
353     hltchain->SetBranchAddress(Names::gkHltLabelBrn, &hltLabelStrings);
354 khahn 1.1
355 dkralph 1.53 runchain->SetBranchAddress(Names::gkRunInfoBrn, &runInfo);
356    
357 dkralph 1.60 Vertex vtx; // best primary vertex in the event
358 khahn 1.11
359 khahn 1.13 hltchain->GetEntry(0);
360    
361 dkralph 1.60 int imax = (ctrl.n_events_to_process < 0) ? chain->GetEntries() : ctrl.n_events_to_process;
362     cerr << "processing: " << imax << " ( / " << chain->GetEntries() << " )" << endl;
363 anlevin 1.54
364 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
365     ctrl.debug = false;
366 khahn 1.11
367 dkralph 1.53 int lastHltEntry=-2;
368 dkralph 1.62 for(UInt_t ientry=0; ientry<imax; ientry++) {
369     chain->GetEntry(ientry);
370     if(!(ientry%1000)) cerr << "entry: " << ientry << " ( / " << imax << " )" << endl;
371    
372     increment(counts,"start");
373     if( ctrl.debug ) {
374     cout << "-----------------------------------------------------------------" << endl;
375     cout << "-----------------------------------------------------------------" << endl;
376     cout << "Run: " << info->RunNum()
377     << "\tEvt: " << info->EvtNum()
378     << "\tLumi: " << info->LumiSec()
379     << endl;
380     cerr << "Run: " << info->RunNum()
381     << "\tEvt: " << info->EvtNum()
382     << "\tLumi: " << info->LumiSec()
383     << endl;
384     cout << "-----------------------------------------------------------------" << endl;
385     }
386 khahn 1.41
387 dkralph 1.62 runchain->GetEvent(info->RunEntry());
388     hltchain->GetEntry(runInfo->HltEntry());
389     hltTable->Clear();
390     fillTriggerNames(hltTable, hltTableStrings );
391     // if(ctrl.debug && (lastHltEntry != runInfo->HltEntry())) hltTable->Print();
392     lastHltEntry = runInfo->HltEntry();
393     fillTriggerBits( hltTable, trigMask, triggerBits );
394     setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs );
395     // printTriggerObjs( hltTable, fTrigObjs);
396 dkralph 1.53
397 dkralph 1.62 string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
398     if(ctrl.debug) cout << "era is " << ctrl.era << endl;
399     if( ctrl.era == 0 ) {
400     setEra( fname, ctrl );
401     if(ctrl.debug) cout << "era is now " << ctrl.era << endl;
402     }
403 khahn 1.41
404 dkralph 1.62 // pfNoPU
405     PFnoPUflag.clear();
406     int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
407     assert(pfnopu_size == pfArr->GetEntries());
408    
409     // trigger
410     if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
411     currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
412     }
413     if( ctrl.debug ) cout << "file is : " << currentFile << endl;
414     passes_HLT = passHLT(ctrl, triggerBits, ti, info->RunNum(), hltTable, fTrigObjs); // NOTE: run value is not used if it's MC
415 dkralph 1.67
416     // data/MC
417     if(ctrl.mc) {
418     if(ctrl.fillGen) fillGenInfo( mcArr, mcEvtInfo, geninfo, genSampleType, ctrl);
419     // NOTE: xs weight and npuw are reset in merge.cc
420     if(ctrl.use_xs_weights)
421     weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
422     else
423     weights.w = 1;
424     weights.npu = getNPU(puArr, 0);
425     weights.npuw = getPUWeight(ctrl.era, fname, weights.npu);
426     } else {
427     // JSON
428     if(!(ctrl.noJSON) ) {
429     RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());
430     if( !(rlrm.HasRunLumi(rl)) ) {
431     if( ctrl.debug ) cout << "fails JSON" << endl;
432     continue;
433 khahn 1.16 }
434 khahn 1.13 }
435 dkralph 1.67 }
436 khahn 1.16
437 dkralph 1.62 //
438     // lepton/kinematic selection ...
439     //
440     failingLeptons.clear();
441     passingLeptons.clear();
442     EventData ret4l = apply_HZZ4L_reference_selection(ctrl, info,
443     vtxArr,
444     pfArr,
445     puDArr,
446     electronArr,
447     &electronReferencePreSelection,
448     &electronReferenceIDMVASelectionV1, // not used anymore! (Blame the damn regression implementation, not me!)
449     &electronReferenceIsoSelection,
450     muonArr,
451     &muonReferencePreSelection,
452     &muonIDPFSelection,
453     &muonReferenceIsoSelection);
454 khahn 1.33
455 dkralph 1.62 if( ctrl.debug ) cout << endl;
456 khahn 1.14
457 dkralph 1.62 if(ctrl.fakeScheme == "none") { // fill angletuple if event passes full selection
458     if( ret4l.status.pass() ) {
459 anlevin 1.70 setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, muonArr, electronArr, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt);
460 dkralph 1.62 nt.Fill();
461 anlevin 1.68
462     int theZ1type = kine.l1type;
463     int theZ2type = kine.l3type;
464    
465     if(ctrl.debug) cout << "simpleLeptonJets.size() = " << simpleLeptonJets.size() << endl;
466    
467     if(kine.m4l > 100){
468     if(simpleLeptonJets.size() >= 1) {
469     increment(counts,"m4l > 100 && >= 1 jets",theZ1type,theZ2type);
470     if(simpleLeptonJets.size() == 2) {
471     increment(counts,"m4l > 100 && 2 jets",theZ1type,theZ2type);
472     SimpleLepton j1 = simpleLeptonJets[0];
473     SimpleLepton j2 = simpleLeptonJets[1];
474     double deta = abs(j1.vec.Eta()-j2.vec.Eta());
475     double mjj = (j1.vec + j2.vec).M();
476     double fisher = 0.09407 * deta +0.00041581*mjj;
477     if(fisher > 0.4) increment(counts, "m4l > 100 && fisher > 0.4",theZ1type,theZ2type);
478     }
479     }
480     }
481 dkralph 1.69
482 anlevin 1.68
483 dkralph 1.62 } else {
484     if(ctrl.debug) cout << "failing with code : " << ret4l.status.selectionBits << endl;
485     }
486     } else { // fill FOtuple and angletuple if event has a good Z and one or two extra leptons
487     assert(ctrl.fakeScheme=="ZPlusF" || ctrl.fakeScheme=="ZPlusFF");
488     if(ret4l.status.selectionBits.test(PASS_GOODZ1) ) {
489     unsigned nleps = passingLeptons.size() + failingLeptons.size();
490     if( (nleps>=3 && ctrl.fakeScheme=="ZPlusF" ) || (nleps>=4 && ctrl.fakeScheme=="ZPlusFF" ) ) {
491     addDummyZ2Lepotons(ret4l);
492 anlevin 1.70 setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, muonArr, electronArr, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt);
493 dkralph 1.62 nt.Fill();
494     foTree->Fill();
495 dkralph 1.60 }
496 dkralph 1.62 } else {
497     if(ctrl.debug) cout << "failing PASS_GOODZ1" << endl;
498 khahn 1.15 }
499 dkralph 1.53 }
500 anlevin 1.72
501     hltTable->Delete();
502    
503 dkralph 1.62 }
504 khahn 1.1
505 dkralph 1.62 if(ctrl.fakeScheme != "none") {
506     foTree->getFile()->cd();
507     foTree->getTree()->Write();
508     }
509 khahn 1.13 nt.WriteClose();
510 khahn 1.19
511 anlevin 1.57 for(unsigned icut=0; icut<cuts.size(); icut++) {
512 dkralph 1.60 map<TString,int> thisCount(*(counts[cuts[icut]]));
513 anlevin 1.68 cerr << setw(25) << cuts[icut] << "\t" << setw(9) << thisCount["all"] << " ("
514 dkralph 1.60 << setw(9) << thisCount["4e"] << setw(9) << thisCount["4m"] << setw(9) << thisCount["2e2m"] << ")" << endl;
515 anlevin 1.57 }
516 anlevin 1.72
517 dkralph 1.62 }
518     //----------------------------------------------------------------------------------------
519     void addDummyZ2Lepotons(EventData &ret4l)
520     // for fake ntuples, we don't know which are the Z2 leptons yet, but need to fill something so we don't seg fault
521     {
522     SimpleLepton dum1,dum2;
523     dum1.vec.SetPtEtaPhiM(1,2,3,4);
524     dum2.vec.SetPtEtaPhiM(5,6,7,8);
525     ret4l.Z2leptons.push_back(dum1);
526     ret4l.Z2leptons.push_back(dum2);
527     }
528     //----------------------------------------------------------------------------------------
529     void setNtupleVals(ControlFlags &ctrl, EventData &ret4l, InfoStruct &evtinfo, Angles &angles, KinematicsStruct &kine,
530 anlevin 1.70 JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<Muon> *muonArr, Array<Electron> *electronArr, Array<PFJet> *jetArr, Array<PFMet> *metArr,
531 dkralph 1.62 vector<SimpleLepton> &simpleLeptonJets, FactorizedJetCorrector *fJetCorrector, Array<PileupInfo> *puArr,
532     Array<PileupEnergyDensity> *puDArr, JetIDMVA *fJetIDMVA, Array<Vertex> *vtxArr, bitset<1024> &triggerBits,
533     TriggerTable *hltTable, Array<TriggerObject> *hltObjArr, TriggerObjectsTable *fTrigObjs, AngleTuple *nt)
534     {
535     fillKinematics(ret4l,kine);
536 anlevin 1.70
537     //the last two arguments are usePt and useY respectively
538     fillMela(kine,0,0);
539    
540 anlevin 1.71 fillMassErrors(ctrl,ret4l,muonArr,electronArr,kine);
541 anlevin 1.70
542 dkralph 1.62 TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
543     fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0, vtxArr->GetEntries());
544 dkralph 1.67 fillJets(ctrl, jetArr, simpleLeptonJets, fJetCorrector, puDArr, fJetIDMVA, vtxArr, ret4l);
545     fillJetInfo(simpleLeptonJets, ji, ctrl);
546 anlevin 1.70 //fillJetAngleBranches(ji, ret4l, nt, ctrl);
547 dkralph 1.62 evtinfo.status = 0;
548     evtinfo.status = setHltBits(ti, triggerBits);
549    
550     if(ctrl.fakeScheme == "none") {
551     fillAngles(ret4l,angles);
552    
553     if( ctrl.mc) {
554 anlevin 1.66 if(ctrl.use_eff_weights) setEfficiencyWeights(ctrl, ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights);
555 dkralph 1.62 if(ctrl.debug)
556     cout << "w: " << weights.w << "\t" << "npuw: " << weights.npuw << "\t" << "won: " << weights.won << "\t" << "woff: " << weights.woff << endl;
557     }
558    
559     if(ctrl.debug) {
560     stringstream ss;
561     ss << "PASS:: " << "\trun: " << evtinfo.run << "\tevt: " << evtinfo.evt << "\tlumi: " << evtinfo.lumi << "\tchannel: "
562     << kine.channel << "\tm4l: " << kine.m4l << "\tmZ1: " << kine.mZ1 << "\tmZ2: " << kine.mZ2 << endl;
563     cerr << ss.str();
564     cout << ss.str();
565     }
566     } else {
567     // 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
568     }
569     }