ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.16
Committed: Mon Sep 12 13:50:44 2011 UTC (13 years, 8 months ago) by arizzi
Content type: text/plain
Branch: MAIN
Changes since 1.15: +33 -105 lines
Log Message:
factorize Weighters, add count histo and other fixes

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