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.1 by tboccali, Wed Jun 8 17:25:32 2011 UTC vs.
Revision 1.36 by arizzi, Thu Sep 15 10:50:35 2011 UTC

# Line 17 | Line 17 | Implementation:
17   //
18   //
19  
20 < #include "UserCode/HbbAnalyzer/interface/HbbAnalyzerNew.h"
21 < #include "UserCode/HbbAnalyzer/interface/VHbbEvent.h"
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 "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
33 >
34 > #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
35  
36   #define GENPTOLOR(a) TLorentzVector((a).px(), (a).py(), (a).pz(), (a).energy())
37   #define GENPTOLORP(a) TLorentzVector((a)->px(), (a)->py(), (a)->pz(), (a)->energy())
38  
39 +
40 + struct CompareJetPtMuons {
41 +  bool operator()( const VHbbEvent::MuonInfo& j1, const  VHbbEvent::MuonInfo& j2 ) const {
42 +    return j1.p4.Pt() > j2.p4.Pt();
43 +  }
44 + };
45 + struct CompareJetPtElectrons {
46 +  bool operator()( const VHbbEvent::ElectronInfo& j1, const  VHbbEvent::ElectronInfo& j2 ) const {
47 +    return j1.p4.Pt() > j2.p4.Pt();
48 +  }
49 + };
50 + struct CompareJetPtTaus {
51 +  bool operator()( const VHbbEvent::TauInfo& j1, const  VHbbEvent::TauInfo& j2 ) const {
52 +    return j1.p4.Pt() > j2.p4.Pt();
53 +  }
54 + };
55 +
56 +
57 +
58   HbbAnalyzerNew::HbbAnalyzerNew(const edm::ParameterSet& iConfig):
59 <  eleLabel_(iConfig.getUntrackedParameter<edm::InputTag>("electronTag")),
60 <  muoLabel_(iConfig.getUntrackedParameter<edm::InputTag>("muonTag")),
61 <  jetLabel_(iConfig.getUntrackedParameter<edm::InputTag>("jetTag")),
62 <  subjetLabel_(iConfig.getUntrackedParameter<edm::InputTag>("subjetTag")),
63 <  simplejet1Label_(iConfig.getUntrackedParameter<edm::InputTag>("simplejet1Tag")),
64 <  simplejet2Label_(iConfig.getUntrackedParameter<edm::InputTag>("simplejet2Tag")),
65 <  simplejet3Label_(iConfig.getUntrackedParameter<edm::InputTag>("simplejet3Tag")),
66 <  simplejet4Label_(iConfig.getUntrackedParameter<edm::InputTag>("simplejet4Tag")),
67 <  tauLabel_(iConfig.getUntrackedParameter<edm::InputTag>("tauTag")),
68 <  metLabel_(iConfig.getUntrackedParameter<edm::InputTag>("metTag")),
69 <  phoLabel_(iConfig.getUntrackedParameter<edm::InputTag>("photonTag")),
70 <  dimuLabel_(iConfig.getUntrackedParameter<edm::InputTag>("dimuTag")),
71 <  dielecLabel_(iConfig.getUntrackedParameter<edm::InputTag>("dielecTag")),
72 <  hltResults_(iConfig.getUntrackedParameter<edm::InputTag>("hltResultsTag")){
59 >  eleLabel_(iConfig.getParameter<edm::InputTag>("electronTag")),
60 >  muoLabel_(iConfig.getParameter<edm::InputTag>("muonTag")),
61 >  jetLabel_(iConfig.getParameter<edm::InputTag>("jetTag")),
62 >  subjetLabel_(iConfig.getParameter<edm::InputTag>("subjetTag")),
63 >  simplejet1Label_(iConfig.getParameter<edm::InputTag>("simplejet1Tag")),
64 >  simplejet2Label_(iConfig.getParameter<edm::InputTag>("simplejet2Tag")),
65 >  simplejet3Label_(iConfig.getParameter<edm::InputTag>("simplejet3Tag")),
66 >  simplejet4Label_(iConfig.getParameter<edm::InputTag>("simplejet4Tag")),
67 >  tauLabel_(iConfig.getParameter<edm::InputTag>("tauTag")),
68 >  metLabel_(iConfig.getParameter<edm::InputTag>("metTag")),
69 >  phoLabel_(iConfig.getParameter<edm::InputTag>("photonTag")),
70 >  hltResults_(iConfig.getParameter<edm::InputTag>("hltResultsTag")),
71 >  runOnMC_(iConfig.getParameter<bool>("runOnMC")), verbose_(iConfig.getUntrackedParameter<bool>("verbose")) {
72 >
73    //
74    // put the setwhatproduced etc etc
75  
76    produces<VHbbEvent>();
77 +  produces<VHbbEventAuxInfo>();
78  
79  
80   }
# Line 64 | Line 97 | void
97   HbbAnalyzerNew::produce(edm::Event& iEvent, const edm::EventSetup& iSetup){
98    using namespace edm;
99    using namespace reco;
100 +
101 +
102 +  // JEC Uncertainty
103 +
104 +  //  JetCorrectionUncertainty *jecUnc=0;
105 +  edm::ESHandle<JetCorrectorParametersCollection> JetCorParColl;
106 +  iSetup.get<JetCorrectionsRecord>().get("AK5PF",JetCorParColl);
107 +  JetCorrectionUncertainty *jecUnc=0;
108 +  //  if (!runOnMC_){
109 +  JetCorrectorParameters const & JetCorPar = (*JetCorParColl)["Uncertainty"];
110 +  jecUnc = new JetCorrectionUncertainty(JetCorPar);
111 +  //  }
112    
113 <  
114 <  std::auto_ptr<VHbbEvent> hbbInfo( new VHbbEvent() );
115 <  
113 >  std::auto_ptr<VHbbEvent> hbbInfo( new VHbbEvent() );  
114 >  std::auto_ptr<VHbbEventAuxInfo> auxInfo( new VHbbEventAuxInfo() );
115 >
116 >
117 >  if (runOnMC_){
118 >    Handle<GenEventInfoProduct> evt_info;
119 >    iEvent.getByType(evt_info);
120 >    auxInfo->weightMCProd = evt_info->weight();
121 >  }
122 >  else
123 >    { auxInfo->weightMCProd =1.;}
124    //
125    // ??
126 <  
126 >  
127 >  // trigger
128 >
129    // trigger
130    edm::Handle<edm::TriggerResults>  hltresults;
131    //iEvent.getByLabel("TriggerResults", hltresults);
# Line 80 | Line 135 | HbbAnalyzerNew::produce(edm::Event& iEve
135    iEvent.getByLabel(hltResults_, hltresults);
136    
137    const edm::TriggerNames & triggerNames_ = iEvent.triggerNames(*hltresults);
83  
84  int ntrigs = hltresults->size();
85  if (ntrigs==0){std::cout << "%HLTInfo -- No trigger name given in TriggerResults of the input " << std::endl;}
86
87  for (int itrig = 0; itrig != ntrigs; ++itrig){
88
89    TString trigName=triggerNames_.triggerName(itrig);
90    bool accept = hltresults->accept(itrig);
91
92    if (accept){(hbbInfo->triggerInfo.flag)[itrig] = 1;}
93    else { (hbbInfo->triggerInfo.flag)[itrig] = 0;}
94
95    //    std::cout << "%HLTInfo --  Number of HLT Triggers: " << ntrigs << std::endl;
96    //    std::cout << "%HLTInfo --  HLTTrigger(" << itrig << "): " << trigName << " = " << accept << std::endl;
97  }
98
99  //
100  // big bloat
101  //
102
103
104  int goodDoubleMu3=0,goodDoubleMu3_2=0,  
105    goodMu9=0, goodIsoMu9=0, goodMu11=0, goodIsoMu13_3=0, goodMu15=0, goodMu15_1=0;
106  int goodDoubleElec10=0,goodDoubleElec15_1=0,goodDoubleElec17_1=0;
107  int goodMet100=0;
108  int goodSingleEle1=0,goodSingleEle2=0,goodSingleEle3=0,goodSingleEle4=0;
109  int goodBtagMu1=0,goodBtagMu2=0,goodBtagMu0=0,goodBtagMu11=0;  
110  int goodBtagMuJet1=0, goodBtagMuJet2=0, goodBtagMuJet3=0, goodBtagMuJet4=0;
111  int goodIsoMu15=0,goodIsoMu17v5=0,goodIsoMu17v6=0;
112
113  for (int itrig = 0; itrig != ntrigs; ++itrig){
114    TString trigName=triggerNames_.triggerName(itrig);
115    if(strcmp(trigName,"HLT_Mu9")==0) goodMu9++;
116    if(strcmp(trigName,"HLT_IsoMu9")==0) goodIsoMu9++;
117    if(strcmp(trigName,"HLT_IsoMu13_v3")==0) goodIsoMu13_3++;
118    if(strcmp(trigName,"HLT_Mu11")==0) goodMu11++;
119    if(strcmp(trigName,"HLT_DoubleMu3")==0) goodDoubleMu3++;
120    if(strcmp(trigName,"HLT_DoubleMu3_v2")==0) goodDoubleMu3_2++;
121    if(strcmp(trigName,"HLT_Mu15")==0) goodMu15++;
122    if(strcmp(trigName,"HLT_Mu15_v1")==0) goodMu15_1++;
123
124    if(strcmp(trigName,"HLT_DoubleEle10_SW_L1R")==0) goodDoubleElec10++;
125    if(strcmp(trigName,"HLT_DoubleEle15_SW_L1R_v1")==0) goodDoubleElec15_1++;
126    if(strcmp(trigName,"HLT_DoubleEle17_SW_L1R_v1")==0) goodDoubleElec17_1++;
127    if(strcmp(trigName,"HLT_MET100_v1")==0) goodMet100++;
128    if(strcmp(trigName,"HLT_Ele15_SW_L1R")==0) goodSingleEle1++;
129    if(strcmp(trigName,"HLT_Ele17_SW_TightEleId_L1R")==0) goodSingleEle2++;
130    if(strcmp(trigName,"HLT_Ele17_SW_TighterEleIdIsol_L1R_v2")==0) goodSingleEle3++;
131    if(strcmp(trigName,"HLT_Ele17_SW_TighterEleIdIsol_L1R_v3")==0) goodSingleEle4++;
132    if(strcmp(trigName,"HLT_BTagMu_DiJet20U_v1")==0) goodBtagMu1++;
133    if(strcmp(trigName,"HLT_BTagMu_DiJet30U_Mu5_v3")==0) goodBtagMu2++;
134    if(strcmp(trigName,"HLT_BTagMu_Jet20U")==0) goodBtagMu0++;
135    if(strcmp(trigName,"HLT_BTagMu_DiJet20U_Mu5_v1")==0) goodBtagMu11++;
136    if(strcmp(trigName,"HLT_Mu17_CentralJet30_BTagIP_v2")==0) goodBtagMuJet1++;
137    if(strcmp(trigName,"HLT_Mu17_CentralJet30_v2")==0) goodBtagMuJet2++;
138    if(strcmp(trigName,"HLT_HT200_Mu5_PFMHT35_v2")==0) goodBtagMuJet3++;
139    if(strcmp(trigName,"HLT_Mu12_CentralJet30_BTagIP_v2")==0) goodBtagMuJet4++;  
140
141    if(strcmp(trigName,"HLT_IsoMu15_v5")==0) goodIsoMu15++;
142    if(strcmp(trigName,"HLT_IsoMu17_v5")==0) goodIsoMu17v5++;  
143    if(strcmp(trigName,"HLT_IsoMu17_v6")==0) goodIsoMu17v6++;  
144  }
145  int itrig1=-99;
146  if(goodMu9!=0) itrig1 = triggerNames_.triggerIndex("HLT_Mu9");
147  int itrig2=-99;
148  if(goodIsoMu9!=0) itrig2 = triggerNames_.triggerIndex("HLT_IsoMu9");
149  int itrig3=-99;
150  if(goodIsoMu13_3!=0) itrig3 = triggerNames_.triggerIndex("HLT_IsoMu13_v3");
151  int itrig4=-99;
152  if(goodMu11!=0) itrig4 = triggerNames_.triggerIndex("HLT_Mu11");
153  int itrig5=-99;  
154  if(goodDoubleMu3!=0) itrig5 = triggerNames_.triggerIndex("HLT_DoubleMu3");
155  int itrig6=-99;
156  if(goodDoubleMu3_2!=0) itrig6 = triggerNames_.triggerIndex("HLT_DoubleMu3_v2");
157  int itrig7=-99;
158  if(goodMu15!=0) itrig7 = triggerNames_.triggerIndex("HLT_Mu15");
159  int itrig8=-99;
160  if(goodMu15_1!=0) itrig8 = triggerNames_.triggerIndex("HLT_Mu15_v1");
161
162  int itrig9=-99;
163  if(goodDoubleElec10!=0) itrig9 = triggerNames_.triggerIndex("HLT_DoubleEle10_SW_L1R");
164  int itrig10=-99;
165  if(goodDoubleElec15_1!=0) itrig10 = triggerNames_.triggerIndex("HLT_DoubleEle15_SW_L1R_v1");
166  int itrig11=-99;
167  if(goodDoubleElec17_1!=0) itrig11 = triggerNames_.triggerIndex("HLT_DoubleEle17_SW_L1R_v1");
168  int itrig12=-99;
169  if(goodMet100!=0) itrig12 = triggerNames_.triggerIndex("HLT_MET100_v1");
170
171  int itrig13=-99;
172  if(goodSingleEle1!=0) itrig13 = triggerNames_.triggerIndex("HLT_Ele15_SW_L1R");
173  int itrig14=-99;
174  if(goodSingleEle2!=0) itrig14 = triggerNames_.triggerIndex("HLT_Ele17_SW_TightEleId_L1R");
175  int itrig15=-99;
176  if(goodSingleEle3!=0) itrig15 = triggerNames_.triggerIndex("HLT_Ele17_SW_TighterEleIdIsol_L1R_v2");
177  int itrig16=-99;
178  if(goodSingleEle4!=0) itrig16 = triggerNames_.triggerIndex("HLT_Ele17_SW_TighterEleIdIsol_L1R_v3");
179
180  int itrig17=-99;
181  if(goodBtagMu1!=0) itrig17 = triggerNames_.triggerIndex("HLT_BTagMu_DiJet20U_v1");      
182  int itrig18=-99;
183  if(goodBtagMu2!=0) itrig18 = triggerNames_.triggerIndex("HLT_BTagMu_DiJet30U_Mu5_v3");    
184  int itrig19=-99;
185  if(goodBtagMu0!=0) itrig19 = triggerNames_.triggerIndex("HLT_BTagMu_Jet20U");
186  int itrig20=-99;
187  if(goodBtagMu11!=0) itrig20 = triggerNames_.triggerIndex("HLT_BTagMu_DiJet20U_Mu5_v1");
188  int itrig21=-99;
189  if(goodBtagMuJet1!=0) itrig21 = triggerNames_.triggerIndex("HLT_Mu17_CentralJet30_BTagIP_v2");
190  int itrig22=-99;
191  if(goodBtagMuJet2!=0) itrig22 = triggerNames_.triggerIndex("HLT_Mu17_CentralJet30_v2");
192  int itrig23=-99;
193  if(goodBtagMuJet3!=0) itrig23 = triggerNames_.triggerIndex("HLT_HT200_Mu5_PFMHT35_v2");
194  int itrig231=-99;
195  if(goodBtagMuJet4!=0) itrig231 = triggerNames_.triggerIndex("HLT_Mu12_CentralJet30_BTagIP_v2");  
196
197  int itrig24=-99;
198  if(goodIsoMu15!=0) itrig24 = triggerNames_.triggerIndex("HLT_IsoMu15_v5");
199  int itrig25=-99;
200  if(goodIsoMu17v5!=0) itrig25 = triggerNames_.triggerIndex("HLT_IsoMu17_v5");
201  int itrig26=-99;
202  if(goodIsoMu17v6!=0) itrig26 = triggerNames_.triggerIndex("HLT_IsoMu17_v6");
203  
204  if (itrig1!=-99 && hltresults->accept(itrig1))  hbbInfo->triggerInfo.triggerMu9=1; else hbbInfo->triggerInfo.triggerMu9=0;
205  if (itrig2!=-99 && hltresults->accept(itrig2))  hbbInfo->triggerInfo.triggerIsoMu9=1; else hbbInfo->triggerInfo.triggerIsoMu9=0;
206  if (itrig3!=-99 && hltresults->accept(itrig3))  hbbInfo->triggerInfo.triggerIsoMu13_3=1; else hbbInfo->triggerInfo.triggerIsoMu13_3=0;
207  if (itrig4!=-99 && hltresults->accept(itrig4))  hbbInfo->triggerInfo.triggerMu11=1; else hbbInfo->triggerInfo.triggerMu11=0;
208  if (itrig5!=-99 && hltresults->accept(itrig5))  hbbInfo->triggerInfo.triggerDoubleMu3=1; else hbbInfo->triggerInfo.triggerDoubleMu3=0;
209  if (itrig6!=-99 && hltresults->accept(itrig6))  hbbInfo->triggerInfo.triggerDoubleMu3_2=1; else hbbInfo->triggerInfo.triggerDoubleMu3_2=0;
210  if (itrig7!=-99 && hltresults->accept(itrig7))  hbbInfo->triggerInfo.triggerMu15=1; else hbbInfo->triggerInfo.triggerMu15=0;
211  if (itrig8!=-99 && hltresults->accept(itrig8))  hbbInfo->triggerInfo.triggerMu15_1=1; else hbbInfo->triggerInfo.triggerMu15_1=0;  
212  
213  if (itrig9!=-99 && hltresults->accept(itrig9))  hbbInfo->triggerInfo.triggerDoubleElec10=1; else hbbInfo->triggerInfo.triggerDoubleElec10=0;  
214  if (itrig10!=-99 && hltresults->accept(itrig10))  hbbInfo->triggerInfo.triggerDoubleElec15_1=1; else hbbInfo->triggerInfo.triggerDoubleElec15_1=0;  
215  if (itrig11!=-99 && hltresults->accept(itrig11))  hbbInfo->triggerInfo.triggerDoubleElec17_1=1; else hbbInfo->triggerInfo.triggerDoubleElec17_1=0;  
216  if (itrig12!=-99 && hltresults->accept(itrig12))  hbbInfo->triggerInfo.triggerMet100_1=1; else hbbInfo->triggerInfo.triggerMet100_1=0;
217  
218  if (itrig13!=-99 && hltresults->accept(itrig13))  hbbInfo->triggerInfo.triggerSingleEle1=1; else hbbInfo->triggerInfo.triggerSingleEle1=0;
219  if (itrig14!=-99 && hltresults->accept(itrig14))  hbbInfo->triggerInfo.triggerSingleEle2=1; else hbbInfo->triggerInfo.triggerSingleEle2=0;
220  if (itrig15!=-99 && hltresults->accept(itrig15))  hbbInfo->triggerInfo.triggerSingleEle3=1; else hbbInfo->triggerInfo.triggerSingleEle3=0;
221  if (itrig16!=-99 && hltresults->accept(itrig16))  hbbInfo->triggerInfo.triggerSingleEle4=1; else hbbInfo->triggerInfo.triggerSingleEle4=0;
222  
223  if (itrig17!=-99 && hltresults->accept(itrig17))  hbbInfo->triggerInfo.triggerBtagMu1=1; else hbbInfo->triggerInfo.triggerBtagMu1=0;  
224  if (itrig18!=-99 && hltresults->accept(itrig18))  hbbInfo->triggerInfo.triggerBtagMu2=1; else hbbInfo->triggerInfo.triggerBtagMu2=0;
225  if (itrig19!=-99 && hltresults->accept(itrig19))  hbbInfo->triggerInfo.triggerBtagMu0=1; else hbbInfo->triggerInfo.triggerBtagMu0=0;
226  if (itrig20!=-99 && hltresults->accept(itrig20))  hbbInfo->triggerInfo.triggerBtagMu11=1; else hbbInfo->triggerInfo.triggerBtagMu11=0;
227  if (itrig21!=-99 && hltresults->accept(itrig21))  hbbInfo->triggerInfo.triggerBtagMuJet1=1; else hbbInfo->triggerInfo.triggerBtagMuJet1=0;
228  if (itrig22!=-99 && hltresults->accept(itrig22))  hbbInfo->triggerInfo.triggerBtagMuJet2=1; else hbbInfo->triggerInfo.triggerBtagMuJet2=0;
229  if (itrig23!=-99 && hltresults->accept(itrig23))  hbbInfo->triggerInfo.triggerBtagMuJet3=1; else hbbInfo->triggerInfo.triggerBtagMuJet3=0;
230  if (itrig231!=-99 && hltresults->accept(itrig231))  hbbInfo->triggerInfo.triggerBtagMuJet4=1; else hbbInfo->triggerInfo.triggerBtagMuJet4=0;
231  
232  if (itrig24!=-99 && hltresults->accept(itrig24))  hbbInfo->triggerInfo.triggerIsoMu15=1; else hbbInfo->triggerInfo.triggerIsoMu15=0;
233  if (itrig25!=-99 && hltresults->accept(itrig25))  hbbInfo->triggerInfo.triggerIsoMu17v5=1; else hbbInfo->triggerInfo.triggerIsoMu17v5=0;
234  if (itrig26!=-99 && hltresults->accept(itrig26))  hbbInfo->triggerInfo.triggerIsoMu17v6=1; else hbbInfo->triggerInfo.triggerIsoMu17v6=0;
235  
236  if (itrig1==-99)  hbbInfo->triggerInfo.triggerMu9=-99;
237  if (itrig2==-99)  hbbInfo->triggerInfo.triggerIsoMu9=-99;
238  if (itrig3==-99)  hbbInfo->triggerInfo.triggerIsoMu13_3=-99;
239  if (itrig4==-99)  hbbInfo->triggerInfo.triggerMu11=-99;
240  if (itrig5==-99)  hbbInfo->triggerInfo.triggerDoubleMu3=-99;
241  if (itrig6==-99)  hbbInfo->triggerInfo.triggerDoubleMu3_2=-99;
242  if (itrig7==-99)  hbbInfo->triggerInfo.triggerMu15=-99;
243  if (itrig8==-99)  hbbInfo->triggerInfo.triggerMu15_1=-99;
244
245  if (itrig9==-99)  hbbInfo->triggerInfo.triggerDoubleElec10=-99;
246  if (itrig10==-99)  hbbInfo->triggerInfo.triggerDoubleElec15_1=-99;
247  if (itrig11==-99)  hbbInfo->triggerInfo.triggerDoubleElec17_1=-99;
248  if (itrig12==-99) hbbInfo->triggerInfo.triggerMet100_1=-99;
249
250  if (itrig13==-99) hbbInfo->triggerInfo.triggerSingleEle1=-99;
251  if (itrig14==-99) hbbInfo->triggerInfo.triggerSingleEle2=-99;
252  if (itrig15==-99) hbbInfo->triggerInfo.triggerSingleEle3=-99;
253  if (itrig16==-99) hbbInfo->triggerInfo.triggerSingleEle4=-99;
254
255  if(itrig17==-99)  hbbInfo->triggerInfo.triggerBtagMu1=-99;  
256  if(itrig18==-99)  hbbInfo->triggerInfo.triggerBtagMu2=-99;
257  if(itrig19==-99)  hbbInfo->triggerInfo.triggerBtagMu0=-99;
258  if(itrig20==-99)  hbbInfo->triggerInfo.triggerBtagMu11=-99;
259  if(itrig21==-99)  hbbInfo->triggerInfo.triggerBtagMuJet1=-99;
260  if(itrig22==-99)  hbbInfo->triggerInfo.triggerBtagMuJet2=-99;
261  if(itrig23==-99)  hbbInfo->triggerInfo.triggerBtagMuJet3=-99;
262  if(itrig231==-99)  hbbInfo->triggerInfo.triggerBtagMuJet4=-99;
263
264  if(itrig24==-99)  hbbInfo->triggerInfo.triggerIsoMu15=-99;
265  if(itrig25==-99)  hbbInfo->triggerInfo.triggerIsoMu17v5=-99;
266  if(itrig26==-99)  hbbInfo->triggerInfo.triggerIsoMu17v6=-99;
267
268  //  MinDRMu=-99.,MCBestMuId=-99,MCBestMuMomId=-99,MCBestMuGMomId=-99;
269  //  for(int i=0;i<50;i++) {DeltaRMu[i]=-99;}
270
138  
139 +  int ntrigs = hltresults->size();
140 +  if (ntrigs==0){std::cerr << "%HLTInfo -- No trigger name given in TriggerResults of the input " << std::endl;}
141  
142    BeamSpot vertexBeamSpot;
143    edm::Handle<reco::BeamSpot> recoBeamSpotHandle;
# Line 286 | Line 155 | HbbAnalyzerNew::produce(edm::Event& iEve
155    Handle<reco::VertexCollection> recVtxs;
156    iEvent.getByLabel("offlinePrimaryVertices", recVtxs);
157    
158 +  auxInfo->pvInfo.nVertices = recVtxs->size();
159 +
160    for(size_t i = 0; i < recVtxs->size(); ++ i) {
161      const Vertex &vtx = (*recVtxs)[i];
162      double RecVtxProb=TMath::Prob(vtx.chi2(),vtx.ndof());
# Line 298 | Line 169 | HbbAnalyzerNew::produce(edm::Event& iEve
169    const Vertex &RecVtx = (*recVtxs)[VtxIn];
170    const Vertex &RecVtxFirst = (*recVtxs)[0];
171    
172 <  hbbInfo->pvInfo.firstPVInPT2 = TVector3(RecVtxFirst.x(), RecVtxFirst.y(), RecVtxFirst.z());
173 <  hbbInfo->pvInfo.firstPVInProb = TVector3(RecVtx.x(), RecVtx.y(), RecVtx.z());
172 >  auxInfo->pvInfo.firstPVInPT2 = TVector3(RecVtxFirst.x(), RecVtxFirst.y(), RecVtxFirst.z());
173 >  auxInfo->pvInfo.firstPVInProb = TVector3(RecVtx.x(), RecVtx.y(), RecVtx.z());
174  
175      
176    edm::Handle<double> rhoHandle;
177 <  iEvent.getByLabel(edm::InputTag("kt6PFJets", "rho"),rhoHandle); // configure srcRho = cms.InputTag('kt6PFJets")
178 <  hbbInfo->puInfo.rho = *rhoHandle;
177 >  iEvent.getByLabel(edm::InputTag("kt6PFJets", "rho"),rhoHandle);  
178 >  auxInfo->puInfo.rho = *rhoHandle;
179    
180 +  edm::Handle<std::vector< PileupSummaryInfo> > puHandle;
181 +
182 +  if (runOnMC_){
183 +    iEvent.getByType(puHandle);
184 +    if (puHandle.isValid()){
185 +      
186 +      std::vector< PileupSummaryInfo> pu = (*puHandle);
187 +      for (std::vector<PileupSummaryInfo>::const_iterator it= pu.begin(); it!=pu.end(); ++it){
188 +         int bx = (*it).getBunchCrossing();
189 +        unsigned int num = (*it).getPU_NumInteractions();
190 +        //      std::cout <<" PU PUSHING "<<bx<<" " <<num<<std::endl;
191 +        auxInfo->puInfo.pus[bx]  =num;
192 +      }
193 +    }
194 +  }
195 +
196    //// real start
197    
198    
199    Handle<GenParticleCollection> genParticles;
200    
314  bool isMC=1;
201    bool printJet=0;
202    
203    
204 <  if(isMC){
319 <    
320 <    int Hin=-99,Win=-99,Zin=-99,bin=-99,bbarin=-99;
204 >  if(runOnMC_){
205      
206 <    iEvent.getByLabel("genParticles", genParticles);
206 >   iEvent.getByLabel("genParticles", genParticles);
207      
208      for(size_t i = 0; i < genParticles->size(); ++ i) {
209 +    
210        const GenParticle & p = (*genParticles)[i];
211        int id = p.pdgId();
212        int st = p.status();  
213 <        
213 >      
214        if(id==25){
215 <          
216 <        /*          int wh=0;
217 <                    int nMoth = p.numberOfMothers();
218 <                    for(size_t jj = 0; jj < nMoth; ++ jj) {
219 <                    const Candidate * mom = p.mother( jj );
220 <                    int nmomdau= mom->numberOfDaughters();
221 <                    for(size_t j = 0; j < nmomdau; ++ j) {
222 <                    const Candidate * Wmomdau = mom->daughter( j );
338 <                    if(abs(Wmomdau->pdgId())==24) wh++;
339 <                    }
340 <                    }
341 <                      
342 <                    if(wh==0) continue;
343 <        */
344 <        Hin=i;
345 <        hbbInfo->mcH.status=st;
346 <        hbbInfo->mcH.charge=p.charge();
347 <        if(p.mother(0)!=0) hbbInfo->mcH.momid=p.mother(0)->pdgId();
348 <        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcH.gmomid=p.mother(0)->mother(0)->pdgId();
349 <        hbbInfo->mcH.fourMomentum = GENPTOLOR(p);
350 <          
215 >        
216 >        VHbbEventAuxInfo::ParticleMCInfo htemp;
217 >        htemp.status=st;
218 >        htemp.charge=p.charge();
219 >        if(p.mother(0)!=0) htemp.momid=p.mother(0)->pdgId();
220 >        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) htemp.gmomid=p.mother(0)->mother(0)->pdgId();
221 >        htemp.p4 = GENPTOLOR(p);
222 >        
223          int ndau = p.numberOfDaughters();
224          for(int j = 0; j < ndau; ++ j) {
225            const Candidate * Hdau = p.daughter( j );
226 <          hbbInfo->mcH.dauid.push_back(Hdau->pdgId());
227 <          hbbInfo->mcH.dauFourMomentum.push_back(GENPTOLORP(Hdau));
226 >          htemp.dauid.push_back(Hdau->pdgId());
227 >          htemp.dauFourMomentum.push_back(GENPTOLORP(Hdau));
228          }
229 +        (auxInfo->mcH).push_back(htemp);
230        }
231 +      
232 +      
233 +      if(abs(id)==24){
234          
235 +        VHbbEventAuxInfo::ParticleMCInfo wtemp;
236 +        wtemp.status=st;
237 +        wtemp.charge=p.charge();
238 +        if(p.mother(0)!=0) wtemp.momid=p.mother(0)->pdgId();
239 +        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) wtemp.gmomid=p.mother(0)->mother(0)->pdgId();
240 +        wtemp.p4=GENPTOLOR(p);
241          
360      if(abs(id)==24){
361          
362        Win=i;
363        hbbInfo->mcW.status=st;
364        hbbInfo->mcW.charge=p.charge();
365        if(p.mother(0)!=0) hbbInfo->mcW.momid=p.mother(0)->pdgId();
366        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcW.gmomid=p.mother(0)->mother(0)->pdgId();
367        hbbInfo->mcW.fourMomentum=GENPTOLOR(p);
368
242          int ndau = p.numberOfDaughters();
243          for(int j = 0; j < ndau; ++ j) {
244            const Candidate * Wdau = p.daughter( j );
245 <          hbbInfo->mcW.dauid.push_back(Wdau->pdgId());
246 <          hbbInfo->mcW.dauFourMomentum.push_back(GENPTOLORP(Wdau));
245 >          wtemp.dauid.push_back(Wdau->pdgId());
246 >          wtemp.dauFourMomentum.push_back(GENPTOLORP(Wdau));
247          }
248 +        auxInfo->mcW.push_back(wtemp);
249        }
250          
251        if(abs(id)==23){
252  
253 <        Zin=i;
254 <        hbbInfo->mcZ.status=st;
255 <        hbbInfo->mcZ.charge=p.charge();
256 <        if(p.mother(0)!=0) hbbInfo->mcZ.momid=p.mother(0)->pdgId();
257 <        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcZ.gmomid=p.mother(0)->mother(0)->pdgId();
258 <        hbbInfo->mcZ.fourMomentum=GENPTOLOR(p);
253 >
254 >        VHbbEventAuxInfo::ParticleMCInfo ztemp;
255 >        ztemp.status=st;
256 >        ztemp.charge=p.charge();
257 >        if(p.mother(0)!=0) ztemp.momid=p.mother(0)->pdgId();
258 >        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) ztemp.gmomid=p.mother(0)->mother(0)->pdgId();
259 >        ztemp.p4=GENPTOLOR(p);
260  
261          int ndau = p.numberOfDaughters();
262          for(int j = 0; j < ndau; ++ j) {
263            const Candidate * Zdau = p.daughter( j );
264 <          hbbInfo->mcZ.dauid.push_back(Zdau->pdgId());
265 <          hbbInfo->mcZ.dauFourMomentum.push_back(GENPTOLOR(p));
264 >          ztemp.dauid.push_back(Zdau->pdgId());
265 >          ztemp.dauFourMomentum.push_back(GENPTOLOR(p));
266          }
267 +        auxInfo->mcZ.push_back(ztemp);
268        }
269        //
270        // binfo
271        //
272 <
272 >      
273        
274        if(id==5){
275 <        bin=i;
276 <        hbbInfo->mcB.status=st;
277 <        hbbInfo->mcB.charge=p.charge();
278 <        if(p.mother(0)!=0) hbbInfo->mcB.momid=p.mother(0)->pdgId();
279 <        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcB.gmomid=p.mother(0)->mother(0)->pdgId();
275 >
276 >        VHbbEventAuxInfo::ParticleMCInfo btemp;
277 >        btemp.status=st;
278 >        btemp.charge=p.charge();
279 >        if(p.mother(0)!=0) btemp.momid=p.mother(0)->pdgId();
280 >        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) btemp.gmomid=p.mother(0)->mother(0)->pdgId();
281 >
282 >        btemp.p4=GENPTOLOR(p);
283 >        
284 >        int nHDaubdau = p.numberOfDaughters();
285 >        for(int j = 0; j < nHDaubdau; ++ j) {
286 >          const Candidate * Bdau = p.daughter( j );
287 >          btemp.dauid.push_back(Bdau->pdgId());
288 >        }
289 >        auxInfo->mcB.push_back(btemp);
290        }
291        
292        if(id==-5){
407        bbarin=i;
408        hbbInfo->mcBbar.status=st;
409        hbbInfo->mcBbar.charge=p.charge();
410        if(p.mother(0)!=0) hbbInfo->mcBbar.momid=p.mother(0)->pdgId();
411        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcBbar.gmomid=p.mother(0)->mother(0)->pdgId();
412      }
413      
414      if(abs(id)==4){
415        hbbInfo->mcC.status=st;
416        hbbInfo->mcC.charge=p.charge();
417        if(p.mother(0)!=0) hbbInfo->mcC.momid=p.mother(0)->pdgId();
418        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) hbbInfo->mcC.gmomid=p.mother(0)->mother(0)->pdgId();
419      }
293  
294 +        VHbbEventAuxInfo::ParticleMCInfo bbtemp;
295 +        
296 +        bbtemp.status=st;
297 +        bbtemp.charge=p.charge();
298 +        if(p.mother(0)!=0) bbtemp.momid=p.mother(0)->pdgId();
299 +        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) bbtemp.gmomid=p.mother(0)->mother(0)->pdgId();
300  
301 <    }
301 >        bbtemp.p4=GENPTOLOR(p);
302 >        
303 >        int nHDaubdau = p.numberOfDaughters();
304 >        for(int j = 0; j < nHDaubdau; ++ j) {
305 >          const Candidate * Bdau = p.daughter( j );
306 >          bbtemp.dauid.push_back(Bdau->pdgId());
307 >        }
308  
309  
310 <    if(bin!=-99 && bbarin!=-99){
311 <      const Candidate & bGen = (*genParticles)[bin];
427 <      const Candidate & bbarGen = (*genParticles)[bbarin];
428 <      hbbInfo->mcB.fourMomentum=GENPTOLOR(bGen);
429 <      hbbInfo->mcBbar.fourMomentum=GENPTOLOR(bbarGen);
310 >        auxInfo->mcBbar.push_back(bbtemp);
311 >     }
312        
313 <      int nHDaubdau = bGen.numberOfDaughters();
314 <      for(int j = 0; j < nHDaubdau; ++ j) {
315 <        const Candidate * Bdau = bGen.daughter( j );
316 <        hbbInfo->mcB.dauid.push_back(Bdau->pdgId());
317 <        hbbInfo->mcB.dauFourMomentum.push_back(GENPTOLORP(Bdau));
318 <      }
437 <      int nHDaubbardau = bbarGen.numberOfDaughters();
438 <      for(int j = 0; j < nHDaubbardau; ++ j) {
439 <        const Candidate * Bbardau = bbarGen.daughter( j );
440 <        hbbInfo->mcBbar.dauid.push_back(Bbardau->pdgId());
441 <        hbbInfo->mcBbar.dauFourMomentum.push_back(GENPTOLORP(Bbardau));
442 <      }
313 >      if(abs(id)==4){
314 >        VHbbEventAuxInfo::ParticleMCInfo ctemp;
315 >        ctemp.status=st;
316 >        ctemp.charge=p.charge();
317 >        if(p.mother(0)!=0) ctemp.momid=p.mother(0)->pdgId();
318 >        if(p.mother(0)!=0 && p.mother(0)->mother(0)!=0) ctemp.gmomid=p.mother(0)->mother(0)->pdgId();
319  
320 <  
320 >        ctemp.p4=GENPTOLOR(p);
321 >        
322 >        int nHDaubdau = p.numberOfDaughters();
323 >        for(int j = 0; j < nHDaubdau; ++ j) {
324 >          const Candidate * Bdau = p.daughter( j );
325 >          ctemp.dauid.push_back(Bdau->pdgId());
326 >        }
327  
328 <    }
328 >        auxInfo->mcC.push_back(ctemp);  
329 >
330 >      }
331  
332 +    }
333  
334    }   // isMC
335  
# Line 488 | Line 373 | HbbAnalyzerNew::produce(edm::Event& iEve
373    iEvent.getByLabel(eleLabel_,electronHandle);
374    edm::View<pat::Electron> electrons = *electronHandle;
375  
491  edm::Handle<edm::View<pat::MET> > metHandle;
492  iEvent.getByLabel(metLabel_,metHandle);
493  edm::View<pat::MET> mets = *metHandle;
376  
377    //   edm::Handle<edm::View<pat::Photon> > phoHandle;
378    //   iEvent.getByLabel(phoLabel_,phoHandle);
# Line 500 | Line 382 | HbbAnalyzerNew::produce(edm::Event& iEve
382    iEvent.getByLabel(tauLabel_,tauHandle);
383    edm::View<pat::Tau> taus = *tauHandle;
384  
503  edm::Handle<CandidateView> dimuons;
504  iEvent.getByLabel(dimuLabel_,dimuons);
505
506  edm::Handle<CandidateView> dielectrons;
507  iEvent.getByLabel(dielecLabel_,dielectrons);
385  
386 +  //BTAGGING SCALE FACTOR FROM DATABASE
387 +  //Combined Secondary Vertex Loose
388 +  edm::ESHandle<BtagPerformance> bTagSF_CSVL_;
389 +  iSetup.get<BTagPerformanceRecord>().get("BTAGCSVL",bTagSF_CSVL_);
390 +  //Combined Secondary Vertex Medium
391 +  edm::ESHandle<BtagPerformance> bTagSF_CSVM_;
392 +  iSetup.get<BTagPerformanceRecord>().get("BTAGCSVM",bTagSF_CSVM_);
393 +  //Combined Secondary Vertex Tight
394 +  edm::ESHandle<BtagPerformance> bTagSF_CSVT_;
395 +  iSetup.get<BTagPerformanceRecord>().get("BTAGCSVT",bTagSF_CSVT_);
396 +
397 +  edm::ESHandle<BtagPerformance> mistagSF_CSVL_;
398 +  iSetup.get<BTagPerformanceRecord>().get("MISTAGCSVL",mistagSF_CSVL_);
399 +  //Combined Secondary Vertex Medium
400 +  edm::ESHandle<BtagPerformance> mistagSF_CSVM_;
401 +  iSetup.get<BTagPerformanceRecord>().get("MISTAGCSVM",mistagSF_CSVM_);
402 +  //Combined Secondary Vertex Tight
403 +  edm::ESHandle<BtagPerformance> mistagSF_CSVT_;
404 +  iSetup.get<BTagPerformanceRecord>().get("MISTAGCSVT",mistagSF_CSVT_);
405 +
406 + BTagSFContainer btagSFs;
407 +  btagSFs.BTAGSF_CSVL = (bTagSF_CSVL_.product());
408 +  btagSFs.BTAGSF_CSVM = (bTagSF_CSVM_.product());
409 +  btagSFs.BTAGSF_CSVT = (bTagSF_CSVT_.product());
410 +  btagSFs.MISTAGSF_CSVL = (mistagSF_CSVL_.product());
411 +  btagSFs.MISTAGSF_CSVM = (mistagSF_CSVM_.product());
412 +  btagSFs.MISTAGSF_CSVT = (mistagSF_CSVT_.product());
413  
414 + #ifdef ENABLE_SIMPLEJETS1
415    for(edm::View<pat::Jet>::const_iterator jet_iter = simplejets1.begin(); jet_iter!=simplejets1.end(); ++jet_iter){
416      //     if(jet_iter->pt()>50)
417      //       njetscounter++;
418      VHbbEvent::SimpleJet sj;
419 <    sj.flavour = jet_iter->partonFlavour();
419 >    fillSimpleJet(sj,jet_iter);
420 >    //    if(!runOnMC_)
421  
422 <
517 <    sj.tche=jet_iter->bDiscriminator("trackCountingHighEffBJetTags");
518 <    sj.tchp=jet_iter->bDiscriminator("trackCountingHighPurBJetTags");
519 <    sj.jp=jet_iter->bDiscriminator("jetProbabilityBJetTags");
520 <    sj.jpb=jet_iter->bDiscriminator("jetBProbabilityBJetTags");
521 <    sj.ssvhe=jet_iter->bDiscriminator("simpleSecondaryVertexHighEffBJetTags");
522 <    sj.csv=jet_iter->bDiscriminator("combinedSecondaryVertexBJetTags");
523 <    sj.csvmva=jet_iter->bDiscriminator("combinedSecondaryVertexMVABJetTags");
524 <    sj.charge=jet_iter->jetCharge();
525 <    sj.ntracks=jet_iter->associatedTracks().size();
526 <    sj.fourMomentum=GENPTOLORP(jet_iter);
422 >   setJecUnc(sj,jecUnc);
423  
424      Particle::LorentzVector p4Jet = jet_iter->p4();
425  
426 <    if(isMC){
427 <      double minb1DR=9999.;
428 <      for(size_t i = 0; i < genParticles->size(); ++ i) {
429 <        const GenParticle & p = (*genParticles)[i];
430 <        int id = p.pdgId();
431 <        if(abs(id)<=6 || id==21 || id==23 || abs(id)==24){
432 <          double bb1DR=TMath::Sqrt((p.eta()-p4Jet.eta())*(p.eta()-p4Jet.eta())+
433 <                                   (p.phi()-p4Jet.phi())*(p.phi()-p4Jet.phi()));
434 <          if(bb1DR<minb1DR) {minb1DR=bb1DR; sj.b1BestMCid=id; if(p.mother()!=0) sj.b1BestMCmomid=p.mother()->pdgId();}
426 >    if(runOnMC_){
427 >
428 >      fillScaleFactors(sj, btagSFs);
429 >
430 >      //PAT genJet matching
431 >      //genJet
432 >      const reco::GenJet *gJ = jet_iter->genJet();
433 >      //physical parton for mother info ONLY
434 >      if( (jet_iter->genParton())
435 >          and (jet_iter->genParton()->mother()) )
436 >        sj.bestMCmomid=jet_iter->genParton()->mother()->pdgId();
437 >      TLorentzVector gJp4;
438 >      if(gJ){
439 >        gJp4.SetPtEtaPhiE(gJ->pt(),gJ->eta(),gJ->phi(),gJ->energy());
440 >        sj. bestMCp4mom = gJp4;
441 >        if(verbose_){
442 >          std::clog << "genJet matched Pt = " << gJp4.Pt() << std::endl;
443 >          std::clog << "genJet matched eta = " << gJp4.Eta() << std::endl;
444 >          std::clog << "genJet matched deltaR = " <<gJp4.DeltaR(sj.p4) << std::endl;
445 >          std::clog << "genJet matched mother id = " << sj.bestMCmomid << std::endl;
446          }
447        }
448 <    } //isMC    
448 >      
449 >    } //isMC
450      hbbInfo->simpleJets.push_back(sj);
451      
452    }
453 <  
453 > #endif //ENABLE_SIMPLEJETS1
454 >
455 >  for(edm::View<pat::Jet>::const_iterator jet_iter = simplejets3.begin(); jet_iter!=simplejets3.end(); ++jet_iter){
456 >    //     if(jet_iter->pt()>50)
457 >    //       njetscounter++;
458 >    VHbbEvent::SimpleJet sj;
459 >    fillSimpleJet(sj,jet_iter);
460 >    //    if(!runOnMC_)  
461 >  setJecUnc(sj,jecUnc);
462 >
463 >
464 >   Particle::LorentzVector p4Jet = jet_iter->p4();
465 >
466 >    if(runOnMC_){
467 >
468 >      fillScaleFactors(sj, btagSFs);
469 >
470 >      //PAT genJet matching
471 >      //genJet
472 >      const reco::GenJet *gJ = jet_iter->genJet();
473 >      //physical parton for mother info ONLY
474 >      if( (jet_iter->genParton())
475 >          and (jet_iter->genParton()->mother()) )
476 >        sj.bestMCmomid=jet_iter->genParton()->mother()->pdgId();
477 >      TLorentzVector gJp4;
478 >      if(gJ){
479 >        gJp4.SetPtEtaPhiE(gJ->pt(),gJ->eta(),gJ->phi(),gJ->energy());
480 >        sj. bestMCp4mom = gJp4;
481 >        if(verbose_){
482 >          std::clog << "genJet matched Pt = " << gJp4.Pt() << std::endl;
483 >          std::clog << "genJet matched eta = " << gJp4.Eta() << std::endl;
484 >          std::clog << "genJet matched deltaR = " <<gJp4.DeltaR(sj.p4) << std::endl;
485 >          std::clog << "genJet matched mother id = " << sj.bestMCmomid << std::endl;
486 >        }
487 >      }
488 >      
489 >    } //isMC
490 >    hbbInfo->simpleJets3.push_back(sj);
491 >    
492 >  }
493 >
494 > #ifdef ENABLE_SIMPLEJETS4
495 >  for(edm::View<pat::Jet>::const_iterator jet_iter = simplejets4.begin(); jet_iter!=simplejets4.end(); ++jet_iter){
496 >    //     if(jet_iter->pt()>50)
497 >    //       njetscounter++;
498 >    VHbbEvent::SimpleJet sj;
499 >    fillSimpleJet(sj,jet_iter);
500 >    //    if(!runOnMC_)  
501 >    setJecUnc(sj,jecUnc);
502 >
503 >
504 >    Particle::LorentzVector p4Jet = jet_iter->p4();
505 >
506 >    if(runOnMC_){
507 >
508 >      fillScaleFactors(sj, btagSFs);
509 >
510 >      //PAT genJet matching
511 >      //genJet
512 >      const reco::GenJet *gJ = jet_iter->genJet();
513 >      //physical parton for mother info ONLY
514 >      if( (jet_iter->genParton())
515 >          and (jet_iter->genParton()->mother()) )
516 >        sj.bestMCmomid=jet_iter->genParton()->mother()->pdgId();
517 >      TLorentzVector gJp4;
518 >      if(gJ){
519 >        gJp4.SetPtEtaPhiE(gJ->pt(),gJ->eta(),gJ->phi(),gJ->energy());
520 >        sj. bestMCp4mom = gJp4;
521 >        if(verbose_){
522 >          std::clog << "genJet matched Pt = " << gJp4.Pt() << std::endl;
523 >          std::clog << "genJet matched eta = " << gJp4.Eta() << std::endl;
524 >          std::clog << "genJet matched deltaR = " <<gJp4.DeltaR(sj.p4) << std::endl;
525 >          std::clog << "genJet matched mother id = " << sj.bestMCmomid << std::endl;
526 >        }
527 >      }
528 >      
529 >    } //isMC
530 >    hbbInfo->simpleJets4.push_back(sj);
531 >    
532 >  }
533 > #endif //ENABLE SIMPLEJETS4
534 >
535    
536    for(edm::View<pat::Jet>::const_iterator jet_iter = simplejets2.begin(); jet_iter!=simplejets2.end(); ++jet_iter){
537      
538      VHbbEvent::SimpleJet sj;
539 <    sj.flavour = jet_iter->partonFlavour();
539 >    fillSimpleJet(sj,jet_iter);    
540 >    //  if(!runOnMC_)  
541 > setJecUnc(sj,jecUnc);
542 >    /*    sj.flavour = jet_iter->partonFlavour();
543      
544      
545      sj.tche=jet_iter->bDiscriminator("trackCountingHighEffBJetTags");
# Line 559 | Line 551 | HbbAnalyzerNew::produce(edm::Event& iEve
551      sj.csvmva=jet_iter->bDiscriminator("combinedSecondaryVertexMVABJetTags");
552      sj.charge=jet_iter->jetCharge();
553      sj.ntracks=jet_iter->associatedTracks().size();
554 <    sj.fourMomentum=GENPTOLORP(jet_iter);
554 >    sj.p4=GENPTOLORP(jet_iter);
555 >    sj.chargedTracksFourMomentum=(getChargedTracksMomentum(&*(jet_iter)));
556 >    sj.SF_CSVL=1;
557 >    sj.SF_CSVM=1;
558 >    sj.SF_CSVT=1;
559 >    sj.SF_CSVLerr=0;
560 >    sj.SF_CSVMerr=0;
561 >    sj.SF_CSVTerr=0;
562 >
563 >    //
564 >    // addtaginfo for csv
565 >    //
566 >
567 >    if (jet_iter->hasTagInfo("SimpleSecondaryVertex")) {
568 >
569 >      const reco::SecondaryVertexTagInfo * tf = jet_iter->tagInfoSecondaryVertex();
570 >      sj.vtxMass = tf->secondaryVertex(0).p4().mass();
571 >      sj.vtxNTracks = tf->secondaryVertex(0).nTracks();
572 >      Measurement1D m = tf->flightDistance(0);
573 >      sj.vtx3dL = m.value();
574 >      sj.vtx3deL = m.error();
575 >    }
576 >
577  
578 +    //
579 +    // add tVector
580 +    //
581 +    sj.tVector = getTvect(&(*jet_iter));
582 +    */
583      Particle::LorentzVector p4Jet = jet_iter->p4();
584  
585 <    if(isMC){
586 <      double minb2DR=9999.;
587 <      for(size_t i = 0; i < genParticles->size(); ++ i) {
588 <        const GenParticle & p = (*genParticles)[i];
589 <        int id = p.pdgId();
590 <        if(abs(id)<=6 || id==21 || id==23 || abs(id)==24){
591 <          double bb2DR=TMath::Sqrt((p.eta()-p4Jet.eta())*(p.eta()-p4Jet.eta())+
592 <                                   (p.phi()-p4Jet.phi())*(p.phi()-p4Jet.phi()));
593 <          if(bb2DR<minb2DR) {minb2DR=bb2DR; sj.b1BestMCid=id; if(p.mother()!=0) sj.b1BestMCmomid=p.mother()->pdgId();}
585 >    if(runOnMC_){
586 >
587 >      //BTV scale factors
588 >      fillScaleFactors(sj, btagSFs);
589 >
590 >      //PAT genJet matching
591 >      //genJet
592 >      const reco::GenJet *gJ = jet_iter->genJet();
593 >      //physical parton for mother info ONLY
594 >      if( (jet_iter->genParton())
595 >          and (jet_iter->genParton()->mother()) )
596 >        sj.bestMCmomid=jet_iter->genParton()->mother()->pdgId();
597 >      TLorentzVector gJp4;
598 >      if(gJ){
599 >        gJp4.SetPtEtaPhiE(gJ->pt(),gJ->eta(),gJ->phi(),gJ->energy());
600 >        sj. bestMCp4mom = gJp4;
601 >        if(verbose_){
602 >          std::clog << "genJet matched Pt = " << gJp4.Pt() << std::endl;
603 >          std::clog << "genJet matched eta = " << gJp4.Eta() << std::endl;
604 >          std::clog << "genJet matched deltaR = " << gJp4.DeltaR(sj.p4) << std::endl;
605 >          std::clog << "genJet matched mother id = " << sj.bestMCmomid << std::endl;
606          }
607        }
608 +
609      }   //isMC
610      
611      hbbInfo->simpleJets2.push_back(sj);
# Line 611 | Line 643 | HbbAnalyzerNew::produce(edm::Event& iEve
643      //    if(printJet) {std::cout << "NsubJets: " << constituents.size() << "\n";}
644      VHbbEvent::HardJet hj;
645      hj.constituents=constituents.size();
646 <    hj.fourMomentum =GENPTOLORP(jet_iter);
647 <
646 >    hj.p4 =GENPTOLORP(jet_iter);
647 >    
648      for (unsigned int iJC(0); iJC<constituents.size(); ++iJC ){
649        Jet::Constituent icandJet = constituents[iJC];
650  
# Line 623 | Line 655 | HbbAnalyzerNew::produce(edm::Event& iEve
655        hj.subFourMomentum.push_back(GENPTOLORP(icandJet));
656        hj.etaSub.push_back(icandJet->eta());
657        hj.phiSub.push_back(icandJet->phi());
626
658      
659      }
660      hbbInfo->hardJets.push_back(hj);
# Line 646 | Line 677 | HbbAnalyzerNew::produce(edm::Event& iEve
677                              << "," << subjet_iter->bDiscriminator("combinedSecondaryVertexBJetTags") << "\n";}
678  
679      VHbbEvent::SimpleJet sj;
680 <
681 <    sj.flavour = subjet_iter->partonFlavour();
682 <    
680 >    fillSimpleJet(sj,subjet_iter);
681 >    //  if(!runOnMC_)  
682 >    setJecUnc(sj,jecUnc);
683 >    /*    sj.flavour = subjet_iter->partonFlavour();
684 >    sj.tVector = getTvect(&(*subjet_iter));
685      sj.tche=subjet_iter->bDiscriminator("trackCountingHighEffBJetTags");
686      sj.tchp=subjet_iter->bDiscriminator("trackCountingHighPurBJetTags");
687      sj.jp=subjet_iter->bDiscriminator("jetProbabilityBJetTags");
# Line 658 | Line 691 | HbbAnalyzerNew::produce(edm::Event& iEve
691      sj.csvmva=subjet_iter->bDiscriminator("combinedSecondaryVertexMVABJetTags");
692      sj.charge=subjet_iter->jetCharge();
693      sj.ntracks=subjet_iter->associatedTracks().size();
694 <    sj.fourMomentum=GENPTOLORP(subjet_iter);
694 >    sj.p4=GENPTOLORP(subjet_iter);
695 >    sj.p4=(getChargedTracksMomentum(&*(subjet_iter)));
696  
697 +    //
698 +    // addtaginfo for csv
699 +    //
700 +
701 +    if (subjet_iter->hasTagInfo("SimpleSecondaryVertex")) {
702 +
703 +      const reco::SecondaryVertexTagInfo * tf = subjet_iter->tagInfoSecondaryVertex();
704 +      sj.vtxMass = tf->secondaryVertex(0).p4().mass();
705 +      sj.vtxNTracks = tf->secondaryVertex(0).nTracks();
706 +      Measurement1D m = tf->flightDistance(0);
707 +      sj.vtx3dL = m.value();
708 +      sj.vtx3deL = m.error();
709 +    }
710 +    */
711      hbbInfo->subJets.push_back(sj);
712  
713    }
# Line 669 | Line 717 | HbbAnalyzerNew::produce(edm::Event& iEve
717    // met is calomet
718    //
719  
672
673  for(edm::View<pat::MET>::const_iterator met = mets.begin(); met!=mets.end(); ++met){
674    hbbInfo->calomet.sumEt=met->sumEt();
675    hbbInfo->calomet.metSig=met->mEtSig();
676    hbbInfo->calomet.eLong=met->e_longitudinal();
677    hbbInfo->calomet.fourMomentum=GENPTOLORP(met);
678  }
679
720    edm::Handle<edm::View<pat::MET> > metTCHandle;
721    iEvent.getByLabel("patMETsTC",metTCHandle);
722    edm::View<pat::MET> metsTC = *metTCHandle;
723 <  for(edm::View<pat::MET>::const_iterator metTC = metsTC.begin(); metTC!=metsTC.end(); ++metTC){
724 <    hbbInfo->calomet.sumEt=metTC->sumEt();
725 <    hbbInfo->calomet.metSig=metTC->mEtSig();
726 <    hbbInfo->calomet.eLong=metTC->e_longitudinal();
727 <    hbbInfo->calomet.fourMomentum=GENPTOLORP(metTC);
723 >  if(metsTC.size()){
724 >    hbbInfo->tcmet.sumEt=(metsTC[0]).sumEt();
725 >    hbbInfo->tcmet.metSig=(metsTC[0]).significance();
726 >    hbbInfo->tcmet.eLong=(metsTC[0]).e_longitudinal();
727 >    hbbInfo->tcmet.p4=GENPTOLOR((metsTC[0]));
728 >    if (verbose_)     std::cout <<" METTC "<<     hbbInfo->tcmet.metSig <<" " <<     hbbInfo->tcmet.sumEt<<std::endl;
729 >  }
730 >  
731 >
732 >  edm::Handle<edm::View<reco::MET> > mHTHandle;
733 >  iEvent.getByLabel("patMETsHT",mHTHandle);
734 >  edm::View<reco::MET> metsHT = *mHTHandle;
735 >  if(metsHT.size()){
736 >    hbbInfo->mht.sumEt=(metsHT[0]).sumEt();
737 >    hbbInfo->mht.metSig=(metsHT[0]).significance();
738 >    hbbInfo->mht.eLong=(metsHT[0]).e_longitudinal();
739 >    hbbInfo->mht.p4=GENPTOLOR((metsHT[0]));
740 >    if (verbose_)     std::cout <<" METHT "<<     hbbInfo->mht.metSig <<" " <<     hbbInfo->mht.sumEt<<std::endl;
741 >  }
742 >  
743 >  edm::Handle<edm::View<pat::MET> > metHandle;
744 >  iEvent.getByLabel(metLabel_,metHandle);
745 >  edm::View<pat::MET> mets = *metHandle;
746 >  
747 >  if(mets.size()){
748 >    hbbInfo->calomet.sumEt=(mets[0]).sumEt();
749 >    hbbInfo->calomet.metSig=(mets[0]).significance();
750 >    hbbInfo->calomet.eLong=(mets[0]).e_longitudinal();
751 >    hbbInfo->calomet.p4=GENPTOLOR((mets[0]));
752 >    if (verbose_)     std::cout <<" METCALO "<<     hbbInfo->calomet.metSig <<" " <<     hbbInfo->calomet.sumEt<<std::endl;
753    }
754 +  
755    edm::Handle<edm::View<pat::MET> > metPFHandle;
756    iEvent.getByLabel("patMETsPF",metPFHandle);
757    edm::View<pat::MET> metsPF = *metPFHandle;
758 <  for(edm::View<pat::MET>::const_iterator metPF = metsPF.begin(); metPF!=metsPF.end(); ++metPF){
759 <    hbbInfo->calomet.sumEt=metPF->sumEt();
760 <    hbbInfo->calomet.metSig=metPF->mEtSig();
761 <    hbbInfo->calomet.eLong=metPF->e_longitudinal();
762 <    hbbInfo->calomet.fourMomentum=GENPTOLORP(metPF);
758 >  
759 >  if(metsPF.size()){
760 >    hbbInfo->pfmet.sumEt=(metsPF[0]).sumEt();
761 >    hbbInfo->pfmet.metSig=(metsPF[0]).significance();
762 >    hbbInfo->pfmet.eLong=(metsPF[0]).e_longitudinal();
763 >    hbbInfo->pfmet.p4=GENPTOLOR((metsPF[0]));
764 >    if (verbose_)     std::cout <<" METPF "<<     hbbInfo->pfmet.metSig <<" " <<     hbbInfo->pfmet.sumEt<<std::endl;
765 >  }
766 >  
767 >  
768 >  if(verbose_){
769 >    std::cout << "METs: calomet "<<mets.size()<<" tcmet"<<metsTC.size()<<" pfmet "<<metsPF.size()<<" MHT" <<metsHT.size()<<std::endl;  
770    }
771  
772 <
772 >  if(verbose_)
773 >    std::cout << " INPUT MUONS "<<muons.size()<<std::endl;
774  
775    for(edm::View<pat::Muon>::const_iterator mu = muons.begin(); mu!=muons.end(); ++mu){
776      VHbbEvent::MuonInfo mf;
777 <    mf.fourMomentum =GENPTOLORP( mu);
777 >    mf.p4 =GENPTOLORP( mu);
778      mf.charge=mu->charge();
779      mf.tIso=mu->trackIso();
780      mf.eIso=mu->ecalIso();
781      mf.hIso=mu->hcalIso();
782 <    Geom::Phi<double> deltaphi(mu->phi()-atan2(mf.fourMomentum.Px(), mf.fourMomentum.Py()));
782 >    mf.pfChaIso=mu->chargedHadronIso();
783 >    mf.pfPhoIso=mu->photonIso();
784 >    mf.pfNeuIso=mu->neutralHadronIso();
785 >    Geom::Phi<double> deltaphi(mu->phi()-atan2(mf.p4.Px(), mf.p4.Py()));
786      double acop = deltaphi.value();
787      mf.acop=acop;
788  
789      mf.ipDb=mu->dB();
790      mf.ipErrDb=mu->edB();
791 <    if(mu->isGlobalMuon()) mf.cat=1;
792 <    else if(mu->isTrackerMuon()) mf.cat=2;
793 <    else mf.cat=3;
791 >    mf.cat=0;
792 >    if(mu->isGlobalMuon()) mf.cat|=1;
793 >    if(mu->isTrackerMuon()) mf.cat|=2;
794 >    if(mu->isStandAloneMuon()) mf.cat|=4;
795      TrackRef trkMu1Ref = mu->get<TrackRef>();
796      if(trkMu1Ref.isNonnull()){
797        const Track* MuTrk1 = mu->get<TrackRef>().get();
# Line 730 | Line 808 | HbbAnalyzerNew::produce(edm::Event& iEve
808        const reco::HitPattern& q = gTrack->hitPattern();
809        mf.globChi2=gTrack.get()->normalizedChi2();
810        mf.globNHits=q.numberOfValidMuonHits();
811 +      mf. validMuStations = q. muonStationsWithValidHits();
812      }else{
813        mf.globChi2=-99;
814        mf.globNHits=-99;
815      }
816  
817 +    //Muon trigger matching
818 +    for (int itrig = 0; itrig != ntrigs; ++itrig){
819 +      std::string trigName=triggerNames_.triggerName(itrig);
820 +      if( (mu->triggerObjectMatchesByPath(trigName,false,false).size() != 0) ){
821 +        mf.hltMatchedBits.push_back(itrig);
822 +        if(verbose_){
823 +          std::clog << "Trigger Matching box" << std::endl;
824 +          std::clog << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
825 +          std::clog << "Matching parameters are defined in the cfg" << std::endl;
826 +          std::clog << "Trigger bit = " << itrig << std::endl;
827 +          std::clog << "Trigger name = " << trigName << std::endl;
828 +          std::clog << "Trigger object matched collection size = " << mu->triggerObjectMatchesByPath(trigName,false,false).size() << std::endl;
829 +          std::clog << "Pat Muon pt = " << mf.p4.Pt() << " HLT object matched = " << mu->triggerObjectMatch(0)->p4().Pt() << std::endl;
830 +          std::clog << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
831 +        }
832 +      }
833 +    }
834 +    //
835 +
836 +    // add stamuon
837 +
838 +    //    if (mu->isStandAloneMuon()) {
839 +    //      reco::TrackRef sta = mu->standAloneMuon();
840 +    //      
841 +    //    }
842 +
843 +
844      //     int muInfo[12];
845      //     fillMuBlock(mu,  muInfo);
846 <    if(isMC){
846 >    if(runOnMC_){
847        const GenParticle* muMc = mu->genLepton();
848        if(muMc!=0){
849          mf.mcId=muMc->pdgId();
# Line 748 | Line 854 | HbbAnalyzerNew::produce(edm::Event& iEve
854      hbbInfo->muInfo.push_back(mf);
855    }
856  
857 <
857 > if(verbose_)
858 >    std::cout << " INPUT electrons "<<electrons.size()<<std::endl;
859    for(edm::View<pat::Electron>::const_iterator elec = electrons.begin(); elec!=electrons.end(); ++elec){
860      VHbbEvent::ElectronInfo ef;
861 <    ef.fourMomentum=GENPTOLORP(elec);
861 >    ef.p4=GENPTOLORP(elec);
862      ef.scEta =elec->superCluster()->eta();
863      ef.scPhi =elec->superCluster()->phi();
864      //    if(ElecEta[eleccont]!=0) ElecEt[eleccont]=elec->superCluster()->energy()/cosh(elec->superCluster()->eta());
# Line 759 | Line 866 | HbbAnalyzerNew::produce(edm::Event& iEve
866      ef.tIso=elec->trackIso();
867      ef.eIso=elec->ecalIso();
868      ef.hIso=elec->hcalIso();
869 <    Geom::Phi<double> deltaphi(elec->superCluster()->phi()-atan2(hbbInfo->calomet.fourMomentum.Py(),hbbInfo->calomet.fourMomentum.Px()));
869 >    ef.pfChaIso=elec->chargedHadronIso();
870 >    ef.pfPhoIso=elec->photonIso();
871 >    ef.pfNeuIso=elec->neutralHadronIso();
872 >
873 >    Geom::Phi<double> deltaphi(elec->superCluster()->phi()-atan2(hbbInfo->calomet.p4.Py(),hbbInfo->calomet.p4.Px()));
874      ef.acop = deltaphi.value();
875 <    
876 <    if(isMC){
875 >    //
876 >    // fill eleids
877 >    //    
878 > /*    ef.id95 = elec->electronID("simpleEleId95cIso");
879 >    ef.id85 = elec->electronID("simpleEleId85cIso");
880 >    ef.id70 = elec->electronID("simpleEleId70cIso");
881 >    ef.id95r = elec->electronID("simpleEleId95relIso");
882 >    ef.id70r = elec->electronID("simpleEleId70relIso");
883 >    ef.id85r = elec->electronID("simpleEleId85relIso");
884 > */
885 >    ef.id95 =elec->electronID("eidVBTFCom95");
886 >    ef.id95r=elec->electronID("eidVBTFRel95");
887 >    ef.id85 =elec->electronID("eidVBTFCom85");
888 >    ef.id85r=elec->electronID("eidVBTFRel85");
889 >    ef.id80 =elec->electronID("eidVBTFCom80");
890 >    ef.id80r=elec->electronID("eidVBTFRel80");
891 >    ef.id70 =elec->electronID("eidVBTFCom70");
892 >    ef.id70r=elec->electronID("eidVBTFRel70");
893 >
894 >    //Electron trigger matching
895 >    for (int itrig = 0; itrig != ntrigs; ++itrig){
896 >      std::string trigName=triggerNames_.triggerName(itrig);
897 >      if( (elec->triggerObjectMatchesByPath(trigName).size() != 0) ){
898 >        ef.hltMatchedBits.push_back(itrig);
899 >        if(verbose_){
900 >          std::clog << "Trigger Matching box" << std::endl;
901 >          std::clog << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
902 >          std::clog << "Matching parameters are defined in the cfg" << std::endl;
903 >          std::clog << "Trigger bit = " << itrig << std::endl;
904 >          std::clog << "Trigger name = " << trigName << std::endl;
905 >          std::clog << "Trigger object matched collection size = " << elec->triggerObjectMatchesByPath(trigName).size() << std::endl;
906 >          std::clog << "Pat Electron pt = " << ef.p4.Pt() << " HLT object matched = " << elec->triggerObjectMatch(0)->p4().Pt() << std::endl;
907 >          std::clog << "+++++++++++++++++++++++++++++++++++++++++++++++++" << std::endl;
908 >        }
909 >      }
910 >    }
911 >
912 >    if(runOnMC_){
913        const GenParticle* elecMc = elec->genLepton();
914        if(elecMc!=0){
915          ef.mcId=elecMc->pdgId();
# Line 773 | Line 920 | HbbAnalyzerNew::produce(edm::Event& iEve
920      hbbInfo->eleInfo.push_back(ef);
921    }
922  
923 +  if(verbose_)
924 +    std::cout << " INPUT taus "<<taus.size()<<std::endl;
925    for(edm::View<pat::Tau>::const_iterator tau = taus.begin(); tau!=taus.end(); ++tau){
926      VHbbEvent::TauInfo tf;
927 <    tf.fourMomentum=GENPTOLORP(tau);
927 >    tf.p4=GENPTOLORP(tau);
928      tf.charge=tau->charge();
929      tf.tIso=tau->trackIso();
930      tf.eIso=tau->ecalIso();
931      tf.hIso=tau->hcalIso();
932 <    Geom::Phi<double> deltaphi(tau->phi()-atan2(hbbInfo->calomet.fourMomentum.Py(),hbbInfo->calomet.fourMomentum.Px()));
932 >    Geom::Phi<double> deltaphi(tau->phi()-atan2(hbbInfo->calomet.p4.Py(),hbbInfo->calomet.p4.Px()));
933      double acop = deltaphi.value();
934      tf.acop=acop;
935      tf.idbyIso=tau->tauID("byIsolation");
# Line 793 | Line 942 | HbbAnalyzerNew::produce(edm::Event& iEve
942      hbbInfo->tauInfo.push_back(tf);
943    }
944  
945 +  CompareJetPtMuons ptComparatorMu;
946 +  CompareJetPtElectrons ptComparatorE;
947 +  CompareJetPtTaus ptComparatorTau;
948 +
949 +  std::sort(hbbInfo->muInfo.begin(), hbbInfo->muInfo.end(), ptComparatorMu);
950 +  std::sort(hbbInfo->eleInfo.begin(), hbbInfo->eleInfo.end(), ptComparatorE);
951 +  std::sort(hbbInfo->tauInfo.begin(), hbbInfo->tauInfo.end(), ptComparatorTau);
952  
797  // dimuons and dielectrons
798
799  for( size_t i = 0; i < dimuons->size(); i++ ) {
800    VHbbEvent::DiMuonInfo df;
801    const Candidate & dimuonCand = (*dimuons)[ i ];
802    df.fourMomentum= GENPTOLOR(dimuonCand);
803    const Candidate * lep0 = dimuonCand.daughter( 0 );
804    const Candidate * lep1 = dimuonCand.daughter( 1 );
805    // needed to access specific methods of pat::Muon
806    const pat::Muon & muonDau0 = dynamic_cast<const pat::Muon &>(*lep0->masterClone());
807    const pat::Muon & muonDau1 = dynamic_cast<const pat::Muon &>(*lep1->masterClone());
808    
809    df.daughter1.fourMomentum=GENPTOLOR(muonDau0);
810    df.daughter2.fourMomentum=GENPTOLOR(muonDau1);
811    
812    df.daughter1.tIso= muonDau0.trackIso();
813    df.daughter2.tIso= muonDau1.trackIso();
814
815    df.daughter1.eIso= muonDau0.ecalIso();
816    df.daughter2.eIso= muonDau1.ecalIso();
817
818    df.daughter1.hIso= muonDau0.hcalIso();
819    df.daughter2.hIso= muonDau1.hcalIso();
820
821    df.daughter1.ipDb=muonDau0.dB();
822    df.daughter2.ipDb=muonDau1.dB();
823
824    df.daughter1.ipErrDb=muonDau0.edB();
825    df.daughter2.ipErrDb=muonDau1.edB();
826
827
828    if(muonDau0.isGlobalMuon()) df.daughter1.cat =1;
829    else if(muonDau0.isTrackerMuon()) df.daughter1.cat=2;
830    else df.daughter1.cat=3;
831    if(muonDau1.isGlobalMuon()) df.daughter2.cat =1;
832    else if(muonDau1.isTrackerMuon()) df.daughter2.cat=2;
833    else df.daughter2.cat=3;
834
835    TrackRef trkMu1Ref = muonDau0.get<TrackRef>();
836    TrackRef trkMu2Ref = muonDau1.get<TrackRef>();
837
838    if(trkMu1Ref.isNonnull() && trkMu2Ref.isNonnull()){
839      const Track* MuTrk1 = muonDau0.get<TrackRef>().get();
840      const Track* MuTrk2 = muonDau1.get<TrackRef>().get();
841      df.daughter1.zPVPt=MuTrk1->dz(RecVtxFirst.position());
842      df.daughter1.zPVProb=MuTrk1->dz(RecVtx.position());
843      df.daughter2.zPVPt=MuTrk2->dz(RecVtxFirst.position());
844      df.daughter2.zPVProb=MuTrk2->dz(RecVtx.position());
845
846      df.daughter1.nHits = MuTrk1->numberOfValidHits();
847      df.daughter2.nHits = MuTrk2->numberOfValidHits();
953  
954 <      df.daughter1.chi2 = MuTrk1->normalizedChi2();
850 <      df.daughter2.chi2 = MuTrk2->normalizedChi2();
851 <
852 <      TrackRef iTrack1 = muonDau0.innerTrack();
853 <      const reco::HitPattern& p1 = iTrack1->hitPattern();
854 <      TrackRef iTrack2 = muonDau1.innerTrack();
855 <      const reco::HitPattern& p2 = iTrack2->hitPattern();
856 <
857 <      df.daughter1.nPixelHits = p1.pixelLayersWithMeasurement();
858 <      df.daughter2.nPixelHits = p2.pixelLayersWithMeasurement();
859 <
860 <      if(muonDau0.isGlobalMuon()){
861 <        TrackRef gTrack = muonDau0.globalTrack();
862 <        const reco::HitPattern& q = gTrack->hitPattern();
863 <        df.daughter1.globNHits=q.numberOfValidMuonHits();
864 <        df.daughter1.globChi2=gTrack.get()->normalizedChi2();
865 <      }
866 <      if(muonDau1.isGlobalMuon()){
867 <        TrackRef gTrack = muonDau1.globalTrack();
868 <        const reco::HitPattern& q = gTrack->hitPattern();
869 <        df.daughter2.globNHits=q.numberOfValidMuonHits();
870 <        df.daughter2.globChi2=gTrack.get()->normalizedChi2();
871 <      }
954 >    
955    
956 <    }
957 <      
958 <    hbbInfo->diMuonInfo.push_back(df);
956 >   if (verbose_){
957 >     std::cout <<" Pushing hbbInfo "<<std::endl;
958 >     std::cout <<" SimpleJets1 = "<<hbbInfo->simpleJets.size()<<std::endl<<
959 >       " SimpleJets2 = "<<hbbInfo->simpleJets2.size()<<std::endl<<
960 >       " SubJets = "<<hbbInfo->subJets.size()<<std::endl<<
961 >       " HardJets = "<<hbbInfo->hardJets.size()<<std::endl<<
962 >       " Muons = "<<hbbInfo->muInfo.size()<<std::endl<<
963 >       " Electrons = "<<hbbInfo->eleInfo.size()<<std::endl<<
964 >       " Taus = "<<hbbInfo->tauInfo.size()<<std::endl<<
965 >       " Electrons = "<<hbbInfo->eleInfo.size()<<std::endl<<
966 >       "--------------------- "<<std::endl;
967    }
968  
878  for( size_t i = 0; i < dielectrons->size(); i++ ) {
879    VHbbEvent::DiElectronInfo df;
880    const Candidate & dielecCand = (*dielectrons)[ i ];
881
882    df.fourMomentum=GENPTOLOR(dielecCand);
883
884    // accessing the daughters of the dimuon candidate
885    const Candidate * lep0 = dielecCand.daughter( 0 );
886    const Candidate * lep1 = dielecCand.daughter( 1 );
887    // needed to access specific methods of pat::Muon
888    const pat::Electron & elecDau0 = dynamic_cast<const pat::Electron &>(*lep0->masterClone());
889    const pat::Electron & elecDau1 = dynamic_cast<const pat::Electron &>(*lep1->masterClone());
890
891    df.daughter1.fourMomentum = GENPTOLOR(elecDau0);
892    df.daughter2.fourMomentum = GENPTOLOR(elecDau1);
969  
894    df.daughter1.tIso = elecDau0.trackIso();
895    df.daughter2.tIso = elecDau1.trackIso();
896
897    df.daughter1.eIso = elecDau0.ecalIso();
898    df.daughter2.eIso = elecDau1.ecalIso();
899
900    df.daughter1.hIso = elecDau0.hcalIso();
901    df.daughter2.hIso = elecDau1.hcalIso();
902    
903    
904    hbbInfo->diElectronInfo.push_back(df);
905    
906  }
970    iEvent.put(hbbInfo);
971 +  iEvent.put(auxInfo);
972 +
973  
974   }
975    
# Line 939 | Line 1004 | void
1004   HbbAnalyzerNew::endJob() {
1005   }
1006  
1007 + TVector2 HbbAnalyzerNew::getTvect( const pat::Jet* patJet ){
1008 +
1009 +  TVector2 t_Vect(0,0);
1010 +  TVector2 null(0,0);
1011 +  TVector2 ci(0,0);
1012 +  TLorentzVector pi(0,0,0,0);
1013 +  TLorentzVector J(0,0,0,0);
1014 +  TVector2 r(0,0);
1015 +  double patJetpfcPt = 1e10;
1016 +  double r_mag = 1e10;
1017 +  unsigned int nOfconst = 0;
1018 +
1019 +
1020 +  if (patJet->isPFJet() == false) {
1021 +    return t_Vect;
1022 +  }
1023 +  
1024 +
1025 +  //re-reconstruct the jet direction with the charged tracks
1026 +  std::vector<reco::PFCandidatePtr>
1027 +    patJetpfc = patJet->getPFConstituents();
1028 +  for(size_t idx = 0; idx < patJetpfc.size(); idx++){
1029 +    if( patJetpfc.at(idx)->charge() != 0 ){
1030 +      pi.SetPtEtaPhiE( patJetpfc.at(idx)->pt(), patJetpfc.at(idx)->eta(), patJetpfc.at(idx)->phi(), patJetpfc.at(idx)->energy() );
1031 +      J += pi;
1032 +      nOfconst++;
1033 +    }
1034 +  }
1035 + // if there are less than two charged tracks do not calculate the pull (there is not enough info). It returns a null vector
1036 +
1037 +  if( nOfconst < 2 )
1038 +    return null;
1039 +  
1040 +
1041 +
1042 +  TVector2 v_J( J.Rapidity(), J.Phi() );
1043 + //calculate TVector using only charged tracks
1044 +  for(size_t idx = 0; idx < patJetpfc.size(); idx++){
1045 +    if( patJetpfc.at(idx)->charge() != 0  ){
1046 +      patJetpfcPt = patJetpfc.at(idx)->pt();
1047 +      pi.SetPtEtaPhiE( patJetpfc.at(idx)->pt(), patJetpfc.at(idx)->eta(), patJetpfc.at(idx)->phi(), patJetpfc.at(idx)->energy() );
1048 +      r.Set( pi.Rapidity() - J.Rapidity(), Geom::deltaPhi( patJetpfc.at(idx)->phi(), J.Phi() ) );
1049 +      r_mag = r.Mod();
1050 +      t_Vect += ( patJetpfcPt / J.Pt() ) * r_mag * r;
1051 +    }
1052 +  }
1053 +
1054 +  
1055 +  return t_Vect;
1056 +  
1057 + }
1058 +
1059 + TLorentzVector HbbAnalyzerNew::getChargedTracksMomentum(const pat::Jet* patJet ){
1060 +  //  return TLorentzVector();
1061 +  TLorentzVector pi(0,0,0,0);
1062 +  TLorentzVector v_j1(0,0,0,0);
1063 +
1064 +
1065 +  //  std::cout <<"fff ECCCCCCOOOOO "<<patJet->isPFJet()<<std::endl;
1066 +
1067 +  if (patJet->isPFJet() == false ){
1068 +      v_j1 = GENPTOLORP(patJet);
1069 +      return v_j1;
1070 +  }
1071 +  std::vector<reco::PFCandidatePtr>
1072 +    j1pfc = patJet->getPFConstituents();
1073 +  for(size_t idx = 0; idx < j1pfc.size(); idx++){
1074 +    if( j1pfc.at(idx)->charge() != 0 ){
1075 +      pi.SetPtEtaPhiE( j1pfc.at(idx)->pt(), j1pfc.at(idx)->eta(), j1pfc.at(idx)->phi(), j1pfc.at(idx)->energy() );
1076 +      v_j1 += pi;
1077 +    }
1078 +  }
1079 +  return v_j1;
1080 +  //re-
1081 + }
1082 +
1083 +
1084 + //Btagging scale factors
1085 + void HbbAnalyzerNew::fillScaleFactors(VHbbEvent::SimpleJet& sj, BTagSFContainer iSF){
1086 +
1087 +
1088 +  BinningPointByMap measurePoint;
1089 +  //for a USDG
1090 +  //for CB jets
1091 +  //scale factor 1 for CB jets over 240GeV/c
1092 +  if( TMath::Abs(sj.flavour) == 4 or TMath::Abs(sj.flavour) == 5 ){
1093 +    measurePoint.insert( BinningVariables::JetEt, sj.p4.Et() );
1094 +    measurePoint.insert( BinningVariables::JetAbsEta, fabs(sj.p4.Eta()) );
1095 +    if( iSF.BTAGSF_CSVL->isResultOk(PerformanceResult::BTAGBEFFCORR , measurePoint) ){
1096 +      sj.SF_CSVL = iSF.BTAGSF_CSVL->getResult(PerformanceResult::BTAGBEFFCORR , measurePoint);
1097 +      sj.SF_CSVLerr = iSF.BTAGSF_CSVL->getResult(PerformanceResult::BTAGBERRCORR , measurePoint);        
1098 +      if(verbose_){
1099 +        std::clog << "C/B Jet flavour = " << sj.flavour << std::endl;
1100 +        std::clog << "C/B Jet Et = " << sj.p4.Et() << std::endl;
1101 +        std::clog << "C/B Jet eta = " << sj.p4.Eta() << std::endl;          
1102 +        std::clog << "C/B CSVL Scale Factor = " << sj.SF_CSVL << std::endl;
1103 +        std::clog << "C/B CSVL Scale Factor error = " << sj.SF_CSVLerr << std::endl;
1104 +      }
1105 +    }
1106 +    if( iSF.BTAGSF_CSVM->isResultOk(PerformanceResult::BTAGBEFFCORR , measurePoint) ){
1107 +      sj.SF_CSVM = iSF.BTAGSF_CSVM->getResult(PerformanceResult::BTAGBEFFCORR , measurePoint);
1108 +      sj.SF_CSVMerr = iSF.BTAGSF_CSVM->getResult(PerformanceResult::BTAGBERRCORR , measurePoint);        
1109 +    }
1110 +    if( iSF.BTAGSF_CSVT->isResultOk(PerformanceResult::BTAGBEFFCORR , measurePoint) ){
1111 +      sj.SF_CSVT = iSF.BTAGSF_CSVT->getResult(PerformanceResult::BTAGBEFFCORR , measurePoint);
1112 +      sj.SF_CSVTerr = iSF.BTAGSF_CSVT->getResult(PerformanceResult::BTAGBERRCORR , measurePoint);        
1113 +    }
1114 +    else{
1115 +      if(verbose_){
1116 +        std::cerr << "No SF found in the database for this jet" << std::endl;
1117 +        std::clog << "No SF found: Jet flavour = " << sj.flavour << std::endl;
1118 +        std::clog << "No SF found: Jet Et = " << sj.p4.Et() << std::endl;
1119 +        std::clog << "No SF found: Jet eta = " << sj.p4.Eta() << std::endl;
1120 +      }
1121 +    }
1122 +  }
1123 +  else {
1124 +    measurePoint.insert( BinningVariables::JetEt, sj.p4.Et() );
1125 +    measurePoint.insert( BinningVariables::JetAbsEta, fabs(sj.p4.Eta()) );
1126 +    if( iSF.MISTAGSF_CSVL->isResultOk(PerformanceResult::BTAGLEFFCORR , measurePoint) ){
1127 +      sj.SF_CSVL = iSF.MISTAGSF_CSVL->getResult(PerformanceResult::BTAGLEFFCORR , measurePoint);
1128 +      sj.SF_CSVLerr = iSF.MISTAGSF_CSVL->getResult(PerformanceResult::BTAGLERRCORR , measurePoint);
1129 +      if(verbose_){
1130 +        std::clog << "Light Jet flavour = " << sj.flavour << std::endl;
1131 +        std::clog << "Light Jet Et = " << sj.p4.Et() << std::endl;
1132 +        std::clog << "Light Jet eta = " << sj.p4.Eta() << std::endl;        
1133 +        std::clog << "Light CSVL Scale Factor = " << sj.SF_CSVL << std::endl;
1134 +        std::clog << "Light CSVL Scale Factor error = " << sj.SF_CSVLerr << std::endl;
1135 +      }
1136 +    }
1137 +    if( iSF.MISTAGSF_CSVM->isResultOk(PerformanceResult::BTAGLEFFCORR , measurePoint) ){
1138 +      sj.SF_CSVM = iSF.MISTAGSF_CSVM->getResult(PerformanceResult::BTAGLEFFCORR , measurePoint);
1139 +      sj.SF_CSVMerr = iSF.MISTAGSF_CSVM->getResult(PerformanceResult::BTAGLERRCORR , measurePoint);
1140 +    }
1141 +    if( iSF.MISTAGSF_CSVT->isResultOk(PerformanceResult::BTAGLEFFCORR , measurePoint) ){
1142 +      sj.SF_CSVT = iSF.MISTAGSF_CSVT->getResult(PerformanceResult::BTAGLEFFCORR , measurePoint);
1143 +      sj.SF_CSVTerr = iSF.MISTAGSF_CSVT->getResult(PerformanceResult::BTAGLERRCORR , measurePoint);
1144 +    }
1145 +    else{
1146 +      if(verbose_){
1147 +        std::cerr << "No SF found in the database for this jet" << std::endl;
1148 +        std::clog << "No SF found: Jet flavour = " << sj.flavour << std::endl;
1149 +        std::clog << "No SF found: Jet Et = " << sj.p4.Et() << std::endl;
1150 +        std::clog << "No SF found: Jet eta = " << sj.p4.Eta() << std::endl;
1151 +      }
1152 +    }
1153 +  }
1154 +    
1155 + }
1156 +
1157 + void HbbAnalyzerNew::setJecUnc(VHbbEvent::SimpleJet& sj,JetCorrectionUncertainty* jecunc){
1158 +  //
1159 +  // test
1160 +  //
1161 +
1162 +  return;
1163 +  double eta = sj.p4.Eta();
1164 +  double pt = sj.p4.Pt();
1165 +  
1166 +  jecunc->setJetEta(eta);
1167 +  jecunc->setJetPt(pt); // here you must use the CORRECTED jet pt
1168 +  double unc = jecunc->getUncertainty(true);
1169 +  sj.jecunc= unc;
1170 + }
1171 +
1172 +
1173 + void HbbAnalyzerNew ::fillSimpleJet (VHbbEvent::SimpleJet& sj, edm::View<pat::Jet>::const_iterator jet_iter){
1174 +      sj.flavour = jet_iter->partonFlavour();
1175 +
1176 +    sj.tche=jet_iter->bDiscriminator("trackCountingHighEffBJetTags");
1177 +    sj.tchp=jet_iter->bDiscriminator("trackCountingHighPurBJetTags");
1178 +    sj.jp=jet_iter->bDiscriminator("jetProbabilityBJetTags");
1179 +    sj.jpb=jet_iter->bDiscriminator("jetBProbabilityBJetTags");
1180 +    sj.ssvhe=jet_iter->bDiscriminator("simpleSecondaryVertexHighEffBJetTags");
1181 +    sj.csv=jet_iter->bDiscriminator("combinedSecondaryVertexBJetTags");
1182 +    sj.csvmva=jet_iter->bDiscriminator("combinedSecondaryVertexMVABJetTags");
1183 +    sj.charge=jet_iter->jetCharge();
1184 +    sj.ntracks=jet_iter->associatedTracks().size();
1185 +    sj.p4=GENPTOLORP(jet_iter);
1186 +    sj.chargedTracksFourMomentum=(getChargedTracksMomentum(&*(jet_iter)));
1187 +    sj.SF_CSVL=1;
1188 +    sj.SF_CSVM=1;
1189 +    sj.SF_CSVT=1;
1190 +    sj.SF_CSVLerr=0;
1191 +    sj.SF_CSVMerr=0;
1192 +    sj.SF_CSVTerr=0;
1193 +
1194 +    
1195 +    if (jet_iter->isPFJet() == true) {
1196 +
1197 +      sj.chargedHadronEFraction = jet_iter-> chargedHadronEnergyFraction();
1198 +      sj.neutralHadronEFraction = jet_iter-> neutralHadronEnergyFraction ();
1199 +      sj.chargedEmEFraction = jet_iter-> chargedEmEnergyFraction ();
1200 +      sj.neutralEmEFraction = jet_iter-> neutralEmEnergyFraction ();
1201 +      sj. nConstituents = jet_iter->getPFConstituents().size();
1202 +      
1203 +    }
1204 +    //
1205 +    // addtaginfo for csv
1206 +    //
1207 +
1208 +    //    if (jet_iter->hasTagInfo("SimpleSecondaryVertex")) {
1209 +
1210 +    const reco::SecondaryVertexTagInfo * tf = jet_iter->tagInfoSecondaryVertex();
1211 +   if (tf){
1212 +     if (tf->nVertices() >0){
1213 +        sj.vtxMass = tf->secondaryVertex(0).p4().mass();
1214 +        sj.vtxNTracks = tf->secondaryVertex(0).nTracks();
1215 +        std::vector<reco::TrackBaseRef >::const_iterator tit =  tf->secondaryVertex(0).tracks_begin();
1216 +        for (; tit<  tf->secondaryVertex(0).tracks_end(); ++tit){
1217 +          sj.vtxTrackIds.push_back(tit->key());
1218 +        }
1219 +        Measurement1D m = tf->flightDistance(0);
1220 +        sj.vtx3dL = m.value();
1221 +        sj.vtx3deL = m.error();
1222 +     }
1223 +    }
1224 +   //
1225 +    // add tVector
1226 +    //
1227 +    sj.tVector = getTvect(&(*jet_iter));
1228 + }
1229 +
1230 +
1231   //define this as a plug-in
1232   DEFINE_FWK_MODULE(HbbAnalyzerNew);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines