ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.9
Committed: Thu Sep 8 11:16:42 2011 UTC (13 years, 8 months ago) by arizzi
Content type: text/plain
Branch: MAIN
Changes since 1.8: +81 -54 lines
Log Message:
changes in leptons handling

File Contents

# User Rev Content
1 arizzi 1.1 #include <TH1F.h>
2     #include "PhysicsTools/Utilities/interface/LumiReWeighting.h"
3     #include <TH2F.h>
4     #include <TROOT.h>
5     #include <TFile.h>
6     #include <TTree.h>
7     #include <TSystem.h>
8     #include "DataFormats/FWLite/interface/Event.h"
9     #include "DataFormats/FWLite/interface/Handle.h"
10     #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
11     #include "DataFormats/MuonReco/interface/Muon.h"
12     #include "DataFormats/PatCandidates/interface/Muon.h"
13     #include "PhysicsTools/FWLite/interface/TFileService.h"
14     #include "FWCore/ParameterSet/interface/ProcessDesc.h"
15     #include "FWCore/PythonParameterSet/interface/PythonProcessDesc.h"
16     #include "DataFormats/Math/interface/deltaR.h"
17     #include "DataFormats/Math/interface/deltaPhi.h"
18    
19     #include "DataFormats/FWLite/interface/LuminosityBlock.h"
20     #include "DataFormats/FWLite/interface/Run.h"
21     #include "DataFormats/Luminosity/interface/LumiSummary.h"
22    
23 arizzi 1.4 #include "VHbbAnalysis/VHbbDataFormats/interface/HbbCandidateFinderAlgo.h"
24     #include "VHbbAnalysis/VHbbDataFormats/src/HbbCandidateFinderAlgo.cc"
25 arizzi 1.1
26     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbEvent.h"
27     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbEventAuxInfo.h"
28     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidate.h"
29     #include "VHbbAnalysis/VHbbDataFormats/interface/TriggerReader.h"
30 nmohr 1.5 #include "VHbbAnalysis/VHbbDataFormats/interface/TopMassReco.h"
31 arizzi 1.1
32     #include <sstream>
33     #include <string>
34    
35     #define MAXJ 30
36     #define MAXL 10
37    
38 arizzi 1.4
39     TTree * tscaleHLTmu = 0;
40     TTree * tscaleIDmu = 0;
41    
42 arizzi 1.1 float ScaleCSV(float CSV)
43     {
44     if(CSV < 0.68) return 1.0;
45     if(CSV < 0.9) return 0.96;
46     else return 0.94;
47     }
48    
49    
50     float ScaleIsoHLT(float pt1, float eta1)
51     {
52     float ptMin,ptMax,etaMin,etaMax,scale,error;
53     float s1 = 0;
54 arizzi 1.4 if(tscaleHLTmu ==0)
55     {
56     TFile *scaleFile = new TFile ("IsoToHLT42.root","read");
57     tscaleHLTmu = (TTree*) scaleFile->Get("tree");
58     }
59 arizzi 1.1 int count = 0;
60 arizzi 1.4 tscaleHLTmu->SetBranchAddress("ptMin",&ptMin);
61     tscaleHLTmu->SetBranchAddress("ptMax",&ptMax);
62     tscaleHLTmu->SetBranchAddress("etaMin",&etaMin);
63     tscaleHLTmu->SetBranchAddress("etaMax",&etaMax);
64     tscaleHLTmu->SetBranchAddress("scale",&scale);
65     tscaleHLTmu->SetBranchAddress("error",&error);
66 arizzi 1.1
67 arizzi 1.4 for(int jentry = 0; jentry < tscaleHLTmu->GetEntries(); jentry++)
68 arizzi 1.1 {
69 arizzi 1.4 tscaleHLTmu->GetEntry(jentry);
70 arizzi 1.1 if((pt1 > ptMin) && (pt1 < ptMax) && (eta1 > etaMin) && (eta1 < etaMax))
71     {
72     s1 = scale;
73     count++;
74     }
75     }
76    
77     if(count == 0 || s1 == 0)
78     {
79 arizzi 1.4 //caleFile->Close();
80 arizzi 1.1 return 1;
81     }
82    
83    
84 arizzi 1.4 //aleFile->Close();
85 arizzi 1.1 return (s1);
86     }
87    
88    
89    
90     float ScaleID(float pt1, float eta1)
91     {
92    
93     float ptMin,ptMax,etaMin,etaMax,scale,error;
94     float s1 = 0;
95 arizzi 1.4 if(tscaleIDmu==0)
96     { TFile *scaleFile = new TFile ("ScaleEffs42.root","read");
97     tscaleIDmu = (TTree*) scaleFile->Get("tree");
98     }
99 arizzi 1.1 int count = 0;
100 arizzi 1.4 tscaleIDmu->SetBranchAddress("ptMin",&ptMin);
101     tscaleIDmu->SetBranchAddress("ptMax",&ptMax);
102     tscaleIDmu->SetBranchAddress("etaMin",&etaMin);
103     tscaleIDmu->SetBranchAddress("etaMax",&etaMax);
104     tscaleIDmu->SetBranchAddress("scale",&scale);
105     tscaleIDmu->SetBranchAddress("error",&error);
106 arizzi 1.1
107 arizzi 1.4 for(int jentry = 0; jentry < tscaleIDmu->GetEntries(); jentry++)
108 arizzi 1.1 {
109    
110 arizzi 1.4 tscaleIDmu->GetEntry(jentry);
111 arizzi 1.1 if((pt1 > ptMin) && (pt1 < ptMax) && (eta1 > etaMin) && (eta1 < etaMax))
112     {
113     s1 = scale;
114     count++;
115     }
116     }
117    
118     if(count == 0 || s1 == 0)
119     {
120 arizzi 1.4 //caleFile->Close();
121 arizzi 1.1 return 1;
122     }
123    
124 arizzi 1.4 //aleFile->Close();
125 arizzi 1.1 return (s1);
126    
127     }
128    
129 nmohr 1.7 bool jsonContainsEvent (const std::vector< edm::LuminosityBlockRange > &jsonVec,
130     const edm::EventBase &event)
131     {
132     // if the jsonVec is empty, then no JSON file was provided so all
133     // events should pass
134     if (jsonVec.empty())
135     {
136     return true;
137     }
138     bool (* funcPtr) (edm::LuminosityBlockRange const &,
139     edm::LuminosityBlockID const &) = &edm::contains;
140     edm::LuminosityBlockID lumiID (event.id().run(),
141     event.id().luminosityBlock());
142     std::vector< edm::LuminosityBlockRange >::const_iterator iter =
143     std::find_if (jsonVec.begin(), jsonVec.end(),
144     boost::bind(funcPtr, _1, lumiID) );
145     return jsonVec.end() != iter;
146    
147     }
148    
149 arizzi 1.1
150    
151     typedef struct
152     {
153     float mass; //MT in case of W
154     float pt;
155     float eta;
156     float phi;
157 arizzi 1.9 } TrackInfo;
158 arizzi 1.1
159    
160 arizzi 1.9 struct LeptonInfo
161 arizzi 1.1 {
162     void reset()
163     {
164     for(int i =0; i < MAXL;i++){ mass[i]=-99; pt[i]=-99; eta[i]=-99; phi[i]=-99; aodCombRelIso[i]=-99; pfCombRelIso[i]=-99; photonIso[i]=-99; neutralHadIso[i]=-99; chargedHadIso[i]=-99; particleIso[i]=-99; dxy[i]=-99; dz[i]=-99; type[i]=-99; }
165     }
166    
167     template <class Input> void set(const Input & i, int j,int t)
168     {
169     type[j]=t;
170     pt[j]=i.p4.Pt();
171     mass[j]=i.p4.M();
172     eta[j]=i.p4.Eta();
173     phi[j]=i.p4.Phi();
174     aodCombRelIso[j]=(i.hIso+i.eIso+i.tIso)/i.p4.Pt();
175     pfCombRelIso[j]=(i.pfChaIso+i.pfPhoIso+i.pfNeuIso)/i.p4.Pt();
176     photonIso[j]=i.pfPhoIso;
177     neutralHadIso[j]=i.pfNeuIso;
178     chargedHadIso[j]=i.pfChaIso;
179 arizzi 1.4 setID(i,j);
180 arizzi 1.1 //FIXME: whats this? particleIso;
181     }
182 arizzi 1.4 template <class Input> void setID(const Input & i, int j)
183     {
184     id[j]=-99;
185     }
186    
187    
188    
189 arizzi 1.1
190     float mass[MAXL]; //MT in case of W
191     float pt[MAXL];
192     float eta[MAXL];
193     float phi[MAXL];
194     float aodCombRelIso[MAXL];
195     float pfCombRelIso[MAXL];
196     float photonIso[MAXL];
197     float neutralHadIso[MAXL];
198     float chargedHadIso[MAXL];
199     float particleIso[MAXL];
200     float dxy[MAXL];
201     float dz[MAXL];
202     int type[MAXL];
203 arizzi 1.4 float id[MAXL];
204 arizzi 1.1 };
205    
206 arizzi 1.9 template <> void LeptonInfo::setID<VHbbEvent::ElectronInfo>(const VHbbEvent::ElectronInfo & i, int j){
207 arizzi 1.4 id[j]=i.id80r;
208     }
209    
210 arizzi 1.1 typedef struct
211     {
212     float et;
213     float sumet;
214     float sig;
215     float phi;
216 arizzi 1.9 } METInfo;
217 arizzi 1.1
218     typedef struct
219     {
220     float mht;
221     float ht;
222     float sig;
223     float phi;
224 arizzi 1.9 } MHTInfo;
225 nmohr 1.5
226     typedef struct
227     {
228     float mass;
229     float pt;
230     float wMass;
231 arizzi 1.9 } TopInfo;
232 arizzi 1.1
233 nmohr 1.7 typedef struct
234 arizzi 1.1 {
235     int run;
236     int lumi;
237     int event;
238 nmohr 1.7 int json;
239 arizzi 1.9 } EventInfo;
240 arizzi 1.1
241     typedef struct
242     {
243     void set(const VHbbEvent::SimpleJet & j, int i)
244     {
245     pt[i]=j.p4.Pt();
246     eta[i]=j.p4.Eta();
247     phi[i]=j.p4.Phi();
248     csv[i]=j.csv;
249 arizzi 1.3 //FIXME: numTracksSV (NEED EDM FIX)
250     //FIXME: chf; float nhf; float cef; float nef; float nch; nconstituents; (NEED EDM FIX)
251    
252 arizzi 1.1 flavour[i]=j.flavour;
253 arizzi 1.3 //FIXME: genPt parton or genjet? (NEED EDM FIX)
254    
255     if(j.bestMCp4.Pt() > 0)
256     {
257     genPt[i]=j.bestMCp4.Pt();
258     genEta[i]=j.bestMCp4.Eta();
259     genPhi[i]=j.bestMCp4.Phi();
260     }
261     //FIXME JECUnc (NEED EDM FIX)
262    
263 arizzi 1.1 }
264     void reset()
265     {
266     for(int i=0;i<MAXJ;i++) {
267     pt[i]=-99; eta[i]=-99; phi[i]=-99; csv[i]=-99; cosTheta[i]=-99; numTracksSV[i]=-99; chf[i]=-99; nhf[i]=-99; cef[i]=-99; nef[i]=-99; nch[i]=-99; nconstituents[i]=-99; flavour[i]=-99; genPt[i]=-99; genEta[i]=-99; genPhi[i]=-99; JECUnc[i]=-99;
268     }
269     }
270     float pt[MAXJ];
271     float eta[MAXJ];
272     float phi[MAXJ];
273     float csv[MAXJ];
274     float cosTheta[MAXJ];
275     int numTracksSV[MAXJ];
276     float chf[MAXJ];
277     float nhf[MAXJ];
278     float cef[MAXJ];
279     float nef[MAXJ];
280     float nch[MAXJ];
281     float nconstituents[MAXJ];
282     float flavour[MAXJ];
283     float genPt[MAXJ];
284     float genEta[MAXJ];
285     float genPhi[MAXJ];
286     float JECUnc[MAXJ];
287    
288 arizzi 1.9 } JetInfo;
289 arizzi 1.1
290     int main(int argc, char* argv[])
291     {
292     gROOT->Reset();
293    
294     TTree *_outTree;
295 arizzi 1.9 METInfo MET;
296     MHTInfo MHT;
297     TopInfo top;
298     EventInfo EVENT;
299     // JetInfo jet1,jet2, addJet1, addJet2;
300     // lepton1,lepton2;
301     JetInfo hJets, aJets;
302     LeptonInfo vLeptons, aLeptons;
303 arizzi 1.1 int naJets=0, nhJets=0;
304 arizzi 1.9 TrackInfo H;
305     TrackInfo V;
306     int nvlep=0,nalep=0;
307 arizzi 1.1
308 arizzi 1.6 float jjdr,jjdPhi,jjdEta,HVdPhi,VMt,deltaPullAngle,deltaPullAngleAK7,gendrcc,gendrbb, genZpt, genWpt, weightTrig,addJet3Pt, minDeltaPhijetMET, jetPt_minDeltaPhijetMET , PUweight;
309 arizzi 1.3 int nofLeptons15,nofLeptons20, Vtype,numJets,numBJets,eventFlav;
310 arizzi 1.1 // bool isMET80_CJ80, ispfMHT150, isMET80_2CJ20,isMET65_2CJ20, isJETID,isIsoMu17;
311     bool triggerFlags[500];
312     // ----------------------------------------------------------------------
313     // First Part:
314     //
315     // * enable the AutoLibraryLoader
316     // * book the histograms of interest
317     // * open the input file
318     // ----------------------------------------------------------------------
319    
320     // load framework libraries
321     gSystem->Load( "libFWCoreFWLite" );
322     gSystem->Load("libDataFormatsFWLite");
323     AutoLibraryLoader::enable();
324    
325     // parse arguments
326     if ( argc < 2 ) {
327     return 0;
328     }
329    
330 arizzi 1.4 std::vector<VHbbCandidate> * candZlocal = new std::vector<VHbbCandidate>;
331     std::vector<VHbbCandidate> * candWlocal = new std::vector<VHbbCandidate>;
332    
333 arizzi 1.1 // get the python configuration
334     PythonProcessDesc builder(argv[1]);
335     const edm::ParameterSet& in = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("fwliteInput" );
336     const edm::ParameterSet& out = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("fwliteOutput");
337     const edm::ParameterSet& ana = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("Analyzer");
338 nmohr 1.7 std::vector<edm::LuminosityBlockRange> jsonVector;
339     if ( in.exists("lumisToProcess") )
340     {
341     std::vector<edm::LuminosityBlockRange> const & lumisTemp =
342     in.getUntrackedParameter<std::vector<edm::LuminosityBlockRange> > ("lumisToProcess");
343     jsonVector.resize( lumisTemp.size() );
344     copy( lumisTemp.begin(), lumisTemp.end(), jsonVector.begin() );
345     }
346 arizzi 1.1
347     // now get each parameter
348     int maxEvents_( in.getParameter<int>("maxEvents") );
349     unsigned int outputEvery_( in.getParameter<unsigned int>("outputEvery") );
350     std::string outputFile_( out.getParameter<std::string>("fileName" ) );
351    
352    
353     std::vector<std::string> triggers( ana.getParameter<std::vector<std::string> >("triggers") );
354 arizzi 1.6 double btagThr = ana.getParameter<double>("bJetCountThreshold" );
355 arizzi 1.4 bool fromCandidate = ana.getParameter<bool>("readFromCandidates");
356     HbbCandidateFinderAlgo * algoZ = new HbbCandidateFinderAlgo(ana.getParameter<bool>("verbose"), ana.getParameter<double>("jetPtThresholdZ"),
357     ana.getParameter<bool>("useHighestPtHiggsZ") );
358     HbbCandidateFinderAlgo * algoW = new HbbCandidateFinderAlgo(ana.getParameter<bool>("verbose"), ana.getParameter<double>("jetPtThresholdW"),
359     ana.getParameter<bool>("useHighestPtHiggsW") );
360    
361 arizzi 1.1
362     std::vector<std::string> inputFiles_( in.getParameter<std::vector<std::string> >("fileNames") );
363     // std::string inputFile( in.getParameter<std::string> ("fileName") );
364    
365    
366 arizzi 1.3 std::string PUmcfileName_ = in.getParameter<std::string> ("PUmcfileName") ;
367     std::string PUdatafileName_ = in.getParameter<std::string> ("PUdatafileName") ;
368 arizzi 1.1 bool isMC_( ana.getParameter<bool>("isMC") );
369     TriggerReader trigger(isMC_);
370    
371 arizzi 1.6 // TFile *_outPUFile = new TFile((outputFile_+"_PU").c_str(), "recreate");
372     // TH1F * pu = new TH1F("pileup","",-0.5,24.5,25);
373 arizzi 1.1 TFile *_outFile = new TFile(outputFile_.c_str(), "recreate");
374     _outTree = new TTree("tree", "myTree");
375    
376     _outTree->Branch("H" , &H , "mass/F:pt/F:eta:phi/F");
377     _outTree->Branch("V" , &V , "mass/F:pt/F:eta:phi/F");
378     _outTree->Branch("nhJets" , &nhJets , "nhJets/I");
379     _outTree->Branch("naJets" , &naJets , "naJets/I");
380 arizzi 1.2
381     _outTree->Branch("hJet_pt",hJets.pt ,"pt[nhJets]/F");
382     _outTree->Branch("hJet_eta",hJets.eta ,"eta[nhJets]/F");
383     _outTree->Branch("hJet_phi",hJets.phi ,"phi[nhJets]/F");
384     _outTree->Branch("hJet_csv",hJets.csv ,"csv[nhJets]/F");
385     _outTree->Branch("hJet_cosTheta",hJets.cosTheta ,"cosTheta[nhJets]/F");
386     _outTree->Branch("hJet_numTracksSV",hJets.numTracksSV ,"numTracksSV[nhJets]/I");
387     _outTree->Branch("hJet_chf",hJets.chf ,"chf[nhJets]/F");
388     _outTree->Branch("hJet_nhf",hJets.nhf ,"nhf[nhJets]/F");
389     _outTree->Branch("hJet_cef",hJets.cef ,"cef[nhJets]/F");
390     _outTree->Branch("hJet_nef",hJets.nef ,"nef[nhJets]/F");
391     _outTree->Branch("hJet_nch",hJets.nch ,"nch[nhJets]/F");
392     _outTree->Branch("hJet_nconstituents",hJets.nconstituents ,"nconstituents[nhJets]");
393     _outTree->Branch("hJet_flavour",hJets.flavour ,"flavour[nhJets]/F");
394     _outTree->Branch("hJet_genPt",hJets.genPt ,"genPt[nhJets]/F");
395     _outTree->Branch("hJet_genEta",hJets.genEta ,"genEta[nhJets]/F");
396     _outTree->Branch("hJet_genPhi",hJets.genPhi ,"genPhi[nhJets]/F");
397     _outTree->Branch("hJet_JECUnc",hJets.JECUnc ,"JECUnc[nhJets]/F");
398    
399     _outTree->Branch("aJet_pt",aJets.pt ,"pt[naJets]/F");
400     _outTree->Branch("aJet_eta",aJets.eta ,"eta[naJets]/F");
401     _outTree->Branch("aJet_phi",aJets.phi ,"phi[naJets]/F");
402     _outTree->Branch("aJet_csv",aJets.csv ,"csv[naJets]/F");
403     _outTree->Branch("aJet_cosTheta",aJets.cosTheta ,"cosTheta[naJets]/F");
404     _outTree->Branch("aJet_numTracksSV",aJets.numTracksSV ,"numTracksSV[naJets]/I");
405     _outTree->Branch("aJet_chf",aJets.chf ,"chf[naJets]/F");
406     _outTree->Branch("aJet_nhf",aJets.nhf ,"nhf[naJets]/F");
407     _outTree->Branch("aJet_cef",aJets.cef ,"cef[naJets]/F");
408     _outTree->Branch("aJet_nef",aJets.nef ,"nef[naJets]/F");
409     _outTree->Branch("aJet_nch",aJets.nch ,"nch[naJets]/F");
410     _outTree->Branch("aJet_nconstituents",aJets.nconstituents ,"nconstituents[naJets]");
411     _outTree->Branch("aJet_flavour",aJets.flavour ,"flavour[naJets]/F");
412     _outTree->Branch("aJet_genPt",aJets.genPt ,"genPt[naJets]/F");
413     _outTree->Branch("aJet_genEta",aJets.genEta ,"genEta[naJets]/F");
414     _outTree->Branch("aJet_genPhi",aJets.genPhi ,"genPhi[naJets]/F");
415     _outTree->Branch("aJet_JECUnc",aJets.JECUnc ,"JECUnc[naJets]/F");
416    
417 arizzi 1.1
418     _outTree->Branch("addJet3Pt", &addJet3Pt , "addJet3Pt/F");
419     _outTree->Branch("jjdr" , &jjdr , "jjdr/F" );
420     _outTree->Branch("jjdPhi" , &jjdPhi , "jjdPhi/F" );
421 arizzi 1.6 _outTree->Branch("jjdEta" , &jjdEta , "jjdEta/F" );
422 arizzi 1.1 _outTree->Branch("numJets" , &numJets , "numJets/I" );
423     _outTree->Branch("numBJets" , &numBJets , "numBJets/I" );
424     _outTree->Branch("nofLeptons15" , &nofLeptons15 , "nofLeptons15/I" );
425     _outTree->Branch("nofLeptons20" , &nofLeptons20 , "nofLeptons20/I" );
426     _outTree->Branch("deltaPullAngle", &deltaPullAngle , "deltaPullAngle/F");
427     _outTree->Branch("gendrcc" , &gendrcc , "gendrcc/F");
428     _outTree->Branch("gendrbb" , &gendrbb , "gendrbb/F");
429     _outTree->Branch("genZpt" , &genZpt , "genZpt/F");
430     _outTree->Branch("genWpt" , &genWpt , "genWpt/F");
431     _outTree->Branch("weightTrig" , &weightTrig , "weightTrig/F");
432     _outTree->Branch("deltaPullAngleAK7", &deltaPullAngleAK7 , "deltaPullAngleAK7/F");
433     _outTree->Branch("PUweight", &PUweight , "PUweight/F");
434 arizzi 1.3 _outTree->Branch("eventFlav", &eventFlav , "eventFlav/I");
435 arizzi 1.1
436    
437    
438    
439     _outTree->Branch("Vtype" , &Vtype , "Vtype/I" );
440     _outTree->Branch("HVdPhi" , &HVdPhi , "HVdPhi/F" );
441     _outTree->Branch("VMt" , &VMt , "VMt/F" );
442    
443 arizzi 1.9 _outTree->Branch("nvlep" , &nvlep , "nvlep/I");
444     _outTree->Branch("nalep" , &nalep , "nalep/I");
445 arizzi 1.3
446 arizzi 1.9 _outTree->Branch("vLepton_mass",vLeptons.mass ,"mass[nvlep]/F");
447     _outTree->Branch("vLepton_pt",vLeptons.pt ,"pt[nvlep]/F");
448     _outTree->Branch("vLepton_eta",vLeptons.eta ,"eta[nvlep]");
449     _outTree->Branch("vLepton_phi",vLeptons.phi ,"phi[nvlep]/F");
450     _outTree->Branch("vLepton_aodCombRelIso",vLeptons.aodCombRelIso ,"aodCombRelIso[nvlep]/F");
451     _outTree->Branch("vLepton_pfCombRelIso",vLeptons.pfCombRelIso ,"pfCombRelIso[nvlep]/F");
452     _outTree->Branch("vLepton_photonIso",vLeptons.photonIso ,"photonIso[nvlep]/F");
453     _outTree->Branch("vLepton_neutralHadIso",vLeptons.neutralHadIso ,"neutralHadIso[nvlep]/F");
454     _outTree->Branch("vLepton_chargedHadIso",vLeptons.chargedHadIso ,"chargedHadIso[nvlep]/F");
455     _outTree->Branch("vLepton_particleIso",vLeptons.particleIso ,"particleIso[nvlep]/F");
456     _outTree->Branch("vLepton_dxy",vLeptons.dxy ,"dxy[nvlep]/F");
457     _outTree->Branch("vLepton_dz",vLeptons.dz ,"dz[nvlep]/F");
458     _outTree->Branch("vLepton_type",vLeptons.type ,"type[nvlep]/I");
459     _outTree->Branch("vLepton_id",vLeptons.id ,"id[nvlep]/F");
460    
461     _outTree->Branch("aLepton_mass",aLeptons.mass ,"mass[nalep]/F");
462     _outTree->Branch("aLepton_pt",aLeptons.pt ,"pt[nalep]/F");
463     _outTree->Branch("aLepton_eta",aLeptons.eta ,"eta[nalep]");
464     _outTree->Branch("aLepton_phi",aLeptons.phi ,"phi[nalep]/F");
465     _outTree->Branch("aLepton_aodCombRelIso",aLeptons.aodCombRelIso ,"aodCombRelIso[nalep]/F");
466     _outTree->Branch("aLepton_pfCombRelIso",aLeptons.pfCombRelIso ,"pfCombRelIso[nalep]/F");
467     _outTree->Branch("aLepton_photonIso",aLeptons.photonIso ,"photonIso[nalep]/F");
468     _outTree->Branch("aLepton_neutralHadIso",aLeptons.neutralHadIso ,"neutralHadIso[nalep]/F");
469     _outTree->Branch("aLepton_chargedHadIso",aLeptons.chargedHadIso ,"chargedHadIso[nalep]/F");
470     _outTree->Branch("aLepton_particleIso",aLeptons.particleIso ,"particleIso[nalep]/F");
471     _outTree->Branch("aLepton_dxy",aLeptons.dxy ,"dxy[nalep]/F");
472     _outTree->Branch("aLepton_dz",aLeptons.dz ,"dz[nalep]/F");
473     _outTree->Branch("aLepton_type",aLeptons.type ,"type[nalep]/I");
474     _outTree->Branch("aLepton_id",aLeptons.id ,"id[nalep]/F");
475    
476 arizzi 1.8 _outTree->Branch("top" , &top , "mass/F:pt/F:wMass/F");
477 arizzi 1.1
478     _outTree->Branch("MET" , &MET , "et/F:sumet:sig/F:phi/F");
479     _outTree->Branch("MHT" , &MHT , "mht/F:ht:sig/F:phi/F");
480     _outTree->Branch("minDeltaPhijetMET" , &minDeltaPhijetMET , "minDeltaPhijetMET/F");
481     _outTree->Branch("jetPt_minDeltaPhijetMET" , &jetPt_minDeltaPhijetMET , "jetPt_minDeltaPhijetMET/F");
482    
483     std::stringstream s;
484     s << "triggerFlags[" << triggers.size() << "]/b";
485     _outTree->Branch("triggerFlags", triggerFlags, s.str().c_str());
486 nmohr 1.7
487     _outTree->Branch("EVENT" , &EVENT , "run/I:lumi/I:event/I:json/I");
488 arizzi 1.1
489 arizzi 1.3 /*
490 arizzi 1.4 FIXME - btag SF
491 arizzi 1.1 */
492    
493     int ievt=0;
494     int totalcount=0;
495    
496     // TFile* inFile = new TFile(inputFile.c_str(), "read");
497     for(unsigned int iFile=0; iFile<inputFiles_.size(); ++iFile) {
498     std::cout << iFile << std::endl;
499     TFile* inFile = TFile::Open(inputFiles_[iFile].c_str());
500     if(inFile==0) continue;
501    
502     // loop the events
503    
504     fwlite::Event ev(inFile);
505     for(ev.toBegin(); !ev.atEnd(); ++ev, ++ievt)
506     {
507    
508     if(isMC_){
509     // PU weights
510 arizzi 1.3
511 arizzi 1.9 // edm::LumiReWeighting LumiWeights_ = edm::LumiReWeighting(PUmcfileName_,PUdatafileName_ , "pileup", "pileup");
512     // double avg=0;
513 arizzi 1.3 //FIXME: PU (NEED EDM FIX)
514 arizzi 1.1 // if( PUintimeSizes.isValid() && PUouttime1minusSizes.isValid() && PUouttime1plusSizes.isValid()){
515     // avg = (double)( *PUintimeSizes );
516     // }
517 arizzi 1.3 PUweight = 1.0; // FIXME: LumiWeights_.weight3BX( avg /3.); (NEED EDM FIX)
518 arizzi 1.1 }
519 nmohr 1.7
520     //Write event info
521     EVENT.run = ev.id().run();
522     EVENT.lumi = ev.id().luminosityBlock();
523     EVENT.event = ev.id().event();
524     EVENT.json = jsonContainsEvent (jsonVector, ev);
525 arizzi 1.3
526 arizzi 1.4
527     const std::vector<VHbbCandidate> * candZ ;
528     const std::vector<VHbbCandidate> * candW ;
529    
530     if(fromCandidate)
531     {
532 arizzi 1.3 fwlite::Handle< std::vector<VHbbCandidate> > vhbbCandHandleZ;
533     vhbbCandHandleZ.getByLabel(ev,"hbbBestCSVPt20Candidates");
534 arizzi 1.4 candZ = vhbbCandHandleZ.product();
535 arizzi 1.3
536     fwlite::Handle< std::vector<VHbbCandidate> > vhbbCandHandle;
537     vhbbCandHandle.getByLabel(ev,"hbbHighestPtHiggsPt30Candidates");
538 arizzi 1.4 candW = vhbbCandHandle.product();
539     }
540     else
541     {
542     candZlocal->clear();
543     candWlocal->clear();
544     fwlite::Handle< VHbbEvent > vhbbHandle;
545     vhbbHandle.getByLabel(ev,"HbbAnalyzerNew");
546     const VHbbEvent iEvent = *vhbbHandle.product();
547     algoZ->run(vhbbHandle.product(),*candZlocal);
548     algoW->run(vhbbHandle.product(),*candWlocal);
549     candZ= candZlocal;
550     candW= candWlocal;
551    
552    
553 arizzi 1.1
554 arizzi 1.4 }
555 arizzi 1.1
556 arizzi 1.3 const std::vector<VHbbCandidate> * cand = candZ;
557 arizzi 1.1
558    
559     fwlite::Handle< VHbbEventAuxInfo > vhbbAuxHandle;
560     vhbbAuxHandle.getByLabel(ev,"HbbAnalyzerNew");
561     const VHbbEventAuxInfo & aux = *vhbbAuxHandle.product();
562    
563     /* fwlite::Handle< VHbbEvent > vhbbHandle;
564     vhbbHandle.getByLabel(ev,"HbbAnalyzerNew");
565     const VHbbEvent iEvent = *vhbbHandle.product();
566     */
567    
568     // std::clog << "Filling tree "<< std::endl;
569    
570 arizzi 1.3 if(cand->size() == 0 or cand->at(0).H.jets.size() < 2) continue;
571     if(cand->size() > 1 )
572     {
573     std::cout << "MULTIPLE CANDIDATES: " << cand->size() << std::endl;
574     }
575     if(cand->at(0).candidateType == VHbbCandidate::Wmun || cand->at(0).candidateType == VHbbCandidate::Wen ) cand=candW;
576     if(cand->size() == 0)
577     {
578     // std::cout << "W event loss due to tigther cuts" << std::endl;
579     continue;
580     }
581     const VHbbCandidate & vhCand = cand->at(0);
582 arizzi 1.4 trigger.setEvent(&ev);
583     for(size_t j=0;j < triggers.size();j++)
584     triggerFlags[j]=trigger.accept(triggers[j]);
585 arizzi 1.3
586     eventFlav=0;
587     if(aux.mcBbar.size() > 0 || aux.mcB.size() > 0) eventFlav=5;
588     else if(aux.mcC.size() > 0) eventFlav=4;
589 arizzi 1.8
590 arizzi 1.3
591 arizzi 1.1 H.mass = vhCand.H.p4.M();
592     H.pt = vhCand.H.p4.Pt();
593     H.eta = vhCand.H.p4.Eta();
594     H.phi = vhCand.H.p4.Phi();
595     V.mass = vhCand.V.p4.M();
596     V.pt = vhCand.V.p4.Pt();
597     V.eta = vhCand.V.p4.Eta();
598     V.phi = vhCand.V.p4.Phi();
599     nhJets=2;
600     hJets.set(vhCand.H.jets[0],0);
601     hJets.set(vhCand.H.jets[1],1);
602     aJets.reset();
603     naJets=vhCand.additionalJets.size();
604 arizzi 1.6 numBJets=0;
605     if(vhCand.H.jets[0].csv> btagThr) numBJets++;
606     if(vhCand.H.jets[1].csv> btagThr) numBJets++;
607     for( int j=0; j < naJets && j < MAXJ; j++ )
608     {
609     aJets.set(vhCand.additionalJets[j],j);
610     if(vhCand.additionalJets[j].csv> btagThr) numBJets++;
611     }
612 arizzi 1.1 numJets = vhCand.additionalJets.size()+2;
613     jjdr = deltaR(vhCand.H.jets[0].p4.Eta(),vhCand.H.jets[0].p4.Phi(),vhCand.H.jets[1].p4.Eta(),vhCand.H.jets[1].p4.Phi());
614     jjdPhi = deltaPhi(vhCand.H.jets[0].p4.Phi(),vhCand.H.jets[1].p4.Phi());
615 arizzi 1.6 jjdEta= TMath::Abs( vhCand.H.jets[0].p4.Eta() - vhCand.H.jets[1].p4.Eta() );
616 arizzi 1.1 HVdPhi = deltaPhi(vhCand.H.p4.Phi(),vhCand.V.p4.Phi()) ;
617     deltaPullAngle = vhCand.H.deltaTheta;
618     float deltaPhipfMETjet1 = deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.H.jets[0].p4.Phi() );
619     float deltaPhipfMETjet2 = deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.H.jets[1].p4.Phi() );
620     if(deltaPhipfMETjet1 <= deltaPhipfMETjet2)
621     {
622     minDeltaPhijetMET=deltaPhipfMETjet1;
623     jetPt_minDeltaPhijetMET=vhCand.H.jets[0].p4.Pt();
624     }
625     else
626     {
627     minDeltaPhijetMET=deltaPhipfMETjet2;
628     jetPt_minDeltaPhijetMET=vhCand.H.jets[1].p4.Pt();
629     }
630    
631 arizzi 1.3 hJets.cosTheta[0]= vhCand.H.helicities[0];
632     hJets.cosTheta[1]= vhCand.H.helicities[1];
633 arizzi 1.1
634     MET.et = vhCand.V.mets.at(0).p4.Pt();
635     MET.phi = vhCand.V.mets.at(0).p4.Phi();
636     MET.sumet = vhCand.V.mets.at(0).sumEt;
637     MET.sig = vhCand.V.mets.at(0).metSig;
638 arizzi 1.3 //FIXME add MHT _outTree->Branch("MHT" , &MHT , "mht/F:ht:sig/F:phi/F"); (NEED EDM FIX)
639 arizzi 1.1 Vtype = vhCand.candidateType;
640 arizzi 1.9 vLeptons.reset();
641 arizzi 1.3 weightTrig = 0.;
642 arizzi 1.8 TLorentzVector leptonForTop;
643 arizzi 1.9 size_t firstAddMu=0;
644     size_t firstAddEle=0;
645 arizzi 1.1 if(Vtype == VHbbCandidate::Zmumu ){
646 arizzi 1.9 vLeptons.set(vhCand.V.muons[0],0,12);
647     vLeptons.set(vhCand.V.muons[1],1,12);
648     float cweightID = ScaleID(vLeptons.pt[0],vLeptons.eta[0]) * ScaleID(vLeptons.pt[1],vLeptons.eta[1]) ;
649     float weightTrig1 = ScaleIsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
650     float weightTrig2 = ScaleIsoHLT(vLeptons.pt[1],vLeptons.eta[1]);
651 arizzi 1.1 float cweightTrig = weightTrig1 + weightTrig2 - weightTrig1*weightTrig2;
652     weightTrig = cweightID * cweightTrig;
653 arizzi 1.9 nvlep=2;
654     firstAddMu=2;
655 arizzi 1.1 }
656     if( Vtype == VHbbCandidate::Zee ){
657 arizzi 1.9 vLeptons.set(vhCand.V.electrons[0],0,11);
658     vLeptons.set(vhCand.V.electrons[1],1,11);
659     nvlep=2;
660     firstAddEle=2;
661 arizzi 1.3 //FIXME: trigger weights for electrons
662 arizzi 1.1 }
663     if(Vtype == VHbbCandidate::Wmun ){
664 arizzi 1.8 leptonForTop=vhCand.V.muons[0].p4;
665 arizzi 1.9 vLeptons.set(vhCand.V.muons[0],0,12);
666     float cweightID = ScaleID(vLeptons.pt[0],vLeptons.eta[0]);
667     float weightTrig1 = ScaleIsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
668 arizzi 1.1 float cweightTrig = weightTrig1;
669     weightTrig = cweightID * cweightTrig;
670 arizzi 1.9 nvlep=1;
671     firstAddMu=1;
672 arizzi 1.1 }
673     if( Vtype == VHbbCandidate::Wen ){
674 arizzi 1.8 leptonForTop=vhCand.V.electrons[0].p4;
675 arizzi 1.9 vLeptons.set(vhCand.V.electrons[0],0,11);
676     nvlep=1;
677     firstAddEle=1;
678 arizzi 1.1 }
679 arizzi 1.3 if( Vtype == VHbbCandidate::Znn ){
680 arizzi 1.9 nvlep=0;
681 arizzi 1.3 //FIXME: trigger weights for Znn
682    
683     }
684 arizzi 1.9
685     aLeptons.reset();
686     nalep=0;
687     for(size_t j=firstAddMu;j< vhCand.V.muons.size();j++) aLeptons.set(vhCand.V.electrons[j],nalep++,12);
688     for(size_t j=firstAddEle;j< vhCand.V.electrons.size();j++) aLeptons.set(vhCand.V.electrons[j],nalep++,12);
689 arizzi 1.8
690    
691     double maxBtag=-99999;
692     TLorentzVector bJet;
693     for(unsigned int j=0; j < vhCand.H.jets.size(); j++ ){
694     if (vhCand.H.jets[j].csv > maxBtag) { bJet=vhCand.H.jets[j].p4 ; maxBtag =vhCand.H.jets[j].csv; }
695     }
696     for(unsigned int j=0; j < vhCand.additionalJets.size(); j++ ){
697     if (vhCand.additionalJets[j].csv > maxBtag) { bJet=vhCand.additionalJets[j].p4 ; maxBtag =vhCand.additionalJets[j].csv; }
698     }
699     if(maxBtag > -99999)
700     {
701     TopHypo topQuark = TopMassReco::topMass(leptonForTop,bJet,vhCand.V.mets.at(0).p4);
702     top.mass = topQuark.p4.M();
703     top.pt = topQuark.p4.Pt();
704     top.wMass = topQuark.p4W.M();
705     } else {
706     top.mass = -99;
707     top.pt = -99;
708     top.wMass = -99;
709     }
710    
711    
712    
713 arizzi 1.1 //FIXME _outTree->Branch("nofLeptons15" , &nofLeptons15 , "nofLeptons15/I" );
714     nofLeptons20= vhCand.additionalLeptons();
715     // if(aux.mcC.size() >=2)
716     // std::cout << "C Must not be zero and it is ... " << aux.mcC[1].p4.Pt() << std::endl;
717     // if(aux.mcB.size() >=1)
718     // std::cout << "B Must not be zero and it is ... " << aux.mcB[0].p4.Pt() << std::endl;
719    
720 arizzi 1.3 // FIXME gendrcc=aux.genCCDeltaR(); (NEED EDM FIX)
721    
722     // FIXME gendrbb=aux.genBBDeltaR(); (NEED EDM FIX)
723 arizzi 1.1 genZpt=aux.mcZ.size() > 0 ? aux.mcZ[0].p4.Pt():-99;
724     genWpt=aux.mcW.size() > 0 ? aux.mcW[0].p4.Pt():-99;
725 arizzi 1.3
726 arizzi 1.1 //FIXME: _outTree->Branch("deltaPullAngleAK7", &deltaPullAngleAK7 , "deltaPullAngleAK7/F");
727    
728    
729    
730     _outTree->Fill();
731 arizzi 1.4
732 arizzi 1.1 }// closed event loop
733    
734     std::cout << "closing the file: " << inputFiles_[iFile] << std::endl;
735     inFile->Close();
736     // close input file
737     } // loop on files
738    
739    
740     std::cout << "Events: " << ievt <<std::endl;
741     std::cout << "TotalCount: " << totalcount <<std::endl;
742    
743    
744    
745     _outFile->cd();
746    
747     _outTree->Write();
748     _outFile->Write();
749     _outFile->Close();
750     return 0;
751     }
752    
753