00001 #ifndef RESPONSECURVE_H
00002 #define RESPONSECURVE_H
00003
00004 #include "Sct/Streamable.h"
00005 #include "Sct/Exception.h"
00006 #include "Sct/LogicErrors.h"
00007 #include <map>
00008 #include <TF1.h>
00009 #include <boost/utility.hpp>
00010 #include <boost/shared_ptr.hpp>
00011
00012 using std::map;
00013 using std::auto_ptr;
00014 using std::string;
00015
00016 using namespace Sct;
00017 using namespace boost;
00018
00019 namespace SctData {
00020 class ChipConfiguration;
00024 class ResponseCurve : public virtual Streamable {
00025 public:
00030 shared_ptr<TF1> getFunction() const throw() ;
00035 virtual shared_ptr<TF1> getInverseFunction() const throw(LogicError) = 0;
00037 const int getIndex() const throw();
00043 virtual double getGain(const double charge) const throw() = 0;
00048 virtual auto_ptr<ResponseCurve> create() const throw() = 0 ;
00050 virtual ~ResponseCurve() throw();
00052 ResponseCurve& operator=(const ResponseCurve&) throw();
00054 bool operator==(const ResponseCurve&)const throw();
00056 virtual string getClassName() const throw() {return "SctData::ResponseCurve";}
00058 virtual string getCurveName() const throw() {return "Unknown Response Curve";}
00059 private:
00060 ResponseCurve();
00061 shared_ptr<TF1> ptr_function;
00062 protected:
00063 mutable shared_ptr<TF1> ptr_inverse;
00065 ResponseCurve(auto_ptr<TF1>) throw(LogicError);
00066 };
00067
00069 class ResponseCurveMap : boost::noncopyable {
00070 public:
00072 bool addToMap(const string& curvename, const int index, ResponseCurve&) throw() ;
00074 static ResponseCurveMap& getMap() throw();
00078 auto_ptr<ResponseCurve> get(const string& curvename) const throw(LogicError);
00082 auto_ptr<ResponseCurve> get(const int index) const throw(LogicError);
00084 auto_ptr<ResponseCurve> get(const ChipConfiguration& chip) const throw(LogicError);
00088 int getIndex(const string& curvename) const throw(LogicError);
00089 private:
00090 map<int, ResponseCurve*> indexMap;
00091 map<string, int> nameMap;
00092 };
00093
00094
00099 class LinearResponseCurve : public ResponseCurve {
00100 public:
00101 LinearResponseCurve() throw(LogicError);
00102 virtual ~LinearResponseCurve() throw();
00103 virtual shared_ptr<TF1> getInverseFunction() const throw(LogicError);
00104 virtual double getGain(const double charge) const throw();
00105 virtual string getCurveName() const throw() {return "LinearResponseCurve";}
00106 virtual auto_ptr<ResponseCurve> create() const throw();
00107 static bool inMap;
00108
00109 static double linFn(double *x, double *par) throw();
00111 static double invLinFn(double *x, double *par) throw();
00112 int m_deb;
00113 };
00114
00119 class ExponentialResponseCurve : public ResponseCurve {
00120 public:
00121 ExponentialResponseCurve() throw(LogicError);
00122 virtual ~ExponentialResponseCurve() throw(){;}
00123 virtual shared_ptr<TF1> getInverseFunction() const throw(LogicError);
00124 virtual double getGain(const double charge) const throw();
00125 virtual string getCurveName() const throw() {return "ExponentialResponseCurve";}
00126 virtual auto_ptr<ResponseCurve> create() const throw() ;
00127
00129 static double expFn(double *x, double *par) throw();
00131 static double invExpFn(double *x, double *par) throw();
00132
00133 static bool inMap;
00134 };
00135
00136
00141 class GrilloResponseCurve : public ResponseCurve {
00142 public:
00143 GrilloResponseCurve() throw(LogicError);
00144 virtual ~GrilloResponseCurve() throw() {;}
00145 virtual shared_ptr<TF1> getInverseFunction() const throw(LogicError);
00146 virtual double getGain(const double charge) const throw() ;
00147 virtual string getCurveName() const throw() {return "GrilloResponseCurve";}
00148 virtual auto_ptr<ResponseCurve> create() const throw() ;
00149 static bool inMap;
00150
00151 static double grilloFn(double *x, double *par) throw();
00153 static double invGrilloFn(double *x, double *par) throw();
00154 };
00155
00159 class QuadraticResponseCurve : public ResponseCurve {
00160 public:
00161 QuadraticResponseCurve() throw(LogicError);
00162 virtual ~QuadraticResponseCurve() throw() {;}
00163 virtual shared_ptr<TF1> getInverseFunction() const throw(LogicError);
00164 virtual double getGain(const double charge) const throw();
00165 virtual string getCurveName() const throw() {return "QuadraticResponseCurve";}
00166 virtual auto_ptr<ResponseCurve> create() const throw();
00167 static bool inMap;
00168
00169 static double quadFn(double *x, double *par) throw();
00171 static double invQuadFn(double *x, double *par) throw();
00172 };
00173
00174
00175 inline shared_ptr<TF1> ResponseCurve::getFunction() const throw() {
00176 return ptr_function;
00177 }
00178
00179 inline const int ResponseCurve::getIndex() const throw() {
00180 return ResponseCurveMap::getMap().getIndex(this->getCurveName());
00181 }
00182 }
00183
00184 #endif //#ifndef RESPONSECURVE_H