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.3 by khahn, Wed Sep 14 21:43:21 2011 UTC vs.
Revision 1.57 by anlevin, Sat Oct 13 19:47:56 2012 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 <TTree.h>                  
16 > #include <TChain.h>                
17 > #include <TBranch.h>                
18 > #include <TClonesArray.h>          
19 >
20 >
21 > //
22 > // TMVA
23 > //
24 > #include "TMVA/Reader.h"
25 > #include "TMVA/Tools.h"
26 > #include "TMVA/Config.h"
27 > #include "TMVA/MethodBDT.h"
28  
29   //
30   // ntuple format headers
31   //
32 < #include "HiggsAnaDefs.hh"
33 < #include "TEventInfo.hh"
34 < #include "TElectron.hh"
35 < #include "TMuon.hh"
36 < #include "TJet.hh"
37 < #include "RunLumiRangeMap.h"
32 > #include "EventHeader.h"
33 > #include "Electron.h"
34 > #include "Muon.h"
35 > #include "Vertex.h"
36 > #include "PFMet.h"
37 > #include "PFCandidate.h"
38 > #include "PFCandidateCol.h"
39 > #include "PileupInfoCol.h"
40 > #include "PileupEnergyDensity.h"
41 > #include "MCParticle.h"
42 > #include "TriggerMask.h"
43 > #include "TriggerTable.h"
44 > #include "TriggerObject.h"
45 > #include "TriggerObjectRel.h"
46 > #include "Names.h"
47 > #include "BaseMod.h"
48 > #include "TriggerObjectsTable.h"
49  
50   //
51 < // utility headers
51 > // our headers
52   //
53   #include "ParseArgs.h"
54 + #include "MuonSelection.h"
55 + #include "ElectronSelection.h"
56 + #include "ElectronMomentumCorrection.h"
57 + #include "IsolationSelection.h"
58 + #include "ReferenceSelection.h"
59 +
60 + #include "TriggerUtils.h"
61 + #include "PassHLT.h"
62 + #include "Angles.h"
63 + #include "KinematicsStruct.h"
64 + #include "InfoStruct.h"
65 + #include "GenInfoStruct.h"
66 + #include "WeightStruct.h"
67 + #include "AngleTuple.h"
68 + #include "FOTuple.h"
69 +
70 + #include "RunLumiRangeMap.h"
71   #include "SampleWeight.h"
72 < #include "Selection.h"
73 < #include "HZZCiCElectronSelection.h"
49 < #include "SampleWeight.h"
72 > #include "EfficiencyWeightsInterface.h"
73 > #include "SelectionFuncs.h"
74  
75 < //#define THEIR_EVENTS
75 > #include "SimpleLepton.h"
76 >
77 > #ifndef CMSSW_BASE
78 > #define CMSSW_BASE "../"
79 > #endif
80 >
81 > using namespace mithep;
82 >
83 > //
84 > // globals
85 > //----------------------------------------------------------------------------
86 > TH1D *hpu_2011, *hpu_2012;
87 > RunLumiRangeMap rlrm;
88 > vector<SimpleLepton> failingLeptons ; // for fake estimation
89 > vector<SimpleLepton> passingLeptons;      // for fake estimation
90 > vector<unsigned> cutvec;
91 > vector<vector<unsigned> > zcutvec;
92 > vector<vector<unsigned> > zzcutvec;
93 > map<unsigned,float>       evtrhoMap;
94 > vector<string> cutstrs;
95 > bool passes_HLT_MC,passes_HLT;
96 > vector<bool>   PFnoPUflag;;
97 > map<TString, map<TString,int>* > counts;
98 >
99 > //
100 > // prototypes
101 > //----------------------------------------------------------------------------
102 > void initRunLumiRangeMap(ControlFlags &ctrl);
103 > //----------------------------------------------------------------------------
104  
105 < //=== MAIN =================================================================================================
105 > //
106 > // MAIN
107 > //----------------------------------------------------------------------------
108   int main(int argc, char** argv)
109 + //----------------------------------------------------------------------------
110   {
111 <  
111 >  vector<TString> cuts;
112 >  cuts.push_back("trigger");
113 >  cuts.push_back("sfOsHiPt");
114 >  cuts.push_back("4<mZ2<120");
115 >  cuts.push_back("pt>20,10");
116 >  cuts.push_back("mll>4");
117 >  cuts.push_back("m4l>70");
118 >  cuts.push_back("m4l>100,mZ2>12");
119 >
120 >  for(unsigned icut=0; icut<cuts.size(); icut++)
121 >    counts[cuts[icut]] = new map<TString,int>;
122 >
123 >  map<TString,map<TString,int>* >::iterator cit;
124 >  for(cit=counts.begin(); cit!=counts.end(); cit++) {
125 >    map<TString,int> *cts = (*cit).second;
126 >    (*cts)["all"]  = int(0);
127 >    (*cts)["4e"]   = int(0);
128 >    (*cts)["4m"]   = int(0);
129 >    (*cts)["2e2m"] = int(0);
130 >  }
131 >
132 >  cutstrs.push_back(string("skim0"));              //0
133 >  cutstrs.push_back(string("skim1"));              //1
134 >  cutstrs.push_back(string("skim2"));              //1
135 >  cutstrs.push_back(string("trigger"));            //2
136 >  // -------------------------------------------------
137 >  cutstrs.push_back(string("Z candidate"));        //3
138 >  cutstrs.push_back(string("good Z1"));            //4
139 >  // -------------------------------------------------
140 >  cutstrs.push_back(string("4l"));                 //5  
141 >  cutstrs.push_back(string("ZZ candidate"));       //6
142 >  cutstrs.push_back(string("good Z2"));            //7
143 >  cutstrs.push_back(string("ZZ 20/10"));           //8
144 >  cutstrs.push_back(string("resonance"));          //9
145 >  cutstrs.push_back(string("m4l>70"));             //10
146 >  cutstrs.push_back(string("m4l>100, mZ2 > 12"));                  //11
147 >
148 >  string cmsswpath(CMSSW_BASE);
149 >  cmsswpath.append("/src");
150 >  std::bitset<1024> triggerBits;
151    vector<vector<string> > inputFiles;
152    inputFiles.push_back(vector<string>());
153 +  map<string,unsigned> entrymap; // number of unskimmed entries in each file
154 +  for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0);
155 +  for( int i=0; i<2; i++ )  {
156 +    zcutvec.push_back(vector<unsigned>());
157 +    for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0);
158 +  }
159 +  for( int i=0; i<3; i++ )  {
160 +    zzcutvec.push_back(vector<unsigned>());
161 +    for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
162 +  }
163 +
164  
165    //
166    // args
167    //--------------------------------------------------------------------------------------------------------------
168    ControlFlags ctrl;
169    parse_args( argc, argv, ctrl );
170 <  if( ctrl.inputfile.empty() ||
171 <      ctrl.inputfile.empty() ) {
172 <    cerr << "usage: applySelection.exe <flags> " << endl;
173 <    cerr << "\tmandoatory flags : " << endl;
174 <    cerr << "\t--inputfile |  file containing a list of ntuples to run over" << endl;
175 <    cerr << "\t--outputfile | file to store  selected evet" << endl;
176 <    return 1;
177 <  }
170 >  if( ctrl.inputfiles.empty() &&ctrl.inputfile.empty() )
171 >    {
172 >      cerr << "usage: applySelection.exe <flags> " << endl;
173 >      cerr << "\tmandoatory flags : " << endl;
174 >      cerr << "\t--inputfiles |  file containing a list of ntuples to run over" << endl;
175 >      cerr << "\t--inputfile |  a file to run over" << endl;
176 >      cerr << "\t--outputfile | file to store  selected evet" << endl;
177 >      return 1;
178 >    }
179    ctrl.dump();
180  
181 +
182 +
183    //
184    // File I/O
185    //--------------------------------------------------------------------------------------------------------------
186    TChain * chain = new TChain("Events");
187 <  ifstream f(ctrl.inputfile.c_str());
187 >  TChain * hltchain = new TChain("HLT");
188 >  TChain * runchain = new TChain(Names::gkRunTreeName);
189 >
190    string fname;
191 <  while (f >> fname) {
192 <    if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines  
193 <    cout << "adding inputfile : " << fname.c_str() << endl;
194 <    chain->AddFile(fname.c_str());
191 >  unsigned total_unskimmed=0;
192 >  if( !ctrl.inputfiles.empty() ) {
193 >    ifstream f(ctrl.inputfiles.c_str());
194 >    while (f >> fname) {
195 >      if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
196 >      cout << "adding inputfile : " << fname.c_str() << endl;
197 >      entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
198 >      cout << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl;
199 >      total_unskimmed += entrymap[string(fname.c_str())];
200 >      chain->AddFile(fname.c_str());
201 >      hltchain->AddFile(fname.c_str());
202 >      runchain->AddFile(fname.c_str());
203 >    }
204 >  } else {
205 >    cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
206 >    unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str());
207 >    entrymap[string(ctrl.inputfile.c_str())] = unsk_ents;
208 >    cout << "unskimmed entries: " << unsk_ents << endl;
209 >    total_unskimmed += unsk_ents;
210 >    chain->AddFile(ctrl.inputfile.c_str());
211 >    hltchain->AddFile(ctrl.inputfile.c_str());
212 >    runchain->AddFile(ctrl.inputfile.c_str());
213    }
214 +  // // write the total number of unskimmed events that went into making this output file to a text file
215 +  writeEntries(ctrl,total_unskimmed);
216  
217 +  const char * ofname;
218 +  if( strcmp( ctrl.outputfile.c_str(), "") ) {
219 +    ofname = ctrl.outputfile.c_str();
220 +  } else {
221 +    ofname = "tmp.root";
222 +  }
223    // table of cross section values  
224 <  SimpleTable xstab("./data/xs.dat");
224 >  string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat"));
225 >  cout << "xspath: " << xspath.c_str() << endl;
226 >  SimpleTable xstab(xspath.c_str());
227 >
228 >
229  
230    //
231    // Setup
232    //--------------------------------------------------------------------------------------------------------------
233 <  TH1F * h_evt = new TH1F("hevt", "hevt", 2, 0, 2 );
234 <  TH1F * h_evtfail = new TH1F("hevtfail", "hevtfail", 1024, 0, 1024 );
235 <  TNtuple * passtuple = new TNtuple( "passtuple", "passtuple", "run:evt:lumi:channel:mZ1:mZ2:m4l:pt4l:w" );
236 <  initCiCSelection();
237 <  initRunLumiRangeMap();
233 >  Angles angles;
234 >  KinematicsStruct kine;
235 >  InfoStruct evtinfo;
236 >  WeightStruct weights;
237 >  GenInfoStruct geninfo;
238 >
239 >  AngleTuple nt( (const char*)ofname, (const char*)"zznt");
240 >  nt.makeAngleBranch(angles);
241 >  nt.makeKinematicsBranch(kine);
242 >  nt.makeInfoBranch(evtinfo);
243 >
244 >  
245 >  FOTuple foTree( nt.getFile(), (const char*)"FOtree");
246 >  foTree.makeInfoBranch(evtinfo);
247 >  foTree.makeFailedLeptonBranch(failingLeptons);
248 >  foTree.makePassedLeptonBranch(passingLeptons);
249 >
250 >  TH1F * h_wf11_hpt;
251 >  if(ctrl.mc) {
252 >    nt.makeWeightBranch(weights);
253 >    if(ctrl.fillGen ) nt.makeGenInfoBranch(geninfo);
254 >    //initEfficiencyWeights();
255 >    initPUWeights();
256 >
257 >    // Higgs only, pt reweighting
258 >    if( ctrl.mH <= 140 ) {
259 >      char wptname[256];
260 >      sprintf( wptname, "/data/blue/pharris/Flat/ntupler/root/weight_ptH_%i.root", ctrl.mH );
261 >      TFile * f_hpt = new TFile(wptname);
262 >      f_hpt->Print();
263 >      sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH);
264 >      h_wf11_hpt  = (TH1F*)(f_hpt->FindObjectAny(wptname));
265 >    }
266 >
267 >  } else {
268 >    initRunLumiRangeMap(ctrl);
269 >  }
270  
271 +  //  initMuonIDMVA();
272 +  initElectronIDMVAV1();
273 +  initTrigger();
274 +  ElectronMomentumCorrection electron_mom_corr;
275 +  electron_mom_corr.initialize_regression("../EGamma/EGammaAnalysisTools/data/eleEnergyRegWeights_V1.root");
276 +  TrigInfo ti;
277 +  initAnalysisTriggers(ti);
278  
279    //
280 <  // Loop
280 >  // Setup tree I/O
281    //--------------------------------------------------------------------------------------------------------------
103  
104  //
105  // Access samples and fill histograms
282    TFile *inputFile=0;
283    TTree *eventTree=0;  
284 <  
109 <  // Data structures to store info from TTrees
110 <  mithep::TEventInfo *info    = new mithep::TEventInfo();
111 <  TClonesArray *electronArr   = new TClonesArray("mithep::TElectron");
112 <  TClonesArray *muonArr       = new TClonesArray("mithep::TMuon");
113 <  
114 <
115 <  TBranch *infoBr;
116 <  TBranch *electronBr;
117 <  TBranch *muonBr;
118 <
119 < //   chain->SetBranchStatus("*",0); //disable all branches
120 < //   chain->SetBranchStatus("Info", 1);
121 < //   chain->SetBranchStatus("Muon", 1);
122 < //   chain->SetBranchStatus("Electron", 1);
123 <
124 <  chain->SetBranchAddress("Info",       &info);
125 <  chain->SetBranchAddress("Electron", &electronArr);
126 <  chain->SetBranchAddress("Muon", &muonArr);
284 >  string currentFile("");
285  
286 +  UInt_t fNMaxTriggers = 1024;
287 +  mithep::EventHeader                         *info          = new mithep::EventHeader();
288 +  mithep::Array<mithep::PFMet>                *metArr        = new mithep::Array<mithep::PFMet>();
289 +  mithep::Array<mithep::Electron>             *electronArr   = new mithep::Array<mithep::Electron>();
290 +  mithep::Array<mithep::Muon>                 *muonArr       = new mithep::Array<mithep::Muon>();
291 +  mithep::Array<mithep::Vertex>               *vtxArr        = new mithep::Array<mithep::Vertex>();
292 +  mithep::Array<mithep::PFCandidate>          *pfArr         = new mithep::Array<mithep::PFCandidate>();
293 +  mithep::Array<mithep::PileupInfo>           *puArr         = new mithep::Array<mithep::PileupInfo>();
294 +  mithep::Array<mithep::PileupEnergyDensity>  *puDArr        = new mithep::Array<mithep::PileupEnergyDensity>();
295 +  mithep::Array<mithep::Track>                *trkArr        = new mithep::Array<mithep::Track>();
296 +  mithep::Array<mithep::MCParticle>           *mcArr         = new mithep::Array<mithep::MCParticle>();
297 +  mithep::MCEventInfo                         *mcEvtInfo     = new mithep::MCEventInfo();
298 +  mithep::TriggerMask                         *trigMask      = new mithep::TriggerMask();
299 +  mithep::TriggerTable                        *hltTable      = new mithep::TriggerTable(fNMaxTriggers);
300 +  vector<string>                              *hltTableStrings  = new vector<string>();
301 +  vector<string>                              *hltLabelStrings  = new vector<string>();
302 +  mithep::Array<mithep::TriggerObject>        *hltObjArr     = new mithep::Array<mithep::TriggerObject>();
303 +  mithep::Array<mithep::TriggerObjectRel>     *hltRelsArr    = new mithep::Array<mithep::TriggerObjectRel>();
304 +  std::vector<std::string>                    *hltTab        = new vector<string>();
305 +  std::vector<std::string>                    *hltLab        = new vector<string>();
306 +  TriggerObjectsTable                         *fTrigObjs     = new TriggerObjectsTable(hltTable,fNMaxTriggers);
307 +
308 +  RunInfo                                     *runInfo       = new RunInfo();
309 +
310 +  TString fElectronName(Names::gkElectronBrn);
311 +  TString fMuonName(Names::gkMuonBrn);
312 +  TString fInfoName(Names::gkEvtHeaderBrn);
313 +  TString fPFMetName("PFMet");
314 +  TString fPrimVtxName(Names::gkPVBrn);
315 +  TString fPFCandidateName(Names::gkPFCandidatesBrn);
316 +  TString fPileupInfoName(Names::gkPileupInfoBrn);
317 +  TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
318 +  TString fTrackName(Names::gkTrackBrn);
319 +  TString fMCParticleName(Names::gkMCPartBrn);
320 +  TString fMCEvtInfoName(Names::gkMCEvtInfoBrn);
321 +  TString fTriggerMaskName(Names::gkHltBitBrn);
322 +  TString fTriggerTableName(Names::gkHltTableBrn);
323 +  TString fTriggerLabelName(Names::gkHltLabelBrn);
324 +  TString fTriggerObjectName(Names::gkHltObjBrn);
325 +  TString fTriggerObjectRelsName(Form("HLTObjectsRelation"));
326 +
327 + //   TString fHLTLabName(Names::gkHltLabelBrn);
328 + //   TString fHLTTabName(Names::gkHltTableBrn);
329 + //   TString fHLTTabNamePub(Form("%sFwk",fHLTTabName.Data()));
330 + //   TString fHLTLabNamePub(Form("%sFwk",fHLTLabName.Data()));
331 + //   TString fObjsNamePub(Form("%sFwk",fTriggerObjectName.Data()));
332  
333  
334 <  cout << "nEntries: " << chain->GetEntries() << endl;
335 <  for(UInt_t ientry=0; ientry<chain->GetEntries(); ientry++) {          
336 <    
337 <    chain->GetEntry(ientry);
338 <
339 <    // get event weight for this file                                                    
340 <    double xs=1,eventweight=1;                                                            
341 <    if(ctrl.mc) eventweight = xstab.Get(getname(chain).c_str()) / chain->GetEntries();    
342 <
343 < #ifdef THEIR_EVENTS
344 <    if( !( info->evtNum == 504867308  ||
345 <           info->evtNum == 368148849  ||
346 <           info->evtNum == 129514273  ||
347 <           info->evtNum == 286336207  ||
348 <           info->evtNum == 344708580  ||
349 <           info->evtNum == 30998576   ||
350 <           info->evtNum == 155679852  ||
351 <           info->evtNum == 394010457  ||
352 <           info->evtNum == 917379387  ||
353 <           info->evtNum == 78213037   ||
354 <           info->evtNum == 337493970  ||
355 <           info->evtNum == 1491724484 ||
356 <           info->evtNum == 480301165  ||
357 <           info->evtNum == 1038911933 ||
358 <           info->evtNum == 876658967  ||
359 <           info->evtNum == 966824024  ||
360 <           info->evtNum == 141954801  ||
361 <           info->evtNum == 160966858  ||
362 <           info->evtNum == 191231387  ||
363 <           info->evtNum == 66033190   ||
364 <           info->evtNum == 10347106   ||
365 <           info->evtNum == 107360878  ) ) continue;
366 < #endif
367 <
368 <    unsigned evtfail = fails_HZZ4L_selection(ctrl, info, electronArr, muonArr, eventweight, passtuple );    
369 <    h_evtfail->Fill( evtfail, eventweight );
370 <    cout << endl << endl;  
371 <          
372 <  } //end loop over data    
334 >  
335 >  chain->SetBranchAddress(fInfoName,        &info);
336 >  chain->SetBranchAddress(fPFMetName,       &metArr);
337 >  chain->SetBranchAddress(fElectronName,    &electronArr);
338 >  chain->SetBranchAddress(fMuonName,        &muonArr);
339 >  chain->SetBranchAddress(fPrimVtxName,     &vtxArr);
340 >  chain->SetBranchAddress(fPFCandidateName, &pfArr);
341 >  if( ctrl.mc ) {
342 >    chain->SetBranchAddress(fPileupInfoName,  &puArr);
343 >    chain->SetBranchAddress(fMCParticleName,  &mcArr);
344 >    chain->SetBranchAddress(fMCEvtInfoName,  &mcEvtInfo);
345 >  }
346 >  chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
347 >  chain->SetBranchAddress(fTrackName, &trkArr);
348 >  chain->SetBranchAddress(fTriggerMaskName, &trigMask);
349 >  chain->SetBranchAddress(fTriggerObjectName,  &hltObjArr);
350 >  chain->SetBranchAddress(fTriggerObjectRelsName,  &hltRelsArr);
351 >  //  chain->SetBranchAddress(fHLTTabNamePub,  &hltTab);
352 >  //  chain->SetBranchAddress(fHLTLabNamePub,  &hltLab);
353 >
354 >  cout << "hlttable: " << fTriggerTableName << endl;
355 >  hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
356 >  hltchain->SetBranchAddress(fTriggerLabelName, &hltLabelStrings);
357 >
358 >  runchain->SetBranchAddress(Names::gkRunInfoBrn, &runInfo);
359 >
360 >  mithep::Vertex              vtx;          // best primary vertex in the event
361 >
362 >  //  ginfo = NULL;
363 >  // if( ctrl.mc ) { chain->SetBranchAddress("Gen",        &ginfo);}
364 >
365 >  int count=0, pass=0;
366 >  float passcorr=0., passcorr_errup=0., passcorr_errdown=0.;
367 >  float denom[3]={0.,0.,0.};
368 >  float numer[3]={0.,0.,0.};
369 >  float numercorr[3]={0.,0.,0.};
370 >
371 >  // only 1 HLT table / file ???
372 >  hltchain->GetEntry(0);
373 >
374 >  int imax;
375 >  //-1 means process all of the events
376 >  if(ctrl.n_events_to_process != -2 && ctrl.n_events_to_process != -1){
377 >    if(ctrl.n_events_to_process > chain->GetEntries()){
378 >      cerr << "error: n_events_to_process is larger than chain->GetEntries()" << endl;
379 >      return 1;
380 >    }
381 >    imax = ctrl.n_events_to_process;
382 >  }
383 >  else
384 >    imax = chain->GetEntries();
385  
386 +  cout << "number of events to process: " << imax << endl;
387  
388 +  //
389 +  // Loop !!!!!!!!!
390 +  //--------------------------------------------------------------------------------------------------------------
391 +  int lastHltEntry=-2;
392 +  for(UInt_t ientry=0; ientry<imax; ientry++)
393 +    {
394 +      chain->GetEntry(ientry);
395 +      if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
396 +
397 +      if( ctrl.debug ) {
398 +        cout << "-----------------------------------------------------------------" << endl;
399 +        cout << "-----------------------------------------------------------------" << endl;
400 +        cout << "Run: " << info->RunNum()
401 +             << "\tEvt: " << info->EvtNum()
402 +             << "\tLumi: " << info->LumiSec()
403 +             << endl;
404 +        cerr << "Run: " << info->RunNum()
405 +             << "\tEvt: " << info->EvtNum()
406 +             << "\tLumi: " << info->LumiSec()
407 +             << endl;
408 +        cout << "-----------------------------------------------------------------" << endl;
409 +      }
410 +
411 +      runchain->GetEvent(info->RunEntry());
412 +      hltchain->GetEntry(runInfo->HltEntry());
413 +      hltTable->Clear();
414 +      fillTriggerNames(hltTable, hltTableStrings );
415 +      if(ctrl.debug && (lastHltEntry != runInfo->HltEntry())) hltTable->Print();
416 +      lastHltEntry = runInfo->HltEntry();
417 +      fillTriggerBits( hltTable, trigMask, triggerBits );
418 +      setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs );
419 +      // printTriggerObjs( hltTable, fTrigObjs);
420 +      
421 +      string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
422 +      if(ctrl.debug) cout << "era is " << ctrl.era << endl;
423 +      if( ctrl.era == 0  ) {
424 +        setEra( fname, ctrl );
425 +        if(ctrl.debug) cout << "era is now " << ctrl.era << endl;
426 +      }
427 +
428 +      //
429 +      // pfNoPU
430 +      //
431 +      //mithep::Array<PFCandidate> pfNoPileUp;
432 +      PFnoPUflag.clear();
433 +      int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
434 +      assert(pfnopu_size == pfArr->GetEntries());
435 +
436 +      //
437 +      // trigger
438 +      //
439 +      if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
440 +        currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
441 +      }
442 +      if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
443 +
444 +      //
445 +      // data/MC
446 +      //
447 +      if(ctrl.mc) {
448 +        //
449 +        // gen info
450 +        //
451 +        if( ctrl.fillGen )
452 +          fillGenInfo( mcArr, mcEvtInfo, geninfo, ESampleType::kHZZ, ctrl);
453 +
454 +        //
455 +        // xsec & PU weights
456 +        //
457 +        weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
458 +        cout << "xsec weight: " << weights.w << endl;
459 +
460 +        unsigned npu = getNPU(puArr, 0);
461 +        weights.npu  = npu;
462 +        weights.npuw = getPUWeight(ctrl.era,npu);
463 +        cerr << "weights.npuw: " <<  weights.npuw << endl;
464 +
465 +        //
466 +        // pt reweighting for Higgs < 140, F11
467 +        //
468 +        if( ctrl.fillGen ) {
469 +          if( (fname.find("f11-h115zz4l") != string::npos) ||
470 +              (fname.find("f11-h120zz4l") != string::npos) ||
471 +              (fname.find("f11-h130zz4l") != string::npos)  ) {
472 +            weights.w *= h_wf11_hpt->GetBinContent(h_wf11_hpt->FindBin(geninfo.pt_zz));
473 +          }
474 +        }
475 +
476 +        // trigger
477 +        passes_HLT_MC = true; // passed to apply as extern global, just for sync
478 +        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) {
479 +          passes_HLT_MC = false;
480 +        }
481 +
482 +      } else {
483 +        //
484 +        // JSON
485 +        //
486 +        if(!(ctrl.noJSON) ) {
487 +          RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
488 +          if( !(rlrm.HasRunLumi(rl)) )  {
489 +            if( ctrl.debug ) cout << "fails JSON" << endl;
490 +            continue;
491 +          }
492 +        }
493 +        
494 +        // trigger
495 +        passes_HLT = true;
496 +        //if( !passHLT(ctrl, triggerBits,ti,info->RunNum()) ) {
497 +        //  passes_HLT = false;
498 +        //}
499 +
500 +      }
501 +
502 +      //
503 +      // lepton/kinematic selection ...
504 +      //
505 +      failingLeptons.clear();
506 +      passingLeptons.clear();
507 +      EventData ret4l =
508 +
509 +
510 +        // reference
511 +        apply_HZZ4L_reference_selection(ctrl, info,
512 +                                        vtxArr,
513 +                                        pfArr,
514 +                                        puDArr,
515 +                                        electronArr,
516 +                                        &electronReferencePreSelection,
517 +                                        &electronReferenceIDMVASelectionV1,
518 +                                        &electronReferenceIsoSelection,
519 +                                        muonArr,
520 +                                        &muonReferencePreSelection,
521 +                                        &muonIDPFSelection,
522 +                                        &muonReferenceIsoSelection);
523 +      
524 +      if( ctrl.debug ) cout << endl;
525 +
526 +
527 +      int Z1type=0, Z2type=0;
528 +      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
529 +        if( abs(ret4l.Z1leptons[0].type) == 11  ) Z1type = 11;
530 +        if( abs(ret4l.Z1leptons[0].type) == 13  ) Z1type = 13;
531 +      }  
532 +      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
533 +        if( abs(ret4l.Z2leptons[0].type) == 11  ) Z2type = 11;
534 +        if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
535 +      }  
536 +      
537 +      if( ret4l.status.pass() ) {
538 +        fillAngles(ret4l,angles);
539 +        fillKinematics(ret4l,kine);
540 +        fillMassErrors(ret4l,muonArr,electronArr,kine);
541 +        TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
542 +        fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0);
543 +        if( ctrl.mc) {
544 +          //setEffiencyWeights(ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights);
545 +          if(ctrl.debug)
546 +            cout << "w: " << weights.w << "\t"
547 +                 << "npuw: " << weights.npuw << "\t"
548 +                 << "won: " << weights.won << "\t"
549 +                 << "woff: " << weights.woff << endl;
550 +        }
551 +        
552 +
553 +        nt.Fill();
554 +        
555 +        cerr  << "PASS:: "
556 +              << "\trun: " << evtinfo.run
557 +              << "\tevt: " << evtinfo.evt
558 +              << "\tlumi: " << evtinfo.lumi
559 +              << "\tchannel: " << kine.channel
560 +              << "\tm4l: " << kine.m4l
561 +              << "\tmZ1: " << kine.mZ1
562 +              << "\tmZ2: " << kine.mZ2
563 +              << endl;
564 +        pass++;
565 +        //      if( pass > 3 ) break;
566 +
567 +      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) &&
568 +                 ret4l.status.selectionBits.to_ulong() < (1UL<<PASS_4L)) { // save for fakes ...
569 +        if(ctrl.debug) {
570 +          cout << "failingLeptons : " << failingLeptons.size() << endl;
571 +          for( int f=0; f<failingLeptons.size(); f++ ) {
572 +            SimpleLepton  l = failingLeptons[f];
573 +            cout << "f: " << f << "\t"
574 +                 << "type: " << l.type << "\t"
575 +                 << "pT: " << l.vec.Pt()  << "\t"
576 +                 << "eta: " << l.vec.Eta()
577 +                 << endl;
578 +          }
579 +        }
580 +        TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
581 +        fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0);
582 +        foTree.Fill();
583 +      } else {
584 +        if(ctrl.debug)
585 +          cout << "failing with some other code : " << ret4l.status.selectionBits << endl;
586 +      }
587 +      if(ctrl.debug)
588 +        cout << "passes HLT: " << passes_HLT << endl;
589 +    }
590  
591 <  delete info;
592 <  delete electronArr;
593 <  delete muonArr;
591 >  
592 >  foTree.getFile()->cd();
593 >  foTree.getTree()->Write();
594 >  nt.WriteClose();
595 >
596 >  if(ctrl.debug)
597 >    cout << endl << endl;
598 >  for( int i=0; i<cutvec.size(); i++ ) {
599 >    cout << "cut: " << i << "\t"
600 >         << "pass: " << cutvec[i];
601 >
602 >    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
603 >      cout << "\t2e: " << zcutvec[0][i]
604 >           << "\t2m: " << zcutvec[1][i];
605 >
606 >    if( i>PASS_ZCANDIDATE )
607 >      cout << "\t4e: " << zzcutvec[0][i]
608 >           << "\t4m: " << zzcutvec[1][i]
609 >           << "\t2e2m: " << zzcutvec[2][i];
610  
611 +    cout << "\t" << cutstrs[i] << endl;
612  
613 +    cout << endl;
614 +  }
615  
616 <  //--------------------------------------------------------------------------------------------------------------
617 <  // Save Histograms;
618 <  //==============================================================================================================
619 <  const char * ofname;
620 <  if( strcmp( ctrl.outputfile.c_str(), "") ) {
621 <    ofname = ctrl.outputfile.c_str();
622 <  } else {
623 <    ofname = "tmp.root";
616 >  for(unsigned icut=0; icut<cuts.size(); icut++) {
617 >    cout << setw(20) << cuts[icut] << "\t"
618 >         << setw(9) << (*(counts[cuts[icut]]))["all"]
619 >         << "  ("
620 >         << setw(9) << (*(counts[cuts[icut]]))["4e"]
621 >         << setw(9) << (*(counts[cuts[icut]]))["4m"]
622 >         << setw(9) << (*(counts[cuts[icut]]))["2e2m"]
623 >         << ")" << endl;
624    }
625  
188  TFile *file = new TFile(ofname, "RECREATE");
189  h_evt->Write();
190  h_evtfail->Write();
191  passtuple->Write();
192  file->Close();
193  delete file;
626  
195  cerr << "done!" << endl;
627   }
628  
629  
630 <
630 > //----------------------------------------------------------------------------
631 > void initRunLumiRangeMap(ControlFlags &ctrl)
632 > //----------------------------------------------------------------------------
633 > {
634 >  /*
635 >  rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
636 >  //  rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
637 >  rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
638 >  rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));  
639 >  rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));  
640 >  // r11b
641 >  rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));  
642 >  */
643 >
644 >  // 2012 only for now ...
645 >  std::string jsonFile;
646 >  if(ctrl.jsonFile=="")
647 >    jsonFile = "./data/Cert_190456-194479_8TeV_PromptReco_Collisions12_JSON.txt";
648 >  else
649 >    jsonFile = ctrl.jsonFile;
650 >  rlrm.AddJSONFile(jsonFile);  
651 > };

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines