00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00035
00036 #include "PulserCalibration/PulserGain.h"
00037 #include "MessageService/MsgService.h"
00038 #include "DatabaseInterface/DbiResultSet.h"
00039 #include "DatabaseInterface/DbiValidityRec.h"
00040 #include <cstring>
00041 #include "Plex/PlexStripEndId.h"
00042 ClassImp(PulserGain)
00043
00044 CVSID("$Id: PulserGain.cxx,v 1.7 2006/01/25 13:52:17 cpw1 Exp $");
00045
00046
00047
00048 #include "DatabaseInterface/DbiResultPtr.tpl"
00049 template class DbiResultPtr<PulserGain>;
00050 #include "DatabaseInterface/DbiWriter.tpl"
00051 template class DbiWriter<PulserGain>;
00052
00053
00054 PulserGain::PulserGain()
00055 {
00056 fAggregateNo = -1;
00057 fStripEnd = -1;
00058 for (int i=0;i<40;i++) {
00059 fMean[i] = -1;
00060 fError[i] = -1;
00061 fNumEntries[i] = -1;
00062 fNumTriggers[i] = -1;
00063 }
00064 fFirstPoint = fLastPoint = 0;
00065 fNumPoints = 0;
00066
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 void PulserGain::New(Int_t aggNo, Int_t points, Int_t stripEndKey)
00084 {
00085 fAggregateNo = aggNo;
00086 fStripEnd = stripEndKey;
00087 fNumPoints =points;
00088 memset(fMean,0,40*sizeof(Float_t));
00089 memset(fError,0,40*sizeof(Float_t));
00090 memset(fNumEntries,0,40*sizeof(Float_t));
00091 memset(fNumTriggers,0,40*sizeof(Float_t));
00092 fFirstPoint = fLastPoint = 0;
00093 }
00094
00095 bool PulserGain::AddPoint(Int_t point, const PulserSummary &ps,int aggNo,int expectedPoints)
00096 {
00097
00098
00099
00100 if (!(point>fLastPoint)) return false;
00101 fStripEnd = ps.GetStripEndId().BuildPlnStripEndKey();
00102 fAggregateNo = aggNo;
00103 fMean[point-1] = ps.GetMean();
00104 fError[point-1] =ps.GetError();
00105 fNumEntries[point-1] = ps.GetEntries();
00106 fNumTriggers[point-1] = ps.GetTriggers();
00107 fNumPoints = expectedPoints;
00108
00109 fLastPoint = point;
00110 if (fFirstPoint==0) fFirstPoint = point;
00111
00112 return true;
00113 }
00114
00115 void PulserGain::Fill(DbiResultSet& rs,
00116 const DbiValidityRec* )
00117 {
00118 rs >> fAggregateNo >> fStripEnd >> fNumPoints >> fFirstPoint >> fLastPoint;
00119 for (int i=0;i<40;i++) rs >> fMean[i];
00120 for (int i=0;i<40;i++) rs >> fError[i];
00121 for (int i=0;i<40;i++) rs >> fNumEntries[i];
00122 for (int i=0;i<40;i++) rs >> fNumTriggers[i];
00123 }
00124
00125 void PulserGain::Store(DbiOutRowStream& ors,
00126 const DbiValidityRec* ) const
00127 {
00128 ors << fAggregateNo << fStripEnd << fNumPoints << fFirstPoint << fLastPoint;
00129 for (int i=0;i<40;i++) ors << fMean[i];
00130 for (int i=0;i<40;i++) ors << fError[i];
00131 for (int i=0;i<40;i++) ors << fNumEntries[i];
00132 for (int i=0;i<40;i++) ors << fNumTriggers[i];
00133
00134 }
00135
00136 bool PulserGain::Add(const PulserGain &pg)
00137 {
00138 assert(pg.GetAggregateNo()==fAggregateNo);
00139 const float * mean = pg.GetMean();
00140 const float * error = pg.GetError();
00141 const float * numentries = pg.GetNumEntries();
00142 const float * numtriggers = pg.GetNumTriggers();
00143
00144
00145 if (pg.GetFirstPoint()==1+fLastPoint) {
00146
00147 fLastPoint = pg.GetLastPoint();
00148 }
00149 else if(pg.GetLastPoint()==fFirstPoint-1) {
00150
00151 fFirstPoint = pg.GetFirstPoint();
00152 }
00153 else {
00154
00155 MSG("Pulser",Msg::kError) << "This should never happen!\n";
00156 return false;
00157
00158 }
00159 for (int i=pg.GetFirstPoint();i<=pg.GetLastPoint();i++) {
00160 fMean[i-1] = mean[i-1];
00161 fError[i-1] = error[i-1];
00162 fNumEntries[i-1] = numentries[i-1];
00163 fNumTriggers[i-1] = numtriggers[i-1];
00164 fNumPoints = pg.GetNumPoints();
00165
00166 }
00167 return true;
00168 }
00169
00170 Float_t PulserGain::ZCMean(Int_t i) const {
00171
00172 Float_t zcmean = fMean[i] * fNumEntries[i] / fNumTriggers[i];
00173 return zcmean;
00174 }
00175
00176 Float_t PulserGain::ZCError(Int_t i) const {
00177
00178 Float_t zcerr = fNumEntries[i]*fError[i]*fError[i];
00179 zcerr+= (1.-fNumEntries[i]/fNumTriggers[i])*fMean[i]*fMean[i];
00180 zcerr = sqrt(fNumEntries[i]*zcerr)/fNumTriggers[i];
00181 return zcerr;
00182 }