ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.21
Committed: Tue Sep 13 16:16:32 2011 UTC (13 years, 8 months ago) by arizzi
Content type: text/plain
Branch: MAIN
CVS Tags: Sept14th2011_2, Sept14th2011
Changes since 1.20: +19 -2 lines
Log Message:
all leptons not used for V,  are now in the additional lepton, not only those passing the V selection cuts

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