Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:15:33

0001 #ifndef HeavyFlavorAnalysis_RecoDecay_BPHKinematicFit_h
0002 #define HeavyFlavorAnalysis_RecoDecay_BPHKinematicFit_h
0003 /** \class BPHKinematicFit
0004  *
0005  *  Description: 
0006  *     Highest-level base class to encapsulate kinematic fit operations
0007  *
0008  *  \author Paolo Ronchese INFN Padova
0009  *     high-level base class to perform a kinematic fit
0010  */
0011 
0012 //----------------------
0013 // Base Class Headers --
0014 //----------------------
0015 #include "HeavyFlavorAnalysis/RecoDecay/interface/BPHDecayVertex.h"
0016 
0017 //------------------------------------
0018 // Collaborating Class Declarations --
0019 //------------------------------------
0020 #include "RecoVertex/KinematicFitPrimitives/interface/RefCountedKinematicParticle.h"
0021 #include "RecoVertex/KinematicFitPrimitives/interface/RefCountedKinematicTree.h"
0022 
0023 class MultiTrackKinematicConstraint;
0024 class KinematicConstraint;
0025 
0026 //---------------
0027 // C++ Headers --
0028 //---------------
0029 #include <string>
0030 #include <vector>
0031 #include <map>
0032 #include <set>
0033 
0034 //              ---------------------
0035 //              -- Class Interface --
0036 //              ---------------------
0037 
0038 class BPHKinematicFit : public virtual BPHDecayVertex {
0039 public:
0040   /** Constructors are protected
0041    *  this object can exist only as part of a derived class
0042    */
0043   // deleted copy constructor and assignment operator
0044   BPHKinematicFit(const BPHKinematicFit& x) = delete;
0045   BPHKinematicFit& operator=(const BPHKinematicFit& x) = delete;
0046 
0047   /** Destructor
0048    */
0049   ~BPHKinematicFit() override = default;
0050 
0051   /** Operations
0052    */
0053 
0054   /// apply a mass constraint
0055   void setConstraint(double mass, double sigma);
0056   /// retrieve the constraint
0057   double constrMass() const;
0058   double constrSigma() const;
0059   /// set a decaying daughter as an unique particle fitted independently
0060   void setIndependentFit(const std::string& name, bool flag = true, double mass = -1.0, double sigma = -1.0);
0061 
0062   /// get kinematic particles
0063   virtual const std::vector<RefCountedKinematicParticle>& kinParticles() const;
0064   virtual std::vector<RefCountedKinematicParticle> kinParticles(const std::vector<std::string>& names) const;
0065 
0066   /// perform the kinematic fit and get the result
0067   virtual const RefCountedKinematicTree& kinematicTree() const;
0068   virtual const RefCountedKinematicTree& kinematicTree(const std::string& name, double mass, double sigma) const;
0069   virtual const RefCountedKinematicTree& kinematicTree(const std::string& name, double mass) const;
0070   virtual const RefCountedKinematicTree& kinematicTree(const std::string& name) const;
0071   virtual const RefCountedKinematicTree& kinematicTree(const std::string& name, KinematicConstraint* kc) const;
0072   virtual const RefCountedKinematicTree& kinematicTree(const std::string& name,
0073                                                        MultiTrackKinematicConstraint* kc) const;
0074 
0075   /// reset the kinematic fit
0076   virtual void resetKinematicFit() const;
0077 
0078   /// get fit status
0079   virtual bool isEmpty() const;
0080   virtual bool isValidFit() const;
0081 
0082   /// get current particle
0083   virtual const RefCountedKinematicParticle currentParticle() const;
0084   virtual const RefCountedKinematicVertex currentDecayVertex() const;
0085 
0086   /// get top particle
0087   virtual const RefCountedKinematicParticle topParticle() const;
0088   virtual const RefCountedKinematicVertex topDecayVertex() const;
0089   virtual ParticleMass mass() const;
0090 
0091   /// compute total momentum after the fit
0092   virtual const math::XYZTLorentzVector& p4() const;
0093 
0094   /// retrieve particle mass sigma
0095   double getMassSigma(const reco::Candidate* cand) const;
0096 
0097   /// retrieve independent fit flag
0098   bool getIndependentFit(const std::string& name, double& mass, double& sigma) const;
0099 
0100 protected:
0101   // constructors
0102   BPHKinematicFit(int daugNum = 2, int compNum = 2);
0103   // pointer used to retrieve informations from other bases
0104   BPHKinematicFit(const BPHKinematicFit* ptr);
0105 
0106   // add a simple particle giving it a name
0107   // particles are cloned, eventually specifying a different mass
0108   // and a sigma
0109   virtual void addK(const std::string& name, const reco::Candidate* daug, double mass = -1.0, double sigma = -1.0);
0110   // add a simple particle and specify a criterion to search for
0111   // the associated track
0112   virtual void addK(const std::string& name,
0113                     const reco::Candidate* daug,
0114                     const std::string& searchList,
0115                     double mass = -1.0,
0116                     double sigma = -1.0);
0117   // add a previously reconstructed particle giving it a name
0118   virtual void addK(const std::string& name, const BPHRecoConstCandPtr& comp);
0119 
0120   // utility function used to cash reconstruction results
0121   void setNotUpdated() const override;
0122 
0123 private:
0124   // mass constraint
0125   double massConst;
0126   double massSigma;
0127 
0128   // map linking daughters to mass sigma
0129   std::map<const reco::Candidate*, double> dMSig;
0130 
0131   // map to handle composite daughters as single particles
0132   struct FlyingParticle {
0133     bool flag = false;
0134     double mass = -1.0;
0135     double sigma = -1.0;
0136   };
0137   std::map<const BPHRecoCandidate*, FlyingParticle> cKinP;
0138 
0139   // temporary particle set
0140   mutable std::vector<BPHRecoConstCandPtr> tmpList;
0141 
0142   // reconstruction results cache
0143   mutable bool oldKPs;
0144   mutable bool oldFit;
0145   mutable bool oldMom;
0146   mutable std::map<const reco::Candidate*, RefCountedKinematicParticle> kinMap;
0147   mutable std::map<const BPHRecoCandidate*, RefCountedKinematicParticle> kCDMap;
0148   mutable std::vector<RefCountedKinematicParticle> allParticles;
0149   mutable RefCountedKinematicTree kinTree;
0150   mutable math::XYZTLorentzVector totalMomentum;
0151 
0152   // build kin particles, perform the fit and compute the total momentum
0153   virtual void buildParticles() const;
0154   virtual void addParticles(std::vector<RefCountedKinematicParticle>& kl,
0155                             std::map<const reco::Candidate*, RefCountedKinematicParticle>& km,
0156                             std::map<const BPHRecoCandidate*, RefCountedKinematicParticle>& cm) const;
0157   virtual void getParticles(const std::string& moth,
0158                             const std::string& daug,
0159                             std::vector<RefCountedKinematicParticle>& kl,
0160                             std::set<RefCountedKinematicParticle>& ks,
0161                             const BPHKinematicFit* curr) const;
0162   virtual void getParticles(const std::string& moth,
0163                             const std::vector<std::string>& daug,
0164                             std::vector<RefCountedKinematicParticle>& kl,
0165                             std::set<RefCountedKinematicParticle>& ks,
0166                             const BPHKinematicFit* curr) const;
0167   virtual unsigned int numParticles(const BPHKinematicFit* cand = nullptr) const;
0168   static void insertParticle(RefCountedKinematicParticle& kp,
0169                              std::vector<RefCountedKinematicParticle>& kl,
0170                              std::set<RefCountedKinematicParticle>& ks);
0171   virtual const BPHKinematicFit* splitKP(const std::string& name,
0172                                          std::vector<RefCountedKinematicParticle>* kComp,
0173                                          std::vector<RefCountedKinematicParticle>* kTail = nullptr) const;
0174   virtual const RefCountedKinematicTree& kinematicTree(const std::vector<RefCountedKinematicParticle>& kPart,
0175                                                        MultiTrackKinematicConstraint* kc) const;
0176   virtual void fitMomentum() const;
0177 };
0178 
0179 #endif