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.17 by yilmaz, Fri May 11 16:27:35 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 43 | Line 43 | using namespace edm;
43   using namespace reco;
44  
45   HiInclusiveJetAnalyzer::HiInclusiveJetAnalyzer(const edm::ParameterSet& iConfig) {
46  
46  
47    jetTag_ = iConfig.getParameter<InputTag>("jetTag");
48 <        vtxTag_ = iConfig.getUntrackedParameter<edm::InputTag>("vtxTag",edm::InputTag("hiSelectedVertex"));
48 >  vtxTag_ = iConfig.getUntrackedParameter<edm::InputTag>("vtxTag",edm::InputTag("hiSelectedVertex"));  
49 >  trackTag_ = iConfig.getParameter<InputTag>("trackTag");
50 >  useQuality_ = iConfig.getUntrackedParameter<bool>("useQuality",0);
51 >  string trackQuality_ = iConfig.getUntrackedParameter<string>("trackQuality","highPurity");
52  
53    isMC_ = iConfig.getUntrackedParameter<bool>("isMC",false);
54 +  doTrigger_ = iConfig.getUntrackedParameter<bool>("doTrigger",false);
55  
56 +  rParam = iConfig.getParameter<double>("rParam");
57 +  
58    if(isMC_){
59      genjetTag_ = iConfig.getParameter<InputTag>("genjetTag");
60      eventInfoTag_ = iConfig.getParameter<InputTag>("eventInfoTag");
# Line 57 | Line 62 | HiInclusiveJetAnalyzer::HiInclusiveJetAn
62    verbose_ = iConfig.getUntrackedParameter<bool>("verbose",false);
63  
64    useCentrality_ = iConfig.getUntrackedParameter<bool>("useCentrality",false);
65 <  useVtx_ = iConfig.getUntrackedParameter<bool>("useVtx",true);
65 >  useVtx_ = iConfig.getUntrackedParameter<bool>("useVtx",false);
66    useJEC_ = iConfig.getUntrackedParameter<bool>("useJEC",true);
67 +  usePat_ = iConfig.getUntrackedParameter<bool>("usePAT",true);
68  
69 <  if(!isMC_){
69 >  doLifeTimeTagging_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTagging",false);
70 >  doLifeTimeTaggingExtras_ = iConfig.getUntrackedParameter<bool>("doLifeTimeTaggingExtras",true);
71 >  saveBfragments_  = iConfig.getUntrackedParameter<bool>("saveBfragments",false);
72 >
73 >  pfCandidateLabel_ = iConfig.getUntrackedParameter<edm::InputTag>("pfCandidateLabel",edm::InputTag("particleFlowTmp"));
74 >
75 >  if(doTrigger_){
76      L1gtReadout_ = iConfig.getParameter<edm::InputTag>("L1gtReadout");
77      hltResName_ = iConfig.getUntrackedParameter<string>("hltTrgResults","TriggerResults::HLT");
78      
# Line 77 | Line 89 | HiInclusiveJetAnalyzer::HiInclusiveJetAn
89    }
90  
91    cout<<" jet collection : "<<jetTag_<<endl;
92 <  if(isMC_)cout<<" genjet collection : "<<genjetTag_<<endl;
92 >  doSubEvent_ = 0;
93  
94 +  if(isMC_){
95 +     cout<<" genjet collection : "<<genjetTag_<<endl;
96 +     genPtMin_ = iConfig.getUntrackedParameter<double>("genPtMin",0);
97 +     doSubEvent_ = iConfig.getUntrackedParameter<bool>("doSubEvent",1);
98 +  }
99  
100    
101   }
# Line 102 | Line 119 | HiInclusiveJetAnalyzer::beginJob() {
119    string jetTagTitle = jetTag_.label()+" Jet Analysis Tree";
120    t = fs1->make<TTree>("t",jetTagTitle.c_str());
121  
105
122    //  TTree* t= new TTree("t","Jet Response Analyzer");
123 <  t->Branch("run",&jets_.run,"run/I");
123 >  //t->Branch("run",&jets_.run,"run/I");
124    t->Branch("evt",&jets_.evt,"evt/I");
125 <  t->Branch("lumi",&jets_.lumi,"lumi/I");
125 >  //t->Branch("lumi",&jets_.lumi,"lumi/I");
126    t->Branch("b",&jets_.b,"b/F");
127 <  t->Branch("vx",&jets_.vx,"vx/F");
128 <  t->Branch("vy",&jets_.vy,"vy/F");
129 <  t->Branch("vz",&jets_.vz,"vz/F");
130 <  t->Branch("hf",&jets_.hf,"hf/F");
127 >  if (useVtx_) {
128 >     t->Branch("vx",&jets_.vx,"vx/F");
129 >     t->Branch("vy",&jets_.vy,"vy/F");
130 >     t->Branch("vz",&jets_.vz,"vz/F");
131 >  }
132 >  if (useCentrality_) {
133 >     t->Branch("hf",&jets_.hf,"hf/F");
134 >     t->Branch("bin",&jets_.bin,"bin/I");
135 >  }
136 >
137    t->Branch("nref",&jets_.nref,"nref/I");
116  t->Branch("bin",&jets_.bin,"bin/I");
138    t->Branch("rawpt",jets_.rawpt,"rawpt[nref]/F");
139    t->Branch("jtpt",jets_.jtpt,"jtpt[nref]/F");
140    t->Branch("jteta",jets_.jteta,"jteta[nref]/F");
141    t->Branch("jty",jets_.jty,"jty[nref]/F");
142    t->Branch("jtphi",jets_.jtphi,"jtphi[nref]/F");
143 +  t->Branch("jtpu",jets_.jtpu,"jtpu[nref]/F");
144 +
145 +  // jet ID information, jet composition
146 +  t->Branch("discr_fr01", jets_.discr_fr01,"discr_fr01[nref]/F");
147  
148 +  t->Branch("trackMax", jets_.trackMax,"trackMax[nref]/F");
149 +  t->Branch("trackSum", jets_.trackSum,"trackSum[nref]/F");
150 +  t->Branch("trackN", jets_.trackN,"trackN[nref]/I");
151 +
152 +  t->Branch("chargedMax", jets_.chargedMax,"chargedMax[nref]/F");
153 +  t->Branch("chargedSum", jets_.chargedSum,"chargedSum[nref]/F");
154 +  t->Branch("chargedN", jets_.chargedN,"chargedN[nref]/I");
155 +
156 +  t->Branch("photonMax", jets_.photonMax,"photonMax[nref]/F");
157 +  t->Branch("photonSum", jets_.photonSum,"photonSum[nref]/F");
158 +  t->Branch("photonN", jets_.photonN,"photonN[nref]/I");
159 +
160 +  t->Branch("neutralMax", jets_.neutralMax,"neutralMax[nref]/F");
161 +  t->Branch("neutralSum", jets_.neutralSum,"neutralSum[nref]/F");
162 +  t->Branch("neutralN", jets_.neutralN,"neutralN[nref]/I");
163 +
164 +  t->Branch("eMax", jets_.eMax,"eMax[nref]/F");
165 +  t->Branch("eSum", jets_.eSum,"eSum[nref]/F");
166 +  t->Branch("eN", jets_.eN,"eN[nref]/I");
167 +
168 +  t->Branch("muMax", jets_.muMax,"muMax[nref]/F");
169 +  t->Branch("muSum", jets_.muSum,"muSum[nref]/F");
170 +  t->Branch("muN", jets_.muN,"muN[nref]/I");
171 +
172 +
173 +  // b-jet discriminators
174 +  if (doLifeTimeTagging_) {
175 +
176 +    t->Branch("discr_csvMva",jets_.discr_csvMva,"discr_csvMva[nref]/F");
177 +    t->Branch("discr_csvSimple",jets_.discr_csvSimple,"discr_csvSimple[nref]/F");
178 +    t->Branch("discr_muByIp3",jets_.discr_muByIp3,"discr_muByIp3[nref]/F");
179 +    t->Branch("discr_muByPt",jets_.discr_muByPt,"discr_muByPt[nref]/F");
180 +    t->Branch("discr_prob",jets_.discr_prob,"discr_prob[nref]/F");
181 +    t->Branch("discr_probb",jets_.discr_probb,"discr_probb[nref]/F");
182 +    t->Branch("discr_tcHighEff",jets_.discr_tcHighEff,"discr_tcHighEff[nref]/F");
183 +    t->Branch("discr_tcHighPur",jets_.discr_tcHighPur,"discr_tcHighPur[nref]/F");
184 +    
185 +    t->Branch("nsvtx",    jets_.nsvtx,    "nsvtx[nref]/I");
186 +    t->Branch("svtxntrk", jets_.svtxntrk, "svtxntrk[nref]/I");
187 +    t->Branch("svtxdl",   jets_.svtxdl,   "svtxdl[nref]/F");
188 +    t->Branch("svtxdls",  jets_.svtxdls,  "svtxdls[nref]/F");
189 +    t->Branch("svtxm",    jets_.svtxm,    "svtxm[nref]/F");
190 +    t->Branch("svtxpt",   jets_.svtxpt,   "svtxpt[nref]/F");
191 +    
192 +    t->Branch("nIPtrk",jets_.nIPtrk,"nIPtrk[nref]/I");
193 +    t->Branch("nselIPtrk",jets_.nselIPtrk,"nselIPtrk[nref]/I");
194 +
195 +    if (doLifeTimeTaggingExtras_) {
196 +      t->Branch("nIP",&jets_.nIP,"nIP/I");
197 +      t->Branch("ipJetIndex",jets_.ipJetIndex,"ipJetIndex[nIP]/I");
198 +      t->Branch("ipPt",jets_.ipPt,"ipPt[nIP]/F");
199 +      t->Branch("ipProb0",jets_.ipProb0,"ipProb0[nIP]/F");
200 +      t->Branch("ipProb1",jets_.ipProb1,"ipProb1[nIP]/F");
201 +      t->Branch("ip2d",jets_.ip2d,"ip2d[nIP]/F");
202 +      t->Branch("ip2dSig",jets_.ip2dSig,"ip2dSig[nIP]/F");
203 +      t->Branch("ip3d",jets_.ip3d,"ip3d[nIP]/F");
204 +      t->Branch("ip3dSig",jets_.ip3dSig,"ip3dSig[nIP]/F");
205 +      t->Branch("ipDist2Jet",jets_.ipDist2Jet,"ipDist2Jet[nIP]/F");
206 +      t->Branch("ipDist2JetSig",jets_.ipDist2JetSig,"ipDist2JetSig[nIP]/F");
207 +      t->Branch("ipClosest2Jet",jets_.ipClosest2Jet,"ipClosest2Jet[nIP]/F");
208 +
209 +    }      
210 +
211 +    t->Branch("mue",     jets_.mue,     "mue[nref]/F");
212 +    t->Branch("mupt",    jets_.mupt,    "mupt[nref]/F");
213 +    t->Branch("mueta",   jets_.mueta,   "mueta[nref]/F");
214 +    t->Branch("muphi",   jets_.muphi,   "muphi[nref]/F");
215 +    t->Branch("mudr",    jets_.mudr,    "mudr[nref]/F");
216 +    t->Branch("muptrel", jets_.muptrel, "muptrel[nref]/F");
217 +    t->Branch("muchg",   jets_.muchg,   "muchg[nref]/I");
218 +  }
219 +
220 +  
221    if(isMC_){
222 +    t->Branch("beamId1",&jets_.beamId1,"beamId1/I");    
223 +    t->Branch("beamId2",&jets_.beamId2,"beamId2/I");    
224 +
225      t->Branch("pthat",&jets_.pthat,"pthat/F");    
226  
227      // Only matched gen jets
# Line 132 | Line 233 | HiInclusiveJetAnalyzer::beginJob() {
233      t->Branch("refdrjt",jets_.refdrjt,"refdrjt[nref]/F");
234      // matched parton
235      t->Branch("refparton_pt",jets_.refparton_pt,"refparton_pt[nref]/F");
236 <    t->Branch("refparton_flavor",jets_.refparton_flavor,"refparton_flavor[nref]/F");
236 >    t->Branch("refparton_flavor",jets_.refparton_flavor,"refparton_flavor[nref]/I");
237 >    t->Branch("refparton_flavorForB",jets_.refparton_flavorForB,"refparton_flavorForB[nref]/I");
238  
239      // For all gen jets, matched or unmatched
240      t->Branch("ngen",&jets_.ngen,"ngen/I");
# Line 143 | Line 245 | HiInclusiveJetAnalyzer::beginJob() {
245      t->Branch("genphi",jets_.genphi,"genphi[ngen]/F");
246      t->Branch("gendphijt",jets_.gendphijt,"gendphijt[ngen]/F");
247      t->Branch("gendrjt",jets_.gendrjt,"gendrjt[ngen]/F");
248 +
249 +    if(doSubEvent_){
250 +       t->Branch("gensubid",jets_.gensubid,"gensubid[ngen]/I");
251 +    }
252 +
253 +    if(saveBfragments_  ) {
254 +      t->Branch("bMult",&jets_.bMult,"bMult/I");
255 +      t->Branch("bJetIndex",jets_.bJetIndex,"bJetIndex[bMult]/I");
256 +      t->Branch("bStatus",jets_.bStatus,"bStatus[bMult]/I");
257 +      t->Branch("bVx",jets_.bVx,"bVx[bMult]/F");
258 +      t->Branch("bVy",jets_.bVy,"bVy[bMult]/F");
259 +      t->Branch("bVz",jets_.bVz,"bVz[bMult]/F");
260 +      t->Branch("bPt",jets_.bPt,"bPt[bMult]/F");
261 +      t->Branch("bEta",jets_.bEta,"bEta[bMult]/F");
262 +      t->Branch("bPhi",jets_.bPhi,"bPhi[bMult]/F");
263 +      t->Branch("bPdg",jets_.bPdg,"bPdg[bMult]/I");
264 +      t->Branch("bChg",jets_.bChg,"bChg[bMult]/I");
265 +    }
266 +
267    }
268 <  
268 >  /*
269    if(!isMC_){
270      t->Branch("nL1TBit",&jets_.nL1TBit,"nL1TBit/I");
271      t->Branch("l1TBit",jets_.l1TBit,"l1TBit[nL1TBit]/O");
# Line 156 | Line 277 | HiInclusiveJetAnalyzer::beginJob() {
277      t->Branch("hltBit",jets_.hltBit,"hltBit[nHLTBit]/O");
278  
279    }
280 <
280 >  */
281    TH1D::SetDefaultSumw2();
282    
283    
# Line 177 | Line 298 | HiInclusiveJetAnalyzer::analyze(const Ev
298  
299    LogDebug("HiInclusiveJetAnalyzer")<<"START event: "<<event<<" in run "<<run<<endl;
300  
180
301   int bin = -1;
302    double hf = 0.;
303    double b = 999.;
304  
305    if(useCentrality_){
186    //if(!isMC_){
306        if(!centrality_) centrality_ = new CentralityProvider(iSetup);      
307        centrality_->newEvent(iEvent,iSetup); // make sure you do this first in every event
308        //double c = centrality_->centralityValue();
# Line 193 | Line 312 | HiInclusiveJetAnalyzer::analyze(const Ev
312  
313        bin = centrality_->getBin();
314        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      */
315    }
316    
317  
318  
319  
219  //double jetPtMin = 35.;
220
320  
321     // loop the events
322    
# Line 236 | Line 335 | HiInclusiveJetAnalyzer::analyze(const Ev
335        }
336           }
337    
338 <
339 <
340 <   edm::Handle<pat::JetCollection> jets;
338 >   edm::Handle<pat::JetCollection> patjets;
339 >   if(usePat_)iEvent.getByLabel(jetTag_, patjets);
340 >  
341 >   edm::Handle<reco::JetView> jets;
342     iEvent.getByLabel(jetTag_, jets);
343  
344 <  
344 >   edm::Handle<reco::PFCandidateCollection> pfCandidates;
345 >   iEvent.getByLabel(pfCandidateLabel_,pfCandidates);  
346 >
347 >   edm::Handle<reco::TrackCollection> tracks;
348 >   iEvent.getByLabel(trackTag_,tracks);
349 >
350     // FILL JRA TREE
351  
352     jets_.b = b;
353     jets_.nref = 0;
354    
355 <   if(!isMC_){
355 >   if(doTrigger_){
356       fillL1Bits(iEvent);
357       fillHLTBits(iEvent);
358     }
359  
360     for(unsigned int j = 0 ; j < jets->size(); ++j){
361 <     const pat::Jet& jet = (*jets)[j];
361 >     const reco::Jet& jet = (*jets)[j];
362      
363 <     //cout<<" jet pt "<<jet.pt()<<endl;
364 <     //if(jet.pt() < jetPtMin) continue;
365 <     if (useJEC_) jets_.rawpt[jets_.nref]=jet.correctedJet("Uncorrected").pt();
363 >
364 >     if (useJEC_ && usePat_){
365 >       jets_.rawpt[jets_.nref]=(*patjets)[j].correctedJet("Uncorrected").pt();
366 >     }
367 >    
368 >     if(doLifeTimeTagging_){
369 >      
370 >       if(jetTag_.label()=="icPu5patJets"){
371 >         jets_.discr_csvMva[jets_.nref]    = (*patjets)[j].bDiscriminator("icPu5CombinedSecondaryVertexMVABJetTags");
372 >         jets_.discr_csvSimple[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5CombinedSecondaryVertexBJetTags");
373 >         jets_.discr_muByIp3[jets_.nref]   = (*patjets)[j].bDiscriminator("icPu5SoftMuonByIP3dBJetTags");
374 >         jets_.discr_muByPt[jets_.nref]    = (*patjets)[j].bDiscriminator("icPu5SoftMuonByPtBJetTags");
375 >         jets_.discr_prob[jets_.nref]      = (*patjets)[j].bDiscriminator("icPu5JetBProbabilityBJetTags");
376 >         jets_.discr_probb[jets_.nref]     = (*patjets)[j].bDiscriminator("icPu5JetProbabilityBJetTags");
377 >         jets_.discr_tcHighEff[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5TrackCountingHighEffBJetTags");
378 >         jets_.discr_tcHighPur[jets_.nref] = (*patjets)[j].bDiscriminator("icPu5TrackCountingHighPurBJetTags");
379 >       }
380 >       else if(jetTag_.label()=="akPu3PFpatJets"){
381 >         jets_.discr_csvMva[jets_.nref]    = (*patjets)[j].bDiscriminator("akPu3PFCombinedSecondaryVertexMVABJetTags");
382 >         jets_.discr_csvSimple[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFCombinedSecondaryVertexBJetTags");
383 >         jets_.discr_muByIp3[jets_.nref]   = (*patjets)[j].bDiscriminator("akPu3PFSoftMuonByIP3dBJetTags");
384 >         jets_.discr_muByPt[jets_.nref]    = (*patjets)[j].bDiscriminator("akPu3PFSoftMuonByPtBJetTags");
385 >         jets_.discr_prob[jets_.nref]      = (*patjets)[j].bDiscriminator("akPu3PFJetBProbabilityBJetTags");
386 >         jets_.discr_probb[jets_.nref]     = (*patjets)[j].bDiscriminator("akPu3PFJetProbabilityBJetTags");
387 >         jets_.discr_tcHighEff[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFTrackCountingHighEffBJetTags");
388 >         jets_.discr_tcHighPur[jets_.nref] = (*patjets)[j].bDiscriminator("akPu3PFTrackCountingHighPurBJetTags");
389 >       }
390 >       else{
391 >         cout<<" b-tagging variables not filled for this collection, turn of doLifeTimeTagging "<<endl;
392 >       }
393 >
394 >       const reco::SecondaryVertexTagInfo& tagInfoSV=*(*patjets)[j].tagInfoSecondaryVertex();
395 >      
396 >       jets_.nsvtx[jets_.nref]     = tagInfoSV.nVertices();      
397 >      
398 >       if (tagInfoSV.nVertices()>0) {
399 >         jets_.svtxntrk[jets_.nref]  = tagInfoSV.nVertexTracks(0);
400 >         // this is the 3d flight distance, for 2-D use (0,true)
401 >         Measurement1D m1D = tagInfoSV.flightDistance(0);        
402 >         jets_.svtxdl[jets_.nref]    = m1D.value();
403 >         jets_.svtxdls[jets_.nref]   = m1D.significance();
404 >        
405 >         const reco::Vertex& svtx = tagInfoSV.secondaryVertex(0);        
406 >         //cout<<" SV:  vx: "<<svtx.x()<<" vy "<<svtx.y()<<" vz "<<svtx.z()<<endl;
407 >         //cout<<" PV:  vx: "<<jet.vx()<<" vy "<<jet.vy()<<" vz "<<jet.vz()<<endl;      
408 >         jets_.svtxm[jets_.nref]    = svtx.p4().mass();
409 >         jets_.svtxpt[jets_.nref]   = svtx.p4().pt();    
410 >         //cout<<" chi2 "<<svtx.chi2()<<" ndof "<<svtx.ndof()<<endl;
411 >       }
412 >      
413 >       const reco::TrackIPTagInfo& tagInfoIP=*(*patjets)[j].tagInfoTrackIP();
414 >      
415 >       jets_.nIPtrk[jets_.nref] = tagInfoIP.tracks().size();
416 >       jets_.nselIPtrk[jets_.nref] = tagInfoIP.selectedTracks().size();
417 >
418 >       if (doLifeTimeTaggingExtras_) {
419 >
420 >         TrackRefVector selTracks=tagInfoIP.selectedTracks();
421 >        
422 >         GlobalPoint pv(tagInfoIP.primaryVertex()->position().x(),tagInfoIP.primaryVertex()->position().y(),tagInfoIP.primaryVertex()->position().z());
423 >        
424 >         for(int it=0;it<jets_.nselIPtrk[jets_.nref] ;it++)
425 >           {
426 >             jets_.ipJetIndex[jets_.nIP + it]= jets_.nref;
427 >             TrackIPTagInfo::TrackIPData data = tagInfoIP.impactParameterData()[it];  
428 >             jets_.ipPt[jets_.nIP + it] = selTracks[it]->pt();
429 >             jets_.ipProb0[jets_.nIP + it] = tagInfoIP.probabilities(0)[it];
430 >             jets_.ipProb1[jets_.nIP + it] = tagInfoIP.probabilities(1)[it];
431 >             jets_.ip2d[jets_.nIP + it] = data.ip2d.value();
432 >             jets_.ip2dSig[jets_.nIP + it] = data.ip2d.significance();
433 >             jets_.ip3d[jets_.nIP + it] = data.ip3d.value();
434 >             jets_.ip3dSig[jets_.nIP + it] = data.ip3d.significance();
435 >             jets_.ipDist2Jet[jets_.nIP + it] = data.distanceToJetAxis.value();
436 >             jets_.ipDist2JetSig[jets_.nIP + it] = data.distanceToJetAxis.significance();
437 >             jets_.ipClosest2Jet[jets_.nIP + it] = (data.closestToJetAxis - pv).mag();  //decay length  
438 >           }
439 >
440 >         jets_.nIP += jets_.nselIPtrk[jets_.nref];
441 >
442 >       }
443 >      
444 >       const reco::PFCandidateCollection *pfCandidateColl = &(*pfCandidates);
445 >       int pfMuonIndex = getPFJetMuon(jet, pfCandidateColl);
446 >       if(pfMuonIndex >=0){
447 >         const reco::PFCandidate muon = pfCandidateColl->at(pfMuonIndex);
448 >         jets_.mupt[jets_.nref]    =  muon.pt();
449 >         jets_.mueta[jets_.nref]   =  muon.eta();
450 >         jets_.muphi[jets_.nref]   =  muon.phi();  
451 >         jets_.mue[jets_.nref]     =  muon.energy();
452 >         jets_.mudr[jets_.nref]    =  reco::deltaR(jet,muon);
453 >         jets_.muptrel[jets_.nref] =  getPtRel(muon, jet);
454 >         jets_.muchg[jets_.nref]   =  muon.charge();
455 >       }else{
456 >         jets_.mupt[jets_.nref]    =  0.0;
457 >         jets_.mueta[jets_.nref]   =  0.0;
458 >         jets_.muphi[jets_.nref]   =  0.0;
459 >         jets_.mue[jets_.nref]     =  0.0;
460 >         jets_.mudr[jets_.nref]    =  9.9;
461 >         jets_.muptrel[jets_.nref] =  0.0;
462 >         jets_.muchg[jets_.nref]   = 0;
463 >       }
464 >
465 >     }
466 >
467 >
468 >
469 >     // Jet ID variables
470 >
471 >     jets_.muMax[jets_.nref] = 0;
472 >     jets_.muSum[jets_.nref] = 0;
473 >     jets_.muN[jets_.nref] = 0;
474 >
475 >     jets_.eMax[jets_.nref] = 0;
476 >     jets_.eSum[jets_.nref] = 0;
477 >     jets_.eN[jets_.nref] = 0;
478 >
479 >     jets_.neutralMax[jets_.nref] = 0;
480 >     jets_.neutralSum[jets_.nref] = 0;
481 >     jets_.neutralN[jets_.nref] = 0;
482 >
483 >     jets_.photonMax[jets_.nref] = 0;
484 >     jets_.photonSum[jets_.nref] = 0;
485 >     jets_.photonN[jets_.nref] = 0;
486 >
487 >     jets_.chargedMax[jets_.nref] = 0;
488 >     jets_.chargedSum[jets_.nref] = 0;
489 >     jets_.chargedN[jets_.nref] = 0;
490 >
491 >     jets_.trackMax[jets_.nref] = 0;
492 >     jets_.trackSum[jets_.nref] = 0;
493 >     jets_.trackN[jets_.nref] = 0;
494 >
495 >
496 >     for(unsigned int icand = 0; icand < tracks->size(); ++icand){
497 >        const reco::Track& track = (*tracks)[icand];
498 >        double dr = deltaR(jet,track);
499 >        if(dr < rParam){
500 >           double ptcand = track.pt();
501 >           jets_.trackSum[jets_.nref] += ptcand;
502 >           jets_.trackN[jets_.nref] += 1;
503 >           if(ptcand > jets_.trackMax[jets_.nref]) jets_.trackMax[jets_.nref] = ptcand;
504 >
505 >        }
506 >     }
507 >
508 >     for(unsigned int icand = 0; icand < pfCandidates->size(); ++icand){
509 >        const reco::PFCandidate& track = (*pfCandidates)[icand];
510 >        double dr = deltaR(jet,track);
511 >        if(dr < rParam){
512 >           double ptcand = track.pt();
513 >           int pfid = track.particleId();
514 >
515 >           switch(pfid){
516 >
517 >           case 1:
518 >              jets_.chargedSum[jets_.nref] += ptcand;
519 >              jets_.chargedN[jets_.nref] += 1;
520 >              if(ptcand > jets_.chargedMax[jets_.nref]) jets_.chargedMax[jets_.nref] = ptcand;
521 >              break;
522 >
523 >           case 2:
524 >              jets_.eSum[jets_.nref] += ptcand;
525 >              jets_.eN[jets_.nref] += 1;
526 >              if(ptcand > jets_.eMax[jets_.nref]) jets_.eMax[jets_.nref] = ptcand;
527 >              break;
528 >
529 >           case 3:
530 >              jets_.muSum[jets_.nref] += ptcand;
531 >              jets_.muN[jets_.nref] += 1;
532 >              if(ptcand > jets_.muMax[jets_.nref]) jets_.muMax[jets_.nref] = ptcand;
533 >              break;
534 >
535 >           case 4:
536 >              jets_.photonSum[jets_.nref] += ptcand;
537 >              jets_.photonN[jets_.nref] += 1;
538 >              if(ptcand > jets_.photonMax[jets_.nref]) jets_.photonMax[jets_.nref] = ptcand;
539 >              break;
540 >
541 >           case 5:
542 >              jets_.neutralSum[jets_.nref] += ptcand;
543 >              jets_.neutralN[jets_.nref] += 1;
544 >              if(ptcand > jets_.neutralMax[jets_.nref]) jets_.neutralMax[jets_.nref] = ptcand;
545 >              break;
546 >
547 >           }
548 >        }
549 >     }
550 >
551 >  
552 >
553 >
554 >
555 >
556 >     //     if(etrk.quality(reco::TrackBase::qualityByName(qualityString_))) pev_.trkQual[pev_.nTrk]=1;
557 >
558 >        /////////////////////////////////////////////////////////////////
559 >        // Jet core pt^2 discriminant for fake jets
560 >        // Edited by Yue Shi Lai <ylai@mit.edu>
561 >
562 >        // Initial value is 0
563 >        jets_.discr_fr01[jets_.nref] = 0;
564 >        // Start with no directional adaption, i.e. the fake rejection
565 >        // axis is the jet axis
566 >        float pseudorapidity_adapt = jets_.jteta[jets_.nref];
567 >        float azimuth_adapt = jets_.jtphi[jets_.nref];
568 >
569 >        // Unadapted discriminant with adaption search
570 >        for (size_t iteration = 0; iteration < 2; iteration++) {
571 >                float pseudorapidity_adapt_new = pseudorapidity_adapt;
572 >                float azimuth_adapt_new = azimuth_adapt;
573 >                float max_weighted_perp = 0;
574 >                float perp_square_sum = 0;
575 >
576 >                for (size_t index_pf_candidate = 0;
577 >                         index_pf_candidate < pfCandidates->size();
578 >                         index_pf_candidate++) {
579 >                        const reco::PFCandidate &p =
580 >                                (*pfCandidates)[index_pf_candidate];
581 >
582 >                        switch (p.particleId()) {
583 >                        case 1: // Charged hadron
584 >                        case 3: // Muon
585 >                        case 4: // Photon
586 >                                {
587 >                                        const float dpseudorapidity =
588 >                                                p.eta() - pseudorapidity_adapt;
589 >                                        const float dazimuth =
590 >                                                reco::deltaPhi(p.phi(), azimuth_adapt);
591 >                                        // The Gaussian scale factor is 0.5 / (0.1 * 0.1)
592 >                                        // = 50
593 >                                        const float angular_weight =
594 >                                                exp(-50.0F * (dpseudorapidity * dpseudorapidity +
595 >                                                                          dazimuth * dazimuth));
596 >                                        const float weighted_perp =
597 >                                                angular_weight * p.pt() * p.pt();
598 >                                        const float weighted_perp_square =
599 >                                                weighted_perp * p.pt();
600 >
601 >                                        perp_square_sum += weighted_perp_square;
602 >                                        if (weighted_perp >= max_weighted_perp) {
603 >                                                pseudorapidity_adapt_new = p.eta();
604 >                                                azimuth_adapt_new = p.phi();
605 >                                                max_weighted_perp = weighted_perp;
606 >                                        }
607 >                                }
608 >                        }
609 >                }
610 >                // Update the fake rejection value
611 >                jets_.discr_fr01[jets_.nref] = std::max(
612 >                        jets_.discr_fr01[jets_.nref], perp_square_sum);
613 >                // Update the directional adaption
614 >                pseudorapidity_adapt = pseudorapidity_adapt_new;
615 >                azimuth_adapt = azimuth_adapt_new;
616 >        }
617 >
618 >
619       jets_.jtpt[jets_.nref] = jet.pt();                            
620       jets_.jteta[jets_.nref] = jet.eta();
621       jets_.jtphi[jets_.nref] = jet.phi();
622       jets_.jty[jets_.nref] = jet.eta();
623 <    
623 >     jets_.jtpu[jets_.nref] = jet.pileup();
624          
625 <     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 <     }
625 >     if(isMC_ && usePat_){
626  
627 <     // matched partons
628 <     if (jet.genParton()) {
629 <       jets_.refparton_pt[jets_.nref] = jet.genParton()->pt();
630 <       jets_.refparton_flavor[jets_.nref] = jet.genParton()->pdgId();
631 <     } else {
632 <       jets_.refparton_pt[jets_.nref] = -999;
633 <       jets_.refparton_flavor[jets_.nref] = -999;
634 <     }
627 >       const reco::GenJet * genjet = (*patjets)[j].genJet();
628 >        
629 >       if(genjet){
630 >         jets_.refpt[jets_.nref] = genjet->pt();        
631 >         jets_.refeta[jets_.nref] = genjet->eta();
632 >         jets_.refphi[jets_.nref] = genjet->phi();
633 >         jets_.refy[jets_.nref] = genjet->eta();
634 >         jets_.refdphijt[jets_.nref] = reco::deltaPhi(jet.phi(), genjet->phi());        
635 >         jets_.refdrjt[jets_.nref] = reco::deltaR(jet.eta(),jet.phi(),genjet->eta(),genjet->phi());            
636 >       }else{
637 >         jets_.refpt[jets_.nref] = -999.;
638 >         jets_.refeta[jets_.nref] = -999.;
639 >         jets_.refphi[jets_.nref] = -999.;
640 >         jets_.refy[jets_.nref] = -999.;
641 >         jets_.refdphijt[jets_.nref] = -999.;
642 >         jets_.refdrjt[jets_.nref] = -999.;
643 >       }
644  
645 +       jets_.refparton_flavorForB[jets_.nref] = (*patjets)[j].partonFlavour();
646 +      
647 +       // matched partons
648 +       const reco::GenParticle & parton = *(*patjets)[j].genParton();
649 +
650 +       if((*patjets)[j].genParton()){
651 +         jets_.refparton_pt[jets_.nref] = parton.pt();
652 +         jets_.refparton_flavor[jets_.nref] = parton.pdgId();
653 +        
654 +         if(saveBfragments_ && abs(jets_.refparton_flavorForB[jets_.nref])==5){
655 +
656 +           usedStringPts.clear();
657 +          
658 +           // uncomment this if you want to know the ugly truth about parton matching -matt
659 +           //if(jet.pt() > 50 &&abs(parton.pdgId())!=5 && parton.pdgId()!=21)
660 +           // cout<<" Identified as a b, but doesn't match b or gluon, id = "<<parton.pdgId()<<endl;
661 +          
662 +           jets_.bJetIndex[jets_.bMult] = jets_.nref;
663 +           jets_.bStatus[jets_.bMult] = parton.status();
664 +           jets_.bVx[jets_.bMult] = parton.vx();
665 +           jets_.bVy[jets_.bMult] = parton.vy();
666 +           jets_.bVz[jets_.bMult] = parton.vz();
667 +           jets_.bPt[jets_.bMult] = parton.pt();
668 +           jets_.bEta[jets_.bMult] = parton.eta();
669 +           jets_.bPhi[jets_.bMult] = parton.phi();
670 +           jets_.bPdg[jets_.bMult] = parton.pdgId();
671 +           jets_.bChg[jets_.bMult] = parton.charge();
672 +           jets_.bMult++;
673 +           saveDaughters(parton);
674 +         }
675 +
676 +
677 +       } else {
678 +         jets_.refparton_pt[jets_.nref] = -999;
679 +         jets_.refparton_flavor[jets_.nref] = -999;
680 +       }
681 +      
682 +
683 +     }
684  
685       jets_.nref++;
686        
# Line 299 | Line 690 | HiInclusiveJetAnalyzer::analyze(const Ev
690  
691     if(isMC_){
692  
693 +     edm::Handle<HepMCProduct> hepMCProduct;
694 +     iEvent.getByLabel(eventInfoTag_,hepMCProduct);
695 +     const HepMC::GenEvent* MCEvt = hepMCProduct->GetEvent();
696 +     std::pair<HepMC::GenParticle*,HepMC::GenParticle*> beamParticles = MCEvt->beam_particles();
697 +     jets_.beamId1 = beamParticles.first->pdg_id();
698 +     jets_.beamId2 = beamParticles.second->pdg_id();
699 +
700       edm::Handle<GenEventInfoProduct> hEventInfo;
701       iEvent.getByLabel(eventInfoTag_,hEventInfo);
702       //jets_.pthat = hEventInfo->binningValues()[0];
# Line 316 | Line 714 | HiInclusiveJetAnalyzer::analyze(const Ev
714         float genjet_pt = genjet.pt();
715        
716         // threshold to reduce size of output in minbias PbPb
717 <       if(genjet_pt>20.){
717 >       if(genjet_pt>genPtMin_){
718  
719           jets_.genpt[jets_.ngen] = genjet_pt;                            
720           jets_.geneta[jets_.ngen] = genjet.eta();
721           jets_.genphi[jets_.ngen] = genjet.phi();
722           jets_.geny[jets_.ngen] = genjet.eta();
723          
724 +         if(doSubEvent_){
725 +            const GenParticle* gencon = genjet.getGenConstituent(0);
726 +            jets_.gensubid[jets_.ngen] = gencon->collisionId();
727 +         }
728          
729           // find matching patJet if there is one
730          
731           jets_.gendrjt[jets_.ngen] = -1.0;
732           jets_.genmatchindex[jets_.ngen] = -1;
733          
332        
734           for(unsigned int ijet = 0 ; ijet < jets->size(); ++ijet){
735             const pat::Jet& jet = (*jets)[ijet];
736 <          
737 <           if(jet.genJet()){
738 <             if(fabs(genjet.pt()-jet.genJet()->pt())<0.0001 &&
739 <                fabs(genjet.eta()-jet.genJet()->eta())<0.0001 &&
740 <                (fabs(genjet.phi()-jet.genJet()->phi())<0.0001 || fabs(genjet.phi()-jet.genJet()->phi() - 2.0*TMath::Pi()) < 0.0001 )){
736 >           const reco::GenJet* matchedGenJet = (*patjets)[ijet].genJet();
737 >           if(matchedGenJet){
738 >             // poor man's matching, someone fix please
739 >             if(fabs(genjet.pt()-matchedGenJet->pt())<0.0001 &&
740 >                fabs(genjet.eta()-matchedGenJet->eta())<0.0001 &&
741 >                (fabs(genjet.phi()-matchedGenJet->phi())<0.0001 || fabs(genjet.phi()-matchedGenJet->phi() - 2.0*TMath::Pi()) < 0.0001 )){
742                
743                 jets_.genmatchindex[jets_.ngen] = (int)ijet;
744                 jets_.gendphijt[jets_.ngen] = reco::deltaPhi(jet.phi(),genjet.phi());    
# Line 353 | Line 755 | HiInclusiveJetAnalyzer::analyze(const Ev
755      
756     }
757     t->Fill();
758 +   memset(&jets_,0,sizeof jets_);
759   }
760  
761  
# Line 452 | Line 855 | inline bool HiInclusiveJetAnalyzer::getP
855   }
856  
857  
858 + int
859 + HiInclusiveJetAnalyzer::getPFJetMuon(const pat::Jet& pfJet, const reco::PFCandidateCollection *pfCandidateColl)
860 + {
861 +  
862 +  int pfMuonIndex = -1;
863 +  float ptMax = 0.;
864 +
865 +
866 +  for(unsigned icand=0;icand<pfCandidateColl->size(); icand++) {
867 +    const reco::PFCandidate pfCandidate = pfCandidateColl->at(icand);      
868 +    
869 +    int id = pfCandidate.particleId();
870 +    if(abs(id) != 3) continue;
871 +
872 +    if(reco::deltaR(pfJet,pfCandidate)>0.5) continue;      
873 +    
874 +    double pt =  pfCandidate.pt();
875 +    if(pt>ptMax){
876 +      ptMax = pt;
877 +      pfMuonIndex = (int) icand;
878 +    }
879 +  }
880 +
881 +  return pfMuonIndex;  
882 +
883 + }
884  
885 +
886 + double
887 + HiInclusiveJetAnalyzer::getPtRel(const reco::PFCandidate lep, const pat::Jet& jet )
888 + {
889 +  
890 +  float lj_x = jet.p4().px();
891 +  float lj_y = jet.p4().py();
892 +  float lj_z = jet.p4().pz();
893 +  
894 +  // absolute values squared
895 +  float lj2  = lj_x*lj_x+lj_y*lj_y+lj_z*lj_z;
896 +  float lep2 = lep.px()*lep.px()+lep.py()*lep.py()+lep.pz()*lep.pz();
897 +  
898 +  // projection vec(mu) to lepjet axis
899 +  float lepXlj = lep.px()*lj_x+lep.py()*lj_y+lep.pz()*lj_z;
900 +  
901 +  // absolute value squared and normalized
902 +  float pLrel2 = lepXlj*lepXlj/lj2;
903 +  
904 +  // lep2 = pTrel2 + pLrel2
905 +  float pTrel2 = lep2-pLrel2;
906 +  
907 +  return (pTrel2 > 0) ? std::sqrt(pTrel2) : 0.0;
908 + }
909 +
910 + // Recursive function, but this version gets called only the first time
911 + void
912 + HiInclusiveJetAnalyzer::saveDaughters(const reco::GenParticle &gen){
913 +  
914 +  for(unsigned i=0;i<gen.numberOfDaughters();i++){
915 +    const reco::Candidate & daughter = *gen.daughter(i);
916 +    double daughterPt = daughter.pt();
917 +    if(daughterPt<1.) continue;
918 +    double daughterEta = daughter.eta();
919 +    if(fabs(daughterEta)>3.) continue;
920 +    int daughterPdgId = daughter.pdgId();
921 +    int daughterStatus = daughter.status();
922 +    // Special case when b->b+string, both b and string contain all daughters, so only take the string
923 +    if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
924 +
925 +    // cheesy way of finding strings which were already used
926 +    if(daughter.pdgId()==92){
927 +      for(unsigned ist=0;ist<usedStringPts.size();ist++){
928 +        if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
929 +      }
930 +      usedStringPts.push_back(daughter.pt());
931 +    }
932 +    jets_.bJetIndex[jets_.bMult] = jets_.nref;
933 +    jets_.bStatus[jets_.bMult] = daughterStatus;
934 +    jets_.bVx[jets_.bMult] = daughter.vx();
935 +    jets_.bVy[jets_.bMult] = daughter.vy();
936 +    jets_.bVz[jets_.bMult] = daughter.vz();
937 +    jets_.bPt[jets_.bMult] = daughterPt;
938 +    jets_.bEta[jets_.bMult] = daughterEta;
939 +    jets_.bPhi[jets_.bMult] = daughter.phi();
940 +    jets_.bPdg[jets_.bMult] = daughterPdgId;
941 +    jets_.bChg[jets_.bMult] = daughter.charge();
942 +    jets_.bMult++;
943 +    saveDaughters(daughter);
944 +  }
945 + }
946 +
947 + // This version called for all subsequent calls
948 + void
949 + HiInclusiveJetAnalyzer::saveDaughters(const reco::Candidate &gen){
950 +
951 +  for(unsigned i=0;i<gen.numberOfDaughters();i++){
952 +    const reco::Candidate & daughter = *gen.daughter(i);
953 +    double daughterPt = daughter.pt();
954 +    if(daughterPt<1.) continue;
955 +    double daughterEta = daughter.eta();
956 +    if(fabs(daughterEta)>3.) continue;
957 +    int daughterPdgId = daughter.pdgId();
958 +    int daughterStatus = daughter.status();
959 +    // Special case when b->b+string, both b and string contain all daughters, so only take the string
960 +    if(gen.pdgId()==daughterPdgId && gen.status()==3 && daughterStatus==2) continue;
961 +
962 +    // cheesy way of finding strings which were already used
963 +    if(daughter.pdgId()==92){
964 +      for(unsigned ist=0;ist<usedStringPts.size();ist++){
965 +        if(fabs(daughter.pt() - usedStringPts[ist]) < 0.0001) return;
966 +      }
967 +      usedStringPts.push_back(daughter.pt());
968 +    }
969 +
970 +    jets_.bJetIndex[jets_.bMult] = jets_.nref;
971 +    jets_.bStatus[jets_.bMult] = daughterStatus;
972 +    jets_.bVx[jets_.bMult] = daughter.vx();
973 +    jets_.bVy[jets_.bMult] = daughter.vy();
974 +    jets_.bVz[jets_.bMult] = daughter.vz();
975 +    jets_.bPt[jets_.bMult] = daughterPt;
976 +    jets_.bEta[jets_.bMult] = daughterEta;
977 +    jets_.bPhi[jets_.bMult] = daughter.phi();
978 +    jets_.bPdg[jets_.bMult] = daughterPdgId;
979 +    jets_.bChg[jets_.bMult] = daughter.charge();
980 +    jets_.bMult++;
981 +    saveDaughters(daughter);
982 +  }
983 + }
984                                                                          
985   DEFINE_FWK_MODULE(HiInclusiveJetAnalyzer);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines