00001 //-------------------------------------------------------------------------- 00002 // File and Version Information: 00003 // $Id: Consistency.h,v 1.1.1.1 2005/04/21 01:17:17 zhangy Exp $ 00004 // 00005 // Description: 00006 // The Consistency class is a top level parent for various 00007 // statistical classes 00008 // 00009 // This class also defines an enum ConsistentStatus for representing 00010 // various error conditions 00011 // 00012 // Return an object of this class from a chisquared calculation, for 00013 // example, so that probability and chisquared can be treated 00014 // directly. Future subclasses might implement other statistics 00015 // (Poisson, etc), and this class could use operations to combine, 00016 // print, etc. (Or other statistics could be added to this class, 00017 // allowing it to convert between different measures; the uses 00018 // will dictate the structure) 00019 // 00020 // Note: implementation of this class is minimal at present; please 00021 // read the comments! 00022 // 00023 // Environment: 00024 // Software developed for the BaBar Detector at the SLAC B-Factory. 00025 // 00026 // Author List: 00027 // Bob Jacobsen 00028 // 00029 // History : 00030 // April 98 - Gautier Hamel de Monchenault 00031 // o introduce genealogy methods 00032 // o add significanceLevel() accessor which returns _value 00033 // o comment out the automatic translation to double 00034 // o add 'const' to operators == and < 00035 // 00036 // 00037 // Copyright Information: 00038 // Copyright (C) 1995, 1996 00039 // 00040 //------------------------------------------------------------------------ 00041 #ifndef CONSISTENCY_HH 00042 #define CONSISTENCY_HH 00043 00044 //#include "BaBar/BaBar.hh" 00045 00046 #include <iosfwd> 00047 class ConsistencySet; 00048 00049 //----------------- 00050 // BaBar Headers -- 00051 //----------------- 00052 00053 class Consistency { 00054 00055 public: 00056 00057 // default constructor; sets internal state to noMeasure and value to zero 00058 Consistency(); 00059 00060 // default value for likelihood is for backward compatibility 00061 Consistency( double consistency, double likelihood=0.); 00062 00063 // copy constructor 00064 Consistency(const Consistency& rhs); 00065 00066 virtual ~Consistency() {} 00067 00068 // assignment 00069 Consistency& operator= (const Consistency& rhs); 00070 00071 // equality -- this will never work right since one has to compare 00072 // two doubles. But RW sometimes requires this. 00073 bool operator==(const Consistency& rhs) const; 00074 // less operator is better in that regard, but it's not unique 00075 bool operator < (const Consistency& rhs) const; 00076 // greater than operator 00077 bool operator > (const Consistency& rhs) const; 00078 00079 // members for returning 00080 // the statistical significance level 00081 // and the likelihood 00082 // of the represented observation; 00083 // subclasses are responsible 00084 // for keeping the data member up to date 00085 double significanceLevel() const { return _value; } 00086 double likelihood() const { return _likelihood;} 00087 00088 // Old function kept in the interface for back compatibility. 00089 // Avoid to use it - use significanceLevel() instead. 00090 // Will disappear eventually 00091 double consistency() const { return _value; } 00092 00093 // represent the various ways that a statistical measure could be bad 00094 enum ConsistentStatus { OK=0, noMeasure, underFlow, unPhysical }; 00095 00096 // OK just that; usable statistical data 00097 // noMeasure no statistical statement possible; DOF == 0, for example. 00098 // may or may not be consistent 00099 // underFlow probability too small to calculate with; may or may not want 00100 // to treat as zero, but value may have been treated by machine 00101 // underflow handling 00102 // unPhysical because of a "can't happen" condition, probability is 00103 // identically equal to zero; 00104 00105 // return the status 00106 ConsistentStatus status() const {return _stat;} 00107 void setStatus(ConsistentStatus s ) { _stat = s; } 00108 00109 // represent whether the measured value was "left" or "right" of 00110 // the expected. This is generally only useful if there is more 00111 // than one provider of consistencies in a given situation (e.g. 00112 // multiple systems doing PID), and they have a convention for 00113 // what these mean 00114 enum ConsistentSign { left=-1, unknown=0, right=1 }; 00115 00116 // return the sign 00117 ConsistentSign sign() const {return _sign; } 00118 void setSign(ConsistentSign s ) { _sign = s; } 00119 00120 // use as a double returns the consistency value; this member is 00121 // intended as just a convenience, and may be removed if it makes 00122 // trouble. 00123 00124 // genealogy 00125 virtual const ConsistencySet* genealogy() const; 00126 00127 // print 00128 virtual void print(std::ostream& ) const; 00129 00130 protected: 00131 00132 ConsistentStatus _stat; 00133 ConsistentSign _sign; 00134 double _value; // value of the consistency 00135 double _likelihood; // value of the likelihood 00136 00137 //------------------ 00138 // Static methods -- 00139 //------------------ 00140 00141 public: 00142 static const Consistency& badMeasurement(); 00143 00144 }; 00145 00146 #endif 00147 00148 00149 00150