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.23 by khahn, Sun May 20 19:08:59 2012 UTC vs.
Revision 1.62 by dkralph, Mon Dec 17 17:12:21 2012 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 <
66 < //#include "Selection.h"
55 < //#include "ReferenceSelection.h"
56 < #include "ReferenceSelection2.h"
65 > #include "ReferenceSelection.h"
66 > #include "MuonMomentumCorrection.h"
67  
68   #include "TriggerUtils.h"
69   #include "PassHLT.h"
70   #include "Angles.h"
71   #include "KinematicsStruct.h"
72   #include "InfoStruct.h"
73 < //#include "GenInfoStruct.h"
73 > #include "GenInfoStruct.h"
74   #include "WeightStruct.h"
65 //#include "GlobalDataAndFuncs.h"
66 #include "RunLumiRangeMap.h"
67
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 82 | 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 90 | 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   //----------------------------------------------------------------------------
100 bool setPV(ControlFlags,const mithep::Array<mithep::Vertex>*, mithep::Vertex& );
101 void initPUWeights();
102 double getPUWeight(unsigned npu);
103 void setEffiencyWeights(EventData&, WeightStruct& );
104 void initRunLumiRangeMap();
105 void initEvtRhoMap(map<unsigned,float> &);
106 unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
107                         vector<bool> &pfNoPileUpFlag,
108                         mithep::Array<Vertex>      * vtxArr );
109 //----------------------------------------------------------------------------
110
130  
131   //
132   // MAIN
# Line 115 | 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("trigger"));            //2
140 <  // -------------------------------------------------
141 <  cutstrs.push_back(string("Z candidate"));        //3
142 <  cutstrs.push_back(string("good Z1"));            //4
143 <  // -------------------------------------------------
144 <  cutstrs.push_back(string("4l"));                 //5  
145 <  cutstrs.push_back(string("ZZ candidate"));       //6
146 <  cutstrs.push_back(string("good Z2"));            //7
147 <  cutstrs.push_back(string("ZZ 20/10"));           //8
148 <  cutstrs.push_back(string("resonance"));          //9
149 <  cutstrs.push_back(string("m4l>70"));             //10
150 <  cutstrs.push_back(string("m4l>100"));            //11
151 <
152 <
153 <
154 <
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
142  for( int i=0; i<cutstrs.size(); i++ ) cutvec.push_back(0);
143  for( int i=0; i<2; i++ )  {
144    zcutvec.push_back(vector<unsigned>());
145    for( int j=0; j<cutstrs.size(); j++ ) zcutvec[i].push_back(0);
146  }
147  for( int i=0; i<3; i++ )  {
148    zzcutvec.push_back(vector<unsigned>());
149    for( int j=0; j<cutstrs.size(); j++ ) zzcutvec[i].push_back(0);
150  }
151
166  
167    //
168    // args
169    //--------------------------------------------------------------------------------------------------------------
170    ControlFlags ctrl;
171    parse_args( argc, argv, ctrl );
158  if( ctrl.inputfiles.empty() &&ctrl.inputfile.empty() )
159    {
160      cerr << "usage: applySelection.exe <flags> " << endl;
161      cerr << "\tmandoatory flags : " << endl;
162      cerr << "\t--inputfiles |  file containing a list of ntuples to run over" << endl;
163      cerr << "\t--inputfile |  a file to run over" << endl;
164      cerr << "\t--outputfile | file to store  selected evet" << endl;
165      return 1;
166    }
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 205 | 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;
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 <  FOTuple foTree( nt.getFile(), (const char*)"FOtree");
246 <  foTree.makeFailedLeptonBranch(failingLeptons);
247 <  foTree.makeZLeptonBranch(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_w_hpt;
253 >  int genSampleType(0);
254    if(ctrl.mc) {
255      nt.makeWeightBranch(weights);
256 <    //    nt.makeGenInfoBranch(geninfo);
257 <    initEfficiencyWeights();
258 <    initPUWeights();
259 <    /*
260 <    // Higgs only, pt reweighting
261 <    if( ctrl.mH <= 140 ) {
262 <      char wptname[256];
238 <      sprintf( wptname, "/data/blue/pharris/Flat/ntupler/root/weight_ptH_%i.root", ctrl.mH );
239 <      TFile * f_hpt = new TFile(wptname);
240 <      f_hpt->Print();
241 <      sprintf(wptname, "weight_hqt_fehipro_fit_%i", ctrl.mH);
242 <      h_w_hpt  = (TH1F*)(f_hpt->FindObjectAny(wptname));
243 <      h_w_hpt->Print();
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  
271 <  //  initMuonIDMVA();
251 <  initMuonIsoMVA();
252 <  initElectronIDMVA();
253 <  initElectronIsoMVA();
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  
259  
301    //
302    // Setup tree I/O
303    //--------------------------------------------------------------------------------------------------------------
# Line 264 | 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::TGenInfo    *ginfo  = new mithep::TGenInfo();
310 <  mithep::Array<mithep::Electron>             *electronArr   = new mithep::Array<mithep::Electron>();
311 <  mithep::Array<mithep::Muon>                 *muonArr       = new mithep::Array<mithep::Muon>();
312 <  mithep::Array<mithep::Vertex>               *vtxArr        = new mithep::Array<mithep::Vertex>();
313 <  mithep::Array<mithep::PFCandidate>          *pfArr         = new mithep::Array<mithep::PFCandidate>();
314 <  mithep::Array<mithep::PileupInfo>           *puArr         = new mithep::Array<mithep::PileupInfo>();
315 <  mithep::Array<mithep::PileupEnergyDensity>  *puDArr        = new mithep::Array<mithep::PileupEnergyDensity>();
316 <  mithep::Array<mithep::Track>                *trkArr        = new mithep::Array<mithep::Track>();
317 <  mithep::Array<mithep::MCParticle>           *mcArr         = new mithep::Array<mithep::MCParticle>();
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);
288 <  TString fTrackName(Names::gkTrackBrn);
289 <  TString fMCParticleName(Names::gkMCPartBrn);
290 <  TString fTriggerMaskName(Names::gkHltBitBrn);
291 <  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);
338 >    chain->SetBranchAddress(Names::gkPileupInfoBrn,             &puArr);
339 >    chain->SetBranchAddress(Names::gkMCPartBrn,                 &mcArr);
340 >    chain->SetBranchAddress(Names::gkMCEvtInfoBrn,              &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
349 <
350 <  //  ginfo = NULL;
351 <  // if( ctrl.mc ) { chain->SetBranchAddress("Gen",        &ginfo);}
352 <
313 <  int count=0, pass=0;
314 <  float passcorr=0., passcorr_errup=0., passcorr_errdown=0.;
315 <  float denom[3]={0.,0.,0.};
316 <  float numer[3]={0.,0.,0.};
317 <  float numercorr[3]={0.,0.,0.};
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 >  runchain->SetBranchAddress(Names::gkRunInfoBrn, &runInfo);
351 >
352 >  Vertex              vtx;          // best primary vertex in the event
353  
319  // only 1 HLT table / file ???
354    hltchain->GetEntry(0);
321  cerr << "here... " << endl;
355  
356 <  int imax = chain->GetEntries();
357 <  cout << "nEntries: " << imax << 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 +  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 <  //
363 <  // Loop !!!!!!!!!
364 <  //--------------------------------------------------------------------------------------------------------------
365 <  for(UInt_t ientry=0; ientry<imax; ientry++)
366 <    {
367 <      chain->GetEntry(ientry);
368 <
369 <      /*
370 <      bool found_tau=false;
371 <      if( ctrl.mc) {  // && ctrl.debug
372 <        cout << "nparticles: " << mcArr->GetEntries() << endl;
373 <        cout << "-----------------------------------" << endl;
374 <        for( int i=0; i<mcArr->GetEntries(); i++ ) {
375 <          const mithep::MCParticle *mc = mcArr->At(i);
376 <          cout << "i: " << i << "\t"
377 <               << "id: " << mc->AbsPdgId()
378 <               << endl;
379 <          if( mc->Is(MCParticle::kTau) ) {
380 <            found_tau=true;
381 <          }
382 <        }
383 <      }
384 <      cout << "-----------------------------------" << endl;
385 <      cout << "found tau: " << found_tau << endl;
386 <      */
387 <
388 <      // events that fail bc ele overlaps w/ reco mu
389 <      /*
390 <      if( info->EvtNum() != 67315 &&
391 <          info->EvtNum() != 288693 ) continue;
392 <      */
393 <
394 <      // events where they apparently don't veto electrons ...
395 <      /*
396 <      if( info->EvtNum() != 141713 &&
397 <          info->EvtNum() != 178019 &&
398 <          info->EvtNum() != 60823 &&
399 <          info->EvtNum() != 192795 ) continue;
400 <      */
401 <
402 <      if(!(ientry%1000)) cerr << "entry: " << ientry << endl;
403 <      setPV( ctrl, vtxArr, vtx);
404 <      //if (!(setPV( ctrl, vtxArr, vtx)) ) continue;
405 <
406 <      float rho = evtrhoMap[info->EvtNum()];
407 <
408 <      //
409 <      // pfNoPU
410 <      //
411 <      //mithep::Array<PFCandidate> pfNoPileUp;
412 <      PFnoPUflag.clear();
413 <      int pfnopu_size = makePFnoPUArray( pfArr, PFnoPUflag, vtxArr );
414 <      assert(pfnopu_size == pfArr->GetEntries());
415 <
416 <      //
417 <      // data/MC
418 <      //
419 <      if(ctrl.mc) {
420 <        //
421 <        // xsec & PU weights
387 <        //
388 <        weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
389 <        cout << "xsec weight: " << weights.w << endl;
390 <        int npu = -1;
391 <        for(int i=0;i<puArr->GetEntries();i++) {
392 <          if(puArr->At(i)->GetBunchCrossing() == 0)
393 <            npu = puArr->At(i)->GetPU_NumInteractions();
394 <        }
395 <        assert(npu>=0);
396 <        evtinfo.npu;
397 <        weights.npuw = getPUWeight(evtinfo.npu);
398 <        //      cout << "weight: " << weights.w << endl;
399 <        //
400 <        // trigger
401 <        //
402 <        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
403 <          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
404 <          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
405 <          hltchain->GetEntry(0);
406 <          hltTable->Clear();
407 <          fillTriggerBits(hltTable, hltTableStrings );
408 <        }
409 <        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
410 <        fillTriggerBits( hltTable, trigMask, triggerBits );
411 <        passes_HLT_MC = true; // passed to apply as extern global, just for sync
412 <        if( !passHLTMC(triggerBits, info->RunNum(), info->EvtNum() ) ) {
413 <          passes_HLT_MC = false;
414 <        }
415 <      } else {
416 <        //
417 <        // JSON
418 <        //
419 <        /*
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 >    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 >    // 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
412 >    if(ctrl.mc) {
413 >      if(ctrl.fillGen) fillGenInfo( mcArr, mcEvtInfo, geninfo, genSampleType, ctrl);
414 >      // NOTE: xs weight and npuw are reset in merge.cc
415 >      weights.w = getWeight(xstab,entrymap,chain)/ctrl.totalMC;
416 >      if(ctrl.debug) cout ;
417 >      weights.npu = getNPU(puArr, 0);
418 >      weights.npuw = getPUWeight(ctrl.era, fname, weights.npu);
419 >    } else {
420 >      // JSON
421 >      if(!(ctrl.noJSON) ) {
422          RunLumiRangeMap::RunLumiPairType rl(info->RunNum(), info->LumiSec());      
423          if( !(rlrm.HasRunLumi(rl)) )  {
424 <          if( ctrl.debug ) cout << "\tfails JSON" << endl;
423 <          continue;
424 <        }
425 <        */
426 <        //
427 <        // trigger
428 <        //
429 <        if( string(chain->GetFile()->GetEndpointUrl()->GetFile()) != currentFile ) {
430 <          currentFile = string(chain->GetFile()->GetEndpointUrl()->GetFile());
431 <          hltchain->SetBranchAddress(fTriggerTableName, &hltTableStrings);
432 <          hltchain->GetEntry(0);
433 <          hltTable->Clear();
434 <          fillTriggerBits(hltTable, hltTableStrings );
435 <        }
436 <        if( ctrl.debug ) cout << "file is : " << currentFile  << endl;
437 <        /*
438 <        fillTriggerBits( hltTable, trigMask, triggerBits );
439 <        if( !passHLT(triggerBits, info->RunNum(), info->EvtNum() ) ) {
440 <          if( ctrl.debug ) cout << "\tfails trigger ... " << endl;
424 >          if( ctrl.debug ) cout << "fails JSON" << endl;
425            continue;
426          }
443        */
427        }
428 +    }
429  
430 <      //
431 <      // lepton/kinematic selection ...
432 <      //
433 <      failingLeptons.clear();
434 <      passingLeptons.clear();
435 <      EventData ret4l =
436 <
437 <
438 <        // reference
439 <        /*
440 <        apply_HZZ4L_reference2_selection(ctrl, info,
441 <                                         vtx,
442 <                                         pfArr,
443 <                                         //rho,
444 <                                         puDArr,
445 <                                         electronArr,
446 <                                         &electronReferencePreSelection,
463 <                                         &electronReferenceIDMVASelection,
464 <                                         &electronReferenceIsoSelection,
465 <                                         muonArr,
466 <                                         &muonReferencePreSelection,
467 <                                         &muonIDPFSelection,
468 <                                         &muonReferenceIsoSelection);
469 <        */
470 <
471 <        // evolved
472 <        apply_HZZ4L_reference2_selection(ctrl, info,
473 <                                         vtx,
474 <                                         pfArr,
475 <                                         //rho,
476 <                                         puDArr,
477 <                                         electronArr,
478 <                                         &electronReferencePreSelection,
479 <                                         //&electronPreSelection,
480 <                                         &electronReferenceIDMVASelection,
481 <                                         &electronIsoMVASelection,
482 <                                         muonArr,
483 <                                         &muonReferencePreSelection,
484 <                                         //&muonPreSelection,
485 <                                         &muonIDPFSelection,
486 <                                         &muonIsoMVASelection);
487 <
488 <
489 <      if( ctrl.debug ) cout << endl;
490 <
491 <
492 <      int Z1type=0, Z2type=0;
493 <      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZCANDIDATE ) {
494 <        if( abs(ret4l.Z1leptons[0].type) == 11  ) Z1type = 11;
495 <        if( abs(ret4l.Z1leptons[0].type) == 13  ) Z1type = 13;
496 <      }  
497 <      if( ret4l.status.selectionBits.to_ulong() >= PASS_ZZCANDIDATE ) {
498 <        if( abs(ret4l.Z2leptons[0].type) == 11  ) Z2type = 11;
499 <        if( abs(ret4l.Z2leptons[0].type) == 13  ) Z2type = 13;
500 <      }  
501 <      
502 < #ifdef SYNC
503 <      cout  << "bits: " << ret4l.status.selectionBits  << "\t"
504 <            << "Z1: " << Z1type << "\t"
505 <            << "Z2: " << Z2type << endl;
506 <      cout << endl;
507 < #endif      
430 >    //
431 >    // lepton/kinematic selection ...
432 >    //
433 >    failingLeptons.clear();
434 >    passingLeptons.clear();
435 >    EventData ret4l = apply_HZZ4L_reference_selection(ctrl, info,
436 >                                                      vtxArr,
437 >                                                      pfArr,
438 >                                                      puDArr,
439 >                                                      electronArr,
440 >                                                      &electronReferencePreSelection,
441 >                                                      &electronReferenceIDMVASelectionV1, // not used anymore! (Blame the damn regression implementation, not me!)
442 >                                                      &electronReferenceIsoSelection,
443 >                                                      muonArr,
444 >                                                      &muonReferencePreSelection,
445 >                                                      &muonIDPFSelection,
446 >                                                      &muonReferenceIsoSelection);
447        
448 <      if( ret4l.status.pass() ) {
449 <        fillAngles(ret4l,angles);
450 <        fillKinematics(ret4l,kinematics);
451 <        fillEventInfo(info,evtinfo);
452 <        if( ctrl.mc) {
514 <        // fillGenInfo(ginfo,geninfo);
515 <          setEffiencyWeights(ret4l, weights);
516 <           if(ctrl.debug)
517 <             cout << "w: " << weights.w << "\t"
518 <                  << "won: " << weights.won << "\t"
519 <                  << "woff: " << weights.woff << endl;
520 <        }
521 <        
522 <        /*
523 <        // only for Higgs < 140
524 <        geninfo.weight *= h_w_hpt->GetBinContent(h_w_hpt->FindBin(geninfo.pt_zz));
525 <        angles.bdt = reader->EvaluateMVA("BDTG");
526 <        */
448 >    if( ctrl.debug ) cout << endl;
449 >
450 >    if(ctrl.fakeScheme == "none") { // fill angletuple if event passes full selection
451 >      if( ret4l.status.pass() ) {
452 >        setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt);
453          nt.Fill();
454 <        
455 <        cerr  << "PASS:: "
456 <              << "\trun: " << evtinfo.run
457 <              << "\tevt: " << evtinfo.evt
458 <              << "\tlumi: " << evtinfo.lumi
459 <              << "\tcostheta1: " << angles.costheta1
460 <              << "\tcostheta2: " << angles.costheta2
461 <              << "\tcostheta*: " << angles.costhetastar
462 <              << "\tbdt: " << angles.bdt
463 <              << endl;
464 <        pass++;
465 <        //      if( pass > 3 ) break;
540 <
541 <      } else if( ret4l.status.selectionBits.test(PASS_GOODZ1) ) { // save for fakes ...
542 <        //      if(ctrl.debug) {
543 <          cout << "failingLeptons : " << failingLeptons.size() << endl;
544 <          for( int f=0; f<failingLeptons.size(); f++ ) {
545 <            SimpleLepton  l = failingLeptons[f];
546 <            cout << "f: " << f << "\t"
547 <                 << "type: " << l.type << "\t"
548 <                 << "pT: " << l.vec.Pt()  << "\t"
549 <                 << "eta: " << l.vec.Eta()
550 <                 << endl;
551 <            //    }
454 >      } else {
455 >        if(ctrl.debug) cout << "failing with code : " << ret4l.status.selectionBits << endl;
456 >      }
457 >    } else { // fill FOtuple and angletuple if event has a good Z and one or two extra leptons
458 >      assert(ctrl.fakeScheme=="ZPlusF" || ctrl.fakeScheme=="ZPlusFF");
459 >      if(ret4l.status.selectionBits.test(PASS_GOODZ1) ) {
460 >        unsigned nleps = passingLeptons.size() + failingLeptons.size();
461 >        if( (nleps>=3 && ctrl.fakeScheme=="ZPlusF" ) || (nleps>=4 && ctrl.fakeScheme=="ZPlusFF" ) ) {
462 >          addDummyZ2Lepotons(ret4l);
463 >          setNtupleVals(ctrl, ret4l, evtinfo, angles, kine, ji, weights, info, jetArr, metArr, simpleLeptonJets, fJetCorrector, puArr, puDArr, fJetIDMVA, vtxArr, triggerBits, hltTable, hltObjArr, fTrigObjs, &nt);
464 >          nt.Fill();
465 >          foTree->Fill();
466          }
467 <        foTree.Fill();
467 >      } else {
468 >        if(ctrl.debug) cout << "failing PASS_GOODZ1" << endl;
469        }
555    }  
556
557  
558  foTree.getFile()->cd();
559  foTree.getTree()->Write();
560  nt.WriteClose();
561
562  cout << endl;
563  cout << endl;
564  for( int i=0; i<cutvec.size(); i++ ) {
565    cout << "cut: " << i << "\t"
566         << "pass: " << cutvec[i];
567
568    if( i>PASS_TRIGGER&&i<=PASS_GOODZ1 )
569      cout << "\t2e: " << zcutvec[0][i]
570           << "\t2m: " << zcutvec[1][i];
571
572    if( i>PASS_ZCANDIDATE )
573      cout << "\t4e: " << zzcutvec[0][i]
574           << "\t4m: " << zzcutvec[1][i]
575           << "\t2e2m: " << zzcutvec[2][i];
576
577    cout << "\t" << cutstrs[i] << endl;
578
579    cout << endl;
580  }
581
582 }
583
584 //----------------------------------------------------------------------------
585 //
586 // Get primary vertices
587 // Assumes primary vertices are ordered by sum-pT^2 (as should be in CMSSW)
588 // NOTE: if no PV is found from fitting tracks, the beamspot is used
589 //
590 //----------------------------------------------------------------------------
591 bool setPV(ControlFlags ctrl,
592           const mithep::Array<mithep::Vertex> * vtxArr,
593           mithep::Vertex & vtx)
594 //----------------------------------------------------------------------------
595 {
596  const Vertex *bestPV = 0;
597  float best_sumpt=-1;
598
599  // good PV requirements
600  const UInt_t   fMinNTracksFit = 0;
601  const Double_t fMinNdof       = 4;
602  const Double_t fMaxAbsZ       = 24;
603  const Double_t fMaxRho        = 2;
604  
605  for(int i=0; i<vtxArr->GetEntries(); ++i) {
606    const Vertex *pv = (Vertex*)(vtxArr->At(i));
607    if( ctrl.debug ) cout << "vertex :: " << i << "\tntrks: " << pv->NTracks() << endl;
608    
609    // Select best PV for corrected d0; if no PV passing cuts, the first PV in the collection will be used
610    if(!pv->IsValid())                                continue;
611    if(pv->NTracksFit()       < fMinNTracksFit)       continue;
612    if(pv->Ndof()                 < fMinNdof)         continue;
613    if(fabs(pv->Z()) > fMaxAbsZ)                      continue;
614    if(pv->Position().Rho()   > fMaxRho)              continue;    
615    
616    // take the first ...
617    bestPV = pv;
618    break;
619
620    // this never reached ...    
621    float tmp_sumpt=0;
622    for( int t=0; t<pv->NTracks(); t++ )
623      tmp_sumpt += pv->Trk(t)->Pt();
624    
625    if( tmp_sumpt > best_sumpt  ) {
626      bestPV = pv;
627      best_sumpt = tmp_sumpt;
628      if( ctrl.debug) cout << "new PV set, pt : " << best_sumpt << endl;
470      }
471    }
631  // sync
632  if(!bestPV) bestPV = vtxArr->At(0);
633  //if(!bestPV) return false;
634  vtx.SetPosition(bestPV->X(),bestPV->Y(),bestPV->Z());
635  vtx.SetErrors(bestPV->XErr(),bestPV->YErr(),bestPV->ZErr());
636  return true;
637 };
638
472  
473 <
474 < //----------------------------------------------------------------------------
475 < void setEffiencyWeights(EventData & evtdat, WeightStruct & weights )
643 < //----------------------------------------------------------------------------
644 < {
645 <  vector<SimpleLepton> lepvec = evtdat.Z1leptons;
646 <  lepvec.insert(lepvec.end(), evtdat.Z2leptons.begin(), evtdat.Z2leptons.end());
647 <  double w_offline=-1, werr_offline=0;
648 <  double w_online=-1, werr_online=0;
649 <  
650 <  vector< pair <double,double> > wlegs; // pair here is eff & err
651 <  vector< pair <float,float> > mvec;  // pair here is eta & pt
652 <
653 <  //      vector< pair <float,float> > evec;  // pair here is eta & pt
654 <  // now deal with medium vs loose
655 <  vector< pair< bool, pair <float,float> > > evec;  // pair here is eta & pt
656 <  
657 <  for( int k=0; k<lepvec.size(); k++ ) {
658 <    if( abs(lepvec[k].type) == 13 ) {
659 <      mvec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
660 <      wlegs.push_back( muonPerLegOfflineEfficiencyWeight( fabs(lepvec[k].vec.Eta()),
661 <                                                          lepvec[k].vec.Pt() ) );
662 <    } else {
663 <      
664 <      // now deal with medium vs loose
665 <      //              evec.push_back( std::pair<float,float> (fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt()) );
666 <      
667 <      std::pair<float,float> tmppair(fabs(lepvec[k].vec.Eta()), lepvec[k].vec.Pt());
668 <      evec.push_back( std::pair<bool, std::pair<float,float> > (lepvec[k].isTight, tmppair) );
669 <      
670 <      //              wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
671 <      //                                                                 lepvec[k].vec.Pt() ) );
672 <      
673 <      wlegs.push_back( elePerLegOfflineEfficiencyWeight(  fabs(lepvec[k].vec.Eta()),
674 <                                                          lepvec[k].vec.Pt(),
675 <                                                          lepvec[k].isTight ) );
676 <      
677 <    }
473 >  if(ctrl.fakeScheme != "none") {
474 >    foTree->getFile()->cd();
475 >    foTree->getTree()->Write();
476    }
477 <  
680 <  pair<double,double> offpair = getOfflineEfficiencyWeight( wlegs );
681 <  weights.woff    = offpair.first;
682 <  weights.werroff = offpair.second;
683 <  
684 <  pair<double,double> onpair  = getOnlineEfficiencyWeight( mvec, evec );
685 <  weights.won    = onpair.first;
686 <  weights.werron = onpair.second;
687 < }
688 <
689 <
690 < //----------------------------------------------------------------------------
691 < void initRunLumiRangeMap()
692 < //----------------------------------------------------------------------------
693 < {
694 <  /*
695 <  rlrm.AddJSONFile(std::string("./data/Cert_136033-149442_7TeV_Apr21ReReco_Collisions10_JSON.txt"));
696 <  //  rlrm.AddJSONFile(std::string("./data/Cert_160404-173244_7TeV_PromptReco_Collisions11_JSON_v2.txt"));
697 <  rlrm.AddJSONFile(std::string("./data/Cert_160404-178078_7TeV_PromptReco_Collisions11_JSON.txt"));
698 <  rlrm.AddJSONFile(std::string("./data/Cert_160404-163869_7TeV_May10ReReco_Collisions11_JSON_v3.txt"));  
699 <  rlrm.AddJSONFile(std::string("./data/Cert_170249-172619_7TeV_ReReco5Aug_Collisions11_JSON.txt"));  
700 <  // r11b
701 <  rlrm.AddJSONFile(std::string("./data/Cert_160404-180252_7TeV_PromptReco_Collisions11_JSON.txt"));  
702 <  */
703 < };
704 <
705 <
706 < //----------------------------------------------------------------------------
707 < void initPUWeights()
708 < //----------------------------------------------------------------------------
709 < {
710 <  TFile * puf = new TFile("data/PileupReweighting.Summer11DYmm_To_Full2011.root");
711 <  hpu = (TH1D*)(puf->Get("puWeights"));
712 < }
477 >  nt.WriteClose();
478  
479 < //----------------------------------------------------------------------------
480 < double getPUWeight(unsigned npu)
481 < //----------------------------------------------------------------------------
482 < {
483 <  return hpu->GetBinContent(hpu->FindBin(npu));
479 >  for(unsigned icut=0; icut<cuts.size(); icut++) {
480 >    map<TString,int> thisCount(*(counts[cuts[icut]]));
481 >    cerr << setw(20) << cuts[icut] << "\t" << setw(9) << thisCount["all"] << "  ("
482 >         << setw(9) << thisCount["4e"] << setw(9) << thisCount["4m"] << setw(9) << thisCount["2e2m"] << ")" << endl;
483 >  }
484   }
485 <
486 < //----------------------------------------------------------------------------
487 < void initEvtRhoMap( map<unsigned, float> & evtrhoMap )
723 < //----------------------------------------------------------------------------
485 > //----------------------------------------------------------------------------------------
486 > void addDummyZ2Lepotons(EventData &ret4l)
487 > // for fake ntuples, we don't know which are the Z2 leptons yet, but need to fill something so we don't seg fault
488   {
489 <  unsigned evt;
490 <  float rho;
491 <
492 <  cout << "initialzing EvtRhoMap ";
493 <  //FILE * f = fopen("evtrho.dat", "r");
730 <  //  FILE * f = fopen("allrho.cali.uniq.dat", "r");
731 <  FILE * f = fopen("allrhoAA.cali.uniq.dat", "r");
732 <  int lcount=0;
733 <  while( fscanf( f, "%u:%f", &evt, &rho ) ) {
734 <    if( feof(f) ) break;
735 <    evtrhoMap[evt] = rho;
736 <    lcount++;
737 <    if( !(lcount%1000) ) cout << "."; flush(cout);
738 <  }
739 <  cout << " done" << endl;
489 >  SimpleLepton dum1,dum2;
490 >  dum1.vec.SetPtEtaPhiM(1,2,3,4);
491 >  dum2.vec.SetPtEtaPhiM(5,6,7,8);
492 >  ret4l.Z2leptons.push_back(dum1);
493 >  ret4l.Z2leptons.push_back(dum2);
494   }
495 <
496 < //----------------------------------------------------------------------------
497 < unsigned makePFnoPUArray(mithep::Array<PFCandidate> * fPFCandidates,
498 <                     vector<bool> &pfNoPileUpflag,
499 <                     mithep::Array<Vertex>      * vtxArr )
500 < //----------------------------------------------------------------------------
495 > //----------------------------------------------------------------------------------------
496 > void setNtupleVals(ControlFlags &ctrl, EventData &ret4l, InfoStruct &evtinfo, Angles &angles, KinematicsStruct &kine,
497 >                   JetInfoStruct &ji, WeightStruct &weights, EventHeader *info, Array<PFJet> *jetArr, Array<PFMet> *metArr,
498 >                   vector<SimpleLepton> &simpleLeptonJets, FactorizedJetCorrector *fJetCorrector, Array<PileupInfo> *puArr,
499 >                   Array<PileupEnergyDensity> *puDArr, JetIDMVA *fJetIDMVA, Array<Vertex> *vtxArr, bitset<1024> &triggerBits,
500 >                   TriggerTable *hltTable, Array<TriggerObject> *hltObjArr, TriggerObjectsTable *fTrigObjs, AngleTuple *nt)
501   {
502 <  for(UInt_t i = 0; i < fPFCandidates->GetEntries(); i++) {
503 <    const PFCandidate *pf = fPFCandidates->At(i);
504 <    assert(pf);
505 <
506 <    if(pf->PFType() == PFCandidate::eHadron) {
507 <      if(pf->HasTrackerTrk() &&
508 <         vtxArr->At(0)->HasTrack(pf->TrackerTrk()) &&
509 <         vtxArr->At(0)->TrackWeight(pf->TrackerTrk()) > 0) {
510 <
511 <        pfNoPileUpflag.push_back(1);
512 <
513 <      } else {
514 <
515 <        Bool_t vertexFound = kFALSE;
516 <        const Vertex *closestVtx = 0;
517 <        Double_t dzmin = 10000;
518 <        
765 <        // loop over vertices
766 <        for(UInt_t j = 0; j < vtxArr->GetEntries(); j++) {
767 <          const Vertex *vtx = vtxArr->At(j);
768 <          assert(vtx);
769 <          
770 <          if(pf->HasTrackerTrk() &&
771 <             vtx->HasTrack(pf->TrackerTrk()) &&
772 <             vtx->TrackWeight(pf->TrackerTrk()) > 0) {
773 <            vertexFound = kTRUE;
774 <            closestVtx = vtx;
775 <            break;
776 <          }
777 <          Double_t dz = fabs(pf->SourceVertex().Z() - vtx->Z());
778 <          if(dz < dzmin) {
779 <            closestVtx = vtx;
780 <            dzmin = dz;
781 <          }
782 <        }
783 <
784 <        //      if(fCheckClosestZVertex) {
785 <        if(1) {
786 <          // Fallback: if track is not associated with any vertex,
787 <          // associate it with the vertex closest in z
788 <          if(vertexFound || closestVtx != vtxArr->At(0)) {
789 <            //      pfPileUp->Add(pf);
790 <            pfNoPileUpflag.push_back(0);
791 <          } else {
792 <            pfNoPileUpflag.push_back(1);
793 <          }
794 <        } else {
795 <          if(vertexFound && closestVtx != vtxArr->At(0)) {
796 <            //      pfPileUp->Add(pf);
797 <            pfNoPileUpflag.push_back(0);
798 <          } else {
799 <            //      PFCandidate * pfNoPileUp->AddNew(); // Ridiculous but that's how it is
800 <            pfNoPileUpflag.push_back(1);
801 <          }
802 <        }
803 <      } //hadron & trk stuff
804 <    } else { // hadron
805 <      //      PFCandidate * ptr = pfNoPileUp->AddNew();
806 <      pfNoPileUpflag.push_back(1);
502 >  fillKinematics(ret4l,kine);
503 >  // fillMassErrors(ret4l,muonArr,electronArr,kine);
504 >  TLorentzVector pfmet; pfmet.SetPxPyPzE(metArr->At(0)->Mex(),metArr->At(0)->Mey(),0,0);
505 >  fillEventInfo( info, pfmet, evtinfo, ctrl.mc ? getNPU(puArr) : 0, vtxArr->GetEntries());
506 >  fillJets(ctrl, jetArr, simpleLeptonJets, fJetCorrector, puDArr, fJetIDMVA, vtxArr, ret4l);
507 >  fillJetInfo(simpleLeptonJets, ji, ctrl);
508 >  fillJetAngleBranches(ji, ret4l, nt, ctrl);
509 >  evtinfo.status = 0;
510 >  evtinfo.status = setHltBits(ti, triggerBits);
511 >
512 >  if(ctrl.fakeScheme == "none") {
513 >    fillAngles(ret4l,angles);
514 >
515 >    if( ctrl.mc) {
516 >      setEfficiencyWeights(ctrl, ctrl.era, ret4l, triggerBits, hltTable, hltObjArr, fTrigObjs, weights);
517 >      if(ctrl.debug)
518 >        cout << "w: " << weights.w << "\t" << "npuw: " << weights.npuw << "\t" << "won: " << weights.won << "\t" << "woff: " << weights.woff << endl;
519      }
808  } // Loop over PF candidates
520  
521 <  return pfNoPileUpflag.size();
521 >    if(ctrl.debug) {
522 >      stringstream ss;
523 >      ss << "PASS:: " << "\trun: " << evtinfo.run << "\tevt: " << evtinfo.evt << "\tlumi: " << evtinfo.lumi << "\tchannel: "
524 >         << kine.channel << "\tm4l: " << kine.m4l << "\tmZ1: " << kine.mZ1 << "\tmZ2: " << kine.mZ2 << endl;
525 >      cerr << ss.str();
526 >      cout << ss.str();
527 >    }
528 >  } else {
529 >    // 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
530 >  }
531   }
812

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines