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.9 by yilmaz, Sun Apr 22 19:12:44 2012 UTC vs.
Revision 1.21 by yilmaz, Wed May 16 09:08:37 2012 UTC

# Line 24 | Line 24
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 42 | Line 43 | using namespace edm;
43   using namespace reco;
44  
45   HiInclusiveJetAnalyzer::HiInclusiveJetAnalyzer(const edm::ParameterSet& iConfig) {
45  
46  
47    jetTag_ = iConfig.getParameter<InputTag>("jetTag");
48 +  matchTag_ = iConfig.getUntrackedParameter<InputTag>("matchTag",jetTag_);
49 +
50    vtxTag_ = iConfig.getUntrackedParameter<edm::InputTag>("vtxTag",edm::InputTag("hiSelectedVertex"));  
51 +  trackTag_ = iConfig.getParameter<InputTag>("trackTag");
52 +  useQuality_ = iConfig.getUntrackedParameter<bool>("useQuality",0);
53 +  string trackQuality_ = iConfig.getUntrackedParameter<string>("trackQuality","highPurity");
54  
55    isMC_ = iConfig.getUntrackedParameter<bool>("isMC",false);
56 <  
56 >  fillGenJets_ = iConfig.getUntrackedParameter<bool>("fillGenJets",false);
57 >
58 >  doTrigger_ = iConfig.getUntrackedParameter<bool>("doTrigger",false);
59 >
60 >  rParam = iConfig.getParameter<double>("rParam");
61 >  hardPtMin_ = iConfig.getUntrackedParameter<double>("hardPtMin",4);  
62 >
63    if(isMC_){
64      genjetTag_ = iConfig.getParameter<InputTag>("genjetTag");
65      eventInfoTag_ = iConfig.getParameter<InputTag>("eventInfoTag");
# Line 61 | Line 72 | HiInclusiveJetAnalyzer::HiInclusiveJetAn
72    usePat_ = iConfig.getUntrackedParameter<bool>("usePAT",true);
73  
74    doLifeTimeTagging_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTagging",false);
75 +  doLifeTimeTaggingExtras_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTaggingExtras",true);
76 +  saveBfragments_  = iConfig.getUntrackedParameter<bool>("saveBfragments",false);
77 +
78    pfCandidateLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("pfCandidateLabel",edm::InputTag("particleFlowTmp"));
79  
80 <  if(!isMC_){
80 >  if(doTrigger_){
81      L1gtReadout_ = iConfig.getParameter<edm::InputTag>("L1gtReadout");
82      hltResName_ = iConfig.getUntrackedParameter<string>("hltTrgResults","TriggerResults::HLT");
83      
# Line 80 | Line 94 | HiInclusiveJetAnalyzer::HiInclusiveJetAn
94    }
95  
96    cout<<" jet collection : "<<jetTag_<<endl;
97 +  doSubEvent_ = 0;
98 +
99    if(isMC_){
100       cout<<" genjet collection : "<<genjetTag_<<endl;
101       genPtMin_ = iConfig.getUntrackedParameter<double>("genPtMin",0);
102 +     doSubEvent_ = iConfig.getUntrackedParameter<bool>("doSubEvent",1);
103    }
104  
105    
# Line 130 | Line 147 | HiInclusiveJetAnalyzer::beginJob() {
147    t->Branch("jtphi",jets_.jtphi,"jtphi[nref]/F");
148    t->Branch("jtpu",jets_.jtpu,"jtpu[nref]/F");
149  
150 +  // jet ID information, jet composition
151 +  t->Branch("discr_fr01", jets_.discr_fr01,"discr_fr01[nref]/F");
152 +
153 +  t->Branch("trackMax", jets_.trackMax,"trackMax[nref]/F");
154 +  t->Branch("trackSum", jets_.trackSum,"trackSum[nref]/F");
155 +  t->Branch("trackN", jets_.trackN,"trackN[nref]/I");
156 +  t->Branch("trackHardSum", jets_.trackHardSum,"trackHardSum[nref]/F");
157 +  t->Branch("trackHardN", jets_.trackHardN,"trackHardN[nref]/I");
158 +
159 +  t->Branch("chargedMax", jets_.chargedMax,"chargedMax[nref]/F");
160 +  t->Branch("chargedSum", jets_.chargedSum,"chargedSum[nref]/F");
161 +  t->Branch("chargedN", jets_.chargedN,"chargedN[nref]/I");
162 +  t->Branch("chargedHardSum", jets_.chargedHardSum,"chargedHardSum[nref]/F");
163 +  t->Branch("chargedHardN", jets_.chargedHardN,"chargedHardN[nref]/I");
164 +
165 +  t->Branch("photonMax", jets_.photonMax,"photonMax[nref]/F");
166 +  t->Branch("photonSum", jets_.photonSum,"photonSum[nref]/F");
167 +  t->Branch("photonN", jets_.photonN,"photonN[nref]/I");
168 +  t->Branch("photonHardSum", jets_.photonHardSum,"photonHardSum[nref]/F");
169 +  t->Branch("photonHardN", jets_.photonHardN,"photonHardN[nref]/I");
170 +
171 +  t->Branch("neutralMax", jets_.neutralMax,"neutralMax[nref]/F");
172 +  t->Branch("neutralSum", jets_.neutralSum,"neutralSum[nref]/F");
173 +  t->Branch("neutralN", jets_.neutralN,"neutralN[nref]/I");
174 +
175 +  t->Branch("eMax", jets_.eMax,"eMax[nref]/F");
176 +  t->Branch("eSum", jets_.eSum,"eSum[nref]/F");
177 +  t->Branch("eN", jets_.eN,"eN[nref]/I");
178 +
179 +  t->Branch("muMax", jets_.muMax,"muMax[nref]/F");
180 +  t->Branch("muSum", jets_.muSum,"muSum[nref]/F");
181 +  t->Branch("muN", jets_.muN,"muN[nref]/I");
182 +
183 +  t->Branch("matchedPt", jets_.matchedPt,"matchedPt[nref]/F");
184 +  t->Branch("matchedR", jets_.matchedR,"matchedR[nref]/F");
185 +
186    // b-jet discriminators
187    if (doLifeTimeTagging_) {
188  
# Line 142 | Line 195 | HiInclusiveJetAnalyzer::beginJob() {
195      t->Branch("discr_tcHighEff",jets_.discr_tcHighEff,"discr_tcHighEff[nref]/F");
196      t->Branch("discr_tcHighPur",jets_.discr_tcHighPur,"discr_tcHighPur[nref]/F");
197      
198 <    t->Branch("nsvtx",    jets_.nsvtx,    "nsvtx[nref]/b");
199 <    t->Branch("svtxntrk", jets_.svtxntrk, "svtxntrk[nref]/b");
198 >    t->Branch("nsvtx",    jets_.nsvtx,    "nsvtx[nref]/I");
199 >    t->Branch("svtxntrk", jets_.svtxntrk, "svtxntrk[nref]/I");
200      t->Branch("svtxdl",   jets_.svtxdl,   "svtxdl[nref]/F");
201      t->Branch("svtxdls",  jets_.svtxdls,  "svtxdls[nref]/F");
202      t->Branch("svtxm",    jets_.svtxm,    "svtxm[nref]/F");
203      t->Branch("svtxpt",   jets_.svtxpt,   "svtxpt[nref]/F");
204      
205 <    t->Branch("nIPtracks",jets_.nIPtracks,"nIPTracks[nref]/b");
206 <    t->Branch("nselIPtracks",jets_.nselIPtracks,"nselIPTracks[nref]/b");
205 >    t->Branch("nIPtrk",jets_.nIPtrk,"nIPtrk[nref]/I");
206 >    t->Branch("nselIPtrk",jets_.nselIPtrk,"nselIPtrk[nref]/I");
207 >
208 >    if (doLifeTimeTaggingExtras_) {
209 >      t->Branch("nIP",&jets_.nIP,"nIP/I");
210 >      t->Branch("ipJetIndex",jets_.ipJetIndex,"ipJetIndex[nIP]/I");
211 >      t->Branch("ipPt",jets_.ipPt,"ipPt[nIP]/F");
212 >      t->Branch("ipProb0",jets_.ipProb0,"ipProb0[nIP]/F");
213 >      t->Branch("ipProb1",jets_.ipProb1,"ipProb1[nIP]/F");
214 >      t->Branch("ip2d",jets_.ip2d,"ip2d[nIP]/F");
215 >      t->Branch("ip2dSig",jets_.ip2dSig,"ip2dSig[nIP]/F");
216 >      t->Branch("ip3d",jets_.ip3d,"ip3d[nIP]/F");
217 >      t->Branch("ip3dSig",jets_.ip3dSig,"ip3dSig[nIP]/F");
218 >      t->Branch("ipDist2Jet",jets_.ipDist2Jet,"ipDist2Jet[nIP]/F");
219 >      t->Branch("ipDist2JetSig",jets_.ipDist2JetSig,"ipDist2JetSig[nIP]/F");
220 >      t->Branch("ipClosest2Jet",jets_.ipClosest2Jet,"ipClosest2Jet[nIP]/F");
221 >
222 >    }      
223  
224      t->Branch("mue",     jets_.mue,     "mue[nref]/F");
225      t->Branch("mupt",    jets_.mupt,    "mupt[nref]/F");
# Line 160 | Line 229 | HiInclusiveJetAnalyzer::beginJob() {
229      t->Branch("muptrel", jets_.muptrel, "muptrel[nref]/F");
230      t->Branch("muchg",   jets_.muchg,   "muchg[nref]/I");
231    }
232 +
233    
234    if(isMC_){
235 +    t->Branch("beamId1",&jets_.beamId1,"beamId1/I");    
236 +    t->Branch("beamId2",&jets_.beamId2,"beamId2/I");    
237 +
238      t->Branch("pthat",&jets_.pthat,"pthat/F");    
239  
240      // Only matched gen jets
# Line 176 | Line 249 | HiInclusiveJetAnalyzer::beginJob() {
249      t->Branch("refparton_flavor",jets_.refparton_flavor,"refparton_flavor[nref]/I");
250      t->Branch("refparton_flavorForB",jets_.refparton_flavorForB,"refparton_flavorForB[nref]/I");
251  
252 <    // For all gen jets, matched or unmatched
253 <    t->Branch("ngen",&jets_.ngen,"ngen/I");
254 <    t->Branch("genmatchindex",jets_.genmatchindex,"genmatchindex[ngen]/I");
255 <    t->Branch("genpt",jets_.genpt,"genpt[ngen]/F");
256 <    t->Branch("geneta",jets_.geneta,"geneta[ngen]/F");
257 <    t->Branch("geny",jets_.geny,"geny[ngen]/F");
258 <    t->Branch("genphi",jets_.genphi,"genphi[ngen]/F");
259 <    t->Branch("gendphijt",jets_.gendphijt,"gendphijt[ngen]/F");
260 <    t->Branch("gendrjt",jets_.gendrjt,"gendrjt[ngen]/F");
252 >    if(fillGenJets_){
253 >       // For all gen jets, matched or unmatched
254 >       t->Branch("ngen",&jets_.ngen,"ngen/I");
255 >       t->Branch("genmatchindex",jets_.genmatchindex,"genmatchindex[ngen]/I");
256 >       t->Branch("genpt",jets_.genpt,"genpt[ngen]/F");
257 >       t->Branch("geneta",jets_.geneta,"geneta[ngen]/F");
258 >       t->Branch("geny",jets_.geny,"geny[ngen]/F");
259 >       t->Branch("genphi",jets_.genphi,"genphi[ngen]/F");
260 >       t->Branch("gendphijt",jets_.gendphijt,"gendphijt[ngen]/F");
261 >       t->Branch("gendrjt",jets_.gendrjt,"gendrjt[ngen]/F");
262 >      
263 >       if(doSubEvent_){
264 >          t->Branch("gensubid",jets_.gensubid,"gensubid[ngen]/I");
265 >       }
266 >    }
267 >    
268 >    if(saveBfragments_  ) {
269 >      t->Branch("bMult",&jets_.bMult,"bMult/I");
270 >      t->Branch("bJetIndex",jets_.bJetIndex,"bJetIndex[bMult]/I");
271 >      t->Branch("bStatus",jets_.bStatus,"bStatus[bMult]/I");
272 >      t->Branch("bVx",jets_.bVx,"bVx[bMult]/F");
273 >      t->Branch("bVy",jets_.bVy,"bVy[bMult]/F");
274 >      t->Branch("bVz",jets_.bVz,"bVz[bMult]/F");
275 >      t->Branch("bPt",jets_.bPt,"bPt[bMult]/F");
276 >      t->Branch("bEta",jets_.bEta,"bEta[bMult]/F");
277 >      t->Branch("bPhi",jets_.bPhi,"bPhi[bMult]/F");
278 >      t->Branch("bPdg",jets_.bPdg,"bPdg[bMult]/I");
279 >      t->Branch("bChg",jets_.bChg,"bChg[bMult]/I");
280 >    }
281 >
282    }
283    /*
284    if(!isMC_){
# Line 238 | Line 332 | HiInclusiveJetAnalyzer::analyze(const Ev
332  
333  
334  
241  //double jetPtMin = 35.;
242
335  
336     // loop the events
337    
# Line 260 | Line 352 | HiInclusiveJetAnalyzer::analyze(const Ev
352    
353     edm::Handle<pat::JetCollection> patjets;
354     if(usePat_)iEvent.getByLabel(jetTag_, patjets);
355 +
356 +   edm::Handle<pat::JetCollection> matchedjets;
357 +   iEvent.getByLabel(matchTag_, matchedjets);
358    
359     edm::Handle<reco::JetView> jets;
360     iEvent.getByLabel(jetTag_, jets);
361  
362     edm::Handle<reco::PFCandidateCollection> pfCandidates;
363 <   if(doLifeTimeTagging_){
364 <     iEvent.getByLabel(pfCandidateLabel_,pfCandidates);  
365 <   }
363 >   iEvent.getByLabel(pfCandidateLabel_,pfCandidates);  
364 >
365 >   edm::Handle<reco::TrackCollection> tracks;
366 >   iEvent.getByLabel(trackTag_,tracks);
367 >
368     // FILL JRA TREE
369  
370     jets_.b = b;
371     jets_.nref = 0;
372    
373 <   if(!isMC_){
373 >   if(doTrigger_){
374       fillL1Bits(iEvent);
375       fillHLTBits(iEvent);
376     }
# Line 281 | Line 378 | HiInclusiveJetAnalyzer::analyze(const Ev
378     for(unsigned int j = 0 ; j < jets->size(); ++j){
379       const reco::Jet& jet = (*jets)[j];
380      
381 <     //cout<<" jet pt "<<jet.pt()<<endl;
285 <     //if(jet.pt() < jetPtMin) continue;
381 >
382       if (useJEC_ && usePat_){
383         jets_.rawpt[jets_.nref]=(*patjets)[j].correctedJet("Uncorrected").pt();
384       }
# Line 310 | Line 406 | HiInclusiveJetAnalyzer::analyze(const Ev
406           jets_.discr_tcHighPur[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFTrackCountingHighPurBJetTags");
407         }
408         else{
409 <         cout<<" you fail at btagging "<<endl;
409 >         cout<<" b-tagging variables not filled for this collection, turn of doLifeTimeTagging "<<endl;
410         }
411 <      
411 >
412         const reco::SecondaryVertexTagInfo& tagInfoSV=*(*patjets)[j].tagInfoSecondaryVertex();
413 +      
414 +       jets_.nsvtx[jets_.nref]     = tagInfoSV.nVertices();      
415 +      
416         if (tagInfoSV.nVertices()>0) {
318         Measurement1D m1D = tagInfoSV.flightDistance(0);
319         jets_.nsvtx[jets_.nref]     = tagInfoSV.nVertices();    
417           jets_.svtxntrk[jets_.nref]  = tagInfoSV.nVertexTracks(0);
418 +         // this is the 3d flight distance, for 2-D use (0,true)
419 +         Measurement1D m1D = tagInfoSV.flightDistance(0);        
420           jets_.svtxdl[jets_.nref]    = m1D.value();
421           jets_.svtxdls[jets_.nref]   = m1D.significance();
422          
423 <         const reco::Vertex& svtx = tagInfoSV.secondaryVertex(0);
424 <        
423 >         const reco::Vertex& svtx = tagInfoSV.secondaryVertex(0);        
424 >         //cout<<" SV:  vx: "<<svtx.x()<<" vy "<<svtx.y()<<" vz "<<svtx.z()<<endl;
425 >         //cout<<" PV:  vx: "<<jet.vx()<<" vy "<<jet.vy()<<" vz "<<jet.vz()<<endl;      
426           jets_.svtxm[jets_.nref]    = svtx.p4().mass();
427 <         jets_.svtxpt[jets_.nref]   = svtx.p4().pt();
428 <
329 <       }
330 <       else {    
331 <         jets_.nsvtx[jets_.nref]    =   0;
332 <         jets_.svtxntrk[jets_.nref] =   0;
333 <         jets_.svtxdl[jets_.nref]   = 0.0;
334 <         jets_.svtxdls[jets_.nref]  = 0.0;
335 <         jets_.svtxm[jets_.nref]    = 0.0;
336 <         jets_.svtxpt[jets_.nref]   = 0.0;
427 >         jets_.svtxpt[jets_.nref]   = svtx.p4().pt();    
428 >         //cout<<" chi2 "<<svtx.chi2()<<" ndof "<<svtx.ndof()<<endl;
429         }
430 +      
431         const reco::TrackIPTagInfo& tagInfoIP=*(*patjets)[j].tagInfoTrackIP();
432 +      
433 +       jets_.nIPtrk[jets_.nref] = tagInfoIP.tracks().size();
434 +       jets_.nselIPtrk[jets_.nref] = tagInfoIP.selectedTracks().size();
435  
436 <       jets_.nIPtracks[jets_.nref] = tagInfoIP.tracks().size();
341 <       jets_.nselIPtracks[jets_.nref] = tagInfoIP.selectedTracks().size();
436 >       if (doLifeTimeTaggingExtras_) {
437  
438 <       // would be nice to save the info for the tracks, but requires a more sophisticated tree
439 <       /*
440 <       //cout << "Jet pt: " << tagInfoIP.jet()->pt() << endl;
441 <       cout << "Tot tracks: " << tagInfoIP.tracks().size() << endl;    
442 <       TrackRefVector selTracks=tagInfoIP.selectedTracks();
443 <       int n=selTracks.size();
444 <       cout << "Sel tracks: " << n << endl;
445 <       // false      cout << " Pt  \t d len \t jet dist \t p3d \t p2d\t ip3d \t ip2d " << endl;
446 <       GlobalPoint pv(tagInfoIP.primaryVertex()->position().x(),tagInfoIP.primaryVertex()->position().y(),tagInfoIP.primaryVertex()->position().z());
447 <       cout << pv << " vs " << tagInfoIP.primaryVertex()->position()   << endl;
448 <       for(int j=0;j< n;j++)
449 <         {
450 <           TrackIPTagInfo::TrackIPData data = tagInfoIP.impactParameterData()[j];  
451 <           cout << selTracks[j]->pt() << "\t";
452 <           cout << tagInfoIP.probabilities(0)[j] << "\t";
453 <           cout << tagInfoIP.probabilities(1)[j] << "\t";
454 <           cout << data.ip3d.value() << "\t";
455 <           cout << data.ip3d.significance() << "\t";
456 <           cout << data.distanceToJetAxis.value() << "\t";
457 <           cout << data.distanceToJetAxis.significance() << "\t";
458 <           cout << data.distanceToGhostTrack.value() << "\t";
364 <           cout << data.distanceToGhostTrack.significance() << "\t";
365 <           cout << data.closestToJetAxis << "\t";
366 <           cout << (data.closestToJetAxis - pv).mag() << "\t";
367 <           cout << data.closestToGhostTrack << "\t";
368 <           cout << (data.closestToGhostTrack - pv).mag() << "\t";
369 <           cout << data.ip2d.value() << "\t";
370 <           cout << data.ip2d.significance() <<  endl;    
371 <         }
372 <       */
438 >         TrackRefVector selTracks=tagInfoIP.selectedTracks();
439 >        
440 >         GlobalPoint pv(tagInfoIP.primaryVertex()->position().x(),tagInfoIP.primaryVertex()->position().y(),tagInfoIP.primaryVertex()->position().z());
441 >        
442 >         for(int it=0;it<jets_.nselIPtrk[jets_.nref] ;it++)
443 >           {
444 >             jets_.ipJetIndex[jets_.nIP + it]= jets_.nref;
445 >             TrackIPTagInfo::TrackIPData data = tagInfoIP.impactParameterData()[it];  
446 >             jets_.ipPt[jets_.nIP + it] = selTracks[it]->pt();
447 >             jets_.ipProb0[jets_.nIP + it] = tagInfoIP.probabilities(0)[it];
448 >             jets_.ipProb1[jets_.nIP + it] = tagInfoIP.probabilities(1)[it];
449 >             jets_.ip2d[jets_.nIP + it] = data.ip2d.value();
450 >             jets_.ip2dSig[jets_.nIP + it] = data.ip2d.significance();
451 >             jets_.ip3d[jets_.nIP + it] = data.ip3d.value();
452 >             jets_.ip3dSig[jets_.nIP + it] = data.ip3d.significance();
453 >             jets_.ipDist2Jet[jets_.nIP + it] = data.distanceToJetAxis.value();
454 >             jets_.ipDist2JetSig[jets_.nIP + it] = data.distanceToJetAxis.significance();
455 >             jets_.ipClosest2Jet[jets_.nIP + it] = (data.closestToJetAxis - pv).mag();  //decay length  
456 >           }
457 >
458 >         jets_.nIP += jets_.nselIPtrk[jets_.nref];
459  
460 +       }
461 +      
462         const reco::PFCandidateCollection *pfCandidateColl = &(*pfCandidates);
463         int pfMuonIndex = getPFJetMuon(jet, pfCandidateColl);
464         if(pfMuonIndex >=0){
# Line 382 | Line 470 | HiInclusiveJetAnalyzer::analyze(const Ev
470           jets_.mudr[jets_.nref]    =  reco::deltaR(jet,muon);
471           jets_.muptrel[jets_.nref] =  getPtRel(muon, jet);
472           jets_.muchg[jets_.nref]   =  muon.charge();
473 <       }
386 <       else{
473 >       }else{
474           jets_.mupt[jets_.nref]    =  0.0;
475           jets_.mueta[jets_.nref]   =  0.0;
476           jets_.muphi[jets_.nref]   =  0.0;
# Line 392 | Line 479 | HiInclusiveJetAnalyzer::analyze(const Ev
479           jets_.muptrel[jets_.nref] =  0.0;
480           jets_.muchg[jets_.nref]   = 0;
481         }
482 +
483       }
484  
485 +
486 +
487 +     // Jet ID variables
488 +
489 +     jets_.muMax[jets_.nref] = 0;
490 +     jets_.muSum[jets_.nref] = 0;
491 +     jets_.muN[jets_.nref] = 0;
492 +
493 +     jets_.eMax[jets_.nref] = 0;
494 +     jets_.eSum[jets_.nref] = 0;
495 +     jets_.eN[jets_.nref] = 0;
496 +
497 +     jets_.neutralMax[jets_.nref] = 0;
498 +     jets_.neutralSum[jets_.nref] = 0;
499 +     jets_.neutralN[jets_.nref] = 0;
500 +
501 +     jets_.photonMax[jets_.nref] = 0;
502 +     jets_.photonSum[jets_.nref] = 0;
503 +     jets_.photonN[jets_.nref] = 0;
504 +     jets_.photonHardSum[jets_.nref] = 0;
505 +     jets_.photonHardN[jets_.nref] = 0;
506 +
507 +     jets_.chargedMax[jets_.nref] = 0;
508 +     jets_.chargedSum[jets_.nref] = 0;
509 +     jets_.chargedN[jets_.nref] = 0;
510 +     jets_.chargedHardSum[jets_.nref] = 0;
511 +     jets_.chargedHardN[jets_.nref] = 0;
512 +
513 +     jets_.trackMax[jets_.nref] = 0;
514 +     jets_.trackSum[jets_.nref] = 0;
515 +     jets_.trackN[jets_.nref] = 0;
516 +     jets_.trackHardSum[jets_.nref] = 0;
517 +     jets_.trackHardN[jets_.nref] = 0;
518 +
519 +
520 +     for(unsigned int icand = 0; icand < tracks->size(); ++icand){
521 +        const reco::Track& track = (*tracks)[icand];
522 +        if(useQuality_ && !(track.quality(reco::TrackBase::qualityByName(trackQuality_)))) continue;
523 +
524 +        double dr = deltaR(jet,track);
525 +        if(dr < rParam){
526 +           double ptcand = track.pt();
527 +           jets_.trackSum[jets_.nref] += ptcand;
528 +           jets_.trackN[jets_.nref] += 1;
529 +
530 +           if(ptcand > hardPtMin_){
531 +              jets_.trackHardSum[jets_.nref] += ptcand;
532 +              jets_.trackHardN[jets_.nref] += 1;
533 +
534 +           }
535 +           if(ptcand > jets_.trackMax[jets_.nref]) jets_.trackMax[jets_.nref] = ptcand;
536 +
537 +        }
538 +     }
539 +
540 +     for(unsigned int icand = 0; icand < pfCandidates->size(); ++icand){
541 +        const reco::PFCandidate& track = (*pfCandidates)[icand];
542 +        double dr = deltaR(jet,track);
543 +        if(dr < rParam){
544 +           double ptcand = track.pt();
545 +           int pfid = track.particleId();
546 +
547 +           switch(pfid){
548 +
549 +           case 1:
550 +              jets_.chargedSum[jets_.nref] += ptcand;
551 +              jets_.chargedN[jets_.nref] += 1;
552 +              if(ptcand > hardPtMin_){
553 +                 jets_.chargedHardSum[jets_.nref] += ptcand;
554 +                 jets_.chargedHardN[jets_.nref] += 1;
555 +              }
556 +              if(ptcand > jets_.chargedMax[jets_.nref]) jets_.chargedMax[jets_.nref] = ptcand;
557 +              break;
558 +
559 +           case 2:
560 +              jets_.eSum[jets_.nref] += ptcand;
561 +              jets_.eN[jets_.nref] += 1;
562 +              if(ptcand > jets_.eMax[jets_.nref]) jets_.eMax[jets_.nref] = ptcand;
563 +              break;
564 +
565 +           case 3:
566 +              jets_.muSum[jets_.nref] += ptcand;
567 +              jets_.muN[jets_.nref] += 1;
568 +              if(ptcand > jets_.muMax[jets_.nref]) jets_.muMax[jets_.nref] = ptcand;
569 +              break;
570 +
571 +           case 4:
572 +              jets_.photonSum[jets_.nref] += ptcand;
573 +              jets_.photonN[jets_.nref] += 1;
574 +              if(ptcand > hardPtMin_){
575 +                 jets_.photonHardSum[jets_.nref] += ptcand;
576 +                 jets_.photonHardN[jets_.nref] += 1;
577 +              }
578 +              if(ptcand > jets_.photonMax[jets_.nref]) jets_.photonMax[jets_.nref] = ptcand;
579 +              break;
580 +
581 +           case 5:
582 +              jets_.neutralSum[jets_.nref] += ptcand;
583 +              jets_.neutralN[jets_.nref] += 1;
584 +              if(ptcand > jets_.neutralMax[jets_.nref]) jets_.neutralMax[jets_.nref] = ptcand;
585 +              break;
586 +
587 +           default:
588 +             break;
589 +
590 +           }
591 +        }
592 +     }
593 +
594 +     double drMin = 100;
595 +     for(unsigned int imatch = 0 ; imatch < matchedjets->size(); ++imatch){
596 +        const reco::Jet& mjet = (*matchedjets)[imatch];
597 +
598 +        double dr = deltaR(jet,mjet);
599 +        if(dr < drMin){
600 +           jets_.matchedPt[jets_.nref] = mjet.pt();
601 +           jets_.matchedR[jets_.nref] = dr;
602 +
603 +        }
604 +     }
605 +  
606 +
607 +
608 +
609 +     //     if(etrk.quality(reco::TrackBase::qualityByName(qualityString_))) pev_.trkQual[pev_.nTrk]=1;
610 +
611 +        /////////////////////////////////////////////////////////////////
612 +        // Jet core pt^2 discriminant for fake jets
613 +        // Edited by Yue Shi Lai <ylai@mit.edu>
614 +
615 +        // Initial value is 0
616 +        jets_.discr_fr01[jets_.nref] = 0;
617 +        // Start with no directional adaption, i.e. the fake rejection
618 +        // axis is the jet axis
619 +        float pseudorapidity_adapt = jets_.jteta[jets_.nref];
620 +        float azimuth_adapt = jets_.jtphi[jets_.nref];
621 +
622 +        // Unadapted discriminant with adaption search
623 +        for (size_t iteration = 0; iteration < 2; iteration++) {
624 +                float pseudorapidity_adapt_new = pseudorapidity_adapt;
625 +                float azimuth_adapt_new = azimuth_adapt;
626 +                float max_weighted_perp = 0;
627 +                float perp_square_sum = 0;
628 +
629 +                for (size_t index_pf_candidate = 0;
630 +                         index_pf_candidate < pfCandidates->size();
631 +                         index_pf_candidate++) {
632 +                        const reco::PFCandidate &p =
633 +                                (*pfCandidates)[index_pf_candidate];
634 +
635 +                        switch (p.particleId()) {
636 +                          //case 1:     // Charged hadron
637 +                          //case 3:     // Muon
638 +                        case 4: // Photon
639 +                                {
640 +                                        const float dpseudorapidity =
641 +                                                p.eta() - pseudorapidity_adapt;
642 +                                        const float dazimuth =
643 +                                                reco::deltaPhi(p.phi(), azimuth_adapt);
644 +                                        // The Gaussian scale factor is 0.5 / (0.1 * 0.1)
645 +                                        // = 50
646 +                                        const float angular_weight =
647 +                                                exp(-50.0F * (dpseudorapidity * dpseudorapidity +
648 +                                                                          dazimuth * dazimuth));
649 +                                        const float weighted_perp =
650 +                                                angular_weight * p.pt() * p.pt();
651 +                                        const float weighted_perp_square =
652 +                                                weighted_perp * p.pt();
653 +
654 +                                        perp_square_sum += weighted_perp_square;
655 +                                        if (weighted_perp >= max_weighted_perp) {
656 +                                                pseudorapidity_adapt_new = p.eta();
657 +                                                azimuth_adapt_new = p.phi();
658 +                                                max_weighted_perp = weighted_perp;
659 +                                        }
660 +                                }
661 +                        default:                                                  
662 +                          break;
663 +                        }
664 +                }
665 +                // Update the fake rejection value
666 +                jets_.discr_fr01[jets_.nref] = std::max(
667 +                        jets_.discr_fr01[jets_.nref], perp_square_sum);
668 +                // Update the directional adaption
669 +                pseudorapidity_adapt = pseudorapidity_adapt_new;
670 +                azimuth_adapt = azimuth_adapt_new;
671 +        }
672 +
673 +
674       jets_.jtpt[jets_.nref] = jet.pt();                            
675       jets_.jteta[jets_.nref] = jet.eta();
676       jets_.jtphi[jets_.nref] = jet.phi();
# Line 401 | Line 678 | HiInclusiveJetAnalyzer::analyze(const Ev
678       jets_.jtpu[jets_.nref] = jet.pileup();
679          
680       if(isMC_ && usePat_){
681 <       jets_.refparton_flavorForB[jets_.nref] = (*patjets)[j].partonFlavour();
682 <       const reco::GenJet* genjet = (*patjets)[j].genJet();
681 >
682 >       const reco::GenJet * genjet = (*patjets)[j].genJet();
683          
684         if(genjet){
685           jets_.refpt[jets_.nref] = genjet->pt();        
# Line 420 | Line 697 | HiInclusiveJetAnalyzer::analyze(const Ev
697           jets_.refdrjt[jets_.nref] = -999.;
698         }
699  
700 <   // matched partons
701 <       const reco::GenParticle * parton = (*patjets)[j].genParton();
702 <       if(parton){
703 <         jets_.refparton_pt[jets_.nref] = parton->pt();
704 <         jets_.refparton_flavor[jets_.nref] = parton->pdgId();
700 >       jets_.refparton_flavorForB[jets_.nref] = (*patjets)[j].partonFlavour();
701 >      
702 >       // matched partons
703 >       const reco::GenParticle & parton = *(*patjets)[j].genParton();
704 >
705 >       if((*patjets)[j].genParton()){
706 >         jets_.refparton_pt[jets_.nref] = parton.pt();
707 >         jets_.refparton_flavor[jets_.nref] = parton.pdgId();
708 >        
709 >         if(saveBfragments_ && abs(jets_.refparton_flavorForB[jets_.nref])==5){
710 >
711 >           usedStringPts.clear();
712 >          
713 >           // uncomment this if you want to know the ugly truth about parton matching -matt
714 >           //if(jet.pt() > 50 &&abs(parton.pdgId())!=5 && parton.pdgId()!=21)
715 >           // cout<<" Identified as a b, but doesn't match b or gluon, id = "<<parton.pdgId()<<endl;
716 >          
717 >           jets_.bJetIndex[jets_.bMult] = jets_.nref;
718 >           jets_.bStatus[jets_.bMult] = parton.status();
719 >           jets_.bVx[jets_.bMult] = parton.vx();
720 >           jets_.bVy[jets_.bMult] = parton.vy();
721 >           jets_.bVz[jets_.bMult] = parton.vz();
722 >           jets_.bPt[jets_.bMult] = parton.pt();
723 >           jets_.bEta[jets_.bMult] = parton.eta();
724 >           jets_.bPhi[jets_.bMult] = parton.phi();
725 >           jets_.bPdg[jets_.bMult] = parton.pdgId();
726 >           jets_.bChg[jets_.bMult] = parton.charge();
727 >           jets_.bMult++;
728 >           saveDaughters(parton);
729 >         }
730 >
731 >
732         } else {
733 <       jets_.refparton_pt[jets_.nref] = -999;
734 <       jets_.refparton_flavor[jets_.nref] = -999;
733 >         jets_.refparton_pt[jets_.nref] = -999;
734 >         jets_.refparton_flavor[jets_.nref] = -999;
735         }
736 +      
737 +
738       }
739  
740       jets_.nref++;
# Line 439 | Line 745 | HiInclusiveJetAnalyzer::analyze(const Ev
745  
746     if(isMC_){
747  
748 +     edm::Handle<HepMCProduct> hepMCProduct;
749 +     iEvent.getByLabel(eventInfoTag_,hepMCProduct);
750 +     const HepMC::GenEvent* MCEvt = hepMCProduct->GetEvent();
751 +     std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beamParticles = MCEvt->beam_particles();
752 +     jets_.beamId1 = beamParticles.first->pdg_id();
753 +     jets_.beamId2 = beamParticles.second->pdg_id();
754 +
755       edm::Handle<GenEventInfoProduct> hEventInfo;
756       iEvent.getByLabel(eventInfoTag_,hEventInfo);
757       //jets_.pthat = hEventInfo->binningValues()[0];
# Line 463 | Line 776 | HiInclusiveJetAnalyzer::analyze(const Ev
776           jets_.genphi[jets_.ngen] = genjet.phi();
777           jets_.geny[jets_.ngen] = genjet.eta();
778          
779 +         if(doSubEvent_){
780 +            const GenParticle* gencon = genjet.getGenConstituent(0);
781 +            jets_.gensubid[jets_.ngen] = gencon->collisionId();
782 +         }
783          
784           // find matching patJet if there is one
785          
# Line 493 | Line 810 | HiInclusiveJetAnalyzer::analyze(const Ev
810      
811     }
812     t->Fill();
813 +   memset(&jets_,0,sizeof jets_);
814   }
815  
816  
# Line 643 | Line 961 | HiInclusiveJetAnalyzer::getPtRel(const r
961    
962    return (pTrel2 > 0) ? std::sqrt(pTrel2) : 0.0;
963   }
964 +
965 + // Recursive function, but this version gets called only the first time
966 + void
967 + HiInclusiveJetAnalyzer::saveDaughters(const reco::GenParticle &gen){
968 +  
969 +  for(unsigned i=0;i<gen.numberOfDaughters();i++){
970 +    const reco::Candidate & daughter = *gen.daughter(i);
971 +    double daughterPt = daughter.pt();
972 +    if(daughterPt<1.) continue;
973 +    double daughterEta = daughter.eta();
974 +    if(fabs(daughterEta)>3.) continue;
975 +    int daughterPdgId = daughter.pdgId();
976 +    int daughterStatus = daughter.status();
977 +    // Special case when b->b+string, both b and string contain all daughters, so only take the string
978 +    if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
979 +
980 +    // cheesy way of finding strings which were already used
981 +    if(daughter.pdgId()==92){
982 +      for(unsigned ist=0;ist<usedStringPts.size();ist++){
983 +        if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
984 +      }
985 +      usedStringPts.push_back(daughter.pt());
986 +    }
987 +    jets_.bJetIndex[jets_.bMult] = jets_.nref;
988 +    jets_.bStatus[jets_.bMult] = daughterStatus;
989 +    jets_.bVx[jets_.bMult] = daughter.vx();
990 +    jets_.bVy[jets_.bMult] = daughter.vy();
991 +    jets_.bVz[jets_.bMult] = daughter.vz();
992 +    jets_.bPt[jets_.bMult] = daughterPt;
993 +    jets_.bEta[jets_.bMult] = daughterEta;
994 +    jets_.bPhi[jets_.bMult] = daughter.phi();
995 +    jets_.bPdg[jets_.bMult] = daughterPdgId;
996 +    jets_.bChg[jets_.bMult] = daughter.charge();
997 +    jets_.bMult++;
998 +    saveDaughters(daughter);
999 +  }
1000 + }
1001 +
1002 + // This version called for all subsequent calls
1003 + void
1004 + HiInclusiveJetAnalyzer::saveDaughters(const reco::Candidate &gen){
1005 +
1006 +  for(unsigned i=0;i<gen.numberOfDaughters();i++){
1007 +    const reco::Candidate & daughter = *gen.daughter(i);
1008 +    double daughterPt = daughter.pt();
1009 +    if(daughterPt<1.) continue;
1010 +    double daughterEta = daughter.eta();
1011 +    if(fabs(daughterEta)>3.) continue;
1012 +    int daughterPdgId = daughter.pdgId();
1013 +    int daughterStatus = daughter.status();
1014 +    // Special case when b->b+string, both b and string contain all daughters, so only take the string
1015 +    if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
1016 +
1017 +    // cheesy way of finding strings which were already used
1018 +    if(daughter.pdgId()==92){
1019 +      for(unsigned ist=0;ist<usedStringPts.size();ist++){
1020 +        if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
1021 +      }
1022 +      usedStringPts.push_back(daughter.pt());
1023 +    }
1024 +
1025 +    jets_.bJetIndex[jets_.bMult] = jets_.nref;
1026 +    jets_.bStatus[jets_.bMult] = daughterStatus;
1027 +    jets_.bVx[jets_.bMult] = daughter.vx();
1028 +    jets_.bVy[jets_.bMult] = daughter.vy();
1029 +    jets_.bVz[jets_.bMult] = daughter.vz();
1030 +    jets_.bPt[jets_.bMult] = daughterPt;
1031 +    jets_.bEta[jets_.bMult] = daughterEta;
1032 +    jets_.bPhi[jets_.bMult] = daughter.phi();
1033 +    jets_.bPdg[jets_.bMult] = daughterPdgId;
1034 +    jets_.bChg[jets_.bMult] = daughter.charge();
1035 +    jets_.bMult++;
1036 +    saveDaughters(daughter);
1037 +  }
1038 + }
1039                                                                          
1040   DEFINE_FWK_MODULE(HiInclusiveJetAnalyzer);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines