StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StBTofSimResParams.h
1 //
2 // StBTofSimResParams.h
3 //
4 //
5 // Modified by Zaochen on 07/21/2021.
6 // Created by jdb on 03/08/18.
7 //
8 //
9 
10 #ifndef StBTofSimResParams_h
11 #define StBTofSimResParams_h
12 
13 #include <iostream>
14 #include <fstream>
15 #include <vector>
16 #include "St_db_Maker/St_db_Maker.h"
17 #include "tables/St_tofSimResParams_Table.h"
18 
19 
20 // using std::string;
21 // class tofSimResParams_st;
22 
23 class StBTofSimResParams : public StMaker {
24  public:
25 
27  ~StBTofSimResParams() {}
28 
29  double average_timeres_tof(){return mAverageTimeResTof;}
30 
35  double timeres_tof(unsigned int itray, unsigned int imodule, unsigned int icell)
36  {
37  double result = 8.5e-11;
38  if ( itray > 120 || imodule > 32 || icell > 6 )
39  return result;
40 
41  return params[ itray-1 ][ (imodule-1) * 6 + (icell-1) ];
42  }
43 
45  //void loadParams(const int date = 20160913, const int time = 175725, const char* Default_time = "2016-09-13 17:57:25")
46  void loadParams(const int runNumber = 20076002)
47  {
48  //--------------------------------------------------------------------------------------------------
49  //the following lines may be needed if not run with bfc.C, but run btof simulation individually,
50  //it will require you to set up a timestamp to pickup the table in DB, here below show an example to use
51  //runnumber to set the timestamp, you can also modify the function to pickup the timestamp you want
52  //const int yearNumber = runNumber/1000000 - 1 + 2000;
53  //const int date = (yearNumber-1)*1000*10 + 1001; // prior year + October 1st(Date)
54 
55  //St_db_Maker *dbMk = new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
56  //dbMk->SetDebug();
57  //dbMk->SetDateTime(date,1);
58  //dbMk->SetFlavor("ofl");
59  //dbMk->Init();
60  //dbMk->Make();
61 
62  //TDataSet *DB = 0;
63  //DB = dbMk->GetDataBase("Calibrations/tof/tofSimResParams");
64  //--------------------------------------------------------------------------------------------------
65 
66  TDataSet *DB = 0;
67  DB = GetDataBase("Calibrations/tof/tofSimResParams");
68 
69  if(!DB)
70  {
71  LOG_WARN << "ERROR: could not read requested table from DB" << endm;
72  return;
73  }
74 
75  St_tofSimResParams *dataset = 0;
76  dataset = (St_tofSimResParams*) DB->Find("tofSimResParams");
77 
78  if(dataset)
79  {
80  //TDatime val[2];
81  //dbMk->GetValidity((TTable*)dataset,val);
82 
83  tofSimResParams_st* tofTable = static_cast<tofSimResParams_st*>(dataset->GetTable());
84 
85  const int mNTray = 120;
86  const int mNCellsPerTray = 192;
87 
88  mAverageTimeResTof = 0;
89  for ( int i = 0; i < mNTray; i++ )
90  {
91  for ( int j = 0; j < mNCellsPerTray; j++ )
92  {
93  size_t index = i * mNCellsPerTray + j;
94  params[i][j] = tofTable[0].resolution[index];
95 
96  mAverageTimeResTof += params[i][j];
97 
98  LOG_DEBUG << "tray:" << i << ", mod cell:" << j << " = " << tofTable[0].resolution[index] << " == " << params[i][j] << endm;
99  }
100  }
101 
102  mAverageTimeResTof=mAverageTimeResTof/(mNTray*mNCellsPerTray);
103 
104  LOG_INFO << "Loaded tofSimResParams. Average = " << mAverageTimeResTof << endm;
105  return;
106  }
107  else
108  {
109  LOG_WARN << "ERROR: dataset does not contain requested table" << endm;
110  return;
111  }
112 
113  } // loadParams
114 
115  protected:
116  double params[120][192];
117  double mAverageTimeResTof;
118 };
119 
120 #endif /* Config_h */
double timeres_tof(unsigned int itray, unsigned int imodule, unsigned int icell)
void loadParams(const int runNumber=20076002)
Loads BTOF Sim Params from database.
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362