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.1 by khahn, Thu Sep 8 13:33:18 2011 UTC vs.
Revision 1.21 by khahn, Sat May 12 03:00:15 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 "EWKAnaDefs.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 "TriggerMask.h"
41 > #include "TriggerTable.h"
42 > #include "Names.h"
43 > #include "BaseMod.h"
44  
45   //
46 < // utility headers
46 > // our headers
47   //
48   #include "ParseArgs.h"
49 < #include "Selection.h"
50 < #include "HZZCiCElectronSelection.h"
49 > #include "MuonSelection.h"
50 > #include "ElectronSelection.h"
51 > #include "IsolationSelection.h"
52 >
53 > //#include "Selection.h"
54 > //#include "ReferenceSelection.h"
55 > #include "ReferenceSelection2.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 "GlobalDataAndFuncs.h"
65 > #include "RunLumiRangeMap.h"
66 >
67 > #include "AngleTuple.h"
68 > #include "FOTuple.h"
69 >
70 > #include "SampleWeight.h"
71 > #include "EfficiencyWeightsInterface.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 >
95 > //
96 > // prototypes
97 > //----------------------------------------------------------------------------
98 > bool setPV(ControlFlags,const mithep::Array<mithep::Vertex>*, mithep::Vertex& );
99 > void initPUWeights();
100 > double getPUWeight(unsigned npu);
101 > void setEffiencyWeights(EventData&, WeightStruct& );
102 > void initRunLumiRangeMap();
103 > void initEvtRhoMap(map<unsigned,float> &);
104 > //----------------------------------------------------------------------------
105  
49 //#define THEIR_EVENTS
106  
107 < //=== MAIN =================================================================================================
107 > //
108 > // MAIN
109 > //----------------------------------------------------------------------------
110   int main(int argc, char** argv)
111 + //----------------------------------------------------------------------------
112   {
113 <  
113 >  cutstrs.push_back(string("skim0"));              //0
114 >  cutstrs.push_back(string("skim1"));              //1
115 >  cutstrs.push_back(string("trigger"));            //2
116 >  // -------------------------------------------------
117 >  cutstrs.push_back(string("Z candidate"));        //3
118 >  cutstrs.push_back(string("good Z1"));            //4
119 >  // -------------------------------------------------
120 >  cutstrs.push_back(string("4l"));                 //5  
121 >  cutstrs.push_back(string("ZZ candidate"));       //6
122 >  cutstrs.push_back(string("good Z2"));            //7
123 >  cutstrs.push_back(string("ZZ 20/10"));           //8
124 >  cutstrs.push_back(string("resonance"));          //9
125 >  cutstrs.push_back(string("m4l>70"));             //10
126 >  cutstrs.push_back(string("m4l>100"));            //11
127 >
128 >
129 >
130 >
131 >  string cmsswpath(CMSSW_BASE);
132 >  cmsswpath.append("/src");
133 >  std::bitset<1024> triggerBits;
134    vector<vector<string> > inputFiles;
135    inputFiles.push_back(vector<string>());
136 +  map<string,unsigned> entrymap; // number of unskimmed entries in each file
137 +  for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0);
138 +  for( int i=0; i<2; i++ )  {
139 +    zcutvec.push_back(vector<unsigned>());
140 +    for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0);
141 +  }
142 +  for( int i=0; i<3; i++ )  {
143 +    zzcutvec.push_back(vector<unsigned>());
144 +    for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
145 +  }
146 +
147  
148    //
149    // args
150    //--------------------------------------------------------------------------------------------------------------
151    ControlFlags ctrl;
152    parse_args( argc, argv, ctrl );
153 <  if( ctrl.inputfile.empty() ||
154 <      ctrl.inputfile.empty() ) {
155 <    cerr << "usage: applySelection.exe <flags> " << endl;
156 <    cerr << "\tmandoatory flags : " << endl;
157 <    cerr << "\t--inputfile |  file containing a list of ntuples to run over" << endl;
158 <    cerr << "\t--outputfile | file to store  selected evet" << endl;
159 <    return 1;
160 <  }
153 >  if( ctrl.inputfiles.empty() &&ctrl.inputfile.empty() )
154 >    {
155 >      cerr << "usage: applySelection.exe <flags> " << endl;
156 >      cerr << "\tmandoatory flags : " << endl;
157 >      cerr << "\t--inputfiles |  file containing a list of ntuples to run over" << endl;
158 >      cerr << "\t--inputfile |  a file to run over" << endl;
159 >      cerr << "\t--outputfile | file to store  selected evet" << endl;
160 >      return 1;
161 >    }
162    ctrl.dump();
163  
164 +
165 +
166    //
167    // File I/O
168    //--------------------------------------------------------------------------------------------------------------
169    TChain * chain = new TChain("Events");
170 <  ifstream f(ctrl.inputfile.c_str());
170 >  TChain * hltchain = new TChain("HLT");
171 >
172    string fname;
173 <  while (f >> fname) {
174 <    if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines  
175 <    cout << "adding inputfile : " << fname.c_str() << endl;
176 <    chain->AddFile(fname.c_str());
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 >      chain->AddFile(fname.c_str());
181 >      hltchain->AddFile(fname.c_str());
182 >    }
183 >  } else {
184 >    cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
185 >    unsigned tmpent = unskimmedEntries(ctrl.inputfile.c_str());
186 >    cout << "tmpent: " << tmpent << endl;
187 >    entrymap[string(ctrl.inputfile.c_str())] = unskimmedEntries(ctrl.inputfile.c_str());
188 >    cout << "unskimmed entries: " << entrymap[string(ctrl.inputfile.c_str())] << endl;
189 >    chain->AddFile(ctrl.inputfile.c_str());
190 >    hltchain->AddFile(ctrl.inputfile.c_str());
191 >  }
192 >
193 >  const char * ofname;
194 >  if( strcmp( ctrl.outputfile.c_str(), "") ) {
195 >    ofname = ctrl.outputfile.c_str();
196 >  } else {
197 >    ofname = "tmp.root";
198    }
199 +  // table of cross section values  
200 +  string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat"));
201 +  cout << "xspath: " << xspath.c_str() << endl;
202 +  SimpleTable xstab(xspath.c_str());
203 +
204  
205    //
206    // Setup
207    //--------------------------------------------------------------------------------------------------------------
208 <  TH1F * h_evt = new TH1F("hevt", "hevt", 2, 0, 2 );
209 <  TH1F * h_evtfail = new TH1F("hevtfail", "hevtfail", 100, 0, 100 );
210 <  TNtuple * passtuple = new TNtuple( "passtuple", "passtuple", "run:evt:lumi:channel:mZ1:mZ2:m4l:pt4l:w" );
211 <  initCiCSelection();
212 <  initRunLumiRangeMap();
208 >  Angles angles;
209 >  KinematicsStruct kinematics;
210 >  InfoStruct evtinfo;
211 >  WeightStruct weights;
212 >  //  GenInfoStruct geninfo;
213 >
214 >  AngleTuple nt( (const char*)ofname, (const char*)"zznt");
215 >  nt.makeAngleBranch(angles);
216 >  nt.makeKinematicsBranch(kinematics);
217 >  nt.makeInfoBranch(evtinfo);
218 >
219 >  FOTuple foTree( nt.getFile(), (const char*)"FOtree");
220 >  foTree.makeFailedLeptonBranch(failingLeptons);
221 >  foTree.makeZLeptonBranch(passingLeptons);
222 >
223 >  TH1F * h_w_hpt;
224 >  if(ctrl.mc) {
225 >    nt.makeWeightBranch(weights);
226 >    //    nt.makeGenInfoBranch(geninfo);
227 >    initEfficiencyWeights();
228 >    initPUWeights();
229 >    /*
230 >    // Higgs only, pt reweighting
231 >    if( ctrl.mH <= 140 ) {
232 >      char wptname[256];
233 >      sprintf( wptname, "/data/blue/pharris/Flat/ntupler/root/weight_ptH_%i.root", ctrl.mH );
234 >      TFile * f_hpt = new TFile(wptname);
235 >      f_hpt->Print();
236 >      sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH);
237 >      h_w_hpt  = (TH1F*)(f_hpt->FindObjectAny(wptname));
238 >      h_w_hpt->Print();
239 >    }
240 >    */
241 >  } else {
242 >    initRunLumiRangeMap();
243 >  }
244  
245 +  //  initMuonIDMVA();
246 +  initMuonIsoMVA();
247 +  initElectronIDMVA();
248 +  initElectronIsoMVA();
249 +  initTrigger();
250 +
251 +  // hack
252 +  initEvtRhoMap(evtrhoMap);
253  
95  //
96  // Loop
97  //--------------------------------------------------------------------------------------------------------------
254    
255    //
256 <  // Access samples and fill histograms
256 >  // Setup tree I/O
257 >  //--------------------------------------------------------------------------------------------------------------
258    TFile *inputFile=0;
259    TTree *eventTree=0;  
260 <  
104 <  // Data structures to store info from TTrees
105 <  mithep::TEventInfo *info    = new mithep::TEventInfo();
106 <  TClonesArray *electronArr   = new TClonesArray("mithep::TElectron");
107 <  TClonesArray *muonArr       = new TClonesArray("mithep::TMuon");
108 <  
260 >  string currentFile("");
261  
262 <  TBranch *infoBr;
263 <  TBranch *electronBr;
264 <  TBranch *muonBr;
265 <
266 < //   chain->SetBranchStatus("*",0); //disable all branches
267 < //   chain->SetBranchStatus("Info", 1);
268 < //   chain->SetBranchStatus("Muon", 1);
269 < //   chain->SetBranchStatus("Electron", 1);
262 >  mithep::EventHeader *info    = new mithep::EventHeader();
263 >  //  mithep::TGenInfo    *ginfo  = new mithep::TGenInfo();
264 >  mithep::Array<mithep::Electron>             *electronArr   = new mithep::Array<mithep::Electron>();
265 >  mithep::Array<mithep::Muon>                 *muonArr       = new mithep::Array<mithep::Muon>();
266 >  mithep::Array<mithep::Vertex>               *vtxArr        = new mithep::Array<mithep::Vertex>();
267 >  mithep::Array<mithep::PFCandidate>          *pfArr         = new mithep::Array<mithep::PFCandidate>();
268 >  mithep::Array<mithep::PileupInfo>           *puArr         = new mithep::Array<mithep::PileupInfo>();
269 >  mithep::Array<mithep::PileupEnergyDensity>  *puDArr        = new mithep::Array<mithep::PileupEnergyDensity>();
270 >  mithep::Array<mithep::Track>                *trkArr        = new mithep::Array<mithep::Track>();
271 >  mithep::TriggerMask                         *trigMask      = new mithep::TriggerMask();
272 >  mithep::TriggerTable                        *hltTable      = new mithep::TriggerTable();
273 >  vector<string>                              *hltTableStrings  = new vector<string>();
274 >
275 >  TString fElectronName(Names::gkElectronBrn);
276 >  TString fMuonName(Names::gkMuonBrn);
277 >  TString fInfoName(Names::gkEvtHeaderBrn);
278 >  TString fPrimVtxName(Names::gkPVBrn);
279 >  TString fPFCandidateName(Names::gkPFCandidatesBrn);
280 >  TString fPileupInfoName(Names::gkPileupInfoBrn);
281 >  TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
282 >  TString fTrackName(Names::gkTrackBrn);
283 >  TString fTriggerMaskName(Names::gkHltBitBrn);
284 >  TString fTriggerTableName(Names::gkHltTableBrn);
285 >  
286 >  chain->SetBranchAddress(fInfoName,        &info);
287 >  chain->SetBranchAddress(fElectronName,    &electronArr);
288 >  chain->SetBranchAddress(fMuonName,        &muonArr);
289 >  chain->SetBranchAddress(fPrimVtxName,     &vtxArr);
290 >  chain->SetBranchAddress(fPFCandidateName, &pfArr);
291 >  if( ctrl.mc ) chain->SetBranchAddress(fPileupInfoName,  &puArr);
292 >  chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
293 >  chain->SetBranchAddress(fTrackName, &trkArr);
294 >  chain->SetBranchAddress(fTriggerMaskName, &trigMask);
295 >  cout << "hlttable: " << fTriggerTableName << endl;
296 >  hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
297 >
298 >  mithep::Vertex              vtx;          // best primary vertex in the event
299 >
300 >  //  ginfo = NULL;
301 >  // if( ctrl.mc ) { chain->SetBranchAddress("Gen",        &ginfo);}
302 >
303 >  int count=0, pass=0;
304 >  float passcorr=0., passcorr_errup=0., passcorr_errdown=0.;
305 >  float denom[3]={0.,0.,0.};
306 >  float numer[3]={0.,0.,0.};
307 >  float numercorr[3]={0.,0.,0.};
308 >
309 >  // only 1 HLT table / file ???
310 >  hltchain->GetEntry(0);
311 >  cerr << "here... " << endl;
312  
313 <  chain->SetBranchAddress("Info",       &info);
314 <  chain->SetBranchAddress("Electron", &electronArr);
121 <  chain->SetBranchAddress("Muon", &muonArr);
313 >  int imax = chain->GetEntries();
314 >  cout << "nEntries: " << imax << endl;
315  
316  
317 +  //
318 +  // Loop !!!!!!!!!
319 +  //--------------------------------------------------------------------------------------------------------------
320 +  for(UInt_t ientry=0; ientry<imax; ientry++)
321 +    {
322 +      chain->GetEntry(ientry);
323 +      if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
324 +      setPV( ctrl, vtxArr, vtx);
325 +
326 +      cout << "origrho: " << puDArr->At(0)->Rho()
327 +           << "\torigrholoweta: " << puDArr->At(0)->RhoLowEta()
328 +           << endl;
329 +
330 +
331 +      //
332 +      // data/MC
333 +      //
334 +      if(ctrl.mc) {
335 +        //
336 +        // xsec & PU weights
337 +        //
338 +        //      weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
339 +        int npu = -1;
340 +        for(int i=0;i<puArr->GetEntries();i++) {
341 +          if(puArr->At(i)->GetBunchCrossing() == 0)
342 +            npu = puArr->At(i)->GetPU_NumInteractions();
343 +        }
344 +        assert(npu>=0);
345 +        evtinfo.npu;
346 +        weights.npuw = getPUWeight(evtinfo.npu);
347 +        //      cout << "weight: " << weights.w << endl;
348 +        //
349 +        // trigger
350 +        //
351 +        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
352 +          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
353 +          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
354 +          hltchain->GetEntry(0);
355 +          hltTable->Clear();
356 +          fillTriggerBits(hltTable, hltTableStrings );
357 +        }
358 +        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
359 +        fillTriggerBits( hltTable, trigMask, triggerBits );
360 +        passes_HLT_MC = true; // passed to apply as extern global, just for sync
361 +        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum() ) ) {
362 +          passes_HLT_MC = false;
363 +        }
364 +      } else {
365 +        //
366 +        // JSON
367 +        //
368 +        /*
369 +        RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
370 +        if( !(rlrm.HasRunLumi(rl)) )  {
371 +          if( ctrl.debug ) cout << "\tfails JSON" << endl;
372 +          continue;
373 +        }
374 +        */
375 +        //
376 +        // trigger
377 +        //
378 +        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
379 +          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
380 +          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
381 +          hltchain->GetEntry(0);
382 +          hltTable->Clear();
383 +          fillTriggerBits(hltTable, hltTableStrings );
384 +        }
385 +        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
386 +        /*
387 +        fillTriggerBits( hltTable, trigMask, triggerBits );
388 +        if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
389 +          if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
390 +          continue;
391 +        }
392 +        */
393 +      }
394 +
395 +      //
396 +      // lepton/kinematic selection ...
397 +      //
398 +      failingLeptons.clear();
399 +      passingLeptons.clear();
400 +      EventData ret4l =
401 +
402 +        /*
403 +        apply_HZZ4L_reference2_selection(ctrl, info,
404 +                                         vtx,
405 +                                         pfArr,
406 +                                         puDArr,
407 +                                         electronArr,
408 +                                         &electronReferencePreSelection,
409 +                                         &electronReferenceIDMVASelection,
410 +                                         &electronReferenceIsoSelection,
411 +                                         muonArr,
412 +                                         &muonReferencePreSelection,
413 +                                         &muonIDPFSelection,
414 +                                         &muonReferenceIsoSelection);
415 +        */
416 +        apply_HZZ4L_reference2_selection(ctrl, info,
417 +                              vtx,
418 +                              pfArr,
419 +                              puDArr,
420 +                              electronArr,
421 +                              &electronReferencePreSelection,
422 +                              &electronReferenceIDMVASelection,
423 +                              &electronIsoMVASelection,
424 +                              muonArr,
425 +                              &muonReferencePreSelection,
426 +                              &muonIDPFSelection,
427 +                              &muonIsoMVASelection);
428 +
429 +
430 +
431 +      if( ctrl.debug ) cout << endl;
432 +
433 +
434 +      int Z1type=0, Z2type=0;
435 +      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
436 +        if( abs(ret4l.Z1leptons[0].type) == 11  ) Z1type = 11;
437 +        if( abs(ret4l.Z1leptons[0].type) == 13  ) Z1type = 13;
438 +      }  
439 +      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
440 +        if( abs(ret4l.Z2leptons[0].type) == 11  ) Z2type = 11;
441 +        if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
442 +      }  
443 +      
444 +      cout  << "bits: " << ret4l.status.selectionBits  << "\t"
445 +            << "Z1: " << Z1type << "\t"
446 +            << "Z2: " << Z2type << endl;
447 +      cout << endl;
448 +                      
449 +      
450 +      if( ret4l.status.pass() ) {
451 +        fillAngles(ret4l,angles);
452 +        fillKinematics(ret4l,kinematics);
453 +        fillEventInfo(info,evtinfo);
454 +        if( ctrl.mc) {
455 +        // fillGenInfo(ginfo,geninfo);
456 +          setEffiencyWeights(ret4l, weights);
457 +           if(ctrl.debug)
458 +             cout << "w: " << weights.w << "\t"
459 +                  << "won: " << weights.won << "\t"
460 +                  << "woff: " << weights.woff << endl;
461 +        }
462 +        
463 +        /*
464 +        // only for Higgs < 140
465 +        geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz));
466 +        angles.bdt = reader->EvaluateMVA("BDTG");
467 +        */
468 +        nt.Fill();
469 +        
470 +        cerr  << "PASS:: "
471 +              << "\trun: " << evtinfo.run
472 +              << "\tevt: " << evtinfo.evt
473 +              << "\tlumi: " << evtinfo.lumi
474 +              << "\tcostheta1: " << angles.costheta1
475 +              << "\tcostheta2: " << angles.costheta2
476 +              << "\tcostheta*: " << angles.costhetastar
477 +              << "\tbdt: " << angles.bdt
478 +              << endl;
479 +        pass++;
480 +        //      if( pass > 3 ) break;
481 +
482 +      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) ) { // save for fakes ...
483 +        //      if(ctrl.debug) {
484 +          cout << "failingLeptons : " << failingLeptons.size() << endl;
485 +          for( int f=0; f<failingLeptons.size(); f++ ) {
486 +            SimpleLepton  l = failingLeptons[f];
487 +            cout << "f: " << f << "\t"
488 +                 << "type: " << l.type << "\t"
489 +                 << "pT: " << l.vec.Pt()  << "\t"
490 +                 << "eta: " << l.vec.Eta()
491 +                 << endl;
492 +            //    }
493 +        }
494 +        foTree.Fill();
495 +      }
496 +    }  
497  
498 <  cout << "nEntries: " << chain->GetEntries() << endl;
499 <  for(UInt_t ientry=0; ientry<chain->GetEntries(); ientry++) {          
500 <    
501 <    chain->GetEntry(ientry);
498 >  
499 >  foTree.getFile()->cd();
500 >  foTree.getTree()->Write();
501 >  nt.WriteClose();
502 >
503 >  cout << endl;
504 >  cout << endl;
505 >  for( int i=0; i<cutvec.size(); i++ ) {
506 >    cout << "cut: " << i << "\t"
507 >         << "pass: " << cutvec[i];
508 >
509 >    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
510 >      cout << "\t2e: " << zcutvec[0][i]
511 >           << "\t2m: " << zcutvec[1][i];
512 >
513 >    if( i>PASS_ZCANDIDATE )
514 >      cout << "\t4e: " << zzcutvec[0][i]
515 >           << "\t4m: " << zzcutvec[1][i]
516 >           << "\t2e2m: " << zzcutvec[2][i];
517  
518 < #ifdef THEIR_EVENTS
131 <    if( !( info->evtNum == 504867308  ||
132 <           info->evtNum == 368148849  ||
133 <           info->evtNum == 129514273  ||
134 <           info->evtNum == 286336207  ||
135 <           info->evtNum == 344708580  ||
136 <           info->evtNum == 30998576   ||
137 <           info->evtNum == 155679852  ||
138 <           info->evtNum == 394010457  ||
139 <           info->evtNum == 917379387  ||
140 <           info->evtNum == 78213037   ||
141 <           info->evtNum == 337493970  ||
142 <           info->evtNum == 1491724484 ||
143 <           info->evtNum == 480301165  ||
144 <           info->evtNum == 1038911933 ||
145 <           info->evtNum == 876658967  ||
146 <           info->evtNum == 966824024  ||
147 <           info->evtNum == 141954801  ||
148 <           info->evtNum == 160966858  ||
149 <           info->evtNum == 191231387  ||
150 <           info->evtNum == 66033190   ||
151 <           info->evtNum == 10347106   ||
152 <           info->evtNum == 107360878  ) ) continue;
153 < #endif
518 >    cout << "\t" << cutstrs[i] << endl;
519  
520 <    unsigned evtfail = fails_HZZ4L_selection(ctrl, info, electronArr, muonArr, passtuple );    
521 <    double eventweight = info->eventweight;
157 <    h_evtfail->Fill( evtfail, eventweight );
158 <    cout << endl << endl;  
159 <          
160 <  } //end loop over data    
520 >    cout << endl;
521 >  }
522  
523 + }
524  
525 + //----------------------------------------------------------------------------
526 + //
527 + // Get primary vertices
528 + // Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW)
529 + // NOTE: if no PV is found from fitting tracks, the beamspot is used
530 + //
531 + //----------------------------------------------------------------------------
532 + bool setPV(ControlFlags ctrl,
533 +           const mithep::Array<mithep::Vertex> * vtxArr,
534 +           mithep::Vertex & vtx)
535 + //----------------------------------------------------------------------------
536 + {
537 +  const Vertex *bestPV = 0;
538 +  float best_sumpt=-1;
539 +
540 +  // good PV requirements
541 +  const UInt_t   fMinNTracksFit = 0;
542 +  const Double_t fMinNdof       = 4;
543 +  const Double_t fMaxAbsZ       = 24;
544 +  const Double_t fMaxRho        = 2;
545 +  
546 +  for(int i=0; i<vtxArr->GetEntries(); ++i) {
547 +    const Vertex *pv = (Vertex*)(vtxArr->At(i));
548 +    if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl;
549 +    
550 +    // Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used
551 +    //  if(!pv->IsValid()) continue;
552 +    if(pv->NTracksFit()       < fMinNTracksFit)       continue;
553 +    if(pv->Ndof()                 < fMinNdof)         continue;
554 +    if(fabs(pv->Z()) > fMaxAbsZ)                      continue;
555 +    if(pv->Position().Rho()   > fMaxRho)              continue;    
556 +    
557 +    // take the first ...
558 +    bestPV = pv;
559 +    break;
560 +
561 +    // this never reached ...    
562 +    float tmp_sumpt=0;
563 +    for( int t=0; t<pv->NTracks(); t++ )
564 +      tmp_sumpt += pv->Trk(t)->Pt();
565 +    
566 +    if( tmp_sumpt > best_sumpt  ) {
567 +      bestPV = pv;
568 +      best_sumpt = tmp_sumpt;
569 +      if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
570 +    }
571 +  }
572 +  
573 +  if(!bestPV) bestPV = vtxArr->At(0);
574 +  vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z());
575 +  vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr());
576 +  return true;
577 + };
578  
164  delete info;
165  delete electronArr;
166  delete muonArr;
579  
580  
581 + //----------------------------------------------------------------------------
582 + void setEffiencyWeights(EventData & evtdat, WeightStruct & weights )
583 + //----------------------------------------------------------------------------
584 + {
585 +  vector<SimpleLepton> lepvec = evtdat.Z1leptons;
586 +  lepvec.insert(lepvec.end(), evtdat.Z2leptons.begin(), evtdat.Z2leptons.end());
587 +  double w_offline=-1, werr_offline=0;
588 +  double w_online=-1, werr_online=0;
589 +  
590 +  vector< pair <double,double> > wlegs; // pair here is eff & err
591 +  vector< pair <float,float> > mvec;  // pair here is eta & pt
592  
593 <  //--------------------------------------------------------------------------------------------------------------
594 <  // Save Histograms;
595 <  //==============================================================================================================
596 <  const char * ofname;
597 <  if( strcmp( ctrl.outputfile.c_str(), "") ) {
598 <    ofname = ctrl.outputfile.c_str();
599 <  } else {
600 <    ofname = "tmp.root";
593 >  //      vector< pair <float,float> > evec;  // pair here is eta & pt
594 >  // now deal with medium vs loose
595 >  vector< pair< bool, pair <float,float> > > evec;  // pair here is eta & pt
596 >  
597 >  for( int k=0; k<lepvec.size(); k++ ) {
598 >    if( abs(lepvec[k].type) == 13 ) {
599 >      mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
600 >      wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
601 >                                                          lepvec[k].vec.Pt() ) );
602 >    } else {
603 >      
604 >      // now deal with medium vs loose
605 >      //              evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
606 >      
607 >      std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
608 >      evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
609 >      
610 >      //              wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
611 >      //                                                                 lepvec[k].vec.Pt() ) );
612 >      
613 >      wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
614 >                                                          lepvec[k].vec.Pt(),
615 >                                                          lepvec[k].isTight ) );
616 >      
617 >    }
618    }
619 +  
620 +  pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
621 +  weights.woff    = offpair.first;
622 +  weights.werroff = offpair.second;
623 +  
624 +  pair<double,double> onpair  = getOnlineEfficiencyWeight( mvec, evec );
625 +  weights.won    = onpair.first;
626 +  weights.werron = onpair.second;
627 + }
628  
180  TFile *file = new TFile(ofname, "RECREATE");
181  h_evt->Write();
182  h_evtfail->Write();
183  passtuple->Write();
184  file->Close();
185  delete file;
629  
630 <  cerr << "done!" << endl;
631 < }
630 > //----------------------------------------------------------------------------
631 > void initRunLumiRangeMap()
632 > //----------------------------------------------------------------------------
633 > {
634 >  /*
635 >  rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
636 >  //  rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
637 >  rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
638 >  rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));  
639 >  rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));  
640 >  // r11b
641 >  rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));  
642 >  */
643 > };
644 >
645  
646 + //----------------------------------------------------------------------------
647 + void initPUWeights()
648 + //----------------------------------------------------------------------------
649 + {
650 +  TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Full2011.root");
651 +  hpu = (TH1D*)(puf->Get("puWeights"));
652 + }
653 +
654 + //----------------------------------------------------------------------------
655 + double getPUWeight(unsigned npu)
656 + //----------------------------------------------------------------------------
657 + {
658 +  return hpu->GetBinContent(hpu->FindBin(npu));
659 + }
660  
661 + //----------------------------------------------------------------------------
662 + void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
663 + //----------------------------------------------------------------------------
664 + {
665 +  unsigned evt;
666 +  float rho;
667  
668 +  FILE * f = fopen("evtrho.dat", "r");
669 +  while( fscanf( f, "%u:%f", &evt, &rho ) ) {
670 +    evtrhoMap[evt] = rho;
671 +  }
672 +  
673 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines