ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler7TeV.cc
Revision: 1.5
Committed: Fri Jun 8 09:29:50 2012 UTC (12 years, 11 months ago) by bortigno
Content type: text/plain
Branch: MAIN
CVS Tags: EdmV41alpha1, EdmV33Jun12v2_consistent, Step2ForV33_v2, Step2ForV33_v1
Changes since 1.4: +6 -5 lines
Log Message:
fix in lheHT

File Contents

# User Rev Content
1 bortigno 1.1 #include <TH1F.h>
2     #include <TH3F.h>
3     #include "PhysicsTools/Utilities/interface/LumiReWeighting.h"
4     #include "PhysicsTools/Utilities/interface/Lumi3DReWeighting.h"
5     #include <TH2F.h>
6     #include <TROOT.h>
7     #include <TFile.h>
8     #include <TTree.h>
9     #include <TSystem.h>
10     #include "DataFormats/FWLite/interface/Event.h"
11     #include "DataFormats/FWLite/interface/Handle.h"
12     #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
13     #include "DataFormats/MuonReco/interface/Muon.h"
14     #include "DataFormats/PatCandidates/interface/Muon.h"
15     #include "PhysicsTools/FWLite/interface/TFileService.h"
16     #include "FWCore/ParameterSet/interface/ProcessDesc.h"
17     #include "FWCore/PythonParameterSet/interface/PythonProcessDesc.h"
18     #include "DataFormats/Math/interface/deltaR.h"
19     #include "DataFormats/Math/interface/deltaPhi.h"
20    
21     #include "DataFormats/FWLite/interface/LuminosityBlock.h"
22     #include "DataFormats/FWLite/interface/Run.h"
23     #include "DataFormats/Luminosity/interface/LumiSummary.h"
24    
25     #include "VHbbAnalysis/VHbbDataFormats/interface/HbbCandidateFinderAlgo.h"
26     #include "VHbbAnalysis/VHbbDataFormats/src/HbbCandidateFinderAlgo.cc"
27    
28     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbEvent.h"
29     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbEventAuxInfo.h"
30     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidate.h"
31     #include "VHbbAnalysis/VHbbDataFormats/interface/TriggerReader.h"
32     #include "VHbbAnalysis/VHbbDataFormats/interface/TopMassReco.h"
33    
34     //for IVF
35     #include "RecoBTag/SecondaryVertex/interface/SecondaryVertex.h"
36     #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
37     #include "DataFormats/GeometryVector/interface/GlobalVector.h"
38     #include "DataFormats/GeometryVector/interface/VectorUtil.h"
39     #include <DataFormats/GeometrySurface/interface/Surface.h>
40     #include "Math/SMatrix.h"
41    
42     //for LHE info
43     #include "SimDataFormats/GeneratorProducts/interface/LHEEventProduct.h"
44 bortigno 1.2 #include "SimDataFormats/GeneratorProducts/interface/LHERunInfoProduct.h"
45     //pdf reweighting
46    
47 bortigno 1.1
48     //Move class definition to Ntupler.h ?
49     //#include "VHbbAnalysis/VHbbDataFormats/interface/Ntupler.h"
50    
51     #include "ZSV/BAnalysis/interface/SimBHadron.h"
52     //btagging
53     #include "VHbbAnalysis/VHbbDataFormats/interface/BTagWeight.h"
54     //trigger
55     #include "VHbbAnalysis/VHbbDataFormats/interface/TriggerWeight.h"
56    
57     #include <sstream>
58     #include <string>
59    
60     #define MAXJ 30
61     #define MAXL 10
62     #define MAXB 10
63     #define MAXT 60
64     #define nMetUnc 24
65     //eleEnDown/Up, muEn, tauEn, JES, JER, Unclustered for type1 MET [0-11] and than type1p2 MET [12-23]
66    
67     struct CompareDeltaR {
68     CompareDeltaR(TLorentzVector p4dir_): p4dir(p4dir_) {}
69     bool operator()( const VHbbEvent::SimpleJet& j1, const VHbbEvent::SimpleJet& j2 ) const {
70     return j1.p4.DeltaR(p4dir) > j2.p4.DeltaR(p4dir);
71     }
72     TLorentzVector p4dir;
73     };
74    
75     const GlobalVector flightDirection(const TVector3 pv, const reco::Vertex &sv){
76     GlobalVector fdir(sv.position().X() - pv.X(),
77     sv.position().Y() - pv.Y(),
78     sv.position().Z() - pv.Z());
79     return fdir;
80     }
81    
82     bool jsonContainsEvent (const std::vector< edm::LuminosityBlockRange > &jsonVec,
83     const edm::EventBase &event)
84     {
85     // if the jsonVec is empty, then no JSON file was provided so all
86     // events should pass
87     if (jsonVec.empty())
88     {
89     return true;
90     }
91     bool (* funcPtr) (edm::LuminosityBlockRange const &,
92     edm::LuminosityBlockID const &) = &edm::contains;
93     edm::LuminosityBlockID lumiID (event.id().run(),
94     event.id().luminosityBlock());
95     std::vector< edm::LuminosityBlockRange >::const_iterator iter =
96     std::find_if (jsonVec.begin(), jsonVec.end(),
97     boost::bind(funcPtr, _1, lumiID) );
98     return jsonVec.end() != iter;
99    
100     }
101    
102 bortigno 1.2
103     #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
104     namespace LHAPDF {
105     void initPDFSet(int nset, int setid, int member=0);
106     int numberPDF(int nset);
107     void usePDFMember(int nset, int member);
108     double xfx(int nset, double x, double Q, int fl);
109     double getXmin(int nset, int member);
110     double getXmax(int nset, int member);
111     double getQ2min(int nset, int member);
112     double getQ2max(int nset, int member);
113     void extrapolate(bool extrapolate=true);
114     }
115    
116    
117 bortigno 1.1 float resolutionBias(float eta)
118     {
119     // return 0;//Nominal!
120     if(eta< 1.1) return 0.05;
121     if(eta< 2.5) return 0.10;
122     if(eta< 5) return 0.30;
123     return 0;
124     }
125    
126    
127     typedef struct
128     {
129     void set(const SimBHadron & sbhc, int i){
130     mass[i] = sbhc.mass();
131     pt[i] = sbhc.pt();
132     eta[i] = sbhc.eta();
133     phi[i] = sbhc.phi();
134     vtx_x[i] = sbhc.decPosition.x();
135     vtx_y[i] = sbhc.decPosition.y();
136     vtx_z[i] = sbhc.decPosition.z();
137     pdgId[i] = sbhc.pdgId();
138     status[i] = sbhc.status();
139     };
140     void reset(){
141     for(int i=0; i < MAXB; ++i){
142     mass[i] = -99; pt[i] = -99; eta[i] = -99; phi[i] = -99; vtx_x[i] = -99; vtx_y[i] = -99; vtx_z[i] = -99; pdgId[i] = -99; status[i] = -99;
143     }
144     };
145     float mass[MAXB];
146     float pt[MAXB];
147     float eta[MAXB];
148     float phi[MAXB];
149     float vtx_x[MAXB];
150     float vtx_y[MAXB];
151     float vtx_z[MAXB];
152     int pdgId[MAXB];
153     int status[MAXB];
154     // int quarkStatus[MAXB];
155     // int brotherStatus[MAXB];
156     // int otherId[MAXB];
157     // bool etaOk[MAXB];
158     // bool simOk[MAXB];
159     // bool trackOk[MAXB];
160     // bool cutOk[MAXB];
161     // bool cutNewOk[MAXB];
162     // bool mcMatchOk[MAXB];
163     // bool matchOk[MAXB];
164     } SimBHadronInfo;
165    
166    
167     typedef struct
168     {
169     void set( const reco::SecondaryVertex & recoSv, const TVector3 recoPv, int isv){
170     pt[isv] = recoSv.p4().Pt();
171     eta[isv] = flightDirection(recoPv,recoSv).eta();
172     phi[isv] = flightDirection(recoPv,recoSv).phi();
173     massBcand[isv] = recoSv.p4().M();
174     massSv[isv] = recoSv.p4().M();
175     dist3D[isv] = recoSv.dist3d().value();
176     distSig3D[isv] = recoSv.dist3d().significance();
177     dist2D[isv] = recoSv.dist2d().value();
178     distSig2D[isv] = recoSv.dist2d().significance();
179     dist3D_norm[isv] = recoSv.dist3d().value()/recoSv.p4().Gamma();
180     };
181     void reset(){
182     for(int i = 0; i < MAXB; ++i){
183     massBcand[i] = -99; massSv[i]= -99; pt[i] = -99; eta[i] = -99; phi[i] = -99; dist3D[i] = -99; distSig3D[i] = -99; dist2D[i] = -99; distSig2D[i] = -99; dist3D_norm[i] = -99;
184     }
185     };
186     float massBcand[MAXB];
187     float massSv[MAXB];
188     float pt[MAXB];
189     float eta[MAXB];
190     float phi[MAXB];
191     float dist3D[MAXB];
192     float distSig3D[MAXB];
193     float dist2D[MAXB];
194     float distSig2D[MAXB];
195     float dist3D_norm[MAXB];
196     } IVFInfo;
197    
198    
199     typedef struct
200     {
201     int HiggsFlag;
202     float mass;
203     float pt;
204     float eta;
205     float phi;
206     float dR;
207     float dPhi;
208     float dEta;
209     } HiggsInfo;
210    
211     typedef struct
212     {
213     int FatHiggsFlag;
214     float mass;
215     float pt;
216     float eta;
217     float phi;
218     float filteredmass;
219     float filteredpt;
220     float filteredeta;
221     float filteredphi;
222     // float dR;
223     // float dPhi;
224     // float dEta;
225     } FatHiggsInfo;
226    
227    
228    
229     typedef struct
230     {
231     float mass;
232     float pt;
233     float eta;
234     float phi;
235     float status;
236     float charge;
237     float momid;
238     } genParticleInfo;
239    
240    
241    
242     typedef struct
243    
244     {
245     float bmass;
246     float bpt;
247     float beta;
248     float bphi;
249     float bstatus;
250     float wdau1mass;
251     float wdau1pt;
252     float wdau1eta;
253     float wdau1phi;
254     float wdau1id;
255     float wdau2mass;
256     float wdau2pt;
257     float wdau2eta;
258     float wdau2phi;
259     float wdau2id;
260    
261    
262     } genTopInfo;
263    
264    
265    
266    
267     typedef struct
268     {
269     bool HiggsCSVtkSharing;
270     bool HiggsIPtkSharing;
271     bool HiggsSVtkSharing;
272     bool FatHiggsCSVtkSharing;
273     bool FatHiggsIPtkSharing;
274     bool FatHiggsSVtkSharing;
275     } TrackSharingInfo;
276    
277     typedef struct
278     {
279     float mass; //MT in case of W
280     float pt;
281     float eta;
282     float phi;
283     } TrackInfo;
284    
285    
286     struct LeptonInfo
287     {
288     void reset()
289     {
290     for(int i =0; i < MAXL;i++){
291     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; chargedPUIso[i]=-99; particleIso[i]=-99; dxy[i]=-99; dz[i]=-99; type[i]=-99; genPt[i]=-99; genEta[i]=-99; genPhi[i]=-99;
292     id80[i]=-99; id95[i]=-99; vbtf[i]=-99; id80NoIso[i]=-99;
293     charge[i]=-99;
294     }
295     }
296    
297     template <class Input> void set(const Input & i, int j,int t)
298     {
299     type[j]=t;
300     pt[j]=i.p4.Pt();
301     mass[j]=i.p4.M();
302     eta[j]=i.p4.Eta();
303     phi[j]=i.p4.Phi();
304     aodCombRelIso[j]=(i.hIso+i.eIso+i.tIso)/i.p4.Pt();
305     pfCombRelIso[j]=(i.pfChaIso+i.pfPhoIso+i.pfNeuIso)/i.p4.Pt();
306     photonIso[j]=i.pfPhoIso;
307     neutralHadIso[j]=i.pfNeuIso;
308     chargedHadIso[j]=i.pfChaIso;
309     chargedPUIso[j]=i.pfChaPUIso;
310     charge[j]=i.charge;
311     if(i.mcFourMomentum.Pt() > 0)
312     {
313     genPt[j]=i.mcFourMomentum.Pt();
314     genEta[j]=i.mcFourMomentum.Eta();
315     genPhi[j]=i.mcFourMomentum.Phi();
316     }
317     setSpecific(i,j);
318     }
319     template <class Input> void setSpecific(const Input & i, int j)
320     {
321     }
322    
323    
324    
325    
326     float mass[MAXL]; //MT in case of W
327     float pt[MAXL];
328     float eta[MAXL];
329     float phi[MAXL];
330     float aodCombRelIso[MAXL];
331     float pfCombRelIso[MAXL];
332     float photonIso[MAXL];
333     float neutralHadIso[MAXL];
334     float chargedHadIso[MAXL];
335     float chargedPUIso[MAXL];
336     float particleIso[MAXL];
337     float genPt[MAXL];
338     float genEta[MAXL];
339     float genPhi[MAXL];
340     float dxy[MAXL];
341     float dz[MAXL];
342     int type[MAXL];
343     float id80[MAXL];
344     float id95[MAXL];
345     float vbtf[MAXL];
346     float id80NoIso[MAXL];
347     float charge[MAXL];
348    
349     };
350    
351     template <> void LeptonInfo::setSpecific<VHbbEvent::ElectronInfo>(const VHbbEvent::ElectronInfo & i, int j){
352     id80[j]=i.id80;
353     id95[j]=i.id95;
354     id80NoIso[j]=(i.innerHits ==0 && !(fabs(i.convDist)<0.02 && fabs(i.convDcot)<0.02) &&
355     ((i.isEB && i.sihih<0.01 && fabs(i.Dphi)<0.06 && fabs(i.Deta)<0.004) || (i.isEE && i.sihih<0.03 && fabs(i.Dphi)<0.03 && fabs(i.Deta)<0.007)));
356     }
357     template <> void LeptonInfo::setSpecific<VHbbEvent::MuonInfo>(const VHbbEvent::MuonInfo & i, int j){
358     dxy[j]=i.ipDb;
359     dz[j]=i.zPVPt;
360     vbtf[j]=( i.globChi2<10 && i.nPixelHits>= 1 && i.globNHits != 0 && i.nHits > 10 && i.cat & 0x1 && i.cat & 0x2 && i.nMatches >=2 && i.ipDb<.2 &&
361     (i.pfChaIso+i.pfPhoIso+i.pfNeuIso)/i.p4.Pt()<.15 && fabs(i.p4.Eta())<2.4 && i.p4.Pt()>20 ) ;
362    
363     }
364    
365    
366     typedef struct
367     {
368     float et;
369     float sumet;
370     float sig;
371     float phi;
372     } METInfo;
373    
374    
375     typedef struct
376     {
377    
378     float et[nMetUnc]; float phi[nMetUnc]; float sumet[nMetUnc];
379     template <class Input> void set(const Input & i, int j)
380     {
381     et[j]=i.p4.Pt();
382     phi[j]=i.p4.Phi();
383     sumet[j]=i.sumEt;
384    
385     }
386     } METUncInfo ;
387    
388    
389     typedef struct
390     {
391     float mht;
392     float ht;
393     float sig;
394     float phi;
395     } MHTInfo;
396    
397     typedef struct
398     {
399     float mass;
400     float pt;
401     float wMass;
402     } TopInfo;
403    
404     typedef struct
405     {
406     int run;
407     int lumi;
408     int event;
409     int json;
410     } EventInfo;
411    
412     typedef struct
413     {
414     void set(const VHbbEvent::SimpleJet & j, int i)
415     {
416     pt[i]=j.p4.Pt();
417     eta[i]=j.p4.Eta();
418     phi[i]=j.p4.Phi();
419     e[i]=j.p4.E();
420     csv[i]=j.csv;
421     csvivf[i]=j.csvivf;
422     cmva[i]=j.cmva;
423     numTracksSV[i] = j.vtxNTracks;
424     vtxMass[i]= j.vtxMass;
425     vtxPt[i]= j.vtxP4.Pt();
426     vtxEta[i]= j.vtxP4.Eta();
427     vtxPhi[i]= j.vtxP4.Phi();
428     vtxE[i]= j.vtxP4.E();
429     vtx3dL[i] = j.vtx3dL;
430     vtx3deL[i] = j.vtx3deL;
431     chf[i]=j.chargedHadronEFraction;
432     nhf[i] =j.neutralHadronEFraction;
433     cef[i] =j.chargedEmEFraction;
434     nef[i] =j.neutralEmEFraction;
435     nconstituents[i] =j.nConstituents;
436     nch[i]=j.ntracks;
437     SF_CSVL[i]=j.SF_CSVL;
438     SF_CSVM[i]=j.SF_CSVM;
439     SF_CSVT[i]=j.SF_CSVT;
440     SF_CSVLerr[i]=j.SF_CSVLerr;
441     SF_CSVMerr[i]=j.SF_CSVMerr;
442     SF_CSVTerr[i]=j.SF_CSVTerr;
443    
444     flavour[i]=j.flavour;
445     isSemiLeptMCtruth[i]=j.isSemiLeptMCtruth;
446     isSemiLept[i]=j.isSemiLept;
447     SoftLeptpdgId[i] = j.SoftLeptpdgId;
448     SoftLeptIdlooseMu[i] = j.SoftLeptIdlooseMu;
449     SoftLeptId95[i] = j.SoftLeptId95;
450     SoftLeptPt[i] = j.SoftLeptPt;
451     SoftLeptdR[i] = j.SoftLeptdR;
452     SoftLeptptRel[i] = j.SoftLeptptRel;
453     SoftLeptRelCombIso[i] = j.SoftLeptRelCombIso;
454     if(j.bestMCp4.Pt() > 0)
455     {
456     genPt[i]=j.bestMCp4.Pt();
457     genEta[i]=j.bestMCp4.Eta();
458     genPhi[i]=j.bestMCp4.Phi();
459     }
460     JECUnc[i]=j.jecunc;
461     id[i]=jetId(i);
462     ptRaw[i]=j.ptRaw;
463     ptLeadTrack[i]=j.ptLeadTrack;
464    
465     }
466     bool jetId(int i)
467     {
468     if(nhf[i] > 0.99) return false;
469     if(nef[i] > 0.99) return false;
470     if(nconstituents[i] <= 1) return false;
471     if(fabs(eta[i])<2.5) {
472     if(cef[i] > 0.99) return false;
473     if(chf[i] == 0) return false;
474     if(nch[i]== 0) return false;
475     }
476     return true;
477     }
478     void reset()
479     {
480     for(int i=0;i<MAXJ;i++) {
481     pt[i]=-99; eta[i]=-99; phi[i]=-99;e[i]=-99;csv[i]=-99;
482     csvivf[i]=-99; cmva[i]=-99;
483     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; isSemiLeptMCtruth[i]=-99; isSemiLept[i]=-99;
484     SoftLeptpdgId[i] = -99; SoftLeptIdlooseMu[i] = -99; SoftLeptId95[i] = -99; SoftLeptPt[i] = -99; SoftLeptdR[i] = -99; SoftLeptptRel[i] = -99; SoftLeptRelCombIso[i] = -99;
485     genPt[i]=-99; genEta[i]=-99; genPhi[i]=-99; JECUnc[i]=-99; ptRaw[i]=-99.; ptLeadTrack[i]=-99.;
486     }
487     }
488     float pt[MAXJ];
489     float eta[MAXJ];
490     float phi[MAXJ];
491     float e[MAXJ];
492     float csv[MAXJ];
493     float csvivf[MAXJ];
494     float cmva[MAXJ];
495     float cosTheta[MAXJ];
496     int numTracksSV[MAXJ];
497     float chf[MAXJ];
498     float nhf[MAXJ];
499     float cef[MAXJ];
500     float nef[MAXJ];
501     float nch[MAXJ];
502     float nconstituents[MAXJ];
503     float flavour[MAXJ];
504     int isSemiLept[MAXJ];
505     int isSemiLeptMCtruth[MAXJ];
506     int SoftLeptpdgId[MAXJ] ;
507     int SoftLeptIdlooseMu[MAXJ] ;
508     int SoftLeptId95[MAXJ] ;
509     float SoftLeptPt[MAXJ] ;
510     float SoftLeptdR[MAXJ] ;
511     float SoftLeptptRel[MAXJ] ;
512     float SoftLeptRelCombIso[MAXJ];
513     float genPt[MAXJ];
514     float genEta[MAXJ];
515     float genPhi[MAXJ];
516     float JECUnc[MAXJ];
517     float vtxMass[MAXJ];
518     float vtxPt[MAXJ];
519     float vtxEta[MAXJ];
520     float vtxPhi[MAXJ];
521     float vtxE[MAXJ];
522     float vtx3dL [MAXJ];
523     float vtx3deL[MAXJ];
524     bool id[MAXJ];
525     float SF_CSVL[MAXJ];
526     float SF_CSVM[MAXJ];
527     float SF_CSVT[MAXJ];
528     float SF_CSVLerr[MAXJ];
529     float SF_CSVMerr[MAXJ];
530     float SF_CSVTerr[MAXJ];
531     float ptRaw[MAXJ];
532     float ptLeadTrack[MAXJ];
533     } JetInfo;
534    
535     int main(int argc, char* argv[])
536     {
537     gROOT->Reset();
538    
539    
540    
541     TTree *_outTree;
542     IVFInfo IVF;
543     SimBHadronInfo SimBs;
544     float rho,rho25;
545     int nPVs;
546     METInfo MET;
547     METInfo fakeMET;
548     METInfo METnoPU;
549     METInfo METnoPUCh;
550     METInfo METtype1corr;
551     METInfo METtype1p2corr;
552     METInfo METnoPUtype1corr;
553     METInfo METnoPUtype1p2corr;
554    
555     MHTInfo MHT;
556    
557     METUncInfo metUnc;
558    
559    
560     TopInfo top;
561     EventInfo EVENT;
562     // JetInfo jet1,jet2, addJet1, addJet2;
563     // lepton1,lepton2;
564     JetInfo hJets, aJets, fathFilterJets, aJetsFat;
565     LeptonInfo vLeptons, aLeptons;
566     int naJets=0, nhJets=0, nfathFilterJets=0, naJetsFat=0;
567     HiggsInfo H,SVH,SimBsH;
568     FatHiggsInfo FatH;
569     genParticleInfo genZ, genZstar, genWstar, genW, genH, genB, genBbar; //add here the fatjet higgs
570     genTopInfo genTop, genTbar;
571     TrackInfo V;
572     int nvlep=0,nalep=0;
573     float lheV_pt=0; //for the Madgraph sample stitching
574 bortigno 1.3 float lheHT=0; //for the Madgraph sample stitching
575     float lheNj=0; //for the Madgraph sample stitching
576 bortigno 1.2 float PDFweight=1.; // for pdf reweighting (only madgraph)
577 bortigno 1.1 TrackSharingInfo TkSharing; // track sharing info;
578    
579     float HVdPhi,HVMass,HMETdPhi,VMt,deltaPullAngle,deltaPullAngleAK7,deltaPullAngle2,deltaPullAngle2AK7,gendrcc,gendrbb, genZpt, genWpt, genHpt, weightTrig, weightTrigMay,weightTrigV4, weightTrigMET, weightTrigOrMu30, minDeltaPhijetMET, jetPt_minDeltaPhijetMET , PUweight, PUweight2011B;
580     float PU0,PUp1,PUm1;
581    
582     float weightEleRecoAndId,weightEleTrigJetMETPart, weightEleTrigElePart,weightEleTrigEleAugPart;
583     float weightTrigMET80, weightTrigMET100, weightTrig2CJet20 , weightTrigMET150 , weightTrigMET802CJet, weightTrigMET1002CJet, weightTrigMETLP ;
584    
585     int WplusMode,WminusMode;
586     int Vtype,nSvs=0,nSimBs=0,numJets,numBJets,eventFlav;
587     // bool isMET80_CJ80, ispfMHT150, isMET80_2CJ20,isMET65_2CJ20, isJETID,isIsoMu17;
588     bool triggerFlags[500],hbhe,ecalFlag,totalKinematics, cschaloFlag, hcallaserFlag, trackingfailureFlag ;
589    
590    
591     float btag1T2CSF=1.,btag2TSF=1.,btag1TSF=1.,btagA0CSF=1., btagA0TSF=1., btag2CSF=1., btag1TA1C=1.;
592     // ----------------------------------------------------------------------
593     // First Part:
594     //
595     // * enable the AutoLibraryLoader
596     // * book the histograms of interest
597     // * open the input file
598     // ----------------------------------------------------------------------
599    
600     // load framework libraries
601     gSystem->Load("libFWCoreFWLite");
602     gSystem->Load("libDataFormatsFWLite");
603     AutoLibraryLoader::enable();
604 bortigno 1.2
605     //init the PDF set. Need to check for each sample beacuse pdfset and pdfmember info missing in AODSIM. (for Madgraph always (1,10042,0) : mctqe6l)
606     // LHAPDF::initPDFSet(1,_pdfset, _pdfmember);
607     LHAPDF::initPDFSet(1, 10042, 0);
608 bortigno 1.1
609     // parse arguments
610     if ( argc < 2 ) {
611     return 0;
612     }
613    
614     std::vector<VHbbCandidate> * candZlocal = new std::vector<VHbbCandidate>;
615     std::vector<VHbbCandidate> * candWlocal = new std::vector<VHbbCandidate>;
616    
617     // get the python configuration
618     PythonProcessDesc builder(argv[1]);
619     const edm::ParameterSet& in = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("fwliteInput" );
620     const edm::ParameterSet& out = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("fwliteOutput");
621     const edm::ParameterSet& ana = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("Analyzer");
622    
623     std::vector<edm::LuminosityBlockRange> jsonVector;
624     if ( in.exists("lumisToProcess") )
625     {
626     std::vector<edm::LuminosityBlockRange> const & lumisTemp =
627     in.getUntrackedParameter<std::vector<edm::LuminosityBlockRange> > ("lumisToProcess");
628     jsonVector.resize( lumisTemp.size() );
629     copy( lumisTemp.begin(), lumisTemp.end(), jsonVector.begin() );
630     }
631    
632     // now get each parameter
633     int maxEvents_( in.getParameter<int>("maxEvents") );
634     int skipEvents_( in.getParameter<int>("skipEvents") );
635     int runMin_( in.getParameter<int>("runMin") );
636     int runMax_( in.getParameter<int>("runMax") );
637     unsigned int outputEvery_( in.getParameter<unsigned int>("outputEvery") );
638     std::string outputFile_( out.getParameter<std::string>("fileName" ) );
639     std::vector<std::string> triggers( ana.getParameter<std::vector<std::string> >("triggers") );
640     double btagThr = ana.getParameter<double>("bJetCountThreshold" );
641     bool fromCandidate = ana.getParameter<bool>("readFromCandidates");
642     bool useHighestPtHiggsZ = ana.getParameter<bool>("useHighestPtHiggsZ");
643     bool useHighestPtHiggsW = ana.getParameter<bool>("useHighestPtHiggsW");
644     HbbCandidateFinderAlgo * algoZ = new HbbCandidateFinderAlgo(ana.getParameter<bool>("verbose"), ana.getParameter<double>("jetPtThresholdZ"),useHighestPtHiggsZ);
645     HbbCandidateFinderAlgo * algoW = new HbbCandidateFinderAlgo(ana.getParameter<bool>("verbose"), ana.getParameter<double>("jetPtThresholdW"),useHighestPtHiggsW );
646     HbbCandidateFinderAlgo * algoRecoverLowPt = new HbbCandidateFinderAlgo(ana.getParameter<bool>("verbose"), 15, true);
647    
648     TriggerWeight triggerWeight(ana);
649     BTagWeight btag(2); // 2 operating points "Custom" = 0.5 and "Tight = 0.898"
650     BTagSampleEfficiency btagEff( ana.getParameter<std::string>("btagEffFileName" ).c_str() );
651    
652     std::vector<std::string> inputFiles_( in.getParameter<std::vector<std::string> >("fileNames") );
653     // std::string inputFile( in.getParameter<std::string> ("fileName") );
654    
655     std::string PUmcfileName_ = in.getParameter<std::string> ("PUmcfileName") ;
656     std::string PUmcfileName2011B_ = in.getParameter<std::string> ("PUmcfileName2011B") ;
657    
658     std::string PUdatafileName_ = in.getParameter<std::string> ("PUdatafileName") ;
659     std::string PUdatafileName2011B_ = in.getParameter<std::string> ("PUdatafileName2011B") ;
660     std::string Weight3DfileName_ = in.getParameter<std::string> ("Weight3DfileName") ;
661    
662    
663    
664     bool isMC_( ana.getParameter<bool>("isMC") );
665     TriggerReader trigger(isMC_);
666     TriggerReader patFilters(false);
667    
668     edm::LumiReWeighting lumiWeights;
669     edm::Lumi3DReWeighting lumiWeights2011B;
670     if(isMC_)
671     {
672     lumiWeights = edm::LumiReWeighting(PUmcfileName_,PUdatafileName_ , "pileup", "pileup");
673    
674     lumiWeights2011B = edm::Lumi3DReWeighting(PUmcfileName2011B_,PUdatafileName2011B_ , "pileup", "pileup");
675     if(Weight3DfileName_!="")
676     { lumiWeights2011B.weight3D_init(Weight3DfileName_.c_str()); }
677     else
678     {
679     lumiWeights2011B.weight3D_init(1.0); // generate the weights the fisrt time;
680     }
681    
682     }
683    
684     // TFile *_outPUFile = new TFile((outputFile_+"_PU").c_str(), "recreate");
685     TFile *_outFile = new TFile(outputFile_.c_str(), "recreate");
686     TH1F * count = new TH1F("Count","Count", 1,0,2 );
687     TH1F * countWithPU = new TH1F("CountWithPU","CountWithPU", 1,0,2 );
688     TH1F * countWithPU2011B = new TH1F("CountWithPU2011B","CountWithPU2011B", 1,0,2 );
689     TH3F * input3DPU = new TH3F("Input3DPU","Input3DPU", 36,-0.5,35.5,36,-0.5,35.5, 36,-0.5,35.5 );
690    
691     TH1F * pu = new TH1F("pileup","",51,-0.5,50.5);
692     _outTree = new TTree("tree", "myTree");
693    
694     _outTree->Branch("H" , &H , "HiggsFlag/I:mass/F:pt/F:eta:phi/F:dR/F:dPhi/F:dEta/F");
695     _outTree->Branch("V" , &V , "mass/F:pt/F:eta:phi/F");
696     _outTree->Branch("FatH" , &FatH , "FatHiggsFlag/I:mass/F:pt/F:eta:phi/F:filteredmass/F:filteredpt/F:filteredeta/F:filteredphi/F");
697     _outTree->Branch("lheV_pt" , &lheV_pt , "lheV_pt/F");
698 bortigno 1.3 _outTree->Branch("lheHT" , &lheHT , "lheHT/F");
699     _outTree->Branch("lheNj" , &lheNj , "lheNj/F");
700 bortigno 1.2 _outTree->Branch("PDFweight" , &PDFweight , "PDFweight/F");
701 bortigno 1.1 _outTree->Branch("genZ" , &genZ , "mass/F:pt/F:eta:phi/F:status/F:charge:momid/F");
702     _outTree->Branch("genZstar" , &genZstar , "mass/F:pt/F:eta:phi/F:status/F:charge:momid/F");
703     _outTree->Branch("genW" , &genW , "mass/F:pt/F:eta:phi/F:status/F:charge:momid/F");
704     _outTree->Branch("genWstar" , &genWstar , "mass/F:pt/F:eta:phi/F:status/F:charge:momid/F");
705     _outTree->Branch("genH" , &genH , "mass/F:pt/F:eta:phi/F:status/F:charge:momid/F");
706     _outTree->Branch("genB" , &genB , "mass/F:pt/F:eta:phi/F:status/F:charge:momid/F");
707     _outTree->Branch("genBbar" , &genBbar , "mass/F:pt/F:eta:phi/F:status/F:charge:momid/F");
708    
709     _outTree->Branch("genTop" , &genTop , "bmass/F:bpt/F:beta:bphi/F:bstatus/F:wdau1mass/F:wdau1pt/F:wdau1eta:wdau1phi/F:wdau1id/F:wdau2mass/F:wdau2pt/F:wdau2eta:wdau2phi/F:wdau2id/F");
710     _outTree->Branch("genTbar" , &genTbar , "bmass/F:bpt/F:beta:bphi/F:bstatus/F:wdau1mass/F:wdau1pt/F:wdau1eta:wdau1phi/F:wdau1id/F:wdau2mass/F:wdau2pt/F:wdau2eta:wdau2phi/F:wdau2id/F");
711    
712     _outTree->Branch("TkSharing", &TkSharing, "HiggsCSVtkSharing/b:HiggsIPtkSharing:HiggsSVtkSharing:FatHiggsCSVtkSharing:FatHiggsIPtkSharing:FatHiggsSVtkSharing");
713    
714     _outTree->Branch("nhJets" , &nhJets , "nhJets/I");
715     _outTree->Branch("nfathFilterJets", &nfathFilterJets, "nfathFilterJets/I");
716     _outTree->Branch("naJets" , &naJets , "naJets/I");
717    
718    
719    
720     _outTree->Branch("hJet_pt",hJets.pt ,"pt[nhJets]/F");
721     _outTree->Branch("hJet_eta",hJets.eta ,"eta[nhJets]/F");
722     _outTree->Branch("hJet_phi",hJets.phi ,"phi[nhJets]/F");
723     _outTree->Branch("hJet_e",hJets.e ,"e[nhJets]/F");
724     _outTree->Branch("hJet_csv",hJets.csv ,"csv[nhJets]/F");
725     _outTree->Branch("hJet_csvivf",hJets.csvivf ,"csvivf[nhJets]/F");
726     _outTree->Branch("hJet_cmva",hJets.cmva ,"cmva[nhJets]/F");
727     _outTree->Branch("hJet_cosTheta",hJets.cosTheta ,"cosTheta[nhJets]/F");
728     _outTree->Branch("hJet_numTracksSV",hJets.numTracksSV ,"numTracksSV[nhJets]/I");
729     _outTree->Branch("hJet_chf",hJets.chf ,"chf[nhJets]/F");
730     _outTree->Branch("hJet_nhf",hJets.nhf ,"nhf[nhJets]/F");
731     _outTree->Branch("hJet_cef",hJets.cef ,"cef[nhJets]/F");
732     _outTree->Branch("hJet_nef",hJets.nef ,"nef[nhJets]/F");
733     _outTree->Branch("hJet_nch",hJets.nch ,"nch[nhJets]/F");
734     _outTree->Branch("hJet_nconstituents",hJets.nconstituents ,"nconstituents[nhJets]");
735     _outTree->Branch("hJet_flavour",hJets.flavour ,"flavour[nhJets]/F");
736     _outTree->Branch("hJet_isSemiLept",hJets.isSemiLept ,"isSemiLept[nhJets]/I");
737     _outTree->Branch("hJet_isSemiLeptMCtruth",hJets.isSemiLeptMCtruth ,"isSemiLeptMCtruth[nhJets]/I");
738     _outTree->Branch("hJet_SoftLeptpdgId", hJets.SoftLeptpdgId , "SoftLeptpdgId[nhJets]/I");
739     _outTree->Branch("hJet_SoftLeptIdlooseMu", hJets.SoftLeptIdlooseMu , "SoftLeptIdlooseMu[nhJets]/I");
740     _outTree->Branch("hJet_SoftLeptId95", hJets.SoftLeptId95 , "SoftLeptId95[nhJets]/I");
741     _outTree->Branch("hJet_SoftLeptPt", hJets.SoftLeptPt , "SoftLeptPt[nhJets]/F");
742     _outTree->Branch("hJet_SoftLeptdR", hJets.SoftLeptdR , "SoftLeptdR[nhJets]/F");
743     _outTree->Branch("hJet_SoftLeptptRel", hJets.SoftLeptptRel , "SoftLeptptRel[nhJets]/F");
744     _outTree->Branch("hJet_SoftLeptRelCombIso", hJets.SoftLeptRelCombIso , "SoftLeptRelCombIso[nhJets]/F");
745     _outTree->Branch("hJet_genPt",hJets.genPt ,"genPt[nhJets]/F");
746     _outTree->Branch("hJet_genEta",hJets.genEta ,"genEta[nhJets]/F");
747     _outTree->Branch("hJet_genPhi",hJets.genPhi ,"genPhi[nhJets]/F");
748     _outTree->Branch("hJet_JECUnc",hJets.JECUnc ,"JECUnc[nhJets]/F");
749     _outTree->Branch("hJet_vtxMass",hJets.vtxMass ,"vtxMass[nhJets]/F");
750     _outTree->Branch("hJet_vtxPt",hJets.vtxPt ,"vtxPt[nhJets]/F");
751     _outTree->Branch("hJet_vtxEta",hJets.vtxEta ,"vtxEta[nhJets]/F");
752     _outTree->Branch("hJet_vtxPhi",hJets.vtxPhi ,"vtxPhi[nhJets]/F");
753     _outTree->Branch("hJet_vtxE",hJets.vtxE ,"vtxE[nhJets]/F");
754     _outTree->Branch("hJet_vtx3dL",hJets.vtx3dL ,"vtx3dL[nhJets]/F");
755     _outTree->Branch("hJet_vtx3deL",hJets.vtx3deL ,"vtx3deL[nhJets]/F");
756     _outTree->Branch("hJet_id",hJets.id ,"id[nhJets]/b");
757     _outTree->Branch("hJet_SF_CSVL",hJets.SF_CSVL ,"SF_CSVL[nhJets]/b");
758     _outTree->Branch("hJet_SF_CSVM",hJets.SF_CSVM ,"SF_CSVM[nhJets]/b");
759     _outTree->Branch("hJet_SF_CSVT",hJets.SF_CSVT ,"SF_CSVT[nhJets]/b");
760     _outTree->Branch("hJet_SF_CSVLerr",hJets.SF_CSVLerr ,"SF_CSVLerr[nhJets]/b");
761     _outTree->Branch("hJet_SF_CSVMerr",hJets.SF_CSVMerr ,"SF_CSVMerr[nhJets]/b");
762     _outTree->Branch("hJet_SF_CSVTerr",hJets.SF_CSVTerr ,"SF_CSVTerr[nhJets]/b");
763     _outTree->Branch("hJet_ptRaw",hJets.ptRaw ,"ptRaw[nhJets]/F");
764     _outTree->Branch("hJet_ptLeadTrack",hJets.ptLeadTrack ,"ptLeadTrack[nhJets]/F");
765    
766     _outTree->Branch("fathFilterJets_pt",fathFilterJets.pt ,"pt[nfathFilterJets]/F");
767     _outTree->Branch("fathFilterJets_eta",fathFilterJets.eta ,"eta[nfathFilterJets]/F");
768     _outTree->Branch("fathFilterJets_phi",fathFilterJets.phi ,"phi[nfathFilterJets]/F");
769     _outTree->Branch("fathFilterJets_e",fathFilterJets.e ,"e[nfathFilterJets]/F");
770     _outTree->Branch("fathFilterJets_csv",fathFilterJets.csv ,"csv[nfathFilterJets]/F");
771     _outTree->Branch("fathFilterJets_chf",fathFilterJets.chf ,"chf[nfathFilterJets]/F");
772     _outTree->Branch("fathFilterJets_ptRaw",fathFilterJets.ptRaw ,"ptRaw[nfathFilterJets]/F");
773     _outTree->Branch("fathFilterJets_ptLeadTrack",fathFilterJets.ptLeadTrack ,"ptLeadTrack[nfathFilterJets]/F");
774     _outTree->Branch("fathFilterJets_flavour",fathFilterJets.flavour ,"flavour[nfathFilterJets]/F");
775     _outTree->Branch("fathFilterJets_isSemiLept",fathFilterJets.isSemiLept ,"isSemiLept[nfathFilterJets]/F");
776     _outTree->Branch("fathFilterJets_isSemiLeptMCtruth",fathFilterJets.isSemiLeptMCtruth ,"isSemiLeptMCtruth[nfathFilterJets]/F");
777     _outTree->Branch("fathFilterJets_genPt",fathFilterJets.genPt ,"genPt[nfathFilterJets]/F");
778     _outTree->Branch("fathFilterJets_genEta",fathFilterJets.genEta ,"genEta[nfathFilterJets]/F");
779     _outTree->Branch("fathFilterJets_genPhi",fathFilterJets.genPhi ,"genPhi[nfathFilterJets]/F");
780     _outTree->Branch("fathFilterJets_vtxMass",fathFilterJets.vtxMass ,"vtxMass[nfathFilterJets]/F");
781     _outTree->Branch("fathFilterJets_vtx3dL",fathFilterJets.vtx3dL ,"vtx3dL[nfathFilterJets]/F");
782     _outTree->Branch("fathFilterJets_vtx3deL",fathFilterJets.vtx3deL ,"vtx3deL[nfathFilterJets]/F");
783     _outTree->Branch("fathFilterJets_vtxPt",fathFilterJets.vtxPt ,"vtxPt[nfathFilterJets]/F");
784     _outTree->Branch("fathFilterJets_vtxEta",fathFilterJets.vtxEta ,"vtxEta[nfathFilterJets]/F");
785     _outTree->Branch("fathFilterJets_vtxPhi",fathFilterJets.vtxPhi ,"vtxPhi[nfathFilterJets]/F");
786     _outTree->Branch("fathFilterJets_vtxE",fathFilterJets.vtxE ,"vtxE[nfathFilterJets]/F");
787    
788    
789     // _outTree->Branch("fathFilterJets_pt",fathFilterJets.pt ,"pt[nfathFilterJets]/F");
790     // _outTree->Branch("fathFilterJets_eta",fathFilterJets.eta ,"eta[nfathFilterJets]/F");
791     // _outTree->Branch("fathFilterJets_phi",fathFilterJets.phi ,"phi[nfathFilterJets]/F");
792     // _outTree->Branch("fathFilterJets_e",fathFilterJets.e ,"e[nfathFilterJets]/F");
793     // _outTree->Branch("fathFilterJets_csv",fathFilterJets.csv ,"csv[nfathFilterJets]/F");
794     _outTree->Branch("fathFilterJets_csvivf",fathFilterJets.csvivf ,"csvivf[nfathFilterJets]/F");
795     _outTree->Branch("fathFilterJets_cmva",fathFilterJets.cmva ,"cmva[nfathFilterJets]/F");
796     // _outTree->Branch("fathFilterJets_flavour",fathFilterJets.flavour ,"flavour[nfathFilterJets]/F");
797    
798    
799     _outTree->Branch("aJet_pt",aJets.pt ,"pt[naJets]/F");
800     _outTree->Branch("aJet_eta",aJets.eta ,"eta[naJets]/F");
801     _outTree->Branch("aJet_phi",aJets.phi ,"phi[naJets]/F");
802     _outTree->Branch("aJet_e",aJets.e ,"e[naJets]/F");
803     _outTree->Branch("aJet_csv",aJets.csv ,"csv[naJets]/F");
804     _outTree->Branch("aJet_csvivf",aJets.csvivf ,"csvivf[naJets]/F");
805     _outTree->Branch("aJet_cmva",aJets.cmva ,"cmva[naJets]/F");
806     _outTree->Branch("aJet_cosTheta",aJets.cosTheta ,"cosTheta[naJets]/F");
807     _outTree->Branch("aJet_numTracksSV",aJets.numTracksSV ,"numTracksSV[naJets]/I");
808     _outTree->Branch("aJet_chf",aJets.chf ,"chf[naJets]/F");
809     _outTree->Branch("aJet_nhf",aJets.nhf ,"nhf[naJets]/F");
810     _outTree->Branch("aJet_cef",aJets.cef ,"cef[naJets]/F");
811     _outTree->Branch("aJet_nef",aJets.nef ,"nef[naJets]/F");
812     _outTree->Branch("aJet_nch",aJets.nch ,"nch[naJets]/F");
813     _outTree->Branch("aJet_nconstituents",aJets.nconstituents ,"nconstituents[naJets]");
814     _outTree->Branch("aJet_flavour",aJets.flavour ,"flavour[naJets]/F");
815     _outTree->Branch("aJet_isSemiLept",aJets.isSemiLept ,"isSemiLept[naJets]/I");
816     _outTree->Branch("aJet_isSemiLeptMCtruth",aJets.isSemiLeptMCtruth ,"isSemiLeptMCtruth[naJets]/I");
817     _outTree->Branch("aJet_SoftLeptpdgId",aJets.SoftLeptpdgId , "SoftLeptpdgId[naJets]/I");
818     _outTree->Branch("aJet_SoftLeptIdlooseMu", aJets.SoftLeptIdlooseMu , "SoftLeptIdlooseMu[naJets]/I");
819     _outTree->Branch("aJet_SoftLeptId95", aJets.SoftLeptId95 , "SoftLeptId95[naJets]/I");
820     _outTree->Branch("aJet_SoftLeptPt", aJets.SoftLeptPt , "SoftLeptPt[naJets]/F");
821     _outTree->Branch("aJet_SoftLeptdR", aJets.SoftLeptdR , "SoftLeptdR[naJets]/F");
822     _outTree->Branch("aJet_SoftLeptptRel", aJets.SoftLeptptRel , "SoftLeptptRel[naJets]/F");
823     _outTree->Branch("aJet_SoftLeptRelCombIso", aJets.SoftLeptRelCombIso , "SoftLeptRelCombIso[naJets]/F");
824    
825     _outTree->Branch("aJet_genPt",aJets.genPt ,"genPt[naJets]/F");
826     _outTree->Branch("aJet_genEta",aJets.genEta ,"genEta[naJets]/F");
827     _outTree->Branch("aJet_genPhi",aJets.genPhi ,"genPhi[naJets]/F");
828     _outTree->Branch("aJet_JECUnc",aJets.JECUnc ,"JECUnc[naJets]/F");
829     _outTree->Branch("aJet_vtxMass",aJets.vtxMass ,"vtxMass[naJets]/F");
830     _outTree->Branch("aJet_vtx3dL",aJets.vtx3dL ,"vtx3dL[naJets]/F");
831     _outTree->Branch("aJet_vtx3deL",aJets.vtx3deL ,"vtx3deL[naJets]/F");
832     _outTree->Branch("aJet_id",aJets.id ,"id[naJets]/b");
833     _outTree->Branch("aJet_SF_CSVL",aJets.SF_CSVL ,"SF_CSVL[naJets]/b");
834     _outTree->Branch("aJet_SF_CSVM",aJets.SF_CSVM ,"SF_CSVM[naJets]/b");
835     _outTree->Branch("aJet_SF_CSVT",aJets.SF_CSVT ,"SF_CSVT[naJets]/b");
836     _outTree->Branch("aJet_SF_CSVLerr",aJets.SF_CSVLerr ,"SF_CSVLerr[naJets]/b");
837     _outTree->Branch("aJet_SF_CSVMerr",aJets.SF_CSVMerr ,"SF_CSVMerr[naJets]/b");
838     _outTree->Branch("aJet_SF_CSVTerr",aJets.SF_CSVTerr ,"SF_CSVTerr[naJets]/b");
839     _outTree->Branch("aJet_ptRaw",aJets.ptRaw ,"ptRaw[naJets]/F");
840    
841     _outTree->Branch("naJetsFat" , &naJetsFat , "naJetsFat/I");
842     _outTree->Branch("aJetFat_pt",aJetsFat.pt ,"pt[naJetsFat]/F");
843     _outTree->Branch("aJetFat_eta",aJetsFat.eta ,"eta[naJetsFat]/F");
844     _outTree->Branch("aJetFat_phi",aJetsFat.phi ,"phi[naJetsFat]/F");
845     _outTree->Branch("aJetFat_e",aJetsFat.e ,"e[naJetsFat]/F");
846     _outTree->Branch("aJetFat_csv",aJetsFat.csv ,"csv[naJetsFat]/F");
847    
848    
849     _outTree->Branch("numJets" , &numJets , "numJets/I" );
850     _outTree->Branch("numBJets" , &numBJets , "numBJets/I" );
851     _outTree->Branch("deltaPullAngle", &deltaPullAngle , "deltaPullAngle/F");
852     _outTree->Branch("deltaPullAngle2", &deltaPullAngle2 , "deltaPullAngle2/F");
853     _outTree->Branch("gendrcc" , &gendrcc , "gendrcc/F");
854     _outTree->Branch("gendrbb" , &gendrbb , "gendrbb/F");
855     _outTree->Branch("genZpt" , &genZpt , "genZpt/F");
856     _outTree->Branch("genWpt" , &genWpt , "genWpt/F");
857     _outTree->Branch("genHpt" , &genHpt , "genHpt/F");
858     _outTree->Branch("weightTrig" , &weightTrig , "weightTrig/F");
859     _outTree->Branch("weightTrigMay" , &weightTrigMay , "weightTrigMay/F");
860     _outTree->Branch("weightTrigV4" , &weightTrigV4 , "weightTrigV4/F");
861     _outTree->Branch("weightTrigMET" , &weightTrigMET , "weightTrigMET/F");
862     _outTree->Branch("weightTrigOrMu30" , &weightTrigOrMu30 , "weightTrigOrMu30/F");
863     _outTree->Branch("weightEleRecoAndId" , &weightEleRecoAndId , "weightEleRecoAndId/F");
864     _outTree->Branch("weightEleTrigJetMETPart" , &weightEleTrigJetMETPart , "weightEleTrigJetMETPart/F");
865     _outTree->Branch("weightEleTrigElePart" , &weightEleTrigElePart , "weightEleTrigElePart/F");
866     _outTree->Branch("weightEleTrigEleAugPart" , &weightEleTrigEleAugPart , "weightEleTrigEleAugPart/F");
867    
868     _outTree->Branch("weightTrigMET80" , &weightTrigMET80 , "weightTrigMET80/F");
869     _outTree->Branch("weightTrigMET100" , &weightTrigMET100 , "weightTrigMET100/F");
870     _outTree->Branch("weightTrig2CJet20" , &weightTrig2CJet20 , "weightTrig2CJet20/F");
871     _outTree->Branch("weightTrigMET150" , &weightTrigMET150 , "weightTrigMET150/F");
872     _outTree->Branch("weightTrigMET802CJet" , &weightTrigMET802CJet , "weightTrigMET802CJet/F");
873     _outTree->Branch("weightTrigMET1002CJet" , &weightTrigMET1002CJet , "weightTrigMET1002CJet/F");
874     _outTree->Branch("weightTrigMETLP" , &weightTrigMETLP , "weightTrigMETLP/F");
875    
876    
877     _outTree->Branch("deltaPullAngleAK7", &deltaPullAngleAK7 , "deltaPullAngleAK7/F");
878     _outTree->Branch("deltaPullAngle2AK7", &deltaPullAngle2AK7 , "deltaPullAngle2AK7/F");
879     _outTree->Branch("PU0", &PU0 , "PU0/F");
880     _outTree->Branch("PUm1", &PUm1 , "PUm1/F");
881     _outTree->Branch("PUp1", &PUp1 , "PUp1/F");
882     _outTree->Branch("PUweight", &PUweight , "PUweight/F");
883     _outTree->Branch("PUweight2011B", &PUweight2011B , "PUweight2011B/F");
884     _outTree->Branch("eventFlav", &eventFlav , "eventFlav/I");
885    
886    
887    
888    
889     _outTree->Branch("Vtype" , &Vtype , "Vtype/I" );
890     _outTree->Branch("HVdPhi" , &HVdPhi , "HVdPhi/F" );
891     _outTree->Branch("HVMass" , &HVMass , "HVMass/F" );
892     _outTree->Branch("HMETdPhi" , &HMETdPhi , "HMETdPhi/F" );
893     _outTree->Branch("VMt" , &VMt , "VMt/F" );
894    
895     _outTree->Branch("nvlep" , &nvlep , "nvlep/I");
896     _outTree->Branch("nalep" , &nalep , "nalep/I");
897    
898     _outTree->Branch("vLepton_mass",vLeptons.mass ,"mass[nvlep]/F");
899     _outTree->Branch("vLepton_pt",vLeptons.pt ,"pt[nvlep]/F");
900     _outTree->Branch("vLepton_eta",vLeptons.eta ,"eta[nvlep]");
901     _outTree->Branch("vLepton_phi",vLeptons.phi ,"phi[nvlep]/F");
902     _outTree->Branch("vLepton_aodCombRelIso",vLeptons.aodCombRelIso ,"aodCombRelIso[nvlep]/F");
903     _outTree->Branch("vLepton_pfCombRelIso",vLeptons.pfCombRelIso ,"pfCombRelIso[nvlep]/F");
904     _outTree->Branch("vLepton_photonIso",vLeptons.photonIso ,"photonIso[nvlep]/F");
905     _outTree->Branch("vLepton_neutralHadIso",vLeptons.neutralHadIso ,"neutralHadIso[nvlep]/F");
906     _outTree->Branch("vLepton_chargedHadIso",vLeptons.chargedHadIso ,"chargedHadIso[nvlep]/F");
907     _outTree->Branch("vLepton_chargedPUIso",vLeptons.chargedPUIso ,"chargedPUIso[nvlep]/F");
908     _outTree->Branch("vLepton_particleIso",vLeptons.particleIso ,"particleIso[nvlep]/F");
909     _outTree->Branch("vLepton_dxy",vLeptons.dxy ,"dxy[nvlep]/F");
910     _outTree->Branch("vLepton_dz",vLeptons.dz ,"dz[nvlep]/F");
911     _outTree->Branch("vLepton_type",vLeptons.type ,"type[nvlep]/I");
912     _outTree->Branch("vLepton_id80",vLeptons.id80 ,"id80[nvlep]/F");
913     _outTree->Branch("vLepton_id95",vLeptons.id95 ,"id95[nvlep]/F");
914     _outTree->Branch("vLepton_vbtf",vLeptons.vbtf ,"vbtf[nvlep]/F");
915     _outTree->Branch("vLepton_id80NoIso",vLeptons.id80NoIso ,"id80NoIso[nvlep]/F");
916     _outTree->Branch("vLepton_genPt",vLeptons.genPt ,"genPt[nvlep]/F");
917     _outTree->Branch("vLepton_genEta",vLeptons.genEta ,"genEta[nvlep]");
918     _outTree->Branch("vLepton_genPhi",vLeptons.genPhi ,"genPhi[nvlep]/F");
919     _outTree->Branch("vLepton_charge",vLeptons.charge ,"charge[nvlep]/F");
920    
921     _outTree->Branch("aLepton_mass",aLeptons.mass ,"mass[nalep]/F");
922     _outTree->Branch("aLepton_pt",aLeptons.pt ,"pt[nalep]/F");
923     _outTree->Branch("aLepton_eta",aLeptons.eta ,"eta[nalep]");
924     _outTree->Branch("aLepton_phi",aLeptons.phi ,"phi[nalep]/F");
925     _outTree->Branch("aLepton_aodCombRelIso",aLeptons.aodCombRelIso ,"aodCombRelIso[nalep]/F");
926     _outTree->Branch("aLepton_pfCombRelIso",aLeptons.pfCombRelIso ,"pfCombRelIso[nalep]/F");
927     _outTree->Branch("aLepton_photonIso",aLeptons.photonIso ,"photonIso[nalep]/F");
928     _outTree->Branch("aLepton_neutralHadIso",aLeptons.neutralHadIso ,"neutralHadIso[nalep]/F");
929     _outTree->Branch("aLepton_chargedHadIso",aLeptons.chargedHadIso ,"chargedHadIso[nalep]/F");
930     _outTree->Branch("aLepton_chargedPUIso",aLeptons.chargedPUIso ,"chargedPUIso[nalep]/F");
931     _outTree->Branch("aLepton_particleIso",aLeptons.particleIso ,"particleIso[nalep]/F");
932     _outTree->Branch("aLepton_dxy",aLeptons.dxy ,"dxy[nalep]/F");
933     _outTree->Branch("aLepton_dz",aLeptons.dz ,"dz[nalep]/F");
934     _outTree->Branch("aLepton_type",aLeptons.type ,"type[nalep]/I");
935     _outTree->Branch("aLepton_id80",aLeptons.id80 ,"id80[nalep]/F");
936     _outTree->Branch("aLepton_id95",aLeptons.id95 ,"id95[nalep]/F");
937     _outTree->Branch("aLepton_vbtf",aLeptons.vbtf ,"vbtf[nalep]/F");
938     _outTree->Branch("aLepton_id80NoIso",aLeptons.id80NoIso ,"id80NoIso[nalep]/F");
939     _outTree->Branch("aLepton_genPt",aLeptons.genPt ,"genPt[nalep]/F");
940     _outTree->Branch("aLepton_genEta",aLeptons.genEta ,"genEta[nalep]");
941     _outTree->Branch("aLepton_genPhi",aLeptons.genPhi ,"genPhi[nalep]/F");
942     _outTree->Branch("aLepton_charge",aLeptons.charge ,"charge[nalep]/F");
943    
944     _outTree->Branch("top" , &top , "mass/F:pt/F:wMass/F");
945     _outTree->Branch("WplusMode" , &WplusMode , "WplusMode/I");
946     _outTree->Branch("WminusMode" , &WminusMode , "WminusMode/I");
947    
948     //IVF
949     _outTree->Branch("nSvs",&nSvs ,"nSvs/I");
950     _outTree->Branch("Sv_massBCand", &IVF.massBcand,"massBcand[nSvs]/F");
951     _outTree->Branch("Sv_massSv", &IVF.massSv,"massSv[nSvs]/F");
952     _outTree->Branch("Sv_pt", &IVF.pt,"pt[nSvs]/F");
953     _outTree->Branch("Sv_eta", &IVF.eta,"eta[nSvs]/F");
954     _outTree->Branch("Sv_phi", &IVF.phi,"phi[nSvs]/F");
955     _outTree->Branch("Sv_dist3D", &IVF.dist3D,"dist3D[nSvs]/F");
956     _outTree->Branch("Sv_dist2D", &IVF.dist2D,"dist2D[nSvs]/F");
957     _outTree->Branch("Sv_distSim2D", &IVF.distSig2D,"distSig2D[nSvs]/F");
958     _outTree->Branch("Sv_distSig3D", &IVF.distSig3D,"distSig3D[nSvs]/F");
959     _outTree->Branch("Sv_dist3D_norm", &IVF.dist3D_norm,"dist3D_norm[nSvs]/F");
960     //IVF higgs candidate
961     _outTree->Branch("SVH" , &SVH , "mass/F:pt/F:eta:phi/F:dR/F:dPhi/F:dEta/F");
962    
963    
964    
965     // //SimBHadron
966     _outTree->Branch("nSimBs",&nSimBs ,"nSimBs/I");
967     _outTree->Branch("SimBs_mass", &SimBs.mass,"mass[nSimBs]/F");
968     _outTree->Branch("SimBs_pt", &SimBs.pt,"pt[nSimBs]/F");
969     _outTree->Branch("SimBs_eta", &SimBs.eta,"eta[nSimBs]/F");
970     _outTree->Branch("SimBs_phi", &SimBs.phi,"phi[nSimBs]/F");
971     _outTree->Branch("SimBs_vtx_x", &SimBs.vtx_x,"vtx_x[nSimBs]/F");
972     _outTree->Branch("SimBs_vtx_y", &SimBs.vtx_y,"vtx_y[nSimBs]/F");
973     _outTree->Branch("SimBs_vtx_z", &SimBs.vtx_z,"vtx_z[nSimBs]/F");
974     _outTree->Branch("SimBs_pdgId", &SimBs.pdgId,"pdgId[nSimBs]/F");
975     _outTree->Branch("SimBs_status", &SimBs.status,"status[nSimBs]/F");
976     //SimBHadron Higgs Candidate
977     _outTree->Branch("SimBsH" , &SimBsH , "mass/F:pt/F:eta:phi/F:dR/F:dPhi/F:dEta/F");
978    
979     _outTree->Branch("rho" , &rho , "rho/F");
980     _outTree->Branch("rho25" , &rho25 , "rho25/F");
981     _outTree->Branch("nPVs" , &nPVs , "nPVs/I");
982     _outTree->Branch("METnoPU" , &METnoPU , "et/F:sumet:sig/F:phi/F");
983     _outTree->Branch("METnoPUCh" , &METnoPUCh , "et/F:sumet:sig/F:phi/F");
984     _outTree->Branch("MET" , &MET , "et/F:sumet:sig/F:phi/F");
985     _outTree->Branch("METtype1corr" , &METtype1corr , "et/F:sumet:sig/F:phi/F");
986     _outTree->Branch("METtype1p2corr" , &METtype1p2corr , "et/F:sumet:sig/F:phi/F");
987     _outTree->Branch("METnoPUtype1corr" , &METnoPUtype1corr , "et/F:sumet:sig/F:phi/F");
988     _outTree->Branch("METnoPUtype1p2corr" , &METnoPUtype1p2corr , "et/F:sumet:sig/F:phi/F");
989    
990     _outTree->Branch("metUnc_et",&metUnc.et ,"et[24]/F");
991     _outTree->Branch("metUnc_phi",&metUnc.phi ,"phi[24]/F");
992     _outTree->Branch("metUnc_sumet",&metUnc.sumet ,"sumet[24]/F");
993    
994    
995    
996     _outTree->Branch("fakeMET" , &fakeMET , "et/F:sumet:sig/F:phi/F");
997     _outTree->Branch("MHT" , &MHT , "mht/F:ht:sig/F:phi/F");
998     _outTree->Branch("minDeltaPhijetMET" , &minDeltaPhijetMET , "minDeltaPhijetMET/F");
999     _outTree->Branch("jetPt_minDeltaPhijetMET" , &jetPt_minDeltaPhijetMET , "jetPt_minDeltaPhijetMET/F");
1000    
1001     std::stringstream s;
1002     s << "triggerFlags[" << triggers.size() << "]/b";
1003     _outTree->Branch("triggerFlags", triggerFlags, s.str().c_str());
1004    
1005     _outTree->Branch("EVENT" , &EVENT , "run/I:lumi/I:event/I:json/I");
1006     _outTree->Branch("hbhe" , &hbhe , "hbhe/b");
1007     _outTree->Branch("totalKinematics" , &totalKinematics , "totalKinematics/b");
1008     _outTree->Branch("ecalFlag" , &ecalFlag , "ecalFlag/b");
1009     _outTree->Branch("cschaloFlag" , &cschaloFlag , "cschaloFlag/b");
1010     _outTree->Branch("hcallaserFlag" , &hcallaserFlag , "hcallaserFlag/b");
1011     _outTree->Branch("trackingfailureFlag" , &trackingfailureFlag , "trackingfailureFlag/b");
1012     _outTree->Branch("btag1TSF" , &btag1TSF , "btag1TSF/F");
1013     _outTree->Branch("btag2TSF" , &btag2TSF , "btag2TSF/F");
1014     _outTree->Branch("btag1T2CSF" , &btag1T2CSF , "btag1T2CSF/F");
1015     _outTree->Branch("btag2CSF" , &btag2CSF , "btag2CSF/F");
1016     _outTree->Branch("btagA0CSF" , &btagA0CSF , "btagA0CSF/F");
1017     _outTree->Branch("btagA0TSF" , &btagA0TSF , "btagA0TSF/F");
1018     _outTree->Branch("btag1TA1C" , &btag1TA1C , "btag1TA1C/F");
1019    
1020     int ievt=0;
1021     int totalcount=0;
1022    
1023     // TFile* inFile = new TFile(inputFile.c_str(), "read");
1024     for(unsigned int iFile=0; iFile<inputFiles_.size(); ++iFile) {
1025     std::cout << iFile << std::endl;
1026     TFile* inFile = TFile::Open(inputFiles_[iFile].c_str());
1027     if(inFile==0) continue;
1028    
1029     // loop the events
1030    
1031 bortigno 1.2 fwlite::Run run(inFile);
1032 bortigno 1.1 fwlite::Event ev(inFile);
1033     for(ev.toBegin(); !ev.atEnd() ; ++ev, ++ievt)
1034     {
1035     if (ievt <= skipEvents_) continue;
1036     if (maxEvents_ >= 0){
1037     if (ievt > maxEvents_ + skipEvents_) break;
1038     };
1039    
1040     fwlite::Handle< VHbbEventAuxInfo > vhbbAuxHandle;
1041     vhbbAuxHandle.getByLabel(ev,"HbbAnalyzerNew");
1042     const VHbbEventAuxInfo & aux = *vhbbAuxHandle.product();
1043    
1044     if(EVENT.run < runMin_ && runMin_ > 0) continue;
1045     if(EVENT.run > runMax_ && runMax_ > 0) continue;
1046    
1047     count->Fill(1.);
1048    
1049    
1050    
1051    
1052    
1053    
1054     PUweight=1.;
1055     PUweight2011B=1.;
1056     if(isMC_){
1057    
1058     // PU weights // Run2011A
1059     std::map<int, unsigned int>::const_iterator puit = aux.puInfo.pus.find(0);
1060     int npu =puit->second ;
1061     PUweight = lumiWeights.weight( npu );
1062     pu->Fill(puit->second);
1063     // PU weight Run2011B
1064     // PU weight Run2011B
1065     std::map<int, unsigned int>::const_iterator puit0 = aux.puInfo.pus.find(0);
1066     std::map<int, unsigned int>::const_iterator puitm1 = aux.puInfo.pus.find(-1);
1067     std::map<int, unsigned int>::const_iterator puitp1 = aux.puInfo.pus.find(+1);
1068     PU0=puit0->second;
1069     PUp1=puitp1->second;
1070     PUm1=puitm1->second;
1071     input3DPU->Fill(PUm1,PU0,PUp1);
1072     PUweight2011B = lumiWeights2011B.weight3D( puitm1->second, puit0->second,puitp1->second);
1073    
1074     }
1075     countWithPU->Fill(1,PUweight);
1076     countWithPU2011B->Fill(1,PUweight2011B);
1077    
1078 bortigno 1.2
1079 bortigno 1.1 //LHE Infos
1080     fwlite::Handle<LHEEventProduct> evt;
1081    
1082     // std::cout << "Label for lhe = " << evt.getBranchNameFor(ev,"source") << std::endl;
1083     if( !((evt.getBranchNameFor(ev,"source")).empty()) ){
1084     evt.getByLabel(ev,"source");
1085 bortigno 1.2
1086 bortigno 1.1 //std::cout << "LHEEventProduct found!" << std::endl;
1087     bool lCheck=false;
1088     bool lbarCheck=false;
1089     bool vlCheck=false;
1090     bool vlbarCheck=false;
1091     int idl, idlbar;
1092     TLorentzVector l,lbar,vl,vlbar,V_tlv;
1093     const lhef::HEPEUP hepeup_ = evt->hepeup();
1094 bortigno 1.2 double _origECMS = 7000; // energy in GeV
1095     double _newECMS = 8000; // energy in GeV
1096     float Q = hepeup_.SCALUP;
1097     int id1 = hepeup_.IDUP[0];
1098     double x1 = fabs(hepeup_.PUP[0][2]/(_origECMS/2));
1099     double x1prime = fabs(hepeup_.PUP[0][2]/(_newECMS/2));
1100     int id2 = hepeup_.IDUP[1];
1101     double x2 = fabs(hepeup_.PUP[1][2]/(_origECMS/2));
1102     double x2prime = fabs(hepeup_.PUP[1][2]/(_newECMS/2));
1103     // std::cout << "*******LHECOMWeightProducer*******\n" <<
1104     // " Q : " << Q << "\n" <<
1105     // " id1: " << id1 << "\n" <<
1106     // " x1 : " << x1 << "\n" <<
1107     // " x1': " << x1prime << "\n" <<
1108     // " id2: " << id2 << "\n" <<
1109     // " x2 : " << x2 << "\n" <<
1110     // " x2': " << x2prime << std::endl;
1111     //gluon is 0 in the LHAPDF numberin
1112     if (id1 == 21)
1113     id1 = 0;
1114     if (id2 == 21)
1115     id2 = 0;
1116     int _pdfmember = 0;
1117     LHAPDF::usePDFMember(1,_pdfmember);
1118     double oldpdf1 = LHAPDF::xfx(1, x1, Q, id1)/x1;
1119     double oldpdf2 = LHAPDF::xfx(1, x2, Q, id2)/x2;
1120     double newpdf1 = LHAPDF::xfx(1, x1prime, Q, id1)/x1prime;
1121     double newpdf2 = LHAPDF::xfx(1, x2prime, Q, id2)/x2prime;
1122     PDFweight = (newpdf1/oldpdf1)*(newpdf2/oldpdf2);
1123    
1124     // std::cout << " xfx1 : " << oldpdf1 << "\n" <<
1125     // " xfx2 : " << oldpdf2 << "\n" <<
1126     // " xfx1': " << newpdf1 << "\n" <<
1127     // " xfx2': " << newpdf2 << "\n" <<
1128     // " weight:" << (newpdf1/oldpdf1)*(newpdf2/oldpdf2) << std::endl;
1129    
1130 bortigno 1.4 lheHT=0.;
1131     lheNj=0;
1132 bortigno 1.1 const std::vector<lhef::HEPEUP::FiveVector> pup_ = hepeup_.PUP; // px, py, pz, E, M
1133     for(unsigned int i=0; i<pup_.size(); ++i){
1134     int id=hepeup_.IDUP[i]; //pdgId
1135 bortigno 1.3 int status = hepeup_.ISTUP[i];
1136 bortigno 1.5 int idabs=TMath::Abs(id);
1137     if( status == 1 && ( ( idabs == 21 ) || (idabs > 0 && idabs < 7) ) ){ // gluons and quarks
1138     lheHT += TMath::Sqrt( TMath::Power(hepeup_.PUP[i][0],2) + TMath::Power(hepeup_.PUP[i][1],2) ); // first entry is px, second py
1139     lheNj++;
1140     }
1141    
1142 bortigno 1.1 if(id==11){ l.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lCheck=true;}
1143     if(id==-11){ lbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lbarCheck=true;}
1144     if(id==12){ vl.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlCheck=true;}
1145     if(id==-12){ vlbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlbarCheck=true;}
1146    
1147     if(id==13){ l.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lCheck=true;}
1148     if(id==-13){ lbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lbarCheck=true;}
1149     if(id==14){ vl.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlCheck=true;}
1150     if(id==-14){ vlbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlbarCheck=true;}
1151    
1152     if(id==15){ l.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lCheck=true;}
1153     if(id==-15){ lbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lbarCheck=true;}
1154     if(id==16){ vl.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlCheck=true;}
1155     if(id==-16){ vlbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlbarCheck=true;}
1156    
1157     }
1158     if( lCheck && lbarCheck ) V_tlv = l + lbar; // ZtoLL
1159     if( vlCheck && vlbarCheck ) V_tlv = vl + vlbar; // ZtoNuNu
1160     if( lCheck && vlbarCheck ) V_tlv = l + vlbar; // WToLNu
1161     if( lbarCheck && vlCheck ) V_tlv = lbar + vl; // WToLNu
1162     lheV_pt = V_tlv.Pt();
1163     }
1164    
1165     //std::cout << "lhe V pt = " << lheV_pt << std::endl;
1166    
1167     //Write event info
1168     EVENT.run = ev.id().run();
1169     EVENT.lumi = ev.id().luminosityBlock();
1170     EVENT.event = ev.id().event();
1171     EVENT.json = jsonContainsEvent (jsonVector, ev);
1172    
1173     // simBHadrons
1174     const SimBHadronCollection *sbhc;
1175     if(isMC_){
1176     fwlite::Handle<SimBHadronCollection> SBHC;
1177     SBHC.getByLabel(ev, "bhadrons");
1178     sbhc = SBHC.product();
1179     }
1180    
1181     const std::vector<VHbbCandidate> * candZ ;
1182     const std::vector<VHbbCandidate> * candW ;
1183     VHbbEvent modifiedEvent;;
1184     const VHbbEvent * iEvent =0;
1185     if(fromCandidate)
1186     {
1187     fwlite::Handle< std::vector<VHbbCandidate> > vhbbCandHandleZ;
1188     vhbbCandHandleZ.getByLabel(ev,"hbbBestCSVPt20Candidates");
1189     candZ = vhbbCandHandleZ.product();
1190    
1191     fwlite::Handle< std::vector<VHbbCandidate> > vhbbCandHandle;
1192     vhbbCandHandle.getByLabel(ev,"hbbHighestPtHiggsPt30Candidates");
1193     candW = vhbbCandHandle.product();
1194     }
1195     else
1196     {
1197     candZlocal->clear();
1198     candWlocal->clear();
1199     fwlite::Handle< VHbbEvent > vhbbHandle;
1200     vhbbHandle.getByLabel(ev,"HbbAnalyzerNew");
1201     modifiedEvent = *vhbbHandle.product();
1202     if(isMC_)
1203     {
1204     iEvent= &modifiedEvent;
1205    
1206     for(size_t j=0; j< modifiedEvent.simpleJets2.size() ; j++)
1207     {
1208     TLorentzVector & p4 = modifiedEvent.simpleJets2[j].p4;
1209     TLorentzVector & mcp4 = modifiedEvent.simpleJets2[j].bestMCp4;
1210     if ((fabs(p4.Pt() - mcp4.Pt())/ p4.Pt())<0.5) { //Limit the effect to the core
1211     float cor = (p4.Pt()+resolutionBias(fabs(p4.Eta()))*(p4.Pt()-mcp4.Pt()))/p4.Pt();
1212     p4.SetPtEtaPhiE(p4.Pt()*cor,p4.Eta(), p4.Phi(), p4.E()*cor);
1213     }
1214     }
1215     } else
1216     {
1217     iEvent = vhbbHandle.product();
1218     }
1219    
1220     algoZ->run(iEvent,*candZlocal);
1221     algoW->run(iEvent,*candWlocal);
1222    
1223     if(candZlocal->size() == 0 or candZlocal->at(0).H.jets.size() < 2) //recover low pt
1224     {
1225     candZlocal->clear();
1226     candWlocal->clear();
1227     algoRecoverLowPt->run(iEvent,*candZlocal);
1228     algoRecoverLowPt->run(iEvent,*candWlocal);
1229     }
1230    
1231     candZ= candZlocal;
1232     candW= candWlocal;
1233     /* for(size_t m=0;m<iEvent->muInfo.size();m++)
1234     {
1235    
1236     if( fabs(iEvent->muInfo[m].p4.Pt()-28.118684) < 0.0001 ||
1237     fabs(iEvent->muInfo[m].p4.Pt()-34.853199) < 0.0001 )
1238     {
1239     std::cout << "FOUND " << iEvent->muInfo[m].p4.Pt() << " " << EVENT.event << " " << candW->size() << " " << candZ->size() << std::endl;
1240     }
1241     }
1242     */
1243    
1244     }
1245    
1246     const std::vector<VHbbCandidate> * cand = candZ;
1247    
1248    
1249    
1250     /* fwlite::Handle< VHbbEvent > vhbbHandle;
1251     vhbbHandle.getByLabel(ev,"HbbAnalyzerNew");
1252     const VHbbEvent iEvent = *vhbbHandle.product();
1253     */
1254    
1255     // std::clog << "Filling tree "<< std::endl;
1256     bool isW=false;
1257    
1258     // to check how much we gain with jets subtraction
1259    
1260    
1261    
1262     genHpt=aux.mcH.size() > 0 ? aux.mcH[0].p4.Pt():-99;
1263    
1264     if(cand->size() == 0 or cand->at(0).H.jets.size() < 2) continue;
1265     //if(cand->size() == 0 ) continue;
1266     //std::cout << "cand->size() " << cand->size() << std::endl;
1267     //std::cout << "cand->at(0).H.jets.size() " << cand->at(0).H.jets.size() << std::endl;
1268     if(cand->size() > 1 )
1269     {
1270     std::cout << "MULTIPLE CANDIDATES: " << cand->size() << std::endl;
1271     }
1272     if(cand->at(0).candidateType == VHbbCandidate::Wmun || cand->at(0).candidateType == VHbbCandidate::Wen ) { cand=candW; isW=true; }
1273     if(cand->size() == 0)
1274     {
1275     // std::cout << "W event loss due to tigther cuts" << std::endl;
1276     continue;
1277     }
1278    
1279    
1280     // secondary vtxs
1281     fwlite::Handle<std::vector<reco::Vertex> > SVC;
1282     SVC.getByLabel(ev,"bcandidates");
1283     const std::vector<reco::Vertex> svc = *(SVC.product());
1284    
1285     const VHbbCandidate & vhCand = cand->at(0);
1286     patFilters.setEvent(&ev,"VH");
1287     hbhe = patFilters.accept("hbhe");
1288     ecalFlag = patFilters.accept("ecalFilter");
1289     totalKinematics = patFilters.accept("totalKinematics");
1290     cschaloFlag = patFilters.accept("cschaloFilter");
1291     hcallaserFlag = patFilters.accept("hcallaserFilter");
1292     trackingfailureFlag = patFilters.accept("trackingfailureFilter");
1293    
1294     trigger.setEvent(&ev);
1295     for(size_t j=0;j < triggers.size();j++)
1296     triggerFlags[j]=trigger.accept(triggers[j]);
1297    
1298     eventFlav=0;
1299    
1300    
1301    
1302     if(aux.mcBbar.size() > 0 || aux.mcB.size() > 0) eventFlav=5;
1303     else if(aux.mcC.size() > 0) eventFlav=4;
1304    
1305    
1306     Vtype = vhCand.candidateType;
1307    
1308     if(vhCand.H.HiggsFlag) H.HiggsFlag=1; else H.HiggsFlag=0;
1309    
1310     if(vhCand.H.HiggsFlag){
1311     H.mass = vhCand.H.p4.M();
1312     H.pt = vhCand.H.p4.Pt();
1313    
1314    
1315     H.eta = vhCand.H.p4.Eta();
1316     H.phi = vhCand.H.p4.Phi();
1317     }
1318    
1319     if(vhCand.FatH.FatHiggsFlag) FatH.FatHiggsFlag =1; else FatH.FatHiggsFlag=0;
1320     fathFilterJets.reset();
1321     aJetsFat.reset();
1322     if(vhCand.FatH.FatHiggsFlag){
1323     FatH.mass= vhCand.FatH.p4.M();
1324     FatH.pt = vhCand.FatH.p4.Pt();
1325     FatH.eta = vhCand.FatH.p4.Eta();
1326     FatH.phi = vhCand.FatH.p4.Phi();
1327    
1328     // if(vhCand.FatH.FatHiggsFlag) vhCand.FatH.subjetsSize;
1329     nfathFilterJets=vhCand.FatH.subjetsSize;
1330     for( int j=0; j < nfathFilterJets; j++ ){
1331     fathFilterJets.set(vhCand.FatH.jets[j],j);
1332     }
1333    
1334     if(nfathFilterJets==2){
1335     FatH.filteredmass=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4).M();
1336     FatH.filteredpt=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4).Pt();
1337     FatH.filteredeta=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4).Eta();
1338     FatH.filteredphi=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4).Phi();
1339     }
1340     else if(nfathFilterJets==3){
1341     FatH.filteredmass=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4+vhCand.FatH.jets[2].p4).M();
1342     FatH.filteredpt=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4+vhCand.FatH.jets[2].p4).Pt();
1343     FatH.filteredeta=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4+vhCand.FatH.jets[2].p4).Eta();
1344     FatH.filteredphi=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4+vhCand.FatH.jets[2].p4).Phi();
1345     }
1346    
1347     naJetsFat=vhCand.additionalJetsFat.size();
1348     for( int j=0; j < naJetsFat && j < MAXJ; j++ )
1349     {
1350     aJetsFat.set(vhCand.additionalJetsFat[j],j);
1351     }
1352    
1353    
1354     } // FatHiggsFlag
1355    
1356     hJets.reset();
1357     aJets.reset();
1358     if(vhCand.H.HiggsFlag){
1359    
1360     nhJets=2;
1361     hJets.set(vhCand.H.jets[0],0);
1362     hJets.set(vhCand.H.jets[1],1);
1363    
1364    
1365     aJets.reset();
1366    
1367     naJets=vhCand.additionalJets.size();
1368     numBJets=0;
1369     if(vhCand.H.jets[0].csv> btagThr) numBJets++;
1370     if(vhCand.H.jets[1].csv> btagThr) numBJets++;
1371     for( int j=0; j < naJets && j < MAXJ; j++ )
1372     {
1373     aJets.set(vhCand.additionalJets[j],j);
1374     if(vhCand.additionalJets[j].csv> btagThr) numBJets++;
1375     }
1376     numJets = vhCand.additionalJets.size()+2;
1377     H.dR = 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());
1378     H.dPhi = deltaPhi(vhCand.H.jets[0].p4.Phi(),vhCand.H.jets[1].p4.Phi());
1379     H.dEta= TMath::Abs( vhCand.H.jets[0].p4.Eta() - vhCand.H.jets[1].p4.Eta() );
1380     HVdPhi = fabs( deltaPhi(vhCand.H.p4.Phi(),vhCand.V.p4.Phi()) ) ;
1381     HVMass = (vhCand.H.p4 + vhCand.V.p4).M() ;
1382     HMETdPhi = fabs( deltaPhi(vhCand.H.p4.Phi(),vhCand.V.mets.at(0).p4.Phi()) ) ;
1383     //eltaPullAngle = vhCand.H.deltaTheta;
1384    
1385     deltaPullAngle = VHbbCandidateTools::getDeltaTheta(vhCand.H.jets[0],vhCand.H.jets[1]);
1386     deltaPullAngle2 = VHbbCandidateTools::getDeltaTheta(vhCand.H.jets[1],vhCand.H.jets[0]);
1387     hJets.cosTheta[0]= vhCand.H.helicities[0];
1388     hJets.cosTheta[1]= vhCand.H.helicities[1];
1389     } // Higgs Flag
1390    
1391     V.mass = vhCand.V.p4.M();
1392     if(isW) V.mass = vhCand.Mt();
1393     V.pt = vhCand.V.p4.Pt();
1394     V.eta = vhCand.V.p4.Eta();
1395     V.phi = vhCand.V.p4.Phi();
1396     VMt = vhCand.Mt() ;
1397    
1398    
1399     // METInfo calomet; METInfo tcmet; METInfo pfmet; METInfo mht; METInfo metNoPU
1400     MET.et = vhCand.V.mets.at(0).p4.Pt();
1401     MET.phi = vhCand.V.mets.at(0).p4.Phi();
1402     MET.sumet = vhCand.V.mets.at(0).sumEt;
1403     MET.sig = vhCand.V.mets.at(0).metSig;
1404    
1405    
1406     fakeMET.sumet = 0;
1407     fakeMET.sig = 0;
1408     fakeMET.et = 0;
1409     fakeMET.phi = 0;
1410     if( Vtype == VHbbCandidate::Zmumu) {
1411     TVector3 mu1 = vhCand.V.muons[0].p4.Vect();
1412     TVector3 mu2 = vhCand.V.muons[1].p4.Vect();
1413     // Not needed with PFMET
1414     // mu1.SetMag( mu1.Mag() - vhCand.V.muons[0].emEnergy - vhCand.V.muons[0].hadEnergy);
1415     // mu2.SetMag( mu2.Mag() - vhCand.V.muons[1].emEnergy - vhCand.V.muons[1].hadEnergy);
1416     TVector3 sum = vhCand.V.mets.at(0).p4.Vect() + mu1 + mu2;
1417     fakeMET.et = sum.Pt();
1418     fakeMET.phi = sum.Phi();
1419     fakeMET.sumet = vhCand.V.mets.at(0).sumEt - mu1.Pt() - mu2.Pt();
1420     }
1421    
1422    
1423    
1424     METnoPU.et = iEvent->metNoPU.p4.Pt();
1425     METnoPU.phi = iEvent->metNoPU.p4.Phi();
1426     METnoPU.sumet = iEvent->metNoPU.sumEt;
1427     METnoPU.sig = iEvent->metNoPU.metSig;
1428     METnoPUCh.et = iEvent->metCh.p4.Pt();
1429     METnoPUCh.phi = iEvent->metCh.p4.Phi();
1430     METnoPUCh.sumet = iEvent->metCh.sumEt;
1431     METnoPUCh.sig = iEvent->metCh.metSig;
1432    
1433     METnoPUCh.et = iEvent->metCh.p4.Pt();
1434     METnoPUCh.phi = iEvent->metCh.p4.Phi();
1435     METnoPUCh.sumet = iEvent->metCh.sumEt;
1436     METnoPUCh.sig = iEvent->metCh.metSig;
1437    
1438    
1439     METtype1corr.et = iEvent->pfmetType1corr.p4.Pt();
1440     METtype1corr.phi = iEvent->pfmetType1corr.p4.Phi();
1441     METtype1corr.sumet = iEvent->pfmetType1corr.sumEt;
1442     METtype1corr.sig = iEvent->pfmetType1corr.metSig;
1443    
1444    
1445     METtype1p2corr.et = iEvent->pfmetType1p2corr.p4.Pt();
1446     METtype1p2corr.phi = iEvent->pfmetType1p2corr.p4.Phi();
1447     METtype1p2corr.sumet = iEvent->pfmetType1p2corr.sumEt;
1448     METtype1p2corr.sig = iEvent->pfmetType1p2corr.metSig;
1449    
1450    
1451     METnoPUtype1corr.et = iEvent->pfmetNoPUType1corr.p4.Pt();
1452     METnoPUtype1corr.phi = iEvent->pfmetNoPUType1corr.p4.Phi();
1453     METnoPUtype1corr.sumet = iEvent->pfmetNoPUType1corr.sumEt;
1454     METnoPUtype1corr.sig = iEvent->pfmetNoPUType1corr.metSig;
1455    
1456    
1457     METnoPUtype1p2corr.et = iEvent->pfmetNoPUType1p2corr.p4.Pt();
1458     METnoPUtype1p2corr.phi = iEvent->pfmetNoPUType1p2corr.p4.Phi();
1459     METnoPUtype1p2corr.sumet = iEvent->pfmetNoPUType1p2corr.sumEt;
1460     METnoPUtype1p2corr.sig = iEvent->pfmetNoPUType1p2corr.metSig;
1461    
1462     // std::cout << " iEvent->metUncInfo.size() " << iEvent->metUncInfo.size() << std::endl;
1463     for(size_t m=0;m<iEvent->metUncInfo.size();m++)
1464     {
1465     metUnc.set(iEvent->metUncInfo[m], m );
1466     // std::cout << "metUncInfo[" << m <<" ].et = " << metUnc.et[m] << std::endl;
1467     }
1468    
1469    
1470     rho = aux.puInfo.rho;
1471     rho25 = aux.puInfo.rho25;
1472     nPVs=aux.pvInfo.nVertices;
1473    
1474     if(!fromCandidate) {
1475     MHT.mht = iEvent->mht.p4.Pt();
1476     MHT.phi = iEvent->mht.p4.Phi();
1477     MHT.ht = iEvent->mht.sumEt;
1478     MHT.sig = iEvent->mht.metSig;
1479     }
1480    
1481    
1482     /////////
1483     // track sharing flags:
1484     ////////
1485     TkSharing.HiggsCSVtkSharing = TkSharing.HiggsIPtkSharing = TkSharing.HiggsSVtkSharing = TkSharing.FatHiggsCSVtkSharing = TkSharing.FatHiggsIPtkSharing = TkSharing.FatHiggsSVtkSharing = false;
1486    
1487     // csv tracks
1488     if(vhCand.H.HiggsFlag){
1489    
1490     if (vhCand.H.jets[0].csvNTracks > 0 && vhCand.H.jets[1].csvNTracks > 0){
1491     for (int t=0;t!=vhCand.H.jets[0].csvNTracks;t++){
1492     for (int ti=0;ti!=vhCand.H.jets[1].csvNTracks;ti++){
1493     if ((int)vhCand.H.jets[0].csvTrackIds[t] == (int)vhCand.H.jets[1].csvTrackIds[ti]){
1494     TkSharing.HiggsCSVtkSharing = true;
1495     }// same trackID
1496     }// loop tracks in second hjet
1497     }// loop tracks in first hjet
1498     }// if tracks in jet
1499    
1500     // ip tracks
1501     if (vhCand.H.jets[0].btagNTracks > 0 && vhCand.H.jets[1].btagNTracks > 0){
1502     for (int t=0;t!=vhCand.H.jets[0].btagNTracks;t++){
1503     for (int ti=0;ti!=vhCand.H.jets[1].btagNTracks;ti++){
1504     if ((int)vhCand.H.jets[0].btagTrackIds[t] == (int)vhCand.H.jets[1].btagTrackIds[ti]){
1505     TkSharing.HiggsIPtkSharing = true;
1506     }// same trackID
1507     }// loop tracks in second hjet
1508     }// loop tracks in first hjet
1509     }// if tracks in jet
1510    
1511     // sv tracks
1512     if (vhCand.H.jets[0].vtxNTracks > 0 && vhCand.H.jets[1].vtxNTracks > 0){
1513     for (int t=0;t!=vhCand.H.jets[0].vtxNTracks;t++){
1514     for (int ti=0;ti!=vhCand.H.jets[1].vtxNTracks;ti++){
1515     if ((int)vhCand.H.jets[0].vtxTrackIds[t] == (int)vhCand.H.jets[1].vtxTrackIds[ti]){
1516     TkSharing.HiggsSVtkSharing = true;
1517     }// same trackID
1518     }// loop tracks in second hjet
1519     }// loop tracks in first hjet
1520     }// if tracks in jet
1521    
1522     } // Di-jet Higgs Flag
1523    
1524     // tracksharing for Filtered jets:
1525     if(vhCand.FatH.FatHiggsFlag && nfathFilterJets > 1){
1526    
1527     // csv tracks
1528     if (vhCand.FatH.jets[0].csvNTracks > 0 && vhCand.FatH.jets[1].csvNTracks > 0){
1529     for (int t=0;t!=vhCand.FatH.jets[0].csvNTracks;t++){
1530     for (int ti=0;ti!=vhCand.FatH.jets[1].csvNTracks;ti++){
1531     if ((int)vhCand.FatH.jets[0].csvTrackIds[t] == (int)vhCand.FatH.jets[1].csvTrackIds[ti]){
1532     TkSharing.FatHiggsCSVtkSharing = true;
1533     }// same trackID
1534     }// loop tracks in second hjet
1535     }// loop tracks in first hjet
1536     }// if tracks in jet
1537    
1538     // ip tracks
1539     if (vhCand.FatH.jets[0].btagNTracks > 0 && vhCand.FatH.jets[1].btagNTracks > 0){
1540     for (int t=0;t!=vhCand.FatH.jets[0].btagNTracks;t++){
1541     for (int ti=0;ti!=vhCand.FatH.jets[1].btagNTracks;ti++){
1542     if ((int)vhCand.FatH.jets[0].btagTrackIds[t] == (int)vhCand.FatH.jets[1].btagTrackIds[ti]){
1543     TkSharing.FatHiggsIPtkSharing = true;
1544     }// same trackID
1545     }// loop tracks in second hjet
1546     }// loop tracks in first hjet
1547     }// if tracks in jet
1548    
1549     // sv tracks
1550     if (vhCand.FatH.jets[0].vtxNTracks > 0 && vhCand.FatH.jets[1].vtxNTracks > 0){
1551     for (int t=0;t!=vhCand.FatH.jets[0].vtxNTracks;t++){
1552     for (int ti=0;ti!=vhCand.FatH.jets[1].vtxNTracks;ti++){
1553     if ((int)vhCand.FatH.jets[0].vtxTrackIds[t] == (int)vhCand.FatH.jets[1].vtxTrackIds[ti]){
1554     TkSharing.FatHiggsSVtkSharing = true;
1555     }// same trackID
1556     }// loop tracks in second hjet
1557     }// loop tracks in first hjet
1558     }// if tracks in jet
1559    
1560     }// fatH
1561    
1562     ////////
1563     ////////
1564    
1565     //Secondary Vertices
1566     IVF.reset();
1567     nSvs = svc.size();
1568     const TVector3 recoPv = aux.pvInfo.firstPVInPT2;
1569     const math::XYZPoint myPv(recoPv);
1570    
1571     //FAKE ERROR MATRIX
1572     // //look here for Matrix filling info http://project-mathlibs.web.cern.ch/project-mathlibs/sw/html/SMatrixDoc.html
1573     // std::vector<double> fillMatrix(6);
1574     // for (int i = 0; i<6; ++i) fillMatrix[i] = 0.;
1575     // fillMatrix[0] = TMath::Power(0.002,2);
1576     // fillMatrix[2] = TMath::Power(0.002,2);
1577     // fillMatrix[5] = TMath::Power(0.002,2);
1578     // const ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > myFakeMatrixError(fillMatrix.begin(),fillMatrix.end());
1579     // const reco::Vertex recoVtxPv(myPv, myFakeMatrixError);
1580    
1581     // REAL ERROR MATRIX
1582     const reco::Vertex recoVtxPv(myPv, aux.pvInfo.efirstPVInPT2);
1583     for( int j=0; j < nSvs && j < MAXB; ++j ) {
1584     const GlobalVector flightDir = flightDirection(recoPv,svc[j]);
1585     reco::SecondaryVertex recoSv(recoVtxPv, svc[j], flightDir ,true);
1586     IVF.set( recoSv, recoPv ,j);
1587     }
1588     if(nSvs > 1){
1589     TLorentzVector BCands_H1, BCands_H2, BCands_H;
1590     BCands_H1.SetPtEtaPhiM(IVF.pt[0], IVF.eta[0], IVF.phi[0], IVF.massBcand[0]);
1591     BCands_H2.SetPtEtaPhiM(IVF.pt[1], IVF.eta[1], IVF.phi[1], IVF.massBcand[1]);
1592     BCands_H = BCands_H1 + BCands_H2;
1593     SVH.dR = deltaR(IVF.eta[0], IVF.phi[0], IVF.eta[1], IVF.phi[1] );
1594     SVH.dPhi = deltaPhi(IVF.phi[0], IVF.phi[1] );
1595     SVH.dEta = TMath::Abs(IVF.eta[0] - IVF.eta[1] );
1596     SVH.mass = BCands_H.M();
1597     SVH.pt = BCands_H.Pt();
1598     SVH.eta = BCands_H.Eta();
1599     SVH.phi = BCands_H.Phi();
1600     }
1601    
1602     //SimBhadron
1603     SimBs.reset();
1604     if(isMC_){
1605     nSimBs = sbhc->size();
1606     for( int j=0; j < nSimBs && j < MAXB; ++j )
1607     SimBs.set( sbhc->at(j), j);
1608     if(nSimBs > 1){
1609     TLorentzVector SimBs_H1, SimBs_H2, SimBs_H;
1610     SimBs_H1.SetPtEtaPhiM(SimBs.pt[0], SimBs.eta[0], SimBs.phi[0], SimBs.mass[0]);
1611     SimBs_H2.SetPtEtaPhiM(SimBs.pt[1], SimBs.eta[1], SimBs.phi[1], SimBs.mass[1]);
1612     SimBs_H = SimBs_H1 + SimBs_H2;
1613     SimBsH.dR = deltaR(SimBs.eta[0], SimBs.phi[0], SimBs.eta[1], SimBs.phi[1] );
1614     SimBsH.dPhi = deltaPhi(SimBs.phi[0], SimBs.phi[1] );
1615     SimBsH.dEta = TMath::Abs(SimBs.eta[0] - SimBs.eta[1] );
1616     SimBsH.mass = SimBs_H.M();
1617     SimBsH.pt = SimBs_H.Pt();
1618     SimBsH.eta = SimBs_H.Eta();
1619     SimBsH.phi = SimBs_H.Phi();
1620     }
1621     }
1622    
1623     //Loop on jets
1624     double maxBtag=-99999;
1625     minDeltaPhijetMET = 999;
1626     TLorentzVector bJet;
1627     std::vector<std::vector<BTagWeight::JetInfo> > btagJetInfos;
1628     std::vector<float> jet10eta;
1629     std::vector<float> jet10pt;
1630     std::vector<float> jet30eta;
1631     std::vector<float> jet30pt;
1632     if(fromCandidate)
1633     {
1634     //Loop on Higgs Jets
1635     for(unsigned int j=0; j < vhCand.H.jets.size(); j++ ){
1636     if (vhCand.H.jets[j].csv > maxBtag) { bJet=vhCand.H.jets[j].p4 ; maxBtag =vhCand.H.jets[j].csv; }
1637     if (fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.H.jets[j].p4.Phi())) < minDeltaPhijetMET)
1638     {
1639     minDeltaPhijetMET=fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.H.jets[j].p4.Phi()));
1640     jetPt_minDeltaPhijetMET=vhCand.H.jets[j].p4.Pt();
1641     }
1642     btagJetInfos.push_back(btagEff.jetInfo(vhCand.H.jets[j]));
1643     }
1644     //Loop on Additional Jets
1645     for(unsigned int j=0; j < vhCand.additionalJets.size(); j++ ){
1646     if (vhCand.additionalJets[j].csv > maxBtag) { bJet=vhCand.additionalJets[j].p4 ; maxBtag =vhCand.additionalJets[j].csv; }
1647     /* if (fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.additionalJets[j].p4.Phi())) < minDeltaPhijetMET)
1648     {
1649     minDeltaPhijetMET=fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.additionalJets[j].p4.Phi()));
1650     jetPt_minDeltaPhijetMET=vhCand.additionalJets[j].p4.Pt();
1651     }*/
1652     if( ( isW && ! useHighestPtHiggsW ) || ( ! isW && ! useHighestPtHiggsZ ) ) // btag SF computed using only H-jets if best-H made with dijetPt rather than best CSV
1653     {
1654     if(vhCand.additionalJets[j].p4.Pt() > 20)
1655     btagJetInfos.push_back(btagEff.jetInfo(vhCand.additionalJets[j]));
1656     }
1657     }
1658     }
1659     else
1660     {
1661     //Loop on all jets
1662     for(unsigned int j=0; j < iEvent->simpleJets2.size(); j++ ){
1663     if (iEvent->simpleJets2[j].csv > maxBtag) { bJet=iEvent->simpleJets2[j].p4 ; maxBtag =iEvent->simpleJets2[j].csv; }
1664     if ( iEvent->simpleJets2[j].p4.Pt() > 20 && fabs(iEvent->simpleJets2[j].p4.Eta()) < 2.5&& fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), iEvent->simpleJets2[j].p4.Phi())) < minDeltaPhijetMET)
1665     {
1666     minDeltaPhijetMET=fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), iEvent->simpleJets2[j].p4.Phi()));
1667     jetPt_minDeltaPhijetMET=iEvent->simpleJets2[j].p4.Pt();
1668     }
1669     if(iEvent->simpleJets2[j].p4.Pt() > 10)
1670     {
1671     jet10eta.push_back(iEvent->simpleJets2[j].p4.Eta());
1672     jet10pt.push_back(iEvent->simpleJets2[j].p4.Pt());
1673     }
1674     if(iEvent->simpleJets2[j].p4.Pt() > 30)
1675     {
1676     jet30eta.push_back(iEvent->simpleJets2[j].p4.Eta());
1677     jet30pt.push_back(iEvent->simpleJets2[j].p4.Pt());
1678     }
1679    
1680     //For events made with highest CSV, all jets in the event should be taken into account for "tagging" SF (anti tagging is a mess)
1681     // because for example a light jet not used for the Higgs can have in reality a higher CSV due to SF > 1 and become a higgs jet
1682     if( ( isW && ! useHighestPtHiggsW ) || ( ! isW && ! useHighestPtHiggsZ ) )
1683     {
1684     if(iEvent->simpleJets2[j].p4.Pt() > 20 && fabs(iEvent->simpleJets2[j].p4.Eta()) < 2.5)
1685     btagJetInfos.push_back(btagEff.jetInfo(iEvent->simpleJets2[j]));
1686     }
1687     }
1688    
1689     //Loop on Higgs jets
1690    
1691     if(vhCand.H.HiggsFlag){
1692     for(unsigned int j=0; j < vhCand.H.jets.size(); j++ ) {
1693    
1694     //if we use the highest pt pair, only the two higgs jet should be used to compute the SF because the other jets are excluded
1695     // by a criteria (pt of the dijet) that is not btag SF dependent
1696     if(!( ( isW && ! useHighestPtHiggsW ) || ( ! isW && ! useHighestPtHiggsZ ) )) {
1697     btagJetInfos.push_back(btagEff.jetInfo(vhCand.H.jets[j]));
1698     }
1699     }
1700     }// HiggsFlag
1701    
1702     }
1703     vLeptons.reset();
1704     weightTrig = 1.; // better to default to 1
1705     weightTrigMay = -1.;
1706     weightTrigV4 = -1.;
1707     weightTrigOrMu30 = 1.;
1708     TLorentzVector leptonForTop;
1709     size_t firstAddMu=0;
1710     size_t firstAddEle=0;
1711     if(Vtype == VHbbCandidate::Zmumu ){
1712     vLeptons.set(vhCand.V.muons[0],0,13);
1713     vLeptons.set(vhCand.V.muons[1],1,13);
1714     float cweightID = triggerWeight.scaleMuID(vLeptons.pt[0],vLeptons.eta[0]) * triggerWeight.scaleMuID(vLeptons.pt[1],vLeptons.eta[1]) ;
1715     float weightTrig1 = triggerWeight.scaleMuIsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
1716     float weightTrig2 = triggerWeight.scaleMuIsoHLT(vLeptons.pt[1],vLeptons.eta[1]);
1717     float cweightTrig = weightTrig1 + weightTrig2 - weightTrig1*weightTrig2;
1718     weightTrig = cweightID * cweightTrig;
1719     nvlep=2;
1720     firstAddMu=2;
1721     }
1722     if( Vtype == VHbbCandidate::Zee ){
1723     vLeptons.set(vhCand.V.electrons[0],0,11);
1724     vLeptons.set(vhCand.V.electrons[1],1,11);
1725     nvlep=2;
1726     firstAddEle=2;
1727     std::vector<float> pt,eta;
1728     pt.push_back(vLeptons.pt[0]); eta.push_back(vLeptons.eta[0]);
1729     pt.push_back(vLeptons.pt[1]); eta.push_back(vLeptons.eta[1]);
1730     weightEleRecoAndId=triggerWeight.scaleID95Ele(vLeptons.pt[0],vLeptons.eta[0]) * triggerWeight.scaleRecoEle(vLeptons.pt[0],vLeptons.eta[0]) *
1731     triggerWeight.scaleID95Ele(vLeptons.pt[1],vLeptons.eta[1]) * triggerWeight.scaleRecoEle(vLeptons.pt[1],vLeptons.eta[1]);
1732     weightEleTrigElePart = triggerWeight.scaleDoubleEle17Ele8(pt,eta);
1733     weightEleTrigEleAugPart = triggerWeight.scaleDoubleEle17Ele8Aug(pt,eta);
1734     weightTrig = (weightEleTrigElePart*1.14+weightEleTrigEleAugPart*0.98 )/2.12 * weightEleRecoAndId;
1735    
1736    
1737    
1738     }
1739     if(Vtype == VHbbCandidate::Wmun ){
1740     leptonForTop=vhCand.V.muons[0].p4;
1741     vLeptons.set(vhCand.V.muons[0],0,13);
1742     float cweightID = triggerWeight.scaleMuID(vLeptons.pt[0],vLeptons.eta[0]);
1743     float weightTrig1 = triggerWeight.scaleMuIsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
1744     float cweightTrig = weightTrig1;
1745     weightTrig = cweightID * cweightTrig;
1746     float weightTrig1OrMu30 = triggerWeight.scaleMuOr30IsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
1747     weightTrigOrMu30 = cweightID*weightTrig1OrMu30;
1748     nvlep=1;
1749     firstAddMu=1;
1750     }
1751     if( Vtype == VHbbCandidate::Wen ){
1752     leptonForTop=vhCand.V.electrons[0].p4;
1753     vLeptons.set(vhCand.V.electrons[0],0,11);
1754     nvlep=1;
1755     firstAddEle=1;
1756     weightTrigMay = triggerWeight.scaleSingleEleMay(vLeptons.pt[0],vLeptons.eta[0]);
1757     weightTrigV4 = triggerWeight.scaleSingleEleV4(vLeptons.pt[0],vLeptons.eta[0]);
1758     weightEleRecoAndId=triggerWeight.scaleID80Ele(vLeptons.pt[0],vLeptons.eta[0]) * triggerWeight.scaleRecoEle(vLeptons.pt[0],vLeptons.eta[0]);
1759     weightEleTrigJetMETPart=triggerWeight.scaleJet30Jet25(jet30pt,jet30eta)*triggerWeight.scalePFMHTEle(MET.et);
1760     weightEleTrigElePart= weightTrigV4; //this is for debugging only, checking only the V4 part
1761    
1762     weightTrigMay*=weightEleRecoAndId;
1763     weightTrigV4*=weightEleRecoAndId;
1764     weightTrigV4*=weightEleTrigJetMETPart;
1765     // weightTrig = weightTrigMay * 0.187 + weightTrigV4 * (1.-0.187); //FIXME: use proper lumi if we reload 2.fb
1766     weightTrig = (weightTrigMay * 0.215 + weightTrigV4 * 1.915)/ 2.13; //FIXME: use proper lumi if we reload 2.fb
1767     }
1768    
1769     if(isMC_)
1770     {
1771     weightTrigMET80 = triggerWeight.scaleMET80(MET.et);
1772     weightTrigMET100 = triggerWeight.scaleMET80(MET.et);
1773     weightTrig2CJet20 = triggerWeight.scale2CentralJet( jet10pt, jet10eta);
1774     weightTrigMET150 = triggerWeight.scaleMET150(MET.et);
1775     weightTrigMET802CJet= weightTrigMET80 * weightTrig2CJet20;
1776     weightTrigMET1002CJet= weightTrigMET100 * weightTrig2CJet20;
1777     }
1778     if( Vtype == VHbbCandidate::Znn ){
1779     nvlep=0;
1780     float weightTrig1 = triggerWeight.scaleMetHLT(vhCand.V.mets.at(0).p4.Pt());
1781     weightTrigMETLP = weightTrig1;
1782     weightTrig = weightTrigMET150 + weightTrigMET802CJet - weightTrigMET802CJet*weightTrigMET150;
1783     }
1784    
1785     if(weightTrigMay < 0) weightTrigMay=weightTrig;
1786     if(weightTrigV4 < 0) weightTrigV4=weightTrig;
1787     if(!isMC_)
1788     {
1789     weightTrig = 1.;
1790     weightTrigMay = 1.;
1791     weightTrigV4 = 1.;
1792     weightEleRecoAndId= 1.;
1793     weightEleTrigJetMETPart= 1.;
1794     weightEleTrigElePart= 1.;
1795     weightEleTrigEleAugPart=1.;
1796     weightTrigMET80= 1.;
1797     weightTrigMET100= 1.;
1798     weightTrig2CJet20= 1.;
1799     weightTrigMET150= 1.;
1800     weightTrigMET802CJet= 1.;
1801     weightTrigMET1002CJet= 1.;
1802     weightTrigMETLP = 1.;
1803    
1804     }
1805     aLeptons.reset();
1806     nalep=0;
1807     if(fromCandidate)
1808     {
1809     for(size_t j=firstAddMu;j< vhCand.V.muons.size();j++) aLeptons.set(vhCand.V.muons[j],nalep++,13);
1810     for(size_t j=firstAddEle;j< vhCand.V.electrons.size();j++) aLeptons.set(vhCand.V.electrons[j],nalep++,11);
1811     }
1812     else
1813     {
1814     for(size_t j=0;j< iEvent->muInfo.size();j++)
1815     {
1816     if((j!= vhCand.V.firstLepton && j!= vhCand.V.secondLepton) || ((Vtype != VHbbCandidate::Wmun ) && (Vtype != VHbbCandidate::Zmumu )) )
1817     aLeptons.set(iEvent->muInfo[j],nalep++,13);
1818     }
1819     for(size_t j=0;j< iEvent->eleInfo.size();j++)
1820     {
1821     if((j!= vhCand.V.firstLepton && j!= vhCand.V.secondLepton) || ((Vtype != VHbbCandidate::Wen ) && (Vtype != VHbbCandidate::Zee )))
1822     aLeptons.set(iEvent->eleInfo[j],nalep++,11);
1823     }
1824    
1825     }
1826    
1827    
1828     if(isMC_)
1829     {
1830     //std::cout << "BTAGSF " << btagJetInfos.size() << " " << btag.weight<BTag1Tight2CustomFilter>(btagJetInfos) << std::endl;
1831     if ( btagJetInfos.size()< 10)
1832     {
1833     btag1T2CSF = btag.weight<BTag1Tight2CustomFilter>(btagJetInfos);
1834     btag2TSF = btag.weight<BTag2TightFilter>(btagJetInfos);
1835     btag1TSF = btag.weight<BTag1TightFilter>(btagJetInfos);
1836     btagA0CSF = btag.weight<BTagAntiMax0CustomFilter>(btagJetInfos);
1837     btagA0TSF = btag.weight<BTagAntiMax0TightFilter>(btagJetInfos);
1838     btag2CSF = btag.weight<BTag2CustomFilter>(btagJetInfos);
1839     btag1TA1C = btag.weight<BTag1TightAndMax1CustomFilter>(btagJetInfos);
1840     }
1841     else
1842     {
1843     std::cout << "WARNING: combinatorics for " << btagJetInfos.size() << " jets is too high (>=10). use SF=1 " << std::endl;
1844     //TODO: revert to random throw for this cases
1845     btag1T2CSF = 1.;
1846     btag2TSF = 1.;
1847     btag1TSF = 1.;
1848     btagA0CSF = 1.;
1849     btagA0TSF = 1.;
1850     btag2CSF = 1.;
1851     btag1TA1C = 1.;
1852     }
1853     }
1854    
1855     if(maxBtag > -99999)
1856     {
1857     TopHypo topQuark = TopMassReco::topMass(leptonForTop,bJet,vhCand.V.mets.at(0).p4);
1858     top.mass = topQuark.p4.M();
1859     top.pt = topQuark.p4.Pt();
1860     top.wMass = topQuark.p4W.M();
1861     } else {
1862     top.mass = -99;
1863     top.pt = -99;
1864     top.wMass = -99;
1865     }
1866    
1867    
1868    
1869     //FIXME: too much warnings... figure out why
1870     // gendrcc=aux.genCCDeltaR();
1871     // gendrbb=aux.genBBDeltaR();
1872    
1873    
1874    
1875     genZpt=aux.mcZ.size() > 0 ? aux.mcZ[0].p4.Pt():-99;
1876     genWpt=aux.mcW.size() > 0 ? aux.mcW[0].p4.Pt():-99;
1877    
1878     // Z* is status=3 and Nmother=2 (q and qbar)
1879     // Z is status=2 and Ndau=2 (mup and mum)
1880     for (unsigned int i=0; i<aux.mcZ.size(); i++){
1881     if (aux.mcZ[i].status==3) {
1882     genZstar.mass = aux.mcZ[i].p4.M();
1883     genZstar.pt = aux.mcZ[i].p4.Pt();
1884     genZstar.eta = aux.mcZ[i].p4.Eta();
1885     genZstar.phi = aux.mcZ[i].p4.Phi();
1886     genZstar.status = aux.mcZ[i].status;
1887     genZstar.charge = aux.mcZ[i].charge;
1888     if (aux.mcZ[i].momid!=-99) genZstar.momid = aux.mcZ[i].momid ;
1889     }
1890    
1891    
1892    
1893     if (aux.mcZ[i].dauid.size()>1) {
1894     if ( abs(aux.mcZ[i].dauid[0])==13 || abs(aux.mcZ[i].dauid[0])==11 ) {
1895     genZ.mass = aux.mcZ[i].p4.M();
1896     genZ.pt = aux.mcZ[i].p4.Pt();
1897     genZ.eta = aux.mcZ[i].p4.Eta();
1898     genZ.phi = aux.mcZ[i].p4.Phi();
1899     genZ.status = aux.mcZ[i].status;
1900     genZ.charge = aux.mcZ[i].charge;
1901     if ( aux.mcZ[i].momid!=-99) genZ.momid = aux.mcZ[i].momid;
1902     }
1903     }
1904     }
1905    
1906    
1907    
1908     for (unsigned int i=0; i<aux.mcW.size(); i++){
1909     if ( aux.mcW[i].momid==6 && aux.mcW[i].dauid.size()>1 ){
1910     genTop.wdau1mass= aux.mcW[i].dauFourMomentum[0].M();
1911     genTop.wdau1pt= aux.mcW[i].dauFourMomentum[0].Pt();
1912     genTop.wdau1eta= aux.mcW[i].dauFourMomentum[0].Eta();
1913     genTop.wdau1phi= aux.mcW[i].dauFourMomentum[0].Phi();
1914     genTop.wdau1id= aux.mcW[i].dauid[0];
1915    
1916     genTop.wdau2mass= aux.mcW[i].dauFourMomentum[1].M();
1917     genTop.wdau2pt= aux.mcW[i].dauFourMomentum[1].Pt();
1918     genTop.wdau2eta= aux.mcW[i].dauFourMomentum[1].Eta();
1919     genTop.wdau2phi= aux.mcW[i].dauFourMomentum[1].Phi();
1920     genTop.wdau2id= aux.mcW[i].dauid[1];
1921    
1922     }
1923    
1924    
1925     if ( aux.mcW[i].momid==-6 && aux.mcW[i].dauid.size()>1 ){
1926     genTbar.wdau1mass= aux.mcW[i].dauFourMomentum[0].M();
1927     genTbar.wdau1pt= aux.mcW[i].dauFourMomentum[0].Pt();
1928     genTbar.wdau1eta= aux.mcW[i].dauFourMomentum[0].Eta();
1929     genTbar.wdau1phi= aux.mcW[i].dauFourMomentum[0].Phi();
1930     genTbar.wdau1id= aux.mcW[i].dauid[0];
1931    
1932     genTbar.wdau2mass= aux.mcW[i].dauFourMomentum[1].M();
1933     genTbar.wdau2pt= aux.mcW[i].dauFourMomentum[1].Pt();
1934     genTbar.wdau2eta= aux.mcW[i].dauFourMomentum[1].Eta();
1935     genTbar.wdau2phi= aux.mcW[i].dauFourMomentum[1].Phi();
1936     genTbar.wdau2id= aux.mcW[i].dauid[1];
1937    
1938     }
1939    
1940     if (aux.mcW[i].status==3 ) {
1941     genWstar.mass = aux.mcW[i].p4.M();
1942     genWstar.pt = aux.mcW[i].p4.Pt();
1943     genWstar.eta = aux.mcW[i].p4.Eta();
1944     genWstar.phi = aux.mcW[i].p4.Phi();
1945     genWstar.status = aux.mcW[i].status;
1946     genWstar.charge = aux.mcW[i].charge;
1947     if ( aux.mcW[i].momid!=-99) genWstar.momid = aux.mcW[i].momid;
1948     }
1949     if (aux.mcW[i].dauid.size()>1 && (abs(aux.mcW[i].dauid[0])==13 || abs(aux.mcW[i].dauid[0])==11 )) {
1950     genW.mass = aux.mcW[i].p4.M();
1951     genW.pt = aux.mcW[i].p4.Pt();
1952     genW.eta = aux.mcW[i].p4.Eta();
1953     genW.phi = aux.mcW[i].p4.Phi();
1954     genW.status = aux.mcW[i].status;
1955     genW.charge = aux.mcW[i].charge;
1956     if (aux.mcW[i].momid!=-99) genW.momid = aux.mcW[i].momid;
1957     }
1958     }
1959     // b coming from Higgs
1960     for (unsigned int i=0; i<aux.mcB.size(); i++){
1961     if (abs(aux.mcB[i].momid)!=5) {
1962     genB.mass = aux.mcB[i].p4.M();
1963     genB.pt = aux.mcB[i].p4.Pt();
1964     genB.eta = aux.mcB[i].p4.Eta();
1965     genB.phi = aux.mcB[i].p4.Phi();
1966     genB.status = aux.mcB[i].status;
1967     genB.charge = aux.mcB[i].charge;
1968     if (aux.mcB[i].momid!=-99) genB.momid = aux.mcB[i].momid;
1969     }
1970    
1971     if ( aux.mcB[i].momid==6 ){
1972     genTop.bmass = aux.mcB[i].p4.M();
1973     genTop.bpt = aux.mcB[i].p4.Pt();
1974     genTop.beta = aux.mcB[i].p4.Eta();
1975     genTop.bphi = aux.mcB[i].p4.Phi();
1976     genTop.bstatus = aux.mcB[i].status;
1977    
1978     }
1979     }
1980    
1981     for (unsigned int i=0; i<aux.mcBbar.size(); i++){
1982     if (abs(aux.mcBbar[i].momid)!=5 ) {
1983     genBbar.mass = aux.mcBbar[i].p4.M();
1984     genBbar.pt = aux.mcBbar[i].p4.Pt();
1985     genBbar.eta = aux.mcBbar[i].p4.Eta();
1986     genBbar.phi = aux.mcBbar[i].p4.Phi();
1987     genBbar.status = aux.mcBbar[i].status;
1988     if (aux.mcBbar[i].momid!=-99) genBbar.momid = aux.mcBbar[i].momid;
1989     }
1990     if ( aux.mcBbar[i].momid==-6 ){
1991     genTbar.bmass = aux.mcBbar[i].p4.M();
1992     genTbar.bpt = aux.mcBbar[i].p4.Pt();
1993     genTbar.beta = aux.mcBbar[i].p4.Eta();
1994     genTbar.bphi = aux.mcBbar[i].p4.Phi();
1995     genTbar.bstatus = aux.mcBbar[i].status;
1996    
1997    
1998     }
1999    
2000     }
2001    
2002    
2003    
2004    
2005     if (aux.mcH.size()>0) {
2006     genH.mass = aux.mcH[0].p4.M();
2007     genH.pt = aux.mcH[0].p4.Pt();
2008     genH.eta = aux.mcH[0].p4.Eta();
2009     genH.phi = aux.mcH[0].p4.Phi();
2010     genH.status = aux.mcH[0].status;
2011     genH.charge = aux.mcH[0].charge;
2012     if (aux.mcH[0].momid!=-99) genH.momid = aux.mcH[0].momid;
2013     }
2014    
2015    
2016    
2017    
2018     WminusMode=-99;
2019     WplusMode=-99;
2020     for(unsigned int j=0; j< aux.mcW.size();j++)
2021     {
2022     for(unsigned int k=0;k< aux.mcW[j].dauid.size();k++)
2023     {
2024     int idd=abs(aux.mcW[j].dauid[k]);
2025     if(idd==11 || idd==13 || idd==15|| (idd<=5 && idd >=1))
2026     {
2027     if(WminusMode==-99 && aux.mcW[j].charge ==-1) WminusMode = idd;
2028     if(WplusMode==-99 && aux.mcW[j].charge ==+1) WplusMode = idd;
2029     }
2030     }
2031     /*
2032     /// now check if a semileptonic W is also in a bjets....
2033     if ( ( (WminusMode==11 || WminusMode==13 || WminusMode==15 ) || (WplusMode==11 || WplusMode==13 || WplusMode==15 )) && deltaR(vhCand.H.jets[0].p4.Eta(),vhCand.H.jets[0].p4.Phi(), aux.mcW[j].p4.Eta(), aux.mcW[j].p4.Phi())<0.3 ) hJets.isSemiLeptMCtruth[0]=1;
2034     if ( ( (WminusMode==11 || WminusMode==13 || WminusMode==15 ) || (WplusMode==11 || WplusMode==13 || WplusMode==15 )) && deltaR(vhCand.H.jets[1].p4.Eta(),vhCand.H.jets[1].p4.Phi(), aux.mcW[j].p4.Eta(), aux.mcW[j].p4.Phi())<0.3 ) hJets.isSemiLeptMCtruth[1]=1;
2035    
2036     for( int j=0; j < naJets && j < MAXJ; j++ )
2037     {
2038     if ((idd==11 || idd==13 || idd==15 ) && deltaR(vhCand.additionalJets[j].p4.Eta(),vhCand.additionalJets[j].p4.Phi(), aux.mcW[j].p4.Eta(), aux.mcW[j].p4.Phi()) <0.3) aJets.isSemiLept[j]=1;
2039    
2040     }
2041     */
2042    
2043     }
2044     /// Compute pull angle from AK7
2045     if(vhCand.H.HiggsFlag){
2046     if(!fromCandidate){
2047     std::vector<VHbbEvent::SimpleJet> ak7wrt1(iEvent->simpleJets3);
2048     std::vector<VHbbEvent::SimpleJet> ak7wrt2(iEvent->simpleJets3);
2049     if(ak7wrt1.size() > 1){
2050     CompareDeltaR deltaRComparatorJ1(vhCand.H.jets[0].p4);
2051     CompareDeltaR deltaRComparatorJ2(vhCand.H.jets[1].p4);
2052     std::sort( ak7wrt1.begin(),ak7wrt1.end(),deltaRComparatorJ1 );
2053     std::sort( ak7wrt2.begin(),ak7wrt2.end(),deltaRComparatorJ2 );
2054     std::vector<VHbbEvent::SimpleJet> ak7_matched;
2055     // if the matched are different save them
2056     if(ak7wrt1[0].p4.DeltaR(ak7wrt2[0].p4) > 0.1) {
2057     ak7_matched.push_back(ak7wrt1[0]);
2058     ak7_matched.push_back(ak7wrt2[0]);
2059     }
2060     // else look at the second best
2061     else{
2062     // ak7wrt1 is best
2063     if( ak7wrt1[1].p4.DeltaR(vhCand.H.jets[0].p4) < ak7wrt2[1].p4.DeltaR(vhCand.H.jets[1].p4))
2064     {
2065     ak7_matched.push_back(ak7wrt1[1]);
2066     ak7_matched.push_back(ak7wrt2[0]);
2067     }
2068     else
2069     {
2070     ak7_matched.push_back(ak7wrt1[0]);
2071     ak7_matched.push_back(ak7wrt2[1]);
2072     }
2073     }
2074     CompareJetPt ptComparator;
2075     std::sort( ak7_matched.begin(),ak7_matched.end(),ptComparator );
2076     if(ak7_matched[0].p4.DeltaR(vhCand.H.jets[0].p4) < 0.5
2077     and ak7_matched[1].p4.DeltaR(vhCand.H.jets[1].p4) < 0.5)
2078     {
2079     deltaPullAngleAK7 = VHbbCandidateTools::getDeltaTheta(ak7_matched[0],ak7_matched[1]);
2080     deltaPullAngle2AK7 = VHbbCandidateTools::getDeltaTheta(ak7_matched[1],ak7_matched[0]);
2081     }
2082     }
2083     }
2084     }//HiggsFlag
2085    
2086     _outTree->Fill();
2087    
2088     }// closed event loop
2089    
2090     std::cout << "closing the file: " << inputFiles_[iFile] << std::endl;
2091     inFile->Close();
2092     // close input file
2093     } // loop on files
2094    
2095    
2096     std::cout << "Events: " << ievt <<std::endl;
2097     std::cout << "TotalCount: " << totalcount <<std::endl;
2098    
2099    
2100    
2101     _outFile->cd();
2102    
2103     _outTree->Write();
2104     _outFile->Write();
2105     _outFile->Close();
2106     return 0;
2107     }
2108    
2109