Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:25:28

0001 // Associate jets with tracks by simple "dR" criteria
0002 // Fedor Ratnikov (UMd), Aug. 28, 2007
0003 
0004 #include "RecoJets/JetAssociationAlgorithms/interface/JetTracksAssociationXtrpCalo.h"
0005 #include "DataFormats/GeometrySurface/interface/Cylinder.h"
0006 #include "DataFormats/GeometrySurface/interface/Plane.h"
0007 #include "DataFormats/Math/interface/deltaR.h"
0008 #include "DataFormats/Math/interface/Vector3D.h"
0009 #include "MagneticField/Engine/interface/MagneticField.h"
0010 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0011 #include "TrackingTools/TrajectoryParametrization/interface/GlobalTrajectoryParameters.h"
0012 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0013 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0014 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0015 #include "DataFormats/DetId/interface/DetId.h"
0016 #include "DataFormats/JetReco/interface/CaloJet.h"
0017 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
0018 
0019 // -----------------------------------------------------------------------------
0020 //
0021 JetTracksAssociationXtrpCalo::JetTracksAssociationXtrpCalo() {}
0022 
0023 // -----------------------------------------------------------------------------
0024 //
0025 JetTracksAssociationXtrpCalo::~JetTracksAssociationXtrpCalo() {}
0026 
0027 // -----------------------------------------------------------------------------
0028 //
0029 
0030 void JetTracksAssociationXtrpCalo::produce(Association* fAssociation,
0031                                            JetRefs const& fJets,
0032                                            std::vector<reco::TrackExtrapolation> const& fExtrapolations,
0033                                            CaloGeometry const& fGeo,
0034                                            double dR) {
0035   for (JetRefs::const_iterator jetsBegin = fJets.begin(), jetsEnd = fJets.end(), ijet = jetsBegin; ijet != jetsEnd;
0036        ++ijet) {
0037     reco::TrackRefVector associated;
0038     associateInputTracksToJet(associated, **ijet, fExtrapolations, dR);
0039     reco::JetTracksAssociation::setValue(fAssociation, *ijet, associated);
0040   }
0041 }
0042 
0043 void JetTracksAssociationXtrpCalo::associateInputTracksToJet(
0044     reco::TrackRefVector& associated,
0045     const reco::Jet& fJet,
0046     std::vector<reco::TrackExtrapolation> const& fExtrapolations,
0047     double dR) {
0048   reco::CaloJet const* pCaloJet = dynamic_cast<reco::CaloJet const*>(&fJet);
0049   if (pCaloJet == nullptr) {
0050     throw cms::Exception("InvalidInput") << "Expecting calo jets only in JetTracksAssociationXtrpCalo";
0051   }
0052   // Loop over CaloTowers
0053   double jetPhi = pCaloJet->phi();
0054   double jetEta = pCaloJet->detectorP4().eta();
0055 
0056   // now cache the mapping of (det ID --> track)
0057 
0058   //  std::cout<<" New jet "<<jetEta<<" "<<jetPhi<<" Jet ET "<<pCaloJet->et()<<std::endl;
0059 
0060   for (std::vector<reco::TrackExtrapolation>::const_iterator xtrpBegin = fExtrapolations.begin(),
0061                                                              xtrpEnd = fExtrapolations.end(),
0062                                                              ixtrp = xtrpBegin;
0063        ixtrp != xtrpEnd;
0064        ++ixtrp) {
0065     if (ixtrp->positions().empty())
0066       continue;
0067     reco::TrackBase::Point const& point = ixtrp->positions().at(0);
0068 
0069     double dr = reco::deltaR<double>(jetEta, jetPhi, point.eta(), point.phi());
0070     if (dr < dR) {
0071       //    std::cout<<" JetTracksAssociationXtrpCalo::associateInputTracksToJet:: initial track "<<ixtrp->track()->pt()<<" "<<ixtrp->track()->eta()<<
0072       //    " "<<ixtrp->track()->phi()<< " Extrapolated position "<<point.eta()<<" "<<point.phi()<<" Valid? "<<ixtrp->isValid().at(0)<<" Jet eta, phi "<<jetEta<<" "<<jetPhi<<" Jet ET "<<pCaloJet->et()<<
0073       //    " dr "<<dr<<" dR "<<dR<<std::endl;
0074 
0075       reco::TrackRef matchedTrack = ixtrp->track();
0076       associated.push_back(matchedTrack);
0077     }
0078   }
0079 }