CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoJets/JetAssociationAlgorithms/src/JetTracksAssociationDRCalo.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: JetTracksAssociationDRCalo.cc,v 1.9 2010/03/18 12:17:58 bainbrid Exp $
00004 
00005 #include "RecoJets/JetAssociationAlgorithms/interface/JetTracksAssociationDRCalo.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 
00013 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
00014 #include "DataFormats/GeometrySurface/interface/Plane.h"
00015 
00016 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00017 #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h"
00018 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00019 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00020 #include "MagneticField/Engine/interface/MagneticField.h"
00021 
00022 
00023 namespace {
00024   // basic geometry constants, imported from Geometry/HcalTowerAlgo/src/CaloTowerHardcodeGeometryLoader.cc
00025   const double rBarrel = 129.;
00026   const double zEndcap = 320.;
00027   const double zVF = 1100.;
00028   const double rEndcapMin = zEndcap * tan ( 2*atan (exp (-3.)));
00029   const double rVFMin = zEndcap * tan ( 2*atan (exp (-5.191)));
00030 
00031   struct ImpactPoint {
00032     unsigned index;
00033     double eta;
00034     double phi;
00035   };
00036 
00037   GlobalPoint propagateTrackToCalo (const reco::Track& fTrack,
00038                                     const MagneticField& fField,
00039                                     const Propagator& fPropagator)
00040   {
00041     GlobalPoint trackPosition (fTrack.vx(), fTrack.vy(), fTrack.vz()); // reference point
00042     GlobalVector trackMomentum (fTrack.px(), fTrack.py(), fTrack.pz()); // reference momentum
00043     if (fTrack.extra().isAvailable() ) { // use outer point information, if available
00044       trackPosition =  GlobalPoint (fTrack.outerX(), fTrack.outerY(), fTrack.outerZ());
00045       trackMomentum = GlobalVector (fTrack.outerPx(), fTrack.outerPy(), fTrack.outerPz());
00046     }
00047 //     std::cout << "propagateTrackToCalo-> start propagating track"
00048 //            << " x/y/z: " << trackPosition.x() << '/' << trackPosition.y() << '/' << trackPosition.z()
00049 //            << ", pt/eta/phi: " << trackMomentum.perp() << '/' << trackMomentum.eta() << '/' << trackMomentum.barePhi()
00050 //            << std::endl;
00051     GlobalTrajectoryParameters trackParams(trackPosition, trackMomentum, fTrack.charge(), &fField);
00052     FreeTrajectoryState trackState (trackParams);
00053 
00054     // first propagate to barrel
00055     TrajectoryStateOnSurface 
00056       propagatedInfo = fPropagator.propagate (trackState, 
00057                                               *Cylinder::build (Surface::PositionType (0,0,0),
00058                                                                 Surface::RotationType(),
00059                                                                 rBarrel)
00060                                               );
00061     if (propagatedInfo.isValid()) {
00062       GlobalPoint result (propagatedInfo.globalPosition ());
00063       if (fabs (result.z()) < zEndcap) {
00064 //      std::cout << "propagateTrackToCalo-> propagated to barrel:"
00065 //                << " x/y/z/r: " << result.x() << '/' << result.y() << '/' << result.z() << '/' << result.perp()
00066 //                << std::endl;
00067         return result;
00068       }
00069     }
00070     
00071     // failed with barrel, try endcap
00072     double zTarget = trackMomentum.z() > 0 ? zEndcap : -zEndcap;
00073     propagatedInfo = fPropagator.propagate (trackState, 
00074                                             *Plane::build( Surface::PositionType(0, 0, zTarget),
00075                                                            Surface::RotationType())
00076                                             );
00077     if (propagatedInfo.isValid()) {
00078       GlobalPoint result (propagatedInfo.globalPosition ());
00079       if (fabs (result.perp()) > rEndcapMin) {
00080 //      std::cout << "propagateTrackToCalo-> propagated to endcap:"
00081 //                << " x/y/z/r: " << result.x() << '/' << result.y() << '/' << result.z() << '/' << result.perp()
00082 //                << std::endl;
00083         return result;
00084       }
00085     }
00086     // failed with endcap, try VF
00087     zTarget = trackMomentum.z() > 0 ? zVF : -zVF;
00088     propagatedInfo = fPropagator.propagate (trackState, 
00089                                             *Plane::build( Surface::PositionType(0, 0, zTarget),
00090                                                            Surface::RotationType())
00091                                             );
00092     if (propagatedInfo.isValid()) {
00093       GlobalPoint result (propagatedInfo.globalPosition ());
00094       if (fabs (result.perp()) > rVFMin) {
00095 //      std::cout << "propagateTrackToCalo-> propagated to VF:"
00096 //                << " x/y/z/r: " << result.x() << '/' << result.y() << '/' << result.z() << '/' << result.perp()
00097 //                << std::endl;
00098         return result;
00099       }
00100     }
00101     // no luck
00102 //     std::cout << "propagateTrackToCalo-> failed to propagate track to calorimeter" << std::endl;
00103     return GlobalPoint (0, 0, 0);
00104   }
00105 }
00106 
00107 JetTracksAssociationDRCalo::JetTracksAssociationDRCalo (double fDr) 
00108 : mDeltaR2Threshold (fDr*fDr)
00109 {}
00110 
00111 void JetTracksAssociationDRCalo::produce (reco::JetTracksAssociation::Container* fAssociation, 
00112                                           const std::vector <edm::RefToBase<reco::Jet> >& fJets,
00113                                           const std::vector <reco::TrackRef>& fTracks,
00114                                           const MagneticField& fField,
00115                                           const Propagator& fPropagator) const 
00116 {
00117   // cache track parameters
00118   std::vector<ImpactPoint> impacts;
00119   for (unsigned t = 0; t < fTracks.size(); ++t) {
00120     GlobalPoint impact = propagateTrackToCalo (*(fTracks[t]), fField, fPropagator);
00121     if (impact.mag () > 0) { // successful extrapolation
00122       ImpactPoint goodTrack;
00123       goodTrack.index = t;
00124       goodTrack.eta = impact.eta ();
00125       goodTrack.phi = impact.barePhi();
00126       impacts.push_back (goodTrack);
00127     }
00128   }
00129   
00130   for (unsigned j = 0; j < fJets.size(); ++j) {
00131     reco::TrackRefVector assoTracks;
00132     const reco::Jet* jet = &*(fJets[j]); 
00133     double jetEta = jet->eta();
00134     double jetPhi = jet->phi();
00135     for (unsigned t = 0; t < impacts.size(); ++t) {
00136       double dR2 = deltaR2 (jetEta, jetPhi, impacts[t].eta, impacts[t].phi);
00137       if (dR2 < mDeltaR2Threshold)  assoTracks.push_back (fTracks[impacts[t].index]);
00138     }
00139     reco::JetTracksAssociation::setValue (fAssociation, fJets[j], assoTracks);
00140   }
00141 }
00142 
00143 math::XYZPoint JetTracksAssociationDRCalo::propagateTrackToCalorimeter (const reco::Track& fTrack,
00144                                                                    const MagneticField& fField,
00145                                                                    const Propagator& fPropagator)
00146 {
00147   GlobalPoint result (propagateTrackToCalo (fTrack, fField, fPropagator));
00148   return math::XYZPoint (result.x(), result.y(), result.z()); 
00149 }