ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.73
Committed: Thu May 3 00:51:19 2012 UTC (13 years ago) by dlopes
Content type: text/plain
Branch: MAIN
Changes since 1.72: +216 -108 lines
Log Message:
Ntupler used for April 25 Step2 production

File Contents

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