BCkovResTable Class Reference

Interface to BCkovRes database table: table which defines response of the BCkov PMT's. More...

#include <BCkovResTable.h>

List of all members.

Public Member Functions

 ~BCkovResTable ()
double LL (int part, double *q) const
 Computes the log likelihood for particle part given the four PMT charges q.
int FuncType (int part, int pmt) const
double Param0 (int part, int pmt) const
double Param1 (int part, int pmt) const
bool Init (int run)
void Reset ()
void Set (int part, int pmt, int ft, double p0, double p1)
void SetRunRange (int minrun, int maxrun)
void WriteToDB ()

Static Public Member Functions

static BCkovResTableInstance ()

Private Member Functions

 BCkovResTable ()
double ComputeLogA (int ft, double p0, double p1)

Private Attributes

int fMinRun
int fMaxRun
int fFuncType [PIDDef::kNPID][BCkov::kNChan]
double fParam0 [PIDDef::kNPID][BCkov::kNChan]
double fParam1 [PIDDef::kNPID][BCkov::kNChan]
double fLogA [PIDDef::kNPID][BCkov::kNChan]

Static Private Attributes

static BCkovResTablefInstance = 0


Detailed Description

Interface to BCkovRes database table: table which defines response of the BCkov PMT's.

Response is defined in terms of either Gaussian function -- when no signal is expected, or a 'pseudo-poisson': F(x) = C * (1 + (q / w) ^ p) * exp(-q/w), where a is PMT's charge, w is charge per p.e., and p is approximately the expected number of p.e.'s. This function has an advantage over non-discrete Poisson because of its computational simplicity. Note that 1 is needed for F(0) != 0.

Definition at line 25 of file BCkovResTable.h.


Constructor & Destructor Documentation

BCkovResTable::~BCkovResTable (  )  [inline]

Definition at line 28 of file BCkovResTable.h.

00028 {;}

BCkovResTable::BCkovResTable (  )  [private]

Definition at line 32 of file BCkovResTable.cxx.

00032                              :
00033   fMinRun(0),
00034   fMaxRun(0)
00035 {
00036 }


Member Function Documentation

double BCkovResTable::ComputeLogA ( int  ft,
double  p0,
double  p1 
) [private]

Definition at line 100 of file BCkovResTable.cxx.

References M_SQRT_2_PI.

Referenced by Init().

00101 {
00102   if (p1 < 1e-3) return -1e9;
00103   switch (ft) {
00104   case 0: // Gaussian
00105     return -log(p1 * M_SQRT_2_PI);
00106     break;
00107 
00108   case 1: // Pseudo-poisson
00109     return -log(p1 * (1 + TMath::Gamma(p0 + 1)));
00110     break;
00111     
00112   default:
00113     return -1e9;
00114   }
00115 }

int BCkovResTable::FuncType ( int  part,
int  pmt 
) const [inline]

Definition at line 31 of file BCkovResTable.h.

References fFuncType.

00031 {return fFuncType[part][pmt];}

bool BCkovResTable::Init ( int  run  ) 

Definition at line 48 of file BCkovResTable.cxx.

References ComputeLogA(), fFuncType, fLogA, fMaxRun, fMinRun, fParam0, fParam1, GET_FLOAT, GET_INT, MdbTableDict::GetTableRSR(), MdbTableDict::Instance(), BCkov::kNChan, PIDDef::kNPID, MdbAbsRelDBTable::NumberOfCachedRows(), MXML::ReadFile(), Reset(), and MdbTableRunSubRun::Select().

00049 {
00050   if (fMinRun <= run && fMaxRun >= run) return true;
00051   
00052   MXML::ReadFile("BCkovResTable.xml");
00053   MdbTableRunSubRun* table =
00054     MdbTableDict::Instance()->GetTableRSR("BCkovRes");
00055   if(!table) {
00056     cout << "Couldn't find BCkovRes table!" << endl;
00057     return false;
00058   }
00059 
00060   fMinRun = run;
00061   fMaxRun = run;
00062   Reset();
00063 
00064   vector<string> cols;
00065   MdbAbsRelDBTable* query = table->Select(cols, run);
00066   int nRows = query->NumberOfCachedRows();
00067   if (nRows == 0) {
00068     cout << "BCkovResTable: found no rows for run " << run
00069               << endl;
00070     return false;
00071   }
00072 
00073   if (nRows != 1) {
00074     cout << "BCkovResTable: found " << nRows << " rows for run " << run
00075      << "; only the first row will be used" << endl;
00076   }
00077 #define GET_INT(name) query->getCachedTableDataPtr(string(name), 0)->valInt()
00078 #define GET_FLOAT(name) query->getCachedTableDataPtr(string(name), 0)->valFloat()
00079   
00080   fMinRun = GET_INT("runNumMin")[0];
00081   fMaxRun = GET_INT("runNumMax")[0];
00082   for (int i = 0; i < PIDDef::kNPID; ++i) {
00083     for (int j = 0; j < kNChan; ++j) {
00084       fFuncType[i][j] = GET_INT("funcType")[i * kNChan + j];
00085       fParam0[i][j]   = GET_FLOAT("param0")[i * kNChan + j];
00086       fParam1[i][j]   = GET_FLOAT("param0")[i * kNChan + j];
00087 
00088       fLogA[i][j] = ComputeLogA(fFuncType[i][j], 
00089                 fParam0[i][j],
00090                 fParam0[i][j]);
00091     }
00092   }
00093 
00094 #undef GET_VEC  
00095   return true;
00096 } 

BCkovResTable & BCkovResTable::Instance (  )  [static]

Definition at line 40 of file BCkovResTable.cxx.

References fInstance.

00041 {
00042   if (!fInstance) fInstance = new BCkovResTable;
00043   return *fInstance;
00044 }

double BCkovResTable::LL ( int  part,
double *  q 
) const

Computes the log likelihood for particle part given the four PMT charges q.

Definition at line 121 of file BCkovResTable.cxx.

References fFuncType, fLogA, fParam0, fParam1, and BCkov::kNChan.

00122 {
00123   double ll = 0;
00124 
00125   double val;
00126 
00127   for (int i = 0; i < kNChan; ++i) {
00128     ll += fLogA[part][i];
00129 
00130     if (fLogA[part][i] < -1e8) continue;
00131     switch (fFuncType[part][i]) {
00132     case 0: // Gaussian
00133       ll -= 0.5 * pow((q[i] - fParam0[part][i]) / fParam1[part][i], 2);
00134       break;
00135 
00136     case 1: // Pseudo-Poisson
00137       val = q[i] / fParam1[part][i];
00138       ll += log(1 + pow(val, fParam0[part][i])) - val;
00139       break;
00140 
00141     default: 
00142       ll -= 1e9;
00143       break;
00144     }
00145    
00146   }
00147   return ll;
00148 }

double BCkovResTable::Param0 ( int  part,
int  pmt 
) const [inline]

Definition at line 32 of file BCkovResTable.h.

References fParam0.

00032 {return fParam0[part][pmt];}

double BCkovResTable::Param1 ( int  part,
int  pmt 
) const [inline]

Definition at line 33 of file BCkovResTable.h.

References fParam1.

00033 {return fParam1[part][pmt];}

void BCkovResTable::Reset (  ) 

Definition at line 189 of file BCkovResTable.cxx.

References fFuncType, fParam0, and fParam1.

Referenced by BCkovReco::EndRun(), and Init().

00190 {
00191   memset(fFuncType, 0, sizeof(fFuncType));
00192   memset(fParam0, 0, sizeof(fParam0));
00193   memset(fParam1, 0, sizeof(fParam1));
00194 }

void BCkovResTable::Set ( int  part,
int  pmt,
int  ft,
double  p0,
double  p1 
)

Definition at line 198 of file BCkovResTable.cxx.

References fFuncType, fParam0, fParam1, BCkov::kNChan, and PIDDef::kNPID.

Referenced by BCkovReco::EndRun().

00199 {
00200   assert(part >= 0 && part < PIDDef::kNPID);
00201   assert(pmt >= 0 && pmt < kNChan);
00202   fFuncType[part][pmt] = ft;
00203   fParam0[part][pmt] = p0;
00204   fParam1[part][pmt] = p1;
00205 }

void BCkovResTable::SetRunRange ( int  minrun,
int  maxrun 
) [inline]

Definition at line 39 of file BCkovResTable.h.

References fMaxRun, and fMinRun.

Referenced by BCkovReco::EndRun().

00039                                            {
00040     fMinRun = minrun; fMaxRun = maxrun;
00041   }

void BCkovResTable::WriteToDB (  ) 

Definition at line 152 of file BCkovResTable.cxx.

References MdbDatabase::dbVar(), fFuncType, fMaxRun, fMinRun, fParam0, MdbTableDict::GetTableRSR(), MdbTableRunSubRun::InsertRow(), MdbDatabase::Instance(), MdbTableDict::Instance(), BCkov::kNChan, PIDDef::kNPID, p0, p1, and MXML::ReadFile().

Referenced by BCkovReco::EndRun().

00153 {
00154   if (strcmp(getenv("PGUSER"), "mippdbwrite") != 0) {
00155     cout << "BCkovResTable: asked to write to DB, but PGUSER="
00156      << getenv("PGUSER") << ". Cannot perform task."
00157      << endl;
00158     return;
00159   }
00160 
00161   MXML::ReadFile("BCkovResTable.xml");
00162   MdbTableRunSubRun* table =
00163     MdbTableDict::Instance()->GetTableRSR("BCkovRes");
00164   if (!table) return;
00165 
00166   MdbDatabase* dbFact = MdbDatabase::Instance();
00167   std::vector<MdbAbsRelDBVar*> vars;
00168 
00169   std::vector<int> ft(0);
00170   std::vector<float> p0(0), p1(0);
00171 
00172   for (int i = 0; i < PIDDef::kNPID; ++i) {
00173     for (int j = 0; j < kNChan; ++j) {
00174       ft.push_back(fFuncType[i][j]);
00175       p0.push_back(fParam0[i][j]);
00176       p1.push_back(fParam0[i][j]);
00177     }
00178   }
00179 
00180   vars.push_back(dbFact->dbVar(ft));
00181   vars.push_back(dbFact->dbVar(p0));
00182   vars.push_back(dbFact->dbVar(p1));
00183 
00184   table->InsertRow(vars, fMinRun, 0, fMaxRun, 9999, 1);
00185 }


Member Data Documentation

int BCkovResTable::fFuncType[PIDDef::kNPID][BCkov::kNChan] [private]

Definition at line 56 of file BCkovResTable.h.

Referenced by FuncType(), Init(), LL(), Reset(), Set(), and WriteToDB().

BCkovResTable * BCkovResTable::fInstance = 0 [static, private]

Definition at line 51 of file BCkovResTable.h.

Referenced by Instance().

double BCkovResTable::fLogA[PIDDef::kNPID][BCkov::kNChan] [private]

Definition at line 60 of file BCkovResTable.h.

Referenced by Init(), and LL().

int BCkovResTable::fMaxRun [private]

Definition at line 54 of file BCkovResTable.h.

Referenced by Init(), SetRunRange(), and WriteToDB().

int BCkovResTable::fMinRun [private]

Definition at line 53 of file BCkovResTable.h.

Referenced by Init(), SetRunRange(), and WriteToDB().

double BCkovResTable::fParam0[PIDDef::kNPID][BCkov::kNChan] [private]

Definition at line 57 of file BCkovResTable.h.

Referenced by Init(), LL(), Param0(), Reset(), Set(), and WriteToDB().

double BCkovResTable::fParam1[PIDDef::kNPID][BCkov::kNChan] [private]

Definition at line 58 of file BCkovResTable.h.

Referenced by Init(), LL(), Param1(), Reset(), and Set().


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 08:03:57 2009 for MIPP(E907) by  doxygen 1.4.7