File indexing completed on 2024-04-06 12:25:28
0001
0002
0003
0004 #include "RecoJets/JetAssociationAlgorithms/interface/JetTracksAssociationDRVertexAssigned.h"
0005
0006 #include "DataFormats/JetReco/interface/Jet.h"
0007 #include "DataFormats/TrackReco/interface/Track.h"
0008
0009 #include "DataFormats/Math/interface/deltaR.h"
0010 #include "DataFormats/Math/interface/Vector3D.h"
0011 #include "DataFormats/Math/interface/Point3D.h"
0012 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0013
0014 JetTracksAssociationDRVertexAssigned::JetTracksAssociationDRVertexAssigned(double fDr) : mDeltaR2Threshold(fDr * fDr) {}
0015
0016 void JetTracksAssociationDRVertexAssigned::produce(reco::JetTracksAssociation::Container* fAssociation,
0017 const std::vector<edm::RefToBase<reco::Jet> >& fJets,
0018 const std::vector<reco::TrackRef>& fTracks,
0019 const reco::VertexCollection& vertices) const {
0020
0021 std::vector<math::RhoEtaPhiVector> trackP3s;
0022 std::map<int, double> trackvert;
0023
0024
0025
0026 trackP3s.reserve(fTracks.size());
0027 for (unsigned i = 0; i < fTracks.size(); ++i) {
0028 const reco::Track* track = &*(fTracks[i]);
0029 trackP3s.push_back(math::RhoEtaPhiVector(track->p(), track->eta(), track->phi()));
0030
0031
0032
0033 const reco::TrackBaseRef ttr1(fTracks[i]);
0034
0035 int trackhasvert = -1;
0036 for (reco::VertexCollection::const_iterator iv = vertices.begin(); iv != vertices.end(); iv++) {
0037 std::vector<reco::TrackBaseRef>::const_iterator rr = find((*iv).tracks_begin(), (*iv).tracks_end(), ttr1);
0038 if (rr != (*iv).tracks_end()) {
0039 trackhasvert = 1;
0040 trackvert[i] = (*iv).position().z();
0041
0042 break;
0043 }
0044 }
0045 if (trackhasvert < 0) {
0046
0047 math::XYZPoint ppt(0., 0., 0.);
0048 trackvert[i] = track->dz(ppt);
0049
0050
0051 }
0052
0053 }
0054
0055 for (unsigned j = 0; j < fJets.size(); ++j) {
0056 reco::TrackRefVector assoTracks;
0057 const reco::Jet* jet = &*(fJets[j]);
0058 double jetEta = jet->eta();
0059 double jetPhi = jet->phi();
0060 double neweta = 0;
0061 for (unsigned t = 0; t < fTracks.size(); ++t) {
0062 std::map<int, double>::iterator cur = trackvert.find(t);
0063 if (cur != trackvert.end()) {
0064 neweta = jet->physicsEta((*cur).second, jetEta);
0065 } else {
0066 neweta = jetEta;
0067
0068 }
0069
0070
0071
0072 double dR2 = deltaR2(neweta, jetPhi, trackP3s[t].eta(), trackP3s[t].phi());
0073 if (dR2 < mDeltaR2Threshold)
0074 assoTracks.push_back(fTracks[t]);
0075 }
0076
0077 reco::JetTracksAssociation::setValue(fAssociation, fJets[j], assoTracks);
0078 }
0079 }