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

MIPCalibrator.cxx

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

Generated on Thu Nov 1 15:52:59 2007 for loon by  doxygen 1.3.9.1