ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.69
Committed: Fri Mar 16 09:12:46 2012 UTC (13 years, 2 months ago) by degrutto
Content type: text/plain
Branch: MAIN
CVS Tags: EdmV21Apr03, EdmV21Apr2, EdmV21Mar30, EdmV20Mar12
Changes since 1.68: +318 -8 lines
Log Message:
new filters/MET/MCtructh info, no tag in 44X (?), in 428 you need V02-05-01      DataFormats/CSCRecHit, V02-03-00      JetMETCorrections/Algorithms V05-00-17-01   JetMETCorrections/Modules V03-01-00      JetMETCorrections/Objects V04-05-08      JetMETCorrections/Type1MET b4_2_X_cvMEtCorr_13Feb2012_JEC11V12 PhysicsTools/PatUtils  V00-00-08      RecoMET/METAnalyzers HEAD           RecoMET/METFilters

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