CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/RecoJets/JetAssociationAlgorithms/src/JetTracksAssociationDRVertexAssigned.cc

Go to the documentation of this file.
00001 // Associate jets with tracks by simple "dR" criteria
00002 // Fedor Ratnikov (UMd), Aug. 28, 2007
00003 // $Id: JetTracksAssociationDRVertexAssigned.cc,v 1.2 2011/11/29 10:04:47 srappocc Exp $
00004 
00005 #include "RecoJets/JetAssociationAlgorithms/interface/JetTracksAssociationDRVertexAssigned.h"
00006 
00007 #include "DataFormats/JetReco/interface/Jet.h"
00008 #include "DataFormats/TrackReco/interface/Track.h"
00009 
00010 #include "DataFormats/Math/interface/deltaR.h"
00011 #include "DataFormats/Math/interface/Vector3D.h"
00012 #include "DataFormats/Math/interface/Point3D.h"
00013 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00014 
00015 JetTracksAssociationDRVertexAssigned::JetTracksAssociationDRVertexAssigned (double fDr) 
00016 : mDeltaR2Threshold (fDr*fDr)
00017 {}
00018 
00019 void JetTracksAssociationDRVertexAssigned::produce (reco::JetTracksAssociation::Container* fAssociation, 
00020                                          const std::vector <edm::RefToBase<reco::Jet> >& fJets,
00021                                          const std::vector <reco::TrackRef>& fTracks,
00022                                          const reco::VertexCollection& vertices) const 
00023 {
00024   // cache tracks kinematics
00025   std::vector <math::RhoEtaPhiVector> trackP3s;
00026   std::map <int,double> trackvert;
00027 
00028  // std::cout<<" Number of vertices "<<vertices.size()<<std::endl;
00029 
00030   trackP3s.reserve (fTracks.size());
00031   for (unsigned i = 0; i < fTracks.size(); ++i) {
00032     const reco::Track* track = &*(fTracks[i]);
00033     trackP3s.push_back (math::RhoEtaPhiVector (track->p(),track->eta(), track->phi()));
00034         
00035  // OK: Look for the tracks not associated with vertices 
00036 
00037       const reco::TrackBaseRef ttr1(fTracks[i]);
00038 
00039    
00040       int trackhasvert = -1;
00041       for( reco::VertexCollection::const_iterator iv = vertices.begin(); iv != vertices.end(); iv++) {
00042       std::vector<reco::TrackBaseRef>::const_iterator rr = 
00043                                                            find((*iv).tracks_begin(),
00044                                                                 (*iv).tracks_end(),
00045                                                                                ttr1);
00046            if( rr != (*iv).tracks_end() ) { 
00047                       trackhasvert = 1;
00048                       trackvert[i] = (*iv).position().z();
00049         // std::cout<<" Z "<<i<<" "<<trackhasvert<<" "<<(*iv).position().z()<<std::endl;             
00050                       break;
00051            }
00052       } // all vertices  
00053      if(trackhasvert < 0) {
00054     // Take impact parameter of the track as vertex position
00055        math::XYZPoint ppt(0.,0.,0.);
00056        trackvert[i] = track->dz(ppt); 
00057    //    std::cout<<" Z "<<i<<" "<<trackhasvert<<" "<<track->dz(ppt)<<" "<<track->vz()<<" "<<track->vx()<<" "<<
00058    //    track->vy()<<" "<<track->pz()<<std::endl;
00059      }
00060  // OK 
00061   }  // tracks
00062 
00063   for (unsigned j = 0; j < fJets.size(); ++j) { 
00064 
00065     reco::TrackRefVector assoTracks;
00066     const reco::Jet* jet = &*(fJets[j]); 
00067     double jetEta = jet->eta();
00068     double jetPhi = jet->phi();
00069     double neweta = 0;
00070     for (unsigned t = 0; t < fTracks.size(); ++t) {
00071 
00072       std::map<int, double>::iterator cur  = trackvert.find(t);
00073       if(cur != trackvert.end()) { 
00074                neweta = jet->physicsEta((*cur).second,jetEta);            
00075       } else {
00076         neweta = jetEta; 
00077         //std::cout<<" Lost track - not in map "<<std::endl;
00078       }
00079 
00080       //std::cout<<" Old eta-new eta "<<(*cur).second<<" "<<jetEta<<" "<<neweta<<" Track "<<t<<" "<<trackP3s[t].eta()<<std::endl;
00081 
00082       double dR2 = deltaR2 (neweta, jetPhi, trackP3s[t].eta(), trackP3s[t].phi());
00083       if (dR2 < mDeltaR2Threshold)  assoTracks.push_back (fTracks[t]);
00084     }
00085 
00086     reco::JetTracksAssociation::setValue (fAssociation, fJets[j], assoTracks);
00087   }
00088 
00089 }