ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.98
Committed: Mon Jun 11 14:51:46 2012 UTC (12 years, 11 months ago) by arizzi
Content type: text/plain
Branch: MAIN
CVS Tags: EdmV33Jun12v2, EdmV33Jun12v1
Changes since 1.97: +52 -5 lines
Log Message:
Btag SF reshaping in eta/pt bins (2012 value). Still to be debugged!

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