ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/applySelection.cc
(Generate patch)

Comparing UserCode/MitHzz4l/Selection/src/applySelection.cc (file contents):
Revision 1.7 by khahn, Thu Oct 13 14:27:53 2011 UTC vs.
Revision 1.67 by dkralph, Tue Jan 15 10:37:19 2013 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines