MuonDriftCalScheme Class Reference

#include <MuonDriftCalScheme.h>

Inheritance diagram for MuonDriftCalScheme:
CalScheme CfgPromptConfigurable

List of all members.

Public Member Functions

 MuonDriftCalScheme ()
virtual void DoReset (const VldContext &context)
virtual void ConfigModified ()
virtual void PrintConfig (std::ostream &os) const
virtual FloatErr GetDriftCorrected (FloatErr rawcharge, const PlexStripEndId &seid) const
virtual FloatErr DecalDrift (FloatErr undrifted, const PlexStripEndId &seid) const

Private Member Functions

 ClassDef (MuonDriftCalScheme, 0)

Private Attributes

VldTimeStamp fReferenceTime
Int_t fTask
DbiResultPtr< CalDriftfRefTable
DbiResultPtr< CalDriftfCurTable
FloatErr fCurDrift
Int_t fCurError

Detailed Description

Definition at line 31 of file MuonDriftCalScheme.h.


Constructor & Destructor Documentation

MuonDriftCalScheme::MuonDriftCalScheme (  ) 

Definition at line 80 of file MuonDriftCalScheme.cxx.

References Msg::kVerbose, MSG, and Registry::Set().

00081 {
00082    MSG("Calib",Msg::kVerbose) 
00083      << "MuonDriftCalScheme::MuonDriftCalScheme" 
00084      << endl;
00085 
00086    Registry r;
00087    //task 0 means pre-Dogwood0 database
00088    //from Dogwood1 on the task number needs to be set to 1
00089    r.Set("Task",1);
00090    r.Set("ReferenceDate",20051201);
00091    r.Set("ReferenceTime",000010);
00092 
00093    InitializeConfig(r);
00094 }


Member Function Documentation

MuonDriftCalScheme::ClassDef ( MuonDriftCalScheme  ,
 
) [private]

Reimplemented from CalScheme.

void MuonDriftCalScheme::ConfigModified ( void   )  [virtual]

Reimplemented from CalScheme.

Definition at line 97 of file MuonDriftCalScheme.cxx.

References fReferenceTime, fTask, Registry::Get(), CfgPromptConfigurable::GetConfig(), CalScheme::GetContext(), Msg::kWarning, MSG, and CalScheme::Reset().

00098 {
00099   int refdate;
00100   int reftime;
00101 
00102   bool ok = true;
00103   ok = ok && GetConfig().Get("ReferenceDate",refdate);
00104   ok = ok && GetConfig().Get("ReferenceTime",reftime);
00105   ok = ok && GetConfig().Get("Task",fTask);
00106   if(!ok) MSG("Calib",Msg::kWarning) << "MuonDriftCalibrator "
00107                                      << " Problem when configuring. " <<endl;
00108   
00109   // Interpret date.
00110   fReferenceTime = VldTimeStamp(refdate,reftime,0);
00111 
00112   // Ensure the DB has been fixed up.
00113   Reset(GetContext(),true);
00114 }

FloatErr MuonDriftCalScheme::DecalDrift ( FloatErr  undrifted,
const PlexStripEndId seid 
) const [virtual]

Purpose: Apply drift

In: drift-corrected ADCs strip end

Out: drifted adcs

Reimplemented from CalScheme.

Definition at line 320 of file MuonDriftCalScheme.cxx.

References fCurDrift, fCurError, CalScheme::IncrementErrors(), CalScheme::kDriftCalibrator, and CalScheme::kMissingRow.

00322 {
00331 
00332   if(fCurError) {
00333     IncrementErrors(kDriftCalibrator,kMissingRow);
00334   }
00335   return undrifted*fCurDrift;
00336 }

void MuonDriftCalScheme::DoReset ( const VldContext context  )  [virtual]

New context. For this module, this function actually does all the work. That's because we have only 1 calibration constant for the whole detector at one time, so we can pre-compute everything now.

Reimplemented from CalScheme.

Definition at line 116 of file MuonDriftCalScheme.cxx.

References ValueErr< T >::AsString(), VldContext::AsString(), VldTimeStamp::AsString(), Munits::day, fCurDrift, fCurError, fCurTable, Form(), fReferenceTime, fRefTable, fTask, VldContext::GetDetector(), CalDrift::GetMedianAsR1_18_2(), CalDrift::GetMedianErrAsR1_18_2(), DbiResultPtr< T >::GetNumRows(), CalDrift::GetRecoVersion(), DbiResultPtr< T >::GetRow(), VldContext::GetSimFlag(), VldRange::GetTimeEnd(), VldContext::GetTimeStamp(), VldRange::GetTimeStart(), DbiResultPtr< T >::GetValidityRec(), DbiValidityRec::GetVldRange(), CalScheme::IncrementErrors(), Msg::kDebug, CalScheme::kDriftCalibrator, Msg::kError, CalScheme::kMissingTable, MAXMSG, MSG, DbiResultPtr< T >::NewQuery(), ValueErr< T >::Set(), and ValueErr< T >::SetError().

00117 {
00118  
00125 
00126   fCurError = 0;
00127   fCurDrift.Set(1.0 ,0.5); // Default: No drift, 50% error.
00128   string refRecoVersion = "";
00129   string recoVersion = "";
00130 
00132   // Build context for reference point.
00133   VldContext refContext(vc.GetDetector(),
00134                         vc.GetSimFlag(),
00135                         fReferenceTime);
00136   
00138   // Get the reference point data.
00139   fRefTable.NewQuery(refContext,fTask);
00140 
00141   // The reference value:
00142   FloatErr reference(1,0);
00143 
00144   // Maybe we don't have any data there....
00145   if(fRefTable.GetNumRows() == 0) {
00146     IncrementErrors(kDriftCalibrator,kMissingTable);
00147     MAXMSG("Calib",Msg::kError,10) 
00148       << "No rows in CALDRIFT reference table task=" << fTask
00149       << "  cx=" << refContext.AsString() << std::endl;
00150     MAXMSG("Calib",Msg::kError,10) 
00151       << "Your database is bad or MuonDriftCalScheme is misconfigured!" << endl;
00152     // Flag it.
00153     fCurError=1;
00154     refRecoVersion = "Null";
00155     assert(fRefTable.GetNumRows() && "No Table row for reference date"); 
00156  } else {
00157     const CalDrift* refRow = fRefTable.GetRow(0); // We know at least one row exists.
00158     reference = refRow->GetMedianAsR1_18_2(vc.GetDetector());
00159     reference.SetError(0); // The error on the reference point is not relevant.
00160     refRecoVersion = refRow->GetRecoVersion();
00161  }
00162   
00163   // The current value:
00164   FloatErr current(1,0);
00165   
00166   fCurTable.NewQuery(vc,fTask);
00167 
00168   if(fCurTable.GetNumRows() == 0) {
00169     IncrementErrors(kDriftCalibrator,kMissingTable);
00170 
00171     MAXMSG("Calib",Msg::kError,10) 
00172       << "No rows in CALDRIFT table task=" << fTask
00173       << "  cx=" << vc.AsString() 
00174 //       << "  cx=" << refContext.AsString() 
00175       << ". Trying extrapolation." << std::endl;
00176     // Ok, now we have work to do.
00177 
00178     VldTimeStamp prevTime;
00179     const CalDrift* prevRow =0;
00180     VldTimeStamp nextTime;
00181     const CalDrift* nextRow =0;
00182 
00183     // Attempt to find the previous valid data.
00184     const char* sqlprev = Form("(TIMEEND<='%s') "
00185                               "and (TASK=%d) "
00186                               "and (DETECTORMASK & %d) "
00187                               "and (SIMMASK & %d) "
00188                               "order by TIMEEND desc limit 1", 
00189                                vc.GetTimeStamp().AsString("s"), 
00190                                fTask,                    
00191                                vc.GetDetector(),   
00192                                vc.GetSimFlag() );
00193     //MSG("Calib",Msg::kDebug) << "PrevRequest: " << sqlprev << endl;        
00194     DbiSqlContext prevContext(sqlprev);
00195     DbiResultPtr<CalDrift> prevTable("CALDRIFT",prevContext);
00196     if(prevTable.GetNumRows()>0) {
00197       prevRow = prevTable.GetRow(0);
00198       VldRange r = prevTable.GetValidityRec(prevRow)->GetVldRange();
00199       prevTime = r.GetTimeStart() + 0.5*(r.GetTimeEnd() - r.GetTimeStart());
00200     }    
00201     
00202     // Attempt to find the next valid data.
00203     const char* sqlnext = Form("(TIMESTART>='%s') "
00204                               "and (TASK=%d) "
00205                               "and (DETECTORMASK & %d) "
00206                               "and (SIMMASK & %d) "
00207                               "order by TIMESTART asc limit 1", 
00208                                vc.GetTimeStamp().AsString("s"), 
00209                                fTask,                    
00210                                vc.GetDetector(),   
00211                                vc.GetSimFlag() );
00212     //MSG("Calib",Msg::kDebug) << "NextRequest: " << sqlnext << endl;        
00213     DbiSqlContext nextContext(sqlnext);
00214     DbiResultPtr<CalDrift> nextTable("CALDRIFT",nextContext);
00215     if(nextTable.GetNumRows()>0) {
00216       nextRow = nextTable.GetRow(0);
00217       VldRange r = nextTable.GetValidityRec(nextRow)->GetVldRange();
00218       nextTime = r.GetTimeStart() + 0.5*(r.GetTimeEnd() - r.GetTimeStart());
00219    }    
00220   
00221     if((nextRow)&&(prevRow)) {
00222 
00223       // Interpolate between these two straddling points.
00224       //MSG("Calib",Msg::kDebug) << "Interpolating.      ";
00225       double dt = (nextTime-prevTime);
00226       Float_t y1a=prevRow->GetMedianAsR1_18_2(vc.GetDetector());
00227       Float_t y1b=prevRow->GetMedianErrAsR1_18_2(vc.GetDetector());
00228 
00229       FloatErr y1(y1a, y1b);
00230       Float_t y2a=nextRow->GetMedianAsR1_18_2(vc.GetDetector());
00231       Float_t y2b=nextRow->GetMedianErrAsR1_18_2(vc.GetDetector());
00232  
00233       FloatErr y2(y2a,y2b);
00234       FloatErr y = (y2-y1)*(vc.GetTimeStamp()-prevTime)/dt + y1;
00235       if(fCurError==0)
00236         fCurDrift = y/reference;
00237       
00238     } else if (nextRow) {
00239 
00240       // Extrapolate from the next point.
00241       //MSG("Calib",Msg::kDebug) << "Extrapolating next. ";
00242       Float_t ya=nextRow->GetMedianAsR1_18_2(vc.GetDetector());
00243       Float_t yb= nextRow->GetMedianErrAsR1_18_2(vc.GetDetector());
00244       FloatErr y(ya,yb);
00245       
00246       // Degrade the error by 2% per month it's out of date.
00247       y *= FloatErr(1.0, 0.02 * fabs(nextTime-vc.GetTimeStamp())/
00248                     (30*Munits::day));
00249       if(fCurError==0)
00250         fCurDrift = y/reference;
00251       
00252     } else if (prevRow) {
00253      
00254       // Extrapolate from the previous point.
00255       MSG("Calib",Msg::kDebug) << "Extrapolating prev. ";
00256       Float_t ya=prevRow->GetMedianAsR1_18_2(vc.GetDetector());
00257       Float_t yb=prevRow->GetMedianErrAsR1_18_2(vc.GetDetector());
00258      
00259       FloatErr y(ya,yb);
00260       // Degrade the error by 2% per day it's out of date.
00261       y *= FloatErr(1.0, 0.02 * fabs(prevTime-vc.GetTimeStamp())/
00262                     (30*Munits::day));
00263       if(fCurError==0)
00264         fCurDrift = y/reference;
00265       
00266     } else {
00267       // No data at all!
00268       fCurError = 1;
00269       MAXMSG("Calib",Msg::kError,10) 
00270         << "No rows in CALDRIFT task=" << fTask
00271         << "for ANY time!  Badness." << std::endl;
00272     }
00273   } else {
00274     // We have current data, so all the above is unneccessary.
00275     MSG("Calib",Msg::kDebug) << "Have data.          ";
00276     const CalDrift* nowRow = fCurTable.GetRow(0);
00277     Float_t ya=nowRow->GetMedianAsR1_18_2(vc.GetDetector());
00278     Float_t yb=nowRow->GetMedianErrAsR1_18_2(vc.GetDetector());
00279     current.Set(ya,yb); 
00280         
00281     if(fCurError == 0)
00282       fCurDrift = current/reference;
00283   }
00284   MSG("Calib",Msg::kDebug) << "Drift constant = " << fCurDrift.AsString()
00285                            << " for time " << vc.AsString() << std::endl;
00286   
00287   
00288 }

FloatErr MuonDriftCalScheme::GetDriftCorrected ( FloatErr  rawcharge,
const PlexStripEndId seid 
) const [virtual]

Purpose: Apply drift correction

In: linearised adc strip end

Out: drift-corrected adcs

Reimplemented from CalScheme.

Definition at line 301 of file MuonDriftCalScheme.cxx.

References fCurDrift, fCurError, CalScheme::IncrementErrors(), CalScheme::kDriftCalibrator, and CalScheme::kMissingRow.

00303 {
00312 
00313   if(fCurError) {
00314     IncrementErrors(kDriftCalibrator,kMissingRow);
00315   }
00316   return rawcharge/fCurDrift;
00317 }

void MuonDriftCalScheme::PrintConfig ( std::ostream &  os  )  const [virtual]

Reimplemented from CalScheme.

Definition at line 292 of file MuonDriftCalScheme.cxx.

References VldTimeStamp::AsString(), fReferenceTime, and fTask.

00293 {
00294   os << " Muon Drift Scheme: " << endl;
00295   os << "  ReferenceTime:     " << fReferenceTime.AsString() << endl;
00296   os << "  Task:              " << fTask << endl;
00297 }


Member Data Documentation

Definition at line 53 of file MuonDriftCalScheme.h.

Referenced by DecalDrift(), DoReset(), and GetDriftCorrected().

Definition at line 54 of file MuonDriftCalScheme.h.

Referenced by DecalDrift(), DoReset(), and GetDriftCorrected().

Definition at line 52 of file MuonDriftCalScheme.h.

Referenced by DoReset().

Definition at line 47 of file MuonDriftCalScheme.h.

Referenced by ConfigModified(), DoReset(), and PrintConfig().

Definition at line 51 of file MuonDriftCalScheme.h.

Referenced by DoReset().

Int_t MuonDriftCalScheme::fTask [private]

Definition at line 48 of file MuonDriftCalScheme.h.

Referenced by ConfigModified(), DoReset(), and PrintConfig().


The documentation for this class was generated from the following files:

Generated on 27 Apr 2017 for loon by  doxygen 1.6.1