00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00025
00026 #include "MessageService/MsgService.h"
00027 #include "PulserCalibration/PulserPinScale.h"
00028 #include "DatabaseInterface/DbiResultSet.h"
00029 #include "DatabaseInterface/DbiValidityRec.h"
00030 #include "TGraphErrors.h"
00031 #include "TF1.h"
00032
00033
00034 ClassImp(PulserPinScale)
00035
00036
00037
00038 CVSID("$Id: PulserPinScale.cxx,v 1.4 2004/11/15 13:03:07 west Exp $");
00039
00040 #include "DatabaseInterface/DbiResultPtr.tpl"
00041 template class DbiResultPtr<PulserPinScale>;
00042 #include "DatabaseInterface/DbiWriter.tpl"
00043 template class DbiWriter<PulserPinScale>;
00044
00045
00046 PulserPinScale::PulserPinScale() {}
00047 PulserPinScale::~PulserPinScale() {}
00048
00049 PulserPinScale::PulserPinScale(PulserGainPin &high, PulserGainPin &low,
00050 int aggNo)
00051 {
00052 fAggregateNo = aggNo;
00053
00054 assert(high.GetNumPoints()==low.GetNumPoints());
00055 const Float_t *x_high=high.GetMean();
00056 const Float_t *ex_high=high.GetError();
00057 const Float_t *y_low = low.GetMean();
00058 const Float_t *ey_low = low.GetError();
00059
00060 TGraphErrors g(high.GetNumPoints(),x_high,y_low,ex_high,ey_low);
00061 float xmin=300;
00062 float xmax = 8000;
00063
00064 for (int i=0;i<high.GetNumPoints();i++) {
00065 if (y_low[i] < 300 && x_high[i]>300) xmin =x_high[i]+1;
00066 if (y_low[i] > 8000 && x_high[i] < 8000) {
00067 xmax = x_high[i]-1;
00068 break;
00069 }
00070 }
00071
00072 TF1 f("line","[0]*x",xmin,xmax);
00073 g.Fit("line","QR");
00074 MSG("Pulser",Msg::kDebug)<<"Aggregate "<<aggNo<<" fit slope "<<f.GetParameter(0)<<endl;
00075
00076 fHighGainScale = 1;
00077 fLowGainScale = 1.0/f.GetParameter(0);
00078
00079 }
00080
00081
00082 PulserPinScale::PulserPinScale(float high, float low, int aggNo)
00083 {
00084 fHighGainScale = high;
00085 fLowGainScale = low;
00086 fAggregateNo = aggNo;
00087 }
00088
00089 void PulserPinScale::Fill(DbiResultSet& rs,
00090 const DbiValidityRec* )
00091 {
00092 rs >> fAggregateNo >> fHighGainScale >> fLowGainScale;
00093
00094 }
00095
00096 void PulserPinScale::Store(DbiOutRowStream& ors,
00097 const DbiValidityRec* ) const
00098 {
00099 ors << fAggregateNo
00100 << fHighGainScale
00101 << fLowGainScale;
00102 }
00103
00104
00105 Float_t PulserPinScale::ScalePins(Float_t high, Float_t low) const
00106 {
00107 if (fHighGainScale<=0||high<0) {
00108 return fLowGainScale*low;
00109 }
00110 if (fLowGainScale<=0||low<0) {
00111 return fHighGainScale*high;
00112 }
00113 if (high>8000) {
00114 return fLowGainScale*low;
00115 }
00116 if (low<500 || low > 8000) {
00117 return fHighGainScale*high;
00118 }
00119 if (high< 500) {
00120 return fLowGainScale*low;
00121 }
00122 return 0.5*(fLowGainScale*low + fHighGainScale*high);
00123
00124 }