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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines