ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/VHbbAnalysis/HbbAnalyzer/plugins/HbbAnalyzerNew.cc
(Generate patch)

Comparing UserCode/VHbbAnalysis/HbbAnalyzer/plugins/HbbAnalyzerNew.cc (file contents):
Revision 1.3 by tboccali, Thu Jun 9 06:51:57 2011 UTC vs.
Revision 1.60 by sethzenz, Wed Feb 22 16:46:53 2012 UTC

# Line 17 | Line 17 | Implementation:
17   //
18   //
19  
20 +
21 + //uncomment to save also jet collections 1 and 4
22 + //#define ENABLE_SIMPLEJETS1
23 + //#define ENABLE_SIMPLEJETS4
24 +
25 + #include "CondFormats/JetMETObjects/interface/JetCorrectorParameters.h"
26 + #include "CondFormats/JetMETObjects/interface/JetCorrectionUncertainty.h"
27 + #include "JetMETCorrections/Objects/interface/JetCorrector.h"
28 + #include "JetMETCorrections/Objects/interface/JetCorrectionsRecord.h"
29 + #include "DataFormats/TrackReco/interface/TrackFwd.h"
30 +
31   #include "VHbbAnalysis/HbbAnalyzer/interface/HbbAnalyzerNew.h"
32 < #include "VHbbAnalysis/HbbAnalyzer/interface/VHbbEvent.h"
32 > #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
33 >
34 > #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
35 > #include "DataFormats/Math/interface/deltaR.h"
36 >
37  
38   #define GENPTOLOR(a) TLorentzVector((a).px(), (a).py(), (a).pz(), (a).energy())
39   #define GENPTOLORP(a) TLorentzVector((a)->px(), (a)->py(), (a)->pz(), (a)->energy())
40  
26 HbbAnalyzerNew::HbbAnalyzerNew(const edm::ParameterSet& iConfig):
27  eleLabel_(iConfig.getUntrackedParameter<edm::InputTag>("electronTag")),
28  muoLabel_(iConfig.getUntrackedParameter<edm::InputTag>("muonTag")),
29  jetLabel_(iConfig.getUntrackedParameter<edm::InputTag>("jetTag")),
30  subjetLabel_(iConfig.getUntrackedParameter<edm::InputTag>("subjetTag")),
31  simplejet1Label_(iConfig.getUntrackedParameter<edm::InputTag>("simplejet1Tag")),
32  simplejet2Label_(iConfig.getUntrackedParameter<edm::InputTag>("simplejet2Tag")),
33  simplejet3Label_(iConfig.getUntrackedParameter<edm::InputTag>("simplejet3Tag")),
34  simplejet4Label_(iConfig.getUntrackedParameter<edm::InputTag>("simplejet4Tag")),
35  tauLabel_(iConfig.getUntrackedParameter<edm::InputTag>("tauTag")),
36  metLabel_(iConfig.getUntrackedParameter<edm::InputTag>("metTag")),
37  phoLabel_(iConfig.getUntrackedParameter<edm::InputTag>("photonTag")),
38  dimuLabel_(iConfig.getUntrackedParameter<edm::InputTag>("dimuTag")),
39  dielecLabel_(iConfig.getUntrackedParameter<edm::InputTag>("dielecTag")),
40  hltResults_(iConfig.getUntrackedParameter<edm::InputTag>("hltResultsTag")),
41  runOnMC_(iConfig.getParameter<bool>("runOnMC")) {
41  
42  
43 + struct CompareJetPtMuons {
44 +  bool operator()( const VHbbEvent::MuonInfo& j1, const  VHbbEvent::MuonInfo& j2 ) const {
45 +    return j1.p4.Pt() > j2.p4.Pt();
46 +  }
47 + };
48 + struct CompareJetPtElectrons {
49 +  bool operator()( const VHbbEvent::ElectronInfo& j1, const  VHbbEvent::ElectronInfo& j2 ) const {
50 +    return j1.p4.Pt() > j2.p4.Pt();
51 +  }
52 + };
53 + struct CompareJetPtTaus {
54 +  bool operator()( const VHbbEvent::TauInfo& j1, const  VHbbEvent::TauInfo& j2 ) const {
55 +    return j1.p4.Pt() > j2.p4.Pt();
56 +  }
57 + };
58 +
59 +
60 +
61 + HbbAnalyzerNew::HbbAnalyzerNew(const edm::ParameterSet& iConfig):
62 +  eleLabel_(iConfig.getParameter<edm::InputTag>("electronTag")),
63 +  muoLabel_(iConfig.getParameter<edm::InputTag>("muonTag")),
64 +  lep_ptCutForBjets_(iConfig.getParameter<double>("lep_ptCutForBjets")),
65 +  elenoCutsLabel_(iConfig.getParameter<edm::InputTag>("electronNoCutsTag")),
66 +  muonoCutsLabel_(iConfig.getParameter<edm::InputTag>("muonNoCutsTag")),
67 +  jetLabel_(iConfig.getParameter<edm::InputTag>("jetTag")),
68 +  subjetLabel_(iConfig.getParameter<edm::InputTag>("subjetTag")),
69 +  filterjetLabel_(iConfig.getParameter<edm::InputTag>("filterjetTag")),
70 +  simplejet1Label_(iConfig.getParameter<edm::InputTag>("simplejet1Tag")),
71 +  simplejet2Label_(iConfig.getParameter<edm::InputTag>("simplejet2Tag")),
72 +  simplejet3Label_(iConfig.getParameter<edm::InputTag>("simplejet3Tag")),
73 +  simplejet4Label_(iConfig.getParameter<edm::InputTag>("simplejet4Tag")),
74 +  tauLabel_(iConfig.getParameter<edm::InputTag>("tauTag")),
75 +  metLabel_(iConfig.getParameter<edm::InputTag>("metTag")),
76 +  phoLabel_(iConfig.getParameter<edm::InputTag>("photonTag")),
77 +  hltResults_(iConfig.getParameter<edm::InputTag>("hltResultsTag")),
78 +  runOnMC_(iConfig.getParameter<bool>("runOnMC")), verbose_(iConfig.getUntrackedParameter<bool>("verbose")) {
79 +
80    //
81    // put the setwhatproduced etc etc
82  
83    produces<VHbbEvent>();
84 +  produces<VHbbEventAuxInfo>();
85  
86  
87   }
# Line 67 | Line 104 | void
104   HbbAnalyzerNew::produce(edm::Event& iEvent, const edm::EventSetup& iSetup){
105    using namespace edm;
106    using namespace reco;
107 +
108 +
109 +  // JEC Uncertainty
110 +
111 +  //  JetCorrectionUncertainty *jecUnc=0;
112 +  edm::ESHandle<JetCorrectorParametersCollection> JetCorParColl;
113 +  iSetup.get<JetCorrectionsRecord>().get("AK5PFchs",JetCorParColl);
114 +  JetCorrectionUncertainty *jecUnc=0;
115 +  //  if (!runOnMC_){
116 +  JetCorrectorParameters const & JetCorPar = (*JetCorParColl)["Uncertainty"];
117 +  jecUnc = new JetCorrectionUncertainty(JetCorPar);
118 +  //  }
119    
120 <  
121 <  std::auto_ptr<VHbbEvent> hbbInfo( new VHbbEvent() );
122 <  
120 >  std::auto_ptr<VHbbEvent> hbbInfo( new VHbbEvent() );  
121 >  std::auto_ptr<VHbbEventAuxInfo> auxInfo( new VHbbEventAuxInfo() );
122 >
123 >
124 >  if (runOnMC_){
125 >    Handle<GenEventInfoProduct> evt_info;
126 >    iEvent.getByType(evt_info);
127 >    auxInfo->weightMCProd = evt_info->weight();
128 >  }
129 >  else
130 >    { auxInfo->weightMCProd =1.;}
131    //
132    // ??
133 <  
133 >  
134 >  // trigger
135 >
136    // trigger
137    edm::Handle<edm::TriggerResults>  hltresults;
138    //iEvent.getByLabel("TriggerResults", hltresults);
# Line 83 | Line 142 | HbbAnalyzerNew::produce(edm::Event& iEve
142    iEvent.getByLabel(hltResults_, hltresults);
143    
144    const edm::TriggerNames & triggerNames_ = iEvent.triggerNames(*hltresults);
86  
87  int ntrigs = hltresults->size();
88  if (ntrigs==0){std::cout << "%HLTInfo -- No trigger name given in TriggerResults of the input " << std::endl;}
89
90  for (int itrig = 0; itrig != ntrigs; ++itrig){
91
92    TString trigName=triggerNames_.triggerName(itrig);
93    bool accept = hltresults->accept(itrig);
94
95    if (accept){(hbbInfo->triggerInfo.flag)[itrig] = 1;}
96    else { (hbbInfo->triggerInfo.flag)[itrig] = 0;}
97
98    //    std::cout << "%HLTInfo --  Number of HLT Triggers: " << ntrigs << std::endl;
99    //    std::cout << "%HLTInfo --  HLTTrigger(" << itrig << "): " << trigName << " = " << accept << std::endl;
100  }
101
102  //
103  // big bloat
104  //
105
106
107  int goodDoubleMu3=0,goodDoubleMu3_2=0,  
108    goodMu9=0, goodIsoMu9=0, goodMu11=0, goodIsoMu13_3=0, goodMu15=0, goodMu15_1=0;
109  int goodDoubleElec10=0,goodDoubleElec15_1=0,goodDoubleElec17_1=0;
110  int goodMet100=0;
111  int goodSingleEle1=0,goodSingleEle2=0,goodSingleEle3=0,goodSingleEle4=0;
112  int goodBtagMu1=0,goodBtagMu2=0,goodBtagMu0=0,goodBtagMu11=0;  
113  int goodBtagMuJet1=0, goodBtagMuJet2=0, goodBtagMuJet3=0, goodBtagMuJet4=0;
114  int goodIsoMu15=0,goodIsoMu17v5=0,goodIsoMu17v6=0;
115
116  for (int itrig = 0; itrig != ntrigs; ++itrig){
117    TString trigName=triggerNames_.triggerName(itrig);
118    if(strcmp(trigName,"HLT_Mu9")==0) goodMu9++;
119    if(strcmp(trigName,"HLT_IsoMu9")==0) goodIsoMu9++;
120    if(strcmp(trigName,"HLT_IsoMu13_v3")==0) goodIsoMu13_3++;
121    if(strcmp(trigName,"HLT_Mu11")==0) goodMu11++;
122    if(strcmp(trigName,"HLT_DoubleMu3")==0) goodDoubleMu3++;
123    if(strcmp(trigName,"HLT_DoubleMu3_v2")==0) goodDoubleMu3_2++;
124    if(strcmp(trigName,"HLT_Mu15")==0) goodMu15++;
125    if(strcmp(trigName,"HLT_Mu15_v1")==0) goodMu15_1++;
126
127    if(strcmp(trigName,"HLT_DoubleEle10_SW_L1R")==0) goodDoubleElec10++;
128    if(strcmp(trigName,"HLT_DoubleEle15_SW_L1R_v1")==0) goodDoubleElec15_1++;
129    if(strcmp(trigName,"HLT_DoubleEle17_SW_L1R_v1")==0) goodDoubleElec17_1++;
130    if(strcmp(trigName,"HLT_MET100_v1")==0) goodMet100++;
131    if(strcmp(trigName,"HLT_Ele15_SW_L1R")==0) goodSingleEle1++;
132    if(strcmp(trigName,"HLT_Ele17_SW_TightEleId_L1R")==0) goodSingleEle2++;
133    if(strcmp(trigName,"HLT_Ele17_SW_TighterEleIdIsol_L1R_v2")==0) goodSingleEle3++;
134    if(strcmp(trigName,"HLT_Ele17_SW_TighterEleIdIsol_L1R_v3")==0) goodSingleEle4++;
135    if(strcmp(trigName,"HLT_BTagMu_DiJet20U_v1")==0) goodBtagMu1++;
136    if(strcmp(trigName,"HLT_BTagMu_DiJet30U_Mu5_v3")==0) goodBtagMu2++;
137    if(strcmp(trigName,"HLT_BTagMu_Jet20U")==0) goodBtagMu0++;
138    if(strcmp(trigName,"HLT_BTagMu_DiJet20U_Mu5_v1")==0) goodBtagMu11++;
139    if(strcmp(trigName,"HLT_Mu17_CentralJet30_BTagIP_v2")==0) goodBtagMuJet1++;
140    if(strcmp(trigName,"HLT_Mu17_CentralJet30_v2")==0) goodBtagMuJet2++;
141    if(strcmp(trigName,"HLT_HT200_Mu5_PFMHT35_v2")==0) goodBtagMuJet3++;
142    if(strcmp(trigName,"HLT_Mu12_CentralJet30_BTagIP_v2")==0) goodBtagMuJet4++;  
143
144    if(strcmp(trigName,"HLT_IsoMu15_v5")==0) goodIsoMu15++;
145    if(strcmp(trigName,"HLT_IsoMu17_v5")==0) goodIsoMu17v5++;  
146    if(strcmp(trigName,"HLT_IsoMu17_v6")==0) goodIsoMu17v6++;  
147  }
148  int itrig1=-99;
149  if(goodMu9!=0) itrig1 = triggerNames_.triggerIndex("HLT_Mu9");
150  int itrig2=-99;
151  if(goodIsoMu9!=0) itrig2 = triggerNames_.triggerIndex("HLT_IsoMu9");
152  int itrig3=-99;
153  if(goodIsoMu13_3!=0) itrig3 = triggerNames_.triggerIndex("HLT_IsoMu13_v3");
154  int itrig4=-99;
155  if(goodMu11!=0) itrig4 = triggerNames_.triggerIndex("HLT_Mu11");
156  int itrig5=-99;  
157  if(goodDoubleMu3!=0) itrig5 = triggerNames_.triggerIndex("HLT_DoubleMu3");
158  int itrig6=-99;
159  if(goodDoubleMu3_2!=0) itrig6 = triggerNames_.triggerIndex("HLT_DoubleMu3_v2");
160  int itrig7=-99;
161  if(goodMu15!=0) itrig7 = triggerNames_.triggerIndex("HLT_Mu15");
162  int itrig8=-99;
163  if(goodMu15_1!=0) itrig8 = triggerNames_.triggerIndex("HLT_Mu15_v1");
164
165  int itrig9=-99;
166  if(goodDoubleElec10!=0) itrig9 = triggerNames_.triggerIndex("HLT_DoubleEle10_SW_L1R");
167  int itrig10=-99;
168  if(goodDoubleElec15_1!=0) itrig10 = triggerNames_.triggerIndex("HLT_DoubleEle15_SW_L1R_v1");
169  int itrig11=-99;
170  if(goodDoubleElec17_1!=0) itrig11 = triggerNames_.triggerIndex("HLT_DoubleEle17_SW_L1R_v1");
171  int itrig12=-99;
172  if(goodMet100!=0) itrig12 = triggerNames_.triggerIndex("HLT_MET100_v1");
173
174  int itrig13=-99;
175  if(goodSingleEle1!=0) itrig13 = triggerNames_.triggerIndex("HLT_Ele15_SW_L1R");
176  int itrig14=-99;
177  if(goodSingleEle2!=0) itrig14 = triggerNames_.triggerIndex("HLT_Ele17_SW_TightEleId_L1R");
178  int itrig15=-99;
179  if(goodSingleEle3!=0) itrig15 = triggerNames_.triggerIndex("HLT_Ele17_SW_TighterEleIdIsol_L1R_v2");
180  int itrig16=-99;
181  if(goodSingleEle4!=0) itrig16 = triggerNames_.triggerIndex("HLT_Ele17_SW_TighterEleIdIsol_L1R_v3");
182
183  int itrig17=-99;
184  if(goodBtagMu1!=0) itrig17 = triggerNames_.triggerIndex("HLT_BTagMu_DiJet20U_v1");      
185  int itrig18=-99;
186  if(goodBtagMu2!=0) itrig18 = triggerNames_.triggerIndex("HLT_BTagMu_DiJet30U_Mu5_v3");    
187  int itrig19=-99;
188  if(goodBtagMu0!=0) itrig19 = triggerNames_.triggerIndex("HLT_BTagMu_Jet20U");
189  int itrig20=-99;
190  if(goodBtagMu11!=0) itrig20 = triggerNames_.triggerIndex("HLT_BTagMu_DiJet20U_Mu5_v1");
191  int itrig21=-99;
192  if(goodBtagMuJet1!=0) itrig21 = triggerNames_.triggerIndex("HLT_Mu17_CentralJet30_BTagIP_v2");
193  int itrig22=-99;
194  if(goodBtagMuJet2!=0) itrig22 = triggerNames_.triggerIndex("HLT_Mu17_CentralJet30_v2");
195  int itrig23=-99;
196  if(goodBtagMuJet3!=0) itrig23 = triggerNames_.triggerIndex("HLT_HT200_Mu5_PFMHT35_v2");
197  int itrig231=-99;
198  if(goodBtagMuJet4!=0) itrig231 = triggerNames_.triggerIndex("HLT_Mu12_CentralJet30_BTagIP_v2");  
199
200  int itrig24=-99;
201  if(goodIsoMu15!=0) itrig24 = triggerNames_.triggerIndex("HLT_IsoMu15_v5");
202  int itrig25=-99;
203  if(goodIsoMu17v5!=0) itrig25 = triggerNames_.triggerIndex("HLT_IsoMu17_v5");
204  int itrig26=-99;
205  if(goodIsoMu17v6!=0) itrig26 = triggerNames_.triggerIndex("HLT_IsoMu17_v6");
206  
207  if (itrig1!=-99 && hltresults->accept(itrig1))  hbbInfo->triggerInfo.triggerMu9=1; else hbbInfo->triggerInfo.triggerMu9=0;
208  if (itrig2!=-99 && hltresults->accept(itrig2))  hbbInfo->triggerInfo.triggerIsoMu9=1; else hbbInfo->triggerInfo.triggerIsoMu9=0;
209  if (itrig3!=-99 && hltresults->accept(itrig3))  hbbInfo->triggerInfo.triggerIsoMu13_3=1; else hbbInfo->triggerInfo.triggerIsoMu13_3=0;
210  if (itrig4!=-99 && hltresults->accept(itrig4))  hbbInfo->triggerInfo.triggerMu11=1; else hbbInfo->triggerInfo.triggerMu11=0;
211  if (itrig5!=-99 && hltresults->accept(itrig5))  hbbInfo->triggerInfo.triggerDoubleMu3=1; else hbbInfo->triggerInfo.triggerDoubleMu3=0;
212  if (itrig6!=-99 && hltresults->accept(itrig6))  hbbInfo->triggerInfo.triggerDoubleMu3_2=1; else hbbInfo->triggerInfo.triggerDoubleMu3_2=0;
213  if (itrig7!=-99 && hltresults->accept(itrig7))  hbbInfo->triggerInfo.triggerMu15=1; else hbbInfo->triggerInfo.triggerMu15=0;
214  if (itrig8!=-99 && hltresults->accept(itrig8))  hbbInfo->triggerInfo.triggerMu15_1=1; else hbbInfo->triggerInfo.triggerMu15_1=0;  
215  
216  if (itrig9!=-99 && hltresults->accept(itrig9))  hbbInfo->triggerInfo.triggerDoubleElec10=1; else hbbInfo->triggerInfo.triggerDoubleElec10=0;  
217  if (itrig10!=-99 && hltresults->accept(itrig10))  hbbInfo->triggerInfo.triggerDoubleElec15_1=1; else hbbInfo->triggerInfo.triggerDoubleElec15_1=0;  
218  if (itrig11!=-99 && hltresults->accept(itrig11))  hbbInfo->triggerInfo.triggerDoubleElec17_1=1; else hbbInfo->triggerInfo.triggerDoubleElec17_1=0;  
219  if (itrig12!=-99 && hltresults->accept(itrig12))  hbbInfo->triggerInfo.triggerMet100_1=1; else hbbInfo->triggerInfo.triggerMet100_1=0;
220  
221  if (itrig13!=-99 && hltresults->accept(itrig13))  hbbInfo->triggerInfo.triggerSingleEle1=1; else hbbInfo->triggerInfo.triggerSingleEle1=0;
222  if (itrig14!=-99 && hltresults->accept(itrig14))  hbbInfo->triggerInfo.triggerSingleEle2=1; else hbbInfo->triggerInfo.triggerSingleEle2=0;
223  if (itrig15!=-99 && hltresults->accept(itrig15))  hbbInfo->triggerInfo.triggerSingleEle3=1; else hbbInfo->triggerInfo.triggerSingleEle3=0;
224  if (itrig16!=-99 && hltresults->accept(itrig16))  hbbInfo->triggerInfo.triggerSingleEle4=1; else hbbInfo->triggerInfo.triggerSingleEle4=0;
225  
226  if (itrig17!=-99 && hltresults->accept(itrig17))  hbbInfo->triggerInfo.triggerBtagMu1=1; else hbbInfo->triggerInfo.triggerBtagMu1=0;  
227  if (itrig18!=-99 && hltresults->accept(itrig18))  hbbInfo->triggerInfo.triggerBtagMu2=1; else hbbInfo->triggerInfo.triggerBtagMu2=0;
228  if (itrig19!=-99 && hltresults->accept(itrig19))  hbbInfo->triggerInfo.triggerBtagMu0=1; else hbbInfo->triggerInfo.triggerBtagMu0=0;
229  if (itrig20!=-99 && hltresults->accept(itrig20))  hbbInfo->triggerInfo.triggerBtagMu11=1; else hbbInfo->triggerInfo.triggerBtagMu11=0;
230  if (itrig21!=-99 && hltresults->accept(itrig21))  hbbInfo->triggerInfo.triggerBtagMuJet1=1; else hbbInfo->triggerInfo.triggerBtagMuJet1=0;
231  if (itrig22!=-99 && hltresults->accept(itrig22))  hbbInfo->triggerInfo.triggerBtagMuJet2=1; else hbbInfo->triggerInfo.triggerBtagMuJet2=0;
232  if (itrig23!=-99 && hltresults->accept(itrig23))  hbbInfo->triggerInfo.triggerBtagMuJet3=1; else hbbInfo->triggerInfo.triggerBtagMuJet3=0;
233  if (itrig231!=-99 && hltresults->accept(itrig231))  hbbInfo->triggerInfo.triggerBtagMuJet4=1; else hbbInfo->triggerInfo.triggerBtagMuJet4=0;
234  
235  if (itrig24!=-99 && hltresults->accept(itrig24))  hbbInfo->triggerInfo.triggerIsoMu15=1; else hbbInfo->triggerInfo.triggerIsoMu15=0;
236  if (itrig25!=-99 && hltresults->accept(itrig25))  hbbInfo->triggerInfo.triggerIsoMu17v5=1; else hbbInfo->triggerInfo.triggerIsoMu17v5=0;
237  if (itrig26!=-99 && hltresults->accept(itrig26))  hbbInfo->triggerInfo.triggerIsoMu17v6=1; else hbbInfo->triggerInfo.triggerIsoMu17v6=0;
238  
239  if (itrig1==-99)  hbbInfo->triggerInfo.triggerMu9=-99;
240  if (itrig2==-99)  hbbInfo->triggerInfo.triggerIsoMu9=-99;
241  if (itrig3==-99)  hbbInfo->triggerInfo.triggerIsoMu13_3=-99;
242  if (itrig4==-99)  hbbInfo->triggerInfo.triggerMu11=-99;
243  if (itrig5==-99)  hbbInfo->triggerInfo.triggerDoubleMu3=-99;
244  if (itrig6==-99)  hbbInfo->triggerInfo.triggerDoubleMu3_2=-99;
245  if (itrig7==-99)  hbbInfo->triggerInfo.triggerMu15=-99;
246  if (itrig8==-99)  hbbInfo->triggerInfo.triggerMu15_1=-99;
247
248  if (itrig9==-99)  hbbInfo->triggerInfo.triggerDoubleElec10=-99;
249  if (itrig10==-99)  hbbInfo->triggerInfo.triggerDoubleElec15_1=-99;
250  if (itrig11==-99)  hbbInfo->triggerInfo.triggerDoubleElec17_1=-99;
251  if (itrig12==-99) hbbInfo->triggerInfo.triggerMet100_1=-99;
252
253  if (itrig13==-99) hbbInfo->triggerInfo.triggerSingleEle1=-99;
254  if (itrig14==-99) hbbInfo->triggerInfo.triggerSingleEle2=-99;
255  if (itrig15==-99) hbbInfo->triggerInfo.triggerSingleEle3=-99;
256  if (itrig16==-99) hbbInfo->triggerInfo.triggerSingleEle4=-99;
257
258  if(itrig17==-99)  hbbInfo->triggerInfo.triggerBtagMu1=-99;  
259  if(itrig18==-99)  hbbInfo->triggerInfo.triggerBtagMu2=-99;
260  if(itrig19==-99)  hbbInfo->triggerInfo.triggerBtagMu0=-99;
261  if(itrig20==-99)  hbbInfo->triggerInfo.triggerBtagMu11=-99;
262  if(itrig21==-99)  hbbInfo->triggerInfo.triggerBtagMuJet1=-99;
263  if(itrig22==-99)  hbbInfo->triggerInfo.triggerBtagMuJet2=-99;
264  if(itrig23==-99)  hbbInfo->triggerInfo.triggerBtagMuJet3=-99;
265  if(itrig231==-99)  hbbInfo->triggerInfo.triggerBtagMuJet4=-99;
266
267  if(itrig24==-99)  hbbInfo->triggerInfo.triggerIsoMu15=-99;
268  if(itrig25==-99)  hbbInfo->triggerInfo.triggerIsoMu17v5=-99;
269  if(itrig26==-99)  hbbInfo->triggerInfo.triggerIsoMu17v6=-99;
270
271  //  MinDRMu=-99.,MCBestMuId=-99,MCBestMuMomId=-99,MCBestMuGMomId=-99;
272  //  for(int i=0;i<50;i++) {DeltaRMu[i]=-99;}
273
145  
146 +  int ntrigs = hltresults->size();
147 +  if (ntrigs==0){std::cerr << "%HLTInfo -- No trigger name given in TriggerResults of the input " << std::endl;}
148  
149    BeamSpot vertexBeamSpot;
150    edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
# Line 289 | Line 162 | HbbAnalyzerNew::produce(edm::Event& iEve
162    Handle<reco::VertexCollection> recVtxs;
163    iEvent.getByLabel("offlinePrimaryVertices", recVtxs);
164    
165 +  auxInfo->pvInfo.nVertices = recVtxs->size();
166 +
167    for(size_t i = 0; i < recVtxs->size(); ++ i) {
168      const Vertex &vtx = (*recVtxs)[i];
169      double RecVtxProb=TMath::Prob(vtx.chi2(),vtx.ndof());
# Line 301 | Line 176 | HbbAnalyzerNew::produce(edm::Event& iEve
176    const Vertex &RecVtx = (*recVtxs)[VtxIn];
177    const Vertex &RecVtxFirst = (*recVtxs)[0];
178    
179 <  hbbInfo->pvInfo.firstPVInPT2 = TVector3(RecVtxFirst.x(), RecVtxFirst.y(), RecVtxFirst.z());
180 <  hbbInfo->pvInfo.firstPVInProb = TVector3(RecVtx.x(), RecVtx.y(), RecVtx.z());
181 <
179 >  auxInfo->pvInfo.firstPVInPT2 = TVector3(RecVtxFirst.x(), RecVtxFirst.y(), RecVtxFirst.z());
180 >  auxInfo->pvInfo.firstPVInProb = TVector3(RecVtx.x(), RecVtx.y(), RecVtx.z());
181 >  
182 >  (auxInfo->pvInfo).efirstPVInPT2 = (RecVtxFirst.error());
183 >  (auxInfo->pvInfo).efirstPVInProb = RecVtx.error();
184      
185    edm::Handle<double> rhoHandle;
186 <  iEvent.getByLabel(edm::InputTag("kt6PFJets", "rho"),rhoHandle); // configure srcRho = cms.InputTag('kt6PFJets")
187 <  hbbInfo->puInfo.rho = *rhoHandle;
188 <  
186 >  iEvent.getByLabel(edm::InputTag("kt6PFJets", "rho"),rhoHandle);  
187 >  auxInfo->puInfo.rho = *rhoHandle;
188 >  
189 >  edm::Handle<double> rho25Handle;
190 >  iEvent.getByLabel(edm::InputTag("kt6PFJets25", "rho"),rho25Handle);  
191 >  auxInfo->puInfo.rho25 = *rho25Handle;
192 >
193 >  edm::Handle<std::vector< PileupSummaryInfo> > puHandle;
194 >
195 >  if (runOnMC_){
196 >    iEvent.getByType(puHandle);
197 >    if (puHandle.isValid()){
198 >      
199 >      std::vector< PileupSummaryInfo> pu = (*puHandle);
200 >      for (std::vector<PileupSummaryInfo>::const_iterator it= pu.begin(); it!=pu.end(); ++it){
201 >         int bx = (*it).getBunchCrossing();
202 >        unsigned int num = (*it).getPU_NumInteractions();
203 >        //      std::cout <<" PU PUSHING "<<bx<<" " <<num<<std::endl;
204 >        auxInfo->puInfo.pus[bx]  =num;
205 >      }
206 >    }
207 >  }
208 >
209    //// real start
210    
211    
# Line 319 | Line 216 | HbbAnalyzerNew::produce(edm::Event& iEve
216    
217    if(runOnMC_){
218      
219 <    int Hin=-99,Win=-99,Zin=-99,bin=-99,bbarin=-99;
323 <    
324 <    iEvent.getByLabel("genParticles", genParticles);
219 >   iEvent.getByLabel("genParticles", genParticles);
220      
221      for(size_t i = 0; i < genParticles->size(); ++ i) {
222 +    
223        const GenParticle & p = (*genParticles)[i];
224        int id = p.pdgId();
225        int st = p.status();  
226 <        
226 >      
227        if(id==25){
228 <          
229 <        /*          int wh=0;
230 <                    int nMoth = p.numberOfMothers();
231 <                    for(size_t jj = 0; jj < nMoth; ++ jj) {
232 <                    const Candidate * mom = p.mother( jj );
233 <                    int nmomdau= mom->numberOfDaughters();
234 <                    for(size_t j = 0; j < nmomdau; ++ j) {
235 <                    const Candidate * Wmomdau = mom->daughter( j );
340 <                    if(abs(Wmomdau->pdgId())==24) wh++;
341 <                    }
342 <                    }
343 <                      
344 <                    if(wh==0) continue;
345 <        */
346 <        Hin=i;
347 <        hbbInfo->mcH.status=st;
348 <        hbbInfo->mcH.charge=p.charge();
349 <        if(p.mother(0)!=0) hbbInfo->mcH.momid=p.mother(0)->pdgId();
350 <        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcH.gmomid=p.mother(0)->mother(0)->pdgId();
351 <        hbbInfo->mcH.fourMomentum = GENPTOLOR(p);
352 <          
228 >        
229 >        VHbbEventAuxInfo::ParticleMCInfo htemp;
230 >        htemp.status=st;
231 >        htemp.charge=p.charge();
232 >        if(p.mother(0)!=0) htemp.momid=p.mother(0)->pdgId();
233 >        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) htemp.gmomid=p.mother(0)->mother(0)->pdgId();
234 >        htemp.p4 = GENPTOLOR(p);
235 >        
236          int ndau = p.numberOfDaughters();
237          for(int j = 0; j < ndau; ++ j) {
238            const Candidate * Hdau = p.daughter( j );
239 <          hbbInfo->mcH.dauid.push_back(Hdau->pdgId());
240 <          hbbInfo->mcH.dauFourMomentum.push_back(GENPTOLORP(Hdau));
239 >          htemp.dauid.push_back(Hdau->pdgId());
240 >          htemp.dauFourMomentum.push_back(GENPTOLORP(Hdau));
241          }
242 +        (auxInfo->mcH).push_back(htemp);
243        }
244 +      
245 +      
246 +      if(abs(id)==24){
247          
248 +        VHbbEventAuxInfo::ParticleMCInfo wtemp;
249 +        wtemp.status=st;
250 +        wtemp.charge=p.charge();
251 +        if(p.mother(0)!=0) wtemp.momid=p.mother(0)->pdgId();
252 +        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) wtemp.gmomid=p.mother(0)->mother(0)->pdgId();
253 +        wtemp.p4=GENPTOLOR(p);
254          
362      if(abs(id)==24){
363          
364        Win=i;
365        hbbInfo->mcW.status=st;
366        hbbInfo->mcW.charge=p.charge();
367        if(p.mother(0)!=0) hbbInfo->mcW.momid=p.mother(0)->pdgId();
368        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcW.gmomid=p.mother(0)->mother(0)->pdgId();
369        hbbInfo->mcW.fourMomentum=GENPTOLOR(p);
370
255          int ndau = p.numberOfDaughters();
256          for(int j = 0; j < ndau; ++ j) {
257            const Candidate * Wdau = p.daughter( j );
258 <          hbbInfo->mcW.dauid.push_back(Wdau->pdgId());
259 <          hbbInfo->mcW.dauFourMomentum.push_back(GENPTOLORP(Wdau));
258 >          wtemp.dauid.push_back(Wdau->pdgId());
259 >          wtemp.dauFourMomentum.push_back(GENPTOLORP(Wdau));
260          }
261 +        auxInfo->mcW.push_back(wtemp);
262        }
263          
264        if(abs(id)==23){
265  
266 <        Zin=i;
267 <        hbbInfo->mcZ.status=st;
268 <        hbbInfo->mcZ.charge=p.charge();
269 <        if(p.mother(0)!=0) hbbInfo->mcZ.momid=p.mother(0)->pdgId();
270 <        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcZ.gmomid=p.mother(0)->mother(0)->pdgId();
271 <        hbbInfo->mcZ.fourMomentum=GENPTOLOR(p);
266 >
267 >        VHbbEventAuxInfo::ParticleMCInfo ztemp;
268 >        ztemp.status=st;
269 >        ztemp.charge=p.charge();
270 >        if(p.mother(0)!=0) ztemp.momid=p.mother(0)->pdgId();
271 >        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) ztemp.gmomid=p.mother(0)->mother(0)->pdgId();
272 >        ztemp.p4=GENPTOLOR(p);
273  
274          int ndau = p.numberOfDaughters();
275          for(int j = 0; j < ndau; ++ j) {
276            const Candidate * Zdau = p.daughter( j );
277 <          hbbInfo->mcZ.dauid.push_back(Zdau->pdgId());
278 <          hbbInfo->mcZ.dauFourMomentum.push_back(GENPTOLOR(p));
277 >          ztemp.dauid.push_back(Zdau->pdgId());
278 >          ztemp.dauFourMomentum.push_back(GENPTOLORP(Zdau));
279          }
280 +        auxInfo->mcZ.push_back(ztemp);
281        }
282        //
283        // binfo
284        //
285 <
285 >      
286        
287        if(id==5){
288 <        bin=i;
289 <        hbbInfo->mcB.status=st;
290 <        hbbInfo->mcB.charge=p.charge();
291 <        if(p.mother(0)!=0) hbbInfo->mcB.momid=p.mother(0)->pdgId();
292 <        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcB.gmomid=p.mother(0)->mother(0)->pdgId();
288 >
289 >        VHbbEventAuxInfo::ParticleMCInfo btemp;
290 >        btemp.status=st;
291 >        btemp.charge=p.charge();
292 >        if(p.mother(0)!=0) btemp.momid=p.mother(0)->pdgId();
293 >        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) btemp.gmomid=p.mother(0)->mother(0)->pdgId();
294 >
295 >        btemp.p4=GENPTOLOR(p);
296 >        
297 >        int nHDaubdau = p.numberOfDaughters();
298 >        for(int j = 0; j < nHDaubdau; ++ j) {
299 >          const Candidate * Bdau = p.daughter( j );
300 >          btemp.dauid.push_back(Bdau->pdgId());
301 >        }
302 >        auxInfo->mcB.push_back(btemp);
303        }
304        
305        if(id==-5){
409        bbarin=i;
410        hbbInfo->mcBbar.status=st;
411        hbbInfo->mcBbar.charge=p.charge();
412        if(p.mother(0)!=0) hbbInfo->mcBbar.momid=p.mother(0)->pdgId();
413        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcBbar.gmomid=p.mother(0)->mother(0)->pdgId();
414      }
415      
416      if(abs(id)==4){
417        hbbInfo->mcC.status=st;
418        hbbInfo->mcC.charge=p.charge();
419        if(p.mother(0)!=0) hbbInfo->mcC.momid=p.mother(0)->pdgId();
420        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcC.gmomid=p.mother(0)->mother(0)->pdgId();
421      }
306  
307 +        VHbbEventAuxInfo::ParticleMCInfo bbtemp;
308 +        
309 +        bbtemp.status=st;
310 +        bbtemp.charge=p.charge();
311 +        if(p.mother(0)!=0) bbtemp.momid=p.mother(0)->pdgId();
312 +        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) bbtemp.gmomid=p.mother(0)->mother(0)->pdgId();
313  
314 <    }
314 >        bbtemp.p4=GENPTOLOR(p);
315 >        
316 >        int nHDaubdau = p.numberOfDaughters();
317 >        for(int j = 0; j < nHDaubdau; ++ j) {
318 >          const Candidate * Bdau = p.daughter( j );
319 >          bbtemp.dauid.push_back(Bdau->pdgId());
320 >        }
321  
322  
323 <    if(bin!=-99 && bbarin!=-99){
324 <      const Candidate & bGen = (*genParticles)[bin];
429 <      const Candidate & bbarGen = (*genParticles)[bbarin];
430 <      hbbInfo->mcB.fourMomentum=GENPTOLOR(bGen);
431 <      hbbInfo->mcBbar.fourMomentum=GENPTOLOR(bbarGen);
323 >        auxInfo->mcBbar.push_back(bbtemp);
324 >     }
325        
326 <      int nHDaubdau = bGen.numberOfDaughters();
327 <      for(int j = 0; j < nHDaubdau; ++ j) {
328 <        const Candidate * Bdau = bGen.daughter( j );
329 <        hbbInfo->mcB.dauid.push_back(Bdau->pdgId());
330 <        hbbInfo->mcB.dauFourMomentum.push_back(GENPTOLORP(Bdau));
331 <      }
439 <      int nHDaubbardau = bbarGen.numberOfDaughters();
440 <      for(int j = 0; j < nHDaubbardau; ++ j) {
441 <        const Candidate * Bbardau = bbarGen.daughter( j );
442 <        hbbInfo->mcBbar.dauid.push_back(Bbardau->pdgId());
443 <        hbbInfo->mcBbar.dauFourMomentum.push_back(GENPTOLORP(Bbardau));
444 <      }
326 >      if(abs(id)==4){
327 >        VHbbEventAuxInfo::ParticleMCInfo ctemp;
328 >        ctemp.status=st;
329 >        ctemp.charge=p.charge();
330 >        if(p.mother(0)!=0) ctemp.momid=p.mother(0)->pdgId();
331 >        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) ctemp.gmomid=p.mother(0)->mother(0)->pdgId();
332  
333 <  
333 >        ctemp.p4=GENPTOLOR(p);
334 >        
335 >        int nHDaubdau = p.numberOfDaughters();
336 >        for(int j = 0; j < nHDaubdau; ++ j) {
337 >          const Candidate * Bdau = p.daughter( j );
338 >          ctemp.dauid.push_back(Bdau->pdgId());
339 >        }
340  
341 <    }
341 >        auxInfo->mcC.push_back(ctemp);  
342  
343 +      }
344 +
345 +    }
346  
347    }   // isMC
348  
# Line 467 | Line 363 | HbbAnalyzerNew::produce(edm::Event& iEve
363    iEvent.getByLabel(subjetLabel_,subjetHandle);
364    edm::View<pat::Jet> subjets = *subjetHandle;
365  
366 +  // filter jet  
367 +  edm::Handle<edm::View<pat::Jet> > filterjetHandle;
368 +  iEvent.getByLabel(filterjetLabel_,filterjetHandle);
369 +  edm::View<pat::Jet> filterjets = *filterjetHandle;
370 +
371    // standard jets
372  
373    edm::Handle<edm::View<pat::Jet> > simplejet1Handle;
# Line 490 | Line 391 | HbbAnalyzerNew::produce(edm::Event& iEve
391    iEvent.getByLabel(eleLabel_,electronHandle);
392    edm::View<pat::Electron> electrons = *electronHandle;
393  
493  edm::Handle<edm::View<pat::MET> > metHandle;
494  iEvent.getByLabel(metLabel_,metHandle);
495  edm::View<pat::MET> mets = *metHandle;
394  
395    //   edm::Handle<edm::View<pat::Photon> > phoHandle;
396    //   iEvent.getByLabel(phoLabel_,phoHandle);
# Line 502 | Line 400 | HbbAnalyzerNew::produce(edm::Event& iEve
400    iEvent.getByLabel(tauLabel_,tauHandle);
401    edm::View<pat::Tau> taus = *tauHandle;
402  
505  edm::Handle<CandidateView> dimuons;
506  iEvent.getByLabel(dimuLabel_,dimuons);
507
508  edm::Handle<CandidateView> dielectrons;
509  iEvent.getByLabel(dielecLabel_,dielectrons);
403  
404 +  //BTAGGING SCALE FACTOR FROM DATABASE
405 +  //Combined Secondary Vertex Loose
406 +  edm::ESHandle<BtagPerformance> bTagSF_CSVL_;
407 +  iSetup.get<BTagPerformanceRecord>().get("BTAGCSVL",bTagSF_CSVL_);
408 +  //Combined Secondary Vertex Medium
409 +  edm::ESHandle<BtagPerformance> bTagSF_CSVM_;
410 +  iSetup.get<BTagPerformanceRecord>().get("BTAGCSVM",bTagSF_CSVM_);
411 +  //Combined Secondary Vertex Tight
412 +  edm::ESHandle<BtagPerformance> bTagSF_CSVT_;
413 +  iSetup.get<BTagPerformanceRecord>().get("BTAGCSVT",bTagSF_CSVT_);
414 +
415 +  edm::ESHandle<BtagPerformance> mistagSF_CSVL_;
416 +  iSetup.get<BTagPerformanceRecord>().get("MISTAGCSVL",mistagSF_CSVL_);
417 +  //Combined Secondary Vertex Medium
418 +  edm::ESHandle<BtagPerformance> mistagSF_CSVM_;
419 +  iSetup.get<BTagPerformanceRecord>().get("MISTAGCSVM",mistagSF_CSVM_);
420 +  //Combined Secondary Vertex Tight
421 +  edm::ESHandle<BtagPerformance> mistagSF_CSVT_;
422 +  iSetup.get<BTagPerformanceRecord>().get("MISTAGCSVT",mistagSF_CSVT_);
423 +
424 + BTagSFContainer btagSFs;
425 +  btagSFs.BTAGSF_CSVL = (bTagSF_CSVL_.product());
426 +  btagSFs.BTAGSF_CSVM = (bTagSF_CSVM_.product());
427 +  btagSFs.BTAGSF_CSVT = (bTagSF_CSVT_.product());
428 +  btagSFs.MISTAGSF_CSVL = (mistagSF_CSVL_.product());
429 +  btagSFs.MISTAGSF_CSVM = (mistagSF_CSVM_.product());
430 +  btagSFs.MISTAGSF_CSVT = (mistagSF_CSVT_.product());
431  
432 + #ifdef ENABLE_SIMPLEJETS1
433    for(edm::View<pat::Jet>::const_iterator jet_iter = simplejets1.begin(); jet_iter!=simplejets1.end(); ++jet_iter){
434      //     if(jet_iter->pt()>50)
435      //       njetscounter++;
436      VHbbEvent::SimpleJet sj;
437 <    sj.flavour = jet_iter->partonFlavour();
437 >    //    std::cout <<" sj1"<<std::endl;
438 >    fillSimpleJet(sj,jet_iter);
439 >    //    if(!runOnMC_)
440  
441 <
519 <    sj.tche=jet_iter->bDiscriminator("trackCountingHighEffBJetTags");
520 <    sj.tchp=jet_iter->bDiscriminator("trackCountingHighPurBJetTags");
521 <    sj.jp=jet_iter->bDiscriminator("jetProbabilityBJetTags");
522 <    sj.jpb=jet_iter->bDiscriminator("jetBProbabilityBJetTags");
523 <    sj.ssvhe=jet_iter->bDiscriminator("simpleSecondaryVertexHighEffBJetTags");
524 <    sj.csv=jet_iter->bDiscriminator("combinedSecondaryVertexBJetTags");
525 <    sj.csvmva=jet_iter->bDiscriminator("combinedSecondaryVertexMVABJetTags");
526 <    sj.charge=jet_iter->jetCharge();
527 <    sj.ntracks=jet_iter->associatedTracks().size();
528 <    sj.fourMomentum=GENPTOLORP(jet_iter);
441 >   setJecUnc(sj,jecUnc);
442  
443      Particle::LorentzVector p4Jet = jet_iter->p4();
444  
445      if(runOnMC_){
446 <      double minb1DR=9999.;
447 <      for(size_t i = 0; i < genParticles->size(); ++ i) {
448 <        const GenParticle & p = (*genParticles)[i];
449 <        int id = p.pdgId();
450 <        if(abs(id)<=6 || id==21 || id==23 || abs(id)==24){
451 <          double bb1DR=TMath::Sqrt((p.eta()-p4Jet.eta())*(p.eta()-p4Jet.eta())+
452 <                                   (p.phi()-p4Jet.phi())*(p.phi()-p4Jet.phi()));
453 <          if(bb1DR<minb1DR) {minb1DR=bb1DR; sj.b1BestMCid=id; if(p.mother()!=0) sj.b1BestMCmomid=p.mother()->pdgId();}
446 >
447 >      fillScaleFactors(sj, btagSFs);
448 >
449 >      //PAT genJet matching
450 >      //genJet
451 >      const reco::GenJet *gJ = jet_iter->genJet();
452 >      //physical parton for mother info ONLY
453 >      if( (jet_iter->genParton()) ){
454 >        sj.bestMCid = jet_iter->genParton()->pdgId();
455 >        if( (jet_iter->genParton()->mother()) )
456 >          sj.bestMCmomid=jet_iter->genParton()->mother()->pdgId();
457 >      }
458 >      TLorentzVector gJp4;
459 >      if(gJ){
460 >        gJp4.SetPtEtaPhiE(gJ->pt(),gJ->eta(),gJ->phi(),gJ->energy());
461 >        sj.bestMCp4 = gJp4;
462 >        if(verbose_){
463 >          std::clog << "genJet matched Pt = " << gJp4.Pt() << std::endl;
464 >          std::clog << "genJet matched eta = " << gJp4.Eta() << std::endl;
465 >          std::clog << "genJet matched deltaR = " <<gJp4.DeltaR(sj.p4) << std::endl;
466 >          std::clog << "genJet matched mother id = " << sj.bestMCmomid << std::endl;
467          }
468        }
469 <    } //isMC    
469 >      
470 >    } //isMC
471      hbbInfo->simpleJets.push_back(sj);
472      
473    }
474 <  
474 > #endif //ENABLE_SIMPLEJETS1
475 >
476 >  for(edm::View<pat::Jet>::const_iterator jet_iter = simplejets3.begin(); jet_iter!=simplejets3.end(); ++jet_iter){
477 >    //     if(jet_iter->pt()>50)
478 >    //       njetscounter++;
479 >    VHbbEvent::SimpleJet sj;
480 >    //    std::cout <<" sj3"<<std::endl;
481 >    fillSimpleJet(sj,jet_iter);
482 >    //    if(!runOnMC_)  
483 >  setJecUnc(sj,jecUnc);
484 >
485 >   Particle::LorentzVector p4Jet = jet_iter->p4();
486 >
487 >    if(runOnMC_){
488 >
489 >      fillScaleFactors(sj, btagSFs);
490 >
491 >      //PAT genJet matching
492 >      //genJet
493 >      const reco::GenJet *gJ = jet_iter->genJet();
494 >      //physical parton for mother info ONLY
495 >      if( (jet_iter->genParton()) ){
496 >        sj.bestMCid = jet_iter->genParton()->pdgId();
497 >        if( (jet_iter->genParton()->mother()) )
498 >          sj.bestMCmomid=jet_iter->genParton()->mother()->pdgId();
499 >      }
500 >      TLorentzVector gJp4;
501 >      if(gJ){
502 >        gJp4.SetPtEtaPhiE(gJ->pt(),gJ->eta(),gJ->phi(),gJ->energy());
503 >        sj.bestMCp4 = gJp4;
504 >        if(verbose_){
505 >          std::clog << "genJet matched Pt = " << gJp4.Pt() << std::endl;
506 >          std::clog << "genJet matched eta = " << gJp4.Eta() << std::endl;
507 >          std::clog << "genJet matched deltaR = " <<gJp4.DeltaR(sj.p4) << std::endl;
508 >          std::clog << "genJet matched mother id = " << sj.bestMCmomid << std::endl;
509 >        }
510 >      }
511 >      
512 >    } //isMC
513 >    //
514 >
515 >
516 >    hbbInfo->simpleJets3.push_back(sj);
517 >    
518 >  }
519 >
520 > #ifdef ENABLE_SIMPLEJETS4
521 >  for(edm::View<pat::Jet>::const_iterator jet_iter = simplejets4.begin(); jet_iter!=simplejets4.end(); ++jet_iter){
522 >    //     if(jet_iter->pt()>50)
523 >    //       njetscounter++;
524 >    VHbbEvent::SimpleJet sj;
525 >    //    std::cout <<" sj4"<<std::endl;
526 >    fillSimpleJet(sj,jet_iter);
527 >    //    if(!runOnMC_)  
528 >    setJecUnc(sj,jecUnc);
529 >
530 >
531 >    Particle::LorentzVector p4Jet = jet_iter->p4();
532 >
533 >    if(runOnMC_){
534 >
535 >      fillScaleFactors(sj, btagSFs);
536 >
537 >      //PAT genJet matching
538 >      //genJet
539 >      const reco::GenJet *gJ = jet_iter->genJet();
540 >      //physical parton for mother info ONLY
541 >      if( (jet_iter->genParton()) ){
542 >        sj.bestMCid = jet_iter->genParton()->pdgId();
543 >        if( (jet_iter->genParton()->mother()) )
544 >          sj.bestMCmomid=jet_iter->genParton()->mother()->pdgId();
545 >      }
546 >      TLorentzVector gJp4;
547 >      if(gJ){
548 >        gJp4.SetPtEtaPhiE(gJ->pt(),gJ->eta(),gJ->phi(),gJ->energy());
549 >        sj.bestMCp4 = gJp4;
550 >        if(verbose_){
551 >          std::clog << "genJet matched Pt = " << gJp4.Pt() << std::endl;
552 >          std::clog << "genJet matched eta = " << gJp4.Eta() << std::endl;
553 >          std::clog << "genJet matched deltaR = " <<gJp4.DeltaR(sj.p4) << std::endl;
554 >          std::clog << "genJet matched mother id = " << sj.bestMCmomid << std::endl;
555 >        }
556 >      }
557 >      
558 >    } //isMC
559 >    hbbInfo->simpleJets4.push_back(sj);
560 >    
561 >  }
562 > #endif //ENABLE SIMPLEJETS4
563 >
564    
565    for(edm::View<pat::Jet>::const_iterator jet_iter = simplejets2.begin(); jet_iter!=simplejets2.end(); ++jet_iter){
566      
567      VHbbEvent::SimpleJet sj;
568 <    sj.flavour = jet_iter->partonFlavour();
568 >    //    std::cout <<" sj2"<<std::endl;
569 >    fillSimpleJet(sj,jet_iter);    
570 >    //  if(!runOnMC_)  
571 > setJecUnc(sj,jecUnc);
572 >    /*    sj.flavour = jet_iter->partonFlavour();
573      
574      
575      sj.tche=jet_iter->bDiscriminator("trackCountingHighEffBJetTags");
# Line 561 | Line 581 | HbbAnalyzerNew::produce(edm::Event& iEve
581      sj.csvmva=jet_iter->bDiscriminator("combinedSecondaryVertexMVABJetTags");
582      sj.charge=jet_iter->jetCharge();
583      sj.ntracks=jet_iter->associatedTracks().size();
584 <    sj.fourMomentum=GENPTOLORP(jet_iter);
584 >    sj.p4=GENPTOLORP(jet_iter);
585 >    sj.chargedTracksFourMomentum=(getChargedTracksMomentum(&*(jet_iter)));
586 >    sj.SF_CSVL=1;
587 >    sj.SF_CSVM=1;
588 >    sj.SF_CSVT=1;
589 >    sj.SF_CSVLerr=0;
590 >    sj.SF_CSVMerr=0;
591 >    sj.SF_CSVTerr=0;
592 >
593 >    //
594 >    // addtaginfo for csv
595 >    //
596 >
597 >    if (jet_iter->hasTagInfo("SimpleSecondaryVertex")) {
598 >
599 >      const reco::SecondaryVertexTagInfo * tf = jet_iter->tagInfoSecondaryVertex();
600 >      sj.vtxMass = tf->secondaryVertex(0).p4().mass();
601 >      sj.vtxNTracks = tf->secondaryVertex(0).nTracks();
602 >      Measurement1D m = tf->flightDistance(0);
603 >      sj.vtx3dL = m.value();
604 >      sj.vtx3deL = m.error();
605 >    }
606 >
607  
608 +    //
609 +    // add tVector
610 +    //
611 +    sj.tVector = getTvect(&(*jet_iter));
612 +    */
613      Particle::LorentzVector p4Jet = jet_iter->p4();
614  
615      if(runOnMC_){
616 <      double minb2DR=9999.;
617 <      for(size_t i = 0; i < genParticles->size(); ++ i) {
618 <        const GenParticle & p = (*genParticles)[i];
619 <        int id = p.pdgId();
620 <        if(abs(id)<=6 || id==21 || id==23 || abs(id)==24){
621 <          double bb2DR=TMath::Sqrt((p.eta()-p4Jet.eta())*(p.eta()-p4Jet.eta())+
622 <                                   (p.phi()-p4Jet.phi())*(p.phi()-p4Jet.phi()));
623 <          if(bb2DR<minb2DR) {minb2DR=bb2DR; sj.b1BestMCid=id; if(p.mother()!=0) sj.b1BestMCmomid=p.mother()->pdgId();}
616 >
617 >      //BTV scale factors
618 >      fillScaleFactors(sj, btagSFs);
619 >
620 >      //PAT genJet matching
621 >      //genJet
622 >      const reco::GenJet *gJ = jet_iter->genJet();
623 >      //physical parton for mother info ONLY
624 >      if( (jet_iter->genParton()) ){
625 >        sj.bestMCid = jet_iter->genParton()->pdgId();
626 >        if( (jet_iter->genParton()->mother()) )
627 >          sj.bestMCmomid=jet_iter->genParton()->mother()->pdgId();
628 >      }
629 >      TLorentzVector gJp4;
630 >      if(gJ){
631 >        gJp4.SetPtEtaPhiE(gJ->pt(),gJ->eta(),gJ->phi(),gJ->energy());
632 >        sj.bestMCp4 = gJp4;
633 >        if(verbose_){
634 >          std::clog << "genJet matched Pt = " << gJp4.Pt() << std::endl;
635 >          std::clog << "genJet matched eta = " << gJp4.Eta() << std::endl;
636 >          std::clog << "genJet matched deltaR = " << gJp4.DeltaR(sj.p4) << std::endl;
637 >          std::clog << "genJet matched mother id = " << sj.bestMCmomid << std::endl;
638          }
639        }
640 <    }   //isMC
640 >
641 >        // add flag if a mc lepton is find inside a cone around the jets...
642 >      iEvent.getByLabel("genParticles", genParticles);
643 >      
644 >      for(size_t i = 0; i < genParticles->size(); ++ i) {
645 >    
646 >      const GenParticle & p = (*genParticles)[i];
647 >      int id = 0;
648 >      p.pt()> lep_ptCutForBjets_ ? id= p.pdgId(): 0;
649 >  
650 >      //      std::cout<< "found a muon with pt " << mu->pt()   << std::endl;
651 >      if   ((abs(id)==13 || abs(id)==11) && deltaR(p.eta(), p.phi(), sj.p4.Eta(), sj.p4.Phi() ) <0.3)  sj.isSemiLeptMCtruth=1;
652 >      }
653 >
654 >    }  //isMC
655 >        // add flag if a reco lepton is find inside a cone around the jets...
656 >    edm::Handle<edm::View<reco::Candidate> > muonNoCutsHandle;
657 >    iEvent.getByLabel(muonoCutsLabel_,muonNoCutsHandle);
658 >    edm::View<reco::Candidate> muonsNoCuts = *muonNoCutsHandle;
659 >    
660 >
661 >    for(edm::View<reco::Candidate>::const_iterator mu = muonsNoCuts.begin(); mu!=muonsNoCuts.end() && sj.isSemiLept!=1; ++mu){
662 >      //      std::cout<< "found a muon with pt " << mu->pt()   << std::endl;
663 >      if   ( (mu->pt()> lep_ptCutForBjets_) && deltaR(mu->eta(), mu->phi(), sj.p4.Eta(), sj.p4.Phi() ) <0.3)  sj.isSemiLept=1;
664 >    }
665 >    
666 >    edm::Handle<edm::View<reco::Candidate> > electronNoCutsHandle;
667 >      iEvent.getByLabel(elenoCutsLabel_,electronNoCutsHandle);
668 >      edm::View<reco::Candidate> electronsNoCuts = *electronNoCutsHandle;
669 >      for(edm::View<reco::Candidate>::const_iterator ele = electronsNoCuts.begin(); ele!=electronsNoCuts.end() && sj.isSemiLept!=1; ++ele){
670 >        if   ( (ele->pt()> lep_ptCutForBjets_) && deltaR(ele->eta(), ele->phi(), sj.p4.Eta(), sj.p4.Phi() ) <0.3)  sj.isSemiLept=1;
671 >        //  std::cout<< " found an electron with pt " << ele->pt()   << std::endl;
672 >      }  
673 >
674 >    
675      
676      hbbInfo->simpleJets2.push_back(sj);
677      
# Line 613 | Line 708 | HbbAnalyzerNew::produce(edm::Event& iEve
708      //    if(printJet) {std::cout << "NsubJets: " << constituents.size() << "\n";}
709      VHbbEvent::HardJet hj;
710      hj.constituents=constituents.size();
711 <    hj.fourMomentum =GENPTOLORP(jet_iter);
712 <
711 >    hj.p4 =GENPTOLORP(jet_iter);
712 >    
713      for (unsigned int iJC(0); iJC<constituents.size(); ++iJC ){
714        Jet::Constituent icandJet = constituents[iJC];
715  
# Line 625 | Line 720 | HbbAnalyzerNew::produce(edm::Event& iEve
720        hj.subFourMomentum.push_back(GENPTOLORP(icandJet));
721        hj.etaSub.push_back(icandJet->eta());
722        hj.phiSub.push_back(icandJet->phi());
628
723      
724      }
725      hbbInfo->hardJets.push_back(hj);
# Line 648 | Line 742 | HbbAnalyzerNew::produce(edm::Event& iEve
742                              << "," << subjet_iter->bDiscriminator("combinedSecondaryVertexBJetTags") << "\n";}
743  
744      VHbbEvent::SimpleJet sj;
745 <
746 <    sj.flavour = subjet_iter->partonFlavour();
747 <    
745 >    //    std::cout <<" sub jet "<<std::endl;
746 >    fillSimpleJet(sj,subjet_iter);
747 >    //  if(!runOnMC_)  
748 >    setJecUnc(sj,jecUnc);
749 >    /*    sj.flavour = subjet_iter->partonFlavour();
750 >    sj.tVector = getTvect(&(*subjet_iter));
751      sj.tche=subjet_iter->bDiscriminator("trackCountingHighEffBJetTags");
752      sj.tchp=subjet_iter->bDiscriminator("trackCountingHighPurBJetTags");
753      sj.jp=subjet_iter->bDiscriminator("jetProbabilityBJetTags");
# Line 660 | Line 757 | HbbAnalyzerNew::produce(edm::Event& iEve
757      sj.csvmva=subjet_iter->bDiscriminator("combinedSecondaryVertexMVABJetTags");
758      sj.charge=subjet_iter->jetCharge();
759      sj.ntracks=subjet_iter->associatedTracks().size();
760 <    sj.fourMomentum=GENPTOLORP(subjet_iter);
760 >    sj.p4=GENPTOLORP(subjet_iter);
761 >    sj.p4=(getChargedTracksMomentum(&*(subjet_iter)));
762  
763 +    //
764 +    // addtaginfo for csv
765 +    //
766 +
767 +    if (subjet_iter->hasTagInfo("SimpleSecondaryVertex")) {
768 +
769 +      const reco::SecondaryVertexTagInfo * tf = subjet_iter->tagInfoSecondaryVertex();
770 +      sj.vtxMass = tf->secondaryVertex(0).p4().mass();
771 +      sj.vtxNTracks = tf->secondaryVertex(0).nTracks();
772 +      Measurement1D m = tf->flightDistance(0);
773 +      sj.vtx3dL = m.value();
774 +      sj.vtx3deL = m.error();
775 +    }
776 +    */
777      hbbInfo->subJets.push_back(sj);
778  
779    }
780  
781 +  for(edm::View<pat::Jet>::const_iterator filterjet_iter = filterjets.begin(); filterjet_iter!=filterjets.end(); ++filterjet_iter){
782 +
783 +    if(printJet) {std::cout << "FilterjetTagged Pt: " << filterjet_iter->pt() << " E,M,eta,phi,Btag: " << filterjet_iter->p4().E()  << "," << filterjet_iter->p4().M() << "," << filterjet_iter->eta() << "," << filterjet_iter->phi()  << "," << filterjet_iter->bDiscriminator("combinedSecondaryVertexBJetTags") << "\n";}
784 +
785 +    VHbbEvent::SimpleJet fj;
786 +    //    std::cout <<" sub jet "<<std::endl;
787 +    fillSimpleJet(fj,filterjet_iter);
788 +    //  if(!runOnMC_)  
789 +    setJecUnc(fj,jecUnc);
790  
791 <  //
792 <  // met is calomet
672 <  //
791 >    hbbInfo->filterJets.push_back(fj);
792 >    
793  
794 +  }
795  
796 <  for(edm::View<pat::MET>::const_iterator met = mets.begin(); met!=mets.end(); ++met){
797 <    hbbInfo->calomet.sumEt=met->sumEt();
798 <    hbbInfo->calomet.metSig=met->mEtSig();
799 <    hbbInfo->calomet.eLong=met->e_longitudinal();
800 <    hbbInfo->calomet.fourMomentum=GENPTOLORP(met);
796 >  //
797 >  // add charged met
798 >  //
799 >  
800 >  edm::Handle<edm::View<reco::MET> > metChargedHandle;
801 >  iEvent.getByLabel("pfMETNoPUCharge",metChargedHandle);
802 >  edm::View<reco::MET> metsCh = *metChargedHandle;
803 >  if(metsCh.size()){
804 >    hbbInfo->metCh.sumEt=(metsCh[0]).sumEt();
805 >    hbbInfo->metCh.metSig=metSignificance(& (metsCh[0]));
806 >    hbbInfo->metCh.eLong=(metsCh[0]).e_longitudinal();
807 >    hbbInfo->metCh.p4=GENPTOLOR((metsCh[0]));
808 >    if (verbose_)     std::cout <<" METCharged "<<     hbbInfo->metCh.metSig <<" " <<     hbbInfo->metCh.sumEt<<std::endl;
809    }
810  
811 +  //
812 +  // met is calomet
813 +  //
814 +
815    edm::Handle<edm::View<pat::MET> > metTCHandle;
816    iEvent.getByLabel("patMETsTC",metTCHandle);
817    edm::View<pat::MET> metsTC = *metTCHandle;
818 <  for(edm::View<pat::MET>::const_iterator metTC = metsTC.begin(); metTC!=metsTC.end(); ++metTC){
819 <    hbbInfo->calomet.sumEt=metTC->sumEt();
820 <    hbbInfo->calomet.metSig=metTC->mEtSig();
821 <    hbbInfo->calomet.eLong=metTC->e_longitudinal();
822 <    hbbInfo->calomet.fourMomentum=GENPTOLORP(metTC);
818 >  if(metsTC.size()){
819 >    hbbInfo->tcmet.sumEt=(metsTC[0]).sumEt();
820 >    hbbInfo->tcmet.metSig=metSignificance(&(metsTC[0]));
821 >    hbbInfo->tcmet.eLong=(metsTC[0]).e_longitudinal();
822 >    hbbInfo->tcmet.p4=GENPTOLOR((metsTC[0]));
823 >    if (verbose_)     std::cout <<" METTC "<<     hbbInfo->tcmet.metSig <<" " <<     hbbInfo->tcmet.sumEt<<std::endl;
824 >  }
825 >  
826 >  edm::Handle<edm::View<reco::MET> > pfMETNoPUHandle;
827 >  iEvent.getByLabel("pfMETNoPU",pfMETNoPUHandle);
828 >  edm::View<reco::MET> metspfMETNoPU = *pfMETNoPUHandle;
829 >  if(metspfMETNoPU.size()){
830 >    hbbInfo->metNoPU.sumEt=(metspfMETNoPU[0]).sumEt();
831 >    hbbInfo->metNoPU.metSig=metSignificance(&(metspfMETNoPU[0]));                
832 >    hbbInfo->metNoPU.eLong=(metspfMETNoPU[0]).e_longitudinal();
833 >    hbbInfo->metNoPU.p4=GENPTOLOR((metspfMETNoPU[0]));
834 >    if (verbose_)     std::cout <<" pfMETNoPU "<<     hbbInfo->metNoPU.metSig <<" " <<     hbbInfo->metNoPU.sumEt<<std::endl;
835 >  }
836 >
837 >  edm::Handle<edm::View<reco::MET> > mHTHandle;
838 >  iEvent.getByLabel("patMETsHT",mHTHandle);
839 >  edm::View<reco::MET> metsHT = *mHTHandle;
840 >  if(metsHT.size()){
841 >    hbbInfo->mht.sumEt=(metsHT[0]).sumEt();
842 >    hbbInfo->mht.metSig=metSignificance(&(metsHT[0]));
843 >    hbbInfo->mht.eLong=(metsHT[0]).e_longitudinal();
844 >    hbbInfo->mht.p4=GENPTOLOR((metsHT[0]));
845 >    if (verbose_)     std::cout <<" METHT "<<     hbbInfo->mht.metSig <<" " <<     hbbInfo->mht.sumEt<<std::endl;
846 >  }
847 >  
848 >  edm::Handle<edm::View<reco::MET> > metHandle;
849 >  iEvent.getByLabel(metLabel_,metHandle);
850 >  edm::View<reco::MET> mets = *metHandle;
851 >  
852 >  if(mets.size()){
853 >    hbbInfo->calomet.sumEt=(mets[0]).sumEt();
854 >    hbbInfo->calomet.metSig=metSignificance(&(mets[0]));
855 >    hbbInfo->calomet.eLong=(mets[0]).e_longitudinal();
856 >    hbbInfo->calomet.p4=GENPTOLOR((mets[0]));
857 >    if (verbose_)     std::cout <<" METCALO "<<     hbbInfo->calomet.metSig <<" " <<     hbbInfo->calomet.sumEt<<std::endl;
858    }
859 +  
860    edm::Handle<edm::View<pat::MET> > metPFHandle;
861    iEvent.getByLabel("patMETsPF",metPFHandle);
862    edm::View<pat::MET> metsPF = *metPFHandle;
863 <  for(edm::View<pat::MET>::const_iterator metPF = metsPF.begin(); metPF!=metsPF.end(); ++metPF){
864 <    hbbInfo->calomet.sumEt=metPF->sumEt();
865 <    hbbInfo->calomet.metSig=metPF->mEtSig();
866 <    hbbInfo->calomet.eLong=metPF->e_longitudinal();
867 <    hbbInfo->calomet.fourMomentum=GENPTOLORP(metPF);
863 >  
864 >  if(metsPF.size()){
865 >    hbbInfo->pfmet.sumEt=(metsPF[0]).sumEt();
866 >    hbbInfo->pfmet.metSig=metSignificance(&(metsPF[0]));
867 >    hbbInfo->pfmet.eLong=(metsPF[0]).e_longitudinal();
868 >    hbbInfo->pfmet.p4=GENPTOLOR((metsPF[0]));
869 >    if (verbose_)     std::cout <<" METPF "<<     hbbInfo->pfmet.metSig <<" " <<     hbbInfo->pfmet.sumEt<<std::endl;
870 >  }
871 >  
872 >  
873 >  if(verbose_){
874 >    std::cout << "METs: calomet "<<mets.size()<<" tcmet"<<metsTC.size()<<" pfmet "<<metsPF.size()<<" MHT" <<metsHT.size()<<std::endl;  
875    }
876  
877 <
877 >  if(verbose_)
878 >    std::cout << " INPUT MUONS "<<muons.size()<<std::endl;
879  
880    for(edm::View<pat::Muon>::const_iterator mu = muons.begin(); mu!=muons.end(); ++mu){
881      VHbbEvent::MuonInfo mf;
882 <    mf.fourMomentum =GENPTOLORP( mu);
882 >    mf.p4 =GENPTOLORP( mu);
883      mf.charge=mu->charge();
884      mf.tIso=mu->trackIso();
885      mf.eIso=mu->ecalIso();
886      mf.hIso=mu->hcalIso();
887 <    Geom::Phi<double> deltaphi(mu->phi()-atan2(mf.fourMomentum.Px(), mf.fourMomentum.Py()));
887 >    mf.pfChaIso=mu->chargedHadronIso();
888 >    mf.pfChaPUIso=mu->userIso(5);
889 >    mf.pfPhoIso=mu->photonIso();
890 >    mf.pfNeuIso=mu->neutralHadronIso();
891 >    Geom::Phi<double> deltaphi(mu->phi()-atan2(mf.p4.Px(), mf.p4.Py()));
892      double acop = deltaphi.value();
893      mf.acop=acop;
894  
895 +    mf.emEnergy = mu->calEnergy().em;
896 +    mf.hadEnergy = mu->calEnergy().had;
897 +
898 +    mf.nMatches = mu->numberOfMatches();
899 +
900      mf.ipDb=mu->dB();
901      mf.ipErrDb=mu->edB();
902 <    if(mu->isGlobalMuon()) mf.cat=1;
903 <    else if(mu->isTrackerMuon()) mf.cat=2;
904 <    else mf.cat=3;
902 >    mf.cat=0;
903 >    if(mu->isGlobalMuon()) mf.cat|=1;
904 >    if(mu->isTrackerMuon()) mf.cat|=2;
905 >    if(mu->isStandAloneMuon()) mf.cat|=4;
906      TrackRef trkMu1Ref = mu->get<TrackRef>();
907      if(trkMu1Ref.isNonnull()){
908        const Track* MuTrk1 = mu->get<TrackRef>().get();
# Line 726 | Line 913 | HbbAnalyzerNew::produce(edm::Event& iEve
913        TrackRef iTrack1 = mu->innerTrack();
914        const reco::HitPattern& p1 = iTrack1->hitPattern();
915        mf.nPixelHits=p1.pixelLayersWithMeasurement();
916 <    }
916 >
917 >      mf.nValidTracker = p1.numberOfValidTrackerHits();
918 >      mf.nValidPixel = p1.numberOfValidPixelHits();
919 >
920 >
921 >
922 >   }
923      if(mu->isGlobalMuon()){
924        TrackRef gTrack = mu->globalTrack();
925        const reco::HitPattern& q = gTrack->hitPattern();
926        mf.globChi2=gTrack.get()->normalizedChi2();
927        mf.globNHits=q.numberOfValidMuonHits();
928 +      mf.validMuStations = q.muonStationsWithValidHits();
929      }else{
930        mf.globChi2=-99;
931        mf.globNHits=-99;
932      }
933  
934 +    //Muon trigger matching
935 +    for (int itrig = 0; itrig != ntrigs; ++itrig){
936 +      std::string trigName=triggerNames_.triggerName(itrig);
937 +      if( (mu->triggerObjectMatchesByPath(trigName,false,false).size() != 0) ){
938 +        mf.hltMatchedBits.push_back(itrig);
939 +        if(verbose_){
940 +          std::clog << "Trigger Matching box" << std::endl;
941 +          std::clog << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
942 +          std::clog << "Matching parameters are defined in the cfg" << std::endl;
943 +          std::clog << "Trigger bit = " << itrig << std::endl;
944 +          std::clog << "Trigger name = " << trigName << std::endl;
945 +          std::clog << "Trigger object matched collection size = " << mu->triggerObjectMatchesByPath(trigName,false,false).size() << std::endl;
946 +          std::clog << "Pat Muon pt = " << mf.p4.Pt() << " HLT object matched = " << mu->triggerObjectMatch(0)->p4().Pt() << std::endl;
947 +          std::clog << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
948 +        }
949 +      }
950 +    }
951 +    //
952 +
953 +    // add stamuon
954 +
955 +    //    if (mu->isStandAloneMuon()) {
956 +    //      reco::TrackRef sta = mu->standAloneMuon();
957 +    //      
958 +    //    }
959 +
960 +
961      //     int muInfo[12];
962      //     fillMuBlock(mu,  muInfo);
963      if(runOnMC_){
# Line 750 | Line 971 | HbbAnalyzerNew::produce(edm::Event& iEve
971      hbbInfo->muInfo.push_back(mf);
972    }
973  
974 <
974 > if(verbose_)
975 >    std::cout << " INPUT electrons "<<electrons.size()<<std::endl;
976    for(edm::View<pat::Electron>::const_iterator elec = electrons.begin(); elec!=electrons.end(); ++elec){
977      VHbbEvent::ElectronInfo ef;
978 <    ef.fourMomentum=GENPTOLORP(elec);
978 >    ef.p4=GENPTOLORP(elec);
979      ef.scEta =elec->superCluster()->eta();
980      ef.scPhi =elec->superCluster()->phi();
981      //    if(ElecEta[eleccont]!=0) ElecEt[eleccont]=elec->superCluster()->energy()/cosh(elec->superCluster()->eta());
# Line 761 | Line 983 | HbbAnalyzerNew::produce(edm::Event& iEve
983      ef.tIso=elec->trackIso();
984      ef.eIso=elec->ecalIso();
985      ef.hIso=elec->hcalIso();
986 <    Geom::Phi<double> deltaphi(elec->superCluster()->phi()-atan2(hbbInfo->calomet.fourMomentum.Py(),hbbInfo->calomet.fourMomentum.Px()));
987 <    ef.acop = deltaphi.value();
986 >    ef.pfChaIso=elec->chargedHadronIso();
987 >    ef.pfChaPUIso=elec->userIso(5);
988 >    ef.pfPhoIso=elec->photonIso();
989 >    ef.pfNeuIso=elec->neutralHadronIso();
990 >
991 >    //
992 >    // ip info
993 >    //
994 >
995 >    ef.ipDb=elec->dB();
996 >    ef.ipErrDb=elec->edB();
997      
998 +
999 +
1000 +    Geom::Phi<double> deltaphi(elec->superCluster()->phi()-atan2(hbbInfo->pfmet.p4.Py(),hbbInfo->pfmet.p4.Px()));
1001 +    ef.acop = deltaphi.value();
1002 +    //
1003 +    ef.sihih = elec->sigmaIetaIeta();
1004 +    ef.Dphi = elec->deltaPhiSuperClusterTrackAtVtx();
1005 +    ef.Deta = elec->deltaEtaSuperClusterTrackAtVtx();
1006 +    ef.HoE = elec->hadronicOverEm();
1007 +    ef.convDist = elec->convDist();
1008 +    ef.convDcot = elec->convDcot();
1009 +    if(elec->gsfTrack().isNonnull()) ef.innerHits = elec->gsfTrack()->trackerExpectedHitsInner().numberOfHits();  
1010 +    ef.isEB = elec->isEB();
1011 +    ef.isEE = elec->isEE();
1012 +    //
1013 +    // fill eleids
1014 +    //    
1015 + /*    ef.id95 = elec->electronID("simpleEleId95cIso");
1016 +    ef.id85 = elec->electronID("simpleEleId85cIso");
1017 +    ef.id70 = elec->electronID("simpleEleId70cIso");
1018 +    ef.id95r = elec->electronID("simpleEleId95relIso");
1019 +    ef.id70r = elec->electronID("simpleEleId70relIso");
1020 +    ef.id85r = elec->electronID("simpleEleId85relIso");
1021 + */
1022 +    ef.id95 =elec->electronID("eidVBTFCom95");
1023 +    ef.id95r=elec->electronID("eidVBTFRel95");
1024 +    ef.id85 =elec->electronID("eidVBTFCom85");
1025 +    ef.id85r=elec->electronID("eidVBTFRel85");
1026 +    ef.id80 =elec->electronID("eidVBTFCom80");
1027 +    ef.id80r=elec->electronID("eidVBTFRel80");
1028 +    ef.id70 =elec->electronID("eidVBTFCom70");
1029 +    ef.id70r=elec->electronID("eidVBTFRel70");
1030 +
1031 +    //Electron trigger matching
1032 +    for (int itrig = 0; itrig != ntrigs; ++itrig){
1033 +      std::string trigName=triggerNames_.triggerName(itrig);
1034 +      if( (elec->triggerObjectMatchesByPath(trigName).size() != 0) ){
1035 +        ef.hltMatchedBits.push_back(itrig);
1036 +        if(verbose_){
1037 +          std::clog << "Trigger Matching box" << std::endl;
1038 +          std::clog << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
1039 +          std::clog << "Matching parameters are defined in the cfg" << std::endl;
1040 +          std::clog << "Trigger bit = " << itrig << std::endl;
1041 +          std::clog << "Trigger name = " << trigName << std::endl;
1042 +          std::clog << "Trigger object matched collection size = " << elec->triggerObjectMatchesByPath(trigName).size() << std::endl;
1043 +          std::clog << "Pat Electron pt = " << ef.p4.Pt() << " HLT object matched = " << elec->triggerObjectMatch(0)->p4().Pt() << std::endl;
1044 +          std::clog << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
1045 +        }
1046 +      }
1047 +    }
1048 +
1049      if(runOnMC_){
1050        const GenParticle* elecMc = elec->genLepton();
1051        if(elecMc!=0){
# Line 775 | Line 1057 | HbbAnalyzerNew::produce(edm::Event& iEve
1057      hbbInfo->eleInfo.push_back(ef);
1058    }
1059  
1060 +  if(verbose_)
1061 +    std::cout << " INPUT taus "<<taus.size()<<std::endl;
1062    for(edm::View<pat::Tau>::const_iterator tau = taus.begin(); tau!=taus.end(); ++tau){
1063      VHbbEvent::TauInfo tf;
1064 <    tf.fourMomentum=GENPTOLORP(tau);
1064 >    tf.p4=GENPTOLORP(tau);
1065      tf.charge=tau->charge();
1066      tf.tIso=tau->trackIso();
1067      tf.eIso=tau->ecalIso();
1068      tf.hIso=tau->hcalIso();
1069 <    Geom::Phi<double> deltaphi(tau->phi()-atan2(hbbInfo->calomet.fourMomentum.Py(),hbbInfo->calomet.fourMomentum.Px()));
1069 >    Geom::Phi<double> deltaphi(tau->phi()-atan2(hbbInfo->pfmet.p4.Py(),hbbInfo->pfmet.p4.Px()));
1070      double acop = deltaphi.value();
1071      tf.acop=acop;
1072 <    tf.idbyIso=tau->tauID("byIsolation");
1073 <    tf.idbyTrackIso=tau->tauID("trackIsolation");
1074 <    tf.idbyTaNCfrOnePercent=tau->tauID("byTaNCfrOnePercent");
1075 <    tf.idbyTaNCfrHalfPercent=tau->tauID("byTaNCfrHalfPercent");
1076 <    tf.idbyTaNCfrQuarterPercent=tau->tauID("byTaNCfrQuarterPercent");
1077 <    tf.idbyTaNCfrTenthPercent=tau->tauID("byTaNCfrTenthPercent");  
1078 <    tf.idbyTaNC=tau->tauID("byTaNC");
1072 >    if (tau->isTauIDAvailable("againstElectronLoose")) tf.idagainstElectronLoose=tau->tauID("againstElectronLoose");
1073 >    if (tau->isTauIDAvailable("againstElectronMedium")) tf.idagainstElectronMedium=tau->tauID("againstElectronMedium");
1074 >    if (tau->isTauIDAvailable("againstElectronTight")) tf.idagainstElectronTight=tau->tauID("againstElectronTight");
1075 >    if (tau->isTauIDAvailable("againstMuonLoose")) tf.idagainstMuonLoose=tau->tauID("againstMuonLoose");
1076 >    if (tau->isTauIDAvailable("againstMuonTight")) tf.idagainstMuonTight=tau->tauID("againstMuonTight");
1077 >    if (tau->isTauIDAvailable("byLooseIsolation")) tf.idbyLooseIsolation=tau->tauID("byLooseIsolation");
1078 >    if (tau->isTauIDAvailable("byMediumIsolation")) tf.idbyMediumIsolation=tau->tauID("byMediumIsolation");
1079 >    if (tau->isTauIDAvailable("byTightIsolation")) tf.idbyTightIsolation=tau->tauID("byTightIsolation");
1080 >    if (tau->isTauIDAvailable("byVLooseIsolation")) tf.idbyVLooseIsolation=tau->tauID("byVLooseIsolation");
1081 >    if (tau->isTauIDAvailable("decayModeFinding")) tf.iddecayModeFinding=tau->tauID("decayModeFinding");
1082 >    if (tau->isTauIDAvailable("byIsolation")) tf.idbyIso=tau->tauID("byIsolation");
1083 >    if (tau->isTauIDAvailable("trackIsolation")) tf.idbyTrackIso=tau->tauID("trackIsolation");
1084 >    if (tau->isTauIDAvailable("byTaNCfrOnePercent")) tf.idbyTaNCfrOnePercent=tau->tauID("byTaNCfrOnePercent");
1085 >    if (tau->isTauIDAvailable("byTaNCfrHalfPercent")) tf.idbyTaNCfrHalfPercent=tau->tauID("byTaNCfrHalfPercent");
1086 >    if (tau->isTauIDAvailable("byTaNCfrQuarterPercent")) tf.idbyTaNCfrQuarterPercent=tau->tauID("byTaNCfrQuarterPercent");
1087 >    if (tau->isTauIDAvailable("byTaNCfrTenthPercent")) tf.idbyTaNCfrTenthPercent=tau->tauID("byTaNCfrTenthPercent");
1088 >    if (tau->isTauIDAvailable("byTaNC")) tf.idbyTaNC=tau->tauID("byTaNC");
1089 >    if (tau->isPFTau()) {
1090 >      tf.isolationPFChargedHadrCandsPtSum = tau->isolationPFChargedHadrCandsPtSum();
1091 >      tf.isolationPFGammaCandsEtSum = tau->isolationPFGammaCandsEtSum();
1092 >      if (tau->leadPFChargedHadrCand().isAvailable()) tf.leadPFChargedHadrCandPt = tau->leadPFChargedHadrCand()->pt();
1093 >      tf.NsignalPFChargedHadrCands = tau->signalPFChargedHadrCands().size();
1094 >      tf.NsignalPFGammaCands = tau->signalPFGammaCands().size();
1095 >    }
1096      hbbInfo->tauInfo.push_back(tf);
1097 +    if (verbose_) {
1098 +      std::cout << "SCZ DEBUG: againstElectronLoose is " << tf.idagainstElectronLoose << std::endl;
1099 +      std::cout << "SCZ DEBUG: againstElectronMedium is " << tf.idagainstElectronMedium << std::endl;
1100 +      std::cout << "SCZ DEBUG: againstElectronTight is " << tf.idagainstElectronTight << std::endl;
1101 +      std::cout << "SCZ DEBUG: againstMuonLoose is " << tf.idagainstMuonLoose << std::endl;
1102 +      std::cout << "SCZ DEBUG: againstMuonTight is " << tf.idagainstMuonTight << std::endl;
1103 +      std::cout << "SCZ DEBUG: byLooseIsolation is " << tf.idbyLooseIsolation << std::endl;
1104 +      std::cout << "SCZ DEBUG: byMediumIsolation is " << tf.idbyMediumIsolation << std::endl;
1105 +      std::cout << "SCZ DEBUG: byTightIsolation is " << tf.idbyTightIsolation << std::endl;
1106 +      std::cout << "SCZ DEBUG: byVLooseIsolation is " << tf.idbyVLooseIsolation << std::endl;
1107 +      std::cout << "SCZ DEBUG: decayModeFinding is " << tf.iddecayModeFinding << std::endl;
1108 +      std::cout << "SCZ DEBUG: byIsolation is " << tf.idbyIso<< std::endl;
1109 +      std::cout << "SCZ DEBUG: trackIsolation is " << tf.idbyTrackIso << std::endl;
1110 +      std::cout << "SCZ DEBUG: byTaNCfrOnePercent is " << tf.idbyTaNCfrOnePercent << std::endl;
1111 +      std::cout << "SCZ DEBUG: byTaNCfrHalfPercent is " << tf.idbyTaNCfrHalfPercent << std::endl;
1112 +      std::cout << "SCZ DEBUG: byTaNCfrQuarterPercent is " << tf.idbyTaNCfrQuarterPercent << std::endl;
1113 +      std::cout << "SCZ DEBUG: byTaNCfrTenthPercent is " << tf.idbyTaNCfrTenthPercent << std::endl;
1114 +      std::cout << "SCZ DEBUG: byTaNC is " << tf.idbyTaNC << std::endl;
1115 +      std::cout << "SCZ DEBUG: isolationPFChargedHadrCandsPtSum is " << tf.isolationPFChargedHadrCandsPtSum << std::endl;
1116 +      std::cout << "SCZ DEBUG: isolationPFGammaCandsEtSum is " << tf.isolationPFGammaCandsEtSum << std::endl;
1117 +      std::cout << "SCZ DEBUG: isolationPFGammaCandsEtSum is " << tf.leadPFChargedHadrCandPt << std::endl;
1118 +      std::cout << "SCZ DEBUG: NsignalPFChargedHadrCands is " << tf.NsignalPFChargedHadrCands << std::endl;
1119 +      std::cout << "SCZ DEBUG: NsignalPFGammaCands is " << tf.NsignalPFGammaCands << std::endl;
1120 +    }
1121    }
1122  
1123 +  CompareJetPtMuons ptComparatorMu;
1124 +  CompareJetPtElectrons ptComparatorE;
1125 +  CompareJetPtTaus ptComparatorTau;
1126 +
1127 +  std::sort(hbbInfo->muInfo.begin(), hbbInfo->muInfo.end(), ptComparatorMu);
1128 +  std::sort(hbbInfo->eleInfo.begin(), hbbInfo->eleInfo.end(), ptComparatorE);
1129 +  std::sort(hbbInfo->tauInfo.begin(), hbbInfo->tauInfo.end(), ptComparatorTau);
1130  
799  // dimuons and dielectrons
800
801  for( size_t i = 0; i < dimuons->size(); i++ ) {
802    VHbbEvent::DiMuonInfo df;
803    const Candidate & dimuonCand = (*dimuons)[ i ];
804    df.fourMomentum= GENPTOLOR(dimuonCand);
805    const Candidate * lep0 = dimuonCand.daughter( 0 );
806    const Candidate * lep1 = dimuonCand.daughter( 1 );
807    // needed to access specific methods of pat::Muon
808    const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
809    const pat::Muon & muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
810    
811    df.daughter1.fourMomentum=GENPTOLOR(muonDau0);
812    df.daughter2.fourMomentum=GENPTOLOR(muonDau1);
813    
814    df.daughter1.tIso= muonDau0.trackIso();
815    df.daughter2.tIso= muonDau1.trackIso();
816
817    df.daughter1.eIso= muonDau0.ecalIso();
818    df.daughter2.eIso= muonDau1.ecalIso();
819
820    df.daughter1.hIso= muonDau0.hcalIso();
821    df.daughter2.hIso= muonDau1.hcalIso();
822
823    df.daughter1.ipDb=muonDau0.dB();
824    df.daughter2.ipDb=muonDau1.dB();
825
826    df.daughter1.ipErrDb=muonDau0.edB();
827    df.daughter2.ipErrDb=muonDau1.edB();
828
829
830    if(muonDau0.isGlobalMuon()) df.daughter1.cat =1;
831    else if(muonDau0.isTrackerMuon()) df.daughter1.cat=2;
832    else df.daughter1.cat=3;
833    if(muonDau1.isGlobalMuon()) df.daughter2.cat =1;
834    else if(muonDau1.isTrackerMuon()) df.daughter2.cat=2;
835    else df.daughter2.cat=3;
836
837    TrackRef trkMu1Ref = muonDau0.get<TrackRef>();
838    TrackRef trkMu2Ref = muonDau1.get<TrackRef>();
839
840    if(trkMu1Ref.isNonnull() && trkMu2Ref.isNonnull()){
841      const Track* MuTrk1 = muonDau0.get<TrackRef>().get();
842      const Track* MuTrk2 = muonDau1.get<TrackRef>().get();
843      df.daughter1.zPVPt=MuTrk1->dz(RecVtxFirst.position());
844      df.daughter1.zPVProb=MuTrk1->dz(RecVtx.position());
845      df.daughter2.zPVPt=MuTrk2->dz(RecVtxFirst.position());
846      df.daughter2.zPVProb=MuTrk2->dz(RecVtx.position());
847
848      df.daughter1.nHits = MuTrk1->numberOfValidHits();
849      df.daughter2.nHits = MuTrk2->numberOfValidHits();
1131  
1132 <      df.daughter1.chi2 = MuTrk1->normalizedChi2();
852 <      df.daughter2.chi2 = MuTrk2->normalizedChi2();
853 <
854 <      TrackRef iTrack1 = muonDau0.innerTrack();
855 <      const reco::HitPattern& p1 = iTrack1->hitPattern();
856 <      TrackRef iTrack2 = muonDau1.innerTrack();
857 <      const reco::HitPattern& p2 = iTrack2->hitPattern();
858 <
859 <      df.daughter1.nPixelHits = p1.pixelLayersWithMeasurement();
860 <      df.daughter2.nPixelHits = p2.pixelLayersWithMeasurement();
861 <
862 <      if(muonDau0.isGlobalMuon()){
863 <        TrackRef gTrack = muonDau0.globalTrack();
864 <        const reco::HitPattern& q = gTrack->hitPattern();
865 <        df.daughter1.globNHits=q.numberOfValidMuonHits();
866 <        df.daughter1.globChi2=gTrack.get()->normalizedChi2();
867 <      }
868 <      if(muonDau1.isGlobalMuon()){
869 <        TrackRef gTrack = muonDau1.globalTrack();
870 <        const reco::HitPattern& q = gTrack->hitPattern();
871 <        df.daughter2.globNHits=q.numberOfValidMuonHits();
872 <        df.daughter2.globChi2=gTrack.get()->normalizedChi2();
873 <      }
1132 >    
1133    
1134 <    }
1135 <      
1136 <    hbbInfo->diMuonInfo.push_back(df);
1134 >   if (verbose_){
1135 >     std::cout <<" Pushing hbbInfo "<<std::endl;
1136 >     std::cout <<" SimpleJets1 = "<<hbbInfo->simpleJets.size()<<std::endl<<
1137 >       " SimpleJets2 = "<<hbbInfo->simpleJets2.size()<<std::endl<<
1138 >       " SubJets = "<<hbbInfo->subJets.size()<<std::endl<<
1139 >       " HardJets = "<<hbbInfo->hardJets.size()<<std::endl<<
1140 >       " FilterJets = "<<hbbInfo->filterJets.size()<<std::endl<<
1141 >       " Muons = "<<hbbInfo->muInfo.size()<<std::endl<<
1142 >       " Electrons = "<<hbbInfo->eleInfo.size()<<std::endl<<
1143 >       " Taus = "<<hbbInfo->tauInfo.size()<<std::endl<<
1144 >       " Electrons = "<<hbbInfo->eleInfo.size()<<std::endl<<
1145 >       "--------------------- "<<std::endl;
1146    }
1147  
880  for( size_t i = 0; i < dielectrons->size(); i++ ) {
881    VHbbEvent::DiElectronInfo df;
882    const Candidate & dielecCand = (*dielectrons)[ i ];
883
884    df.fourMomentum=GENPTOLOR(dielecCand);
1148  
1149 <    // accessing the daughters of the dimuon candidate
1150 <    const Candidate * lep0 = dielecCand.daughter( 0 );
888 <    const Candidate * lep1 = dielecCand.daughter( 1 );
889 <    // needed to access specific methods of pat::Muon
890 <    const pat::Electron & elecDau0 = dynamic_cast<const pat::Electron &>(*lep0->masterClone());
891 <    const pat::Electron & elecDau1 = dynamic_cast<const pat::Electron &>(*lep1->masterClone());
892 <
893 <    df.daughter1.fourMomentum = GENPTOLOR(elecDau0);
894 <    df.daughter2.fourMomentum = GENPTOLOR(elecDau1);
1149 >  iEvent.put(hbbInfo);
1150 >  iEvent.put(auxInfo);
1151  
896    df.daughter1.tIso = elecDau0.trackIso();
897    df.daughter2.tIso = elecDau1.trackIso();
1152  
1153 <    df.daughter1.eIso = elecDau0.ecalIso();
900 <    df.daughter2.eIso = elecDau1.ecalIso();
901 <
902 <    df.daughter1.hIso = elecDau0.hcalIso();
903 <    df.daughter2.hIso = elecDau1.hcalIso();
904 <    
905 <    
906 <    hbbInfo->diElectronInfo.push_back(df);
907 <    
908 <  }
909 <  iEvent.put(hbbInfo);
1153 >  delete jecUnc;
1154  
1155   }
1156    
# Line 941 | Line 1185 | void
1185   HbbAnalyzerNew::endJob() {
1186   }
1187  
1188 + TVector2 HbbAnalyzerNew::getTvect( const pat::Jet* patJet ){
1189 +
1190 +  TVector2 t_Vect(0,0);
1191 +  TVector2 null(0,0);
1192 +  TVector2 ci(0,0);
1193 +  TLorentzVector pi(0,0,0,0);
1194 +  TLorentzVector J(0,0,0,0);
1195 +  TVector2 r(0,0);
1196 +  double patJetpfcPt = 1e10;
1197 +  double r_mag = 1e10;
1198 +  unsigned int nOfconst = 0;
1199 +
1200 +
1201 +  if (patJet->isPFJet() == false) {
1202 +    return t_Vect;
1203 +  }
1204 +  
1205 +
1206 +  //re-reconstruct the jet direction with the charged tracks
1207 +  std::vector<reco::PFCandidatePtr>
1208 +    patJetpfc = patJet->getPFConstituents();
1209 +  for(size_t idx = 0; idx < patJetpfc.size(); idx++){
1210 +    if( patJetpfc.at(idx)->charge() != 0 ){
1211 +      pi.SetPtEtaPhiE( patJetpfc.at(idx)->pt(), patJetpfc.at(idx)->eta(), patJetpfc.at(idx)->phi(), patJetpfc.at(idx)->energy() );
1212 +      J += pi;
1213 +      nOfconst++;
1214 +    }
1215 +  }
1216 + // if there are less than two charged tracks do not calculate the pull (there is not enough info). It returns a null vector
1217 +
1218 +  if( nOfconst < 2 )
1219 +    return null;
1220 +  
1221 +
1222 +
1223 +  TVector2 v_J( J.Rapidity(), J.Phi() );
1224 + //calculate TVector using only charged tracks
1225 +  for(size_t idx = 0; idx < patJetpfc.size(); idx++){
1226 +    if( patJetpfc.at(idx)->charge() != 0  ){
1227 +      patJetpfcPt = patJetpfc.at(idx)->pt();
1228 +      pi.SetPtEtaPhiE( patJetpfc.at(idx)->pt(), patJetpfc.at(idx)->eta(), patJetpfc.at(idx)->phi(), patJetpfc.at(idx)->energy() );
1229 +      r.Set( pi.Rapidity() - J.Rapidity(), Geom::deltaPhi( patJetpfc.at(idx)->phi(), J.Phi() ) );
1230 +      r_mag = r.Mod();
1231 +      t_Vect += ( patJetpfcPt / J.Pt() ) * r_mag * r;
1232 +    }
1233 +  }
1234 +
1235 +  
1236 +  return t_Vect;
1237 +  
1238 + }
1239 +
1240 + TLorentzVector HbbAnalyzerNew::getChargedTracksMomentum(const pat::Jet* patJet ){
1241 +  //  return TLorentzVector();
1242 +  TLorentzVector pi(0,0,0,0);
1243 +  TLorentzVector v_j1(0,0,0,0);
1244 +
1245 +
1246 +  //  std::cout <<"fff ECCCCCCOOOOO "<<patJet->isPFJet()<<std::endl;
1247 +
1248 +  if (patJet->isPFJet() == false ){
1249 +      v_j1 = GENPTOLORP(patJet);
1250 +      return v_j1;
1251 +  }
1252 +  std::vector<reco::PFCandidatePtr>
1253 +    j1pfc = patJet->getPFConstituents();
1254 +  for(size_t idx = 0; idx < j1pfc.size(); idx++){
1255 +    if( j1pfc.at(idx)->charge() != 0 ){
1256 +      pi.SetPtEtaPhiE( j1pfc.at(idx)->pt(), j1pfc.at(idx)->eta(), j1pfc.at(idx)->phi(), j1pfc.at(idx)->energy() );
1257 +      v_j1 += pi;
1258 +    }
1259 +  }
1260 +  return v_j1;
1261 +  //re-
1262 + }
1263 +
1264 +
1265 + //Btagging scale factors
1266 + void HbbAnalyzerNew::fillScaleFactors(VHbbEvent::SimpleJet& sj, BTagSFContainer iSF){
1267 +
1268 +
1269 +  BinningPointByMap measurePoint;
1270 +  //for a USDG
1271 +  //for CB jets
1272 +  //scale factor 1 for CB jets over 240GeV/c
1273 +  if( TMath::Abs(sj.flavour) == 4 or TMath::Abs(sj.flavour) == 5 ){
1274 +    measurePoint.insert( BinningVariables::JetEt, sj.p4.Et() );
1275 +    measurePoint.insert( BinningVariables::JetAbsEta, fabs(sj.p4.Eta()) );
1276 +    if( iSF.BTAGSF_CSVL->isResultOk(PerformanceResult::BTAGBEFFCORR , measurePoint) ){
1277 +      sj.SF_CSVL = iSF.BTAGSF_CSVL->getResult(PerformanceResult::BTAGBEFFCORR , measurePoint);
1278 +      sj.SF_CSVLerr = iSF.BTAGSF_CSVL->getResult(PerformanceResult::BTAGBERRCORR , measurePoint);        
1279 +      if(verbose_){
1280 +        std::clog << "C/B Jet flavour = " << sj.flavour << std::endl;
1281 +        std::clog << "C/B Jet Et = " << sj.p4.Et() << std::endl;
1282 +        std::clog << "C/B Jet eta = " << sj.p4.Eta() << std::endl;          
1283 +        std::clog << "C/B CSVL Scale Factor = " << sj.SF_CSVL << std::endl;
1284 +        std::clog << "C/B CSVL Scale Factor error = " << sj.SF_CSVLerr << std::endl;
1285 +      }
1286 +    }
1287 +    if( iSF.BTAGSF_CSVM->isResultOk(PerformanceResult::BTAGBEFFCORR , measurePoint) ){
1288 +      sj.SF_CSVM = iSF.BTAGSF_CSVM->getResult(PerformanceResult::BTAGBEFFCORR , measurePoint);
1289 +      sj.SF_CSVMerr = iSF.BTAGSF_CSVM->getResult(PerformanceResult::BTAGBERRCORR , measurePoint);        
1290 +    }
1291 +    if( iSF.BTAGSF_CSVT->isResultOk(PerformanceResult::BTAGBEFFCORR , measurePoint) ){
1292 +      sj.SF_CSVT = iSF.BTAGSF_CSVT->getResult(PerformanceResult::BTAGBEFFCORR , measurePoint);
1293 +      sj.SF_CSVTerr = iSF.BTAGSF_CSVT->getResult(PerformanceResult::BTAGBERRCORR , measurePoint);        
1294 +    }
1295 +    else{
1296 +      if(verbose_){
1297 +        std::cerr << "No SF found in the database for this jet" << std::endl;
1298 +        std::clog << "No SF found: Jet flavour = " << sj.flavour << std::endl;
1299 +        std::clog << "No SF found: Jet Et = " << sj.p4.Et() << std::endl;
1300 +        std::clog << "No SF found: Jet eta = " << sj.p4.Eta() << std::endl;
1301 +      }
1302 +    }
1303 +  }
1304 +  else {
1305 +    measurePoint.insert( BinningVariables::JetEt, sj.p4.Et() );
1306 +    measurePoint.insert( BinningVariables::JetAbsEta, fabs(sj.p4.Eta()) );
1307 +    if( iSF.MISTAGSF_CSVL->isResultOk(PerformanceResult::BTAGLEFFCORR , measurePoint) ){
1308 +      sj.SF_CSVL = iSF.MISTAGSF_CSVL->getResult(PerformanceResult::BTAGLEFFCORR , measurePoint);
1309 +      sj.SF_CSVLerr = iSF.MISTAGSF_CSVL->getResult(PerformanceResult::BTAGLERRCORR , measurePoint);
1310 +      if(verbose_){
1311 +        std::clog << "Light Jet flavour = " << sj.flavour << std::endl;
1312 +        std::clog << "Light Jet Et = " << sj.p4.Et() << std::endl;
1313 +        std::clog << "Light Jet eta = " << sj.p4.Eta() << std::endl;        
1314 +        std::clog << "Light CSVL Scale Factor = " << sj.SF_CSVL << std::endl;
1315 +        std::clog << "Light CSVL Scale Factor error = " << sj.SF_CSVLerr << std::endl;
1316 +      }
1317 +    }
1318 +    if( iSF.MISTAGSF_CSVM->isResultOk(PerformanceResult::BTAGLEFFCORR , measurePoint) ){
1319 +      sj.SF_CSVM = iSF.MISTAGSF_CSVM->getResult(PerformanceResult::BTAGLEFFCORR , measurePoint);
1320 +      sj.SF_CSVMerr = iSF.MISTAGSF_CSVM->getResult(PerformanceResult::BTAGLERRCORR , measurePoint);
1321 +    }
1322 +    if( iSF.MISTAGSF_CSVT->isResultOk(PerformanceResult::BTAGLEFFCORR , measurePoint) ){
1323 +      sj.SF_CSVT = iSF.MISTAGSF_CSVT->getResult(PerformanceResult::BTAGLEFFCORR , measurePoint);
1324 +      sj.SF_CSVTerr = iSF.MISTAGSF_CSVT->getResult(PerformanceResult::BTAGLERRCORR , measurePoint);
1325 +    }
1326 +    else{
1327 +      if(verbose_){
1328 +        std::cerr << "No SF found in the database for this jet" << std::endl;
1329 +        std::clog << "No SF found: Jet flavour = " << sj.flavour << std::endl;
1330 +        std::clog << "No SF found: Jet Et = " << sj.p4.Et() << std::endl;
1331 +        std::clog << "No SF found: Jet eta = " << sj.p4.Eta() << std::endl;
1332 +      }
1333 +    }
1334 +  }
1335 +    
1336 + }
1337 +
1338 + void HbbAnalyzerNew::setJecUnc(VHbbEvent::SimpleJet& sj,JetCorrectionUncertainty* jecunc){
1339 +  //
1340 +  // test
1341 +  //
1342 +
1343 +  //  return;
1344 +  double eta = sj.p4.Eta();
1345 +  double pt = sj.p4.Pt();
1346 +  
1347 +  jecunc->setJetEta(eta);
1348 +  jecunc->setJetPt(pt); // here you must use the CORRECTED jet pt
1349 +  double unc = jecunc->getUncertainty(true);
1350 +  sj.jecunc= unc;
1351 + }
1352 +
1353 +
1354 + void HbbAnalyzerNew ::fillSimpleJet (VHbbEvent::SimpleJet& sj, edm::View<pat::Jet>::const_iterator jet_iter){
1355 +      sj.flavour = jet_iter->partonFlavour();
1356 +
1357 +    sj.tche=jet_iter->bDiscriminator("trackCountingHighEffBJetTags");
1358 +    sj.tchp=jet_iter->bDiscriminator("trackCountingHighPurBJetTags");
1359 +    sj.jp=jet_iter->bDiscriminator("jetProbabilityBJetTags");
1360 +    sj.jpb=jet_iter->bDiscriminator("jetBProbabilityBJetTags");
1361 +    sj.ssvhe=jet_iter->bDiscriminator("simpleSecondaryVertexHighEffBJetTags");
1362 +    sj.csv=jet_iter->bDiscriminator("combinedSecondaryVertexBJetTags");
1363 +   sj.csvmva=jet_iter->bDiscriminator("combinedSecondaryVertexMVABJetTags");
1364 +    sj.charge=jet_iter->jetCharge();
1365 +    sj.ntracks=jet_iter->associatedTracks().size();
1366 +    sj.p4=GENPTOLORP(jet_iter);
1367 +    //    std::cout << " ECCO "<<sj.csv<< " "<< sj.p4.Pt()<<std::endl;
1368 +    sj.chargedTracksFourMomentum=(getChargedTracksMomentum(&*(jet_iter)));
1369 +    sj.SF_CSVL=1;
1370 +    sj.SF_CSVM=1;
1371 +    sj.SF_CSVT=1;
1372 +    sj.SF_CSVLerr=0;
1373 +    sj.SF_CSVMerr=0;
1374 +    sj.SF_CSVTerr=0;
1375 +
1376 +    
1377 +    if (jet_iter->isPFJet() == true) {
1378 +
1379 +      sj.chargedHadronEFraction = jet_iter-> chargedHadronEnergyFraction();
1380 +      sj.neutralHadronEFraction = jet_iter-> neutralHadronEnergyFraction ();
1381 +      sj.chargedEmEFraction = jet_iter-> chargedEmEnergyFraction ();
1382 +      sj.neutralEmEFraction = jet_iter-> neutralEmEnergyFraction ();
1383 +      sj.nConstituents = jet_iter->getPFConstituents().size();
1384 +      
1385 +    }
1386 +    //
1387 +    // addtaginfo for csv
1388 +    //
1389 +
1390 +    //    if (jet_iter->hasTagInfo("SimpleSecondaryVertex")) {
1391 +
1392 +    const reco::SecondaryVertexTagInfo * tf = jet_iter->tagInfoSecondaryVertex();
1393 +   if (tf){
1394 +     if (tf->nVertices() >0){
1395 +        sj.vtxMass = tf->secondaryVertex(0).p4().mass();
1396 +        sj.vtxNTracks = tf->secondaryVertex(0).nTracks();
1397 +        std::vector<reco::TrackBaseRef >::const_iterator tit =  tf->secondaryVertex(0).tracks_begin();
1398 +        for (; tit<  tf->secondaryVertex(0).tracks_end(); ++tit){
1399 +          sj.vtxTrackIds.push_back(tit->key());
1400 +        }
1401 +        Measurement1D m = tf->flightDistance(0);
1402 +        sj.vtx3dL = m.value();
1403 +        sj.vtx3deL = m.error();
1404 +     }
1405 +    }
1406 +   //
1407 +    // add tVector
1408 +    //
1409 +    sj.tVector = getTvect(&(*jet_iter));
1410 +
1411 +
1412 + }
1413 +
1414 + float HbbAnalyzerNew::metSignificance(const reco::MET * met)
1415 + {
1416 + double sigmaX2= met->getSignificanceMatrix()(0,0);
1417 + double sigmaY2= met->getSignificanceMatrix()(1,1);
1418 + double significance = 0;
1419 + try {
1420 + if(sigmaX2<1.e10 && sigmaY2<1.e10) significance = met->significance();
1421 + }
1422 + catch(...)
1423 + {
1424 + std::cout << "PROBLEM WITH MET SIGNIFICANCE sigma X2 and Y2 are: " << sigmaX2 << " " << sigmaY2 << std::endl;
1425 + }
1426 + return significance;
1427 + }
1428 +
1429 +
1430   //define this as a plug-in
1431   DEFINE_FWK_MODULE(HbbAnalyzerNew);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines