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

CalDrift.cxx

Go to the documentation of this file.
00001 
00002 // CalDrift.cxx
00003 //
00004 // Package: Dbi (Database Interface).
00005 //
00006 // The DbiTableRow class responsible for the drift calibration
00007 //
00008 //
00009 //
00010 //
00011 // j.evans2@physics.ox.ac.uk
00013 
00014 #include "DatabaseInterface/DbiOutRowStream.h"
00015 #include "MessageService/MsgService.h"
00016 
00017 #include "Calibrator/CalDrift.h"
00018 
00019 ClassImp(CalDrift)
00020 
00021 CVSID("$Id: CalDrift.cxx,v 1.13 2009/05/22 10:57:19 tinti Exp $");
00022 
00023 #include "DatabaseInterface/DbiResultPtr.tpl"
00024 #include "DatabaseInterface/DbiResultSet.h"
00025 #include "DatabaseInterface/DbiWriter.tpl"
00026 #include "DatabaseInterface/DbiValidityRec.h"
00027 #include "Validity/VldContext.h"
00028 
00029 template class DbiResultPtr<CalDrift>;
00030 template class DbiWriter<CalDrift>;
00031 
00032 //____________________________________________________________________72
00033 CalDrift::CalDrift() : DbiTableRow()
00034 {
00035   LEA_CTOR; // Leak detection macro.
00036   fbackMedian = 0.0;
00037   fbackMedianErr = 0.0;
00038   ffrontMedian = 0.0;
00039   ffrontMedianErr = 0.0;
00040   fnonFidMedian = 0.0;
00041   fnonFidMedianErr = 0.0;
00042   fnumMuons = 0;
00043   fnumPlanes = 0;
00044   fmean = 0.0;
00045   fmeanErr = 0.0;
00046   fmedian = 0.0;
00047   fmedianErr = 0.0;
00048   fpeak = 0.0;
00049   fpeakErr = 0.0;
00050   fquantile50 = 0.0;
00051   frecoVersion = "Dogwood"; //default to Dogwood
00052   //frecoVersion = "R1_18_2";
00053   fdriftQuantity1 = 1.0;
00054   fdriftQuantity2 = 1.0;
00055 }
00056 
00057 //____________________________________________________________________72
00058 CalDrift::~CalDrift()
00059 {
00060   LEA_DTOR; // Leak detection macro.
00061 }
00062 
00063 
00064 //____________________________________________________________________72
00065 const Float_t
00066 CalDrift::CalibratedPH(const Float_t ph,
00067                        const VldContext& cxNow,
00068                        const VldContext& cxRef) const
00069 {
00070   // This code shouldn't be used except for test puposes.
00071   // The MuonDriftCalScheme does a much better job.
00072   // Nathaniel, Feb/06
00073 
00074   //set the task to 1=Dogwood
00075   //all previous constants where in the default task=0  
00076   Dbi::Task task = 1;
00077   
00078   DbiResultPtr<CalDrift> nowTable("CALDRIFT",
00079                                   cxNow,
00080                                   task,
00081                                   Dbi::kTableMissing,
00082                                   false);
00083   DbiResultPtr<CalDrift> t0Table("CALDRIFT",
00084                                  cxRef, 
00085                                  task,
00086                                  Dbi::kTableMissing,
00087                                  false);
00088 
00089   Double_t multipFactor = 1.0;
00090   if (nowTable.GetNumRows() && t0Table.GetNumRows()){
00091     const CalDrift* nowRow = nowTable.GetRow(0);
00092     const CalDrift* t0Row = t0Table.GetRow(0);
00093     multipFactor =
00094       t0Row->GetMedianAsR1_18_2(cxRef.GetDetector())
00095       /nowRow->GetMedianAsR1_18_2(cxRef.GetDetector());
00096 //     multipFactor =
00097 //       t0Row->GetMeanAsR1_18_2(cxRef.GetDetector())
00098 //       /nowRow->GetMeanAsR1_18_2(cxRef.GetDetector());
00099 //     multipFactor =
00100 //       t0Row->GetMean()
00101 //       /nowRow->GetMean();
00102   }
00103 
00104   return (Float_t) ((Double_t) ph)*multipFactor;
00105 }
00106 
00107 //____________________________________________________________________72
00108 DbiTableRow* CalDrift::CreateTableRow() const
00109 {
00110   return new CalDrift;
00111 }
00112 
00113 //____________________________________________________________________72
00114 void CalDrift::Fill(DbiResultSet& rs,
00115                     const DbiValidityRec* /* vrec */)
00116 {
00117 //  Purpose:  Fill object from Result Set
00118 //
00119 //  Arguments: 
00120 //    rs           in    Result Set used to fill object
00121 //    vrec         in    Associated validity record (or 0 if filling
00122 //                                                    DbiValidityRec)
00123 //  o Fill object from current row of Result Set.
00124 
00125 //Only using the dumb method for now.
00126 
00127 //WARNING*******************************************
00128   //There's a nasty, nasty hack to force a RecoVersion flag in.
00129   //Make sure the version number in the CalDrift constructor is set to
00130   //the one you want before filling the database.
00131   //I'll fix this at the next reprocessing.
00132   //But I should be the only person who has to use this method for now.
00133 
00134   rs  >> fbackMedian >> fbackMedianErr >> ffrontMedian
00135       >> ffrontMedianErr >> fnonFidMedian >> fnonFidMedianErr
00136       >> fnumMuons >> fnumPlanes >> fmean >> fmeanErr >> fmedian
00137       >> fmedianErr >> fquantile50 >> frecoVersion
00138       >> fdriftQuantity1 >> fdriftQuantity2;
00139 }
00140 
00141 //____________________________________________________________________72
00142 Float_t CalDrift::GetMeanAsR1_18_2(const Detector::Detector_t det)
00143   const
00144 {
00145   Double_t recoFactor = 1.0;
00146   if (Detector::kNear == det){
00147     if ("R1_18"==frecoVersion){
00148       recoFactor = 1.00129; //R1_18_2 = r1_18Factor*R1_18;
00149     }
00150     if ("R1_18_2"==frecoVersion){
00151       recoFactor = 1.0;
00152     }
00153     if ("R1_18_4"==frecoVersion){
00154       recoFactor = 1.0;
00155     }
00156     if ("Cedar"==frecoVersion){
00157       recoFactor = 0.9719; //R1_18_2 = cedarFactor*cedar;
00158     }
00159     if ("Dogwood"==frecoVersion){
00160       recoFactor = 0.972141; //R1_18_2 = dogwoodFactor*Dogwood;
00161     }
00162 
00163   }
00164   if (Detector::kFar == det){
00165     if ("R1_18"==frecoVersion){
00166       recoFactor = 1.0;
00167     }
00168     if ("R1_18_2"==frecoVersion){
00169       recoFactor = 1.0;
00170     }
00171     if ("R1_18_4"==frecoVersion){
00172       recoFactor = 1.0;
00173     }
00174     if ("Cedar"==frecoVersion){
00175       recoFactor = 0.92322; //R1_18_2 = cedarFactor*cedar;
00176     }
00177     if ("Dogwood"==frecoVersion){
00178       recoFactor = 1.01134; //R1_18_2 = dogwoodFactor*Dogwood;
00179     }
00180   }
00181   return fmean*recoFactor;
00182 }
00183 
00184 //____________________________________________________________________72
00185 Float_t CalDrift::GetMedianRecoFactor(const Detector::Detector_t det)
00186   const
00187 {
00188   //factors to scale to R1_18_2
00189   
00190   Double_t recoFactor = 1.0;
00191   if (Detector::kNear == det){
00192     if ("R1_18"==frecoVersion){
00193       recoFactor = 1.00129; //R1_18_2 = r1_18Factor*R1_18;
00194     }
00195     if ("R1_18_2"==frecoVersion){
00196       recoFactor = 1.0;
00197     }
00198     if ("R1_18_4"==frecoVersion){
00199       recoFactor = 1.0;
00200     }
00201     if ("Cedar"==frecoVersion){
00202       recoFactor = 1.0007; //R1_18_2 = cedarFactor*cedar;
00203     }
00204     if ("Dogwood"==frecoVersion){
00205       recoFactor = 0.950574; //R1_18_2 = dogwoodFactor*Dogwood;
00206     }
00207   }
00208   if (Detector::kFar == det){
00209     if ("R1_18"==frecoVersion){
00210       recoFactor = 1.0;
00211     }
00212     if ("R1_18_2"==frecoVersion){
00213       recoFactor = 1.0;
00214     }
00215     if ("R1_18_4"==frecoVersion){
00216       recoFactor = 1.0;
00217     }
00218     if ("Cedar"==frecoVersion){
00219       recoFactor = 0.96688; //R1_18_2 = cedarFactor*cedar;
00220     }
00221     if ("Dogwood"==frecoVersion){
00222       recoFactor = 0.964280; //R1_18_2 = dogwoodFactor*Dogwood;
00223     } 
00224   }
00225   return recoFactor;
00226 }
00227 //____________________________________________________________________72
00228 Float_t CalDrift::GetMedianAsR1_18_2(const Detector::Detector_t det)
00229   const
00230 {
00231   Float_t recoFactor=GetMedianRecoFactor(det);
00232   Float_t calc=fmedian;
00233   if("Dogwood"==frecoVersion && det==Detector::kNear)
00234     calc=ffrontMedian;
00235   return calc*recoFactor;
00236   
00237 }
00238 //____________________________________________________________________72
00239 Float_t CalDrift::GetMedianErrAsR1_18_2(const Detector::Detector_t det)
00240   const
00241 {
00242   Float_t recoFactor=GetMedianRecoFactor(det);
00243   Float_t calc=fmedianErr;
00244   if("Dogwood"==frecoVersion && det==Detector::kNear)
00245     calc=ffrontMedianErr;
00246   return calc*recoFactor;
00247 }
00248 //____________________________________________________________________72
00249 void CalDrift::Store(DbiOutRowStream& ors,
00250                                const DbiValidityRec* /* vrec */) const
00251 {
00252   //
00253   //  Purpose:  Stream object to output row stream
00254   //
00255   //  Arguments: 
00256   //    ors          in     Output row stream.
00257   //    vrec         in    Associated validity record (or 0 if filling
00258   
00259   ors << fbackMedian << fbackMedianErr << ffrontMedian
00260       << ffrontMedianErr << fnonFidMedian << fnonFidMedianErr
00261       << fnumMuons << fnumPlanes << fmean << fmeanErr << fmedian
00262       << fmedianErr << fquantile50 << frecoVersion
00263       << fdriftQuantity1 << fdriftQuantity2;
00264 }

Generated on Mon Feb 15 11:06:27 2010 for loon by  doxygen 1.3.9.1