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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines