CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/RecoJets/JetAssociationAlgorithms/src/JetSignalVertexCompatibilityAlgo.cc

Go to the documentation of this file.
00001 #include <functional>
00002 #include <cmath>
00003 #include <map>
00004 
00005 #include "DataFormats/Common/interface/RefToBase.h"
00006 #include "DataFormats/TrackReco/interface/Track.h"
00007 #include "DataFormats/VertexReco/interface/Vertex.h"
00008 #include "DataFormats/VertexReco/interface/VertexFwd.h"
00009 
00010 #include "TrackingTools/GeomPropagators/interface/AnalyticalImpactPointExtrapolator.h"
00011 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00012 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
00013 #include "TrackingTools/TransientTrack/interface/TransientTrackBuilder.h"
00014 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00015 
00016 #include "RecoVertex/VertexPrimitives/interface/ConvertToFromReco.h"
00017 
00018 #include "RecoJets/JetAssociationAlgorithms/interface/JetSignalVertexCompatibilityAlgo.h"
00019 
00020 using namespace reco;
00021 
00022 // helper
00023 template<typename T>
00024 inline bool
00025 JetSignalVertexCompatibilityAlgo::RefToBaseLess<T>::operator()(
00026         const edm::RefToBase<T> &r1, const edm::RefToBase<T> &r2) const
00027 { return r1.id() < r2.id() || (r1.id() == r2.id() && r1.key() < r2.key()); }
00028 
00029 
00030 JetSignalVertexCompatibilityAlgo::JetSignalVertexCompatibilityAlgo(
00031                                         double cut, double temperature) :
00032         cut(cut), temperature(temperature)
00033 {}
00034 
00035 JetSignalVertexCompatibilityAlgo::~JetSignalVertexCompatibilityAlgo()
00036 {}
00037 
00038 double JetSignalVertexCompatibilityAlgo::trackVertexCompat(
00039                         const Vertex &vtx, const TransientTrack &track)
00040 {
00041         GlobalPoint point1 = RecoVertex::convertPos(vtx.position());
00042         AnalyticalImpactPointExtrapolator extrap(track.field());
00043         TrajectoryStateOnSurface tsos =
00044                         extrap.extrapolate(track.impactPointState(), point1);
00045 
00046         if (!tsos.isValid())
00047                 return 1.0e6;
00048 
00049         GlobalPoint point2 = tsos.globalPosition();
00050         ROOT::Math::SVector<double, 3> dir(point1.x() - point2.x(),
00051                                            point1.y() - point2.y(),
00052                                            point1.z() - point2.z());
00053         GlobalError cov = RecoVertex::convertError(vtx.covariance()) +
00054                           tsos.cartesianError().position();
00055 
00056         return ROOT::Math::Mag2(dir) /
00057                std::sqrt(ROOT::Math::Similarity(cov.matrix_new(), dir));
00058 }
00059 
00060 const TransientTrack&
00061 JetSignalVertexCompatibilityAlgo::convert(const TrackBaseRef &track) const
00062 {
00063         TransientTrackMap::iterator pos = trackMap.lower_bound(track);
00064         if (pos != trackMap.end() && pos->first == track)
00065                 return pos->second;
00066 
00067         // the castTo will only work with regular, i.e. no GsfTracks
00068         // the interface is not intrinsically polymorph...
00069         return trackMap.insert(pos,
00070                 std::make_pair(track, trackBuilder->build(
00071                                         track.castTo<TrackRef>())))->second;
00072 }
00073 
00074 double JetSignalVertexCompatibilityAlgo::activation(double compat) const
00075 {
00076         return 1. / (std::exp((compat - cut) / temperature) + 1.);
00077 }
00078 
00079 std::vector<float>
00080 JetSignalVertexCompatibilityAlgo::compatibility(
00081                                 const reco::VertexCollection &vertices,
00082                                 const reco::TrackRefVector &tracks) const
00083 {
00084         std::vector<float> result(vertices.size(), 0.);
00085         float sum = 0.;
00086 
00087         for(TrackRefVector::const_iterator track = tracks.begin();
00088             track != tracks.end(); ++track) {
00089                 const TransientTrack &transientTrack =
00090                                         convert(TrackBaseRef(*track));
00091 
00092                 for(unsigned int i = 0; i < vertices.size(); i++) {
00093                         double compat =
00094                                 trackVertexCompat(vertices[i], transientTrack);
00095                         double contribution =
00096                                 activation(compat) * (*track)->pt();
00097 
00098                         result[i] += contribution;
00099                         sum += contribution;
00100                 }
00101         }
00102 
00103         if (sum < 1.0e-9) {
00104                 for(unsigned int i = 0; i < result.size(); i++)
00105                         result[i] = 1.0 / result.size();
00106         } else {
00107                 for(unsigned int i = 0; i < result.size(); i++)
00108                         result[i] /= sum;
00109         }
00110 
00111         return result;
00112 }
00113 
00114 void JetSignalVertexCompatibilityAlgo::resetEvent(
00115                                         const TransientTrackBuilder *builder)
00116 {
00117         trackMap.clear();
00118         trackBuilder = builder;
00119 }
00120