Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:24:08

0001 #ifndef RecoCandUtils_CandCommonVertexFitter_h
0002 #define RecoCandUtils_CandCommonVertexFitter_h
0003 /* \class CandCommonVertexFitter

0004  *

0005  * \author Luca Lista, INFN

0006  *

0007  */
0008 
0009 #include "FWCore/ParameterSet/interface/ParameterSetfwd.h"
0010 #include "TrackingTools/TransientTrack/interface/TransientTrack.h"
0011 #include "RecoVertex/VertexPrimitives/interface/TransientVertex.h"
0012 #include "DataFormats/RecoCandidate/interface/RecoCandidate.h"
0013 #include <vector>
0014 class MagneticField;
0015 namespace reco {
0016   class VertexCompositeCandidate;
0017 }
0018 
0019 class CandCommonVertexFitterBase {
0020 public:
0021   typedef reco::Vertex::CovarianceMatrix CovarianceMatrix;
0022   CandCommonVertexFitterBase(const edm::ParameterSet &) : bField_(nullptr) {}
0023   virtual ~CandCommonVertexFitterBase() {}
0024   void set(const MagneticField *bField) { bField_ = bField; }
0025   void set(reco::VertexCompositeCandidate &) const;
0026 
0027 protected:
0028   const MagneticField *bField_;
0029   void fill(std::vector<reco::TransientTrack> &,
0030             std::vector<reco::Candidate *> &,
0031             std::vector<reco::RecoCandidate::TrackType> &,
0032             reco::Candidate &) const;
0033   virtual bool fit(TransientVertex &, const std::vector<reco::TransientTrack> &) const = 0;
0034   /// chi-sqared

0035   mutable double chi2_;
0036   /// number of degrees of freedom

0037   mutable double ndof_;
0038   /// covariance matrix (3x3)

0039   mutable CovarianceMatrix cov_;
0040 };
0041 
0042 #include "PhysicsTools/UtilAlgos/interface/ParameterAdapter.h"
0043 
0044 template <typename Fitter>
0045 class CandCommonVertexFitter : public CandCommonVertexFitterBase {
0046 public:
0047   CandCommonVertexFitter(const edm::ParameterSet &cfg)
0048       : CandCommonVertexFitterBase(cfg), fitter_(reco::modules::make<Fitter>(cfg)) {}
0049   bool fit(TransientVertex &vertex, const std::vector<reco::TransientTrack> &tracks) const override {
0050     try {
0051       vertex = fitter_.vertex(tracks);
0052     } catch (std::exception &err) {
0053       std::cerr << ">>> exception thrown by KalmanVertexFitter:\n"
0054                 << err.what() << "\n"
0055                 << ">>> candidate not fitted to common vertex" << std::endl;
0056       return false;
0057     }
0058     return vertex.isValid();
0059   }
0060 
0061 private:
0062   Fitter fitter_;
0063 };
0064 
0065 #endif