ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/JetAnalysis/src/HiInclusiveJetAnalyzer.cc
Revision: 1.35
Committed: Sat Jan 26 17:06:06 2013 UTC (12 years, 3 months ago) by yjlee
Content type: text/plain
Branch: MAIN
CVS Tags: HiForest_V02_85, HiForest_V02_84, HiForest_V02_83, HiForest_V02_82, HiForest_V02_81, HiForest_V02_80, HiForest_V02_79, HiForest_V02_78, HiForest_V02_77, HiForest_V02_76, HiForest_V02_75, HiForest_V02_74, HiForest_V02_73, HiForest_V02_72, HiForest_V02_71, HiForest_V02_70, HiForest_V02_69, HiForest_V02_68, HiForest_V02_67, HiForest_V02_66, HiForest_V02_65, HiForest_V02_64, HiForest_V02_63, HiForest_V02_62, HiForest_V02_61, HiForest_V02_60, HiForest_V02_59, HiForest_V02_58, HEAD
Changes since 1.34: +26 -25 lines
Error occurred while calculating annotation data.
Log Message:
Fix the jet ID variables

File Contents

# Content
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 #include "Geometry/Records/interface/CaloGeometryRecord.h"
23
24 #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
25 #include "DataFormats/JetReco/interface/CaloJetCollection.h"
26 #include "SimDataFormats/HiGenData/interface/GenHIEvent.h"
27 #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
28 #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
29 #include "DataFormats/JetReco/interface/GenJetCollection.h"
30 #include "DataFormats/VertexReco/interface/Vertex.h"
31 #include "DataFormats/Math/interface/deltaPhi.h"
32 #include "DataFormats/Math/interface/deltaR.h"
33
34 #include "DataFormats/Common/interface/TriggerResults.h"
35 #include "FWCore/Common/interface/TriggerNames.h"
36 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutSetup.h"
37 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
38 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMapRecord.h"
39 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerObjectMap.h"
40 #include "L1Trigger/GlobalTrigger/interface/L1GlobalTrigger.h"
41
42 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
43 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
44
45 using namespace std;
46 using namespace edm;
47 using namespace reco;
48
49 HiInclusiveJetAnalyzer::HiInclusiveJetAnalyzer(const edm::ParameterSet& iConfig) :
50 geo(0)
51 {
52
53 jetTag_ = iConfig.getParameter<InputTag>("jetTag");
54 matchTag_ = iConfig.getUntrackedParameter<InputTag>("matchTag",jetTag_);
55
56 vtxTag_ = iConfig.getUntrackedParameter<edm::InputTag>("vtxTag",edm::InputTag("hiSelectedVertex"));
57 trackTag_ = iConfig.getParameter<InputTag>("trackTag");
58 useQuality_ = iConfig.getUntrackedParameter<bool>("useQuality",1);
59 trackQuality_ = iConfig.getUntrackedParameter<string>("trackQuality","highPurity");
60
61 isMC_ = iConfig.getUntrackedParameter<bool>("isMC",false);
62 fillGenJets_ = iConfig.getUntrackedParameter<bool>("fillGenJets",false);
63
64 doTrigger_ = iConfig.getUntrackedParameter<bool>("doTrigger",false);
65
66 rParam = iConfig.getParameter<double>("rParam");
67 hardPtMin_ = iConfig.getUntrackedParameter<double>("hardPtMin",4);
68 jetPtMin_ = iConfig.getUntrackedParameter<double>("jetPtMin",0);
69
70 if(isMC_){
71 genjetTag_ = iConfig.getParameter<InputTag>("genjetTag");
72 eventInfoTag_ = iConfig.getParameter<InputTag>("eventInfoTag");
73 }
74 verbose_ = iConfig.getUntrackedParameter<bool>("verbose",false);
75
76 useCentrality_ = iConfig.getUntrackedParameter<bool>("useCentrality",false);
77 useVtx_ = iConfig.getUntrackedParameter<bool>("useVtx",false);
78 useJEC_ = iConfig.getUntrackedParameter<bool>("useJEC",true);
79 usePat_ = iConfig.getUntrackedParameter<bool>("usePAT",true);
80
81 doLifeTimeTagging_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTagging",false);
82 doLifeTimeTaggingExtras_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTaggingExtras",true);
83 saveBfragments_ = iConfig.getUntrackedParameter<bool>("saveBfragments",false);
84 skipCorrections_ = iConfig.getUntrackedParameter<bool>("skipCorrections",false);
85
86 pfCandidateLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("pfCandidateLabel",edm::InputTag("particleFlowTmp"));
87
88 EBSrc_ = iConfig.getUntrackedParameter<edm::InputTag>("EBRecHitSrc",edm::InputTag("ecalRecHit","EcalRecHitsEB"));
89 EESrc_ = iConfig.getUntrackedParameter<edm::InputTag>("EERecHitSrc",edm::InputTag("ecalRecHit","EcalRecHitsEE"));
90 HcalRecHitHFSrc_ = iConfig.getUntrackedParameter<edm::InputTag>("hcalHFRecHitSrc",edm::InputTag("hfreco"));
91 HcalRecHitHBHESrc_ = iConfig.getUntrackedParameter<edm::InputTag>("hcalHBHERecHitSrc",edm::InputTag("hbhereco"));
92
93 genParticleSrc_ = iConfig.getUntrackedParameter<edm::InputTag>("genParticles",edm::InputTag("hiGenParticles"));
94
95 if(doTrigger_){
96 L1gtReadout_ = iConfig.getParameter<edm::InputTag>("L1gtReadout");
97 hltResName_ = iConfig.getUntrackedParameter<string>("hltTrgResults","TriggerResults::HLT");
98
99
100 if (iConfig.exists("hltTrgNames"))
101 hltTrgNames_ = iConfig.getUntrackedParameter<vector<string> >("hltTrgNames");
102
103 if (iConfig.exists("hltProcNames"))
104 hltProcNames_ = iConfig.getUntrackedParameter<vector<string> >("hltProcNames");
105 else {
106 hltProcNames_.push_back("FU");
107 hltProcNames_.push_back("HLT");
108 }
109 }
110
111 // cout<<" jet collection : "<<jetTag_<<endl;
112 doSubEvent_ = 0;
113
114 if(isMC_){
115 // cout<<" genjet collection : "<<genjetTag_<<endl;
116 genPtMin_ = iConfig.getUntrackedParameter<double>("genPtMin",0);
117 doSubEvent_ = iConfig.getUntrackedParameter<bool>("doSubEvent",1);
118 }
119
120
121 }
122
123
124
125 HiInclusiveJetAnalyzer::~HiInclusiveJetAnalyzer() { }
126
127
128
129 void
130 HiInclusiveJetAnalyzer::beginRun(const edm::Run& run,
131 const edm::EventSetup & es) {}
132
133 void
134 HiInclusiveJetAnalyzer::beginJob() {
135
136 centrality_ = 0;
137
138 //string jetTagName = jetTag_.label()+"_tree";
139 string jetTagTitle = jetTag_.label()+" Jet Analysis Tree";
140 t = fs1->make<TTree>("t",jetTagTitle.c_str());
141
142 // TTree* t= new TTree("t","Jet Response Analyzer");
143 //t->Branch("run",&jets_.run,"run/I");
144 t->Branch("evt",&jets_.evt,"evt/I");
145 //t->Branch("lumi",&jets_.lumi,"lumi/I");
146 t->Branch("b",&jets_.b,"b/F");
147 if (useVtx_) {
148 t->Branch("vx",&jets_.vx,"vx/F");
149 t->Branch("vy",&jets_.vy,"vy/F");
150 t->Branch("vz",&jets_.vz,"vz/F");
151 }
152 if (useCentrality_) {
153 t->Branch("hf",&jets_.hf,"hf/F");
154 t->Branch("bin",&jets_.bin,"bin/I");
155 }
156
157 t->Branch("nref",&jets_.nref,"nref/I");
158 t->Branch("rawpt",jets_.rawpt,"rawpt[nref]/F");
159 if(!skipCorrections_) t->Branch("jtpt",jets_.jtpt,"jtpt[nref]/F");
160 t->Branch("jteta",jets_.jteta,"jteta[nref]/F");
161 t->Branch("jty",jets_.jty,"jty[nref]/F");
162 t->Branch("jtphi",jets_.jtphi,"jtphi[nref]/F");
163 t->Branch("jtpu",jets_.jtpu,"jtpu[nref]/F");
164 t->Branch("jtm",jets_.jtm,"jtm[nref]/F");
165
166 // jet ID information, jet composition
167 t->Branch("discr_fr01", jets_.discr_fr01,"discr_fr01[nref]/F");
168
169 t->Branch("trackMax", jets_.trackMax,"trackMax[nref]/F");
170 t->Branch("trackSum", jets_.trackSum,"trackSum[nref]/F");
171 t->Branch("trackN", jets_.trackN,"trackN[nref]/I");
172 t->Branch("trackHardSum", jets_.trackHardSum,"trackHardSum[nref]/F");
173 t->Branch("trackHardN", jets_.trackHardN,"trackHardN[nref]/I");
174
175 t->Branch("chargedMax", jets_.chargedMax,"chargedMax[nref]/F");
176 t->Branch("chargedSum", jets_.chargedSum,"chargedSum[nref]/F");
177 t->Branch("chargedN", jets_.chargedN,"chargedN[nref]/I");
178 t->Branch("chargedHardSum", jets_.chargedHardSum,"chargedHardSum[nref]/F");
179 t->Branch("chargedHardN", jets_.chargedHardN,"chargedHardN[nref]/I");
180
181 t->Branch("photonMax", jets_.photonMax,"photonMax[nref]/F");
182 t->Branch("photonSum", jets_.photonSum,"photonSum[nref]/F");
183 t->Branch("photonN", jets_.photonN,"photonN[nref]/I");
184 t->Branch("photonHardSum", jets_.photonHardSum,"photonHardSum[nref]/F");
185 t->Branch("photonHardN", jets_.photonHardN,"photonHardN[nref]/I");
186
187 t->Branch("neutralMax", jets_.neutralMax,"neutralMax[nref]/F");
188 t->Branch("neutralSum", jets_.neutralSum,"neutralSum[nref]/F");
189 t->Branch("neutralN", jets_.neutralN,"neutralN[nref]/I");
190
191 t->Branch("hcalSum", jets_.hcalSum,"hcalSum[nref]/F");
192 t->Branch("ecalSum", jets_.ecalSum,"ecalSum[nref]/F");
193
194 t->Branch("eMax", jets_.eMax,"eMax[nref]/F");
195 t->Branch("eSum", jets_.eSum,"eSum[nref]/F");
196 t->Branch("eN", jets_.eN,"eN[nref]/I");
197
198 t->Branch("muMax", jets_.muMax,"muMax[nref]/F");
199 t->Branch("muSum", jets_.muSum,"muSum[nref]/F");
200 t->Branch("muN", jets_.muN,"muN[nref]/I");
201
202
203 t->Branch("fHPD",jets_.fHPD,"fHPD[nref]/F");
204 t->Branch("fRBX",jets_.fRBX,"fRBX[nref]/F");
205 t->Branch("n90",jets_.n90,"n90[nref]/I");
206 t->Branch("fSubDet1",jets_.fSubDet1,"fSubDet1[nref]/F");
207 t->Branch("fSubDet2",jets_.fSubDet2,"fSubDet2[nref]/F");
208 t->Branch("fSubDet3",jets_.fSubDet3,"fSubDet3[nref]/F");
209 t->Branch("fSubDet4",jets_.fSubDet4,"fSubDet4[nref]/F");
210 t->Branch("restrictedEMF",jets_.restrictedEMF,"restrictedEMF[nref]/F");
211 t->Branch("nHCAL",jets_.nHCAL,"nHCAL[nref]/I");
212 t->Branch("nECAL",jets_.nECAL,"nECAL[nref]/I");
213 t->Branch("apprHPD",jets_.apprHPD,"apprHPD[nref]/F");
214 t->Branch("apprRBX",jets_.apprRBX,"apprRBX[nref]/F");
215
216 // t->Branch("hitsInN90",jets_.n90,"hitsInN90[nref]");
217 t->Branch("n2RPC",jets_.n2RPC,"n2RPC[nref]/I");
218 t->Branch("n3RPC",jets_.n3RPC,"n3RPC[nref]/I");
219 t->Branch("nRPC",jets_.nRPC,"nRPC[nref]/I");
220
221 t->Branch("fEB",jets_.fEB,"fEB[nref]/F");
222 t->Branch("fEE",jets_.fEE,"fEE[nref]/F");
223 t->Branch("fHB",jets_.fHB,"fHB[nref]/F");
224 t->Branch("fHE",jets_.fHE,"fHE[nref]/F");
225 t->Branch("fHO",jets_.fHO,"fHO[nref]/F");
226 t->Branch("fLong",jets_.fLong,"fLong[nref]/F");
227 t->Branch("fShort",jets_.fShort,"fShort[nref]/F");
228 t->Branch("fLS",jets_.fLS,"fLS[nref]/F");
229 t->Branch("fHFOOT",jets_.fHFOOT,"fHFOOT[nref]/F");
230
231
232 // Jet ID
233
234 if(!skipCorrections_) t->Branch("matchedPt", jets_.matchedPt,"matchedPt[nref]/F");
235 t->Branch("matchedRawPt", jets_.matchedRawPt,"matchedRawPt[nref]/F");
236 t->Branch("matchedR", jets_.matchedR,"matchedR[nref]/F");
237
238 // b-jet discriminators
239 if (doLifeTimeTagging_) {
240
241 t->Branch("discr_csvMva",jets_.discr_csvMva,"discr_csvMva[nref]/F");
242 t->Branch("discr_csvSimple",jets_.discr_csvSimple,"discr_csvSimple[nref]/F");
243 t->Branch("discr_muByIp3",jets_.discr_muByIp3,"discr_muByIp3[nref]/F");
244 t->Branch("discr_muByPt",jets_.discr_muByPt,"discr_muByPt[nref]/F");
245 t->Branch("discr_prob",jets_.discr_prob,"discr_prob[nref]/F");
246 t->Branch("discr_probb",jets_.discr_probb,"discr_probb[nref]/F");
247 t->Branch("discr_tcHighEff",jets_.discr_tcHighEff,"discr_tcHighEff[nref]/F");
248 t->Branch("discr_tcHighPur",jets_.discr_tcHighPur,"discr_tcHighPur[nref]/F");
249
250 t->Branch("nsvtx", jets_.nsvtx, "nsvtx[nref]/I");
251 t->Branch("svtxntrk", jets_.svtxntrk, "svtxntrk[nref]/I");
252 t->Branch("svtxdl", jets_.svtxdl, "svtxdl[nref]/F");
253 t->Branch("svtxdls", jets_.svtxdls, "svtxdls[nref]/F");
254 t->Branch("svtxm", jets_.svtxm, "svtxm[nref]/F");
255 t->Branch("svtxpt", jets_.svtxpt, "svtxpt[nref]/F");
256
257 t->Branch("nIPtrk",jets_.nIPtrk,"nIPtrk[nref]/I");
258 t->Branch("nselIPtrk",jets_.nselIPtrk,"nselIPtrk[nref]/I");
259
260 if (doLifeTimeTaggingExtras_) {
261 t->Branch("nIP",&jets_.nIP,"nIP/I");
262 t->Branch("ipJetIndex",jets_.ipJetIndex,"ipJetIndex[nIP]/I");
263 t->Branch("ipPt",jets_.ipPt,"ipPt[nIP]/F");
264 t->Branch("ipProb0",jets_.ipProb0,"ipProb0[nIP]/F");
265 t->Branch("ipProb1",jets_.ipProb1,"ipProb1[nIP]/F");
266 t->Branch("ip2d",jets_.ip2d,"ip2d[nIP]/F");
267 t->Branch("ip2dSig",jets_.ip2dSig,"ip2dSig[nIP]/F");
268 t->Branch("ip3d",jets_.ip3d,"ip3d[nIP]/F");
269 t->Branch("ip3dSig",jets_.ip3dSig,"ip3dSig[nIP]/F");
270 t->Branch("ipDist2Jet",jets_.ipDist2Jet,"ipDist2Jet[nIP]/F");
271 t->Branch("ipDist2JetSig",jets_.ipDist2JetSig,"ipDist2JetSig[nIP]/F");
272 t->Branch("ipClosest2Jet",jets_.ipClosest2Jet,"ipClosest2Jet[nIP]/F");
273
274 }
275
276 t->Branch("mue", jets_.mue, "mue[nref]/F");
277 t->Branch("mupt", jets_.mupt, "mupt[nref]/F");
278 t->Branch("mueta", jets_.mueta, "mueta[nref]/F");
279 t->Branch("muphi", jets_.muphi, "muphi[nref]/F");
280 t->Branch("mudr", jets_.mudr, "mudr[nref]/F");
281 t->Branch("muptrel", jets_.muptrel, "muptrel[nref]/F");
282 t->Branch("muchg", jets_.muchg, "muchg[nref]/I");
283 }
284
285
286 if(isMC_){
287 t->Branch("beamId1",&jets_.beamId1,"beamId1/I");
288 t->Branch("beamId2",&jets_.beamId2,"beamId2/I");
289
290 t->Branch("pthat",&jets_.pthat,"pthat/F");
291
292 // Only matched gen jets
293 t->Branch("refpt",jets_.refpt,"refpt[nref]/F");
294 t->Branch("refeta",jets_.refeta,"refeta[nref]/F");
295 t->Branch("refy",jets_.refy,"refy[nref]/F");
296 t->Branch("refphi",jets_.refphi,"refphi[nref]/F");
297 t->Branch("refdphijt",jets_.refdphijt,"refdphijt[nref]/F");
298 t->Branch("refdrjt",jets_.refdrjt,"refdrjt[nref]/F");
299 // matched parton
300 t->Branch("refparton_pt",jets_.refparton_pt,"refparton_pt[nref]/F");
301 t->Branch("refparton_flavor",jets_.refparton_flavor,"refparton_flavor[nref]/I");
302 t->Branch("refparton_flavorForB",jets_.refparton_flavorForB,"refparton_flavorForB[nref]/I");
303
304 t->Branch("genChargedSum", jets_.genChargedSum,"genChargedSum[nref]/F");
305 t->Branch("genHardSum", jets_.genHardSum,"genHardSum[nref]/F");
306 t->Branch("signalChargedSum", jets_.signalChargedSum,"signalChargedSum[nref]/F");
307 t->Branch("signalHardSum", jets_.signalHardSum,"signalHardSum[nref]/F");
308
309 if(doSubEvent_){
310 t->Branch("subid",jets_.subid,"subid[nref]/I");
311 }
312
313 if(fillGenJets_){
314 // For all gen jets, matched or unmatched
315 t->Branch("ngen",&jets_.ngen,"ngen/I");
316 t->Branch("genmatchindex",jets_.genmatchindex,"genmatchindex[ngen]/I");
317 t->Branch("genpt",jets_.genpt,"genpt[ngen]/F");
318 t->Branch("geneta",jets_.geneta,"geneta[ngen]/F");
319 t->Branch("geny",jets_.geny,"geny[ngen]/F");
320 t->Branch("genphi",jets_.genphi,"genphi[ngen]/F");
321 t->Branch("gendphijt",jets_.gendphijt,"gendphijt[ngen]/F");
322 t->Branch("gendrjt",jets_.gendrjt,"gendrjt[ngen]/F");
323
324 if(doSubEvent_){
325 t->Branch("gensubid",jets_.gensubid,"gensubid[ngen]/I");
326 }
327 }
328
329 if(saveBfragments_ ) {
330 t->Branch("bMult",&jets_.bMult,"bMult/I");
331 t->Branch("bJetIndex",jets_.bJetIndex,"bJetIndex[bMult]/I");
332 t->Branch("bStatus",jets_.bStatus,"bStatus[bMult]/I");
333 t->Branch("bVx",jets_.bVx,"bVx[bMult]/F");
334 t->Branch("bVy",jets_.bVy,"bVy[bMult]/F");
335 t->Branch("bVz",jets_.bVz,"bVz[bMult]/F");
336 t->Branch("bPt",jets_.bPt,"bPt[bMult]/F");
337 t->Branch("bEta",jets_.bEta,"bEta[bMult]/F");
338 t->Branch("bPhi",jets_.bPhi,"bPhi[bMult]/F");
339 t->Branch("bPdg",jets_.bPdg,"bPdg[bMult]/I");
340 t->Branch("bChg",jets_.bChg,"bChg[bMult]/I");
341 }
342
343 }
344 /*
345 if(!isMC_){
346 t->Branch("nL1TBit",&jets_.nL1TBit,"nL1TBit/I");
347 t->Branch("l1TBit",jets_.l1TBit,"l1TBit[nL1TBit]/O");
348
349 t->Branch("nL1ABit",&jets_.nL1ABit,"nL1ABit/I");
350 t->Branch("l1ABit",jets_.l1ABit,"l1ABit[nL1ABit]/O");
351
352 t->Branch("nHLTBit",&jets_.nHLTBit,"nHLTBit/I");
353 t->Branch("hltBit",jets_.hltBit,"hltBit[nHLTBit]/O");
354
355 }
356 */
357 TH1D::SetDefaultSumw2();
358
359
360 }
361
362
363 void
364 HiInclusiveJetAnalyzer::analyze(const Event& iEvent,
365 const EventSetup& iSetup) {
366
367 int event = iEvent.id().event();
368 int run = iEvent.id().run();
369 int lumi = iEvent.id().luminosityBlock();
370
371 jets_.run = run;
372 jets_.evt = event;
373 jets_.lumi = lumi;
374
375 LogDebug("HiInclusiveJetAnalyzer")<<"START event: "<<event<<" in run "<<run<<endl;
376
377 int bin = -1;
378 double hf = 0.;
379 double b = 999.;
380
381 if(!geo){
382 edm::ESHandle<CaloGeometry> pGeo;
383 iSetup.get<CaloGeometryRecord>().get(pGeo);
384 geo = pGeo.product();
385 }
386 if(useCentrality_){
387 if(!centrality_) centrality_ = new CentralityProvider(iSetup);
388 centrality_->newEvent(iEvent,iSetup); // make sure you do this first in every event
389 //double c = centrality_->centralityValue();
390 const reco::Centrality *cent = centrality_->raw();
391
392 hf = cent->EtHFhitSum();
393
394 bin = centrality_->getBin();
395 b = centrality_->bMean();
396 }
397
398 // loop the events
399
400 jets_.bin = bin;
401 jets_.hf = hf;
402
403 reco::Vertex::Point vtx(0,0,0);
404 if (useVtx_) {
405 edm::Handle<vector<reco::Vertex> >vertex;
406 iEvent.getByLabel(vtxTag_, vertex);
407
408 if(vertex->size()>0) {
409 jets_.vx=vertex->begin()->x();
410 jets_.vy=vertex->begin()->y();
411 jets_.vz=vertex->begin()->z();
412 vtx = vertex->begin()->position();
413 }
414 }
415
416 edm::Handle<pat::JetCollection> patjets;
417 if(usePat_)iEvent.getByLabel(jetTag_, patjets);
418
419 edm::Handle<pat::JetCollection> matchedjets;
420 iEvent.getByLabel(matchTag_, matchedjets);
421
422 edm::Handle<reco::JetView> jets;
423 iEvent.getByLabel(jetTag_, jets);
424
425 edm::Handle<reco::PFCandidateCollection> pfCandidates;
426 iEvent.getByLabel(pfCandidateLabel_,pfCandidates);
427
428 edm::Handle<reco::TrackCollection> tracks;
429 iEvent.getByLabel(trackTag_,tracks);
430
431 edm::Handle<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit> > > ebHits;
432 edm::Handle<edm::SortedCollection<EcalRecHit,edm::StrictWeakOrdering<EcalRecHit> > > eeHits;
433
434 edm::Handle<HFRecHitCollection> hfHits;
435 edm::Handle<HBHERecHitCollection> hbheHits;
436
437 iEvent.getByLabel(HcalRecHitHBHESrc_,hbheHits);
438 iEvent.getByLabel(HcalRecHitHFSrc_,hfHits);
439 iEvent.getByLabel(EBSrc_,ebHits);
440 iEvent.getByLabel(EESrc_,eeHits);
441
442 edm::Handle<reco::GenParticleCollection> genparts;
443 iEvent.getByLabel(genParticleSrc_,genparts);
444
445
446 // FILL JRA TREE
447 jets_.b = b;
448 jets_.nref = 0;
449
450
451 if(doTrigger_){
452 fillL1Bits(iEvent);
453 fillHLTBits(iEvent);
454 }
455
456 for(unsigned int j = 0; j < jets->size(); ++j){
457 const reco::Jet& jet = (*jets)[j];
458
459 if(jet.pt() < jetPtMin_) continue;
460 if (useJEC_ && usePat_){
461 jets_.rawpt[jets_.nref]=(*patjets)[j].correctedJet("Uncorrected").pt();
462 }
463
464 if(doLifeTimeTagging_){
465
466 if(jetTag_.label()=="icPu5patJets"){
467 jets_.discr_csvMva[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5CombinedSecondaryVertexMVABJetTags");
468 jets_.discr_csvSimple[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5CombinedSecondaryVertexBJetTags");
469 jets_.discr_muByIp3[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5SoftMuonByIP3dBJetTags");
470 jets_.discr_muByPt[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5SoftMuonByPtBJetTags");
471 jets_.discr_prob[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5JetBProbabilityBJetTags");
472 jets_.discr_probb[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5JetProbabilityBJetTags");
473 jets_.discr_tcHighEff[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5TrackCountingHighEffBJetTags");
474 jets_.discr_tcHighPur[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5TrackCountingHighPurBJetTags");
475 }
476 else if(jetTag_.label()=="akPu3PFpatJets"){
477 jets_.discr_csvMva[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFCombinedSecondaryVertexMVABJetTags");
478 jets_.discr_csvSimple[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFCombinedSecondaryVertexBJetTags");
479 jets_.discr_muByIp3[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFSoftMuonByIP3dBJetTags");
480 jets_.discr_muByPt[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFSoftMuonByPtBJetTags");
481 jets_.discr_prob[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFJetBProbabilityBJetTags");
482 jets_.discr_probb[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFJetProbabilityBJetTags");
483 jets_.discr_tcHighEff[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFTrackCountingHighEffBJetTags");
484 jets_.discr_tcHighPur[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFTrackCountingHighPurBJetTags");
485 }
486 else{
487 // cout<<" b-tagging variables not filled for this collection, turn of doLifeTimeTagging "<<endl;
488 }
489
490 const reco::SecondaryVertexTagInfo& tagInfoSV=*(*patjets)[j].tagInfoSecondaryVertex();
491
492 jets_.nsvtx[jets_.nref] = tagInfoSV.nVertices();
493
494 if (tagInfoSV.nVertices()>0) {
495 jets_.svtxntrk[jets_.nref] = tagInfoSV.nVertexTracks(0);
496 // this is the 3d flight distance, for 2-D use (0,true)
497 Measurement1D m1D = tagInfoSV.flightDistance(0);
498 jets_.svtxdl[jets_.nref] = m1D.value();
499 jets_.svtxdls[jets_.nref] = m1D.significance();
500
501 const reco::Vertex& svtx = tagInfoSV.secondaryVertex(0);
502 //cout<<" SV: vx: "<<svtx.x()<<" vy "<<svtx.y()<<" vz "<<svtx.z()<<endl;
503 //cout<<" PV: vx: "<<jet.vx()<<" vy "<<jet.vy()<<" vz "<<jet.vz()<<endl;
504 jets_.svtxm[jets_.nref] = svtx.p4().mass();
505 jets_.svtxpt[jets_.nref] = svtx.p4().pt();
506 //cout<<" chi2 "<<svtx.chi2()<<" ndof "<<svtx.ndof()<<endl;
507 }
508
509 const reco::TrackIPTagInfo& tagInfoIP=*(*patjets)[j].tagInfoTrackIP();
510
511 jets_.nIPtrk[jets_.nref] = tagInfoIP.tracks().size();
512 jets_.nselIPtrk[jets_.nref] = tagInfoIP.selectedTracks().size();
513
514 if (doLifeTimeTaggingExtras_) {
515
516 TrackRefVector selTracks=tagInfoIP.selectedTracks();
517
518 GlobalPoint pv(tagInfoIP.primaryVertex()->position().x(),tagInfoIP.primaryVertex()->position().y(),tagInfoIP.primaryVertex()->position().z());
519
520 for(int it=0;it<jets_.nselIPtrk[jets_.nref] ;it++)
521 {
522 jets_.ipJetIndex[jets_.nIP + it]= jets_.nref;
523 TrackIPTagInfo::TrackIPData data = tagInfoIP.impactParameterData()[it];
524 jets_.ipPt[jets_.nIP + it] = selTracks[it]->pt();
525 jets_.ipProb0[jets_.nIP + it] = tagInfoIP.probabilities(0)[it];
526 jets_.ipProb1[jets_.nIP + it] = tagInfoIP.probabilities(1)[it];
527 jets_.ip2d[jets_.nIP + it] = data.ip2d.value();
528 jets_.ip2dSig[jets_.nIP + it] = data.ip2d.significance();
529 jets_.ip3d[jets_.nIP + it] = data.ip3d.value();
530 jets_.ip3dSig[jets_.nIP + it] = data.ip3d.significance();
531 jets_.ipDist2Jet[jets_.nIP + it] = data.distanceToJetAxis.value();
532 jets_.ipDist2JetSig[jets_.nIP + it] = data.distanceToJetAxis.significance();
533 jets_.ipClosest2Jet[jets_.nIP + it] = (data.closestToJetAxis - pv).mag(); //decay length
534 }
535
536 jets_.nIP += jets_.nselIPtrk[jets_.nref];
537
538 }
539
540 const reco::PFCandidateCollection *pfCandidateColl = &(*pfCandidates);
541 int pfMuonIndex = getPFJetMuon(jet, pfCandidateColl);
542 if(pfMuonIndex >=0){
543 const reco::PFCandidate muon = pfCandidateColl->at(pfMuonIndex);
544 jets_.mupt[jets_.nref] = muon.pt();
545 jets_.mueta[jets_.nref] = muon.eta();
546 jets_.muphi[jets_.nref] = muon.phi();
547 jets_.mue[jets_.nref] = muon.energy();
548 jets_.mudr[jets_.nref] = reco::deltaR(jet,muon);
549 jets_.muptrel[jets_.nref] = getPtRel(muon, jet);
550 jets_.muchg[jets_.nref] = muon.charge();
551 }else{
552 jets_.mupt[jets_.nref] = 0.0;
553 jets_.mueta[jets_.nref] = 0.0;
554 jets_.muphi[jets_.nref] = 0.0;
555 jets_.mue[jets_.nref] = 0.0;
556 jets_.mudr[jets_.nref] = 9.9;
557 jets_.muptrel[jets_.nref] = 0.0;
558 jets_.muchg[jets_.nref] = 0;
559 }
560
561 }
562
563 // Jet ID variables
564
565 jets_.muMax[jets_.nref] = 0;
566 jets_.muSum[jets_.nref] = 0;
567 jets_.muN[jets_.nref] = 0;
568
569 jets_.eMax[jets_.nref] = 0;
570 jets_.eSum[jets_.nref] = 0;
571 jets_.eN[jets_.nref] = 0;
572
573 jets_.neutralMax[jets_.nref] = 0;
574 jets_.neutralSum[jets_.nref] = 0;
575 jets_.neutralN[jets_.nref] = 0;
576
577 jets_.photonMax[jets_.nref] = 0;
578 jets_.photonSum[jets_.nref] = 0;
579 jets_.photonN[jets_.nref] = 0;
580 jets_.photonHardSum[jets_.nref] = 0;
581 jets_.photonHardN[jets_.nref] = 0;
582
583 jets_.chargedMax[jets_.nref] = 0;
584 jets_.chargedSum[jets_.nref] = 0;
585 jets_.chargedN[jets_.nref] = 0;
586 jets_.chargedHardSum[jets_.nref] = 0;
587 jets_.chargedHardN[jets_.nref] = 0;
588
589 jets_.trackMax[jets_.nref] = 0;
590 jets_.trackSum[jets_.nref] = 0;
591 jets_.trackN[jets_.nref] = 0;
592 jets_.trackHardSum[jets_.nref] = 0;
593 jets_.trackHardN[jets_.nref] = 0;
594
595 jets_.hcalSum[jets_.nref] = 0;
596 jets_.ecalSum[jets_.nref] = 0;
597
598 jets_.genChargedSum[jets_.nref] = 0;
599 jets_.genHardSum[jets_.nref] = 0;
600
601 jets_.signalChargedSum[jets_.nref] = 0;
602 jets_.signalHardSum[jets_.nref] = 0;
603
604 jets_.subid[jets_.nref] = -1;
605
606 for(unsigned int icand = 0; icand < tracks->size(); ++icand){
607 const reco::Track& track = (*tracks)[icand];
608 if(useQuality_ ){
609 bool goodtrack = track.quality(reco::TrackBase::qualityByName(trackQuality_));
610 if(!goodtrack) continue;
611 }
612
613 double dr = deltaR(jet,track);
614 if(dr < rParam){
615 double ptcand = track.pt();
616 jets_.trackSum[jets_.nref] += ptcand;
617 jets_.trackN[jets_.nref] += 1;
618
619 if(ptcand > hardPtMin_){
620 jets_.trackHardSum[jets_.nref] += ptcand;
621 jets_.trackHardN[jets_.nref] += 1;
622
623 }
624 if(ptcand > jets_.trackMax[jets_.nref]) jets_.trackMax[jets_.nref] = ptcand;
625
626 }
627 }
628
629 for(unsigned int icand = 0; icand < pfCandidates->size(); ++icand){
630 const reco::PFCandidate& track = (*pfCandidates)[icand];
631 double dr = deltaR(jet,track);
632 if(dr < rParam){
633 double ptcand = track.pt();
634 int pfid = track.particleId();
635
636 switch(pfid){
637
638 case 1:
639 jets_.chargedSum[jets_.nref] += ptcand;
640 jets_.chargedN[jets_.nref] += 1;
641 if(ptcand > hardPtMin_){
642 jets_.chargedHardSum[jets_.nref] += ptcand;
643 jets_.chargedHardN[jets_.nref] += 1;
644 }
645 if(ptcand > jets_.chargedMax[jets_.nref]) jets_.chargedMax[jets_.nref] = ptcand;
646 break;
647
648 case 2:
649 jets_.eSum[jets_.nref] += ptcand;
650 jets_.eN[jets_.nref] += 1;
651 if(ptcand > jets_.eMax[jets_.nref]) jets_.eMax[jets_.nref] = ptcand;
652 break;
653
654 case 3:
655 jets_.muSum[jets_.nref] += ptcand;
656 jets_.muN[jets_.nref] += 1;
657 if(ptcand > jets_.muMax[jets_.nref]) jets_.muMax[jets_.nref] = ptcand;
658 break;
659
660 case 4:
661 jets_.photonSum[jets_.nref] += ptcand;
662 jets_.photonN[jets_.nref] += 1;
663 if(ptcand > hardPtMin_){
664 jets_.photonHardSum[jets_.nref] += ptcand;
665 jets_.photonHardN[jets_.nref] += 1;
666 }
667 if(ptcand > jets_.photonMax[jets_.nref]) jets_.photonMax[jets_.nref] = ptcand;
668 break;
669
670 case 5:
671 jets_.neutralSum[jets_.nref] += ptcand;
672 jets_.neutralN[jets_.nref] += 1;
673 if(ptcand > jets_.neutralMax[jets_.nref]) jets_.neutralMax[jets_.nref] = ptcand;
674 break;
675
676 default:
677 break;
678
679 }
680 }
681 }
682
683 // Calorimeter fractions
684
685 for(unsigned int i = 0; i < hbheHits->size(); ++i){
686 const HBHERecHit & hit= (*hbheHits)[i];
687 math::XYZPoint pos = getPosition(hit.id(),vtx);
688 double dr = deltaR(jet.eta(),jet.phi(),pos.eta(),pos.phi());
689 if(dr < rParam){
690 jets_.hcalSum[jets_.nref] += getEt(pos,hit.energy());
691 }
692 }
693
694 for(unsigned int i = 0; i < hfHits->size(); ++i){
695 const HFRecHit & hit= (*hfHits)[i];
696 math::XYZPoint pos = getPosition(hit.id(),vtx);
697 double dr = deltaR(jet.eta(),jet.phi(),pos.eta(),pos.phi());
698 if(dr < rParam){
699 jets_.hcalSum[jets_.nref] += getEt(pos,hit.energy());
700 }
701 }
702
703
704 for(unsigned int i = 0; i < ebHits->size(); ++i){
705 const EcalRecHit & hit= (*ebHits)[i];
706 math::XYZPoint pos = getPosition(hit.id(),vtx);
707 double dr = deltaR(jet.eta(),jet.phi(),pos.eta(),pos.phi());
708 if(dr < rParam){
709 jets_.ecalSum[jets_.nref] += getEt(pos,hit.energy());
710 }
711 }
712
713 for(unsigned int i = 0; i < eeHits->size(); ++i){
714 const EcalRecHit & hit= (*eeHits)[i];
715 math::XYZPoint pos = getPosition(hit.id(),vtx);
716 double dr = deltaR(jet.eta(),jet.phi(),pos.eta(),pos.phi());
717 if(dr < rParam){
718 jets_.ecalSum[jets_.nref] += getEt(pos,hit.energy());
719 }
720 }
721
722 // Jet ID for CaloJets
723
724
725
726
727
728
729
730 // Alternative reconstruction matching (PF for calo, calo for PF)
731
732 double drMin = 100;
733 for(unsigned int imatch = 0 ; imatch < matchedjets->size(); ++imatch){
734 const pat::Jet& mjet = (*matchedjets)[imatch];
735
736 double dr = deltaR(jet,mjet);
737 if(dr < drMin){
738 jets_.matchedPt[jets_.nref] = mjet.pt();
739 jets_.matchedRawPt[jets_.nref] = mjet.correctedJet("Uncorrected").pt();
740 jets_.matchedR[jets_.nref] = dr;
741 drMin = dr;
742 }
743 }
744
745 // if(etrk.quality(reco::TrackBase::qualityByName(qualityString_))) pev_.trkQual[pev_.nTrk]=1;
746
747 /////////////////////////////////////////////////////////////////
748 // Jet core pt^2 discriminant for fake jets
749 // Edited by Yue Shi Lai <ylai@mit.edu>
750
751 // Initial value is 0
752 jets_.discr_fr01[jets_.nref] = 0;
753 // Start with no directional adaption, i.e. the fake rejection
754 // axis is the jet axis
755 float pseudorapidity_adapt = jets_.jteta[jets_.nref];
756 float azimuth_adapt = jets_.jtphi[jets_.nref];
757
758 // Unadapted discriminant with adaption search
759 for (size_t iteration = 0; iteration < 2; iteration++) {
760 float pseudorapidity_adapt_new = pseudorapidity_adapt;
761 float azimuth_adapt_new = azimuth_adapt;
762 float max_weighted_perp = 0;
763 float perp_square_sum = 0;
764
765 for (size_t index_pf_candidate = 0;
766 index_pf_candidate < pfCandidates->size();
767 index_pf_candidate++) {
768 const reco::PFCandidate &p =
769 (*pfCandidates)[index_pf_candidate];
770
771 switch (p.particleId()) {
772 //case 1: // Charged hadron
773 //case 3: // Muon
774 case 4: // Photon
775 {
776 const float dpseudorapidity =
777 p.eta() - pseudorapidity_adapt;
778 const float dazimuth =
779 reco::deltaPhi(p.phi(), azimuth_adapt);
780 // The Gaussian scale factor is 0.5 / (0.1 * 0.1)
781 // = 50
782 const float angular_weight =
783 exp(-50.0F * (dpseudorapidity * dpseudorapidity +
784 dazimuth * dazimuth));
785 const float weighted_perp =
786 angular_weight * p.pt() * p.pt();
787 const float weighted_perp_square =
788 weighted_perp * p.pt();
789
790 perp_square_sum += weighted_perp_square;
791 if (weighted_perp >= max_weighted_perp) {
792 pseudorapidity_adapt_new = p.eta();
793 azimuth_adapt_new = p.phi();
794 max_weighted_perp = weighted_perp;
795 }
796 }
797 default:
798 break;
799 }
800 }
801 // Update the fake rejection value
802 jets_.discr_fr01[jets_.nref] = std::max(
803 jets_.discr_fr01[jets_.nref], perp_square_sum);
804 // Update the directional adaption
805 pseudorapidity_adapt = pseudorapidity_adapt_new;
806 azimuth_adapt = azimuth_adapt_new;
807 }
808
809 jets_.jtpt[jets_.nref] = jet.pt();
810 jets_.jteta[jets_.nref] = jet.eta();
811 jets_.jtphi[jets_.nref] = jet.phi();
812 jets_.jty[jets_.nref] = jet.eta();
813 jets_.jtpu[jets_.nref] = jet.pileup();
814 jets_.jtm[jets_.nref] = jet.mass();
815
816 if(usePat_){
817
818 jets_.fHPD[jets_.nref] = (*patjets)[j].jetID().fHPD;
819 jets_.fRBX[jets_.nref] = (*patjets)[j].jetID().fRBX;
820 jets_.n90[jets_.nref] = (*patjets)[j].n90();
821
822 jets_.fSubDet1[jets_.nref] = (*patjets)[j].jetID().fSubDetector1;
823 jets_.fSubDet2[jets_.nref] = (*patjets)[j].jetID().fSubDetector2;
824 jets_.fSubDet3[jets_.nref] = (*patjets)[j].jetID().fSubDetector3;
825 jets_.fSubDet4[jets_.nref] = (*patjets)[j].jetID().fSubDetector4;
826 jets_.restrictedEMF[jets_.nref] = (*patjets)[j].jetID().restrictedEMF;
827 jets_.nHCAL[jets_.nref] = (*patjets)[j].jetID().nHCALTowers;
828 jets_.nECAL[jets_.nref] = (*patjets)[j].jetID().nECALTowers;
829 jets_.apprHPD[jets_.nref] = (*patjets)[j].jetID().approximatefHPD;
830 jets_.apprRBX[jets_.nref] = (*patjets)[j].jetID().approximatefRBX;
831
832 // jets_.n90[jets_.nref] = (*patjets)[j].jetID().hitsInN90;
833 jets_.n2RPC[jets_.nref] = (*patjets)[j].jetID().numberOfHits2RPC;
834 jets_.n3RPC[jets_.nref] = (*patjets)[j].jetID().numberOfHits3RPC;
835 jets_.nRPC[jets_.nref] = (*patjets)[j].jetID().numberOfHitsRPC;
836
837 jets_.fEB[jets_.nref] = (*patjets)[j].jetID().fEB;
838 jets_.fEE[jets_.nref] = (*patjets)[j].jetID().fEE;
839 jets_.fHB[jets_.nref] = (*patjets)[j].jetID().fHB;
840 jets_.fHE[jets_.nref] = (*patjets)[j].jetID().fHE;
841 jets_.fHO[jets_.nref] = (*patjets)[j].jetID().fHO;
842 jets_.fLong[jets_.nref] = (*patjets)[j].jetID().fLong;
843 jets_.fShort[jets_.nref] = (*patjets)[j].jetID().fShort;
844 jets_.fLS[jets_.nref] = (*patjets)[j].jetID().fLS;
845 jets_.fHFOOT[jets_.nref] = (*patjets)[j].jetID().fHFOOT;
846
847
848 }
849
850 if(isMC_){
851
852 for(UInt_t i = 0; i < genparts->size(); ++i){
853 const reco::GenParticle& p = (*genparts)[i];
854 if (p.status()!=1) continue;
855 if (p.charge()==0) continue;
856 double dr = deltaR(jet,p);
857 if(dr < rParam){
858 double ppt = p.pt();
859 jets_.genChargedSum[jets_.nref] += ppt;
860 if(ppt > hardPtMin_) jets_.genHardSum[jets_.nref] += ppt;
861 if(p.collisionId() == 0){
862 jets_.signalChargedSum[jets_.nref] += ppt;
863 if(ppt > hardPtMin_) jets_.signalHardSum[jets_.nref] += ppt;
864 }
865
866 }
867 }
868
869 }
870
871 if(isMC_ && usePat_){
872
873
874 const reco::GenJet * genjet = (*patjets)[j].genJet();
875
876 if(genjet){
877 jets_.refpt[jets_.nref] = genjet->pt();
878 jets_.refeta[jets_.nref] = genjet->eta();
879 jets_.refphi[jets_.nref] = genjet->phi();
880 jets_.refy[jets_.nref] = genjet->eta();
881 jets_.refdphijt[jets_.nref] = reco::deltaPhi(jet.phi(), genjet->phi());
882 jets_.refdrjt[jets_.nref] = reco::deltaR(jet.eta(),jet.phi(),genjet->eta(),genjet->phi());
883
884 if(doSubEvent_){
885 const GenParticle* gencon = genjet->getGenConstituent(0);
886 jets_.subid[jets_.nref] = gencon->collisionId();
887 }
888
889 }else{
890 jets_.refpt[jets_.nref] = -999.;
891 jets_.refeta[jets_.nref] = -999.;
892 jets_.refphi[jets_.nref] = -999.;
893 jets_.refy[jets_.nref] = -999.;
894 jets_.refdphijt[jets_.nref] = -999.;
895 jets_.refdrjt[jets_.nref] = -999.;
896 }
897
898 jets_.refparton_flavorForB[jets_.nref] = (*patjets)[j].partonFlavour();
899
900 // matched partons
901 const reco::GenParticle & parton = *(*patjets)[j].genParton();
902
903 if((*patjets)[j].genParton()){
904 jets_.refparton_pt[jets_.nref] = parton.pt();
905 jets_.refparton_flavor[jets_.nref] = parton.pdgId();
906
907 if(saveBfragments_ && abs(jets_.refparton_flavorForB[jets_.nref])==5){
908
909 usedStringPts.clear();
910
911 // uncomment this if you want to know the ugly truth about parton matching -matt
912 //if(jet.pt() > 50 &&abs(parton.pdgId())!=5 && parton.pdgId()!=21)
913 // cout<<" Identified as a b, but doesn't match b or gluon, id = "<<parton.pdgId()<<endl;
914
915 jets_.bJetIndex[jets_.bMult] = jets_.nref;
916 jets_.bStatus[jets_.bMult] = parton.status();
917 jets_.bVx[jets_.bMult] = parton.vx();
918 jets_.bVy[jets_.bMult] = parton.vy();
919 jets_.bVz[jets_.bMult] = parton.vz();
920 jets_.bPt[jets_.bMult] = parton.pt();
921 jets_.bEta[jets_.bMult] = parton.eta();
922 jets_.bPhi[jets_.bMult] = parton.phi();
923 jets_.bPdg[jets_.bMult] = parton.pdgId();
924 jets_.bChg[jets_.bMult] = parton.charge();
925 jets_.bMult++;
926 saveDaughters(parton);
927 }
928
929
930 } else {
931 jets_.refparton_pt[jets_.nref] = -999;
932 jets_.refparton_flavor[jets_.nref] = -999;
933 }
934
935
936 }
937
938 jets_.nref++;
939
940
941 }
942
943
944 if(isMC_){
945
946 edm::Handle<HepMCProduct> hepMCProduct;
947 iEvent.getByLabel(eventInfoTag_,hepMCProduct);
948 const HepMC::GenEvent* MCEvt = hepMCProduct->GetEvent();
949
950 std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beamParticles = MCEvt->beam_particles();
951 if(beamParticles.first != 0)jets_.beamId1 = beamParticles.first->pdg_id();
952 if(beamParticles.second != 0)jets_.beamId2 = beamParticles.second->pdg_id();
953
954 edm::Handle<GenEventInfoProduct> hEventInfo;
955 iEvent.getByLabel(eventInfoTag_,hEventInfo);
956 //jets_.pthat = hEventInfo->binningValues()[0];
957
958 // binning values and qscale appear to be equivalent, but binning values not always present
959 jets_.pthat = hEventInfo->qScale();
960
961 edm::Handle<vector<reco::GenJet> >genjets;
962 iEvent.getByLabel(genjetTag_, genjets);
963
964 jets_.ngen = 0;
965 for(unsigned int igen = 0 ; igen < genjets->size(); ++igen){
966 const reco::GenJet & genjet = (*genjets)[igen];
967
968 float genjet_pt = genjet.pt();
969
970 // threshold to reduce size of output in minbias PbPb
971 if(genjet_pt>genPtMin_){
972
973
974 jets_.genpt[jets_.ngen] = genjet_pt;
975 jets_.geneta[jets_.ngen] = genjet.eta();
976 jets_.genphi[jets_.ngen] = genjet.phi();
977 jets_.geny[jets_.ngen] = genjet.eta();
978
979 if(doSubEvent_){
980 const GenParticle* gencon = genjet.getGenConstituent(0);
981 jets_.gensubid[jets_.ngen] = gencon->collisionId();
982 }
983
984 // find matching patJet if there is one
985
986 jets_.gendrjt[jets_.ngen] = -1.0;
987 jets_.genmatchindex[jets_.ngen] = -1;
988
989 for(int ijet = 0 ; ijet < jets_.nref; ++ijet){
990 // poor man's matching, someone fix please
991 if(fabs(genjet.pt()-jets_.refpt[ijet])<0.00001 &&
992 fabs(genjet.eta()-jets_.refeta[ijet])<0.00001){
993
994 jets_.genmatchindex[jets_.ngen] = (int)ijet;
995 jets_.gendphijt[jets_.ngen] = reco::deltaPhi(jets_.refphi[ijet],genjet.phi());
996 jets_.gendrjt[jets_.ngen] = sqrt(pow(jets_.gendphijt[jets_.ngen],2)+pow(fabs(genjet.eta()-jets_.refeta[ijet]),2));
997
998 break;
999 }
1000 }
1001 }
1002
1003 jets_.ngen++;
1004 }
1005
1006 }
1007
1008
1009
1010
1011
1012 t->Fill();
1013 memset(&jets_,0,sizeof jets_);
1014
1015 }
1016
1017
1018
1019
1020 //--------------------------------------------------------------------------------------------------
1021 void HiInclusiveJetAnalyzer::fillL1Bits(const edm::Event &iEvent)
1022 {
1023 edm::Handle< L1GlobalTriggerReadoutRecord > L1GlobalTrigger;
1024
1025 iEvent.getByLabel(L1gtReadout_, L1GlobalTrigger);
1026 const TechnicalTriggerWord& technicalTriggerWordBeforeMask = L1GlobalTrigger->technicalTriggerWord();
1027
1028 for (int i=0; i<64;i++)
1029 {
1030 jets_.l1TBit[i] = technicalTriggerWordBeforeMask.at(i);
1031 }
1032 jets_.nL1TBit = 64;
1033
1034 int ntrigs = L1GlobalTrigger->decisionWord().size();
1035 jets_.nL1ABit = ntrigs;
1036
1037 for (int i=0; i != ntrigs; i++) {
1038 bool accept = L1GlobalTrigger->decisionWord()[i];
1039 //jets_.l1ABit[i] = (accept == true)? 1:0;
1040 if(accept== true){
1041 jets_.l1ABit[i] = 1;
1042 }
1043 else{
1044 jets_.l1ABit[i] = 0;
1045 }
1046
1047 }
1048 }
1049
1050 //--------------------------------------------------------------------------------------------------
1051 void HiInclusiveJetAnalyzer::fillHLTBits(const edm::Event &iEvent)
1052 {
1053 // Fill HLT trigger bits.
1054 Handle<TriggerResults> triggerResultsHLT;
1055 getProduct(hltResName_, triggerResultsHLT, iEvent);
1056
1057 const TriggerResults *hltResults = triggerResultsHLT.product();
1058 const TriggerNames & triggerNames = iEvent.triggerNames(*hltResults);
1059
1060 jets_.nHLTBit = hltTrgNames_.size();
1061
1062 for(size_t i=0;i<hltTrgNames_.size();i++){
1063
1064 for(size_t j=0;j<triggerNames.size();++j) {
1065
1066 if(triggerNames.triggerName(j) == hltTrgNames_[i]){
1067
1068 //cout <<"hltTrgNames_(i) "<<hltTrgNames_[i]<<endl;
1069 //cout <<"triggerName(j) "<<triggerNames.triggerName(j)<<endl;
1070 //cout<<" result "<<triggerResultsHLT->accept(j)<<endl;
1071 jets_.hltBit[i] = triggerResultsHLT->accept(j);
1072 }
1073
1074 }
1075 }
1076 }
1077
1078 //--------------------------------------------------------------------------------------------------
1079 template <typename TYPE>
1080 inline void HiInclusiveJetAnalyzer::getProduct(const std::string name, edm::Handle<TYPE> &prod,
1081 const edm::Event &event) const
1082 {
1083 // Try to access data collection from EDM file. We check if we really get just one
1084 // product with the given name. If not we throw an exception.
1085
1086 event.getByLabel(edm::InputTag(name),prod);
1087 if (!prod.isValid())
1088 throw edm::Exception(edm::errors::Configuration, "HiInclusiveJetAnalyzer::GetProduct()\n")
1089 << "Collection with label '" << name << "' is not valid" << std::endl;
1090 }
1091
1092 //--------------------------------------------------------------------------------------------------
1093 template <typename TYPE>
1094 inline bool HiInclusiveJetAnalyzer::getProductSafe(const std::string name, edm::Handle<TYPE> &prod,
1095 const edm::Event &event) const
1096 {
1097 // Try to safely access data collection from EDM file. We check if we really get just one
1098 // product with the given name. If not, we return false.
1099
1100 if (name.size()==0)
1101 return false;
1102
1103 try {
1104 event.getByLabel(edm::InputTag(name),prod);
1105 if (!prod.isValid())
1106 return false;
1107 } catch (...) {
1108 return false;
1109 }
1110 return true;
1111 }
1112
1113
1114 int
1115 HiInclusiveJetAnalyzer::getPFJetMuon(const pat::Jet& pfJet, const reco::PFCandidateCollection *pfCandidateColl)
1116 {
1117
1118 int pfMuonIndex = -1;
1119 float ptMax = 0.;
1120
1121
1122 for(unsigned icand=0;icand<pfCandidateColl->size(); icand++) {
1123 const reco::PFCandidate pfCandidate = pfCandidateColl->at(icand);
1124
1125 int id = pfCandidate.particleId();
1126 if(abs(id) != 3) continue;
1127
1128 if(reco::deltaR(pfJet,pfCandidate)>0.5) continue;
1129
1130 double pt = pfCandidate.pt();
1131 if(pt>ptMax){
1132 ptMax = pt;
1133 pfMuonIndex = (int) icand;
1134 }
1135 }
1136
1137 return pfMuonIndex;
1138
1139 }
1140
1141
1142 double
1143 HiInclusiveJetAnalyzer::getPtRel(const reco::PFCandidate lep, const pat::Jet& jet )
1144 {
1145
1146 float lj_x = jet.p4().px();
1147 float lj_y = jet.p4().py();
1148 float lj_z = jet.p4().pz();
1149
1150 // absolute values squared
1151 float lj2 = lj_x*lj_x+lj_y*lj_y+lj_z*lj_z;
1152 float lep2 = lep.px()*lep.px()+lep.py()*lep.py()+lep.pz()*lep.pz();
1153
1154 // projection vec(mu) to lepjet axis
1155 float lepXlj = lep.px()*lj_x+lep.py()*lj_y+lep.pz()*lj_z;
1156
1157 // absolute value squared and normalized
1158 float pLrel2 = lepXlj*lepXlj/lj2;
1159
1160 // lep2 = pTrel2 + pLrel2
1161 float pTrel2 = lep2-pLrel2;
1162
1163 return (pTrel2 > 0) ? std::sqrt(pTrel2) : 0.0;
1164 }
1165
1166 // Recursive function, but this version gets called only the first time
1167 void
1168 HiInclusiveJetAnalyzer::saveDaughters(const reco::GenParticle &gen){
1169
1170 for(unsigned i=0;i<gen.numberOfDaughters();i++){
1171 const reco::Candidate & daughter = *gen.daughter(i);
1172 double daughterPt = daughter.pt();
1173 if(daughterPt<1.) continue;
1174 double daughterEta = daughter.eta();
1175 if(fabs(daughterEta)>3.) continue;
1176 int daughterPdgId = daughter.pdgId();
1177 int daughterStatus = daughter.status();
1178 // Special case when b->b+string, both b and string contain all daughters, so only take the string
1179 if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
1180
1181 // cheesy way of finding strings which were already used
1182 if(daughter.pdgId()==92){
1183 for(unsigned ist=0;ist<usedStringPts.size();ist++){
1184 if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
1185 }
1186 usedStringPts.push_back(daughter.pt());
1187 }
1188 jets_.bJetIndex[jets_.bMult] = jets_.nref;
1189 jets_.bStatus[jets_.bMult] = daughterStatus;
1190 jets_.bVx[jets_.bMult] = daughter.vx();
1191 jets_.bVy[jets_.bMult] = daughter.vy();
1192 jets_.bVz[jets_.bMult] = daughter.vz();
1193 jets_.bPt[jets_.bMult] = daughterPt;
1194 jets_.bEta[jets_.bMult] = daughterEta;
1195 jets_.bPhi[jets_.bMult] = daughter.phi();
1196 jets_.bPdg[jets_.bMult] = daughterPdgId;
1197 jets_.bChg[jets_.bMult] = daughter.charge();
1198 jets_.bMult++;
1199 saveDaughters(daughter);
1200 }
1201 }
1202
1203 // This version called for all subsequent calls
1204 void
1205 HiInclusiveJetAnalyzer::saveDaughters(const reco::Candidate &gen){
1206
1207 for(unsigned i=0;i<gen.numberOfDaughters();i++){
1208 const reco::Candidate & daughter = *gen.daughter(i);
1209 double daughterPt = daughter.pt();
1210 if(daughterPt<1.) continue;
1211 double daughterEta = daughter.eta();
1212 if(fabs(daughterEta)>3.) continue;
1213 int daughterPdgId = daughter.pdgId();
1214 int daughterStatus = daughter.status();
1215 // Special case when b->b+string, both b and string contain all daughters, so only take the string
1216 if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
1217
1218 // cheesy way of finding strings which were already used
1219 if(daughter.pdgId()==92){
1220 for(unsigned ist=0;ist<usedStringPts.size();ist++){
1221 if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
1222 }
1223 usedStringPts.push_back(daughter.pt());
1224 }
1225
1226 jets_.bJetIndex[jets_.bMult] = jets_.nref;
1227 jets_.bStatus[jets_.bMult] = daughterStatus;
1228 jets_.bVx[jets_.bMult] = daughter.vx();
1229 jets_.bVy[jets_.bMult] = daughter.vy();
1230 jets_.bVz[jets_.bMult] = daughter.vz();
1231 jets_.bPt[jets_.bMult] = daughterPt;
1232 jets_.bEta[jets_.bMult] = daughterEta;
1233 jets_.bPhi[jets_.bMult] = daughter.phi();
1234 jets_.bPdg[jets_.bMult] = daughterPdgId;
1235 jets_.bChg[jets_.bMult] = daughter.charge();
1236 jets_.bMult++;
1237 saveDaughters(daughter);
1238 }
1239 }
1240
1241 double HiInclusiveJetAnalyzer::getEt(math::XYZPoint pos, double energy){
1242 double et = energy*sin(pos.theta());
1243 return et;
1244 }
1245
1246 math::XYZPoint HiInclusiveJetAnalyzer::getPosition(const DetId &id, reco::Vertex::Point vtx){
1247 const GlobalPoint& pos=geo->getPosition(id);
1248 math::XYZPoint posV(pos.x() - vtx.x(),pos.y() - vtx.y(),pos.z() - vtx.z());
1249 return posV;
1250 }
1251
1252
1253
1254 DEFINE_FWK_MODULE(HiInclusiveJetAnalyzer);