ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.70
Committed: Tue Apr 3 10:10:18 2012 UTC (13 years, 1 month ago) by arizzi
Content type: text/plain
Branch: MAIN
CVS Tags: EdmV21Apr06, EdmV21Apr04
Changes since 1.69: +14 -3 lines
Log Message:
add new btaggers, fix bug on SV ntrack, add flavour for subjets

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