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
00027 #include "MessageService/MsgService.h"
00028 #include "CandDigit/CandDigitHandle.h"
00029 #include "Calibrator/MuonSigCorrCalibrator.h"
00030 #include "Plex/PlexSEIdAltL.h"
00031 #include "Plex/PlexStripEndId.h"
00032 #include "DatabaseInterface/DbiValidityRec.h"
00033 #include "Validity/VldRange.h"
00034
00035 CVSID("$Id: MuonSigCorrCalibrator.cxx,v 1.1 2004/07/26 16:52:20 tagg Exp $");
00036 MuonSigCorrCalibrator::MuonSigCorrCalibrator(Int_t calMode)
00037 : fResPtr(), fCalMode(calMode),fMuonTask(0)
00038 {
00039 MSG("Calibrator",Msg::kVerbose) << "MuonSigCorrCalibrator::MuonSigCorrCalibrator"
00040 << endl;
00041 if(fCalMode>0){
00042 if(fCalMode<=2) fMuonTask=0;
00043 else if(fCalMode>2) fMuonTask=fCalMode;
00044 }
00045 MSG("Calibrator",Msg::kVerbose) << "fMuonTask: " << fMuonTask
00046 << endl;
00047 }
00048
00049
00050 MuonSigCorrCalibrator::MuonSigCorrCalibrator(const VldContext vc, Int_t calMode)
00051 : fResPtr(),fTempResPtr(),fCalMode(calMode),fMuonTask(0)
00052 {
00053
00054
00055 if(fCalMode>0){
00056 if(fCalMode<=2) fMuonTask=0;
00057 else if(fCalMode>2) fMuonTask=fCalMode-1;
00058 MSG("Calibrator",Msg::kVerbose) << "fMuonTask: " << fMuonTask
00059 << endl;
00060 fResPtr.NewQuery(vc,fMuonTask);
00061 if(fCalMode==2) {
00062 VldTimeStamp v2hour(-7200,0);
00063 v2hour.Add(vc.GetTimeStamp());
00064
00065 VldContext newvc(vc.GetDetector(),vc.GetSimFlag(),v2hour);
00066 fTempResPtr.NewQuery(newvc,0);
00067 if(fTempResPtr.GetNumRows()==0) {
00068 MSG("SigCor Calibrator",Msg::kWarning)
00069 << "No rows in temperature database"
00070 << " table with validity context "
00071 << vc.AsString() << " will assert() here" << ".\n";
00072
00073
00074 }
00075 }
00076
00077 if(fResPtr.GetNumRows()==0) {
00078 MSG("SigCor Calibrator",Msg::kWarning)
00079 << "No rows in database table with validity context "
00080 << vc.AsString() << " will assert() here" << ".\n";
00081 MSG("SigCor Calibrator",Msg::kWarning)
00082 << "TimeStamp " << vc.GetTimeStamp() << "\n";
00083 MSG("SigCor Calibrator",Msg::kWarning)
00084 << "SimFlag " << (int)vc.GetSimFlag() << "\n";
00085 MSG("SigCor Calibrator",Msg::kWarning)
00086 << "Detector " << (int)vc.GetDetector() << "\n";
00087
00088
00089 if ( ! ((int)vc.GetDetector() & 127) ) {
00090 MSG("SigCor Calibrator",Msg::kWarning)
00091 << "Detector " << (int)vc.GetDetector()
00092 << " is the problem.\n";
00093 }
00094 if ( ! ((int)vc.GetSimFlag() & 127) ) {
00095 MSG("SigCor Calibrator",Msg::kWarning)
00096 << "Simflag " << (int)vc.GetSimFlag()
00097 << " is the problem.\n";
00098 }
00099
00100
00101
00102 const DbiValidityRec* fred = fResPtr.GetValidityRec();
00103 const VldRange freda=fred->GetVldRange();
00104 MSG("SigCor Calibrator",Msg::kWarning)
00105 << "bugger "
00106 << freda.AsString() << ".\n";
00107
00108 }
00109 }
00110 else{
00111 MSG("SigCor Calibrator",Msg::kInfo) << "No SigCor Table loaded - default used.\n";
00112
00113 }
00114
00115 MSG("Calibrator",Msg::kVerbose) << "fMuonTask: " << fMuonTask
00116 << endl;
00117 }
00118
00119
00120 void MuonSigCorrCalibrator::SetCalMode(Int_t calMode)
00121 {
00122 fCalMode=calMode;
00123 if(fCalMode<=2) fMuonTask=0;
00124 else if(fCalMode>2) fMuonTask=fCalMode-1;
00125 }
00126
00127
00128 Float_t MuonSigCorrCalibrator::Calibrate(Float_t siglin,
00129 PlexStripEndId seid) const
00130 {
00131
00132
00133
00134 if(fCalMode==2)
00135 return ApplyCalib(siglin,seid)*GetTemperatureCorrection();
00136 return ApplyCalib(siglin,seid);
00137
00138 }
00139
00140
00141
00142 Float_t MuonSigCorrCalibrator::GetTemperatureCorrection() const
00143 {
00144
00145
00146
00147
00148 if(fTempResPtr.GetNumRows()==0) {
00149 static int msglimit = 20;
00150 if (msglimit) {
00151 MSG("Calibrator",Msg::kWarning)
00152 << "No Temperature database row " << endl;
00153 if (--msglimit == 0)
00154 MSG("Calibrator",Msg::kWarning)
00155 << " ... last warning of this type" << endl;
00156 }
00157 return 1.0;
00158 }
00159 const CalTempCalibration* tempcal = fTempResPtr.GetRow(0);
00160 if(tempcal ==0 ) {
00161
00162 static int msglimit = 20;
00163 if (msglimit) {
00164 MSG("Calibrator",Msg::kWarning)
00165 << "No Temperature database row " << endl;
00166 if (--msglimit == 0)
00167 MSG("Calibrator",Msg::kWarning)
00168 << " ... last warning of this type" << endl;
00169 }
00170 return 1.0;
00171 }
00172 MSG("Calibrator",Msg::kVerbose) << "Got Temperature Correction of: "
00173 << tempcal->GetCorrection() << endl;
00174 return tempcal->GetCorrection();
00175
00176 }
00177
00178
00179 Float_t MuonSigCorrCalibrator::ApplyCalib(Float_t siglin,
00180 PlexStripEndId seid) const
00181 {
00182
00183
00184
00185
00186
00187 MSG("Calibrator",Msg::kVerbose) << "MuonSigCorrCalibrator on " << siglin
00188 << " siglin in seid " << seid.BuildPlnStripEndKey() <<"\n";
00189
00190 const CalMuonCalibration* muoncal = fResPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00191 if(muoncal ==0) {
00192 static int msglimit = 20;
00193 if (msglimit) {
00194 MSG("Calibrator",Msg::kWarning)
00195 << "No database row for StripEnd " << seid
00196 << " (indexed as " << seid.BuildPlnStripEndKey() << " )\n";
00197 if (--msglimit == 0)
00198 MSG("Calibrator",Msg::kWarning)
00199 << " ... last warning of this type" << endl;
00200 }
00201 return siglin;
00202 }
00203 return muoncal->StripToStripCorrected(siglin);
00204 }
00205
00206
00207
00208 void MuonSigCorrCalibrator::ReInit(VldContext vc) {
00209 MSG("Calibrator",Msg::kVerbose) << "MuonSigCorrCalibrator::ReInit(VldContext) fMuonTask: " << fMuonTask << endl;
00210
00211 fResPtr.NewQuery(vc,fMuonTask);
00212
00213 if(fCalMode==2) {
00214 VldTimeStamp v2hour(-7200,0);
00215 v2hour.Add(vc.GetTimeStamp());
00216
00217 VldContext newvc(vc.GetDetector(),vc.GetSimFlag(),v2hour);
00218 fTempResPtr.NewQuery(newvc,0);
00219 if(fTempResPtr.GetNumRows()==0) {
00220 MSG("SigCor Calibrator",Msg::kWarning)
00221 << "No rows in temperature database"
00222 << " table with validity context "
00223 << vc.AsString() << " will assert() here" << ".\n";
00224
00225
00226 }
00227 }
00228
00229
00230 if(fResPtr.GetNumRows()==0) {
00231 MSG("SigCor Calibrator",Msg::kWarning)
00232 << "No rows in database table with validity context "
00233 << vc.AsString() << " will assert() here" << ".\n";
00234 MSG("SigCor Calibrator",Msg::kWarning)
00235 << "TimeStamp " << vc.GetTimeStamp() << "\n";
00236 MSG("SigCor Calibrator",Msg::kWarning)
00237 << "SimFlag " << (int)vc.GetSimFlag() << "\n";
00238 MSG("SigCor Calibrator",Msg::kWarning)
00239 << "Detector " << (int)vc.GetDetector() << "\n";
00240
00241
00242 if ( ! ((int)vc.GetDetector() & 127) ) {
00243 MSG("SigCor Calibrator",Msg::kWarning)
00244 << "Detector " << (int)vc.GetDetector()
00245 << " is the problem.\n";
00246 }
00247 if ( ! ((int)vc.GetSimFlag() & 127) ) {
00248 MSG("SigCor Calibrator",Msg::kWarning)
00249 << "Simflag " << (int)vc.GetSimFlag()
00250 << " is the problem.\n";
00251 }
00252
00253
00254
00255 const DbiValidityRec* fred = fResPtr.GetValidityRec();
00256 const VldRange freda=fred->GetVldRange();
00257 MSG("SigCor Calibrator",Msg::kWarning)
00258 << "bugger "
00259 << freda.AsString() << ".\n";
00260
00261 }
00262 }
00263
00264
00265
00266 const CalMuonCalibration* MuonSigCorrCalibrator::GetCalMuonCalibration(PlexStripEndId seid) const
00267 {
00268 return fResPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00269 }
00270
00271