ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler7TeV.cc
Revision: 1.4
Committed: Tue Jun 5 18:03:16 2012 UTC (12 years, 11 months ago) by bortigno
Content type: text/plain
Branch: MAIN
CVS Tags: Step2ForV32_v2
Changes since 1.3: +2 -0 lines
Log Message:
Add initialisation for lhe variables

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     if(status == 1 && ( TMath::Abs(id) >= 0 || TMath::Abs(id) < 6 ) ){
1137     lheHT += hepeup_.PUP[i][3];
1138     lheNj++;
1139     }
1140    
1141 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;}
1142     if(id==-11){ lbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lbarCheck=true;}
1143     if(id==12){ vl.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlCheck=true;}
1144     if(id==-12){ vlbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlbarCheck=true;}
1145    
1146     if(id==13){ l.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lCheck=true;}
1147     if(id==-13){ lbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lbarCheck=true;}
1148     if(id==14){ vl.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlCheck=true;}
1149     if(id==-14){ vlbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlbarCheck=true;}
1150    
1151     if(id==15){ l.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lCheck=true;}
1152     if(id==-15){ lbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); lbarCheck=true;}
1153     if(id==16){ vl.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlCheck=true;}
1154     if(id==-16){ vlbar.SetPxPyPzE(hepeup_.PUP[i][0],hepeup_.PUP[i][1],hepeup_.PUP[i][2],hepeup_.PUP[i][3]); vlbarCheck=true;}
1155    
1156     }
1157     if( lCheck && lbarCheck ) V_tlv = l + lbar; // ZtoLL
1158     if( vlCheck && vlbarCheck ) V_tlv = vl + vlbar; // ZtoNuNu
1159     if( lCheck && vlbarCheck ) V_tlv = l + vlbar; // WToLNu
1160     if( lbarCheck && vlCheck ) V_tlv = lbar + vl; // WToLNu
1161     lheV_pt = V_tlv.Pt();
1162     }
1163    
1164     //std::cout << "lhe V pt = " << lheV_pt << std::endl;
1165    
1166     //Write event info
1167     EVENT.run = ev.id().run();
1168     EVENT.lumi = ev.id().luminosityBlock();
1169     EVENT.event = ev.id().event();
1170     EVENT.json = jsonContainsEvent (jsonVector, ev);
1171    
1172     // simBHadrons
1173     const SimBHadronCollection *sbhc;
1174     if(isMC_){
1175     fwlite::Handle<SimBHadronCollection> SBHC;
1176     SBHC.getByLabel(ev, "bhadrons");
1177     sbhc = SBHC.product();
1178     }
1179    
1180     const std::vector<VHbbCandidate> * candZ ;
1181     const std::vector<VHbbCandidate> * candW ;
1182     VHbbEvent modifiedEvent;;
1183     const VHbbEvent * iEvent =0;
1184     if(fromCandidate)
1185     {
1186     fwlite::Handle< std::vector<VHbbCandidate> > vhbbCandHandleZ;
1187     vhbbCandHandleZ.getByLabel(ev,"hbbBestCSVPt20Candidates");
1188     candZ = vhbbCandHandleZ.product();
1189    
1190     fwlite::Handle< std::vector<VHbbCandidate> > vhbbCandHandle;
1191     vhbbCandHandle.getByLabel(ev,"hbbHighestPtHiggsPt30Candidates");
1192     candW = vhbbCandHandle.product();
1193     }
1194     else
1195     {
1196     candZlocal->clear();
1197     candWlocal->clear();
1198     fwlite::Handle< VHbbEvent > vhbbHandle;
1199     vhbbHandle.getByLabel(ev,"HbbAnalyzerNew");
1200     modifiedEvent = *vhbbHandle.product();
1201     if(isMC_)
1202     {
1203     iEvent= &modifiedEvent;
1204    
1205     for(size_t j=0; j< modifiedEvent.simpleJets2.size() ; j++)
1206     {
1207     TLorentzVector & p4 = modifiedEvent.simpleJets2[j].p4;
1208     TLorentzVector & mcp4 = modifiedEvent.simpleJets2[j].bestMCp4;
1209     if ((fabs(p4.Pt() - mcp4.Pt())/ p4.Pt())<0.5) { //Limit the effect to the core
1210     float cor = (p4.Pt()+resolutionBias(fabs(p4.Eta()))*(p4.Pt()-mcp4.Pt()))/p4.Pt();
1211     p4.SetPtEtaPhiE(p4.Pt()*cor,p4.Eta(), p4.Phi(), p4.E()*cor);
1212     }
1213     }
1214     } else
1215     {
1216     iEvent = vhbbHandle.product();
1217     }
1218    
1219     algoZ->run(iEvent,*candZlocal);
1220     algoW->run(iEvent,*candWlocal);
1221    
1222     if(candZlocal->size() == 0 or candZlocal->at(0).H.jets.size() < 2) //recover low pt
1223     {
1224     candZlocal->clear();
1225     candWlocal->clear();
1226     algoRecoverLowPt->run(iEvent,*candZlocal);
1227     algoRecoverLowPt->run(iEvent,*candWlocal);
1228     }
1229    
1230     candZ= candZlocal;
1231     candW= candWlocal;
1232     /* for(size_t m=0;m<iEvent->muInfo.size();m++)
1233     {
1234    
1235     if( fabs(iEvent->muInfo[m].p4.Pt()-28.118684) < 0.0001 ||
1236     fabs(iEvent->muInfo[m].p4.Pt()-34.853199) < 0.0001 )
1237     {
1238     std::cout << "FOUND " << iEvent->muInfo[m].p4.Pt() << " " << EVENT.event << " " << candW->size() << " " << candZ->size() << std::endl;
1239     }
1240     }
1241     */
1242    
1243     }
1244    
1245     const std::vector<VHbbCandidate> * cand = candZ;
1246    
1247    
1248    
1249     /* fwlite::Handle< VHbbEvent > vhbbHandle;
1250     vhbbHandle.getByLabel(ev,"HbbAnalyzerNew");
1251     const VHbbEvent iEvent = *vhbbHandle.product();
1252     */
1253    
1254     // std::clog << "Filling tree "<< std::endl;
1255     bool isW=false;
1256    
1257     // to check how much we gain with jets subtraction
1258    
1259    
1260    
1261     genHpt=aux.mcH.size() > 0 ? aux.mcH[0].p4.Pt():-99;
1262    
1263     if(cand->size() == 0 or cand->at(0).H.jets.size() < 2) continue;
1264     //if(cand->size() == 0 ) continue;
1265     //std::cout << "cand->size() " << cand->size() << std::endl;
1266     //std::cout << "cand->at(0).H.jets.size() " << cand->at(0).H.jets.size() << std::endl;
1267     if(cand->size() > 1 )
1268     {
1269     std::cout << "MULTIPLE CANDIDATES: " << cand->size() << std::endl;
1270     }
1271     if(cand->at(0).candidateType == VHbbCandidate::Wmun || cand->at(0).candidateType == VHbbCandidate::Wen ) { cand=candW; isW=true; }
1272     if(cand->size() == 0)
1273     {
1274     // std::cout << "W event loss due to tigther cuts" << std::endl;
1275     continue;
1276     }
1277    
1278    
1279     // secondary vtxs
1280     fwlite::Handle<std::vector<reco::Vertex> > SVC;
1281     SVC.getByLabel(ev,"bcandidates");
1282     const std::vector<reco::Vertex> svc = *(SVC.product());
1283    
1284     const VHbbCandidate & vhCand = cand->at(0);
1285     patFilters.setEvent(&ev,"VH");
1286     hbhe = patFilters.accept("hbhe");
1287     ecalFlag = patFilters.accept("ecalFilter");
1288     totalKinematics = patFilters.accept("totalKinematics");
1289     cschaloFlag = patFilters.accept("cschaloFilter");
1290     hcallaserFlag = patFilters.accept("hcallaserFilter");
1291     trackingfailureFlag = patFilters.accept("trackingfailureFilter");
1292    
1293     trigger.setEvent(&ev);
1294     for(size_t j=0;j < triggers.size();j++)
1295     triggerFlags[j]=trigger.accept(triggers[j]);
1296    
1297     eventFlav=0;
1298    
1299    
1300    
1301     if(aux.mcBbar.size() > 0 || aux.mcB.size() > 0) eventFlav=5;
1302     else if(aux.mcC.size() > 0) eventFlav=4;
1303    
1304    
1305     Vtype = vhCand.candidateType;
1306    
1307     if(vhCand.H.HiggsFlag) H.HiggsFlag=1; else H.HiggsFlag=0;
1308    
1309     if(vhCand.H.HiggsFlag){
1310     H.mass = vhCand.H.p4.M();
1311     H.pt = vhCand.H.p4.Pt();
1312    
1313    
1314     H.eta = vhCand.H.p4.Eta();
1315     H.phi = vhCand.H.p4.Phi();
1316     }
1317    
1318     if(vhCand.FatH.FatHiggsFlag) FatH.FatHiggsFlag =1; else FatH.FatHiggsFlag=0;
1319     fathFilterJets.reset();
1320     aJetsFat.reset();
1321     if(vhCand.FatH.FatHiggsFlag){
1322     FatH.mass= vhCand.FatH.p4.M();
1323     FatH.pt = vhCand.FatH.p4.Pt();
1324     FatH.eta = vhCand.FatH.p4.Eta();
1325     FatH.phi = vhCand.FatH.p4.Phi();
1326    
1327     // if(vhCand.FatH.FatHiggsFlag) vhCand.FatH.subjetsSize;
1328     nfathFilterJets=vhCand.FatH.subjetsSize;
1329     for( int j=0; j < nfathFilterJets; j++ ){
1330     fathFilterJets.set(vhCand.FatH.jets[j],j);
1331     }
1332    
1333     if(nfathFilterJets==2){
1334     FatH.filteredmass=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4).M();
1335     FatH.filteredpt=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4).Pt();
1336     FatH.filteredeta=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4).Eta();
1337     FatH.filteredphi=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4).Phi();
1338     }
1339     else if(nfathFilterJets==3){
1340     FatH.filteredmass=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4+vhCand.FatH.jets[2].p4).M();
1341     FatH.filteredpt=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4+vhCand.FatH.jets[2].p4).Pt();
1342     FatH.filteredeta=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4+vhCand.FatH.jets[2].p4).Eta();
1343     FatH.filteredphi=(vhCand.FatH.jets[0].p4+vhCand.FatH.jets[1].p4+vhCand.FatH.jets[2].p4).Phi();
1344     }
1345    
1346     naJetsFat=vhCand.additionalJetsFat.size();
1347     for( int j=0; j < naJetsFat && j < MAXJ; j++ )
1348     {
1349     aJetsFat.set(vhCand.additionalJetsFat[j],j);
1350     }
1351    
1352    
1353     } // FatHiggsFlag
1354    
1355     hJets.reset();
1356     aJets.reset();
1357     if(vhCand.H.HiggsFlag){
1358    
1359     nhJets=2;
1360     hJets.set(vhCand.H.jets[0],0);
1361     hJets.set(vhCand.H.jets[1],1);
1362    
1363    
1364     aJets.reset();
1365    
1366     naJets=vhCand.additionalJets.size();
1367     numBJets=0;
1368     if(vhCand.H.jets[0].csv> btagThr) numBJets++;
1369     if(vhCand.H.jets[1].csv> btagThr) numBJets++;
1370     for( int j=0; j < naJets && j < MAXJ; j++ )
1371     {
1372     aJets.set(vhCand.additionalJets[j],j);
1373     if(vhCand.additionalJets[j].csv> btagThr) numBJets++;
1374     }
1375     numJets = vhCand.additionalJets.size()+2;
1376     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());
1377     H.dPhi = deltaPhi(vhCand.H.jets[0].p4.Phi(),vhCand.H.jets[1].p4.Phi());
1378     H.dEta= TMath::Abs( vhCand.H.jets[0].p4.Eta() - vhCand.H.jets[1].p4.Eta() );
1379     HVdPhi = fabs( deltaPhi(vhCand.H.p4.Phi(),vhCand.V.p4.Phi()) ) ;
1380     HVMass = (vhCand.H.p4 + vhCand.V.p4).M() ;
1381     HMETdPhi = fabs( deltaPhi(vhCand.H.p4.Phi(),vhCand.V.mets.at(0).p4.Phi()) ) ;
1382     //eltaPullAngle = vhCand.H.deltaTheta;
1383    
1384     deltaPullAngle = VHbbCandidateTools::getDeltaTheta(vhCand.H.jets[0],vhCand.H.jets[1]);
1385     deltaPullAngle2 = VHbbCandidateTools::getDeltaTheta(vhCand.H.jets[1],vhCand.H.jets[0]);
1386     hJets.cosTheta[0]= vhCand.H.helicities[0];
1387     hJets.cosTheta[1]= vhCand.H.helicities[1];
1388     } // Higgs Flag
1389    
1390     V.mass = vhCand.V.p4.M();
1391     if(isW) V.mass = vhCand.Mt();
1392     V.pt = vhCand.V.p4.Pt();
1393     V.eta = vhCand.V.p4.Eta();
1394     V.phi = vhCand.V.p4.Phi();
1395     VMt = vhCand.Mt() ;
1396    
1397    
1398     // METInfo calomet; METInfo tcmet; METInfo pfmet; METInfo mht; METInfo metNoPU
1399     MET.et = vhCand.V.mets.at(0).p4.Pt();
1400     MET.phi = vhCand.V.mets.at(0).p4.Phi();
1401     MET.sumet = vhCand.V.mets.at(0).sumEt;
1402     MET.sig = vhCand.V.mets.at(0).metSig;
1403    
1404    
1405     fakeMET.sumet = 0;
1406     fakeMET.sig = 0;
1407     fakeMET.et = 0;
1408     fakeMET.phi = 0;
1409     if( Vtype == VHbbCandidate::Zmumu) {
1410     TVector3 mu1 = vhCand.V.muons[0].p4.Vect();
1411     TVector3 mu2 = vhCand.V.muons[1].p4.Vect();
1412     // Not needed with PFMET
1413     // mu1.SetMag( mu1.Mag() - vhCand.V.muons[0].emEnergy - vhCand.V.muons[0].hadEnergy);
1414     // mu2.SetMag( mu2.Mag() - vhCand.V.muons[1].emEnergy - vhCand.V.muons[1].hadEnergy);
1415     TVector3 sum = vhCand.V.mets.at(0).p4.Vect() + mu1 + mu2;
1416     fakeMET.et = sum.Pt();
1417     fakeMET.phi = sum.Phi();
1418     fakeMET.sumet = vhCand.V.mets.at(0).sumEt - mu1.Pt() - mu2.Pt();
1419     }
1420    
1421    
1422    
1423     METnoPU.et = iEvent->metNoPU.p4.Pt();
1424     METnoPU.phi = iEvent->metNoPU.p4.Phi();
1425     METnoPU.sumet = iEvent->metNoPU.sumEt;
1426     METnoPU.sig = iEvent->metNoPU.metSig;
1427     METnoPUCh.et = iEvent->metCh.p4.Pt();
1428     METnoPUCh.phi = iEvent->metCh.p4.Phi();
1429     METnoPUCh.sumet = iEvent->metCh.sumEt;
1430     METnoPUCh.sig = iEvent->metCh.metSig;
1431    
1432     METnoPUCh.et = iEvent->metCh.p4.Pt();
1433     METnoPUCh.phi = iEvent->metCh.p4.Phi();
1434     METnoPUCh.sumet = iEvent->metCh.sumEt;
1435     METnoPUCh.sig = iEvent->metCh.metSig;
1436    
1437    
1438     METtype1corr.et = iEvent->pfmetType1corr.p4.Pt();
1439     METtype1corr.phi = iEvent->pfmetType1corr.p4.Phi();
1440     METtype1corr.sumet = iEvent->pfmetType1corr.sumEt;
1441     METtype1corr.sig = iEvent->pfmetType1corr.metSig;
1442    
1443    
1444     METtype1p2corr.et = iEvent->pfmetType1p2corr.p4.Pt();
1445     METtype1p2corr.phi = iEvent->pfmetType1p2corr.p4.Phi();
1446     METtype1p2corr.sumet = iEvent->pfmetType1p2corr.sumEt;
1447     METtype1p2corr.sig = iEvent->pfmetType1p2corr.metSig;
1448    
1449    
1450     METnoPUtype1corr.et = iEvent->pfmetNoPUType1corr.p4.Pt();
1451     METnoPUtype1corr.phi = iEvent->pfmetNoPUType1corr.p4.Phi();
1452     METnoPUtype1corr.sumet = iEvent->pfmetNoPUType1corr.sumEt;
1453     METnoPUtype1corr.sig = iEvent->pfmetNoPUType1corr.metSig;
1454    
1455    
1456     METnoPUtype1p2corr.et = iEvent->pfmetNoPUType1p2corr.p4.Pt();
1457     METnoPUtype1p2corr.phi = iEvent->pfmetNoPUType1p2corr.p4.Phi();
1458     METnoPUtype1p2corr.sumet = iEvent->pfmetNoPUType1p2corr.sumEt;
1459     METnoPUtype1p2corr.sig = iEvent->pfmetNoPUType1p2corr.metSig;
1460    
1461     // std::cout << " iEvent->metUncInfo.size() " << iEvent->metUncInfo.size() << std::endl;
1462     for(size_t m=0;m<iEvent->metUncInfo.size();m++)
1463     {
1464     metUnc.set(iEvent->metUncInfo[m], m );
1465     // std::cout << "metUncInfo[" << m <<" ].et = " << metUnc.et[m] << std::endl;
1466     }
1467    
1468    
1469     rho = aux.puInfo.rho;
1470     rho25 = aux.puInfo.rho25;
1471     nPVs=aux.pvInfo.nVertices;
1472    
1473     if(!fromCandidate) {
1474     MHT.mht = iEvent->mht.p4.Pt();
1475     MHT.phi = iEvent->mht.p4.Phi();
1476     MHT.ht = iEvent->mht.sumEt;
1477     MHT.sig = iEvent->mht.metSig;
1478     }
1479    
1480    
1481     /////////
1482     // track sharing flags:
1483     ////////
1484     TkSharing.HiggsCSVtkSharing = TkSharing.HiggsIPtkSharing = TkSharing.HiggsSVtkSharing = TkSharing.FatHiggsCSVtkSharing = TkSharing.FatHiggsIPtkSharing = TkSharing.FatHiggsSVtkSharing = false;
1485    
1486     // csv tracks
1487     if(vhCand.H.HiggsFlag){
1488    
1489     if (vhCand.H.jets[0].csvNTracks > 0 && vhCand.H.jets[1].csvNTracks > 0){
1490     for (int t=0;t!=vhCand.H.jets[0].csvNTracks;t++){
1491     for (int ti=0;ti!=vhCand.H.jets[1].csvNTracks;ti++){
1492     if ((int)vhCand.H.jets[0].csvTrackIds[t] == (int)vhCand.H.jets[1].csvTrackIds[ti]){
1493     TkSharing.HiggsCSVtkSharing = true;
1494     }// same trackID
1495     }// loop tracks in second hjet
1496     }// loop tracks in first hjet
1497     }// if tracks in jet
1498    
1499     // ip tracks
1500     if (vhCand.H.jets[0].btagNTracks > 0 && vhCand.H.jets[1].btagNTracks > 0){
1501     for (int t=0;t!=vhCand.H.jets[0].btagNTracks;t++){
1502     for (int ti=0;ti!=vhCand.H.jets[1].btagNTracks;ti++){
1503     if ((int)vhCand.H.jets[0].btagTrackIds[t] == (int)vhCand.H.jets[1].btagTrackIds[ti]){
1504     TkSharing.HiggsIPtkSharing = true;
1505     }// same trackID
1506     }// loop tracks in second hjet
1507     }// loop tracks in first hjet
1508     }// if tracks in jet
1509    
1510     // sv tracks
1511     if (vhCand.H.jets[0].vtxNTracks > 0 && vhCand.H.jets[1].vtxNTracks > 0){
1512     for (int t=0;t!=vhCand.H.jets[0].vtxNTracks;t++){
1513     for (int ti=0;ti!=vhCand.H.jets[1].vtxNTracks;ti++){
1514     if ((int)vhCand.H.jets[0].vtxTrackIds[t] == (int)vhCand.H.jets[1].vtxTrackIds[ti]){
1515     TkSharing.HiggsSVtkSharing = true;
1516     }// same trackID
1517     }// loop tracks in second hjet
1518     }// loop tracks in first hjet
1519     }// if tracks in jet
1520    
1521     } // Di-jet Higgs Flag
1522    
1523     // tracksharing for Filtered jets:
1524     if(vhCand.FatH.FatHiggsFlag && nfathFilterJets > 1){
1525    
1526     // csv tracks
1527     if (vhCand.FatH.jets[0].csvNTracks > 0 && vhCand.FatH.jets[1].csvNTracks > 0){
1528     for (int t=0;t!=vhCand.FatH.jets[0].csvNTracks;t++){
1529     for (int ti=0;ti!=vhCand.FatH.jets[1].csvNTracks;ti++){
1530     if ((int)vhCand.FatH.jets[0].csvTrackIds[t] == (int)vhCand.FatH.jets[1].csvTrackIds[ti]){
1531     TkSharing.FatHiggsCSVtkSharing = true;
1532     }// same trackID
1533     }// loop tracks in second hjet
1534     }// loop tracks in first hjet
1535     }// if tracks in jet
1536    
1537     // ip tracks
1538     if (vhCand.FatH.jets[0].btagNTracks > 0 && vhCand.FatH.jets[1].btagNTracks > 0){
1539     for (int t=0;t!=vhCand.FatH.jets[0].btagNTracks;t++){
1540     for (int ti=0;ti!=vhCand.FatH.jets[1].btagNTracks;ti++){
1541     if ((int)vhCand.FatH.jets[0].btagTrackIds[t] == (int)vhCand.FatH.jets[1].btagTrackIds[ti]){
1542     TkSharing.FatHiggsIPtkSharing = true;
1543     }// same trackID
1544     }// loop tracks in second hjet
1545     }// loop tracks in first hjet
1546     }// if tracks in jet
1547    
1548     // sv tracks
1549     if (vhCand.FatH.jets[0].vtxNTracks > 0 && vhCand.FatH.jets[1].vtxNTracks > 0){
1550     for (int t=0;t!=vhCand.FatH.jets[0].vtxNTracks;t++){
1551     for (int ti=0;ti!=vhCand.FatH.jets[1].vtxNTracks;ti++){
1552     if ((int)vhCand.FatH.jets[0].vtxTrackIds[t] == (int)vhCand.FatH.jets[1].vtxTrackIds[ti]){
1553     TkSharing.FatHiggsSVtkSharing = true;
1554     }// same trackID
1555     }// loop tracks in second hjet
1556     }// loop tracks in first hjet
1557     }// if tracks in jet
1558    
1559     }// fatH
1560    
1561     ////////
1562     ////////
1563    
1564     //Secondary Vertices
1565     IVF.reset();
1566     nSvs = svc.size();
1567     const TVector3 recoPv = aux.pvInfo.firstPVInPT2;
1568     const math::XYZPoint myPv(recoPv);
1569    
1570     //FAKE ERROR MATRIX
1571     // //look here for Matrix filling info http://project-mathlibs.web.cern.ch/project-mathlibs/sw/html/SMatrixDoc.html
1572     // std::vector<double> fillMatrix(6);
1573     // for (int i = 0; i<6; ++i) fillMatrix[i] = 0.;
1574     // fillMatrix[0] = TMath::Power(0.002,2);
1575     // fillMatrix[2] = TMath::Power(0.002,2);
1576     // fillMatrix[5] = TMath::Power(0.002,2);
1577     // const ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > myFakeMatrixError(fillMatrix.begin(),fillMatrix.end());
1578     // const reco::Vertex recoVtxPv(myPv, myFakeMatrixError);
1579    
1580     // REAL ERROR MATRIX
1581     const reco::Vertex recoVtxPv(myPv, aux.pvInfo.efirstPVInPT2);
1582     for( int j=0; j < nSvs && j < MAXB; ++j ) {
1583     const GlobalVector flightDir = flightDirection(recoPv,svc[j]);
1584     reco::SecondaryVertex recoSv(recoVtxPv, svc[j], flightDir ,true);
1585     IVF.set( recoSv, recoPv ,j);
1586     }
1587     if(nSvs > 1){
1588     TLorentzVector BCands_H1, BCands_H2, BCands_H;
1589     BCands_H1.SetPtEtaPhiM(IVF.pt[0], IVF.eta[0], IVF.phi[0], IVF.massBcand[0]);
1590     BCands_H2.SetPtEtaPhiM(IVF.pt[1], IVF.eta[1], IVF.phi[1], IVF.massBcand[1]);
1591     BCands_H = BCands_H1 + BCands_H2;
1592     SVH.dR = deltaR(IVF.eta[0], IVF.phi[0], IVF.eta[1], IVF.phi[1] );
1593     SVH.dPhi = deltaPhi(IVF.phi[0], IVF.phi[1] );
1594     SVH.dEta = TMath::Abs(IVF.eta[0] - IVF.eta[1] );
1595     SVH.mass = BCands_H.M();
1596     SVH.pt = BCands_H.Pt();
1597     SVH.eta = BCands_H.Eta();
1598     SVH.phi = BCands_H.Phi();
1599     }
1600    
1601     //SimBhadron
1602     SimBs.reset();
1603     if(isMC_){
1604     nSimBs = sbhc->size();
1605     for( int j=0; j < nSimBs && j < MAXB; ++j )
1606     SimBs.set( sbhc->at(j), j);
1607     if(nSimBs > 1){
1608     TLorentzVector SimBs_H1, SimBs_H2, SimBs_H;
1609     SimBs_H1.SetPtEtaPhiM(SimBs.pt[0], SimBs.eta[0], SimBs.phi[0], SimBs.mass[0]);
1610     SimBs_H2.SetPtEtaPhiM(SimBs.pt[1], SimBs.eta[1], SimBs.phi[1], SimBs.mass[1]);
1611     SimBs_H = SimBs_H1 + SimBs_H2;
1612     SimBsH.dR = deltaR(SimBs.eta[0], SimBs.phi[0], SimBs.eta[1], SimBs.phi[1] );
1613     SimBsH.dPhi = deltaPhi(SimBs.phi[0], SimBs.phi[1] );
1614     SimBsH.dEta = TMath::Abs(SimBs.eta[0] - SimBs.eta[1] );
1615     SimBsH.mass = SimBs_H.M();
1616     SimBsH.pt = SimBs_H.Pt();
1617     SimBsH.eta = SimBs_H.Eta();
1618     SimBsH.phi = SimBs_H.Phi();
1619     }
1620     }
1621    
1622     //Loop on jets
1623     double maxBtag=-99999;
1624     minDeltaPhijetMET = 999;
1625     TLorentzVector bJet;
1626     std::vector<std::vector<BTagWeight::JetInfo> > btagJetInfos;
1627     std::vector<float> jet10eta;
1628     std::vector<float> jet10pt;
1629     std::vector<float> jet30eta;
1630     std::vector<float> jet30pt;
1631     if(fromCandidate)
1632     {
1633     //Loop on Higgs Jets
1634     for(unsigned int j=0; j < vhCand.H.jets.size(); j++ ){
1635     if (vhCand.H.jets[j].csv > maxBtag) { bJet=vhCand.H.jets[j].p4 ; maxBtag =vhCand.H.jets[j].csv; }
1636     if (fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.H.jets[j].p4.Phi())) < minDeltaPhijetMET)
1637     {
1638     minDeltaPhijetMET=fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.H.jets[j].p4.Phi()));
1639     jetPt_minDeltaPhijetMET=vhCand.H.jets[j].p4.Pt();
1640     }
1641     btagJetInfos.push_back(btagEff.jetInfo(vhCand.H.jets[j]));
1642     }
1643     //Loop on Additional Jets
1644     for(unsigned int j=0; j < vhCand.additionalJets.size(); j++ ){
1645     if (vhCand.additionalJets[j].csv > maxBtag) { bJet=vhCand.additionalJets[j].p4 ; maxBtag =vhCand.additionalJets[j].csv; }
1646     /* if (fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.additionalJets[j].p4.Phi())) < minDeltaPhijetMET)
1647     {
1648     minDeltaPhijetMET=fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.additionalJets[j].p4.Phi()));
1649     jetPt_minDeltaPhijetMET=vhCand.additionalJets[j].p4.Pt();
1650     }*/
1651     if( ( isW && ! useHighestPtHiggsW ) || ( ! isW && ! useHighestPtHiggsZ ) ) // btag SF computed using only H-jets if best-H made with dijetPt rather than best CSV
1652     {
1653     if(vhCand.additionalJets[j].p4.Pt() > 20)
1654     btagJetInfos.push_back(btagEff.jetInfo(vhCand.additionalJets[j]));
1655     }
1656     }
1657     }
1658     else
1659     {
1660     //Loop on all jets
1661     for(unsigned int j=0; j < iEvent->simpleJets2.size(); j++ ){
1662     if (iEvent->simpleJets2[j].csv > maxBtag) { bJet=iEvent->simpleJets2[j].p4 ; maxBtag =iEvent->simpleJets2[j].csv; }
1663     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)
1664     {
1665     minDeltaPhijetMET=fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), iEvent->simpleJets2[j].p4.Phi()));
1666     jetPt_minDeltaPhijetMET=iEvent->simpleJets2[j].p4.Pt();
1667     }
1668     if(iEvent->simpleJets2[j].p4.Pt() > 10)
1669     {
1670     jet10eta.push_back(iEvent->simpleJets2[j].p4.Eta());
1671     jet10pt.push_back(iEvent->simpleJets2[j].p4.Pt());
1672     }
1673     if(iEvent->simpleJets2[j].p4.Pt() > 30)
1674     {
1675     jet30eta.push_back(iEvent->simpleJets2[j].p4.Eta());
1676     jet30pt.push_back(iEvent->simpleJets2[j].p4.Pt());
1677     }
1678    
1679     //For events made with highest CSV, all jets in the event should be taken into account for "tagging" SF (anti tagging is a mess)
1680     // 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
1681     if( ( isW && ! useHighestPtHiggsW ) || ( ! isW && ! useHighestPtHiggsZ ) )
1682     {
1683     if(iEvent->simpleJets2[j].p4.Pt() > 20 && fabs(iEvent->simpleJets2[j].p4.Eta()) < 2.5)
1684     btagJetInfos.push_back(btagEff.jetInfo(iEvent->simpleJets2[j]));
1685     }
1686     }
1687    
1688     //Loop on Higgs jets
1689    
1690     if(vhCand.H.HiggsFlag){
1691     for(unsigned int j=0; j < vhCand.H.jets.size(); j++ ) {
1692    
1693     //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
1694     // by a criteria (pt of the dijet) that is not btag SF dependent
1695     if(!( ( isW && ! useHighestPtHiggsW ) || ( ! isW && ! useHighestPtHiggsZ ) )) {
1696     btagJetInfos.push_back(btagEff.jetInfo(vhCand.H.jets[j]));
1697     }
1698     }
1699     }// HiggsFlag
1700    
1701     }
1702     vLeptons.reset();
1703     weightTrig = 1.; // better to default to 1
1704     weightTrigMay = -1.;
1705     weightTrigV4 = -1.;
1706     weightTrigOrMu30 = 1.;
1707     TLorentzVector leptonForTop;
1708     size_t firstAddMu=0;
1709     size_t firstAddEle=0;
1710     if(Vtype == VHbbCandidate::Zmumu ){
1711     vLeptons.set(vhCand.V.muons[0],0,13);
1712     vLeptons.set(vhCand.V.muons[1],1,13);
1713     float cweightID = triggerWeight.scaleMuID(vLeptons.pt[0],vLeptons.eta[0]) * triggerWeight.scaleMuID(vLeptons.pt[1],vLeptons.eta[1]) ;
1714     float weightTrig1 = triggerWeight.scaleMuIsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
1715     float weightTrig2 = triggerWeight.scaleMuIsoHLT(vLeptons.pt[1],vLeptons.eta[1]);
1716     float cweightTrig = weightTrig1 + weightTrig2 - weightTrig1*weightTrig2;
1717     weightTrig = cweightID * cweightTrig;
1718     nvlep=2;
1719     firstAddMu=2;
1720     }
1721     if( Vtype == VHbbCandidate::Zee ){
1722     vLeptons.set(vhCand.V.electrons[0],0,11);
1723     vLeptons.set(vhCand.V.electrons[1],1,11);
1724     nvlep=2;
1725     firstAddEle=2;
1726     std::vector<float> pt,eta;
1727     pt.push_back(vLeptons.pt[0]); eta.push_back(vLeptons.eta[0]);
1728     pt.push_back(vLeptons.pt[1]); eta.push_back(vLeptons.eta[1]);
1729     weightEleRecoAndId=triggerWeight.scaleID95Ele(vLeptons.pt[0],vLeptons.eta[0]) * triggerWeight.scaleRecoEle(vLeptons.pt[0],vLeptons.eta[0]) *
1730     triggerWeight.scaleID95Ele(vLeptons.pt[1],vLeptons.eta[1]) * triggerWeight.scaleRecoEle(vLeptons.pt[1],vLeptons.eta[1]);
1731     weightEleTrigElePart = triggerWeight.scaleDoubleEle17Ele8(pt,eta);
1732     weightEleTrigEleAugPart = triggerWeight.scaleDoubleEle17Ele8Aug(pt,eta);
1733     weightTrig = (weightEleTrigElePart*1.14+weightEleTrigEleAugPart*0.98 )/2.12 * weightEleRecoAndId;
1734    
1735    
1736    
1737     }
1738     if(Vtype == VHbbCandidate::Wmun ){
1739     leptonForTop=vhCand.V.muons[0].p4;
1740     vLeptons.set(vhCand.V.muons[0],0,13);
1741     float cweightID = triggerWeight.scaleMuID(vLeptons.pt[0],vLeptons.eta[0]);
1742     float weightTrig1 = triggerWeight.scaleMuIsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
1743     float cweightTrig = weightTrig1;
1744     weightTrig = cweightID * cweightTrig;
1745     float weightTrig1OrMu30 = triggerWeight.scaleMuOr30IsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
1746     weightTrigOrMu30 = cweightID*weightTrig1OrMu30;
1747     nvlep=1;
1748     firstAddMu=1;
1749     }
1750     if( Vtype == VHbbCandidate::Wen ){
1751     leptonForTop=vhCand.V.electrons[0].p4;
1752     vLeptons.set(vhCand.V.electrons[0],0,11);
1753     nvlep=1;
1754     firstAddEle=1;
1755     weightTrigMay = triggerWeight.scaleSingleEleMay(vLeptons.pt[0],vLeptons.eta[0]);
1756     weightTrigV4 = triggerWeight.scaleSingleEleV4(vLeptons.pt[0],vLeptons.eta[0]);
1757     weightEleRecoAndId=triggerWeight.scaleID80Ele(vLeptons.pt[0],vLeptons.eta[0]) * triggerWeight.scaleRecoEle(vLeptons.pt[0],vLeptons.eta[0]);
1758     weightEleTrigJetMETPart=triggerWeight.scaleJet30Jet25(jet30pt,jet30eta)*triggerWeight.scalePFMHTEle(MET.et);
1759     weightEleTrigElePart= weightTrigV4; //this is for debugging only, checking only the V4 part
1760    
1761     weightTrigMay*=weightEleRecoAndId;
1762     weightTrigV4*=weightEleRecoAndId;
1763     weightTrigV4*=weightEleTrigJetMETPart;
1764     // weightTrig = weightTrigMay * 0.187 + weightTrigV4 * (1.-0.187); //FIXME: use proper lumi if we reload 2.fb
1765     weightTrig = (weightTrigMay * 0.215 + weightTrigV4 * 1.915)/ 2.13; //FIXME: use proper lumi if we reload 2.fb
1766     }
1767    
1768     if(isMC_)
1769     {
1770     weightTrigMET80 = triggerWeight.scaleMET80(MET.et);
1771     weightTrigMET100 = triggerWeight.scaleMET80(MET.et);
1772     weightTrig2CJet20 = triggerWeight.scale2CentralJet( jet10pt, jet10eta);
1773     weightTrigMET150 = triggerWeight.scaleMET150(MET.et);
1774     weightTrigMET802CJet= weightTrigMET80 * weightTrig2CJet20;
1775     weightTrigMET1002CJet= weightTrigMET100 * weightTrig2CJet20;
1776     }
1777     if( Vtype == VHbbCandidate::Znn ){
1778     nvlep=0;
1779     float weightTrig1 = triggerWeight.scaleMetHLT(vhCand.V.mets.at(0).p4.Pt());
1780     weightTrigMETLP = weightTrig1;
1781     weightTrig = weightTrigMET150 + weightTrigMET802CJet - weightTrigMET802CJet*weightTrigMET150;
1782     }
1783    
1784     if(weightTrigMay < 0) weightTrigMay=weightTrig;
1785     if(weightTrigV4 < 0) weightTrigV4=weightTrig;
1786     if(!isMC_)
1787     {
1788     weightTrig = 1.;
1789     weightTrigMay = 1.;
1790     weightTrigV4 = 1.;
1791     weightEleRecoAndId= 1.;
1792     weightEleTrigJetMETPart= 1.;
1793     weightEleTrigElePart= 1.;
1794     weightEleTrigEleAugPart=1.;
1795     weightTrigMET80= 1.;
1796     weightTrigMET100= 1.;
1797     weightTrig2CJet20= 1.;
1798     weightTrigMET150= 1.;
1799     weightTrigMET802CJet= 1.;
1800     weightTrigMET1002CJet= 1.;
1801     weightTrigMETLP = 1.;
1802    
1803     }
1804     aLeptons.reset();
1805     nalep=0;
1806     if(fromCandidate)
1807     {
1808     for(size_t j=firstAddMu;j< vhCand.V.muons.size();j++) aLeptons.set(vhCand.V.muons[j],nalep++,13);
1809     for(size_t j=firstAddEle;j< vhCand.V.electrons.size();j++) aLeptons.set(vhCand.V.electrons[j],nalep++,11);
1810     }
1811     else
1812     {
1813     for(size_t j=0;j< iEvent->muInfo.size();j++)
1814     {
1815     if((j!= vhCand.V.firstLepton && j!= vhCand.V.secondLepton) || ((Vtype != VHbbCandidate::Wmun ) && (Vtype != VHbbCandidate::Zmumu )) )
1816     aLeptons.set(iEvent->muInfo[j],nalep++,13);
1817     }
1818     for(size_t j=0;j< iEvent->eleInfo.size();j++)
1819     {
1820     if((j!= vhCand.V.firstLepton && j!= vhCand.V.secondLepton) || ((Vtype != VHbbCandidate::Wen ) && (Vtype != VHbbCandidate::Zee )))
1821     aLeptons.set(iEvent->eleInfo[j],nalep++,11);
1822     }
1823    
1824     }
1825    
1826    
1827     if(isMC_)
1828     {
1829     //std::cout << "BTAGSF " << btagJetInfos.size() << " " << btag.weight<BTag1Tight2CustomFilter>(btagJetInfos) << std::endl;
1830     if ( btagJetInfos.size()< 10)
1831     {
1832     btag1T2CSF = btag.weight<BTag1Tight2CustomFilter>(btagJetInfos);
1833     btag2TSF = btag.weight<BTag2TightFilter>(btagJetInfos);
1834     btag1TSF = btag.weight<BTag1TightFilter>(btagJetInfos);
1835     btagA0CSF = btag.weight<BTagAntiMax0CustomFilter>(btagJetInfos);
1836     btagA0TSF = btag.weight<BTagAntiMax0TightFilter>(btagJetInfos);
1837     btag2CSF = btag.weight<BTag2CustomFilter>(btagJetInfos);
1838     btag1TA1C = btag.weight<BTag1TightAndMax1CustomFilter>(btagJetInfos);
1839     }
1840     else
1841     {
1842     std::cout << "WARNING: combinatorics for " << btagJetInfos.size() << " jets is too high (>=10). use SF=1 " << std::endl;
1843     //TODO: revert to random throw for this cases
1844     btag1T2CSF = 1.;
1845     btag2TSF = 1.;
1846     btag1TSF = 1.;
1847     btagA0CSF = 1.;
1848     btagA0TSF = 1.;
1849     btag2CSF = 1.;
1850     btag1TA1C = 1.;
1851     }
1852     }
1853    
1854     if(maxBtag > -99999)
1855     {
1856     TopHypo topQuark = TopMassReco::topMass(leptonForTop,bJet,vhCand.V.mets.at(0).p4);
1857     top.mass = topQuark.p4.M();
1858     top.pt = topQuark.p4.Pt();
1859     top.wMass = topQuark.p4W.M();
1860     } else {
1861     top.mass = -99;
1862     top.pt = -99;
1863     top.wMass = -99;
1864     }
1865    
1866    
1867    
1868     //FIXME: too much warnings... figure out why
1869     // gendrcc=aux.genCCDeltaR();
1870     // gendrbb=aux.genBBDeltaR();
1871    
1872    
1873    
1874     genZpt=aux.mcZ.size() > 0 ? aux.mcZ[0].p4.Pt():-99;
1875     genWpt=aux.mcW.size() > 0 ? aux.mcW[0].p4.Pt():-99;
1876    
1877     // Z* is status=3 and Nmother=2 (q and qbar)
1878     // Z is status=2 and Ndau=2 (mup and mum)
1879     for (unsigned int i=0; i<aux.mcZ.size(); i++){
1880     if (aux.mcZ[i].status==3) {
1881     genZstar.mass = aux.mcZ[i].p4.M();
1882     genZstar.pt = aux.mcZ[i].p4.Pt();
1883     genZstar.eta = aux.mcZ[i].p4.Eta();
1884     genZstar.phi = aux.mcZ[i].p4.Phi();
1885     genZstar.status = aux.mcZ[i].status;
1886     genZstar.charge = aux.mcZ[i].charge;
1887     if (aux.mcZ[i].momid!=-99) genZstar.momid = aux.mcZ[i].momid ;
1888     }
1889    
1890    
1891    
1892     if (aux.mcZ[i].dauid.size()>1) {
1893     if ( abs(aux.mcZ[i].dauid[0])==13 || abs(aux.mcZ[i].dauid[0])==11 ) {
1894     genZ.mass = aux.mcZ[i].p4.M();
1895     genZ.pt = aux.mcZ[i].p4.Pt();
1896     genZ.eta = aux.mcZ[i].p4.Eta();
1897     genZ.phi = aux.mcZ[i].p4.Phi();
1898     genZ.status = aux.mcZ[i].status;
1899     genZ.charge = aux.mcZ[i].charge;
1900     if ( aux.mcZ[i].momid!=-99) genZ.momid = aux.mcZ[i].momid;
1901     }
1902     }
1903     }
1904    
1905    
1906    
1907     for (unsigned int i=0; i<aux.mcW.size(); i++){
1908     if ( aux.mcW[i].momid==6 && aux.mcW[i].dauid.size()>1 ){
1909     genTop.wdau1mass= aux.mcW[i].dauFourMomentum[0].M();
1910     genTop.wdau1pt= aux.mcW[i].dauFourMomentum[0].Pt();
1911     genTop.wdau1eta= aux.mcW[i].dauFourMomentum[0].Eta();
1912     genTop.wdau1phi= aux.mcW[i].dauFourMomentum[0].Phi();
1913     genTop.wdau1id= aux.mcW[i].dauid[0];
1914    
1915     genTop.wdau2mass= aux.mcW[i].dauFourMomentum[1].M();
1916     genTop.wdau2pt= aux.mcW[i].dauFourMomentum[1].Pt();
1917     genTop.wdau2eta= aux.mcW[i].dauFourMomentum[1].Eta();
1918     genTop.wdau2phi= aux.mcW[i].dauFourMomentum[1].Phi();
1919     genTop.wdau2id= aux.mcW[i].dauid[1];
1920    
1921     }
1922    
1923    
1924     if ( aux.mcW[i].momid==-6 && aux.mcW[i].dauid.size()>1 ){
1925     genTbar.wdau1mass= aux.mcW[i].dauFourMomentum[0].M();
1926     genTbar.wdau1pt= aux.mcW[i].dauFourMomentum[0].Pt();
1927     genTbar.wdau1eta= aux.mcW[i].dauFourMomentum[0].Eta();
1928     genTbar.wdau1phi= aux.mcW[i].dauFourMomentum[0].Phi();
1929     genTbar.wdau1id= aux.mcW[i].dauid[0];
1930    
1931     genTbar.wdau2mass= aux.mcW[i].dauFourMomentum[1].M();
1932     genTbar.wdau2pt= aux.mcW[i].dauFourMomentum[1].Pt();
1933     genTbar.wdau2eta= aux.mcW[i].dauFourMomentum[1].Eta();
1934     genTbar.wdau2phi= aux.mcW[i].dauFourMomentum[1].Phi();
1935     genTbar.wdau2id= aux.mcW[i].dauid[1];
1936    
1937     }
1938    
1939     if (aux.mcW[i].status==3 ) {
1940     genWstar.mass = aux.mcW[i].p4.M();
1941     genWstar.pt = aux.mcW[i].p4.Pt();
1942     genWstar.eta = aux.mcW[i].p4.Eta();
1943     genWstar.phi = aux.mcW[i].p4.Phi();
1944     genWstar.status = aux.mcW[i].status;
1945     genWstar.charge = aux.mcW[i].charge;
1946     if ( aux.mcW[i].momid!=-99) genWstar.momid = aux.mcW[i].momid;
1947     }
1948     if (aux.mcW[i].dauid.size()>1 && (abs(aux.mcW[i].dauid[0])==13 || abs(aux.mcW[i].dauid[0])==11 )) {
1949     genW.mass = aux.mcW[i].p4.M();
1950     genW.pt = aux.mcW[i].p4.Pt();
1951     genW.eta = aux.mcW[i].p4.Eta();
1952     genW.phi = aux.mcW[i].p4.Phi();
1953     genW.status = aux.mcW[i].status;
1954     genW.charge = aux.mcW[i].charge;
1955     if (aux.mcW[i].momid!=-99) genW.momid = aux.mcW[i].momid;
1956     }
1957     }
1958     // b coming from Higgs
1959     for (unsigned int i=0; i<aux.mcB.size(); i++){
1960     if (abs(aux.mcB[i].momid)!=5) {
1961     genB.mass = aux.mcB[i].p4.M();
1962     genB.pt = aux.mcB[i].p4.Pt();
1963     genB.eta = aux.mcB[i].p4.Eta();
1964     genB.phi = aux.mcB[i].p4.Phi();
1965     genB.status = aux.mcB[i].status;
1966     genB.charge = aux.mcB[i].charge;
1967     if (aux.mcB[i].momid!=-99) genB.momid = aux.mcB[i].momid;
1968     }
1969    
1970     if ( aux.mcB[i].momid==6 ){
1971     genTop.bmass = aux.mcB[i].p4.M();
1972     genTop.bpt = aux.mcB[i].p4.Pt();
1973     genTop.beta = aux.mcB[i].p4.Eta();
1974     genTop.bphi = aux.mcB[i].p4.Phi();
1975     genTop.bstatus = aux.mcB[i].status;
1976    
1977     }
1978     }
1979    
1980     for (unsigned int i=0; i<aux.mcBbar.size(); i++){
1981     if (abs(aux.mcBbar[i].momid)!=5 ) {
1982     genBbar.mass = aux.mcBbar[i].p4.M();
1983     genBbar.pt = aux.mcBbar[i].p4.Pt();
1984     genBbar.eta = aux.mcBbar[i].p4.Eta();
1985     genBbar.phi = aux.mcBbar[i].p4.Phi();
1986     genBbar.status = aux.mcBbar[i].status;
1987     if (aux.mcBbar[i].momid!=-99) genBbar.momid = aux.mcBbar[i].momid;
1988     }
1989     if ( aux.mcBbar[i].momid==-6 ){
1990     genTbar.bmass = aux.mcBbar[i].p4.M();
1991     genTbar.bpt = aux.mcBbar[i].p4.Pt();
1992     genTbar.beta = aux.mcBbar[i].p4.Eta();
1993     genTbar.bphi = aux.mcBbar[i].p4.Phi();
1994     genTbar.bstatus = aux.mcBbar[i].status;
1995    
1996    
1997     }
1998    
1999     }
2000    
2001    
2002    
2003    
2004     if (aux.mcH.size()>0) {
2005     genH.mass = aux.mcH[0].p4.M();
2006     genH.pt = aux.mcH[0].p4.Pt();
2007     genH.eta = aux.mcH[0].p4.Eta();
2008     genH.phi = aux.mcH[0].p4.Phi();
2009     genH.status = aux.mcH[0].status;
2010     genH.charge = aux.mcH[0].charge;
2011     if (aux.mcH[0].momid!=-99) genH.momid = aux.mcH[0].momid;
2012     }
2013    
2014    
2015    
2016    
2017     WminusMode=-99;
2018     WplusMode=-99;
2019     for(unsigned int j=0; j< aux.mcW.size();j++)
2020     {
2021     for(unsigned int k=0;k< aux.mcW[j].dauid.size();k++)
2022     {
2023     int idd=abs(aux.mcW[j].dauid[k]);
2024     if(idd==11 || idd==13 || idd==15|| (idd<=5 && idd >=1))
2025     {
2026     if(WminusMode==-99 && aux.mcW[j].charge ==-1) WminusMode = idd;
2027     if(WplusMode==-99 && aux.mcW[j].charge ==+1) WplusMode = idd;
2028     }
2029     }
2030     /*
2031     /// now check if a semileptonic W is also in a bjets....
2032     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;
2033     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;
2034    
2035     for( int j=0; j < naJets && j < MAXJ; j++ )
2036     {
2037     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;
2038    
2039     }
2040     */
2041    
2042     }
2043     /// Compute pull angle from AK7
2044     if(vhCand.H.HiggsFlag){
2045     if(!fromCandidate){
2046     std::vector<VHbbEvent::SimpleJet> ak7wrt1(iEvent->simpleJets3);
2047     std::vector<VHbbEvent::SimpleJet> ak7wrt2(iEvent->simpleJets3);
2048     if(ak7wrt1.size() > 1){
2049     CompareDeltaR deltaRComparatorJ1(vhCand.H.jets[0].p4);
2050     CompareDeltaR deltaRComparatorJ2(vhCand.H.jets[1].p4);
2051     std::sort( ak7wrt1.begin(),ak7wrt1.end(),deltaRComparatorJ1 );
2052     std::sort( ak7wrt2.begin(),ak7wrt2.end(),deltaRComparatorJ2 );
2053     std::vector<VHbbEvent::SimpleJet> ak7_matched;
2054     // if the matched are different save them
2055     if(ak7wrt1[0].p4.DeltaR(ak7wrt2[0].p4) > 0.1) {
2056     ak7_matched.push_back(ak7wrt1[0]);
2057     ak7_matched.push_back(ak7wrt2[0]);
2058     }
2059     // else look at the second best
2060     else{
2061     // ak7wrt1 is best
2062     if( ak7wrt1[1].p4.DeltaR(vhCand.H.jets[0].p4) < ak7wrt2[1].p4.DeltaR(vhCand.H.jets[1].p4))
2063     {
2064     ak7_matched.push_back(ak7wrt1[1]);
2065     ak7_matched.push_back(ak7wrt2[0]);
2066     }
2067     else
2068     {
2069     ak7_matched.push_back(ak7wrt1[0]);
2070     ak7_matched.push_back(ak7wrt2[1]);
2071     }
2072     }
2073     CompareJetPt ptComparator;
2074     std::sort( ak7_matched.begin(),ak7_matched.end(),ptComparator );
2075     if(ak7_matched[0].p4.DeltaR(vhCand.H.jets[0].p4) < 0.5
2076     and ak7_matched[1].p4.DeltaR(vhCand.H.jets[1].p4) < 0.5)
2077     {
2078     deltaPullAngleAK7 = VHbbCandidateTools::getDeltaTheta(ak7_matched[0],ak7_matched[1]);
2079     deltaPullAngle2AK7 = VHbbCandidateTools::getDeltaTheta(ak7_matched[1],ak7_matched[0]);
2080     }
2081     }
2082     }
2083     }//HiggsFlag
2084    
2085     _outTree->Fill();
2086    
2087     }// closed event loop
2088    
2089     std::cout << "closing the file: " << inputFiles_[iFile] << std::endl;
2090     inFile->Close();
2091     // close input file
2092     } // loop on files
2093    
2094    
2095     std::cout << "Events: " << ievt <<std::endl;
2096     std::cout << "TotalCount: " << totalcount <<std::endl;
2097    
2098    
2099    
2100     _outFile->cd();
2101    
2102     _outTree->Write();
2103     _outFile->Write();
2104     _outFile->Close();
2105     return 0;
2106     }
2107    
2108