ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/VHbbDataFormats/bin/Ntupler.cc
Revision: 1.63
Committed: Tue Nov 1 17:53:28 2011 UTC (13 years, 6 months ago) by arizzi
Content type: text/plain
Branch: MAIN
Changes since 1.62: +10 -5 lines
Log Message:
add flag for the kinematic non conservation filter. initialize the Weights3D if no file name is given in the py config

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     #include <TH2F.h>
5     #include <TROOT.h>
6     #include <TFile.h>
7     #include <TTree.h>
8     #include <TSystem.h>
9     #include "DataFormats/FWLite/interface/Event.h"
10     #include "DataFormats/FWLite/interface/Handle.h"
11     #include "FWCore/FWLite/interface/AutoLibraryLoader.h"
12     #include "DataFormats/MuonReco/interface/Muon.h"
13     #include "DataFormats/PatCandidates/interface/Muon.h"
14     #include "PhysicsTools/FWLite/interface/TFileService.h"
15     #include "FWCore/ParameterSet/interface/ProcessDesc.h"
16     #include "FWCore/PythonParameterSet/interface/PythonProcessDesc.h"
17     #include "DataFormats/Math/interface/deltaR.h"
18     #include "DataFormats/Math/interface/deltaPhi.h"
19    
20     #include "DataFormats/FWLite/interface/LuminosityBlock.h"
21     #include "DataFormats/FWLite/interface/Run.h"
22     #include "DataFormats/Luminosity/interface/LumiSummary.h"
23    
24 arizzi 1.4 #include "VHbbAnalysis/VHbbDataFormats/interface/HbbCandidateFinderAlgo.h"
25     #include "VHbbAnalysis/VHbbDataFormats/src/HbbCandidateFinderAlgo.cc"
26 arizzi 1.1
27     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbEvent.h"
28     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbEventAuxInfo.h"
29     #include "VHbbAnalysis/VHbbDataFormats/interface/VHbbCandidate.h"
30     #include "VHbbAnalysis/VHbbDataFormats/interface/TriggerReader.h"
31 nmohr 1.5 #include "VHbbAnalysis/VHbbDataFormats/interface/TopMassReco.h"
32 arizzi 1.1
33 bortigno 1.30 //for IVF
34     #include "RecoBTag/SecondaryVertex/interface/SecondaryVertex.h"
35     #include "DataFormats/GeometryCommonDetAlgo/interface/Measurement1D.h"
36     #include "DataFormats/GeometryVector/interface/GlobalVector.h"
37     #include "DataFormats/GeometryVector/interface/VectorUtil.h"
38     #include <DataFormats/GeometrySurface/interface/Surface.h>
39     #include "Math/SMatrix.h"
40 arizzi 1.16
41     //Move class definition to Ntupler.h ?
42     //#include "VHbbAnalysis/VHbbDataFormats/interface/Ntupler.h"
43    
44 bortigno 1.30 //for SimBhad: FIXME
45     //#include "VHbbAnalysis/BAnalysis/interface/SimBHadron.h"
46     //btagging
47 arizzi 1.16 #include "VHbbAnalysis/VHbbDataFormats/interface/BTagWeight.h"
48 bortigno 1.30 //trigger
49 arizzi 1.16 #include "VHbbAnalysis/VHbbDataFormats/interface/TriggerWeight.h"
50    
51 arizzi 1.1 #include <sstream>
52     #include <string>
53    
54     #define MAXJ 30
55     #define MAXL 10
56 bortigno 1.30 #define MAXB 10
57 arizzi 1.1
58 arizzi 1.24 struct CompareDeltaR {
59 bortigno 1.30 CompareDeltaR(TLorentzVector p4dir_): p4dir(p4dir_) {}
60     bool operator()( const VHbbEvent::SimpleJet& j1, const VHbbEvent::SimpleJet& j2 ) const {
61     return j1.p4.DeltaR(p4dir) > j2.p4.DeltaR(p4dir);
62     }
63     TLorentzVector p4dir;
64 arizzi 1.24 };
65 arizzi 1.4
66 bortigno 1.30 const GlobalVector flightDirection(const TVector3 pv, const reco::Vertex &sv){
67     GlobalVector fdir(sv.position().X() - pv.X(),
68     sv.position().Y() - pv.Y(),
69     sv.position().Z() - pv.Z());
70     return fdir;
71     }
72    
73 nmohr 1.7 bool jsonContainsEvent (const std::vector< edm::LuminosityBlockRange > &jsonVec,
74     const edm::EventBase &event)
75     {
76 bortigno 1.30 // if the jsonVec is empty, then no JSON file was provided so all
77     // events should pass
78     if (jsonVec.empty())
79     {
80 nmohr 1.7 return true;
81 bortigno 1.30 }
82     bool (* funcPtr) (edm::LuminosityBlockRange const &,
83     edm::LuminosityBlockID const &) = &edm::contains;
84     edm::LuminosityBlockID lumiID (event.id().run(),
85     event.id().luminosityBlock());
86     std::vector< edm::LuminosityBlockRange >::const_iterator iter =
87     std::find_if (jsonVec.begin(), jsonVec.end(),
88     boost::bind(funcPtr, _1, lumiID) );
89     return jsonVec.end() != iter;
90 nmohr 1.7
91     }
92    
93 arizzi 1.1
94 bortigno 1.30 //FIXME : need to update EDM ntuple with SimBhadron infos
95     // typedef struct
96     // {
97     // void set(const SimBHadron & sbhc, int i){
98     // mass[i] = sbhc.mass();
99     // pt[i] = sbhc.pt();
100     // eta[i] = sbhc.eta();
101     // phi[i] = sbhc.phi();
102     // vtx_x[i] = sbhc.decPosition.x();
103     // vtx_y[i] = sbhc.decPosition.y();
104     // vtx_z[i] = sbhc.decPosition.z();
105     // pdgId[i] = sbhc.pdgId();
106     // status[i] = sbhc.status();
107     // };
108     // void reset(){
109     // for(int i=0; i < MAXB; ++i){
110     // 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;
111     // }
112     // };
113     // float mass[MAXB];
114     // float pt[MAXB];
115     // float eta[MAXB];
116     // float phi[MAXB];
117     // float vtx_x[MAXB];
118     // float vtx_y[MAXB];
119     // float vtx_z[MAXB];
120     // int pdgId[MAXB];
121     // int status[MAXB];
122     // // int quarkStatus[MAXB];
123     // // int brotherStatus[MAXB];
124     // // int otherId[MAXB];
125     // // bool etaOk[MAXB];
126     // // bool simOk[MAXB];
127     // // bool trackOk[MAXB];
128     // // bool cutOk[MAXB];
129     // // bool cutNewOk[MAXB];
130     // // bool mcMatchOk[MAXB];
131     // // bool matchOk[MAXB];
132     // } SimBHadronInfo;
133    
134    
135     typedef struct
136     {
137     void set( const reco::SecondaryVertex & recoSv, const TVector3 recoPv, int isv){
138     pt[isv] = recoSv.p4().Pt();
139     eta[isv] = flightDirection(recoPv,recoSv).eta();
140     phi[isv] = flightDirection(recoPv,recoSv).phi();
141     massBcand[isv] = recoSv.p4().M();
142     massSv[isv] = recoSv.p4().M();
143     dist3D[isv] = recoSv.dist3d().value();
144     distSig3D[isv] = recoSv.dist3d().significance();
145     dist2D[isv] = recoSv.dist2d().value();
146     distSig2D[isv] = recoSv.dist2d().significance();
147     dist3D_norm[isv] = recoSv.dist3d().value()/recoSv.p4().Gamma();
148     };
149     void reset(){
150     for(int i = 0; i < MAXB; ++i){
151     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;
152     }
153     };
154     float massBcand[MAXB];
155     float massSv[MAXB];
156     float pt[MAXB];
157     float eta[MAXB];
158     float phi[MAXB];
159     float dist3D[MAXB];
160     float distSig3D[MAXB];
161     float dist2D[MAXB];
162     float distSig2D[MAXB];
163     float dist3D_norm[MAXB];
164     } IVFInfo;
165 arizzi 1.1
166 bortigno 1.30
167     typedef struct
168     {
169 arizzi 1.33 float mass;
170     float pt;
171     float eta;
172     float phi;
173     float dR;
174     float dPhi;
175     float dEta;
176     } HiggsInfo;
177    
178     typedef struct
179     {
180 bortigno 1.30 float mass; //MT in case of W
181     float pt;
182     float eta;
183     float phi;
184     } TrackInfo;
185 arizzi 1.1
186    
187 arizzi 1.9 struct LeptonInfo
188 bortigno 1.30 {
189     void reset()
190 arizzi 1.1 {
191 arizzi 1.48 for(int i =0; i < MAXL;i++){
192 dlopes 1.55 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;
193 arizzi 1.48 id80[i]=-99; id95[i]=-99; vbtf[i]=-99;
194     }
195 bortigno 1.30 }
196 arizzi 1.1
197 bortigno 1.30 template <class Input> void set(const Input & i, int j,int t)
198     {
199     type[j]=t;
200     pt[j]=i.p4.Pt();
201     mass[j]=i.p4.M();
202     eta[j]=i.p4.Eta();
203     phi[j]=i.p4.Phi();
204     aodCombRelIso[j]=(i.hIso+i.eIso+i.tIso)/i.p4.Pt();
205     pfCombRelIso[j]=(i.pfChaIso+i.pfPhoIso+i.pfNeuIso)/i.p4.Pt();
206     photonIso[j]=i.pfPhoIso;
207     neutralHadIso[j]=i.pfNeuIso;
208     chargedHadIso[j]=i.pfChaIso;
209 dlopes 1.55 chargedPUIso[j]=i.pfChaPUIso;
210 bortigno 1.30 setSpecific(i,j);
211     }
212     template <class Input> void setSpecific(const Input & i, int j)
213     {
214     }
215 arizzi 1.4
216    
217    
218 arizzi 1.1
219 bortigno 1.30 float mass[MAXL]; //MT in case of W
220     float pt[MAXL];
221     float eta[MAXL];
222     float phi[MAXL];
223     float aodCombRelIso[MAXL];
224     float pfCombRelIso[MAXL];
225     float photonIso[MAXL];
226     float neutralHadIso[MAXL];
227     float chargedHadIso[MAXL];
228 dlopes 1.55 float chargedPUIso[MAXL];
229 bortigno 1.30 float particleIso[MAXL];
230     float dxy[MAXL];
231     float dz[MAXL];
232     int type[MAXL];
233     float id80[MAXL];
234     float id95[MAXL];
235 arizzi 1.48 float vbtf[MAXL];
236 bortigno 1.30 };
237 arizzi 1.1
238 bortigno 1.30 template <> void LeptonInfo::setSpecific<VHbbEvent::ElectronInfo>(const VHbbEvent::ElectronInfo & i, int j){
239 arizzi 1.36 id80[j]=i.id80;
240     id95[j]=i.id95;
241 bortigno 1.30 }
242     template <> void LeptonInfo::setSpecific<VHbbEvent::MuonInfo>(const VHbbEvent::MuonInfo & i, int j){
243     dxy[j]=i.ipDb;
244     dz[j]=i.zPVPt;
245 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 &&
246     (i.pfChaIso+i.pfPhoIso+i.pfNeuIso)/i.p4.Pt()<.15 && fabs(i.p4.Eta())<2.4 && i.p4.Pt()>20 ) ;
247    
248 bortigno 1.30 }
249    
250 arizzi 1.4
251 bortigno 1.30 typedef struct
252     {
253     float et;
254     float sumet;
255     float sig;
256     float phi;
257     } METInfo;
258 arizzi 1.1
259 bortigno 1.30 typedef struct
260     {
261     float mht;
262     float ht;
263     float sig;
264     float phi;
265     } MHTInfo;
266 nmohr 1.5
267 bortigno 1.30 typedef struct
268     {
269     float mass;
270     float pt;
271     float wMass;
272     } TopInfo;
273 arizzi 1.1
274 bortigno 1.30 typedef struct
275     {
276     int run;
277     int lumi;
278     int event;
279     int json;
280     } EventInfo;
281 arizzi 1.1
282 bortigno 1.30 typedef struct
283     {
284     void set(const VHbbEvent::SimpleJet & j, int i)
285 arizzi 1.1 {
286 bortigno 1.30 pt[i]=j.p4.Pt();
287     eta[i]=j.p4.Eta();
288     phi[i]=j.p4.Phi();
289 arizzi 1.51 e[i]=j.p4.E();
290 bortigno 1.30 csv[i]=j.csv;
291     numTracksSV[i] = j.vtxMass;
292     vtxMass[i]= j.vtxMass;
293     vtx3dL[i] = j.vtx3dL;
294     vtx3deL[i] = j.vtx3deL;
295     chf[i]=j.chargedHadronEFraction;
296     nhf[i] =j.neutralHadronEFraction;
297     cef[i] =j.chargedEmEFraction;
298     nef[i] =j.neutralEmEFraction;
299     nconstituents[i] =j.nConstituents;
300     nch[i]=j.ntracks;
301    
302     flavour[i]=j.flavour;
303     if(j.bestMCp4.Pt() > 0)
304     {
305     genPt[i]=j.bestMCp4.Pt();
306     genEta[i]=j.bestMCp4.Eta();
307     genPhi[i]=j.bestMCp4.Phi();
308     }
309     JECUnc[i]=j.jecunc;
310 arizzi 1.36 id[i]=jetId(i);
311     }
312     bool jetId(int i)
313     {
314     if(nhf[i] > 0.99) return false;
315     if(nef[i] > 0.99) return false;
316 arizzi 1.37 if(nconstituents[i] <= 1) return false;
317 arizzi 1.47 if(fabs(eta[i])<2.5) {
318 arizzi 1.36 if(cef[i] > 0.99) return false;
319 arizzi 1.37 if(chf[i] == 0) return false;
320 arizzi 1.36 if(nch[i]== 0) return false;
321 arizzi 1.37 }
322 arizzi 1.36 return true;
323 bortigno 1.30 }
324     void reset()
325     {
326     for(int i=0;i<MAXJ;i++) {
327 arizzi 1.51 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; genPt[i]=-99; genEta[i]=-99; genPhi[i]=-99; JECUnc[i]=-99;
328 arizzi 1.1 }
329 bortigno 1.30 }
330     float pt[MAXJ];
331     float eta[MAXJ];
332     float phi[MAXJ];
333 arizzi 1.51 float e[MAXJ];
334 bortigno 1.30 float csv[MAXJ];
335     float cosTheta[MAXJ];
336     int numTracksSV[MAXJ];
337     float chf[MAXJ];
338     float nhf[MAXJ];
339     float cef[MAXJ];
340     float nef[MAXJ];
341     float nch[MAXJ];
342     float nconstituents[MAXJ];
343     float flavour[MAXJ];
344     float genPt[MAXJ];
345     float genEta[MAXJ];
346     float genPhi[MAXJ];
347     float JECUnc[MAXJ];
348     float vtxMass[MAXJ];
349     float vtx3dL [MAXJ];
350     float vtx3deL[MAXJ];
351 arizzi 1.36 bool id[MAXJ];
352 bortigno 1.30 } JetInfo;
353 arizzi 1.1
354     int main(int argc, char* argv[])
355     {
356     gROOT->Reset();
357    
358     TTree *_outTree;
359 bortigno 1.30 IVFInfo IVF;
360     //FIXME
361     // SimBHadronInfo SimBs;
362 arizzi 1.39 float rho,rho25;
363     int nPVs;
364 arizzi 1.9 METInfo MET;
365 arizzi 1.52 METInfo fakeMET;
366 arizzi 1.36 METInfo METnoPU;
367 arizzi 1.58 METInfo METnoPUCh;
368 arizzi 1.9 MHTInfo MHT;
369     TopInfo top;
370     EventInfo EVENT;
371 bortigno 1.30 // JetInfo jet1,jet2, addJet1, addJet2;
372 arizzi 1.9 // lepton1,lepton2;
373     JetInfo hJets, aJets;
374     LeptonInfo vLeptons, aLeptons;
375 arizzi 1.1 int naJets=0, nhJets=0;
376 arizzi 1.33 HiggsInfo H,SVH; //add here the fatjet higgs
377 arizzi 1.9 TrackInfo V;
378     int nvlep=0,nalep=0;
379 arizzi 1.1
380 degrutto 1.54
381    
382 arizzi 1.62 float HVdPhi,HVMass,HMETdPhi,VMt,deltaPullAngle,deltaPullAngleAK7,deltaPullAngle2,deltaPullAngle2AK7,gendrcc,gendrbb, genZpt, genWpt, weightTrig, weightTrigMay,weightTrigV4, weightTrigMET, weightTrigOrMu30, minDeltaPhijetMET, jetPt_minDeltaPhijetMET , PUweight, PUweight2011B;
383     float PU0,PUp1,PUm1;
384 degrutto 1.54
385 arizzi 1.60 float weightEleRecoAndId,weightEleTrigJetMETPart, weightEleTrigElePart,weightEleTrigEleAugPart;
386 arizzi 1.24
387 bortigno 1.30 //FIXME
388     // float SimBs_dr = -99, SimBs_dEta= -99, SimBs_dPhi = -99, SimBs_Hmass = -99, SimBs_Hpt = -99, SimBs_Heta = -99, SimBs_Hphi = -99;
389 arizzi 1.49 int WplusMode,WminusMode;
390 bortigno 1.30 int Vtype,nSvs,nSimBs,numJets,numBJets,eventFlav;
391     // bool isMET80_CJ80, ispfMHT150, isMET80_2CJ20,isMET65_2CJ20, isJETID,isIsoMu17;
392 arizzi 1.63 bool triggerFlags[500],hbhe,ecalFlag,totalKinematics;
393 arizzi 1.60 float btag1T2CSF=1.,btag2TSF=1.,btag1TSF=1.,btagA0CSF=1., btagA0TSF=1., btag2CSF=1., btag1TA1C=1.;
394 arizzi 1.1 // ----------------------------------------------------------------------
395     // First Part:
396     //
397     // * enable the AutoLibraryLoader
398     // * book the histograms of interest
399     // * open the input file
400     // ----------------------------------------------------------------------
401    
402     // load framework libraries
403 bortigno 1.30 gSystem->Load("libFWCoreFWLite");
404 arizzi 1.1 gSystem->Load("libDataFormatsFWLite");
405     AutoLibraryLoader::enable();
406    
407     // parse arguments
408     if ( argc < 2 ) {
409     return 0;
410     }
411    
412 arizzi 1.4 std::vector<VHbbCandidate> * candZlocal = new std::vector<VHbbCandidate>;
413     std::vector<VHbbCandidate> * candWlocal = new std::vector<VHbbCandidate>;
414    
415 arizzi 1.1 // get the python configuration
416     PythonProcessDesc builder(argv[1]);
417     const edm::ParameterSet& in = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("fwliteInput" );
418     const edm::ParameterSet& out = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("fwliteOutput");
419     const edm::ParameterSet& ana = builder.processDesc()->getProcessPSet()->getParameter<edm::ParameterSet>("Analyzer");
420 bortigno 1.30
421 nmohr 1.7 std::vector<edm::LuminosityBlockRange> jsonVector;
422     if ( in.exists("lumisToProcess") )
423 bortigno 1.30 {
424     std::vector<edm::LuminosityBlockRange> const & lumisTemp =
425     in.getUntrackedParameter<std::vector<edm::LuminosityBlockRange> > ("lumisToProcess");
426 nmohr 1.7 jsonVector.resize( lumisTemp.size() );
427     copy( lumisTemp.begin(), lumisTemp.end(), jsonVector.begin() );
428 bortigno 1.30 }
429 arizzi 1.1
430     // now get each parameter
431     int maxEvents_( in.getParameter<int>("maxEvents") );
432 nmohr 1.29 int skipEvents_( in.getParameter<int>("skipEvents") );
433 arizzi 1.1 unsigned int outputEvery_( in.getParameter<unsigned int>("outputEvery") );
434     std::string outputFile_( out.getParameter<std::string>("fileName" ) );
435     std::vector<std::string> triggers( ana.getParameter<std::vector<std::string> >("triggers") );
436 arizzi 1.6 double btagThr = ana.getParameter<double>("bJetCountThreshold" );
437 arizzi 1.4 bool fromCandidate = ana.getParameter<bool>("readFromCandidates");
438 arizzi 1.17 bool useHighestPtHiggsZ = ana.getParameter<bool>("useHighestPtHiggsZ");
439     bool useHighestPtHiggsW = ana.getParameter<bool>("useHighestPtHiggsW");
440 nmohr 1.31 HbbCandidateFinderAlgo * algoZ = new HbbCandidateFinderAlgo(ana.getParameter<bool>("verbose"), ana.getParameter<double>("jetPtThresholdZ"),useHighestPtHiggsZ);
441     HbbCandidateFinderAlgo * algoW = new HbbCandidateFinderAlgo(ana.getParameter<bool>("verbose"), ana.getParameter<double>("jetPtThresholdW"),useHighestPtHiggsW );
442 arizzi 1.4
443 arizzi 1.16 TriggerWeight triggerWeight(ana);
444 arizzi 1.17 BTagWeight btag(2); // 2 operating points "Custom" = 0.5 and "Tight = 0.898"
445     BTagSampleEfficiency btagEff( ana.getParameter<std::string>("btagEffFileName" ).c_str() );
446 arizzi 1.1
447     std::vector<std::string> inputFiles_( in.getParameter<std::vector<std::string> >("fileNames") );
448 bortigno 1.30 // std::string inputFile( in.getParameter<std::string> ("fileName") );
449 arizzi 1.1
450 arizzi 1.3 std::string PUmcfileName_ = in.getParameter<std::string> ("PUmcfileName") ;
451 degrutto 1.57 std::string PUmcfileName2011B_ = in.getParameter<std::string> ("PUmcfileName2011B") ;
452    
453 arizzi 1.3 std::string PUdatafileName_ = in.getParameter<std::string> ("PUdatafileName") ;
454 degrutto 1.54 std::string PUdatafileName2011B_ = in.getParameter<std::string> ("PUdatafileName2011B") ;
455 arizzi 1.63 std::string Weight3DfileName_ = in.getParameter<std::string> ("Weight3DfileName") ;
456 degrutto 1.54
457    
458    
459 arizzi 1.1 bool isMC_( ana.getParameter<bool>("isMC") );
460     TriggerReader trigger(isMC_);
461 arizzi 1.18 TriggerReader patFilters(false);
462 arizzi 1.25
463     edm::LumiReWeighting lumiWeights;
464 degrutto 1.54 edm::LumiReWeighting lumiWeights2011B;
465 arizzi 1.25 if(isMC_)
466 bortigno 1.30 {
467 arizzi 1.34 lumiWeights = edm::LumiReWeighting(PUmcfileName_,PUdatafileName_ , "pileup", "pileup");
468 degrutto 1.54
469 degrutto 1.57 lumiWeights2011B = edm::LumiReWeighting(PUmcfileName2011B_,PUdatafileName2011B_ , "pileup", "pileup");
470 arizzi 1.63 if(Weight3DfileName_!="")
471     { lumiWeights2011B.weight3D_init(Weight3DfileName_.c_str()); }
472     else
473     {
474     lumiWeights2011B.weight3D_init(); // generate the weights the fisrt time;
475     }
476 degrutto 1.54
477 bortigno 1.30 }
478 arizzi 1.1
479 bortigno 1.30 // TFile *_outPUFile = new TFile((outputFile_+"_PU").c_str(), "recreate");
480     TFile *_outFile = new TFile(outputFile_.c_str(), "recreate");
481     TH1F * count = new TH1F("Count","Count", 1,0,2 );
482     TH1F * countWithPU = new TH1F("CountWithPU","CountWithPU", 1,0,2 );
483 arizzi 1.58 TH1F * countWithPU2011B = new TH1F("CountWithPU2011B","CountWithPU2011B", 1,0,2 );
484 arizzi 1.62 TH3F * input3DPU = new TH3F("Input3DPU","Input3DPU", 36,-0.5,35.5,36,-0.5,35.5, 36,-0.5,35.5 );
485 arizzi 1.58
486 arizzi 1.41 TH1F * pu = new TH1F("pileup","",51,-0.5,50.5);
487 arizzi 1.1 _outTree = new TTree("tree", "myTree");
488    
489 arizzi 1.33 _outTree->Branch("H" , &H , "mass/F:pt/F:eta:phi/F:dR/F:dPhi/F:dEta/F");
490 arizzi 1.1 _outTree->Branch("V" , &V , "mass/F:pt/F:eta:phi/F");
491     _outTree->Branch("nhJets" , &nhJets , "nhJets/I");
492     _outTree->Branch("naJets" , &naJets , "naJets/I");
493 arizzi 1.2
494     _outTree->Branch("hJet_pt",hJets.pt ,"pt[nhJets]/F");
495     _outTree->Branch("hJet_eta",hJets.eta ,"eta[nhJets]/F");
496     _outTree->Branch("hJet_phi",hJets.phi ,"phi[nhJets]/F");
497 arizzi 1.51 _outTree->Branch("hJet_e",hJets.e ,"e[nhJets]/F");
498 arizzi 1.2 _outTree->Branch("hJet_csv",hJets.csv ,"csv[nhJets]/F");
499     _outTree->Branch("hJet_cosTheta",hJets.cosTheta ,"cosTheta[nhJets]/F");
500     _outTree->Branch("hJet_numTracksSV",hJets.numTracksSV ,"numTracksSV[nhJets]/I");
501     _outTree->Branch("hJet_chf",hJets.chf ,"chf[nhJets]/F");
502     _outTree->Branch("hJet_nhf",hJets.nhf ,"nhf[nhJets]/F");
503     _outTree->Branch("hJet_cef",hJets.cef ,"cef[nhJets]/F");
504     _outTree->Branch("hJet_nef",hJets.nef ,"nef[nhJets]/F");
505     _outTree->Branch("hJet_nch",hJets.nch ,"nch[nhJets]/F");
506     _outTree->Branch("hJet_nconstituents",hJets.nconstituents ,"nconstituents[nhJets]");
507     _outTree->Branch("hJet_flavour",hJets.flavour ,"flavour[nhJets]/F");
508     _outTree->Branch("hJet_genPt",hJets.genPt ,"genPt[nhJets]/F");
509     _outTree->Branch("hJet_genEta",hJets.genEta ,"genEta[nhJets]/F");
510     _outTree->Branch("hJet_genPhi",hJets.genPhi ,"genPhi[nhJets]/F");
511     _outTree->Branch("hJet_JECUnc",hJets.JECUnc ,"JECUnc[nhJets]/F");
512 arizzi 1.36 _outTree->Branch("hJet_vtxMass",hJets.vtxMass ,"vtxMass[nhJets]/F");
513     _outTree->Branch("hJet_vtx3dL",hJets.vtx3dL ,"vtx3dL[nhJets]/F");
514     _outTree->Branch("hJet_vtx3deL",hJets.vtx3deL ,"vtx3deL[nhJets]/F");
515     _outTree->Branch("hJet_id",hJets.id ,"id[nhJets]/b");
516 arizzi 1.2
517     _outTree->Branch("aJet_pt",aJets.pt ,"pt[naJets]/F");
518     _outTree->Branch("aJet_eta",aJets.eta ,"eta[naJets]/F");
519     _outTree->Branch("aJet_phi",aJets.phi ,"phi[naJets]/F");
520 arizzi 1.51 _outTree->Branch("aJet_e",aJets.e ,"e[naJets]/F");
521 arizzi 1.2 _outTree->Branch("aJet_csv",aJets.csv ,"csv[naJets]/F");
522     _outTree->Branch("aJet_cosTheta",aJets.cosTheta ,"cosTheta[naJets]/F");
523     _outTree->Branch("aJet_numTracksSV",aJets.numTracksSV ,"numTracksSV[naJets]/I");
524     _outTree->Branch("aJet_chf",aJets.chf ,"chf[naJets]/F");
525     _outTree->Branch("aJet_nhf",aJets.nhf ,"nhf[naJets]/F");
526     _outTree->Branch("aJet_cef",aJets.cef ,"cef[naJets]/F");
527     _outTree->Branch("aJet_nef",aJets.nef ,"nef[naJets]/F");
528     _outTree->Branch("aJet_nch",aJets.nch ,"nch[naJets]/F");
529     _outTree->Branch("aJet_nconstituents",aJets.nconstituents ,"nconstituents[naJets]");
530     _outTree->Branch("aJet_flavour",aJets.flavour ,"flavour[naJets]/F");
531     _outTree->Branch("aJet_genPt",aJets.genPt ,"genPt[naJets]/F");
532     _outTree->Branch("aJet_genEta",aJets.genEta ,"genEta[naJets]/F");
533     _outTree->Branch("aJet_genPhi",aJets.genPhi ,"genPhi[naJets]/F");
534     _outTree->Branch("aJet_JECUnc",aJets.JECUnc ,"JECUnc[naJets]/F");
535 arizzi 1.24 _outTree->Branch("aJet_vtxMass",aJets.vtxMass ,"vtxMass[naJets]/F");
536     _outTree->Branch("aJet_vtx3dL",aJets.vtx3dL ,"vtx3dL[naJets]/F");
537     _outTree->Branch("aJet_vtx3deL",aJets.vtx3deL ,"vtx3deL[naJets]/F");
538 arizzi 1.36 _outTree->Branch("aJet_id",aJets.id ,"id[naJets]/b");
539 arizzi 1.1
540     _outTree->Branch("numJets" , &numJets , "numJets/I" );
541     _outTree->Branch("numBJets" , &numBJets , "numBJets/I" );
542     _outTree->Branch("deltaPullAngle", &deltaPullAngle , "deltaPullAngle/F");
543 arizzi 1.52 _outTree->Branch("deltaPullAngle2", &deltaPullAngle2 , "deltaPullAngle2/F");
544 arizzi 1.1 _outTree->Branch("gendrcc" , &gendrcc , "gendrcc/F");
545     _outTree->Branch("gendrbb" , &gendrbb , "gendrbb/F");
546     _outTree->Branch("genZpt" , &genZpt , "genZpt/F");
547     _outTree->Branch("genWpt" , &genWpt , "genWpt/F");
548     _outTree->Branch("weightTrig" , &weightTrig , "weightTrig/F");
549 arizzi 1.38 _outTree->Branch("weightTrigMay" , &weightTrigMay , "weightTrigMay/F");
550     _outTree->Branch("weightTrigV4" , &weightTrigV4 , "weightTrigV4/F");
551 arizzi 1.22 _outTree->Branch("weightTrigMET" , &weightTrigMET , "weightTrigMET/F");
552 arizzi 1.51 _outTree->Branch("weightTrigOrMu30" , &weightTrigOrMu30 , "weightTrigOrMu30/F");
553 arizzi 1.24 _outTree->Branch("weightEleRecoAndId" , &weightEleRecoAndId , "weightEleRecoAndId/F");
554     _outTree->Branch("weightEleTrigJetMETPart" , &weightEleTrigJetMETPart , "weightEleTrigJetMETPart/F");
555     _outTree->Branch("weightEleTrigElePart" , &weightEleTrigElePart , "weightEleTrigElePart/F");
556 arizzi 1.60 _outTree->Branch("weightEleTrigEleAugPart" , &weightEleTrigEleAugPart , "weightEleTrigEleAugPart/F");
557 arizzi 1.24
558    
559 arizzi 1.1 _outTree->Branch("deltaPullAngleAK7", &deltaPullAngleAK7 , "deltaPullAngleAK7/F");
560 arizzi 1.52 _outTree->Branch("deltaPullAngle2AK7", &deltaPullAngle2AK7 , "deltaPullAngle2AK7/F");
561 arizzi 1.62 _outTree->Branch("PU0", &PU0 , "PU0/F");
562     _outTree->Branch("PUm1", &PUm1 , "PUm1/F");
563     _outTree->Branch("PUp1", &PUp1 , "PUp1/F");
564 arizzi 1.1 _outTree->Branch("PUweight", &PUweight , "PUweight/F");
565 degrutto 1.54 _outTree->Branch("PUweight2011B", &PUweight2011B , "PUweight2011B/F");
566 arizzi 1.3 _outTree->Branch("eventFlav", &eventFlav , "eventFlav/I");
567 arizzi 1.1
568    
569    
570    
571     _outTree->Branch("Vtype" , &Vtype , "Vtype/I" );
572     _outTree->Branch("HVdPhi" , &HVdPhi , "HVdPhi/F" );
573 arizzi 1.41 _outTree->Branch("HVMass" , &HVMass , "HVMass/F" );
574 arizzi 1.19 _outTree->Branch("HMETdPhi" , &HMETdPhi , "HMETdPhi/F" );
575 arizzi 1.1 _outTree->Branch("VMt" , &VMt , "VMt/F" );
576    
577 arizzi 1.9 _outTree->Branch("nvlep" , &nvlep , "nvlep/I");
578     _outTree->Branch("nalep" , &nalep , "nalep/I");
579 arizzi 1.3
580 arizzi 1.9 _outTree->Branch("vLepton_mass",vLeptons.mass ,"mass[nvlep]/F");
581     _outTree->Branch("vLepton_pt",vLeptons.pt ,"pt[nvlep]/F");
582     _outTree->Branch("vLepton_eta",vLeptons.eta ,"eta[nvlep]");
583     _outTree->Branch("vLepton_phi",vLeptons.phi ,"phi[nvlep]/F");
584     _outTree->Branch("vLepton_aodCombRelIso",vLeptons.aodCombRelIso ,"aodCombRelIso[nvlep]/F");
585     _outTree->Branch("vLepton_pfCombRelIso",vLeptons.pfCombRelIso ,"pfCombRelIso[nvlep]/F");
586     _outTree->Branch("vLepton_photonIso",vLeptons.photonIso ,"photonIso[nvlep]/F");
587     _outTree->Branch("vLepton_neutralHadIso",vLeptons.neutralHadIso ,"neutralHadIso[nvlep]/F");
588     _outTree->Branch("vLepton_chargedHadIso",vLeptons.chargedHadIso ,"chargedHadIso[nvlep]/F");
589 dlopes 1.55 _outTree->Branch("vLepton_chargedPUIso",vLeptons.chargedPUIso ,"chargedPUIso[nvlep]/F");
590 arizzi 1.9 _outTree->Branch("vLepton_particleIso",vLeptons.particleIso ,"particleIso[nvlep]/F");
591     _outTree->Branch("vLepton_dxy",vLeptons.dxy ,"dxy[nvlep]/F");
592     _outTree->Branch("vLepton_dz",vLeptons.dz ,"dz[nvlep]/F");
593     _outTree->Branch("vLepton_type",vLeptons.type ,"type[nvlep]/I");
594 arizzi 1.27 _outTree->Branch("vLepton_id80",vLeptons.id80 ,"id80[nvlep]/F");
595     _outTree->Branch("vLepton_id95",vLeptons.id95 ,"id95[nvlep]/F");
596 arizzi 1.48 _outTree->Branch("vLepton_vbtf",vLeptons.vbtf ,"vbtf[nvlep]/F");
597 arizzi 1.9
598     _outTree->Branch("aLepton_mass",aLeptons.mass ,"mass[nalep]/F");
599     _outTree->Branch("aLepton_pt",aLeptons.pt ,"pt[nalep]/F");
600     _outTree->Branch("aLepton_eta",aLeptons.eta ,"eta[nalep]");
601     _outTree->Branch("aLepton_phi",aLeptons.phi ,"phi[nalep]/F");
602     _outTree->Branch("aLepton_aodCombRelIso",aLeptons.aodCombRelIso ,"aodCombRelIso[nalep]/F");
603     _outTree->Branch("aLepton_pfCombRelIso",aLeptons.pfCombRelIso ,"pfCombRelIso[nalep]/F");
604     _outTree->Branch("aLepton_photonIso",aLeptons.photonIso ,"photonIso[nalep]/F");
605     _outTree->Branch("aLepton_neutralHadIso",aLeptons.neutralHadIso ,"neutralHadIso[nalep]/F");
606     _outTree->Branch("aLepton_chargedHadIso",aLeptons.chargedHadIso ,"chargedHadIso[nalep]/F");
607 dlopes 1.55 _outTree->Branch("aLepton_chargedPUIso",aLeptons.chargedPUIso ,"chargedPUIso[nalep]/F");
608 arizzi 1.9 _outTree->Branch("aLepton_particleIso",aLeptons.particleIso ,"particleIso[nalep]/F");
609     _outTree->Branch("aLepton_dxy",aLeptons.dxy ,"dxy[nalep]/F");
610     _outTree->Branch("aLepton_dz",aLeptons.dz ,"dz[nalep]/F");
611     _outTree->Branch("aLepton_type",aLeptons.type ,"type[nalep]/I");
612 arizzi 1.48 _outTree->Branch("aLepton_id80",aLeptons.id80 ,"id80[nalep]/F");
613     _outTree->Branch("aLepton_id95",aLeptons.id95 ,"id95[nalep]/F");
614     _outTree->Branch("aLepton_vbtf",aLeptons.vbtf ,"vbtf[nalep]/F");
615 arizzi 1.9
616 arizzi 1.8 _outTree->Branch("top" , &top , "mass/F:pt/F:wMass/F");
617 arizzi 1.49 _outTree->Branch("WplusMode" , &WplusMode , "WplusMode/I");
618     _outTree->Branch("WminusMode" , &WminusMode , "WminusMode/I");
619 arizzi 1.1
620 bortigno 1.30 //IVF
621     _outTree->Branch("nSvs",&nSvs ,"nSvs/I");
622 arizzi 1.33 _outTree->Branch("Sv_massBCand", &IVF.massBcand,"massBcand[nSvs]/F");
623     _outTree->Branch("Sv_massSv", &IVF.massSv,"massSv[nSvs]/F");
624     _outTree->Branch("Sv_pt", &IVF.pt,"pt[nSvs]/F");
625     _outTree->Branch("Sv_eta", &IVF.eta,"eta[nSvs]/F");
626     _outTree->Branch("Sv_phi", &IVF.phi,"phi[nSvs]/F");
627     _outTree->Branch("Sv_dist3D", &IVF.dist3D,"dist3D[nSvs]/F");
628     _outTree->Branch("Sv_dist2D", &IVF.dist2D,"dist2D[nSvs]/F");
629     _outTree->Branch("Sv_distSim2D", &IVF.distSig2D,"distSig2D[nSvs]/F");
630     _outTree->Branch("Sv_distSig3D", &IVF.distSig3D,"distSig3D[nSvs]/F");
631     _outTree->Branch("Sv_dist3D_norm", &IVF.dist3D_norm,"dist3D_norm[nSvs]/F");
632 bortigno 1.30 //IVF higgs candidate
633 arizzi 1.33 _outTree->Branch("SVH" , &SVH , "mass/F:pt/F:eta:phi/F:dR/F:dPhi/F:dEta/F");
634 bortigno 1.30
635    
636     //FIXME : need to update the EDMNtuple with BHadron infos
637     // //SimBHadron
638     // _outTree->Branch("nSimBs",&nSimBs ,"nSimBs/I");
639     // _outTree->Branch("SimBs_mass", &SimBs.mass,"mass[nSvs]/F");
640     // _outTree->Branch("SimBs_pt", &SimBs.pt,"pt[nSvs]/F");
641     // _outTree->Branch("SimBs_eta", &SimBs.eta,"eta[nSvs]/F");
642     // _outTree->Branch("SimBs_phi", &SimBs.phi,"phi[nSvs]/F");
643     // _outTree->Branch("SimBs_vtx_x", &SimBs.vtx_x,"vtx_x[nSvs]/F");
644     // _outTree->Branch("SimBs_vtx_y", &SimBs.vtx_y,"vtx_y[nSvs]/F");
645     // _outTree->Branch("SimBs_vtx_z", &SimBs.vtx_z,"vtx_z[nSvs]/F");
646     // _outTree->Branch("SimBs_pdgId", &SimBs.pdgId,"pdgId[nSvs]/F");
647     // _outTree->Branch("SimBs_status", &SimBs.status,"status[nSvs]/F");
648     // //SimBHadron Higgs Candidate
649     // _outTree->Branch("SimBs_dr", &SimBs_dr,"SimBs_dr/F");
650     // _outTree->Branch("SimBs_dPhi", &SimBs_dPhi,"SimBs_dPhi/F");
651     // _outTree->Branch("SimBs_dEta", &SimBs_dEta,"SimBs_dEta/F");
652     // _outTree->Branch("SimBs_Hmass", &SimBs_Hmass,"SimBs_Hmass/F");
653     // _outTree->Branch("SimBs_Hpt", &SimBs_Hpt,"SimBs_Hpt/F");
654     // _outTree->Branch("SimBs_Heta", &SimBs_Heta,"SimBs_Heta/F");
655     // _outTree->Branch("SimBs_Hphi", &SimBs_Hphi,"SimBs_Hphi/F");
656    
657    
658 arizzi 1.36 _outTree->Branch("rho" , &rho , "rho/F");
659     _outTree->Branch("rho25" , &rho25 , "rho25/F");
660     _outTree->Branch("nPVs" , &nPVs , "nPVs/I");
661     _outTree->Branch("METnoPU" , &METnoPU , "et/F:sumet:sig/F:phi/F");
662 arizzi 1.58 _outTree->Branch("METnoPUCh" , &METnoPUCh , "et/F:sumet:sig/F:phi/F");
663 arizzi 1.1 _outTree->Branch("MET" , &MET , "et/F:sumet:sig/F:phi/F");
664 arizzi 1.52 _outTree->Branch("fakeMET" , &fakeMET , "et/F:sumet:sig/F:phi/F");
665 arizzi 1.1 _outTree->Branch("MHT" , &MHT , "mht/F:ht:sig/F:phi/F");
666     _outTree->Branch("minDeltaPhijetMET" , &minDeltaPhijetMET , "minDeltaPhijetMET/F");
667     _outTree->Branch("jetPt_minDeltaPhijetMET" , &jetPt_minDeltaPhijetMET , "jetPt_minDeltaPhijetMET/F");
668    
669 bortigno 1.30 std::stringstream s;
670     s << "triggerFlags[" << triggers.size() << "]/b";
671     _outTree->Branch("triggerFlags", triggerFlags, s.str().c_str());
672 arizzi 1.17
673 bortigno 1.30 _outTree->Branch("EVENT" , &EVENT , "run/I:lumi/I:event/I:json/I");
674     _outTree->Branch("hbhe" , &hbhe , "hbhe/b");
675 arizzi 1.63 _outTree->Branch("totalKinematics" , &totalKinematics , "totalKinematics/b");
676 arizzi 1.56 _outTree->Branch("ecalFlag" , &ecalFlag , "ecalFlag/b");
677 bortigno 1.30 _outTree->Branch("btag1TSF" , &btag1TSF , "btag1TSF/F");
678     _outTree->Branch("btag2TSF" , &btag2TSF , "btag2TSF/F");
679     _outTree->Branch("btag1T2CSF" , &btag1T2CSF , "btag1T2CSF/F");
680 arizzi 1.44 _outTree->Branch("btag2CSF" , &btag2CSF , "btag2CSF/F");
681     _outTree->Branch("btagA0CSF" , &btagA0CSF , "btagA0CSF/F");
682 arizzi 1.60 _outTree->Branch("btagA0TSF" , &btagA0TSF , "btagA0TSF/F");
683 arizzi 1.51 _outTree->Branch("btag1TA1C" , &btag1TA1C , "btag1TA1C/F");
684 arizzi 1.1
685 bortigno 1.30 int ievt=0;
686     int totalcount=0;
687 arizzi 1.1
688 bortigno 1.30 // TFile* inFile = new TFile(inputFile.c_str(), "read");
689 arizzi 1.1 for(unsigned int iFile=0; iFile<inputFiles_.size(); ++iFile) {
690     std::cout << iFile << std::endl;
691     TFile* inFile = TFile::Open(inputFiles_[iFile].c_str());
692     if(inFile==0) continue;
693    
694 bortigno 1.30 // loop the events
695 arizzi 1.1
696     fwlite::Event ev(inFile);
697 nmohr 1.29 for(ev.toBegin(); !ev.atEnd() ; ++ev, ++ievt)
698 arizzi 1.1 {
699 nmohr 1.29 if (ievt <= skipEvents_) continue;
700     if (maxEvents_ >= 0){
701     if (ievt > maxEvents_ + skipEvents_) break;
702     };
703 arizzi 1.16 count->Fill(1.);
704 arizzi 1.1
705 arizzi 1.25 fwlite::Handle< VHbbEventAuxInfo > vhbbAuxHandle;
706     vhbbAuxHandle.getByLabel(ev,"HbbAnalyzerNew");
707     const VHbbEventAuxInfo & aux = *vhbbAuxHandle.product();
708     PUweight=1.;
709 degrutto 1.54 PUweight2011B=1.;
710 arizzi 1.1 if(isMC_){
711 arizzi 1.41
712 degrutto 1.54 // PU weights // Run2011A
713 bortigno 1.30 std::map<int, unsigned int>::const_iterator puit = aux.puInfo.pus.find(0);
714 arizzi 1.42 PUweight = lumiWeights.weight( puit->second );
715 arizzi 1.41 pu->Fill(puit->second);
716 degrutto 1.54 // PU weight Run2011B
717     // PU weight Run2011B
718     std::map<int, unsigned int>::const_iterator puit0 = aux.puInfo.pus.find(0);
719     std::map<int, unsigned int>::const_iterator puitm1 = aux.puInfo.pus.find(-1);
720     std::map<int, unsigned int>::const_iterator puitp1 = aux.puInfo.pus.find(+1);
721 arizzi 1.62 PU0=puit0->second;
722     PUp1=puitp1->second;
723     PUm1=puitm1->second;
724     input3DPU->Fill(PUm1,PU0,PUp1);
725 degrutto 1.54 PUweight2011B = lumiWeights2011B.weight3D( puitm1->second, puit0->second,puitp1->second);
726    
727 bortigno 1.30 }
728 arizzi 1.49 countWithPU->Fill(1,PUweight);
729 arizzi 1.58 countWithPU2011B->Fill(1,PUweight2011B);
730 nmohr 1.7
731 bortigno 1.30 //Write event info
732     EVENT.run = ev.id().run();
733     EVENT.lumi = ev.id().luminosityBlock();
734     EVENT.event = ev.id().event();
735     EVENT.json = jsonContainsEvent (jsonVector, ev);
736    
737     //FIXME : need to update EDM ntuple with BHadron infos
738     // // simBHadrons
739     // fwlite::Handle<SimBHadronCollection> SBHC;
740     // SBHC.getByLabel(ev, "bhadrons");
741     // const SimBHadronCollection sbhc = *(SBHC.product());
742    
743     const std::vector<VHbbCandidate> * candZ ;
744     const std::vector<VHbbCandidate> * candW ;
745     const VHbbEvent * iEvent =0;
746     if(fromCandidate)
747     {
748     fwlite::Handle< std::vector<VHbbCandidate> > vhbbCandHandleZ;
749     vhbbCandHandleZ.getByLabel(ev,"hbbBestCSVPt20Candidates");
750     candZ = vhbbCandHandleZ.product();
751    
752     fwlite::Handle< std::vector<VHbbCandidate> > vhbbCandHandle;
753     vhbbCandHandle.getByLabel(ev,"hbbHighestPtHiggsPt30Candidates");
754     candW = vhbbCandHandle.product();
755     }
756     else
757     {
758     candZlocal->clear();
759     candWlocal->clear();
760     fwlite::Handle< VHbbEvent > vhbbHandle;
761     vhbbHandle.getByLabel(ev,"HbbAnalyzerNew");
762     iEvent = vhbbHandle.product();
763     algoZ->run(vhbbHandle.product(),*candZlocal);
764     algoW->run(vhbbHandle.product(),*candWlocal);
765     candZ= candZlocal;
766     candW= candWlocal;
767    
768     /* for(size_t m=0;m<iEvent->muInfo.size();m++)
769     {
770    
771     if( fabs(iEvent->muInfo[m].p4.Pt()-28.118684) < 0.0001 ||
772     fabs(iEvent->muInfo[m].p4.Pt()-34.853199) < 0.0001 )
773     {
774     std::cout << "FOUND " << iEvent->muInfo[m].p4.Pt() << " " << EVENT.event << " " << candW->size() << " " << candZ->size() << std::endl;
775     }
776     }
777     */
778 arizzi 1.4
779 bortigno 1.30 }
780 arizzi 1.1
781 arizzi 1.3 const std::vector<VHbbCandidate> * cand = candZ;
782 arizzi 1.1
783    
784    
785 bortigno 1.30 /* fwlite::Handle< VHbbEvent > vhbbHandle;
786     vhbbHandle.getByLabel(ev,"HbbAnalyzerNew");
787     const VHbbEvent iEvent = *vhbbHandle.product();
788     */
789 arizzi 1.1
790 bortigno 1.30 // std::clog << "Filling tree "<< std::endl;
791     bool isW=false;
792 arizzi 1.21
793 arizzi 1.17
794 bortigno 1.30 if(cand->size() == 0 or cand->at(0).H.jets.size() < 2) continue;
795     if(cand->size() > 1 )
796 arizzi 1.3 {
797 bortigno 1.30 std::cout << "MULTIPLE CANDIDATES: " << cand->size() << std::endl;
798 arizzi 1.3 }
799 bortigno 1.30 if(cand->at(0).candidateType == VHbbCandidate::Wmun || cand->at(0).candidateType == VHbbCandidate::Wen ) { cand=candW; isW=true; }
800     if(cand->size() == 0)
801 arizzi 1.3 {
802 bortigno 1.30 // std::cout << "W event loss due to tigther cuts" << std::endl;
803 arizzi 1.3 continue;
804     }
805 arizzi 1.35
806 degrutto 1.54
807 arizzi 1.35 // secondary vtxs
808     fwlite::Handle<std::vector<reco::Vertex> > SVC;
809 arizzi 1.52 SVC.getByLabel(ev,"bcandidates");
810 arizzi 1.35 const std::vector<reco::Vertex> svc = *(SVC.product());
811    
812 bortigno 1.30 const VHbbCandidate & vhCand = cand->at(0);
813     patFilters.setEvent(&ev,"VH");
814     hbhe = patFilters.accept("hbhe");
815 arizzi 1.56 ecalFlag = patFilters.accept("ecalFilter");
816 arizzi 1.63 totalKinematics = patFilters.accept("totalKinematics");
817 arizzi 1.18
818 bortigno 1.30 trigger.setEvent(&ev);
819     for(size_t j=0;j < triggers.size();j++)
820 arizzi 1.4 triggerFlags[j]=trigger.accept(triggers[j]);
821 arizzi 1.39
822 bortigno 1.30 eventFlav=0;
823     if(aux.mcBbar.size() > 0 || aux.mcB.size() > 0) eventFlav=5;
824     else if(aux.mcC.size() > 0) eventFlav=4;
825 arizzi 1.8
826 arizzi 1.53 Vtype = vhCand.candidateType;
827 arizzi 1.3
828 bortigno 1.30 H.mass = vhCand.H.p4.M();
829     H.pt = vhCand.H.p4.Pt();
830     H.eta = vhCand.H.p4.Eta();
831     H.phi = vhCand.H.p4.Phi();
832     V.mass = vhCand.V.p4.M();
833 arizzi 1.36 if(isW) V.mass = vhCand.Mt();
834 bortigno 1.30 V.pt = vhCand.V.p4.Pt();
835     V.eta = vhCand.V.p4.Eta();
836     V.phi = vhCand.V.p4.Phi();
837     nhJets=2;
838     hJets.set(vhCand.H.jets[0],0);
839     hJets.set(vhCand.H.jets[1],1);
840     aJets.reset();
841     naJets=vhCand.additionalJets.size();
842     numBJets=0;
843     if(vhCand.H.jets[0].csv> btagThr) numBJets++;
844     if(vhCand.H.jets[1].csv> btagThr) numBJets++;
845     for( int j=0; j < naJets && j < MAXJ; j++ )
846 arizzi 1.6 {
847 bortigno 1.30 aJets.set(vhCand.additionalJets[j],j);
848     if(vhCand.additionalJets[j].csv> btagThr) numBJets++;
849 arizzi 1.6 }
850 bortigno 1.30 numJets = vhCand.additionalJets.size()+2;
851 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());
852     H.dPhi = deltaPhi(vhCand.H.jets[0].p4.Phi(),vhCand.H.jets[1].p4.Phi());
853     H.dEta= TMath::Abs( vhCand.H.jets[0].p4.Eta() - vhCand.H.jets[1].p4.Eta() );
854 bortigno 1.30 HVdPhi = fabs( deltaPhi(vhCand.H.p4.Phi(),vhCand.V.p4.Phi()) ) ;
855 arizzi 1.41 HVMass = (vhCand.H.p4 + vhCand.V.p4).M() ;
856 bortigno 1.30 HMETdPhi = fabs( deltaPhi(vhCand.H.p4.Phi(),vhCand.V.mets.at(0).p4.Phi()) ) ;
857     VMt = vhCand.Mt() ;
858 arizzi 1.52 //eltaPullAngle = vhCand.H.deltaTheta;
859     deltaPullAngle = VHbbCandidateTools::getDeltaTheta(vhCand.H.jets[0],vhCand.H.jets[1]);
860     deltaPullAngle2 = VHbbCandidateTools::getDeltaTheta(vhCand.H.jets[1],vhCand.H.jets[0]);
861    
862 bortigno 1.30
863     hJets.cosTheta[0]= vhCand.H.helicities[0];
864     hJets.cosTheta[1]= vhCand.H.helicities[1];
865 arizzi 1.36 // METInfo calomet; METInfo tcmet; METInfo pfmet; METInfo mht; METInfo metNoPU
866 bortigno 1.30 MET.et = vhCand.V.mets.at(0).p4.Pt();
867     MET.phi = vhCand.V.mets.at(0).p4.Phi();
868     MET.sumet = vhCand.V.mets.at(0).sumEt;
869     MET.sig = vhCand.V.mets.at(0).metSig;
870 arizzi 1.24
871 arizzi 1.52
872     fakeMET.sumet = 0;
873     fakeMET.sig = 0;
874     fakeMET.et = 0;
875     fakeMET.phi = 0;
876     if( Vtype == VHbbCandidate::Zmumu) {
877     TVector3 mu1 = vhCand.V.muons[0].p4.Vect();
878     TVector3 mu2 = vhCand.V.muons[1].p4.Vect();
879     // Not needed with PFMET
880     // mu1.SetMag( mu1.Mag() - vhCand.V.muons[0].emEnergy - vhCand.V.muons[0].hadEnergy);
881     // mu2.SetMag( mu2.Mag() - vhCand.V.muons[1].emEnergy - vhCand.V.muons[1].hadEnergy);
882     TVector3 sum = vhCand.V.mets.at(0).p4.Vect() + mu1 + mu2;
883     fakeMET.et = sum.Pt();
884     fakeMET.phi = sum.Phi();
885     fakeMET.sumet = vhCand.V.mets.at(0).sumEt - mu1.Pt() - mu2.Pt();
886     }
887    
888 arizzi 1.36 METnoPU.et = iEvent->metNoPU.p4.Pt();
889     METnoPU.phi = iEvent->metNoPU.p4.Phi();
890     METnoPU.sumet = iEvent->metNoPU.sumEt;
891     METnoPU.sig = iEvent->metNoPU.metSig;
892 arizzi 1.59 METnoPUCh.et = iEvent->metCh.p4.Pt();
893     METnoPUCh.phi = iEvent->metCh.p4.Phi();
894     METnoPUCh.sumet = iEvent->metCh.sumEt;
895     METnoPUCh.sig = iEvent->metCh.metSig;
896 arizzi 1.36
897 arizzi 1.58 METnoPUCh.et = iEvent->metCh.p4.Pt();
898     METnoPUCh.phi = iEvent->metCh.p4.Phi();
899     METnoPUCh.sumet = iEvent->metCh.sumEt;
900     METnoPUCh.sig = iEvent->metCh.metSig;
901    
902 arizzi 1.36 rho = aux.puInfo.rho;
903     rho25 = aux.puInfo.rho25;
904     nPVs=aux.pvInfo.nVertices;
905    
906 arizzi 1.24 if(!fromCandidate) {
907     MHT.mht = iEvent->mht.p4.Pt();
908     MHT.phi = iEvent->mht.p4.Phi();
909     MHT.ht = iEvent->mht.sumEt;
910     MHT.sig = iEvent->mht.metSig;
911 bortigno 1.30 }
912    
913 arizzi 1.24
914    
915 bortigno 1.30 //Secondary Vertices
916     IVF.reset();
917     nSvs = svc.size();
918     const TVector3 recoPv = aux.pvInfo.firstPVInPT2;
919     const math::XYZPoint myPv(recoPv);
920     //look here for Matrix filling info http://project-mathlibs.web.cern.ch/project-mathlibs/sw/html/SMatrixDoc.html
921     std::vector<double> fillMatrix(6);
922     for (int i = 0; i<6; ++i) fillMatrix[i] = 0.;
923     fillMatrix[0] = TMath::Power(0.002,2);
924     fillMatrix[2] = TMath::Power(0.002,2);
925     fillMatrix[5] = TMath::Power(0.002,2);
926     const ROOT::Math::SMatrix<double, 3, 3, ROOT::Math::MatRepSym<double, 3> > myFakeMatrixError(fillMatrix.begin(),fillMatrix.end());
927     const reco::Vertex recoVtxPv(myPv, myFakeMatrixError);
928     for( int j=0; j < nSvs && j < MAXB; ++j ) {
929     const GlobalVector flightDir = flightDirection(recoPv,svc[j]);
930     reco::SecondaryVertex recoSv(recoVtxPv, svc[j], flightDir ,true);
931     IVF.set( recoSv, recoPv ,j);
932     }
933     if(nSvs > 2){
934     TLorentzVector BCands_H1, BCands_H2, BCands_H;
935     BCands_H1.SetPtEtaPhiM(IVF.pt[0], IVF.eta[0], IVF.phi[0], IVF.massBcand[0]);
936     BCands_H2.SetPtEtaPhiM(IVF.pt[1], IVF.eta[1], IVF.phi[1], IVF.massBcand[1]);
937     BCands_H = BCands_H1 + BCands_H2;
938 arizzi 1.33 SVH.dR = deltaR(IVF.eta[0], IVF.phi[0], IVF.eta[1], IVF.phi[1] );
939     SVH.dPhi = deltaPhi(IVF.phi[0], IVF.phi[1] );
940     SVH.dEta = TMath::Abs(IVF.eta[0] - IVF.eta[1] );
941     SVH.mass = BCands_H.M();
942     SVH.pt = BCands_H.Pt();
943     SVH.eta = BCands_H.Eta();
944     SVH.phi = BCands_H.Phi();
945 bortigno 1.30 }
946    
947     //FIXME : need to update EDM ntuple with simBhadron info
948     // //SimBhadron
949     // SimBs.reset();
950     // nSimBs = sbhc.size();
951     // for( int j=0; j < nSimBs && j < MAXB; ++j )
952     // SimBs.set( sbhc.at(j), j);
953     // if(nSimBs > 2){
954     // TLorentzVector SimBs_H1, SimBs_H2, SimBs_H;
955     // SimBs_H1.SetPtEtaPhiM(SimBs.pt[0], SimBs.eta[0], SimBs.phi[0], SimBs.mass[0]);
956     // SimBs_H2.SetPtEtaPhiM(SimBs.pt[1], SimBs.eta[1], SimBs.phi[1], SimBs.mass[1]);
957     // SimBs_H = SimBs_H1 + SimBs_H2;
958     // SimBs_dr = deltaR(SimBs.eta[0], SimBs.phi[0], SimBs.eta[1], SimBs.phi[1] );
959     // SimBs_dPhi = deltaPhi(SimBs.phi[0], SimBs.phi[1] );
960     // SimBs_dEta = TMath::Abs(SimBs.eta[0] - SimBs.eta[1] );
961     // SimBs_Hmass = SimBs_H.M();
962     // SimBs_Hpt = SimBs_H.Pt();
963     // SimBs_Heta = SimBs_H.Eta();
964     // SimBs_Hphi = SimBs_H.Phi();
965     // }
966    
967    
968     //Loop on jets
969     double maxBtag=-99999;
970     minDeltaPhijetMET = 999;
971     TLorentzVector bJet;
972     std::vector<std::vector<BTagWeight::JetInfo> > btagJetInfos;
973     std::vector<float> jet30eta;
974     std::vector<float> jet30pt;
975     if(fromCandidate)
976     {
977     //Loop on Higgs Jets
978     for(unsigned int j=0; j < vhCand.H.jets.size(); j++ ){
979     if (vhCand.H.jets[j].csv > maxBtag) { bJet=vhCand.H.jets[j].p4 ; maxBtag =vhCand.H.jets[j].csv; }
980 arizzi 1.39 if (fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.H.jets[j].p4.Phi())) < minDeltaPhijetMET)
981 bortigno 1.30 {
982 arizzi 1.39 minDeltaPhijetMET=fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.H.jets[j].p4.Phi()));
983 arizzi 1.24 jetPt_minDeltaPhijetMET=vhCand.H.jets[j].p4.Pt();
984 bortigno 1.30 }
985     btagJetInfos.push_back(btagEff.jetInfo(vhCand.H.jets[j]));
986     }
987     //Loop on Additional Jets
988     for(unsigned int j=0; j < vhCand.additionalJets.size(); j++ ){
989     if (vhCand.additionalJets[j].csv > maxBtag) { bJet=vhCand.additionalJets[j].p4 ; maxBtag =vhCand.additionalJets[j].csv; }
990 arizzi 1.45 /* if (fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.additionalJets[j].p4.Phi())) < minDeltaPhijetMET)
991 bortigno 1.30 {
992 arizzi 1.39 minDeltaPhijetMET=fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), vhCand.additionalJets[j].p4.Phi()));
993 arizzi 1.24 jetPt_minDeltaPhijetMET=vhCand.additionalJets[j].p4.Pt();
994 arizzi 1.45 }*/
995 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
996     {
997     if(vhCand.additionalJets[j].p4.Pt() > 20)
998     btagJetInfos.push_back(btagEff.jetInfo(vhCand.additionalJets[j]));
999     }
1000     }
1001     }
1002     else
1003     {
1004 arizzi 1.45 //Loop on all jets
1005 bortigno 1.30 for(unsigned int j=0; j < iEvent->simpleJets2.size(); j++ ){
1006     if (iEvent->simpleJets2[j].csv > maxBtag) { bJet=iEvent->simpleJets2[j].p4 ; maxBtag =iEvent->simpleJets2[j].csv; }
1007 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)
1008 arizzi 1.46 {
1009     minDeltaPhijetMET=fabs(deltaPhi( vhCand.V.mets.at(0).p4.Phi(), iEvent->simpleJets2[j].p4.Phi()));
1010     jetPt_minDeltaPhijetMET=iEvent->simpleJets2[j].p4.Pt();
1011     }
1012 bortigno 1.30 if(iEvent->simpleJets2[j].p4.Pt() > 30)
1013     {
1014     jet30eta.push_back(iEvent->simpleJets2[j].p4.Eta());
1015     jet30pt.push_back(iEvent->simpleJets2[j].p4.Pt());
1016     }
1017 arizzi 1.24
1018 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)
1019     // 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
1020     if( ( isW && ! useHighestPtHiggsW ) || ( ! isW && ! useHighestPtHiggsZ ) )
1021     {
1022 arizzi 1.58 if(iEvent->simpleJets2[j].p4.Pt() > 20 && fabs(iEvent->simpleJets2[j].p4.Eta()) < 2.5)
1023 bortigno 1.30 btagJetInfos.push_back(btagEff.jetInfo(iEvent->simpleJets2[j]));
1024     }
1025     }
1026    
1027 arizzi 1.45 //Loop on Higgs jets
1028    
1029     for(unsigned int j=0; j < vhCand.H.jets.size(); j++ ) {
1030    
1031 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
1032     // by a criteria (pt of the dijet) that is not btag SF dependent
1033     if(!( ( isW && ! useHighestPtHiggsW ) || ( ! isW && ! useHighestPtHiggsZ ) )) {
1034 arizzi 1.45 btagJetInfos.push_back(btagEff.jetInfo(vhCand.H.jets[j]));
1035 bortigno 1.30 }
1036 arizzi 1.45 }
1037 arizzi 1.24
1038 bortigno 1.30 }
1039     vLeptons.reset();
1040     weightTrig = 1.; // better to default to 1
1041 arizzi 1.38 weightTrigMay = -1.;
1042     weightTrigV4 = -1.;
1043 arizzi 1.51 weightTrigOrMu30 = 1.;
1044 bortigno 1.30 TLorentzVector leptonForTop;
1045     size_t firstAddMu=0;
1046     size_t firstAddEle=0;
1047     if(Vtype == VHbbCandidate::Zmumu ){
1048     vLeptons.set(vhCand.V.muons[0],0,13);
1049     vLeptons.set(vhCand.V.muons[1],1,13);
1050     float cweightID = triggerWeight.scaleMuID(vLeptons.pt[0],vLeptons.eta[0]) * triggerWeight.scaleMuID(vLeptons.pt[1],vLeptons.eta[1]) ;
1051     float weightTrig1 = triggerWeight.scaleMuIsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
1052     float weightTrig2 = triggerWeight.scaleMuIsoHLT(vLeptons.pt[1],vLeptons.eta[1]);
1053     float cweightTrig = weightTrig1 + weightTrig2 - weightTrig1*weightTrig2;
1054     weightTrig = cweightID * cweightTrig;
1055     nvlep=2;
1056     firstAddMu=2;
1057     }
1058     if( Vtype == VHbbCandidate::Zee ){
1059     vLeptons.set(vhCand.V.electrons[0],0,11);
1060     vLeptons.set(vhCand.V.electrons[1],1,11);
1061     nvlep=2;
1062     firstAddEle=2;
1063     std::vector<float> pt,eta;
1064     pt.push_back(vLeptons.pt[0]); eta.push_back(vLeptons.eta[0]);
1065     pt.push_back(vLeptons.pt[1]); eta.push_back(vLeptons.eta[1]);
1066     weightEleRecoAndId=triggerWeight.scaleID95Ele(vLeptons.pt[0],vLeptons.eta[0]) * triggerWeight.scaleRecoEle(vLeptons.pt[0],vLeptons.eta[0]) *
1067     triggerWeight.scaleID95Ele(vLeptons.pt[1],vLeptons.eta[1]) * triggerWeight.scaleRecoEle(vLeptons.pt[1],vLeptons.eta[1]);
1068     weightEleTrigElePart = triggerWeight.scaleDoubleEle17Ele8(pt,eta);
1069 arizzi 1.60 weightEleTrigEleAugPart = triggerWeight.scaleDoubleEle17Ele8Aug(pt,eta);
1070     weightTrig = (weightEleTrigElePart*1.14+weightEleTrigEleAugPart*0.98 )/2.12 * weightEleRecoAndId;
1071 arizzi 1.24
1072    
1073    
1074 bortigno 1.30 }
1075     if(Vtype == VHbbCandidate::Wmun ){
1076     leptonForTop=vhCand.V.muons[0].p4;
1077     vLeptons.set(vhCand.V.muons[0],0,13);
1078     float cweightID = triggerWeight.scaleMuID(vLeptons.pt[0],vLeptons.eta[0]);
1079     float weightTrig1 = triggerWeight.scaleMuIsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
1080     float cweightTrig = weightTrig1;
1081     weightTrig = cweightID * cweightTrig;
1082 arizzi 1.51 float weightTrig1OrMu30 = triggerWeight.scaleMuOr30IsoHLT(vLeptons.pt[0],vLeptons.eta[0]);
1083 dlopes 1.61 weightTrigOrMu30 = cweightID*weightTrig1OrMu30;
1084 bortigno 1.30 nvlep=1;
1085     firstAddMu=1;
1086     }
1087     if( Vtype == VHbbCandidate::Wen ){
1088     leptonForTop=vhCand.V.electrons[0].p4;
1089     vLeptons.set(vhCand.V.electrons[0],0,11);
1090     nvlep=1;
1091     firstAddEle=1;
1092 arizzi 1.38 weightTrigMay = triggerWeight.scaleSingleEleMay(vLeptons.pt[0],vLeptons.eta[0]);
1093     weightTrigV4 = triggerWeight.scaleSingleEleV4(vLeptons.pt[0],vLeptons.eta[0]);
1094 bortigno 1.30 weightEleRecoAndId=triggerWeight.scaleID80Ele(vLeptons.pt[0],vLeptons.eta[0]) * triggerWeight.scaleRecoEle(vLeptons.pt[0],vLeptons.eta[0]);
1095 arizzi 1.59 weightEleTrigJetMETPart=triggerWeight.scaleJet30Jet25(jet30pt,jet30eta)*triggerWeight.scalePFMHTEle(MET.et);
1096 arizzi 1.38 weightEleTrigElePart= weightTrigV4; //this is for debugging only, checking only the V4 part
1097 bortigno 1.30
1098 arizzi 1.38 weightTrigMay*=weightEleRecoAndId;
1099     weightTrigV4*=weightEleRecoAndId;
1100     weightTrigV4*=weightEleTrigJetMETPart;
1101 arizzi 1.60 // weightTrig = weightTrigMay * 0.187 + weightTrigV4 * (1.-0.187); //FIXME: use proper lumi if we reload 2.fb
1102     weightTrig = (weightTrigMay * 0.215 + weightTrigV4 * 1.915)/ 2.13; //FIXME: use proper lumi if we reload 2.fb
1103 bortigno 1.30 }
1104     if( Vtype == VHbbCandidate::Znn ){
1105     nvlep=0;
1106     float weightTrig1 = triggerWeight.scaleMetHLT(vhCand.V.mets.at(0).p4.Pt());
1107     weightTrig = weightTrig1;
1108     weightTrigMET = weightTrig1;
1109     }
1110 arizzi 1.38
1111     if(weightTrigMay < 0) weightTrigMay=weightTrig;
1112     if(weightTrigV4 < 0) weightTrigV4=weightTrig;
1113 arizzi 1.40 if(!isMC_)
1114     {
1115     weightTrig = 1.;
1116     weightTrigMay = 1.;
1117     weightTrigV4 = 1.;
1118    
1119     }
1120 bortigno 1.30 aLeptons.reset();
1121     nalep=0;
1122     if(fromCandidate)
1123 arizzi 1.21 {
1124     for(size_t j=firstAddMu;j< vhCand.V.muons.size();j++) aLeptons.set(vhCand.V.muons[j],nalep++,13);
1125     for(size_t j=firstAddEle;j< vhCand.V.electrons.size();j++) aLeptons.set(vhCand.V.electrons[j],nalep++,11);
1126     }
1127 bortigno 1.30 else
1128 arizzi 1.21 {
1129 bortigno 1.30 for(size_t j=0;j< iEvent->muInfo.size();j++)
1130     {
1131 arizzi 1.21 if((j!= vhCand.V.firstLepton && j!= vhCand.V.secondLepton) || ((Vtype != VHbbCandidate::Wmun ) && (Vtype != VHbbCandidate::Zmumu )) )
1132 bortigno 1.30 aLeptons.set(iEvent->muInfo[j],nalep++,13);
1133     }
1134     for(size_t j=0;j< iEvent->eleInfo.size();j++)
1135     {
1136 arizzi 1.21 if((j!= vhCand.V.firstLepton && j!= vhCand.V.secondLepton) || ((Vtype != VHbbCandidate::Wen ) && (Vtype != VHbbCandidate::Zee )))
1137 bortigno 1.30 aLeptons.set(iEvent->eleInfo[j],nalep++,11);
1138     }
1139 arizzi 1.8
1140 arizzi 1.21 }
1141 arizzi 1.8
1142 arizzi 1.24
1143 bortigno 1.30 if(isMC_)
1144     {
1145     //std::cout << "BTAGSF " << btagJetInfos.size() << " " << btag.weight<BTag1Tight2CustomFilter>(btagJetInfos) << std::endl;
1146     if ( btagJetInfos.size()< 10)
1147     {
1148     btag1T2CSF = btag.weight<BTag1Tight2CustomFilter>(btagJetInfos);
1149     btag2TSF = btag.weight<BTag2TightFilter>(btagJetInfos);
1150     btag1TSF = btag.weight<BTag1TightFilter>(btagJetInfos);
1151 arizzi 1.44 btagA0CSF = btag.weight<BTagAntiMax0CustomFilter>(btagJetInfos);
1152 arizzi 1.60 btagA0TSF = btag.weight<BTagAntiMax0TightFilter>(btagJetInfos);
1153 arizzi 1.44 btag2CSF = btag.weight<BTag2CustomFilter>(btagJetInfos);
1154 arizzi 1.51 btag1TA1C = btag.weight<BTag1TightAndMax1CustomFilter>(btagJetInfos);
1155 bortigno 1.30 }
1156     else
1157     {
1158     std::cout << "WARNING: combinatorics for " << btagJetInfos.size() << " jets is too high (>=10). use SF=1 " << std::endl;
1159     //TODO: revert to random throw for this cases
1160     btag1T2CSF = 1.;
1161     btag2TSF = 1.;
1162     btag1TSF = 1.;
1163 arizzi 1.51 btagA0CSF = 1.;
1164 arizzi 1.60 btagA0TSF = 1.;
1165 arizzi 1.51 btag2CSF = 1.;
1166     btag1TA1C = 1.;
1167 bortigno 1.30 }
1168     }
1169 arizzi 1.17
1170 bortigno 1.30 if(maxBtag > -99999)
1171 arizzi 1.8 {
1172 bortigno 1.30 TopHypo topQuark = TopMassReco::topMass(leptonForTop,bJet,vhCand.V.mets.at(0).p4);
1173     top.mass = topQuark.p4.M();
1174     top.pt = topQuark.p4.Pt();
1175     top.wMass = topQuark.p4W.M();
1176 arizzi 1.8 } else {
1177 bortigno 1.30 top.mass = -99;
1178     top.pt = -99;
1179     top.wMass = -99;
1180     }
1181 arizzi 1.8
1182    
1183    
1184 bortigno 1.30 //FIXME: too much warnings... figure out why
1185     // gendrcc=aux.genCCDeltaR();
1186     // gendrbb=aux.genBBDeltaR();
1187     genZpt=aux.mcZ.size() > 0 ? aux.mcZ[0].p4.Pt():-99;
1188     genWpt=aux.mcW.size() > 0 ? aux.mcW[0].p4.Pt():-99;
1189 arizzi 1.49 WminusMode=-99;
1190     WplusMode=-99;
1191 arizzi 1.50 for(unsigned int j=0; j< aux.mcW.size();j++)
1192 arizzi 1.49 {
1193     for(unsigned int k=0;k< aux.mcW[j].dauid.size();k++)
1194     {
1195     int idd=abs(aux.mcW[j].dauid[k]);
1196     if(idd==11 || idd==13 || idd==15|| (idd<=5 && idd >=1))
1197     {
1198     if(WminusMode==-99 && aux.mcW[j].charge ==-1) WminusMode = idd;
1199     if(WplusMode==-99 && aux.mcW[j].charge ==-1) WplusMode = idd;
1200     }
1201     }
1202 arizzi 1.24
1203 arizzi 1.49
1204     }
1205 arizzi 1.25
1206 arizzi 1.32 /// Compute pull angle from AK7
1207 arizzi 1.25 if(!fromCandidate){
1208 arizzi 1.32 std::vector<VHbbEvent::SimpleJet> ak7wrt1(iEvent->simpleJets3);
1209     std::vector<VHbbEvent::SimpleJet> ak7wrt2(iEvent->simpleJets3);
1210     if(ak7wrt1.size() > 1){
1211 arizzi 1.24 CompareDeltaR deltaRComparatorJ1(vhCand.H.jets[0].p4);
1212     CompareDeltaR deltaRComparatorJ2(vhCand.H.jets[1].p4);
1213 arizzi 1.32 std::sort( ak7wrt1.begin(),ak7wrt1.end(),deltaRComparatorJ1 );
1214     std::sort( ak7wrt2.begin(),ak7wrt2.end(),deltaRComparatorJ2 );
1215 arizzi 1.24 std::vector<VHbbEvent::SimpleJet> ak7_matched;
1216 arizzi 1.32 // if the matched are different save them
1217     if(ak7wrt1[0].p4.DeltaR(ak7wrt2[0].p4) > 0.1) {
1218     ak7_matched.push_back(ak7wrt1[0]);
1219     ak7_matched.push_back(ak7wrt2[0]);
1220     }
1221     // else look at the second best
1222     else{
1223     // ak7wrt1 is best
1224     if( ak7wrt1[1].p4.DeltaR(vhCand.H.jets[0].p4) < ak7wrt2[1].p4.DeltaR(vhCand.H.jets[1].p4))
1225     {
1226     ak7_matched.push_back(ak7wrt1[1]);
1227     ak7_matched.push_back(ak7wrt2[0]);
1228     }
1229     else
1230     {
1231     ak7_matched.push_back(ak7wrt1[0]);
1232     ak7_matched.push_back(ak7wrt2[1]);
1233     }
1234     }
1235 arizzi 1.24 CompareJetPt ptComparator;
1236     std::sort( ak7_matched.begin(),ak7_matched.end(),ptComparator );
1237     if(ak7_matched[0].p4.DeltaR(vhCand.H.jets[0].p4) < 0.5
1238 arizzi 1.32 and ak7_matched[1].p4.DeltaR(vhCand.H.jets[1].p4) < 0.5)
1239     {
1240     deltaPullAngleAK7 = VHbbCandidateTools::getDeltaTheta(ak7_matched[0],ak7_matched[1]);
1241 arizzi 1.52 deltaPullAngle2AK7 = VHbbCandidateTools::getDeltaTheta(ak7_matched[1],ak7_matched[0]);
1242 arizzi 1.32 }
1243 arizzi 1.24 }
1244     }
1245 arizzi 1.3
1246 bortigno 1.30 _outTree->Fill();
1247 arizzi 1.4
1248 bortigno 1.30 }// closed event loop
1249 arizzi 1.1
1250 bortigno 1.30 std::cout << "closing the file: " << inputFiles_[iFile] << std::endl;
1251     inFile->Close();
1252     // close input file
1253     } // loop on files
1254 arizzi 1.1
1255    
1256 bortigno 1.30 std::cout << "Events: " << ievt <<std::endl;
1257     std::cout << "TotalCount: " << totalcount <<std::endl;
1258 arizzi 1.1
1259    
1260    
1261 bortigno 1.30 _outFile->cd();
1262 arizzi 1.1
1263 bortigno 1.30 _outTree->Write();
1264     _outFile->Write();
1265     _outFile->Close();
1266     return 0;
1267 arizzi 1.1 }
1268    
1269