Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-05 08:18:21

0001 /* Copyright 2008-2010, Technische Universitaet Muenchen,
0002    Authors: Christian Hoeppner & Sebastian Neubert & Johannes Rauch & Tobias Schlüter
0003 
0004    This file is part of GENFIT.
0005 
0006    GENFIT is free software: you can redistribute it and/or modify
0007    it under the terms of the GNU Lesser General Public License as published
0008    by the Free Software Foundation, either version 3 of the License, or
0009    (at your option) any later version.
0010 
0011    GENFIT is distributed in the hope that it will be useful,
0012    but WITHOUT ANY WARRANTY; without even the implied warranty of
0013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014    GNU Lesser General Public License for more details.
0015 
0016    You should have received a copy of the GNU Lesser General Public License
0017    along with GENFIT.  If not, see <http://www.gnu.org/licenses/>.
0018 */
0019 /** @addtogroup genfit
0020  * @{
0021  */
0022 
0023 #ifndef genfit_FitStatus_h
0024 #define genfit_FitStatus_h
0025 
0026 #include <Rtypes.h>
0027 #include <Math/ProbFuncMathCore.h>
0028 
0029 
0030 namespace genfit {
0031 
0032 
0033 /**
0034  * @brief Info which information has been pruned from the Track.
0035  *
0036  * Possible options:
0037    * C:  prune all reps except cardinalRep
0038    * F:  prune all points except first point (also prune referenceInfo from fitterInfos)
0039    * L:  prune all points except last point (also prune referenceInfo from fitterInfos)
0040    * FL: prune all points except first and last point (also prune referenceInfo from fitterInfos)
0041    * W:  prune rawMeasurements from TrackPoints
0042    * R:  prune referenceInfo from fitterInfos
0043    * M:  prune measurementInfo from fitterInfos
0044    * I:  if F, L, or FL is set, prune forward (backward) info of first (last) point
0045    * U:  if fitterInfo is a KalmanFitterInfo, prune predictions and keep updates
0046  */
0047 struct PruneFlags {
0048   PruneFlags();
0049   void reset();
0050   //! does not reset! If a flag is already true and is not in opt, it will stay true.
0051   void setFlags(Option_t* option = "");
0052   //! check if all the given flags are set
0053   bool hasFlags(Option_t* option = "CFLWRMIU") const;
0054   //! check if any of the flags is set
0055   bool isPruned() const;
0056 
0057   void Print(const Option_t* = "") const;
0058 
0059 private:
0060   enum fields { C = 1 << 0,
0061         F = 1 << 1,
0062         L = 1 << 2,
0063         W = 1 << 3,
0064         R = 1 << 4,
0065         M = 1 << 5,
0066         I = 1 << 6,
0067         U = 1 << 7 };
0068 
0069   int value; // bitfield composed from above.  ROOT cannot deal with
0070          // bitfield notation, so this is done manually.
0071 
0072   // No ClassDef here.  Update FitStatus version number when changing this.
0073 };
0074 
0075 
0076 /** @brief Class where important numbers and properties of a fit can be stored.
0077  *
0078  *  @author Johannes Rauch (Technische Universit&auml;t M&uuml;nchen, original author)
0079  */
0080 class FitStatus {
0081 
0082  public:
0083 
0084   FitStatus() :
0085     isFitted_(false), isFitConvergedFully_(false), isFitConvergedPartially_(false), nFailedPoints_(0),
0086     trackHasChanged_(false), pruneFlags_(), charge_(0), chi2_(-1e99), ndf_(-1e99)
0087   {;}
0088 
0089   virtual ~FitStatus() {};
0090 
0091   virtual FitStatus* clone() const {return new FitStatus(*this);}
0092 
0093   //! Has the track been fitted?
0094   bool isFitted() const {return isFitted_;}
0095   //! Did the fit converge (in all Points or only partially)?
0096   /**
0097    * Per default, this function will only be true, if all TrackPoints
0098    * (with measurements) have been used in the fit, and the fit has converged.
0099    *
0100    * If one or more TrackPoints have been skipped
0101    * (e.g. plane could not be constructed or extrapolation to plane failed),
0102    * but the fit otherwise met the convergence criteria, isFitConverged(false)
0103    * will return true.
0104    */
0105   bool isFitConverged(bool inAllPoints = true) const {
0106     if (inAllPoints)
0107         return isFitConvergedFully_;
0108     return isFitConvergedPartially_;
0109   }
0110   bool isFitConvergedFully() const {return isFitConvergedFully_;}
0111   bool isFitConvergedPartially() const {return isFitConvergedPartially_;}
0112   int getNFailedPoints() const {return nFailedPoints_;}
0113   //! Has anything in the Track been changed since the fit?
0114   bool hasTrackChanged() const {return trackHasChanged_;}
0115   //! Has the track been pruned after the fit?
0116   bool isTrackPruned() const {return pruneFlags_.isPruned();}
0117   //! Get the fitted charge.
0118   double getCharge() const {return charge_;}
0119   //! Get chi^2 of the fit.
0120   double getChi2() const {return chi2_;}
0121   //! Get the degrees of freedom of the fit.
0122   double getNdf() const {return ndf_;}
0123   /**
0124    * @brief Get the p value of the fit.
0125    *
0126    * Virtual, because the fitter may use a different probability distribution.
0127    */
0128   virtual double getPVal() const {return std::max(0.,ROOT::Math::chisquared_cdf_c(chi2_, ndf_));}
0129 
0130   void setIsFitted(bool fitted = true) {isFitted_ = fitted;}
0131   void setIsFitConvergedFully(bool fitConverged = true) {isFitConvergedFully_ = fitConverged;}
0132   void setIsFitConvergedPartially(bool fitConverged = true) {isFitConvergedPartially_ = fitConverged;}
0133   void setNFailedPoints(int nFailedPoints) {nFailedPoints_ = nFailedPoints;}
0134   void setHasTrackChanged(bool trackChanged = true) {trackHasChanged_ = trackChanged;}
0135   void setCharge(double charge) {charge_ = charge;}
0136 
0137   PruneFlags& getPruneFlags() {return pruneFlags_;}
0138 
0139   void setChi2(const double& chi2) {chi2_ = chi2;}
0140   void setNdf(const double& ndf) {ndf_ = ndf;}
0141 
0142   virtual void Print(const Option_t* = "") const;
0143 
0144  protected:
0145 
0146   //! has the track been fitted?
0147   bool isFitted_;
0148   //! did the fit converge with all TrackPoints?
0149   bool isFitConvergedFully_;
0150   //! did the fit converge with a subset of all TrackPoints?
0151   bool isFitConvergedPartially_;
0152   //! Number of failed TrackPoints
0153   int nFailedPoints_;
0154   //! has anything in the Track been changed since the fit? -> fit isn't valid anymore
0155   bool trackHasChanged_;
0156   //! Prune flags
0157   PruneFlags pruneFlags_;
0158   //! fitted charge
0159   double charge_;
0160 
0161   //! These are provided for the sake of the fitter, and their interpretation may vary.
0162   //! For the Kalman-derived fitters in particular, this corresponds to the backwards fit.
0163   double chi2_;
0164   double ndf_;
0165 
0166   ClassDef(FitStatus, 3);
0167 };
0168 
0169 } /* End of namespace genfit */
0170 /** @} */
0171 
0172 #endif // genfit_FitStatus_h