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

PulserGainPin.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PulserGainPin.cxx,v 1.8 2006/04/19 20:00:55 rhatcher Exp $
00003 //
00004 // PulserGainPin.cxx
00005 //
00006 // Dbi object for raw gain curve info
00007 //
00008 // Author: Phil Adamson 7/2003
00009 //
00010 // $Log: PulserGainPin.cxx,v $
00011 // Revision 1.8  2006/04/19 20:00:55  rhatcher
00012 // convert DetectorType:: to Detector:: everywhere.
00013 //
00014 // Revision 1.7  2005/10/27 09:37:38  cpw1
00015 // Add methods ZCMean and ZCError
00016 //
00017 // Revision 1.6  2004/10/25 20:04:21  murgia
00018 // Initialize numPoints to zero. Set numPoints equal to expected number of points.
00019 //
00020 // Revision 1.5  2004/10/21 10:20:16  west
00021 // gcc 3.4: Replace DbiReader/DbiWriter.cxx -> .tpl and move after CVSID
00022 //
00023 // Revision 1.4  2004/10/05 21:39:48  murgia
00024 // Fixed code to write points with low light levels. Added call to EndFile.
00025 //
00026 // Revision 1.3  2004/09/17 16:58:38  phil.adamson
00027 // Try to fix aggregate number and stripend missing bugs
00028 //
00029 // Revision 1.2  2004/09/14 22:01:47  phil.adamson
00030 //
00031 //
00032 // A couple of minor fixes
00033 //
00034 // Revision 1.1  2004/09/08 21:50:51  pa
00035 // Checkin of new PulserCalibration version. MIght even work
00036 //
00037 //
00039 
00040 #include "PulserCalibration/PulserGainPin.h"
00041 #include "MessageService/MsgService.h"
00042 #include "DatabaseInterface/DbiResultSet.h"
00043 #include "DatabaseInterface/DbiValidityRec.h"
00044 #include <cstring>
00045 #include "Plex/PlexStripEndId.h"
00046 ClassImp(PulserGainPin)
00047 
00048 CVSID("$Id: PulserGainPin.cxx,v 1.8 2006/04/19 20:00:55 rhatcher Exp $");
00049 
00050   //........
00051   
00052 #include "DatabaseInterface/DbiResultPtr.tpl"
00053   template class DbiResultPtr<PulserGainPin>;
00054 #include "DatabaseInterface/DbiWriter.tpl"
00055   template class DbiWriter<PulserGainPin>;
00056 
00057 PulserGainPin::PulserGainPin()
00058 {
00059   fAggregateNo = -1;
00060   for (int i=0;i<40;i++) {
00061      fMean[i] = -1;
00062      fError[i] = -1;
00063      fNumEntries[i] = -1;
00064      fNumTriggers[i] = -1;
00065   }
00066   fFirstPoint = fLastPoint = 0;
00067   fNumPoints = 0;
00068 }
00069 
00070 /*
00071 PulserGainPin::PulserGainPin(Int_t aggNo, Int_t seid, Float_t *mean, 
00072                              Float_t *error, Float_t *num_entries) :
00073   fAggregateNo(aggNo) , fStripEnd(seid) 
00074 {
00075   memset(fMean,0,40*sizeof(Float_t));
00076   memset(fError,0,40*sizeof(Float_t));
00077   memset(fNumEntries,0,40*sizeof(Float_t));
00078   memset(fNumTriggers,0,40*sizeof(Float_t));
00079   fFirstPoint = fLastPoint = 0;
00080   
00081 }
00082 */
00083 
00084  
00085 bool PulserGainPin::AddPoint(Int_t point, const PulserSummary &ps, int aggNo, int expectedPoints)
00086 {
00087     MSG("Pulser",Msg::kDebug)<<"In GainPin Add(psl). Aggregate Number: " << aggNo << endl; 
00088     MSG("Pulser",Msg::kDebug)<<"In GainPin Add(psl). fFirst, fLast, fIdent: " << fFirstPoint << ", " << fLastPoint << endl;
00089 
00090     //  if ((fFirstPoint!=0)&&(point!=(1+fLastPoint))) return false;
00091   // Some channels might be missing a point with low pulse height.
00092   if (!(point>fLastPoint)) return false;
00093   fPlexPinDiodeId = ps.GetPinDiodeId();
00094   fAggregateNo = aggNo;
00095   fMean[point-1] = ps.GetMean();
00096   fError[point-1] =ps.GetError();
00097   fNumEntries[point-1] = ps.GetEntries();
00098   fNumTriggers[point-1] = ps.GetTriggers();
00099   fNumPoints = expectedPoints;
00100 //  ++fNumPoints;
00101   fLastPoint = point;
00102   if (fFirstPoint==0) fFirstPoint = point;
00103     MSG("Pulser",Msg::kDebug)<<"In GainPin Add(psl). Aggregate Number: " << aggNo << endl; 
00104     MSG("Pulser",Msg::kDebug)<<"In GainPin Add(psl). fFirst, fLast, fIdent: " << fFirstPoint << ", " << fLastPoint << endl;
00105 
00106   return true;
00107 }
00108  
00109 void PulserGainPin::Fill(DbiResultSet& rs,
00110                          const DbiValidityRec*  vrec )
00111 {
00112  Detector::Detector_t det =
00113     (Detector::Detector_t) 
00114     ((vrec) ? vrec->GetVldRange().GetDetectorMask() : 0);
00115   
00116   string elecName="Unknown";
00117   char   elecType = ElecType::kUnknown;
00118   char   rackEastWest='?', rackLevel='?';
00119   int    rackBay=0, muxboxInRack=0;
00120   int    diodeinbox=0, gain=0;
00121 
00122   rs >> fAggregateNo  
00123      >> elecName
00124      >> rackEastWest
00125      >> rackLevel
00126      >> rackBay
00127      >> muxboxInRack
00128      >> diodeinbox
00129      >> gain
00130      >> fNumPoints >> fFirstPoint >> fLastPoint;
00131   for (int i=0;i<40;i++) rs >> fMean[i];
00132   for (int i=0;i<40;i++) rs >> fError[i];
00133   for (int i=0;i<40;i++) rs >> fNumEntries[i];
00134   for (int i=0;i<40;i++) rs >> fNumTriggers[i];
00135 
00136  ElecType::Elec_t elec = ElecType::StringToEnum(elecName.c_str(),1);
00137   if (ElecType::kUnknown == elec)  elec = (ElecType::Elec_t) elecType;
00138   
00139   fPlexPinDiodeId = PlexPinDiodeId(det,elec,rackEastWest,rackLevel,
00140                                    rackBay,muxboxInRack,diodeinbox,gain);
00141 
00142 } 
00143 
00144 void PulserGainPin::Store(DbiOutRowStream& ors,
00145                           const DbiValidityRec* /* vrec */) const
00146 {
00147 
00148  ElecType::Elec_t elec = fPlexPinDiodeId.GetElecType();
00149   char rackEastWest = fPlexPinDiodeId.GetEastWest();
00150   char rackLevel    = fPlexPinDiodeId.GetRackLevel();
00151   int  rackBay      = fPlexPinDiodeId.GetRackBay();
00152   int  muxInRack    = fPlexPinDiodeId.GetInRack();
00153   ors << fAggregateNo 
00154       << ElecType::AsString(elec)
00155       << rackEastWest
00156       << rackLevel
00157       << rackBay
00158       << muxInRack
00159       << fPlexPinDiodeId.GetInBox()
00160       << fPlexPinDiodeId.GetGain()
00161       << fNumPoints 
00162       << fFirstPoint 
00163       << fLastPoint;
00164   for (int i=0;i<40;i++) ors << fMean[i];
00165   for (int i=0;i<40;i++) ors << fError[i];
00166   for (int i=0;i<40;i++) ors << fNumEntries[i];
00167   for (int i=0;i<40;i++) ors << fNumTriggers[i];
00168 
00169 }
00170 
00171 bool PulserGainPin::Add(const PulserGainPin &pg)
00172 {
00173 
00174   assert(pg.GetAggregateNo()==fAggregateNo);
00175   const float * mean = pg.GetMean();
00176   const float * error = pg.GetError();
00177   const float * numentries = pg.GetNumEntries();
00178   const float * numtriggers = pg.GetNumTriggers();
00179 
00180   // Allow Add() to add to either end of the curve.
00181  if (pg.GetFirstPoint()==1+fLastPoint) {
00182     // add to end
00183     fLastPoint = pg.GetLastPoint();
00184   }
00185   else if(pg.GetLastPoint()==fFirstPoint-1) {
00186     // add to start
00187     fFirstPoint = pg.GetFirstPoint();
00188   }
00189   else {
00190     // Fragments don't join up
00191     MSG("Pulser",Msg::kError) << "This should never happen!\n";
00192     return false;
00193     // This should never happen, though!
00194   }
00195   for (int i=pg.GetFirstPoint();i<=pg.GetLastPoint();i++) {
00196     fMean[i-1] = mean[i-1];
00197     fError[i-1] = error[i-1];
00198     fNumEntries[i-1] = numentries[i-1];
00199     fNumTriggers[i-1] = numtriggers[i-1];
00200     fNumPoints = pg.GetNumPoints();
00201     //    ++fNumPoints;
00202   }
00203   return true;
00204 
00205 }
00206 
00207 Float_t PulserGainPin::ZCMean(Int_t i) {
00208   // Return zero-corrected mean for point i
00209   Float_t zcmean = fMean[i] * fNumEntries[i] / fNumTriggers[i];
00210   return zcmean;
00211 }
00212 
00213 Float_t PulserGainPin::ZCError(Int_t i) {
00214   // Return zero-corrected error for point i
00215   Float_t zcerr = fNumEntries[i]*fError[i]*fError[i];
00216   zcerr+= (1.-fNumEntries[i]/fNumTriggers[i])*fMean[i]*fMean[i];
00217   zcerr = sqrt(fNumEntries[i]*zcerr)/fNumTriggers[i];
00218   return zcerr;
00219 }

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