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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines