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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines