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.37 by dkralph, Wed Jun 13 13:39:12 2012 UTC vs.
Revision 1.64 by anlevin, Wed Jan 9 10:32:49 2013 UTC

# Line 11 | Line 11 | using namespace std;
11   //
12   // root headers
13   //
14 < #include <TFile.h>                  
14 > #include <TFile.h>
15 > #include <TRegexp.h>
16   #include <TTree.h>                  
17   #include <TChain.h>                
18   #include <TBranch.h>                
# Line 26 | Line 27 | using namespace std;
27   #include "TMVA/Config.h"
28   #include "TMVA/MethodBDT.h"
29  
30 + #include "FactorizedJetCorrector.h"
31 + #include "JetCorrectorParameters.h"
32 +
33   //
34   // ntuple format headers
35   //
# Line 33 | Line 37 | using namespace std;
37   #include "Electron.h"
38   #include "Muon.h"
39   #include "Vertex.h"
40 + #include "PFMet.h"
41 + #include "PFJetCol.h"
42   #include "PFCandidate.h"
43   #include "PFCandidateCol.h"
44   #include "PileupInfoCol.h"
# Line 40 | Line 46 | using namespace std;
46   #include "MCParticle.h"
47   #include "TriggerMask.h"
48   #include "TriggerTable.h"
49 + #include "TriggerObject.h"
50 + #include "TriggerObjectRel.h"
51   #include "Names.h"
52   #include "BaseMod.h"
53 + #include "TriggerObjectsTable.h"
54 + #include "JetIDMVA.h"
55  
56   //
57   // our headers
# Line 49 | Line 59 | using namespace std;
59   #include "ParseArgs.h"
60   #include "MuonSelection.h"
61   #include "ElectronSelection.h"
62 + #include "ElectronMomentumCorrection.h"
63 + #include "JetSelection.h"
64   #include "IsolationSelection.h"
65   #include "ReferenceSelection.h"
66 + #include "MuonMomentumCorrection.h"
67  
68   #include "TriggerUtils.h"
69   #include "PassHLT.h"
# Line 60 | Line 73 | using namespace std;
73   #include "GenInfoStruct.h"
74   #include "WeightStruct.h"
75   #include "AngleTuple.h"
76 + #include "JetInfoStruct.h"
77   #include "FOTuple.h"
78  
79   #include "RunLumiRangeMap.h"
80   #include "SampleWeight.h"
81   #include "EfficiencyWeightsInterface.h"
82 + #include "SelectionFuncs.h"
83  
84   #include "SimpleLepton.h"
85  
# Line 77 | Line 92 | using namespace mithep;
92   //
93   // globals
94   //----------------------------------------------------------------------------
95 < TH1D * hpu;
95 > TH1D *hpu_2011, *hpu_2012;
96   RunLumiRangeMap rlrm;
97   vector<SimpleLepton> failingLeptons ; // for fake estimation
98   vector<SimpleLepton> passingLeptons;      // for fake estimation
# Line 85 | Line 100 | vector<unsigned> cutvec;
100   vector<vector<unsigned> > zcutvec;
101   vector<vector<unsigned> > zzcutvec;
102   map<unsigned,float>       evtrhoMap;
103 + TrigInfo ti;
104   vector<string> cutstrs;
105 < bool passes_HLT_MC;
105 > bool passes_HLT;
106   vector<bool>   PFnoPUflag;;
107 + map<TString, map<TString,int>* > counts;
108 + ElectronMomentumCorrection electron_momentum_correction;
109 + MuCorr *muCorr;
110 + void addDummyZ2Lepotons(EventData &ret4l);
111 + void setNtupleVals(ControlFlags &ctrl, EventData &ret4l, InfoStruct &evtinfo, Angles &angles, KinematicsStruct &kine,
112 +                   JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<PFJet> *jetArr, Array<PFMet> *metArr,
113 +                   vector<SimpleLepton> &simpleLeptonJets, FactorizedJetCorrector *fJetCorrector, Array<PileupInfo> *puArr,
114 +                   Array<PileupEnergyDensity> *puDArr, JetIDMVA *fJetIDMVA, Array<Vertex> *vtxArr, bitset<1024> &triggerBits,
115 +                   TriggerTable *hltTable, Array<TriggerObject> *hltObjArr, TriggerObjectsTable *fTrigObjs, AngleTuple *nt);
116 + //----------------------------------------------------------------------------
117 + void initRunLumiRangeMap(ControlFlags &ctrl)
118 + //----------------------------------------------------------------------------
119 + {
120 +  if(ctrl.jsonFile==""){
121 +    cout << "WARNING: running with empty jsonFile, so setting noJSON to true" << endl;
122 +    ctrl.noJSON = true;
123 +  }
124 +  rlrm.AddJSONFile(string(ctrl.jsonFile));  
125 + }
126  
127   //
128   // prototypes
129   //----------------------------------------------------------------------------
95 void initPUWeights();
96 double getPUWeight(unsigned npu);
97 void setEra(string, ControlFlags&);
98 void setEffiencyWeights(EventData&, WeightStruct& );
99 void initRunLumiRangeMap();
100 void initEvtRhoMap(map<unsigned,float> &);
101 unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
102                         vector<bool> &pfNoPileUpFlag,
103                         const mithep::Array<mithep::Vertex>     * vtxArr );
104 //----------------------------------------------------------------------------
105
130  
131   //
132   // MAIN
# Line 110 | Line 134 | unsigned makePFnoPUArray(mithep::Array<P
134   int main(int argc, char** argv)
135   //----------------------------------------------------------------------------
136   {
137 <  cutstrs.push_back(string("skim0"));              //0
138 <  cutstrs.push_back(string("skim1"));              //1
139 <  cutstrs.push_back(string("skim2"));              //1
140 <  cutstrs.push_back(string("trigger"));            //2
141 <  // -------------------------------------------------
142 <  cutstrs.push_back(string("Z candidate"));        //3
143 <  cutstrs.push_back(string("good Z1"));            //4
144 <  // -------------------------------------------------
145 <  cutstrs.push_back(string("4l"));                 //5  
146 <  cutstrs.push_back(string("ZZ candidate"));       //6
147 <  cutstrs.push_back(string("good Z2"));            //7
148 <  cutstrs.push_back(string("ZZ 20/10"));           //8
149 <  cutstrs.push_back(string("resonance"));          //9
150 <  cutstrs.push_back(string("m4l>70"));             //10
151 <  cutstrs.push_back(string("m4l>100, mZ2 > 12"));                  //11
152 <
153 <
154 <
155 <
137 >  vector<TString> cuts;
138 >  cuts.push_back("start"); // NOTE: is incremented in ReferenceSelection, so if you turn on JSONS be careful
139 >  cuts.push_back("trigger");
140 >  cuts.push_back("sfOsHiPt");
141 >  cuts.push_back("4<mZ2<120");
142 >  cuts.push_back("pt>20,10");
143 >  cuts.push_back("mll>4");
144 >  cuts.push_back("m4l>70");
145 >  cuts.push_back("mZ2>12");
146 >  cuts.push_back("m4l>100");
147 >
148 >  for(unsigned icut=0; icut<cuts.size(); icut++)
149 >    counts[cuts[icut]] = new map<TString,int>;
150 >
151 >  map<TString,map<TString,int>* >::iterator cit;
152 >  for(cit=counts.begin(); cit!=counts.end(); cit++) {
153 >    map<TString,int> *cts = (*cit).second;
154 >    (*cts)["all"]  = int(0);
155 >    (*cts)["4e"]   = int(0);
156 >    (*cts)["4m"]   = int(0);
157 >    (*cts)["2e2m"] = int(0);
158 >  }
159 >  
160    string cmsswpath(CMSSW_BASE);
161    cmsswpath.append("/src");
162 <  std::bitset<1024> triggerBits;
162 >  bitset<1024> triggerBits;
163    vector<vector<string> > inputFiles;
164    inputFiles.push_back(vector<string>());
165    map<string,unsigned> entrymap; // number of unskimmed entries in each file
138  for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0);
139  for( int i=0; i<2; i++ )  {
140    zcutvec.push_back(vector<unsigned>());
141    for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0);
142  }
143  for( int i=0; i<3; i++ )  {
144    zzcutvec.push_back(vector<unsigned>());
145    for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
146  }
147
166  
167    //
168    // args
169    //--------------------------------------------------------------------------------------------------------------
170    ControlFlags ctrl;
171    parse_args( argc, argv, ctrl );
154  if( ctrl.inputfiles.empty() &&ctrl.inputfile.empty() )
155    {
156      cerr << "usage: applySelection.exe <flags> " << endl;
157      cerr << "\tmandoatory flags : " << endl;
158      cerr << "\t--inputfiles |  file containing a list of ntuples to run over" << endl;
159      cerr << "\t--inputfile |  a file to run over" << endl;
160      cerr << "\t--outputfile | file to store  selected evet" << endl;
161      return 1;
162    }
172    ctrl.dump();
173 <
174 <
173 >  cout << "\n\nNOTE: now setting era with arguments... double check this doesnt mess something else up\n\n" << endl;
174 >  assert(ctrl.doFSR);
175  
176    //
177    // File I/O
178    //--------------------------------------------------------------------------------------------------------------
179    TChain * chain = new TChain("Events");
180    TChain * hltchain = new TChain("HLT");
181 +  TChain * runchain = new TChain(Names::gkRunTreeName);
182  
183    string fname;
184 +  unsigned total_unskimmed=0;
185    if( !ctrl.inputfiles.empty() ) {
186      ifstream f(ctrl.inputfiles.c_str());
187 <    while (f >> fname) {
187 >    while (f >> fname) {
188        if( !(strncmp( fname.c_str(), "#", 1 ) ) ) continue; // skip commented lines
189 +      if(fname.find("/store/") != string::npos) fname = "root://eoscms//"+fname;
190        cout << "adding inputfile : " << fname.c_str() << endl;
191        entrymap[string(fname.c_str())] = unskimmedEntries(fname.c_str());
192 <      cout << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl;
192 >      cerr << "unskimmed entries: " << entrymap[string(fname.c_str())] << endl;
193 >      total_unskimmed += entrymap[string(fname.c_str())];
194        chain->AddFile(fname.c_str());
195        hltchain->AddFile(fname.c_str());
196 +      runchain->AddFile(fname.c_str());
197      }
198    } else {
199 +    if(ctrl.inputfile.find("/store/") != string::npos) ctrl.inputfile = "root://eoscms//"+ctrl.inputfile;
200      cout << "adding inputfile : " << ctrl.inputfile.c_str() << endl;
201 <    unsigned tmpent = unskimmedEntries(ctrl.inputfile.c_str());
202 <    cout << "tmpent: " << tmpent << endl;
203 <    entrymap[string(ctrl.inputfile.c_str())] = unskimmedEntries(ctrl.inputfile.c_str());
204 <    cout << "unskimmed entries: " << entrymap[string(ctrl.inputfile.c_str())] << endl;
201 >    unsigned unsk_ents = unskimmedEntries(ctrl.inputfile.c_str());
202 >    entrymap[string(ctrl.inputfile.c_str())] = unsk_ents;
203 >    cerr << "unskimmed entries: " << unsk_ents << endl;
204 >    total_unskimmed += unsk_ents;
205      chain->AddFile(ctrl.inputfile.c_str());
206      hltchain->AddFile(ctrl.inputfile.c_str());
207 +    runchain->AddFile(ctrl.inputfile.c_str());
208    }
209 +  // write the total number of unskimmed events that went into making this output file to a text file
210 +  writeEntries(ctrl,total_unskimmed);
211 +  ctrl.totalMC = total_unskimmed;
212  
213    const char * ofname;
214    if( strcmp( ctrl.outputfile.c_str(), "") ) {
# Line 201 | Line 220 | int main(int argc, char** argv)
220    string xspath = (cmsswpath+string("/MitPhysics/data/xs.dat"));
221    cout << "xspath: " << xspath.c_str() << endl;
222    SimpleTable xstab(xspath.c_str());
223 <
223 >  if(ctrl.mc) {
224 >    getWeight(xstab,entrymap,chain); // test *now* whether we've got the xs in here, so it fails before it creates the output
225 >  }
226  
227    //
228    // Setup
229    //--------------------------------------------------------------------------------------------------------------
230    Angles angles;
231 <  KinematicsStruct kinematics;
231 >  KinematicsStruct kine;
232    InfoStruct evtinfo;
233    WeightStruct weights;
234    GenInfoStruct geninfo;
235 +  JetInfoStruct ji;
236 +  vector<SimpleLepton> simpleLeptonJets;
237  
238    AngleTuple nt( (const char*)ofname, (const char*)"zznt");
239    nt.makeAngleBranch(angles);
240 <  nt.makeKinematicsBranch(kinematics);
240 >  nt.makeKinematicsBranch(kine);
241    nt.makeInfoBranch(evtinfo);
242 +  //  nt.makeJetInfoBranch(ji);
243 +  //  nt.makeJetAngleBranches("DataStruct/data/jetAngleVars.txt");
244  
245 <  
246 <  FOTuple foTree( nt.getFile(), (const char*)"FOtree");
247 <  foTree.makeFailedLeptonBranch(failingLeptons);
248 <  foTree.makePassedLeptonBranch(passingLeptons);
245 >  FOTuple *foTree=0;
246 >  if(ctrl.fakeScheme != "none") {
247 >    foTree = new FOTuple( nt.getFile(), (const char*)"FOtree");
248 >    foTree->makeInfoBranch(evtinfo);
249 >    foTree->makeFailedLeptonBranch(failingLeptons);
250 >    foTree->makePassedLeptonBranch(passingLeptons);
251 >  }
252  
253 <  TH1F * h_wf11_hpt;
253 >  int genSampleType(0);
254    if(ctrl.mc) {
255      nt.makeWeightBranch(weights);
256 <    if(ctrl.fillGen ) nt.makeGenInfoBranch(geninfo);
257 <    initEfficiencyWeights();
258 <    initPUWeights();
259 <
260 <    // Higgs only, pt reweighting
261 <    if( ctrl.mH <= 140 ) {
262 <      char wptname[256];
235 <      sprintf( wptname, "/data/blue/pharris/Flat/ntupler/root/weight_ptH_%i.root", ctrl.mH );
236 <      TFile * f_hpt = new TFile(wptname);
237 <      f_hpt->Print();
238 <      sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH);
239 <      h_wf11_hpt  = (TH1F*)(f_hpt->FindObjectAny(wptname));
256 >    if(ctrl.fillGen) {
257 >      genSampleType = getGenSampleType(ofname);
258 >      if(genSampleType == -1) {
259 >        cout << "\ngenSampleType returned as -1, setting fillGen to false" << endl;
260 >        ctrl.fillGen = false;
261 >      } else
262 >        nt.makeGenInfoBranch(geninfo);
263      }
264 <
264 >    initEfficiencyWeights();
265 >    // initPUWeights();
266    } else {
267 <    initRunLumiRangeMap();
267 >    if(!(ctrl.noJSON) )
268 >      initRunLumiRangeMap(ctrl);
269    }
270  
246  //  initMuonIDMVA();
271    initElectronIDMVAV1();
272    initTrigger();
273 +  initAnalysisTriggers(ti);
274 +  ti.dump();
275 +
276 +  if(ctrl.do_escale) {
277 +    string regPath("EGamma/EGammaAnalysisTools/data/eleEnergyRegWeights_V1.root");
278 +    // if(TString(getenv("HOSTNAME")).Contains(TRegexp("t3[bd][te][cs][hk]")))
279 +      regPath = cmsswpath + "/" + regPath;
280 +    electron_momentum_correction.initialize_regression(regPath);
281 +    if(ctrl.mc) {
282 +      if(ctrl.era == 2011) ctrl.smearing_scaling_dataset = "Fall11";
283 +      else                 ctrl.smearing_scaling_dataset = "Summer12_DR53X_HCP2012";
284 +    } else {
285 +      if(ctrl.era == 2011) ctrl.smearing_scaling_dataset = "Jan16ReReco";
286 +      else                 ctrl.smearing_scaling_dataset = "2012Jul13ReReco";
287 +    }
288 +  }
289 +  if(ctrl.correct_muon_momentum) {
290 +    muCorr = new MuCorr;
291 +    muCorr->corr2011 = new rochcor;
292 +    muCorr->corr2012 = new rochcor2012;
293 +  }
294  
295 <  // hack
296 <  initEvtRhoMap(evtrhoMap);
295 >  vector<TString> fJetCorrParsv;
296 >  vector<JetCorrectorParameters> correctionParameters;
297 >  FactorizedJetCorrector *fJetCorrector;
298 >  JetIDMVA *fJetIDMVA;
299 >  //  initJets(ctrl, cmsswpath, fJetCorrParsv, correctionParameters, fJetCorrector, fJetIDMVA);
300  
253  
301    //
302    // Setup tree I/O
303    //--------------------------------------------------------------------------------------------------------------
# Line 258 | Line 305 | int main(int argc, char** argv)
305    TTree *eventTree=0;  
306    string currentFile("");
307  
308 <  mithep::EventHeader *info    = new mithep::EventHeader();
309 <  mithep::Array<mithep::Electron>             *electronArr   = new mithep::Array<mithep::Electron>();
310 <  mithep::Array<mithep::Muon>                 *muonArr       = new mithep::Array<mithep::Muon>();
311 <  mithep::Array<mithep::Vertex>               *vtxArr        = new mithep::Array<mithep::Vertex>();
312 <  mithep::Array<mithep::PFCandidate>          *pfArr         = new mithep::Array<mithep::PFCandidate>();
313 <  mithep::Array<mithep::PileupInfo>           *puArr         = new mithep::Array<mithep::PileupInfo>();
314 <  mithep::Array<mithep::PileupEnergyDensity>  *puDArr        = new mithep::Array<mithep::PileupEnergyDensity>();
315 <  mithep::Array<mithep::Track>                *trkArr        = new mithep::Array<mithep::Track>();
316 <  mithep::Array<mithep::MCParticle>           *mcArr         = new mithep::Array<mithep::MCParticle>();
317 <  mithep::MCEventInfo                         *mcEvtInfo     = new mithep::MCEventInfo();
318 <  mithep::TriggerMask                         *trigMask      = new mithep::TriggerMask();
319 <  mithep::TriggerTable                        *hltTable      = new mithep::TriggerTable();
320 <  vector<string>                              *hltTableStrings  = new vector<string>();
321 <
322 <  TString fElectronName(Names::gkElectronBrn);
323 <  TString fMuonName(Names::gkMuonBrn);
324 <  TString fInfoName(Names::gkEvtHeaderBrn);
325 <  TString fPrimVtxName(Names::gkPVBrn);
326 <  TString fPFCandidateName(Names::gkPFCandidatesBrn);
327 <  TString fPileupInfoName(Names::gkPileupInfoBrn);
328 <  TString fPileupEnergyDensityName(Names::gkPileupEnergyDensityBrn);
282 <  TString fTrackName(Names::gkTrackBrn);
283 <  TString fMCParticleName(Names::gkMCPartBrn);
284 <  TString fMCEvtInfoName(Names::gkMCEvtInfoBrn);
285 <  TString fTriggerMaskName(Names::gkHltBitBrn);
286 <  TString fTriggerTableName(Names::gkHltTableBrn);
308 >  UInt_t fNMaxTriggers = TRIGGER_BIG_NUMBER;
309 >  EventHeader                   *info                    = new EventHeader();
310 >  Array<PFMet>                  *metArr                  = new Array<PFMet>();
311 >  Array<Electron>               *electronArr             = new Array<Electron>();
312 >  Array<Muon>                   *muonArr                 = new Array<Muon>();
313 >  Array<Vertex>                 *vtxArr                  = new Array<Vertex>();
314 >  Array<PFCandidate>            *pfArr                   = new Array<PFCandidate>();
315 >  Array<PFJet>                  *jetArr                  = new Array<PFJet>();
316 >  Array<PileupInfo>             *puArr                   = new Array<PileupInfo>();
317 >  Array<PileupEnergyDensity>    *puDArr                  = new Array<PileupEnergyDensity>();
318 >  Array<Track>                  *trkArr                  = new Array<Track>();
319 >  Array<MCParticle>             *mcArr                   = new Array<MCParticle>();
320 >  MCEventInfo                   *mcEvtInfo               = new MCEventInfo();
321 >  TriggerMask                   *trigMask                = new TriggerMask();
322 >  TriggerTable                  *hltTable                = new TriggerTable(fNMaxTriggers);
323 >  vector<string>                *hltTableStrings         = new vector<string>();
324 >  vector<string>                *hltLabelStrings         = new vector<string>();
325 >  Array<TriggerObject>          *hltObjArr               = new Array<TriggerObject>();
326 >  Array<TriggerObjectRel>       *hltRelsArr              = new Array<TriggerObjectRel>();
327 >  TriggerObjectsTable           *fTrigObjs               = new TriggerObjectsTable(hltTable,fNMaxTriggers);
328 >  RunInfo                       *runInfo                 = new RunInfo();
329    
330 <  chain->SetBranchAddress(fInfoName,        &info);
331 <  chain->SetBranchAddress(fElectronName,    &electronArr);
332 <  chain->SetBranchAddress(fMuonName,        &muonArr);
333 <  chain->SetBranchAddress(fPrimVtxName,     &vtxArr);
334 <  chain->SetBranchAddress(fPFCandidateName, &pfArr);
330 >  chain->SetBranchAddress(Names::gkEvtHeaderBrn,                &info);
331 >  chain->SetBranchAddress("PFMet",                              &metArr);
332 >  chain->SetBranchAddress(Names::gkElectronBrn,                 &electronArr);
333 >  chain->SetBranchAddress(Names::gkMuonBrn,                     &muonArr);
334 >  chain->SetBranchAddress(Names::gkPVBrn,                       &vtxArr);
335 >  chain->SetBranchAddress(Names::gkPFCandidatesBrn,             &pfArr);
336 >  chain->SetBranchAddress(Names::gkPFJetBrn,                    &jetArr);
337    if( ctrl.mc ) {
338 <    chain->SetBranchAddress(fPileupInfoName,  &puArr);
339 <    chain->SetBranchAddress(fMCParticleName,  &mcArr);
340 <    chain->SetBranchAddress(fMCEvtInfoName,  &mcEvtInfo);
341 <  }
342 <  chain->SetBranchAddress(fPileupEnergyDensityName, &puDArr);
343 <  chain->SetBranchAddress(fTrackName, &trkArr);
344 <  chain->SetBranchAddress(fTriggerMaskName, &trigMask);
345 <  cout << "hlttable: " << fTriggerTableName << endl;
346 <  hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
347 <
348 <  mithep::Vertex              vtx;          // best primary vertex in the event
305 <
306 <  //  ginfo = NULL;
307 <  // if( ctrl.mc ) { chain->SetBranchAddress("Gen",        &ginfo);}
308 <
309 <  int count=0, pass=0;
310 <  float passcorr=0., passcorr_errup=0., passcorr_errdown=0.;
311 <  float denom[3]={0.,0.,0.};
312 <  float numer[3]={0.,0.,0.};
313 <  float numercorr[3]={0.,0.,0.};
338 >    chain->SetBranchAddress(Names::gkPileupInfoBrn,             &puArr);
339 >    chain->SetBranchAddress(Names::gkMCPartBrn,                 &mcArr);
340 >    chain->SetBranchAddress(Names::gkMCEvtInfoBrn,              &mcEvtInfo);
341 >  }
342 >  chain->SetBranchAddress(Names::gkPileupEnergyDensityBrn,      &puDArr);
343 >  chain->SetBranchAddress(Names::gkTrackBrn,                    &trkArr);
344 >  chain->SetBranchAddress(Names::gkHltBitBrn,                   &trigMask);
345 >  chain->SetBranchAddress(Names::gkHltObjBrn,                   &hltObjArr);
346 >  chain->SetBranchAddress("HLTObjectsRelation",                 &hltRelsArr);
347 >  hltchain->SetBranchAddress(Names::gkHltTableBrn,              &hltTableStrings);
348 >  hltchain->SetBranchAddress(Names::gkHltLabelBrn,              &hltLabelStrings);
349  
350 <  // only 1 HLT table / file ???
316 <  hltchain->GetEntry(0);
317 <  cerr << "here... " << endl;
350 >  runchain->SetBranchAddress(Names::gkRunInfoBrn, &runInfo);
351  
352 <  int imax = chain->GetEntries();
320 <  cout << "nEntries: " << imax << endl;
352 >  Vertex              vtx;          // best primary vertex in the event
353  
354 +  hltchain->GetEntry(0);
355  
356 <  //
357 <  // Loop !!!!!!!!!
325 <  //--------------------------------------------------------------------------------------------------------------
326 <  for(UInt_t ientry=0; ientry<imax; ientry++)
327 <    {
328 <      chain->GetEntry(ientry);
329 <      if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
356 >  int imax = (ctrl.n_events_to_process < 0) ? chain->GetEntries() : ctrl.n_events_to_process;
357 >  cerr << "processing: " << imax << " ( / " << chain->GetEntries() << " )" << endl;
358  
359 <      string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
360 <      setEra( fname, ctrl );
359 >  if(ctrl.mc && ctrl.debugOffMc) // necessary for batch mode -- we need debug output for, data but size is too large to store MC output
360 >    ctrl.debug = false;
361  
362 +  int lastHltEntry=-2;
363 +  for(UInt_t ientry=0; ientry<imax; ientry++) {
364 +    chain->GetEntry(ientry);
365 +    if(!(ientry%1000)) cerr << "entry: " << ientry << " ( / " << imax << " )" << endl;
366 +
367 +    increment(counts,"start");
368 +    if( ctrl.debug ) {
369 +      cout << "-----------------------------------------------------------------" << endl;
370 +      cout << "-----------------------------------------------------------------" << endl;
371 +      cout << "Run: " << info->RunNum()
372 +           << "\tEvt: " << info->EvtNum()
373 +           << "\tLumi: " << info->LumiSec()
374 +           << endl;
375 +      cerr << "Run: " << info->RunNum()
376 +           << "\tEvt: " << info->EvtNum()
377 +           << "\tLumi: " << info->LumiSec()
378 +           << endl;
379 +      cout << "-----------------------------------------------------------------" << endl;
380 +    }
381  
382 <      //
383 <      // pfNoPU
384 <      //
385 <      //mithep::Array<PFCandidate> pfNoPileUp;
386 <      PFnoPUflag.clear();
387 <      int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
388 <      assert(pfnopu_size == pfArr->GetEntries());
382 >    runchain->GetEvent(info->RunEntry());
383 >    hltchain->GetEntry(runInfo->HltEntry());
384 >    hltTable->Clear();
385 >    fillTriggerNames(hltTable, hltTableStrings );
386 >    // if(ctrl.debug && (lastHltEntry != runInfo->HltEntry())) hltTable->Print();
387 >    lastHltEntry = runInfo->HltEntry();
388 >    fillTriggerBits( hltTable, trigMask, triggerBits );
389 >    setHLTObjectRelations( hltObjArr, hltRelsArr, hltTableStrings, hltLabelStrings, fTrigObjs );
390 >    // printTriggerObjs( hltTable, fTrigObjs);
391 >      
392 >    string fname = string(chain->GetFile()->GetEndpointUrl()->GetFile());
393 >    if(ctrl.debug) cout << "era is " << ctrl.era << endl;
394 >    if( ctrl.era == 0  ) {
395 >      setEra( fname, ctrl );
396 >      if(ctrl.debug) cout << "era is now " << ctrl.era << endl;
397 >    }
398  
399 <      //
399 >    // pfNoPU
400 >    PFnoPUflag.clear();
401 >    int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
402 >    assert(pfnopu_size == pfArr->GetEntries());
403 >
404 >    // trigger
405 >    if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
406 >      currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
407 >    }
408 >    if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
409 >    passes_HLT = passHLT(ctrl, triggerBits, ti, info->RunNum(), hltTable, fTrigObjs); // NOTE: run value is not used if it's MC
410 >      
411        // data/MC
345      //
412        if(ctrl.mc) {
413 <        //
414 <        // gen info
415 <        //
416 <        if( ctrl.fillGen )
417 <          fillGenInfo( mcArr, mcEvtInfo, geninfo, ESampleType::kHZZ, ctrl);
418 <
419 <        //
354 <        // xsec & PU weights
355 <        //
356 <        weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
357 <        cout << "xsec weight: " << weights.w << endl;
358 <        int npu = -1;
359 <        for(int i=0;i<puArr->GetEntries();i++) {
360 <          if(puArr->At(i)->GetBunchCrossing() == 0)
361 <            npu = puArr->At(i)->GetPU_NumInteractions();
362 <        }
363 <        assert(npu>=0);
364 <        evtinfo.npu;
365 <        weights.npuw = getPUWeight(evtinfo.npu);
366 <        
367 <        //
368 <        // pt reweighting for Higgs < 140, F11
369 <        //
370 <        if( ctrl.fillGen ) {
371 <          if( (fname.find("f11-h115zz4l") != string::npos) ||
372 <              (fname.find("f11-h120zz4l") != string::npos) ||
373 <              (fname.find("f11-h130zz4l") != string::npos)  ) {
374 <            weights.w *= h_wf11_hpt->GetBinContent(h_wf11_hpt->FindBin(geninfo.pt_zz));
375 <          }
376 <        }
377 <
378 <        //
379 <        // trigger
380 <        //
381 <        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
382 <          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
383 <          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
384 <          hltchain->GetEntry(0);
385 <          hltTable->Clear();
386 <          fillTriggerNames(hltTable, hltTableStrings );
387 <        }
388 <        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
389 <        fillTriggerBits( hltTable, trigMask, triggerBits );
390 <        passes_HLT_MC = true; // passed to apply as extern global, just for sync
391 <        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum(), k2012_MC ) ) {
392 <          passes_HLT_MC = false;
393 <        }
413 >        if(ctrl.fillGen) fillGenInfo( mcArr, mcEvtInfo, geninfo, genSampleType, ctrl);
414 >        // NOTE: xs weight and npuw are reset in merge.cc
415 >        if(ctrl.use_weights) weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
416 >        else
417 >          weights.w = 1;
418 >        weights.npu = getNPU(puArr, 0);
419 >        weights.npuw = getPUWeight(ctrl.era, fname, weights.npu);
420        } else {
395        //
421          // JSON
422 <        //
398 <        // if(!(ctrl.noJSON) ) {
399 <        cout << "noJSON flag not in Control Flags" << endl;
400 <        assert(0);
422 >        if(!(ctrl.noJSON) ) {
423            RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
424            if( !(rlrm.HasRunLumi(rl)) )  {
425 <            if( ctrl.debug ) cout << "\tfails JSON" << endl;
425 >            if( ctrl.debug ) cout << "fails JSON" << endl;
426              continue;
427 <          // }
406 <        }
407 <
408 <        //
409 <        // trigger
410 <        //
411 <        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
412 <          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
413 <          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
414 <          hltchain->GetEntry(0);
415 <          hltTable->Clear();
416 <          fillTriggerNames(hltTable, hltTableStrings );
417 <        }
418 <        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
419 <        /*
420 <        fillTriggerBits( hltTable, trigMask, triggerBits );
421 <        if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
422 <          if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
423 <          continue;
427 >          }
428          }
425        */
429        }
430 +    }
431  
432 <      //
433 <      // lepton/kinematic selection ...
434 <      //
435 <      failingLeptons.clear();
436 <      passingLeptons.clear();
437 <      EventData ret4l =
438 <
439 <
440 <        // reference
441 <        apply_HZZ4L_reference_selection(ctrl, info,
442 <                                        vtxArr,
443 <                                        pfArr,
444 <                                        puDArr,
445 <                                        electronArr,
446 <                                        &electronReferencePreSelection,
447 <                                        &electronReferenceIDMVASelectionV1,
448 <                                        &electronReferenceIsoSelection,
445 <                                        muonArr,
446 <                                        &muonReferencePreSelection,
447 <                                        &muonIDPFSelection,
448 <                                        &muonReferenceIsoSelection);
449 <      
450 <      if( ctrl.debug ) cout << endl;
451 <
452 <
453 <      int Z1type=0, Z2type=0;
454 <      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
455 <        if( abs(ret4l.Z1leptons[0].type) == 11  ) Z1type = 11;
456 <        if( abs(ret4l.Z1leptons[0].type) == 13  ) Z1type = 13;
457 <      }  
458 <      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
459 <        if( abs(ret4l.Z2leptons[0].type) == 11  ) Z2type = 11;
460 <        if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
461 <      }  
432 >    //
433 >    // lepton/kinematic selection ...
434 >    //
435 >    failingLeptons.clear();
436 >    passingLeptons.clear();
437 >    EventData ret4l = apply_HZZ4L_reference_selection(ctrl, info,
438 >                                                      vtxArr,
439 >                                                      pfArr,
440 >                                                      puDArr,
441 >                                                      electronArr,
442 >                                                      &electronReferencePreSelection,
443 >                                                      &electronReferenceIDMVASelectionV1, // not used anymore! (Blame the damn regression implementation, not me!)
444 >                                                      &electronReferenceIsoSelection,
445 >                                                      muonArr,
446 >                                                      &muonReferencePreSelection,
447 >                                                      &muonIDPFSelection,
448 >                                                      &muonReferenceIsoSelection);
449        
450 < #ifdef SYNC
464 <      cout  << "bits: " << ret4l.status.selectionBits  << "\t"
465 <            << "Z1: " << Z1type << "\t"
466 <            << "Z2: " << Z2type << endl;
467 <      cout << endl;
468 < #endif      
469 <      
470 <      if( ret4l.status.pass() ) {
471 <        fillAngles(ret4l,angles);
472 <        fillKinematics(ret4l,kinematics);
473 <        fillMassErrors(ret4l,muonArr,electronArr,kinematics);
474 <        fillEventInfo(info,evtinfo);
475 <        if( ctrl.mc) {
476 <          setEffiencyWeights(ret4l, weights);
477 <           if(ctrl.debug)
478 <             cout << "w: " << weights.w << "\t"
479 <                  << "won: " << weights.won << "\t"
480 <                  << "woff: " << weights.woff << endl;
481 <        }
482 <        
450 >    if( ctrl.debug ) cout << endl;
451  
452 +    if(ctrl.fakeScheme == "none") { // fill angletuple if event passes full selection
453 +      if( ret4l.status.pass() ) {
454 +        setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt);
455          nt.Fill();
456 <        
457 <        cerr  << "PASS:: "
458 <              << "\trun: " << evtinfo.run
459 <              << "\tevt: " << evtinfo.evt
460 <              << "\tlumi: " << evtinfo.lumi
461 <              << "\tcostheta1: " << angles.costheta1
462 <              << "\tcostheta2: " << angles.costheta2
463 <              << "\tcostheta*: " << angles.costhetastar
464 <              << "\tbdt: " << angles.bdt
465 <              << endl;
466 <        pass++;
467 <        //      if( pass > 3 ) break;
497 <
498 <      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) &&
499 <                 ret4l.status.selectionBits.to_ulong() < (1UL<<PASS_4L)) { // save for fakes ...
500 <        if(ctrl.debug) {
501 <          cout << "failingLeptons : " << failingLeptons.size() << endl;
502 <          for( int f=0; f<failingLeptons.size(); f++ ) {
503 <            SimpleLepton  l = failingLeptons[f];
504 <            cout << "f: " << f << "\t"
505 <                 << "type: " << l.type << "\t"
506 <                 << "pT: " << l.vec.Pt()  << "\t"
507 <                 << "eta: " << l.vec.Eta()
508 <                 << endl;
509 <          }
456 >      } else {
457 >        if(ctrl.debug) cout << "failing with code : " << ret4l.status.selectionBits << endl;
458 >      }
459 >    } else { // fill FOtuple and angletuple if event has a good Z and one or two extra leptons
460 >      assert(ctrl.fakeScheme=="ZPlusF" || ctrl.fakeScheme=="ZPlusFF");
461 >      if(ret4l.status.selectionBits.test(PASS_GOODZ1) ) {
462 >        unsigned nleps = passingLeptons.size() + failingLeptons.size();
463 >        if( (nleps>=3 && ctrl.fakeScheme=="ZPlusF" ) || (nleps>=4 && ctrl.fakeScheme=="ZPlusFF" ) ) {
464 >          addDummyZ2Lepotons(ret4l);
465 >          setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt);
466 >          nt.Fill();
467 >          foTree->Fill();
468          }
469 <        foTree.Fill();
470 <      } else {
513 <        cout << "failing with some other code : " << ret4l.status.selectionBits << endl;
469 >      } else {
470 >        if(ctrl.debug) cout << "failing PASS_GOODZ1" << endl;
471        }
515    }  
516
517  
518  foTree.getFile()->cd();
519  foTree.getTree()->Write();
520  nt.WriteClose();
521
522  cout << endl;
523  cout << endl;
524  for( int i=0; i<cutvec.size(); i++ ) {
525    cout << "cut: " << i << "\t"
526         << "pass: " << cutvec[i];
527
528    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
529      cout << "\t2e: " << zcutvec[0][i]
530           << "\t2m: " << zcutvec[1][i];
531
532    if( i>PASS_ZCANDIDATE )
533      cout << "\t4e: " << zzcutvec[0][i]
534           << "\t4m: " << zzcutvec[1][i]
535           << "\t2e2m: " << zzcutvec[2][i];
536
537    cout << "\t" << cutstrs[i] << endl;
538
539    cout << endl;
540  }
541
542 }
543
544
545
546 //----------------------------------------------------------------------------
547 void setEffiencyWeights(EventData & evtdat, WeightStruct & weights )
548 //----------------------------------------------------------------------------
549 {
550  vector<SimpleLepton> lepvec = evtdat.Z1leptons;
551  lepvec.insert(lepvec.end(), evtdat.Z2leptons.begin(), evtdat.Z2leptons.end());
552  double w_offline=-1, werr_offline=0;
553  double w_online=-1, werr_online=0;
554  
555  vector< pair <double,double> > wlegs; // pair here is eff & err
556  vector< pair <float,float> > mvec;  // pair here is eta & pt
557
558  //      vector< pair <float,float> > evec;  // pair here is eta & pt
559  // now deal with medium vs loose
560  vector< pair< bool, pair <float,float> > > evec;  // pair here is eta & pt
561  
562  for( int k=0; k<lepvec.size(); k++ ) {
563    if( abs(lepvec[k].type) == 13 ) {
564      mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
565      wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
566                                                          lepvec[k].vec.Pt() ) );
567    } else {
568      
569      // now deal with medium vs loose
570      //              evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
571      
572      std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
573      evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
574      
575      //              wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
576      //                                                                 lepvec[k].vec.Pt() ) );
577      
578      wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
579                                                          lepvec[k].vec.Pt(),
580                                                          lepvec[k].isTight ) );
581      
472      }
473    }
584  
585  pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
586  weights.woff    = offpair.first;
587  weights.werroff = offpair.second;
588  
589  pair<double,double> onpair  = getOnlineEfficiencyWeight( mvec, evec );
590  weights.won    = onpair.first;
591  weights.werron = onpair.second;
592 }
593
594
595 //----------------------------------------------------------------------------
596 void initRunLumiRangeMap()
597 //----------------------------------------------------------------------------
598 {
599  /*
600  rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
601  //  rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
602  rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
603  rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));  
604  rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));  
605  // r11b
606  rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));  
607  */
608
609  // 2012 only for now ...
610  rlrm.AddJSONFile(std::string("./data/Cert_190456-194479_8TeV_PromptReco_Collisions12_JSON.txt"));  
474  
475 < };
476 <
477 <
478 < //----------------------------------------------------------------------------
479 < void initPUWeights()
617 < //----------------------------------------------------------------------------
618 < {
619 <  TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Full2011.root");
620 <  hpu = (TH1D*)(puf->Get("puWeights"));
621 < }
475 >  if(ctrl.fakeScheme != "none") {
476 >    foTree->getFile()->cd();
477 >    foTree->getTree()->Write();
478 >  }
479 >  nt.WriteClose();
480  
481 < //----------------------------------------------------------------------------
482 < double getPUWeight(unsigned npu)
483 < //----------------------------------------------------------------------------
484 < {
485 <  return hpu->GetBinContent(hpu->FindBin(npu));
481 >  for(unsigned icut=0; icut<cuts.size(); icut++) {
482 >    map<TString,int> thisCount(*(counts[cuts[icut]]));
483 >    cerr << setw(20) << cuts[icut] << "\t" << setw(9) << thisCount["all"] << "  ("
484 >         << setw(9) << thisCount["4e"] << setw(9) << thisCount["4m"] << setw(9) << thisCount["2e2m"] << ")" << endl;
485 >  }
486   }
487 <
488 < //----------------------------------------------------------------------------
489 < void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
632 < //----------------------------------------------------------------------------
487 > //----------------------------------------------------------------------------------------
488 > void addDummyZ2Lepotons(EventData &ret4l)
489 > // for fake ntuples, we don't know which are the Z2 leptons yet, but need to fill something so we don't seg fault
490   {
491 <  unsigned evt;
492 <  float rho;
493 <
494 <  cout << "initialzing EvtRhoMap ";
495 <  //FILE * f = fopen("evtrho.dat", "r");
639 <  //  FILE * f = fopen("allrho.cali.uniq.dat", "r");
640 <  FILE * f = fopen("/data/blue/khahn/CMSSW_4_4_2/src/MitHzz4l/allrhoAA.cali.uniq.dat", "r");
641 <  int lcount=0;
642 <  while( fscanf( f, "%u:%f", &evt, &rho ) ) {
643 <    if( feof(f) ) break;
644 <    evtrhoMap[evt] = rho;
645 <    lcount++;
646 <    if( !(lcount%1000) ) cout << "."; flush(cout);
647 <  }
648 <  cout << " done" << endl;
491 >  SimpleLepton dum1,dum2;
492 >  dum1.vec.SetPtEtaPhiM(1,2,3,4);
493 >  dum2.vec.SetPtEtaPhiM(5,6,7,8);
494 >  ret4l.Z2leptons.push_back(dum1);
495 >  ret4l.Z2leptons.push_back(dum2);
496   }
497 <
498 < //----------------------------------------------------------------------------
499 < unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
500 <                         vector<bool> &pfNoPileUpflag,
501 <                         const mithep::Array<mithep::Vertex>      * vtxArr )
502 < //----------------------------------------------------------------------------
497 > //----------------------------------------------------------------------------------------
498 > void setNtupleVals(ControlFlags &ctrl, EventData &ret4l, InfoStruct &evtinfo, Angles &angles, KinematicsStruct &kine,
499 >                   JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<PFJet> *jetArr, Array<PFMet> *metArr,
500 >                   vector<SimpleLepton> &simpleLeptonJets, FactorizedJetCorrector *fJetCorrector, Array<PileupInfo> *puArr,
501 >                   Array<PileupEnergyDensity> *puDArr, JetIDMVA *fJetIDMVA, Array<Vertex> *vtxArr, bitset<1024> &triggerBits,
502 >                   TriggerTable *hltTable, Array<TriggerObject> *hltObjArr, TriggerObjectsTable *fTrigObjs, AngleTuple *nt)
503   {
504 <  for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
505 <    const PFCandidate *pf = fPFCandidates->At(i);
506 <    assert(pf);
507 <
508 <    if(pf->PFType() == PFCandidate::eHadron) {
509 <      if(pf->HasTrackerTrk() &&
510 <         vtxArr->At(0)->HasTrack(pf->TrackerTrk()) &&
511 <         vtxArr->At(0)->TrackWeight(pf->TrackerTrk()) > 0) {
512 <
513 <        pfNoPileUpflag.push_back(1);
514 <
515 <      } else {
516 <
517 <        Bool_t vertexFound = kFALSE;
518 <        const Vertex *closestVtx = 0;
519 <        Double_t dzmin = 10000;
520 <        
674 <        // loop over vertices
675 <        for(UInt_t j = 0; j < vtxArr->GetEntries(); j++) {
676 <          const Vertex *vtx = vtxArr->At(j);
677 <          assert(vtx);
678 <          
679 <          if(pf->HasTrackerTrk() &&
680 <             vtx->HasTrack(pf->TrackerTrk()) &&
681 <             vtx->TrackWeight(pf->TrackerTrk()) > 0) {
682 <            vertexFound = kTRUE;
683 <            closestVtx = vtx;
684 <            break;
685 <          }
686 <          Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
687 <          if(dz < dzmin) {
688 <            closestVtx = vtx;
689 <            dzmin = dz;
690 <          }
691 <        }
692 <
693 <        //      if(fCheckClosestZVertex) {
694 <        if(1) {
695 <          // Fallback: if track is not associated with any vertex,
696 <          // associate it with the vertex closest in z
697 <          if(vertexFound || closestVtx != vtxArr->At(0)) {
698 <            //      pfPileUp->Add(pf);
699 <            pfNoPileUpflag.push_back(0);
700 <          } else {
701 <            pfNoPileUpflag.push_back(1);
702 <          }
703 <        } else {
704 <          if(vertexFound && closestVtx != vtxArr->At(0)) {
705 <            //      pfPileUp->Add(pf);
706 <            pfNoPileUpflag.push_back(0);
707 <          } else {
708 <            //      PFCandidate * pfNoPileUp->AddNew(); // Ridiculous but that's how it is
709 <            pfNoPileUpflag.push_back(1);
710 <          }
711 <        }
712 <      } //hadron & trk stuff
713 <    } else { // hadron
714 <      //      PFCandidate * ptr = pfNoPileUp->AddNew();
715 <      pfNoPileUpflag.push_back(1);
504 >  fillKinematics(ret4l,kine);
505 >  // fillMassErrors(ret4l,muonArr,electronArr,kine);
506 >  TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
507 >  fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0, vtxArr->GetEntries());
508 > //   fillJets(ctrl, jetArr, simpleLeptonJets, fJetCorrector, puDArr, fJetIDMVA, vtxArr, ret4l);
509 > //   fillJetInfo(simpleLeptonJets, ji, ctrl);
510 > //   fillJetAngleBranches(ji, ret4l, nt, ctrl);
511 >  evtinfo.status = 0;
512 >  evtinfo.status = setHltBits(ti, triggerBits);
513 >
514 >  if(ctrl.fakeScheme == "none") {
515 >    fillAngles(ret4l,angles);
516 >
517 >    if( ctrl.mc) {
518 >      setEfficiencyWeights(ctrl, ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights);
519 >      if(ctrl.debug)
520 >        cout << "w: " << weights.w << "\t" << "npuw: " << weights.npuw << "\t" << "won: " << weights.won << "\t" << "woff: " << weights.woff << endl;
521      }
717  } // Loop over PF candidates
718
719  return pfNoPileUpflag.size();
720 }
522  
523 < void setEra(string fname, ControlFlags &ctrl)
524 < {
525 <  if( ctrl.mc && (fname.find("f11-") != string::npos)  ) ctrl.era=2011 ;
526 <  if( ctrl.mc && (fname.find("s12-") != string::npos)  ) ctrl.era=2012 ;
527 <  if( !ctrl.mc && (fname.find("r11-") != string::npos)  ) ctrl.era=2011 ;
528 <  if( !ctrl.mc && (fname.find("r12-") != string::npos)  ) ctrl.era=2012 ;
523 >    if(ctrl.debug) {
524 >      stringstream ss;
525 >      ss << "PASS:: " << "\trun: " << evtinfo.run << "\tevt: " << evtinfo.evt << "\tlumi: " << evtinfo.lumi << "\tchannel: "
526 >         << kine.channel << "\tm4l: " << kine.m4l << "\tmZ1: " << kine.mZ1 << "\tmZ2: " << kine.mZ2 << endl;
527 >      cerr << ss.str();
528 >      cout << ss.str();
529 >    }
530 >  } else {
531 >    // fillAngles(ret4l,angles); // at this point we don't know which four leptons will constitute the ZZ system, so doesn't make sense to fill the angles
532 >  }
533   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines