ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/CmsHi/JetAnalysis/src/HiInclusiveJetAnalyzer.cc
(Generate patch)

Comparing UserCode/CmsHi/JetAnalysis/src/HiInclusiveJetAnalyzer.cc (file contents):
Revision 1.1 by yilmaz, Tue Sep 20 19:45:06 2011 UTC vs.
Revision 1.14 by yilmaz, Thu May 10 16:08:29 2012 UTC

# Line 21 | Line 21
21   #include "DataFormats/HeavyIonEvent/interface/Centrality.h"
22  
23   #include "DataFormats/CaloTowers/interface/CaloTowerCollection.h"
24 #include "DataFormats/PatCandidates/interface/Jet.h"
24   #include "DataFormats/JetReco/interface/CaloJetCollection.h"
25   #include "SimDataFormats/HiGenData/interface/GenHIEvent.h"
26   #include "SimDataFormats/GeneratorProducts/interface/GenEventInfoProduct.h"
27 + #include "SimDataFormats/GeneratorProducts/interface/HepMCProduct.h"
28   #include "DataFormats/JetReco/interface/GenJetCollection.h"
29   #include "DataFormats/VertexReco/interface/Vertex.h"
30   #include "DataFormats/Math/interface/deltaPhi.h"
# Line 46 | Line 46 | HiInclusiveJetAnalyzer::HiInclusiveJetAn
46    
47  
48    jetTag_ = iConfig.getParameter<InputTag>("jetTag");
49 <        vtxTag_ = iConfig.getUntrackedParameter<edm::InputTag>("vtxTag",edm::InputTag("hiSelectedVertex"));
49 >  vtxTag_ = iConfig.getUntrackedParameter<edm::InputTag>("vtxTag",edm::InputTag("hiSelectedVertex"));  
50  
51    isMC_ = iConfig.getUntrackedParameter<bool>("isMC",false);
52 <
52 >  doTrigger_ = iConfig.getUntrackedParameter<bool>("doTrigger",false);
53 >  
54    if(isMC_){
55      genjetTag_ = iConfig.getParameter<InputTag>("genjetTag");
56      eventInfoTag_ = iConfig.getParameter<InputTag>("eventInfoTag");
# Line 57 | Line 58 | HiInclusiveJetAnalyzer::HiInclusiveJetAn
58    verbose_ = iConfig.getUntrackedParameter<bool>("verbose",false);
59  
60    useCentrality_ = iConfig.getUntrackedParameter<bool>("useCentrality",false);
61 <  useVtx_ = iConfig.getUntrackedParameter<bool>("useVtx",true);
61 >  useVtx_ = iConfig.getUntrackedParameter<bool>("useVtx",false);
62    useJEC_ = iConfig.getUntrackedParameter<bool>("useJEC",true);
63 +  usePat_ = iConfig.getUntrackedParameter<bool>("usePAT",true);
64  
65 <  if(!isMC_){
65 >  doLifeTimeTagging_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTagging",false);
66 >  doLifeTimeTaggingExtras_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTaggingExtras",true);
67 >  saveBfragments_  = iConfig.getUntrackedParameter<bool>("saveBfragments",false);
68 >
69 >  pfCandidateLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("pfCandidateLabel",edm::InputTag("particleFlowTmp"));
70 >
71 >  if(doTrigger_){
72      L1gtReadout_ = iConfig.getParameter<edm::InputTag>("L1gtReadout");
73      hltResName_ = iConfig.getUntrackedParameter<string>("hltTrgResults","TriggerResults::HLT");
74      
# Line 77 | Line 85 | HiInclusiveJetAnalyzer::HiInclusiveJetAn
85    }
86  
87    cout<<" jet collection : "<<jetTag_<<endl;
88 <  if(isMC_)cout<<" genjet collection : "<<genjetTag_<<endl;
88 >  doSubEvent_ = 0;
89  
90 +  if(isMC_){
91 +     cout<<" genjet collection : "<<genjetTag_<<endl;
92 +     genPtMin_ = iConfig.getUntrackedParameter<double>("genPtMin",0);
93 +     doSubEvent_ = iConfig.getUntrackedParameter<bool>("doSubEvent",1);
94 +  }
95  
96    
97   }
# Line 102 | Line 115 | HiInclusiveJetAnalyzer::beginJob() {
115    string jetTagTitle = jetTag_.label()+" Jet Analysis Tree";
116    t = fs1->make<TTree>("t",jetTagTitle.c_str());
117  
105
118    //  TTree* t= new TTree("t","Jet Response Analyzer");
119 <  t->Branch("run",&jets_.run,"run/I");
119 >  //t->Branch("run",&jets_.run,"run/I");
120    t->Branch("evt",&jets_.evt,"evt/I");
121 <  t->Branch("lumi",&jets_.lumi,"lumi/I");
121 >  //t->Branch("lumi",&jets_.lumi,"lumi/I");
122    t->Branch("b",&jets_.b,"b/F");
123 <  t->Branch("vx",&jets_.vx,"vx/F");
124 <  t->Branch("vy",&jets_.vy,"vy/F");
125 <  t->Branch("vz",&jets_.vz,"vz/F");
126 <  t->Branch("hf",&jets_.hf,"hf/F");
123 >  if (useVtx_) {
124 >     t->Branch("vx",&jets_.vx,"vx/F");
125 >     t->Branch("vy",&jets_.vy,"vy/F");
126 >     t->Branch("vz",&jets_.vz,"vz/F");
127 >  }
128 >  if (useCentrality_) {
129 >     t->Branch("hf",&jets_.hf,"hf/F");
130 >     t->Branch("bin",&jets_.bin,"bin/I");
131 >  }
132 >
133    t->Branch("nref",&jets_.nref,"nref/I");
116  t->Branch("bin",&jets_.bin,"bin/I");
134    t->Branch("rawpt",jets_.rawpt,"rawpt[nref]/F");
135    t->Branch("jtpt",jets_.jtpt,"jtpt[nref]/F");
136    t->Branch("jteta",jets_.jteta,"jteta[nref]/F");
137    t->Branch("jty",jets_.jty,"jty[nref]/F");
138    t->Branch("jtphi",jets_.jtphi,"jtphi[nref]/F");
139 +  t->Branch("jtpu",jets_.jtpu,"jtpu[nref]/F");
140 +
141 +  // b-jet discriminators
142 +  if (doLifeTimeTagging_) {
143 +
144 +    t->Branch("discr_csvMva",jets_.discr_csvMva,"discr_csvMva[nref]/F");
145 +    t->Branch("discr_csvSimple",jets_.discr_csvSimple,"discr_csvSimple[nref]/F");
146 +    t->Branch("discr_muByIp3",jets_.discr_muByIp3,"discr_muByIp3[nref]/F");
147 +    t->Branch("discr_muByPt",jets_.discr_muByPt,"discr_muByPt[nref]/F");
148 +    t->Branch("discr_prob",jets_.discr_prob,"discr_prob[nref]/F");
149 +    t->Branch("discr_probb",jets_.discr_probb,"discr_probb[nref]/F");
150 +    t->Branch("discr_tcHighEff",jets_.discr_tcHighEff,"discr_tcHighEff[nref]/F");
151 +    t->Branch("discr_tcHighPur",jets_.discr_tcHighPur,"discr_tcHighPur[nref]/F");
152 +    
153 +    t->Branch("nsvtx",    jets_.nsvtx,    "nsvtx[nref]/I");
154 +    t->Branch("svtxntrk", jets_.svtxntrk, "svtxntrk[nref]/I");
155 +    t->Branch("svtxdl",   jets_.svtxdl,   "svtxdl[nref]/F");
156 +    t->Branch("svtxdls",  jets_.svtxdls,  "svtxdls[nref]/F");
157 +    t->Branch("svtxm",    jets_.svtxm,    "svtxm[nref]/F");
158 +    t->Branch("svtxpt",   jets_.svtxpt,   "svtxpt[nref]/F");
159 +    
160 +    t->Branch("nIPtrk",jets_.nIPtrk,"nIPtrk[nref]/I");
161 +    t->Branch("nselIPtrk",jets_.nselIPtrk,"nselIPtrk[nref]/I");
162  
163 +    if (doLifeTimeTaggingExtras_) {
164 +      t->Branch("nIP",&jets_.nIP,"nIP/I");
165 +      t->Branch("ipJetIndex",jets_.ipJetIndex,"ipJetIndex[nIP]/I");
166 +      t->Branch("ipPt",jets_.ipPt,"ipPt[nIP]/F");
167 +      t->Branch("ipProb0",jets_.ipProb0,"ipProb0[nIP]/F");
168 +      t->Branch("ipProb1",jets_.ipProb1,"ipProb1[nIP]/F");
169 +      t->Branch("ip2d",jets_.ip2d,"ip2d[nIP]/F");
170 +      t->Branch("ip2dSig",jets_.ip2dSig,"ip2dSig[nIP]/F");
171 +      t->Branch("ip3d",jets_.ip3d,"ip3d[nIP]/F");
172 +      t->Branch("ip3dSig",jets_.ip3dSig,"ip3dSig[nIP]/F");
173 +      t->Branch("ipDist2Jet",jets_.ipDist2Jet,"ipDist2Jet[nIP]/F");
174 +      t->Branch("ipDist2JetSig",jets_.ipDist2JetSig,"ipDist2JetSig[nIP]/F");
175 +      t->Branch("ipClosest2Jet",jets_.ipClosest2Jet,"ipClosest2Jet[nIP]/F");
176 +
177 +    }      
178 +
179 +    t->Branch("mue",     jets_.mue,     "mue[nref]/F");
180 +    t->Branch("mupt",    jets_.mupt,    "mupt[nref]/F");
181 +    t->Branch("mueta",   jets_.mueta,   "mueta[nref]/F");
182 +    t->Branch("muphi",   jets_.muphi,   "muphi[nref]/F");
183 +    t->Branch("mudr",    jets_.mudr,    "mudr[nref]/F");
184 +    t->Branch("muptrel", jets_.muptrel, "muptrel[nref]/F");
185 +    t->Branch("muchg",   jets_.muchg,   "muchg[nref]/I");
186 +  }
187 +  
188    if(isMC_){
189 +    t->Branch("beamId1",&jets_.beamId1,"beamId1/I");    
190 +    t->Branch("beamId2",&jets_.beamId2,"beamId2/I");    
191 +
192      t->Branch("pthat",&jets_.pthat,"pthat/F");    
193  
194      // Only matched gen jets
# Line 132 | Line 200 | HiInclusiveJetAnalyzer::beginJob() {
200      t->Branch("refdrjt",jets_.refdrjt,"refdrjt[nref]/F");
201      // matched parton
202      t->Branch("refparton_pt",jets_.refparton_pt,"refparton_pt[nref]/F");
203 <    t->Branch("refparton_flavor",jets_.refparton_flavor,"refparton_flavor[nref]/F");
203 >    t->Branch("refparton_flavor",jets_.refparton_flavor,"refparton_flavor[nref]/I");
204 >    t->Branch("refparton_flavorForB",jets_.refparton_flavorForB,"refparton_flavorForB[nref]/I");
205  
206      // For all gen jets, matched or unmatched
207      t->Branch("ngen",&jets_.ngen,"ngen/I");
# Line 143 | Line 212 | HiInclusiveJetAnalyzer::beginJob() {
212      t->Branch("genphi",jets_.genphi,"genphi[ngen]/F");
213      t->Branch("gendphijt",jets_.gendphijt,"gendphijt[ngen]/F");
214      t->Branch("gendrjt",jets_.gendrjt,"gendrjt[ngen]/F");
215 +
216 +    if(doSubEvent_){
217 +       t->Branch("gensubid",jets_.gensubid,"gensubid[ngen]/I");
218 +    }
219 +
220 +    if(saveBfragments_  ) {
221 +      t->Branch("bMult",&jets_.bMult,"bMult/I");
222 +      t->Branch("bJetIndex",jets_.bJetIndex,"bJetIndex[bMult]/I");
223 +      t->Branch("bStatus",jets_.bStatus,"bStatus[bMult]/I");
224 +      t->Branch("bVx",jets_.bVx,"bVx[bMult]/F");
225 +      t->Branch("bVy",jets_.bVy,"bVy[bMult]/F");
226 +      t->Branch("bVz",jets_.bVz,"bVz[bMult]/F");
227 +      t->Branch("bPt",jets_.bPt,"bPt[bMult]/F");
228 +      t->Branch("bEta",jets_.bEta,"bEta[bMult]/F");
229 +      t->Branch("bPhi",jets_.bPhi,"bPhi[bMult]/F");
230 +      t->Branch("bPdg",jets_.bPdg,"bPdg[bMult]/I");
231 +      t->Branch("bChg",jets_.bChg,"bChg[bMult]/I");
232 +    }
233 +
234    }
235 <  
235 >  /*
236    if(!isMC_){
237      t->Branch("nL1TBit",&jets_.nL1TBit,"nL1TBit/I");
238      t->Branch("l1TBit",jets_.l1TBit,"l1TBit[nL1TBit]/O");
# Line 156 | Line 244 | HiInclusiveJetAnalyzer::beginJob() {
244      t->Branch("hltBit",jets_.hltBit,"hltBit[nHLTBit]/O");
245  
246    }
247 <
247 >  */
248    TH1D::SetDefaultSumw2();
249    
250    
# Line 177 | Line 265 | HiInclusiveJetAnalyzer::analyze(const Ev
265  
266    LogDebug("HiInclusiveJetAnalyzer")<<"START event: "<<event<<" in run "<<run<<endl;
267  
180
268   int bin = -1;
269    double hf = 0.;
270    double b = 999.;
271  
272    if(useCentrality_){
186    //if(!isMC_){
273        if(!centrality_) centrality_ = new CentralityProvider(iSetup);      
274        centrality_->newEvent(iEvent,iSetup); // make sure you do this first in every event
275        //double c = centrality_->centralityValue();
# Line 193 | Line 279 | HiInclusiveJetAnalyzer::analyze(const Ev
279  
280        bin = centrality_->getBin();
281        b = centrality_->bMean();
196      //}
197      /*
198    else{
199
200      TFile * centFile = new TFile("/net/hidsk0001/d00/scratch/mnguyen/CMSSW_3_9_1_patch1/src/macros/Hydjet_CentTable.root");
201
202      edm::Handle<reco::Centrality> cent;
203      iEvent.getByLabel(edm::InputTag("hiCentrality"),cent);
204      //cout<<" grabbed centrality "<<endl;
205      CentralityBins::RunMap cmap = getCentralityFromFile(centFile, "makeCentralityTableTFile", "HFhitsHydjet_2760GeV", 1, 1);
206
207      // Still getting cent from hits.  When tower tables become available, we need to switch
208      hf = cent->EtHFhitSum();
209      //cout<<" hf "<<hf<<endl;
210      bin = cmap[run]->getBin(hf);
211      b = cmap[run]->bMeanOfBin(bin);
212    }
213      */
282    }
283    
284  
285  
286  
219  //double jetPtMin = 35.;
220
287  
288     // loop the events
289    
# Line 236 | Line 302 | HiInclusiveJetAnalyzer::analyze(const Ev
302        }
303           }
304    
305 <
306 <
307 <   edm::Handle<pat::JetCollection> jets;
305 >   edm::Handle<pat::JetCollection> patjets;
306 >   if(usePat_)iEvent.getByLabel(jetTag_, patjets);
307 >  
308 >   edm::Handle<reco::JetView> jets;
309     iEvent.getByLabel(jetTag_, jets);
310  
311 <  
311 >   edm::Handle<reco::PFCandidateCollection> pfCandidates;
312 >   if(doLifeTimeTagging_){
313 >     iEvent.getByLabel(pfCandidateLabel_,pfCandidates);  
314 >   }
315     // FILL JRA TREE
316  
317     jets_.b = b;
# Line 253 | Line 323 | HiInclusiveJetAnalyzer::analyze(const Ev
323     }
324  
325     for(unsigned int j = 0 ; j < jets->size(); ++j){
326 <     const pat::Jet& jet = (*jets)[j];
326 >     const reco::Jet& jet = (*jets)[j];
327      
328 <     //cout<<" jet pt "<<jet.pt()<<endl;
329 <     //if(jet.pt() < jetPtMin) continue;
330 <     if (useJEC_) jets_.rawpt[jets_.nref]=jet.correctedJet("Uncorrected").pt();
328 >
329 >     if (useJEC_ && usePat_){
330 >       jets_.rawpt[jets_.nref]=(*patjets)[j].correctedJet("Uncorrected").pt();
331 >     }
332 >    
333 >     if(doLifeTimeTagging_){
334 >      
335 >       if(jetTag_.label()=="icPu5patJets"){
336 >         jets_.discr_csvMva[jets_.nref]    = (*patjets)[j].bDiscriminator("icPu5CombinedSecondaryVertexMVABJetTags");
337 >         jets_.discr_csvSimple[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5CombinedSecondaryVertexBJetTags");
338 >         jets_.discr_muByIp3[jets_.nref]   = (*patjets)[j].bDiscriminator("icPu5SoftMuonByIP3dBJetTags");
339 >         jets_.discr_muByPt[jets_.nref]    = (*patjets)[j].bDiscriminator("icPu5SoftMuonByPtBJetTags");
340 >         jets_.discr_prob[jets_.nref]      = (*patjets)[j].bDiscriminator("icPu5JetBProbabilityBJetTags");
341 >         jets_.discr_probb[jets_.nref]     = (*patjets)[j].bDiscriminator("icPu5JetProbabilityBJetTags");
342 >         jets_.discr_tcHighEff[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5TrackCountingHighEffBJetTags");
343 >         jets_.discr_tcHighPur[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5TrackCountingHighPurBJetTags");
344 >       }
345 >       else if(jetTag_.label()=="akPu3PFpatJets"){
346 >         jets_.discr_csvMva[jets_.nref]    = (*patjets)[j].bDiscriminator("akPu3PFCombinedSecondaryVertexMVABJetTags");
347 >         jets_.discr_csvSimple[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFCombinedSecondaryVertexBJetTags");
348 >         jets_.discr_muByIp3[jets_.nref]   = (*patjets)[j].bDiscriminator("akPu3PFSoftMuonByIP3dBJetTags");
349 >         jets_.discr_muByPt[jets_.nref]    = (*patjets)[j].bDiscriminator("akPu3PFSoftMuonByPtBJetTags");
350 >         jets_.discr_prob[jets_.nref]      = (*patjets)[j].bDiscriminator("akPu3PFJetBProbabilityBJetTags");
351 >         jets_.discr_probb[jets_.nref]     = (*patjets)[j].bDiscriminator("akPu3PFJetProbabilityBJetTags");
352 >         jets_.discr_tcHighEff[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFTrackCountingHighEffBJetTags");
353 >         jets_.discr_tcHighPur[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFTrackCountingHighPurBJetTags");
354 >       }
355 >       else{
356 >         cout<<" b-tagging variables not filled for this collection, turn of doLifeTimeTagging "<<endl;
357 >       }
358 >
359 >       const reco::SecondaryVertexTagInfo& tagInfoSV=*(*patjets)[j].tagInfoSecondaryVertex();
360 >      
361 >       jets_.nsvtx[jets_.nref]     = tagInfoSV.nVertices();      
362 >      
363 >       if (tagInfoSV.nVertices()>0) {
364 >         jets_.svtxntrk[jets_.nref]  = tagInfoSV.nVertexTracks(0);
365 >         // this is the 3d flight distance, for 2-D use (0,true)
366 >         Measurement1D m1D = tagInfoSV.flightDistance(0);        
367 >         jets_.svtxdl[jets_.nref]    = m1D.value();
368 >         jets_.svtxdls[jets_.nref]   = m1D.significance();
369 >        
370 >         const reco::Vertex& svtx = tagInfoSV.secondaryVertex(0);        
371 >         //cout<<" SV:  vx: "<<svtx.x()<<" vy "<<svtx.y()<<" vz "<<svtx.z()<<endl;
372 >         //cout<<" PV:  vx: "<<jet.vx()<<" vy "<<jet.vy()<<" vz "<<jet.vz()<<endl;      
373 >         jets_.svtxm[jets_.nref]    = svtx.p4().mass();
374 >         jets_.svtxpt[jets_.nref]   = svtx.p4().pt();    
375 >         //cout<<" chi2 "<<svtx.chi2()<<" ndof "<<svtx.ndof()<<endl;
376 >       }
377 >      
378 >       const reco::TrackIPTagInfo& tagInfoIP=*(*patjets)[j].tagInfoTrackIP();
379 >      
380 >       jets_.nIPtrk[jets_.nref] = tagInfoIP.tracks().size();
381 >       jets_.nselIPtrk[jets_.nref] = tagInfoIP.selectedTracks().size();
382 >
383 >       if (doLifeTimeTaggingExtras_) {
384 >
385 >         TrackRefVector selTracks=tagInfoIP.selectedTracks();
386 >        
387 >         GlobalPoint pv(tagInfoIP.primaryVertex()->position().x(),tagInfoIP.primaryVertex()->position().y(),tagInfoIP.primaryVertex()->position().z());
388 >        
389 >         for(int it=0;it<jets_.nselIPtrk[jets_.nref] ;it++)
390 >           {
391 >             jets_.ipJetIndex[jets_.nIP + it]= jets_.nref;
392 >             TrackIPTagInfo::TrackIPData data = tagInfoIP.impactParameterData()[it];  
393 >             jets_.ipPt[jets_.nIP + it] = selTracks[it]->pt();
394 >             jets_.ipProb0[jets_.nIP + it] = tagInfoIP.probabilities(0)[it];
395 >             jets_.ipProb1[jets_.nIP + it] = tagInfoIP.probabilities(1)[it];
396 >             jets_.ip2d[jets_.nIP + it] = data.ip2d.value();
397 >             jets_.ip2dSig[jets_.nIP + it] = data.ip2d.significance();
398 >             jets_.ip3d[jets_.nIP + it] = data.ip3d.value();
399 >             jets_.ip3dSig[jets_.nIP + it] = data.ip3d.significance();
400 >             jets_.ipDist2Jet[jets_.nIP + it] = data.distanceToJetAxis.value();
401 >             jets_.ipDist2JetSig[jets_.nIP + it] = data.distanceToJetAxis.significance();
402 >             jets_.ipClosest2Jet[jets_.nIP + it] = (data.closestToJetAxis - pv).mag();  //decay length  
403 >           }
404 >
405 >         jets_.nIP += jets_.nselIPtrk[jets_.nref];
406 >
407 >       }
408 >      
409 >       const reco::PFCandidateCollection *pfCandidateColl = &(*pfCandidates);
410 >       int pfMuonIndex = getPFJetMuon(jet, pfCandidateColl);
411 >       if(pfMuonIndex >=0){
412 >         const reco::PFCandidate muon = pfCandidateColl->at(pfMuonIndex);
413 >         jets_.mupt[jets_.nref]    =  muon.pt();
414 >         jets_.mueta[jets_.nref]   =  muon.eta();
415 >         jets_.muphi[jets_.nref]   =  muon.phi();  
416 >         jets_.mue[jets_.nref]     =  muon.energy();
417 >         jets_.mudr[jets_.nref]    =  reco::deltaR(jet,muon);
418 >         jets_.muptrel[jets_.nref] =  getPtRel(muon, jet);
419 >         jets_.muchg[jets_.nref]   =  muon.charge();
420 >       }
421 >     }
422 >
423       jets_.jtpt[jets_.nref] = jet.pt();                            
424       jets_.jteta[jets_.nref] = jet.eta();
425       jets_.jtphi[jets_.nref] = jet.phi();
426       jets_.jty[jets_.nref] = jet.eta();
427 <    
427 >     jets_.jtpu[jets_.nref] = jet.pileup();
428          
429 <     if(jet.genJet()){
268 <       jets_.refpt[jets_.nref] = jet.genJet()->pt();                            
269 <       jets_.refeta[jets_.nref] = jet.genJet()->eta();
270 <       jets_.refphi[jets_.nref] = jet.genJet()->phi();
271 <       jets_.refy[jets_.nref] = jet.genJet()->eta();
272 <       jets_.refdphijt[jets_.nref] = reco::deltaPhi(jet.phi(),jet.genJet()->phi());    
273 <       jets_.refdrjt[jets_.nref] = reco::deltaR(jet.eta(),jet.phi(),jet.genJet()->eta(),jet.genJet()->phi());          
274 <     }                  
275 <     else{
276 <       jets_.refpt[jets_.nref] = -999.;
277 <       jets_.refeta[jets_.nref] = -999.;
278 <       jets_.refphi[jets_.nref] = -999.;
279 <       jets_.refy[jets_.nref] = -999.;
280 <       jets_.refdphijt[jets_.nref] = -999.;
281 <       jets_.refdrjt[jets_.nref] = -999.;
282 <     }
429 >     if(isMC_ && usePat_){
430  
431 <     // matched partons
432 <     if (jet.genParton()) {
433 <       jets_.refparton_pt[jets_.nref] = jet.genParton()->pt();
434 <       jets_.refparton_flavor[jets_.nref] = jet.genParton()->pdgId();
435 <     } else {
436 <       jets_.refparton_pt[jets_.nref] = -999;
437 <       jets_.refparton_flavor[jets_.nref] = -999;
438 <     }
431 >       const reco::GenJet * genjet = (*patjets)[j].genJet();
432 >        
433 >       if(genjet){
434 >         jets_.refpt[jets_.nref] = genjet->pt();        
435 >         jets_.refeta[jets_.nref] = genjet->eta();
436 >         jets_.refphi[jets_.nref] = genjet->phi();
437 >         jets_.refy[jets_.nref] = genjet->eta();
438 >         jets_.refdphijt[jets_.nref] = reco::deltaPhi(jet.phi(), genjet->phi());        
439 >         jets_.refdrjt[jets_.nref] = reco::deltaR(jet.eta(),jet.phi(),genjet->eta(),genjet->phi());            
440 >       }else{
441 >         jets_.refpt[jets_.nref] = -999.;
442 >         jets_.refeta[jets_.nref] = -999.;
443 >         jets_.refphi[jets_.nref] = -999.;
444 >         jets_.refy[jets_.nref] = -999.;
445 >         jets_.refdphijt[jets_.nref] = -999.;
446 >         jets_.refdrjt[jets_.nref] = -999.;
447 >       }
448 >
449 >       jets_.refparton_flavorForB[jets_.nref] = (*patjets)[j].partonFlavour();
450 >      
451 >       // matched partons
452 >       const reco::GenParticle & parton = *(*patjets)[j].genParton();
453 >
454 >       if((*patjets)[j].genParton()){
455 >         jets_.refparton_pt[jets_.nref] = parton.pt();
456 >         jets_.refparton_flavor[jets_.nref] = parton.pdgId();
457 >        
458 >         if(saveBfragments_ && abs(jets_.refparton_flavorForB[jets_.nref])==5){
459 >
460 >           usedStringPts.clear();
461 >          
462 >           // uncomment this if you want to know the ugly truth about parton matching -matt
463 >           //if(jet.pt() > 50 &&abs(parton.pdgId())!=5 && parton.pdgId()!=21)
464 >           // cout<<" Identified as a b, but doesn't match b or gluon, id = "<<parton.pdgId()<<endl;
465 >          
466 >           jets_.bJetIndex[jets_.bMult] = jets_.nref;
467 >           jets_.bStatus[jets_.bMult] = parton.status();
468 >           jets_.bVx[jets_.bMult] = parton.vx();
469 >           jets_.bVy[jets_.bMult] = parton.vy();
470 >           jets_.bVz[jets_.bMult] = parton.vz();
471 >           jets_.bPt[jets_.bMult] = parton.pt();
472 >           jets_.bEta[jets_.bMult] = parton.eta();
473 >           jets_.bPhi[jets_.bMult] = parton.phi();
474 >           jets_.bPdg[jets_.bMult] = parton.pdgId();
475 >           jets_.bChg[jets_.bMult] = parton.charge();
476 >           jets_.bMult++;
477 >           saveDaughters(parton);
478 >         }
479 >
480 >
481 >       } else {
482 >         jets_.refparton_pt[jets_.nref] = -999;
483 >         jets_.refparton_flavor[jets_.nref] = -999;
484 >       }
485 >      
486  
487 +     }
488  
489       jets_.nref++;
490        
# Line 299 | Line 494 | HiInclusiveJetAnalyzer::analyze(const Ev
494  
495     if(isMC_){
496  
497 +     edm::Handle<HepMCProduct> hepMCProduct;
498 +     iEvent.getByLabel(eventInfoTag_,hepMCProduct);
499 +     const HepMC::GenEvent* MCEvt = hepMCProduct->GetEvent();
500 +     std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beamParticles = MCEvt->beam_particles();
501 +     jets_.beamId1 = beamParticles.first->pdg_id();
502 +     jets_.beamId2 = beamParticles.second->pdg_id();
503 +
504       edm::Handle<GenEventInfoProduct> hEventInfo;
505       iEvent.getByLabel(eventInfoTag_,hEventInfo);
506       //jets_.pthat = hEventInfo->binningValues()[0];
# Line 316 | Line 518 | HiInclusiveJetAnalyzer::analyze(const Ev
518         float genjet_pt = genjet.pt();
519        
520         // threshold to reduce size of output in minbias PbPb
521 <       if(genjet_pt>20.){
521 >       if(genjet_pt>genPtMin_){
522  
523           jets_.genpt[jets_.ngen] = genjet_pt;                            
524           jets_.geneta[jets_.ngen] = genjet.eta();
525           jets_.genphi[jets_.ngen] = genjet.phi();
526           jets_.geny[jets_.ngen] = genjet.eta();
527          
528 +         if(doSubEvent_){
529 +            const GenParticle* gencon = genjet.getGenConstituent(0);
530 +            jets_.gensubid[jets_.ngen] = gencon->collisionId();
531 +         }
532          
533           // find matching patJet if there is one
534          
535           jets_.gendrjt[jets_.ngen] = -1.0;
536           jets_.genmatchindex[jets_.ngen] = -1;
537          
332        
538           for(unsigned int ijet = 0 ; ijet < jets->size(); ++ijet){
539             const pat::Jet& jet = (*jets)[ijet];
540 <          
541 <           if(jet.genJet()){
542 <             if(fabs(genjet.pt()-jet.genJet()->pt())<0.0001 &&
543 <                fabs(genjet.eta()-jet.genJet()->eta())<0.0001 &&
544 <                (fabs(genjet.phi()-jet.genJet()->phi())<0.0001 || fabs(genjet.phi()-jet.genJet()->phi() - 2.0*TMath::Pi()) < 0.0001 )){
540 >           const reco::GenJet* matchedGenJet = (*patjets)[ijet].genJet();
541 >           if(matchedGenJet){
542 >             // poor man's matching, someone fix please
543 >             if(fabs(genjet.pt()-matchedGenJet->pt())<0.0001 &&
544 >                fabs(genjet.eta()-matchedGenJet->eta())<0.0001 &&
545 >                (fabs(genjet.phi()-matchedGenJet->phi())<0.0001 || fabs(genjet.phi()-matchedGenJet->phi() - 2.0*TMath::Pi()) < 0.0001 )){
546                
547                 jets_.genmatchindex[jets_.ngen] = (int)ijet;
548                 jets_.gendphijt[jets_.ngen] = reco::deltaPhi(jet.phi(),genjet.phi());    
# Line 353 | Line 559 | HiInclusiveJetAnalyzer::analyze(const Ev
559      
560     }
561     t->Fill();
562 +   memset(&jets_,0,sizeof jets_);
563   }
564  
565  
# Line 452 | Line 659 | inline bool HiInclusiveJetAnalyzer::getP
659   }
660  
661  
662 + int
663 + HiInclusiveJetAnalyzer::getPFJetMuon(const pat::Jet& pfJet, const reco::PFCandidateCollection *pfCandidateColl)
664 + {
665 +  
666 +  int pfMuonIndex = -1;
667 +  float ptMax = 0.;
668 +
669  
670 +  for(unsigned icand=0;icand<pfCandidateColl->size(); icand++) {
671 +    const reco::PFCandidate pfCandidate = pfCandidateColl->at(icand);      
672 +    
673 +    int id = pfCandidate.particleId();
674 +    if(abs(id) != 3) continue;
675 +
676 +    if(reco::deltaR(pfJet,pfCandidate)>0.5) continue;      
677 +    
678 +    double pt =  pfCandidate.pt();
679 +    if(pt>ptMax){
680 +      ptMax = pt;
681 +      pfMuonIndex = (int) icand;
682 +    }
683 +  }
684 +
685 +  return pfMuonIndex;  
686 +
687 + }
688 +
689 +
690 + double
691 + HiInclusiveJetAnalyzer::getPtRel(const reco::PFCandidate lep, const pat::Jet& jet )
692 + {
693 +  
694 +  float lj_x = jet.p4().px();
695 +  float lj_y = jet.p4().py();
696 +  float lj_z = jet.p4().pz();
697 +  
698 +  // absolute values squared
699 +  float lj2  = lj_x*lj_x+lj_y*lj_y+lj_z*lj_z;
700 +  float lep2 = lep.px()*lep.px()+lep.py()*lep.py()+lep.pz()*lep.pz();
701 +  
702 +  // projection vec(mu) to lepjet axis
703 +  float lepXlj = lep.px()*lj_x+lep.py()*lj_y+lep.pz()*lj_z;
704 +  
705 +  // absolute value squared and normalized
706 +  float pLrel2 = lepXlj*lepXlj/lj2;
707 +  
708 +  // lep2 = pTrel2 + pLrel2
709 +  float pTrel2 = lep2-pLrel2;
710 +  
711 +  return (pTrel2 > 0) ? std::sqrt(pTrel2) : 0.0;
712 + }
713 +
714 + // Recursive function, but this version gets called only the first time
715 + void
716 + HiInclusiveJetAnalyzer::saveDaughters(const reco::GenParticle &gen){
717 +  
718 +  for(unsigned i=0;i<gen.numberOfDaughters();i++){
719 +    const reco::Candidate & daughter = *gen.daughter(i);
720 +    double daughterPt = daughter.pt();
721 +    if(daughterPt<1.) continue;
722 +    double daughterEta = daughter.eta();
723 +    if(fabs(daughterEta)>3.) continue;
724 +    int daughterPdgId = daughter.pdgId();
725 +    int daughterStatus = daughter.status();
726 +    // Special case when b->b+string, both b and string contain all daughters, so only take the string
727 +    if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
728 +
729 +    // cheesy way of finding strings which were already used
730 +    if(daughter.pdgId()==92){
731 +      for(unsigned ist=0;ist<usedStringPts.size();ist++){
732 +        if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
733 +      }
734 +      usedStringPts.push_back(daughter.pt());
735 +    }
736 +    jets_.bJetIndex[jets_.bMult] = jets_.nref;
737 +    jets_.bStatus[jets_.bMult] = daughterStatus;
738 +    jets_.bVx[jets_.bMult] = daughter.vx();
739 +    jets_.bVy[jets_.bMult] = daughter.vy();
740 +    jets_.bVz[jets_.bMult] = daughter.vz();
741 +    jets_.bPt[jets_.bMult] = daughterPt;
742 +    jets_.bEta[jets_.bMult] = daughterEta;
743 +    jets_.bPhi[jets_.bMult] = daughter.phi();
744 +    jets_.bPdg[jets_.bMult] = daughterPdgId;
745 +    jets_.bChg[jets_.bMult] = daughter.charge();
746 +    jets_.bMult++;
747 +    saveDaughters(daughter);
748 +  }
749 + }
750 +
751 + // This version called for all subsequent calls
752 + void
753 + HiInclusiveJetAnalyzer::saveDaughters(const reco::Candidate &gen){
754 +
755 +  for(unsigned i=0;i<gen.numberOfDaughters();i++){
756 +    const reco::Candidate & daughter = *gen.daughter(i);
757 +    double daughterPt = daughter.pt();
758 +    if(daughterPt<1.) continue;
759 +    double daughterEta = daughter.eta();
760 +    if(fabs(daughterEta)>3.) continue;
761 +    int daughterPdgId = daughter.pdgId();
762 +    int daughterStatus = daughter.status();
763 +    // Special case when b->b+string, both b and string contain all daughters, so only take the string
764 +    if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
765 +
766 +    // cheesy way of finding strings which were already used
767 +    if(daughter.pdgId()==92){
768 +      for(unsigned ist=0;ist<usedStringPts.size();ist++){
769 +        if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
770 +      }
771 +      usedStringPts.push_back(daughter.pt());
772 +    }
773 +
774 +    jets_.bJetIndex[jets_.bMult] = jets_.nref;
775 +    jets_.bStatus[jets_.bMult] = daughterStatus;
776 +    jets_.bVx[jets_.bMult] = daughter.vx();
777 +    jets_.bVy[jets_.bMult] = daughter.vy();
778 +    jets_.bVz[jets_.bMult] = daughter.vz();
779 +    jets_.bPt[jets_.bMult] = daughterPt;
780 +    jets_.bEta[jets_.bMult] = daughterEta;
781 +    jets_.bPhi[jets_.bMult] = daughter.phi();
782 +    jets_.bPdg[jets_.bMult] = daughterPdgId;
783 +    jets_.bChg[jets_.bMult] = daughter.charge();
784 +    jets_.bMult++;
785 +    saveDaughters(daughter);
786 +  }
787 + }
788                                                                          
789   DEFINE_FWK_MODULE(HiInclusiveJetAnalyzer);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines