Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

PulserGain.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PulserGain.cxx,v 1.7 2006/01/25 13:52:17 cpw1 Exp $
00003 //
00004 // PulserGain.cxx
00005 //
00006 // Dbi object for raw gain curve info
00007 //
00008 // Author: Phil Adamson 7/2003
00009 //
00010 // $Log: PulserGain.cxx,v $
00011 // Revision 1.7  2006/01/25 13:52:17  cpw1
00012 // Make methods ZCMean and ZCError const
00013 //
00014 //
00015 // Revision 1.6  2005/10/27 09:37:27  cpw1
00016 // Add methods ZCMean and ZCError
00017 //
00018 // Revision 1.5  2004/10/25 20:01:43  murgia
00019 // Initialize numPoints to zero. Set numPoint to expected number of points.
00020 //
00021 // Revision 1.4  2004/10/21 10:20:16  west
00022 // gcc 3.4: Replace DbiReader/DbiWriter.cxx -> .tpl and move after CVSID
00023 //
00024 // Revision 1.3  2004/10/05 21:39:48  murgia
00025 // Fixed code to write points with low light levels. Added call to EndFile.
00026 //
00027 // Revision 1.2  2004/09/17 16:58:38  phil.adamson
00028 // Try to fix aggregate number and stripend missing bugs
00029 //
00030 // Revision 1.1  2004/09/08 21:50:51  pa
00031 // Checkin of new PulserCalibration version. MIght even work
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 PulserGain::PulserGain(Int_t aggNo, Int_t seid, Float_t *mean, 
00071                              Float_t *error, Float_t *num_entries) :
00072   fAggregateNo(aggNo) , fStripEnd(seid) 
00073 {
00074   memset(fMean,0,40*sizeof(Float_t));
00075   memset(fError,0,40*sizeof(Float_t));
00076   memset(fNumEntries,0,40*sizeof(Float_t));
00077   memset(fNumTriggers,0,40*sizeof(Float_t));
00078   fFirstPoint = fLastPoint = 0;
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   //  if ((fFirstPoint!=0)&&(point!=(1+fLastPoint))) return false;
00099   // Some channels might be missing a point with low pulse height.
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   //  ++fNumPoints;
00109   fLastPoint = point;
00110   if (fFirstPoint==0) fFirstPoint = point;
00111 
00112   return true;
00113 }
00114  
00115 void PulserGain::Fill(DbiResultSet& rs,
00116                          const DbiValidityRec* /* vrec */)
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* /* vrec */) 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   // Allow Add() to add to either end of the curve.
00145  if (pg.GetFirstPoint()==1+fLastPoint) {
00146     // add to end
00147     fLastPoint = pg.GetLastPoint();
00148   }
00149   else if(pg.GetLastPoint()==fFirstPoint-1) {
00150     // add to start
00151     fFirstPoint = pg.GetFirstPoint();
00152   }
00153   else {
00154     // Fragments don't join up
00155     MSG("Pulser",Msg::kError) << "This should never happen!\n";
00156     return false;
00157     // This should never happen, though!
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     //    ++fNumPoints;
00166   }
00167   return true;
00168 }
00169 
00170 Float_t PulserGain::ZCMean(Int_t i) const {
00171   // Return zero-corrected mean for point i
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   // Return zero-corrected error for point i
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 }

Generated on Mon Feb 15 11:07:26 2010 for loon by  doxygen 1.3.9.1