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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines