ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/JetAnalysis/src/HiInclusiveJetAnalyzer.cc
Revision: 1.26
Committed: Mon Jul 9 17:28:40 2012 UTC (12 years, 9 months ago) by yilmaz
Content type: text/plain
Branch: MAIN
CVS Tags: HiForest_V02_33, HiForest_V02_32, HiForest_V02_31, HiForest_V02_30, HiForest_V02_27, HiForest_V02_26, QM_2012, HiForest_V02_25, HiForest_V02_24
Branch point for: branch_44x
Changes since 1.25: +22 -1 lines
Log Message:
genparticle variables

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