Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:31:01

0001 #ifndef TrackAssociatorByChi2Impl_h
0002 #define TrackAssociatorByChi2Impl_h
0003 
0004 /** \class TrackAssociatorByChi2Impl
0005  *  Class that performs the association of reco::Tracks and TrackingParticles evaluating the chi2 of reco tracks parameters and sim tracks parameters. The cut can be tuned from the config file: see data/TrackAssociatorByChi2.cfi. Note that the Association Map is filled with -ch2 and not chi2 because it is ordered using std::greater: the track with the lowest association chi2 will be the first in the output map.It is possible to use only diagonal terms (associator by pulls) seeting onlyDiagonal = true in the PSet 
0006  *
0007  *  \author cerati, magni
0008  */
0009 
0010 #include "SimDataFormats/Associations/interface/TrackToTrackingParticleAssociatorBaseImpl.h"
0011 #include "SimDataFormats/Track/interface/SimTrackContainer.h"
0012 #include "MagneticField/Engine/interface/MagneticField.h"
0013 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
0014 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0015 #include "DataFormats/Math/interface/LorentzVector.h"
0016 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0017 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0018 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
0019 
0020 #include <map>
0021 
0022 //Note that the Association Map is filled with -ch2 and not chi2 because it is ordered using std::greater:
0023 //the track with the lowest association chi2 will be the first in the output map.
0024 
0025 namespace edm {
0026   class EDProductGetter;
0027 }
0028 
0029 namespace reco {
0030   typedef edm::AssociationMap<
0031       edm::OneToManyWithQualityGeneric<reco::GenParticleCollection, edm::View<reco::Track>, double> >
0032       GenToRecoCollection;
0033   typedef edm::AssociationMap<
0034       edm::OneToManyWithQualityGeneric<edm::View<reco::Track>, reco::GenParticleCollection, double> >
0035       RecoToGenCollection;
0036 }  // namespace reco
0037 
0038 class TrackAssociatorByChi2Impl : public reco::TrackToTrackingParticleAssociatorBaseImpl {
0039 public:
0040   typedef std::map<double, SimTrack> Chi2SimMap;
0041   typedef std::pair<reco::Track, Chi2SimMap> RecoToSimPair;
0042   typedef std::vector<RecoToSimPair> RecoToSimPairAssociation;
0043 
0044   /*
0045   /// Constructor with PSet
0046   TrackAssociatorByChi2Impl(const edm::ESHandle<MagneticField> mF, const edm::ParameterSet& conf):
0047     chi2cut(conf.getParameter<double>("chi2cut")),
0048     onlyDiagonal(conf.getParameter<bool>("onlyDiagonal")),
0049     bsSrc(conf.getParameter<edm::InputTag>("beamSpot")) {
0050     mF_=mF;  
0051     if (onlyDiagonal)
0052       edm::LogInfo("TrackAssociator") << " ---- Using Off Diagonal Covariance Terms = 0 ---- " <<  "\n";
0053     else 
0054       edm::LogInfo("TrackAssociator") << " ---- Using Off Diagonal Covariance Terms != 0 ---- " <<  "\n";
0055   }
0056   */
0057 
0058   /// Constructor
0059   TrackAssociatorByChi2Impl(edm::EDProductGetter const& productGetter,
0060                             const MagneticField& mF,
0061                             const reco::BeamSpot& bs,
0062                             double chi2Cut,
0063                             bool onlyDiag)
0064       : productGetter_(&productGetter), mF_(&mF), beamSpot_(&bs), chi2cut_(chi2Cut), onlyDiagonal_(onlyDiag) {}
0065 
0066   /// Association Reco To Sim with Collections
0067 
0068   reco::RecoToSimCollection associateRecoToSim(const edm::RefToBaseVector<reco::Track>&,
0069                                                const edm::RefVector<TrackingParticleCollection>&) const override;
0070   /// Association Sim To Reco with Collections
0071 
0072   reco::SimToRecoCollection associateSimToReco(const edm::RefToBaseVector<reco::Track>&,
0073                                                const edm::RefVector<TrackingParticleCollection>&) const override;
0074 
0075   /// compare reco to sim the handle of reco::Track and TrackingParticle collections
0076 
0077   reco::RecoToSimCollection associateRecoToSim(const edm::Handle<edm::View<reco::Track> >& tCH,
0078                                                const edm::Handle<TrackingParticleCollection>& tPCH) const override {
0079     return TrackToTrackingParticleAssociatorBaseImpl::associateRecoToSim(tCH, tPCH);
0080   }
0081 
0082   /// compare reco to sim the handle of reco::Track and TrackingParticle collections
0083 
0084   reco::SimToRecoCollection associateSimToReco(const edm::Handle<edm::View<reco::Track> >& tCH,
0085                                                const edm::Handle<TrackingParticleCollection>& tPCH) const override {
0086     return TrackToTrackingParticleAssociatorBaseImpl::associateSimToReco(tCH, tPCH);
0087   }
0088 
0089 private:
0090   edm::EDProductGetter const* productGetter_;
0091   const MagneticField* mF_;
0092   const reco::BeamSpot* beamSpot_;
0093   double chi2cut_;
0094   bool onlyDiagonal_;
0095 };
0096 
0097 #endif