ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.80
Committed: Thu May 10 20:58:23 2012 UTC (13 years ago) by arizzi
Content type: text/plain
Branch: MAIN
Changes since 1.79: +8 -8 lines
Log Message:
fix step2 crash. TODO: implement mu and ele ID/iso in step2

File Contents

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