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

PEGainCalibrator.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PEGainCalibrator.cxx,v 1.1 2004/07/26 16:52:20 tagg Exp $
00003 //
00004 // Prototype PE gain Calibrator class
00005 //
00006 // rjn@hep.ucl.ac.uk
00008 #include "MessageService/MsgService.h"
00009 #include "CandDigit/CandDigitHandle.h"
00010 #include "Calibrator/PEGainCalibrator.h"
00011 #include "Plex/PlexSEIdAltL.h"
00012 #include "Plex/PlexStripEndId.h"
00013 #include "DatabaseInterface/DbiValidityRec.h"
00014 #include "Validity/VldRange.h"
00015 
00016 CVSID("$Id: PEGainCalibrator.cxx,v 1.1 2004/07/26 16:52:20 tagg Exp $");
00017 
00018 PEGainCalibrator::PEGainCalibrator(int calMode)
00019    : fResPtr(), fCalMode(calMode)
00020 {
00021    MSG("Calibrator",Msg::kVerbose) << "PEGainCalibrator::PEGainCalibrator" 
00022                                    << endl;
00023 }
00024 PEGainCalibrator::PEGainCalibrator(const VldContext vc, int calMode)
00025    : fResPtr(vc),fCalMode(calMode)
00026 {
00027    //assert(fResPtr.GetNumRows()!=0);
00028    //MSG("PE Calibrator",Msg::kVerbose) 
00029    // << "Number of valid rows in PE gain dB table is "
00030    // << fResPtr.GetNumRows()  <<  ".\n";
00031   if(fCalMode>0){
00032     if(fResPtr.GetNumRows()==0) {
00033       static int msglimit = 20;  // no more than 20 buggered messages
00034       if (msglimit) {
00035         MSG("PE Calibrator",Msg::kWarning) 
00036           << "No rows in database table with validity context "
00037           << vc.AsString() << " will assert() here" << ".\n";
00038         MSG("PE Calibrator",Msg::kWarning)
00039           << "TimeStamp " << vc.GetTimeStamp() << "\n";
00040         MSG("PE Calibrator",Msg::kWarning)
00041           << "SimFlag " << (int)vc.GetSimFlag() << "\n";
00042         MSG("PE Calibrator",Msg::kWarning)
00043           << "Detector " << (int)vc.GetDetector() << "\n";
00044         
00045         if ( ! ((int)vc.GetDetector() & 127) ) {
00046           MSG("PE Calibrator",Msg::kWarning)
00047             << "Detector " << (int)vc.GetDetector() 
00048             << " is the problem.\n";
00049         }
00050         if ( ! ((int)vc.GetSimFlag()  & 127) ) {
00051           MSG("PE Calibrator",Msg::kWarning)
00052             << "Simflag " << (int)vc.GetSimFlag() 
00053             << " is the problem.\n";
00054         }
00055         
00056         const DbiValidityRec* fred = fResPtr.GetValidityRec();
00057         const VldRange freda=fred->GetVldRange();
00058         MSG("PE Calibrator",Msg::kWarning) 
00059           << "bugger "
00060           << freda.AsString() << ".\n";
00061         
00062         if (--msglimit == 0) 
00063           MSG("PE Calibrator",Msg::kWarning)
00064             << " ... last warning of this type" << endl;
00065       }
00066     }
00067   }
00068   else{
00069           MSG("PE Calibrator",Msg::kInfo) << " No PE table loaded - defaults used.\n";
00070 
00071   }
00072 }
00073 
00074 //......................................................................
00075 
00076 Float_t PEGainCalibrator::Calibrate(Float_t rawcharge,
00077                                          PlexStripEndId seid) const
00078 {
00079 //======================================================================
00080 // Purpose: Calibrate method
00081 //======================================================================
00082    if (fCalMode) return ApplyCalib(rawcharge,seid);
00083    else          return rawcharge/60.0;   
00084 }
00085 
00086 //......................................................................
00087 
00088 Float_t  PEGainCalibrator::ApplyCalib(Float_t rawcharge, 
00089                                            PlexStripEndId seid) const
00090 {
00091 //======================================================================
00092 // Purpose: The actual numerical calibration, taking Raw Charge and
00093 // converting to PEs.
00094 //======================================================================
00095 
00096    Int_t psekey = seid.BuildPlnStripEndKey();
00097    //MSG("Calibrator",Msg::kVerbose) 
00098    //   << "PEGainCalibrator on " << rawcharge << " raw charge in seid " 
00099    //   << seid << " (indexed as " << psekey <<" )\n";
00100 
00101    // Now need to get the row which corresponds to the stripendnum.
00102    const CalADCtoPE* dpgc = fResPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00103    if(dpgc ==0) {
00104      static int msglimit = 20;  // no more than 20 missing row messages
00105      if (msglimit) {
00106        MSG("Calibrator",Msg::kWarning) 
00107          << "No database row for StripEnd " << seid << " (indexed as " 
00108          << psekey << " )\n";
00109        if (--msglimit == 0)
00110          MSG("Calibrator",Msg::kWarning)
00111            << " ... last warning of this type" << endl;
00112      }
00113      return rawcharge;
00114    }
00115 
00116  return dpgc->GetPE(rawcharge);
00117 }
00118 
00119 //......................................................................
00120 
00121 
00122 
00123 void PEGainCalibrator::ReInit(VldContext vc) {
00124 
00125   // if calibration is off, just return
00126   if (fCalMode == 0) return;
00127 
00128   // MSG("Calibrator",Msg::kVerbose) 
00129   //    << "PEGainCalibrator::ReInit(VldContext)" << endl;
00130 
00131   fResPtr.NewQuery(vc,0);
00132 
00133   MSG("PE Calibrator",Msg::kVerbose) 
00134     << "PEGainCalibrator::ReInit(VldContext)  mode " << fCalMode << endl
00135     << "Number of valid rows in PE gain dB table is "
00136     << fResPtr.GetNumRows()  <<  ".\n";
00137 
00138   //assert(fResPtr.GetNumRows()!=0);
00139    if(fResPtr.GetNumRows()==0) {
00140      static int msglimit = 20;  // no more than 20 buggered messages
00141      if (msglimit) {
00142         MSG("PE Calibrator",Msg::kWarning) 
00143            << "No rows in database table with validity context "
00144            << vc.AsString() << " will assert() here" << ".\n";
00145         MSG("PE Calibrator",Msg::kWarning)
00146            << "TimeStamp " << vc.GetTimeStamp() << "\n";
00147         MSG("PE Calibrator",Msg::kWarning)
00148            << "SimFlag " << (int)vc.GetSimFlag() << "\n";
00149         MSG("PE Calibrator",Msg::kWarning)
00150            << "Detector " << (int)vc.GetDetector() << "\n";
00151 
00152 
00153         if ( ! ((int)vc.GetDetector() & 127) ) {
00154            MSG("PE Calibrator",Msg::kWarning)
00155            << "Detector " << (int)vc.GetDetector() 
00156            << " is the problem.\n";
00157         }
00158         if ( ! ((int)vc.GetSimFlag()  & 127) ) {
00159            MSG("PE Calibrator",Msg::kWarning)
00160            << "Simflag " << (int)vc.GetSimFlag() 
00161            << " is the problem.\n";
00162         }
00163 
00164         const DbiValidityRec* fred = fResPtr.GetValidityRec();
00165         const VldRange freda=fred->GetVldRange();
00166         MSG("PE Calibrator",Msg::kWarning) 
00167            << "bugger "
00168            << freda.AsString() << ".\n";
00169 
00170         if (--msglimit == 0) 
00171           MSG("PE Calibrator",Msg::kWarning)
00172             << " ... last warning of this type" << endl;
00173      }
00174    }
00175 }
00176 
00177 //......................................................................
00178 
00179 
00180 
00181 
00182 
00183 
00184 
00185 
00186 

Generated on Thu Nov 1 15:53:18 2007 for loon by  doxygen 1.3.9.1