StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StVpdSimConfig.h
1 //
2 // StVpdSimConfig.h
3 //
4 //
5 // Created by Nickolas Luttrell on 6/21/16.
6 //
7 //
8 
9 #ifndef StVpdSimConfig_h
10 #define StVpdSimConfig_h
11 
12 #include <iostream>
13 #include <fstream>
14 #include <vector>
15 #include "St_db_Maker/St_db_Maker.h"
16 #include "tables/St_vpdSimParams_Table.h"
17 #include "phys_constants.h"
18 #include <TRandom3.h>
19 
20 using std::string;
21 class vpdSimParams_st;
22 
23 class StVpdSimConfig : public StMaker {
24 public:
25 
26  StVpdSimConfig() {}
27  ~StVpdSimConfig() {}
28 
31  float singleTubeRes;
32  int tubeId,
35  };
36 
44  double singleTubeRes(UInt_t mVPDHitPatternEast, UInt_t mVPDHitPatternWest){
45  double vpdResSumSqr(0.),
46  vpdresolution(0.);
47  int total_vpd_hits = 0; //Total number of vpd tubes used.
48  for (int i=0; i<19; i++){
49  if (1 << i & mVPDHitPatternEast) {
50  vpdResSumSqr += (mSimParams[i].singleTubeRes)*(mSimParams[i].singleTubeRes);
51  total_vpd_hits += 1;
52  }
53  if (1 << i & mVPDHitPatternWest) {
54  vpdResSumSqr += (mSimParams[i+19].singleTubeRes)*(mSimParams[i+19].singleTubeRes);
55  total_vpd_hits += 1;
56  }
57  }
58  vpdresolution = sqrt(vpdResSumSqr)/total_vpd_hits;
59  return vpdresolution;
60  }
61 
66  double getVpdResolution(int nWest, int nEast) {
68  double randNum = 0;
69  double vpdRes = 0;
70  int counter = 0;
71  double tSum = 0;
72 
73  TRandom3 randEngine(0);
74 
75 
76  // this can be further improved to just use the tube resolution when sampling, like is done in VPD Sim Maker
77  for (int i=0; i<MAX_ARRAY_INDEX; i++) {
78  if (mSimParams[i].tubeStatusFlag) {
79  vpdRes += mSimParams[i].singleTubeRes;
80  counter += 1;
81  }
82  }
83 
84  if (counter != 0) {
85  vpdRes = vpdRes/counter;
86  }
87  else {
88  LOG_WARN << "No resolutions found in DB! Using DEFAULT avg of 120 ps single tube res- maybe a terrible guess for your dataset!" << endm;
89  vpdRes = 120;
90  }
91 
92  if ( 0 == nWest && 0 == nEast ){
93  LOG_WARN << "No VPD tubes hit, resolution = 999" << endm;
94  return -999;
95  }
96 
97  for (int j=0;j< (nWest + nEast); j++) {
98  randNum = randEngine.Gaus(0, vpdRes);
99  tSum += randNum;
100  }
101 
102  float result = tSum / ((float)(nWest + nEast));
103  LOG_INFO << "tof blur from vpd resolution (nEast + nWest = " << (nEast+nWest) << ": " << result << endm;
104  return result;
105  }
106 
108 
109  void loadVpdSimParams(const int date = 20160913, const int time = 175725, const char* Default_time = "2016-09-13 17:57:25")
110  {
111 
112  St_db_Maker *dbMk = dynamic_cast<St_db_Maker*>( GetChain()->GetMakerInheritsFrom("St_db_Maker") );
113 
114  TDataSet *DB = GetDataBase("Calibrations/tof/vpdSimParams");
115 
116  if (!DB) {
117  LOG_WARN << "No data set found, creating new St_db_Maker... with date/time" << date << "/" << time << endm;
118  dbMk = new St_db_Maker("db", "MySQL:StarDb", "$STAR/StarDb");
119  dbMk->SetDebug();
120  dbMk->SetDateTime(date,time);
121  dbMk->SetFlavor("ofl");
122  dbMk->Init();
123  dbMk->Make();
124  }
125 
126  if (!DB) {
127  LOG_WARN << "Failed to connect to Database!" << endm;
128  return;
129  }
130 
131  St_vpdSimParams *dataset = 0;
132  dataset = (St_vpdSimParams*) DB->Find("vpdSimParams");
133 
134  if (dataset) {
135  TDatime val[3];
136  dbMk->GetValidity((TTable*)dataset,val);
137  vpdSimParams_st* table = static_cast<vpdSimParams_st*>(dataset->GetTable());
138 
141  for (int i = 0; i < MAX_ARRAY_INDEX; i++) {
142  params.tubeId = table->tubeID[i];
143  params.singleTubeRes = table->tubeRes[i];
144  params.tubeStatusFlag = table->tubeStatusFlag[i];
145  params.tubeTriggerFlag = table->tubeTriggerFlag[i];
146  mSimParams[table->tubeID[i]] = params;
147  }
148 
149  return;
150  }
151  else {
152  LOG_WARN << "ERROR: dataset does not contain requested table" << endm;
153  return;
154  }
155  }
156 
160  void loadVpdSimParams(string params_filename ) {
161 
162  int MAX_DB_INDEX = 38;
163 
164  int vpdTubeRes;
165  int vpdTubeId;
166  int vpdTubeStatusFlag;
167  int vpdTubeTriggerFlag;
168 
170 
171  std::ifstream inData;
172  inData.open( params_filename.c_str() );
173 
174  for (int i = 0; i < MAX_DB_INDEX; i++) {
175  inData >> vpdTubeId >> vpdTubeRes >> vpdTubeStatusFlag >> vpdTubeTriggerFlag;
176  params.tubeId = vpdTubeId;
177  params.singleTubeRes = vpdTubeRes;
178  params.tubeStatusFlag = vpdTubeStatusFlag;
179  params.tubeTriggerFlag = vpdTubeTriggerFlag;
180  mSimParams[params.tubeId] = params;
181  }
182 
183  inData.close();
184  return;
185  }
186 
187  std::map<int, SingleTubeParams> getParams(){
188  return mSimParams;
189  }
190 
191  float getThreshold() const { return mThreshold; }
192  float getVpdDistance() const { return VPDDISTANCE; }
193  float getTDiffCut() const { return TDIFFCUT; }
194  float getMcClock() const { return kMcClock; }
195 
196 protected:
197 
199  std::map<int, SingleTubeParams> mSimParams;
200  int mThreshold = 1;
201 
202  const int MAX_ARRAY_INDEX = 38;
203  const float VPDDISTANCE = 570;
204  const float TDIFFCUT = 0.8;
205  const float kMcClock = 570*1.e9/C_C_LIGHT;
206 };
207 
208 #endif /* Config_h */
double getVpdResolution(int nWest, int nEast)
int tubeTriggerFlag
Status flag for whether tube was triggered on (1) or not (0)
int tubeStatusFlag
Status flag for whether tube was active (1) or inactive (0)
std::map< int, SingleTubeParams > mSimParams
stores a map of the single tube params indexed on tubeId
virtual Int_t Make()
int mThreshold
Threshold value for a tube to recognize it as a true hit.
const float kMcClock
Standard clock for pure simulation in ns. This is present to match the clock of BTof hits...
int tubeId
Tube Id (number) [0,37] with west Vpd [0,18] and east Vpd [19,37].
const float VPDDISTANCE
Distance (in cm) of each Vpd from the zero point.
const float TDIFFCUT
Cut value for eliminating times with a significant deviation from avg.
Definition: TTable.h:48
void loadVpdSimParams(string params_filename)
float singleTubeRes
Resolution of a particular Vpd tube in ps.
void loadVpdSimParams(const int date=20160913, const int time=175725, const char *Default_time="2016-09-13 17:57:25")
Loads Vpd Sim Params from database.
double singleTubeRes(UInt_t mVPDHitPatternEast, UInt_t mVPDHitPatternWest)
Calculate correct resolution based on those tubes that were used.
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362
structure containing tube parameters