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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines