ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/JetAnalysis/src/HiInclusiveJetAnalyzer.cc
Revision: 1.16
Committed: Fri May 11 14:39:32 2012 UTC (12 years, 11 months ago) by ylai
Content type: text/plain
Branch: MAIN
Changes since 1.15: +76 -0 lines
Log Message:
Fake rejection discriminant

File Contents

# User Rev Content
1 yilmaz 1.1 /*
2     Based on the jet response analyzer
3     Modified by Matt Nguyen, November 2010
4    
5     */
6    
7     #include "CmsHi/JetAnalysis/interface/HiInclusiveJetAnalyzer.h"
8    
9     #include "FWCore/Framework/interface/EventSetup.h"
10     #include "FWCore/Framework/interface/ESHandle.h"
11     #include <Math/DistFunc.h>
12     #include "TMath.h"
13    
14     #include "FWCore/Framework/interface/ESHandle.h"
15    
16     #include "FWCore/MessageLogger/interface/MessageLogger.h"
17     #include "FWCore/Utilities/interface/Exception.h"
18     #include "FWCore/Framework/interface/EventSetup.h"
19    
20     #include "DataFormats/HeavyIonEvent/interface/CentralityBins.h"
21     #include "DataFormats/HeavyIonEvent/interface/Centrality.h"
22    
23     #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
24     #include "DataFormats/JetReco/interface/CaloJetCollection.h"
25     #include "SimDataFormats/HiGenData/interface/GenHIEvent.h"
26     #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
27 mnguyen 1.10 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
28 yilmaz 1.1 #include "DataFormats/JetReco/interface/GenJetCollection.h"
29     #include "DataFormats/VertexReco/interface/Vertex.h"
30     #include "DataFormats/Math/interface/deltaPhi.h"
31     #include "DataFormats/Math/interface/deltaR.h"
32    
33     #include "DataFormats/Common/interface/TriggerResults.h"
34     #include "FWCore/Common/interface/TriggerNames.h"
35     #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
36     #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
37     #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
38     #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h"
39     #include "L1Trigger/GlobalTrigger/interface/L1GlobalTrigger.h"
40    
41     using namespace std;
42     using namespace edm;
43     using namespace reco;
44    
45     HiInclusiveJetAnalyzer::HiInclusiveJetAnalyzer(const edm::ParameterSet& iConfig) {
46    
47    
48     jetTag_ = iConfig.getParameter<InputTag>("jetTag");
49 mnguyen 1.8 vtxTag_ = iConfig.getUntrackedParameter<edm::InputTag>("vtxTag",edm::InputTag("hiSelectedVertex"));
50 yilmaz 1.1
51     isMC_ = iConfig.getUntrackedParameter<bool>("isMC",false);
52 yilmaz 1.14 doTrigger_ = iConfig.getUntrackedParameter<bool>("doTrigger",false);
53 mnguyen 1.8
54 yilmaz 1.1 if(isMC_){
55     genjetTag_ = iConfig.getParameter<InputTag>("genjetTag");
56     eventInfoTag_ = iConfig.getParameter<InputTag>("eventInfoTag");
57     }
58     verbose_ = iConfig.getUntrackedParameter<bool>("verbose",false);
59    
60     useCentrality_ = iConfig.getUntrackedParameter<bool>("useCentrality",false);
61 yjlee 1.4 useVtx_ = iConfig.getUntrackedParameter<bool>("useVtx",false);
62 yilmaz 1.1 useJEC_ = iConfig.getUntrackedParameter<bool>("useJEC",true);
63 yilmaz 1.2 usePat_ = iConfig.getUntrackedParameter<bool>("usePAT",true);
64 yilmaz 1.1
65 mnguyen 1.8 doLifeTimeTagging_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTagging",false);
66 mnguyen 1.10 doLifeTimeTaggingExtras_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTaggingExtras",true);
67 mnguyen 1.11 saveBfragments_ = iConfig.getUntrackedParameter<bool>("saveBfragments",false);
68    
69 mnguyen 1.8 pfCandidateLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("pfCandidateLabel",edm::InputTag("particleFlowTmp"));
70    
71 yilmaz 1.14 if(doTrigger_){
72 yilmaz 1.1 L1gtReadout_ = iConfig.getParameter<edm::InputTag>("L1gtReadout");
73     hltResName_ = iConfig.getUntrackedParameter<string>("hltTrgResults","TriggerResults::HLT");
74    
75    
76     if (iConfig.exists("hltTrgNames"))
77     hltTrgNames_ = iConfig.getUntrackedParameter<vector<string> >("hltTrgNames");
78    
79     if (iConfig.exists("hltProcNames"))
80     hltProcNames_ = iConfig.getUntrackedParameter<vector<string> >("hltProcNames");
81     else {
82     hltProcNames_.push_back("FU");
83     hltProcNames_.push_back("HLT");
84     }
85     }
86    
87     cout<<" jet collection : "<<jetTag_<<endl;
88 yilmaz 1.12 doSubEvent_ = 0;
89    
90 yilmaz 1.9 if(isMC_){
91     cout<<" genjet collection : "<<genjetTag_<<endl;
92     genPtMin_ = iConfig.getUntrackedParameter<double>("genPtMin",0);
93 yilmaz 1.12 doSubEvent_ = iConfig.getUntrackedParameter<bool>("doSubEvent",1);
94 yilmaz 1.9 }
95 yilmaz 1.1
96    
97     }
98    
99    
100    
101     HiInclusiveJetAnalyzer::~HiInclusiveJetAnalyzer() { }
102    
103    
104    
105     void
106     HiInclusiveJetAnalyzer::beginRun(const edm::Run& run,
107     const edm::EventSetup & es) {}
108    
109     void
110     HiInclusiveJetAnalyzer::beginJob() {
111    
112     centrality_ = 0;
113    
114     //string jetTagName = jetTag_.label()+"_tree";
115     string jetTagTitle = jetTag_.label()+" Jet Analysis Tree";
116     t = fs1->make<TTree>("t",jetTagTitle.c_str());
117    
118 yjlee 1.6 // TTree* t= new TTree("t","Jet Response Analyzer");
119 yjlee 1.4 //t->Branch("run",&jets_.run,"run/I");
120 yilmaz 1.1 t->Branch("evt",&jets_.evt,"evt/I");
121 yjlee 1.4 //t->Branch("lumi",&jets_.lumi,"lumi/I");
122 yilmaz 1.1 t->Branch("b",&jets_.b,"b/F");
123 yjlee 1.4 if (useVtx_) {
124     t->Branch("vx",&jets_.vx,"vx/F");
125     t->Branch("vy",&jets_.vy,"vy/F");
126     t->Branch("vz",&jets_.vz,"vz/F");
127     }
128     if (useCentrality_) {
129     t->Branch("hf",&jets_.hf,"hf/F");
130     t->Branch("bin",&jets_.bin,"bin/I");
131     }
132 yjlee 1.7
133     t->Branch("nref",&jets_.nref,"nref/I");
134 yilmaz 1.1 t->Branch("rawpt",jets_.rawpt,"rawpt[nref]/F");
135     t->Branch("jtpt",jets_.jtpt,"jtpt[nref]/F");
136     t->Branch("jteta",jets_.jteta,"jteta[nref]/F");
137     t->Branch("jty",jets_.jty,"jty[nref]/F");
138     t->Branch("jtphi",jets_.jtphi,"jtphi[nref]/F");
139 yilmaz 1.2 t->Branch("jtpu",jets_.jtpu,"jtpu[nref]/F");
140 yilmaz 1.1
141 mnguyen 1.8 // b-jet discriminators
142     if (doLifeTimeTagging_) {
143    
144     t->Branch("discr_csvMva",jets_.discr_csvMva,"discr_csvMva[nref]/F");
145     t->Branch("discr_csvSimple",jets_.discr_csvSimple,"discr_csvSimple[nref]/F");
146     t->Branch("discr_muByIp3",jets_.discr_muByIp3,"discr_muByIp3[nref]/F");
147     t->Branch("discr_muByPt",jets_.discr_muByPt,"discr_muByPt[nref]/F");
148     t->Branch("discr_prob",jets_.discr_prob,"discr_prob[nref]/F");
149     t->Branch("discr_probb",jets_.discr_probb,"discr_probb[nref]/F");
150     t->Branch("discr_tcHighEff",jets_.discr_tcHighEff,"discr_tcHighEff[nref]/F");
151     t->Branch("discr_tcHighPur",jets_.discr_tcHighPur,"discr_tcHighPur[nref]/F");
152    
153 mnguyen 1.10 t->Branch("nsvtx", jets_.nsvtx, "nsvtx[nref]/I");
154     t->Branch("svtxntrk", jets_.svtxntrk, "svtxntrk[nref]/I");
155 mnguyen 1.8 t->Branch("svtxdl", jets_.svtxdl, "svtxdl[nref]/F");
156     t->Branch("svtxdls", jets_.svtxdls, "svtxdls[nref]/F");
157     t->Branch("svtxm", jets_.svtxm, "svtxm[nref]/F");
158     t->Branch("svtxpt", jets_.svtxpt, "svtxpt[nref]/F");
159    
160 mnguyen 1.10 t->Branch("nIPtrk",jets_.nIPtrk,"nIPtrk[nref]/I");
161     t->Branch("nselIPtrk",jets_.nselIPtrk,"nselIPtrk[nref]/I");
162 mnguyen 1.11
163 mnguyen 1.10 if (doLifeTimeTaggingExtras_) {
164 mnguyen 1.11 t->Branch("nIP",&jets_.nIP,"nIP/I");
165     t->Branch("ipJetIndex",jets_.ipJetIndex,"ipJetIndex[nIP]/I");
166     t->Branch("ipPt",jets_.ipPt,"ipPt[nIP]/F");
167     t->Branch("ipProb0",jets_.ipProb0,"ipProb0[nIP]/F");
168     t->Branch("ipProb1",jets_.ipProb1,"ipProb1[nIP]/F");
169     t->Branch("ip2d",jets_.ip2d,"ip2d[nIP]/F");
170     t->Branch("ip2dSig",jets_.ip2dSig,"ip2dSig[nIP]/F");
171     t->Branch("ip3d",jets_.ip3d,"ip3d[nIP]/F");
172     t->Branch("ip3dSig",jets_.ip3dSig,"ip3dSig[nIP]/F");
173     t->Branch("ipDist2Jet",jets_.ipDist2Jet,"ipDist2Jet[nIP]/F");
174     t->Branch("ipDist2JetSig",jets_.ipDist2JetSig,"ipDist2JetSig[nIP]/F");
175     t->Branch("ipClosest2Jet",jets_.ipClosest2Jet,"ipClosest2Jet[nIP]/F");
176    
177 mnguyen 1.10 }
178 mnguyen 1.8
179     t->Branch("mue", jets_.mue, "mue[nref]/F");
180     t->Branch("mupt", jets_.mupt, "mupt[nref]/F");
181     t->Branch("mueta", jets_.mueta, "mueta[nref]/F");
182     t->Branch("muphi", jets_.muphi, "muphi[nref]/F");
183     t->Branch("mudr", jets_.mudr, "mudr[nref]/F");
184     t->Branch("muptrel", jets_.muptrel, "muptrel[nref]/F");
185     t->Branch("muchg", jets_.muchg, "muchg[nref]/I");
186     }
187 ylai 1.16
188     t->Branch("discr_fr01", jets_.discr_fr01,"discr_fr01[nref]/F");
189 mnguyen 1.8
190 yilmaz 1.1 if(isMC_){
191 mnguyen 1.10 t->Branch("beamId1",&jets_.beamId1,"beamId1/I");
192     t->Branch("beamId2",&jets_.beamId2,"beamId2/I");
193    
194 yilmaz 1.1 t->Branch("pthat",&jets_.pthat,"pthat/F");
195    
196     // Only matched gen jets
197     t->Branch("refpt",jets_.refpt,"refpt[nref]/F");
198     t->Branch("refeta",jets_.refeta,"refeta[nref]/F");
199     t->Branch("refy",jets_.refy,"refy[nref]/F");
200     t->Branch("refphi",jets_.refphi,"refphi[nref]/F");
201     t->Branch("refdphijt",jets_.refdphijt,"refdphijt[nref]/F");
202     t->Branch("refdrjt",jets_.refdrjt,"refdrjt[nref]/F");
203     // matched parton
204     t->Branch("refparton_pt",jets_.refparton_pt,"refparton_pt[nref]/F");
205 mnguyen 1.8 t->Branch("refparton_flavor",jets_.refparton_flavor,"refparton_flavor[nref]/I");
206     t->Branch("refparton_flavorForB",jets_.refparton_flavorForB,"refparton_flavorForB[nref]/I");
207 yilmaz 1.1
208     // For all gen jets, matched or unmatched
209     t->Branch("ngen",&jets_.ngen,"ngen/I");
210     t->Branch("genmatchindex",jets_.genmatchindex,"genmatchindex[ngen]/I");
211     t->Branch("genpt",jets_.genpt,"genpt[ngen]/F");
212     t->Branch("geneta",jets_.geneta,"geneta[ngen]/F");
213     t->Branch("geny",jets_.geny,"geny[ngen]/F");
214     t->Branch("genphi",jets_.genphi,"genphi[ngen]/F");
215     t->Branch("gendphijt",jets_.gendphijt,"gendphijt[ngen]/F");
216     t->Branch("gendrjt",jets_.gendrjt,"gendrjt[ngen]/F");
217 yilmaz 1.12
218     if(doSubEvent_){
219     t->Branch("gensubid",jets_.gensubid,"gensubid[ngen]/I");
220     }
221 mnguyen 1.11
222     if(saveBfragments_ ) {
223     t->Branch("bMult",&jets_.bMult,"bMult/I");
224     t->Branch("bJetIndex",jets_.bJetIndex,"bJetIndex[bMult]/I");
225     t->Branch("bStatus",jets_.bStatus,"bStatus[bMult]/I");
226     t->Branch("bVx",jets_.bVx,"bVx[bMult]/F");
227     t->Branch("bVy",jets_.bVy,"bVy[bMult]/F");
228     t->Branch("bVz",jets_.bVz,"bVz[bMult]/F");
229     t->Branch("bPt",jets_.bPt,"bPt[bMult]/F");
230     t->Branch("bEta",jets_.bEta,"bEta[bMult]/F");
231     t->Branch("bPhi",jets_.bPhi,"bPhi[bMult]/F");
232     t->Branch("bPdg",jets_.bPdg,"bPdg[bMult]/I");
233     t->Branch("bChg",jets_.bChg,"bChg[bMult]/I");
234     }
235 yilmaz 1.13
236 yilmaz 1.1 }
237 yjlee 1.7 /*
238 yilmaz 1.1 if(!isMC_){
239     t->Branch("nL1TBit",&jets_.nL1TBit,"nL1TBit/I");
240     t->Branch("l1TBit",jets_.l1TBit,"l1TBit[nL1TBit]/O");
241    
242     t->Branch("nL1ABit",&jets_.nL1ABit,"nL1ABit/I");
243     t->Branch("l1ABit",jets_.l1ABit,"l1ABit[nL1ABit]/O");
244    
245     t->Branch("nHLTBit",&jets_.nHLTBit,"nHLTBit/I");
246     t->Branch("hltBit",jets_.hltBit,"hltBit[nHLTBit]/O");
247    
248     }
249 yjlee 1.7 */
250 yilmaz 1.1 TH1D::SetDefaultSumw2();
251    
252    
253     }
254    
255    
256     void
257     HiInclusiveJetAnalyzer::analyze(const Event& iEvent,
258     const EventSetup& iSetup) {
259    
260     int event = iEvent.id().event();
261     int run = iEvent.id().run();
262     int lumi = iEvent.id().luminosityBlock();
263    
264     jets_.run = run;
265     jets_.evt = event;
266     jets_.lumi = lumi;
267    
268     LogDebug("HiInclusiveJetAnalyzer")<<"START event: "<<event<<" in run "<<run<<endl;
269    
270     int bin = -1;
271     double hf = 0.;
272     double b = 999.;
273    
274     if(useCentrality_){
275     if(!centrality_) centrality_ = new CentralityProvider(iSetup);
276     centrality_->newEvent(iEvent,iSetup); // make sure you do this first in every event
277     //double c = centrality_->centralityValue();
278     const reco::Centrality *cent = centrality_->raw();
279    
280     hf = cent->EtHFhitSum();
281    
282     bin = centrality_->getBin();
283     b = centrality_->bMean();
284     }
285    
286    
287    
288    
289    
290     // loop the events
291    
292     jets_.bin = bin;
293     jets_.hf = hf;
294    
295    
296     if (useVtx_) {
297     edm::Handle<vector<reco::Vertex> >vertex;
298     iEvent.getByLabel(vtxTag_, vertex);
299    
300     if(vertex->size()>0) {
301     jets_.vx=vertex->begin()->x();
302     jets_.vy=vertex->begin()->y();
303     jets_.vz=vertex->begin()->z();
304     }
305     }
306    
307 yilmaz 1.2 edm::Handle<pat::JetCollection> patjets;
308     if(usePat_)iEvent.getByLabel(jetTag_, patjets);
309    
310     edm::Handle<reco::JetView> jets;
311 yilmaz 1.1 iEvent.getByLabel(jetTag_, jets);
312    
313 mnguyen 1.8 edm::Handle<reco::PFCandidateCollection> pfCandidates;
314     if(doLifeTimeTagging_){
315     iEvent.getByLabel(pfCandidateLabel_,pfCandidates);
316     }
317 yilmaz 1.1 // FILL JRA TREE
318    
319     jets_.b = b;
320     jets_.nref = 0;
321    
322 yilmaz 1.15 if(doTrigger_){
323 yilmaz 1.1 fillL1Bits(iEvent);
324     fillHLTBits(iEvent);
325     }
326    
327     for(unsigned int j = 0 ; j < jets->size(); ++j){
328 yilmaz 1.2 const reco::Jet& jet = (*jets)[j];
329 yilmaz 1.1
330 mnguyen 1.11
331 yilmaz 1.2 if (useJEC_ && usePat_){
332     jets_.rawpt[jets_.nref]=(*patjets)[j].correctedJet("Uncorrected").pt();
333     }
334 mnguyen 1.8
335     if(doLifeTimeTagging_){
336    
337     if(jetTag_.label()=="icPu5patJets"){
338     jets_.discr_csvMva[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5CombinedSecondaryVertexMVABJetTags");
339     jets_.discr_csvSimple[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5CombinedSecondaryVertexBJetTags");
340     jets_.discr_muByIp3[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5SoftMuonByIP3dBJetTags");
341     jets_.discr_muByPt[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5SoftMuonByPtBJetTags");
342     jets_.discr_prob[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5JetBProbabilityBJetTags");
343     jets_.discr_probb[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5JetProbabilityBJetTags");
344     jets_.discr_tcHighEff[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5TrackCountingHighEffBJetTags");
345     jets_.discr_tcHighPur[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5TrackCountingHighPurBJetTags");
346     }
347     else if(jetTag_.label()=="akPu3PFpatJets"){
348     jets_.discr_csvMva[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFCombinedSecondaryVertexMVABJetTags");
349     jets_.discr_csvSimple[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFCombinedSecondaryVertexBJetTags");
350     jets_.discr_muByIp3[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFSoftMuonByIP3dBJetTags");
351     jets_.discr_muByPt[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFSoftMuonByPtBJetTags");
352     jets_.discr_prob[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFJetBProbabilityBJetTags");
353     jets_.discr_probb[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFJetProbabilityBJetTags");
354     jets_.discr_tcHighEff[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFTrackCountingHighEffBJetTags");
355     jets_.discr_tcHighPur[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFTrackCountingHighPurBJetTags");
356     }
357     else{
358 mnguyen 1.10 cout<<" b-tagging variables not filled for this collection, turn of doLifeTimeTagging "<<endl;
359 mnguyen 1.8 }
360 mnguyen 1.10
361     const reco::SecondaryVertexTagInfo& tagInfoSV=*(*patjets)[j].tagInfoSecondaryVertex();
362    
363     jets_.nsvtx[jets_.nref] = tagInfoSV.nVertices();
364 mnguyen 1.8
365     if (tagInfoSV.nVertices()>0) {
366     jets_.svtxntrk[jets_.nref] = tagInfoSV.nVertexTracks(0);
367 mnguyen 1.10 // this is the 3d flight distance, for 2-D use (0,true)
368     Measurement1D m1D = tagInfoSV.flightDistance(0);
369 mnguyen 1.8 jets_.svtxdl[jets_.nref] = m1D.value();
370     jets_.svtxdls[jets_.nref] = m1D.significance();
371    
372 mnguyen 1.10 const reco::Vertex& svtx = tagInfoSV.secondaryVertex(0);
373 mnguyen 1.11 //cout<<" SV: vx: "<<svtx.x()<<" vy "<<svtx.y()<<" vz "<<svtx.z()<<endl;
374     //cout<<" PV: vx: "<<jet.vx()<<" vy "<<jet.vy()<<" vz "<<jet.vz()<<endl;
375 mnguyen 1.8 jets_.svtxm[jets_.nref] = svtx.p4().mass();
376 mnguyen 1.10 jets_.svtxpt[jets_.nref] = svtx.p4().pt();
377 mnguyen 1.11 //cout<<" chi2 "<<svtx.chi2()<<" ndof "<<svtx.ndof()<<endl;
378 mnguyen 1.8 }
379 mnguyen 1.10
380 mnguyen 1.8 const reco::TrackIPTagInfo& tagInfoIP=*(*patjets)[j].tagInfoTrackIP();
381 mnguyen 1.10
382     jets_.nIPtrk[jets_.nref] = tagInfoIP.tracks().size();
383     jets_.nselIPtrk[jets_.nref] = tagInfoIP.selectedTracks().size();
384 mnguyen 1.8
385 mnguyen 1.10 if (doLifeTimeTaggingExtras_) {
386 mnguyen 1.8
387 mnguyen 1.10 TrackRefVector selTracks=tagInfoIP.selectedTracks();
388    
389     GlobalPoint pv(tagInfoIP.primaryVertex()->position().x(),tagInfoIP.primaryVertex()->position().y(),tagInfoIP.primaryVertex()->position().z());
390    
391     for(int it=0;it<jets_.nselIPtrk[jets_.nref] ;it++)
392     {
393 mnguyen 1.11 jets_.ipJetIndex[jets_.nIP + it]= jets_.nref;
394 mnguyen 1.10 TrackIPTagInfo::TrackIPData data = tagInfoIP.impactParameterData()[it];
395 mnguyen 1.11 jets_.ipPt[jets_.nIP + it] = selTracks[it]->pt();
396     jets_.ipProb0[jets_.nIP + it] = tagInfoIP.probabilities(0)[it];
397     jets_.ipProb1[jets_.nIP + it] = tagInfoIP.probabilities(1)[it];
398     jets_.ip2d[jets_.nIP + it] = data.ip2d.value();
399     jets_.ip2dSig[jets_.nIP + it] = data.ip2d.significance();
400     jets_.ip3d[jets_.nIP + it] = data.ip3d.value();
401     jets_.ip3dSig[jets_.nIP + it] = data.ip3d.significance();
402     jets_.ipDist2Jet[jets_.nIP + it] = data.distanceToJetAxis.value();
403     jets_.ipDist2JetSig[jets_.nIP + it] = data.distanceToJetAxis.significance();
404     jets_.ipClosest2Jet[jets_.nIP + it] = (data.closestToJetAxis - pv).mag(); //decay length
405 mnguyen 1.10 }
406 mnguyen 1.11
407     jets_.nIP += jets_.nselIPtrk[jets_.nref];
408    
409 mnguyen 1.10 }
410    
411 mnguyen 1.8 const reco::PFCandidateCollection *pfCandidateColl = &(*pfCandidates);
412     int pfMuonIndex = getPFJetMuon(jet, pfCandidateColl);
413     if(pfMuonIndex >=0){
414     const reco::PFCandidate muon = pfCandidateColl->at(pfMuonIndex);
415     jets_.mupt[jets_.nref] = muon.pt();
416     jets_.mueta[jets_.nref] = muon.eta();
417     jets_.muphi[jets_.nref] = muon.phi();
418     jets_.mue[jets_.nref] = muon.energy();
419     jets_.mudr[jets_.nref] = reco::deltaR(jet,muon);
420     jets_.muptrel[jets_.nref] = getPtRel(muon, jet);
421     jets_.muchg[jets_.nref] = muon.charge();
422     }
423 ylai 1.16 <<<<<<< HiInclusiveJetAnalyzer.cc
424     else{
425     jets_.mupt[jets_.nref] = 0.0;
426     jets_.mueta[jets_.nref] = 0.0;
427     jets_.muphi[jets_.nref] = 0.0;
428     jets_.mue[jets_.nref] = 0.0;
429     jets_.mudr[jets_.nref] = 9.9;
430     jets_.muptrel[jets_.nref] = 0.0;
431     jets_.muchg[jets_.nref] = 0;
432     }
433    
434     =======
435     >>>>>>> 1.15
436 mnguyen 1.8 }
437    
438 ylai 1.16 /////////////////////////////////////////////////////////////////
439     // Jet core pt^2 discriminant for fake jets
440     // Edited by Yue Shi Lai <ylai@mit.edu>
441    
442     // Initial value is 0
443     jets_.discr_fr01[jets_.nref] = 0;
444     // Start with no directional adaption, i.e. the fake rejection
445     // axis is the jet axis
446     float pseudorapidity_adapt = jets_.jteta[jets_.nref];
447     float azimuth_adapt = jets_.jtphi[jets_.nref];
448    
449     // Unadapted discriminant with adaption search
450     for (size_t iteration = 0; iteration < 2; iteration++) {
451     float pseudorapidity_adapt_new = pseudorapidity_adapt;
452     float azimuth_adapt_new = azimuth_adapt;
453     float max_weighted_perp = 0;
454     float perp_square_sum = 0;
455    
456     for (size_t index_pf_candidate = 0;
457     index_pf_candidate < pfCandidates->size();
458     index_pf_candidate++) {
459     const reco::PFCandidate &p =
460     (*pfCandidates)[index_pf_candidate];
461    
462     switch (p.particleId()) {
463     case 1: // Charged hadron
464     case 3: // Muon
465     case 4: // Photon
466     {
467     const float dpseudorapidity =
468     p.eta() - pseudorapidity_adapt;
469     const float dazimuth =
470     reco::deltaPhi(p.phi(), azimuth_adapt);
471     // The Gaussian scale factor is 0.5 / (0.1 * 0.1)
472     // = 50
473     const float angular_weight =
474     exp(-50.0F * (dpseudorapidity * dpseudorapidity +
475     dazimuth * dazimuth));
476     const float weighted_perp =
477     angular_weight * p.pt() * p.pt();
478     const float weighted_perp_square =
479     weighted_perp * p.pt();
480    
481     perp_square_sum += weighted_perp_square;
482     if (weighted_perp >= max_weighted_perp) {
483     pseudorapidity_adapt_new = p.eta();
484     azimuth_adapt_new = p.phi();
485     max_weighted_perp = weighted_perp;
486     }
487     }
488     }
489     }
490     // Update the fake rejection value
491     jets_.discr_fr01[jets_.nref] = std::max(
492     jets_.discr_fr01[jets_.nref], perp_square_sum);
493     // Update the directional adaption
494     pseudorapidity_adapt = pseudorapidity_adapt_new;
495     azimuth_adapt = azimuth_adapt_new;
496     }
497    
498    
499 yilmaz 1.1 jets_.jtpt[jets_.nref] = jet.pt();
500     jets_.jteta[jets_.nref] = jet.eta();
501     jets_.jtphi[jets_.nref] = jet.phi();
502     jets_.jty[jets_.nref] = jet.eta();
503 yilmaz 1.2 jets_.jtpu[jets_.nref] = jet.pileup();
504 yilmaz 1.1
505 yilmaz 1.2 if(isMC_ && usePat_){
506 mnguyen 1.11
507     const reco::GenJet * genjet = (*patjets)[j].genJet();
508 mnguyen 1.8
509 yilmaz 1.2 if(genjet){
510     jets_.refpt[jets_.nref] = genjet->pt();
511     jets_.refeta[jets_.nref] = genjet->eta();
512     jets_.refphi[jets_.nref] = genjet->phi();
513     jets_.refy[jets_.nref] = genjet->eta();
514     jets_.refdphijt[jets_.nref] = reco::deltaPhi(jet.phi(), genjet->phi());
515     jets_.refdrjt[jets_.nref] = reco::deltaR(jet.eta(),jet.phi(),genjet->eta(),genjet->phi());
516     }else{
517     jets_.refpt[jets_.nref] = -999.;
518     jets_.refeta[jets_.nref] = -999.;
519     jets_.refphi[jets_.nref] = -999.;
520     jets_.refy[jets_.nref] = -999.;
521     jets_.refdphijt[jets_.nref] = -999.;
522     jets_.refdrjt[jets_.nref] = -999.;
523     }
524 yilmaz 1.1
525 mnguyen 1.11 jets_.refparton_flavorForB[jets_.nref] = (*patjets)[j].partonFlavour();
526    
527     // matched partons
528     const reco::GenParticle & parton = *(*patjets)[j].genParton();
529    
530     if((*patjets)[j].genParton()){
531     jets_.refparton_pt[jets_.nref] = parton.pt();
532     jets_.refparton_flavor[jets_.nref] = parton.pdgId();
533    
534     if(saveBfragments_ && abs(jets_.refparton_flavorForB[jets_.nref])==5){
535    
536     usedStringPts.clear();
537    
538     // uncomment this if you want to know the ugly truth about parton matching -matt
539     //if(jet.pt() > 50 &&abs(parton.pdgId())!=5 && parton.pdgId()!=21)
540     // cout<<" Identified as a b, but doesn't match b or gluon, id = "<<parton.pdgId()<<endl;
541    
542     jets_.bJetIndex[jets_.bMult] = jets_.nref;
543     jets_.bStatus[jets_.bMult] = parton.status();
544     jets_.bVx[jets_.bMult] = parton.vx();
545     jets_.bVy[jets_.bMult] = parton.vy();
546     jets_.bVz[jets_.bMult] = parton.vz();
547     jets_.bPt[jets_.bMult] = parton.pt();
548     jets_.bEta[jets_.bMult] = parton.eta();
549     jets_.bPhi[jets_.bMult] = parton.phi();
550     jets_.bPdg[jets_.bMult] = parton.pdgId();
551     jets_.bChg[jets_.bMult] = parton.charge();
552     jets_.bMult++;
553     saveDaughters(parton);
554     }
555    
556    
557 mnguyen 1.8 } else {
558 mnguyen 1.11 jets_.refparton_pt[jets_.nref] = -999;
559     jets_.refparton_flavor[jets_.nref] = -999;
560 mnguyen 1.8 }
561 mnguyen 1.11
562    
563 yilmaz 1.2 }
564 yilmaz 1.1
565     jets_.nref++;
566    
567    
568     }
569    
570    
571     if(isMC_){
572    
573 mnguyen 1.10 edm::Handle<HepMCProduct> hepMCProduct;
574     iEvent.getByLabel(eventInfoTag_,hepMCProduct);
575     const HepMC::GenEvent* MCEvt = hepMCProduct->GetEvent();
576     std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beamParticles = MCEvt->beam_particles();
577     jets_.beamId1 = beamParticles.first->pdg_id();
578     jets_.beamId2 = beamParticles.second->pdg_id();
579    
580 yilmaz 1.1 edm::Handle<GenEventInfoProduct> hEventInfo;
581     iEvent.getByLabel(eventInfoTag_,hEventInfo);
582     //jets_.pthat = hEventInfo->binningValues()[0];
583    
584     // binning values and qscale appear to be equivalent, but binning values not always present
585     jets_.pthat = hEventInfo->qScale();
586    
587     edm::Handle<vector<reco::GenJet> >genjets;
588     iEvent.getByLabel(genjetTag_, genjets);
589    
590     jets_.ngen = 0;
591     for(unsigned int igen = 0 ; igen < genjets->size(); ++igen){
592     const reco::GenJet & genjet = (*genjets)[igen];
593    
594     float genjet_pt = genjet.pt();
595    
596     // threshold to reduce size of output in minbias PbPb
597 yilmaz 1.9 if(genjet_pt>genPtMin_){
598 yilmaz 1.1
599     jets_.genpt[jets_.ngen] = genjet_pt;
600     jets_.geneta[jets_.ngen] = genjet.eta();
601     jets_.genphi[jets_.ngen] = genjet.phi();
602     jets_.geny[jets_.ngen] = genjet.eta();
603    
604 yilmaz 1.12 if(doSubEvent_){
605     const GenParticle* gencon = genjet.getGenConstituent(0);
606     jets_.gensubid[jets_.ngen] = gencon->collisionId();
607     }
608 yilmaz 1.1
609     // find matching patJet if there is one
610    
611     jets_.gendrjt[jets_.ngen] = -1.0;
612     jets_.genmatchindex[jets_.ngen] = -1;
613    
614     for(unsigned int ijet = 0 ; ijet < jets->size(); ++ijet){
615     const pat::Jet& jet = (*jets)[ijet];
616 mnguyen 1.8 const reco::GenJet* matchedGenJet = (*patjets)[ijet].genJet();
617     if(matchedGenJet){
618     // poor man's matching, someone fix please
619     if(fabs(genjet.pt()-matchedGenJet->pt())<0.0001 &&
620     fabs(genjet.eta()-matchedGenJet->eta())<0.0001 &&
621     (fabs(genjet.phi()-matchedGenJet->phi())<0.0001 || fabs(genjet.phi()-matchedGenJet->phi() - 2.0*TMath::Pi()) < 0.0001 )){
622 yilmaz 1.1
623     jets_.genmatchindex[jets_.ngen] = (int)ijet;
624     jets_.gendphijt[jets_.ngen] = reco::deltaPhi(jet.phi(),genjet.phi());
625     jets_.gendrjt[jets_.ngen] = reco::deltaR(jet,genjet);
626    
627     break;
628     }
629     }
630     }
631     jets_.ngen++;
632     }
633    
634     }
635    
636     }
637     t->Fill();
638 mnguyen 1.10 memset(&jets_,0,sizeof jets_);
639 yilmaz 1.1 }
640    
641    
642    
643    
644     //--------------------------------------------------------------------------------------------------
645     void HiInclusiveJetAnalyzer::fillL1Bits(const edm::Event &iEvent)
646     {
647     edm::Handle< L1GlobalTriggerReadoutRecord > L1GlobalTrigger;
648    
649     iEvent.getByLabel(L1gtReadout_, L1GlobalTrigger);
650     const TechnicalTriggerWord& technicalTriggerWordBeforeMask = L1GlobalTrigger->technicalTriggerWord();
651    
652     for (int i=0; i<64;i++)
653     {
654     jets_.l1TBit[i] = technicalTriggerWordBeforeMask.at(i);
655     }
656     jets_.nL1TBit = 64;
657    
658     int ntrigs = L1GlobalTrigger->decisionWord().size();
659     jets_.nL1ABit = ntrigs;
660    
661     for (int i=0; i != ntrigs; i++) {
662     bool accept = L1GlobalTrigger->decisionWord()[i];
663     //jets_.l1ABit[i] = (accept == true)? 1:0;
664     if(accept== true){
665     jets_.l1ABit[i] = 1;
666     }
667     else{
668     jets_.l1ABit[i] = 0;
669     }
670    
671     }
672     }
673    
674     //--------------------------------------------------------------------------------------------------
675     void HiInclusiveJetAnalyzer::fillHLTBits(const edm::Event &iEvent)
676     {
677     // Fill HLT trigger bits.
678     Handle<TriggerResults> triggerResultsHLT;
679     getProduct(hltResName_, triggerResultsHLT, iEvent);
680    
681     const TriggerResults *hltResults = triggerResultsHLT.product();
682     const TriggerNames & triggerNames = iEvent.triggerNames(*hltResults);
683    
684     jets_.nHLTBit = hltTrgNames_.size();
685    
686     for(size_t i=0;i<hltTrgNames_.size();i++){
687    
688     for(size_t j=0;j<triggerNames.size();++j) {
689    
690     if(triggerNames.triggerName(j) == hltTrgNames_[i]){
691    
692     //cout <<"hltTrgNames_(i) "<<hltTrgNames_[i]<<endl;
693     //cout <<"triggerName(j) "<<triggerNames.triggerName(j)<<endl;
694     //cout<<" result "<<triggerResultsHLT->accept(j)<<endl;
695     jets_.hltBit[i] = triggerResultsHLT->accept(j);
696     }
697    
698     }
699     }
700     }
701    
702     //--------------------------------------------------------------------------------------------------
703     template <typename TYPE>
704     inline void HiInclusiveJetAnalyzer::getProduct(const std::string name, edm::Handle<TYPE> &prod,
705     const edm::Event &event) const
706     {
707     // Try to access data collection from EDM file. We check if we really get just one
708     // product with the given name. If not we throw an exception.
709    
710     event.getByLabel(edm::InputTag(name),prod);
711     if (!prod.isValid())
712     throw edm::Exception(edm::errors::Configuration, "HiInclusiveJetAnalyzer::GetProduct()\n")
713     << "Collection with label '" << name << "' is not valid" << std::endl;
714     }
715    
716     //--------------------------------------------------------------------------------------------------
717     template <typename TYPE>
718     inline bool HiInclusiveJetAnalyzer::getProductSafe(const std::string name, edm::Handle<TYPE> &prod,
719     const edm::Event &event) const
720     {
721     // Try to safely access data collection from EDM file. We check if we really get just one
722     // product with the given name. If not, we return false.
723    
724     if (name.size()==0)
725     return false;
726    
727     try {
728     event.getByLabel(edm::InputTag(name),prod);
729     if (!prod.isValid())
730     return false;
731     } catch (...) {
732     return false;
733     }
734     return true;
735     }
736    
737    
738 mnguyen 1.8 int
739     HiInclusiveJetAnalyzer::getPFJetMuon(const pat::Jet& pfJet, const reco::PFCandidateCollection *pfCandidateColl)
740     {
741    
742     int pfMuonIndex = -1;
743     float ptMax = 0.;
744    
745    
746     for(unsigned icand=0;icand<pfCandidateColl->size(); icand++) {
747     const reco::PFCandidate pfCandidate = pfCandidateColl->at(icand);
748    
749     int id = pfCandidate.particleId();
750     if(abs(id) != 3) continue;
751 yilmaz 1.1
752 mnguyen 1.8 if(reco::deltaR(pfJet,pfCandidate)>0.5) continue;
753    
754     double pt = pfCandidate.pt();
755     if(pt>ptMax){
756     ptMax = pt;
757     pfMuonIndex = (int) icand;
758     }
759     }
760    
761     return pfMuonIndex;
762    
763     }
764    
765    
766     double
767     HiInclusiveJetAnalyzer::getPtRel(const reco::PFCandidate lep, const pat::Jet& jet )
768     {
769    
770     float lj_x = jet.p4().px();
771     float lj_y = jet.p4().py();
772     float lj_z = jet.p4().pz();
773    
774     // absolute values squared
775     float lj2 = lj_x*lj_x+lj_y*lj_y+lj_z*lj_z;
776     float lep2 = lep.px()*lep.px()+lep.py()*lep.py()+lep.pz()*lep.pz();
777    
778     // projection vec(mu) to lepjet axis
779     float lepXlj = lep.px()*lj_x+lep.py()*lj_y+lep.pz()*lj_z;
780    
781     // absolute value squared and normalized
782     float pLrel2 = lepXlj*lepXlj/lj2;
783    
784     // lep2 = pTrel2 + pLrel2
785     float pTrel2 = lep2-pLrel2;
786    
787     return (pTrel2 > 0) ? std::sqrt(pTrel2) : 0.0;
788     }
789 mnguyen 1.11
790     // Recursive function, but this version gets called only the first time
791     void
792     HiInclusiveJetAnalyzer::saveDaughters(const reco::GenParticle &gen){
793    
794     for(unsigned i=0;i<gen.numberOfDaughters();i++){
795     const reco::Candidate & daughter = *gen.daughter(i);
796     double daughterPt = daughter.pt();
797     if(daughterPt<1.) continue;
798     double daughterEta = daughter.eta();
799     if(fabs(daughterEta)>3.) continue;
800     int daughterPdgId = daughter.pdgId();
801     int daughterStatus = daughter.status();
802     // Special case when b->b+string, both b and string contain all daughters, so only take the string
803     if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
804    
805     // cheesy way of finding strings which were already used
806     if(daughter.pdgId()==92){
807     for(unsigned ist=0;ist<usedStringPts.size();ist++){
808     if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
809     }
810     usedStringPts.push_back(daughter.pt());
811     }
812     jets_.bJetIndex[jets_.bMult] = jets_.nref;
813     jets_.bStatus[jets_.bMult] = daughterStatus;
814     jets_.bVx[jets_.bMult] = daughter.vx();
815     jets_.bVy[jets_.bMult] = daughter.vy();
816     jets_.bVz[jets_.bMult] = daughter.vz();
817     jets_.bPt[jets_.bMult] = daughterPt;
818     jets_.bEta[jets_.bMult] = daughterEta;
819     jets_.bPhi[jets_.bMult] = daughter.phi();
820     jets_.bPdg[jets_.bMult] = daughterPdgId;
821     jets_.bChg[jets_.bMult] = daughter.charge();
822     jets_.bMult++;
823     saveDaughters(daughter);
824     }
825     }
826    
827     // This version called for all subsequent calls
828     void
829     HiInclusiveJetAnalyzer::saveDaughters(const reco::Candidate &gen){
830    
831     for(unsigned i=0;i<gen.numberOfDaughters();i++){
832     const reco::Candidate & daughter = *gen.daughter(i);
833     double daughterPt = daughter.pt();
834     if(daughterPt<1.) continue;
835     double daughterEta = daughter.eta();
836     if(fabs(daughterEta)>3.) continue;
837     int daughterPdgId = daughter.pdgId();
838     int daughterStatus = daughter.status();
839     // Special case when b->b+string, both b and string contain all daughters, so only take the string
840     if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
841    
842     // cheesy way of finding strings which were already used
843     if(daughter.pdgId()==92){
844     for(unsigned ist=0;ist<usedStringPts.size();ist++){
845     if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
846     }
847     usedStringPts.push_back(daughter.pt());
848     }
849    
850     jets_.bJetIndex[jets_.bMult] = jets_.nref;
851     jets_.bStatus[jets_.bMult] = daughterStatus;
852     jets_.bVx[jets_.bMult] = daughter.vx();
853     jets_.bVy[jets_.bMult] = daughter.vy();
854     jets_.bVz[jets_.bMult] = daughter.vz();
855     jets_.bPt[jets_.bMult] = daughterPt;
856     jets_.bEta[jets_.bMult] = daughterEta;
857     jets_.bPhi[jets_.bMult] = daughter.phi();
858     jets_.bPdg[jets_.bMult] = daughterPdgId;
859     jets_.bChg[jets_.bMult] = daughter.charge();
860     jets_.bMult++;
861     saveDaughters(daughter);
862     }
863     }
864 yilmaz 1.1
865     DEFINE_FWK_MODULE(HiInclusiveJetAnalyzer);