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