Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-27 00:17:03

0001 #ifndef TrackGenAssociatorByChi2Impl_h
0002 #define TrackGenAssociatorByChi2Impl_h
0003 
0004 /** \class TrackGenAssociatorByChi2Impl
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/TrackGenAssociatorByChi2.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/Track/interface/SimTrackContainer.h"
0011 #include "MagneticField/Engine/interface/MagneticField.h"
0012 #include "SimDataFormats/Vertex/interface/SimVertexContainer.h"
0013 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0014 #include "DataFormats/Math/interface/LorentzVector.h"
0015 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0016 #include "DataFormats/HepMCCandidate/interface/GenParticle.h"
0017 #include "DataFormats/HepMCCandidate/interface/GenParticleFwd.h"
0018 #include "SimDataFormats/Associations/interface/TrackAssociation.h"
0019 #include "SimDataFormats/Associations/interface/TrackToGenParticleAssociatorBaseImpl.h"
0020 
0021 #include <map>
0022 
0023 //Note that the Association Map is filled with -ch2 and not chi2 because it is ordered using std::greater:
0024 //the track with the lowest association chi2 will be the first in the output map.
0025 
0026 namespace reco {
0027   typedef edm::AssociationMap<
0028       edm::OneToManyWithQualityGeneric<reco::GenParticleCollection, edm::View<reco::Track>, double> >
0029       GenToRecoCollection;
0030   typedef edm::AssociationMap<
0031       edm::OneToManyWithQualityGeneric<edm::View<reco::Track>, reco::GenParticleCollection, double> >
0032       RecoToGenCollection;
0033 }  // namespace reco
0034 
0035 class TrackGenAssociatorByChi2Impl : public reco::TrackToGenParticleAssociatorBaseImpl {
0036 public:
0037   typedef std::map<double, SimTrack> Chi2SimMap;
0038   typedef std::pair<reco::Track, Chi2SimMap> RecoToSimPair;
0039   typedef std::vector<RecoToSimPair> RecoToSimPairAssociation;
0040 
0041   /// Constructor with PSet
0042 
0043   /// Constructor with magnetic field, double, bool and InputTag
0044   TrackGenAssociatorByChi2Impl(const MagneticField& mF, const reco::BeamSpot& bs, double chi2Cut, bool onlyDiag)
0045       : theMF(&mF), theBeamSpot(&bs), chi2cut(chi2Cut), onlyDiagonal(onlyDiag) {}
0046 
0047   /// Association Sim To Reco with Collections (Gen Particle version)
0048   reco::RecoToGenCollection associateRecoToGen(const edm::RefToBaseVector<reco::Track>&,
0049                                                const edm::RefVector<reco::GenParticleCollection>&) const override;
0050 
0051   /// Association Sim To Reco with Collections (Gen Particle version)
0052   reco::GenToRecoCollection associateGenToReco(const edm::RefToBaseVector<reco::Track>&,
0053                                                const edm::RefVector<reco::GenParticleCollection>&) const override;
0054 
0055   /// compare reco to sim the handle of reco::Track and GenParticle collections
0056   reco::RecoToGenCollection associateRecoToGen(const edm::Handle<edm::View<reco::Track> >& tCH,
0057                                                const edm::Handle<reco::GenParticleCollection>& tPCH) const override {
0058     edm::RefToBaseVector<reco::Track> tc(tCH);
0059     for (unsigned int j = 0; j < tCH->size(); j++)
0060       tc.push_back(edm::RefToBase<reco::Track>(tCH, j));
0061 
0062     edm::RefVector<reco::GenParticleCollection> tpc(tPCH.id());
0063     for (unsigned int j = 0; j < tPCH->size(); j++)
0064       tpc.push_back(edm::Ref<reco::GenParticleCollection>(tPCH, j));
0065 
0066     return associateRecoToGen(tc, tpc);
0067   }
0068 
0069   /// compare reco to sim the handle of reco::Track and GenParticle collections
0070   reco::GenToRecoCollection associateGenToReco(const edm::Handle<edm::View<reco::Track> >& tCH,
0071                                                const edm::Handle<reco::GenParticleCollection>& tPCH) const override {
0072     edm::RefToBaseVector<reco::Track> tc(tCH);
0073     for (unsigned int j = 0; j < tCH->size(); j++)
0074       tc.push_back(edm::RefToBase<reco::Track>(tCH, j));
0075 
0076     edm::RefVector<reco::GenParticleCollection> tpc(tPCH.id());
0077     for (unsigned int j = 0; j < tPCH->size(); j++)
0078       tpc.push_back(edm::Ref<reco::GenParticleCollection>(tPCH, j));
0079 
0080     return associateGenToReco(tc, tpc);
0081   }
0082 
0083 private:
0084   /// basic method where chi2 is computed
0085   double getChi2(const reco::TrackBase::ParameterVector& rParameters,
0086                  const reco::TrackBase::CovarianceMatrix& recoTrackCovMatrix,
0087                  const Basic3DVector<double>& momAtVtx,
0088                  const Basic3DVector<double>& vert,
0089                  int charge,
0090                  const reco::BeamSpot&) const;
0091 
0092   /// compare reco::TrackCollection and TrackingParticleCollection iterators: returns the chi2
0093   double associateRecoToSim(reco::TrackCollection::const_iterator,
0094                             TrackingParticleCollection::const_iterator,
0095                             const reco::BeamSpot&) const;
0096 
0097   const MagneticField* theMF;
0098   const reco::BeamSpot* theBeamSpot;
0099   double chi2cut;
0100   bool onlyDiagonal;
0101 };
0102 
0103 #endif