ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.94
Committed: Wed Jun 6 14:39:40 2012 UTC (12 years, 11 months ago) by arizzi
Content type: text/plain
Branch: MAIN
Changes since 1.93: +4 -2 lines
Log Message:
fixes for JEC in step2

File Contents

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