StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDetectorDbChairs.cxx
1 #include <assert.h>
2 #include <string.h>
3 #include "StDetectorDbMaker.h"
4 #include "TROOT.h"
5 #include "TEnv.h"
6 #include "TF1.h"
7 #include "TMath.h"
8 #include "TString.h"
9 #include "Math/SMatrix.h"
10 using namespace ROOT::Math;
11 
12 #include "TCernLib.h"
13 #include "St_db_Maker/St_db_Maker.h"
14 #if 0
15 #include "tables/St_tpcCorrection_Table.h"
16 #include "tables/St_pidCorrection_Table.h"
17 #include "tables/St_tpcSectorT0offset_Table.h"
18 #include "tables/St_tofTrayConfig_Table.h"
19 #define makeSTRING(PATH) # PATH
20 #define CHECKTABLED(C_STRUCT) \
21  if (table->InheritsFrom("St_" # C_STRUCT)) { \
22  St_ ## C_STRUCT *t = (St_ ## C_STRUCT *) table ; \
23  C_STRUCT ## _st *s = t->GetTable(); Nrows = s->nrows; \
24  C_STRUCT ## _st def = {0}; \
25  iprt = kFALSE; \
26  Int_t shift = 0; \
27  Int_t NrowSize = t->GetRowSize(); \
28  if (! strcmp(makeSTRING(C_STRUCT),"Survey")) {shift = 4; NrowSize = 12*8;} \
29  if (! strcmp(makeSTRING(C_STRUCT),"tpcSectorT0offset")) {for (Int_t i = 0; i < 24; i++) def.t0[i] = -22.257;} \
30  if (! strcmp(makeSTRING(C_STRUCT),"tofTrayConfig")) {def.entries = 120; for (Int_t i = 0; i < 120; i++) {def.iTray[i] = i+1; def.nModules[i] = 32;} \
31  for (Int_t i = 0; i < table->GetNRows(); i++, s++) { \
32  if (memcmp(&def+shift, s+shift, NrowSize)) {iprt = kTRUE; break;} \
33  } \
34  }
35 }
36 #define DEBUGTABLE(STRUCT) \
37  TDatime t[2]; \
38  Bool_t iprt = kTRUE; \
39  Int_t Nrows = -1; \
40  if (St_db_Maker::GetValidity(table,t) > 0) { \
41  if (table->InheritsFrom("St_tpcCorrection") ) { \
42  St_tpcCorrection *tt = (St_tpcCorrection *) table; \
43  tpcCorrection_st *s = tt->GetTable(); Nrows = s->nrows; \
44  } else if (table->InheritsFrom("St_pidCorrection") ) { \
45  St_pidCorrection *tt = (St_pidCorrection *) table; \
46  pidCorrection_st *s = tt->GetTable(); Nrows = s->nrows; \
47  } \
48  LOG_WARN << "St_" << makeSTRING(STRUCT) << "C::instance found table " << table->GetName() \
49  << " with NRows = " << Nrows << " in db" \
50  << Form("\tValidity:%8i.%06i",t[0].GetDate(),t[0].GetTime()) \
51  << Form(" - %8i.%06i",t[1].GetDate(),t[1].GetTime()) << endm; \
52  if (Nrows > 10) Nrows = 10; \
53  CHECKTABLED(tpcCorrection); \
54  CHECKTABLED(tpcHVPlanes); \
55  CHECKTABLED(Survey); \
56  CHECKTABLED(tpcSectorT0offset); \
57  CHECKTABLED(tofTrayConfig); \
58  if (iprt) { \
59  if (table->GetRowSize() < 512) table->Print(0,Nrows); \
60  } else { \
61  LOG_WARN << "Default table" << endm; \
62  } \
63  }
64 //___________________Debug Print out _____________________________________________________________
65 #endif
66 #include "StarChairDefs.h"
67 static Int_t _debug = 0;
68 
69 //___________________Calibrations/ftpc_____________________________________________________________
70 #include "StDetectorDbFTPCGas.h"
71 StDetectorDbFTPCGas* StDetectorDbFTPCGas::fgInstance = 0;
72 #include "St_ftpcGasSystemC.h"
73 MakeChairInstance(ftpcGasSystem,Calibrations/ftpc/ftpcGasSystem);
74 #include "St_ftpcGasOutC.h"
75 MakeChairInstance(ftpcGasOut,Calibrations/ftpc/ftpcGasOut);
76 #include "St_ftpcVoltageC.h"
77 MakeChairInstance(ftpcVoltage,Calibrations/ftpc/ftpcVoltage);
78 #include "St_ftpcVoltageStatusC.h"
79 MakeChairInstance(ftpcVoltageStatus,Calibrations/ftpc/ftpcVoltageStatus);
80 //__________________Calibrations/tpc______________________________________________________________
81 #include "St_tpcGasC.h"
82 MakeChairInstance(tpcGas,Calibrations/tpc/tpcGas);
83 #include "St_TpcEffectivedXC.h"
84 MakeChairInstance(TpcEffectivedX,Calibrations/tpc/TpcEffectivedX);
85 #include "St_tpcGridLeakC.h"
86 MakeChairInstance(tpcGridLeak,Calibrations/tpc/tpcGridLeak);
87 #include "St_tpcOmegaTauC.h"
88 MakeChairInstance(tpcOmegaTau,Calibrations/tpc/tpcOmegaTau);
89 #include "St_tpcDriftVelocityC.h"
90 #include "St_starClockOnlC.h"
91 MakeChairInstance(tpcDriftVelocity,Calibrations/tpc/tpcDriftVelocity);
92 Float_t St_tpcDriftVelocityC::timeBucketPitch(Int_t i) {
93  return laserDriftVelocityEast(i)/St_starClockOnlC::instance()->Frequency()*1e6; // cm
94 }
95 #include "St_TpcSecRowCorC.h"
96 ClassImp(St_TpcSecRowCorC);
97 #include "St_TpcSecRowBC.h"
98 MakeChairInstance2(TpcSecRowCor,St_TpcSecRowBC,Calibrations/tpc/TpcSecRowB);
99 #include "St_TpcSecRowCC.h"
100 MakeChairOptionalInstance2(TpcSecRowCor,St_TpcSecRowCC,Calibrations/tpc/TpcSecRowC);
101 #include "St_TpcSecRowXC.h"
102 MakeChairInstance2(TpcSecRowCor,St_TpcSecRowXC,Calibrations/tpc/TpcSecRowX);
103 #include "St_tpcCorrectionC.h"
104 #include "St_tpcCalibResolutionsC.h"
105 MakeChairInstance(tpcCalibResolutions,Calibrations/tpc/tpcCalibResolutions);
106 #include "St_tpcChargeEventC.h"
107 MakeChairInstance(tpcChargeEvent,Calibrations/tpc/tpcChargeEvent);
108 #include "St_tpcSCGLC.h"
109 MakeChairInstance(tpcSCGL,Calibrations/tpc/tpcSCGL);
110 ClassImp(St_tpcCorrectionC);
111 //________________________________________________________________________________
112 Double_t St_tpcCorrectionC::CalcCorrection(Int_t i, Double_t x, Double_t z, Int_t NparMax) const {
113  tpcCorrection_st *cor = ((St_tpcCorrection *) Table())->GetTable() + i;
114  return SumSeries(cor, x, z, NparMax);
115 }
116 //________________________________________________________________________________
117 Double_t St_tpcCorrectionC::CalcXDerivative(Int_t i, Double_t x, Double_t z, Int_t NparMax) const {
118  tpcCorrection_st *cor = ((St_tpcCorrection *) Table())->GetTable() + i;
119  return SumSeriesXDerivative(cor, x, z, NparMax);
120 }
121 //________________________________________________________________________________
122 Double_t St_tpcCorrectionC::SumSeries(tpcCorrection_st *cor, Double_t x, Double_t z, Int_t NparMax) const {
123  Double_t Sum = 0;
124  if (! cor) return Sum;
125  Int_t N = TMath::Abs(cor->npar)%100;
126  if (N == 0) return Sum;
127  if (NparMax > 0) N = NparMax;
128  static Double_t T0, T1, T2;
129  // parameterization variable
130  Double_t X = x;
131  if (cor->npar < 0) X = TMath::Exp(x);
132  else {
133  switch (cor->type) {
134  case 10:// ADC correction offset + poly for ADC
135  case 11:// ADC correction offset + poly for log(ADC) and |Z|
136  case 12:// ADC correction offset + poly for log(ADC) and TanL
137  case 13:// ADC correction without off set TF1 *F = new TF1("F","[0]+TMath::Exp([1]+[2]*TMath::Exp(x))",3,10) and offset correction via TpcAdcCorrection6MDF
138  X = TMath::Log(x); break;
139  case 1: // Tchebyshev [-1,1]
140  if (cor->min < cor->max) X = -1 + 2*TMath::Max(0.,TMath::Min(1.,(X - cor->min)/( cor->max - cor->min)));
141  break;
142  case 2: // Shifted TChebyshev [0,1]
143  if (cor->min < cor->max) X = TMath::Max(0.,TMath::Min(1.,(X - cor->min)/( cor->max - cor->min)));
144  break;
145  case 3:
146  if (TMath::Abs(x) >= 1) X = 0;
147  else X = TMath::Log(1. - TMath::Abs(x));
148  break;
149  case 4:
150  if (TMath::Abs(x) >= 1) X = 0;
151  else X = TMath::Sign(TMath::Log(1. - TMath::Abs(x)),x);
152  break;
153  case 5:
154  if (x < 1e-7) X = -16.118;
155  else X = TMath::Log(x);
156  break;
157  case 6:
158  X = TMath::Abs(x);
159  break;
160  default: X = x; break;
161  }
162  }
163  if (cor->type != 1 && cor->type != 2 &&
164  cor->min < cor->max) {
165  if (X < cor->min) X = cor->min;
166  if (X > cor->max) X = cor->max;
167  }
168  static TF1 *f1000 = 0, *f1100 = 0, *f1200 = 0, *f1300 = 0, *f1400 = 0, *f1500 = 0;
169  static TF1 *f2000 = 0, *f2100 = 0, *f2200 = 0, *f2300 = 0, *f2400 = 0, *f2500 = 0;
170  TF1 *f = 0;
171  switch (cor->type) {
172  case 1: // Tchebyshev [-1,1]
173  T0 = 1;
174  Sum = cor->a[0]*T0;
175  if (N == 1) break;
176  T1 = X;
177  Sum += cor->a[1]*T1;
178  for (int n = 2; n <= N; n++) {
179  T2 = 2*X*T1 - T0;
180  Sum += cor->a[n]*T2;
181  T0 = T1;
182  T1 = T2;
183  }
184  break;
185  case 2: // Shifted TChebyshev [0,1]
186  T0 = 1;
187  Sum = cor->a[0]*T0;
188  if (N == 1) break;
189  T1 = 2*X - 1;
190  Sum += cor->a[1]*T1;
191  for (int n = 2; n <= N; n++) {
192  T2 = 2*(2*X - 1)*T1 - T0;
193  Sum += cor->a[n]*T2;
194  T0 = T1;
195  T1 = T2;
196  }
197  break;
198  case 10: // ADC correction offset + poly for ADC
199  Sum = cor->a[N-1];
200  for (int n = N-2; n>=0; n--) Sum = X*Sum + cor->a[n];
201  Sum += TMath::Log(1. + cor->OffSet/x);
202  Sum = TMath::Exp(Sum);
203  Sum *= x;
204  break;
205  case 11: // ADC correction offset + poly for log(ADC) and |Z|
206  Sum = cor->a[1] + z*cor->a[2] + z*X*cor->a[3] + TMath::Exp(X*(cor->a[4] + X*cor->a[5]) + cor->a[6]);
207  Sum *= TMath::Exp(-cor->a[0]);
208  break;
209  case 12: // ADC correction offset + poly for log(ADC) and TanL
210  Sum = cor->a[1] + z*cor->a[2] + z*z*cor->a[3] + TMath::Exp(X*(cor->a[4] + X*cor->a[5]) + cor->a[6]);
211  Sum *= TMath::Exp(-cor->a[0]);
212  break;
213  case 13: // ADC correction and offset correction via TpcAdcCorrection6MDF
214  Sum = x * TMath::Exp(cor->a[0] + cor->a[1] + TMath::Exp(cor->a[2] + cor->a[3]*x));
215  break;
216  case 30: // TanH saturation function: [0]+[1]*TMath::TanH([2]*(x-[3]))
217  Sum = cor->a[0]+cor->a[1]*TMath::TanH(cor->a[2]*(x-cor->a[3]));
218  break;
219  case 1000:
220  case 1100:
221  case 1200:
222  case 1300:
223  case 1400:
224  case 1500:
225  if (cor->type == 1000) {
226  if (! f1000) f1000 = new TF1("f1000","gaus+pol0(3)");
227  f = f1000;
228  } else if (cor->type == 1100) {
229  if (! f1100) f1100 = new TF1("f1100","gaus+pol1(3)");
230  f = f1100;
231  } else if (cor->type == 1200) {
232  if (! f1200) f1200 = new TF1("f1200","gaus+pol2(3)");
233  f = f1200;
234  } else if (cor->type == 1300) {
235  if (! f1300) f1300 = new TF1("f1300","gaus+pol3(3)");
236  f = f1300;
237  } else if (cor->type == 1400) {
238  if (! f1400) f1400 = new TF1("f1400","gaus+pol4(3)");
239  f = f1400;
240  } else if (cor->type == 1500) {
241  if (! f1500) f1500 = new TF1("f1500","gaus+pol5(3)");
242  f = f1500;
243  }
244  assert(f);
245  f->SetParameters(cor->a);
246  Sum = f->Eval(X);
247  break;
248  case 2000:
249  case 2100:
250  case 2200:
251  case 2300:
252  case 2400:
253  case 2500:
254  if (cor->type == 2000) {
255  if (! f2000) f2000 = new TF1("f2000","expo+pol0(2)");
256  f = f2000;
257  } else if (cor->type == 2100) {
258  if (! f2100) f2100 = new TF1("f2100","expo+pol1(2)");
259  f = f2100;
260  } else if (cor->type == 2200) {
261  if (! f2200) f2200 = new TF1("f2200","expo+pol2(2)");
262  f = f2200;
263  } else if (cor->type == 2300) {
264  if (! f2300) f2300 = new TF1("f2300","expo+pol3(2)");
265  f = f2300;
266  } else if (cor->type == 2400) {
267  if (! f2400) f2400 = new TF1("f2400","expo+pol4(2)");
268  f = f2400;
269  } else if (cor->type == 2500) {
270  if (! f2500) f2500 = new TF1("f2500","expo+pol5(2)");
271  f = f2500;
272  }
273  assert(f);
274  f->SetParameters(cor->a);
275  Sum = f->Eval(X);
276  break;
277  default: // polynomials
278  Sum = cor->a[N-1];
279  for (int n = N-2; n>=0; n--) Sum = X*Sum + cor->a[n];
280  break;
281  }
282  return Sum;
283 }
284 //________________________________________________________________________________
285 Double_t St_tpcCorrectionC::SumSeriesXDerivative(tpcCorrection_st *cor, Double_t x, Double_t z, Int_t NparMax) const {
286  // Only for polynomials for now
287  Double_t Sum = 0;
288  if (! cor) return Sum;
289  Int_t N = TMath::Abs(cor->npar)%100;
290  if (N == 0) return Sum;
291  if (NparMax > 0) N = NparMax;
292  // parameterization variable
293  Double_t X = x;
294  Double_t Jacobian = 1;
295  if (cor->npar < 0) {X = TMath::Exp(x); Jacobian = X;}
296  else {
297  switch (cor->type) {
298  case 10:// ADC correction offset + poly for ADC
299  case 11:// ADC correction offset + poly for log(ADC) and |Z|
300  case 12:// ADC correction offset + poly for log(ADC) and TanL
301  case 13:// ADC correction without off set TF1 *F = new TF1("F","[0]+TMath::Exp([1]+[2]*TMath::Exp(x))",3,10) and offset correction via TpcAdcCorrection6MDF
302  X = TMath::Log(x);
303  Jacobian = 1./x;
304  break;
305  case 1: // Tchebyshev [-1,1]
306  if (cor->min < cor->max) X = -1 + 2*TMath::Max(0.,TMath::Min(1.,(X - cor->min)/( cor->max - cor->min)));
307  Jacobian = 0;
308  break;
309  case 2: // Shifted TChebyshev [0,1]
310  if (cor->min < cor->max) X = TMath::Max(0.,TMath::Min(1.,(X - cor->min)/( cor->max - cor->min)));
311  Jacobian = 0;
312  break;
313  case 3:
314  if (TMath::Abs(x) >= 1) X = 0;
315  else X = TMath::Log(1. - TMath::Abs(x));
316  Jacobian = 0;
317  break;
318  case 4:
319  if (TMath::Abs(x) >= 1) X = 0;
320  else X = TMath::Sign(TMath::Log(1. - TMath::Abs(x)),x);
321  Jacobian = 0;
322  break;
323  case 5:
324  if (x < 1e-7) X = -16.118;
325  else X = TMath::Log(x);
326  Jacobian = TMath::Exp(-X);
327  break;
328  case 6:
329  X = TMath::Abs(x);
330  Jacobian = TMath::Sign(1., x);
331  break;
332  default: X = x; break;
333  }
334  }
335  if (TMath::Abs(Jacobian) < 1e-7) return 0;
336  if (cor->type != 1 && cor->type != 2 &&
337  cor->min < cor->max) {
338  if (X < cor->min) X = cor->min;
339  if (X > cor->max) X = cor->max;
340  }
341  Sum = cor->a[N-1] * (N - 1);
342  for (int n = N-2; n>=1; n--) Sum = X*Sum + cor->a[n] * n;
343  Sum *= Jacobian;
344  return Sum;
345 }
346 //________________________________________________________________________________
347 Int_t St_tpcCorrectionC::IsActiveChair() const {
348  const St_tpcCorrection *tableC = (const St_tpcCorrection *) Table();
349  Int_t npar = 0;
350  if (! tableC) return npar;
351  tpcCorrection_st *cor = tableC->GetTable();
352  Int_t N = tableC->GetNRows();
353  if (! cor || ! N) {
354  return npar;
355  }
356  N = cor->nrows;
357  for (Int_t i = 0; i < N; i++, cor++) {
358  if (cor->nrows == 0 && cor->idx == 0) continue;
359  if (TMath::Abs(cor->npar) > 0 ||
360  TMath::Abs(cor->OffSet) > 1.e-7 ||
361  TMath::Abs(cor->min) > 1.e-7 ||
362  TMath::Abs(cor->max) > 1.e-7) {
363  npar++;
364  }
365  }
366  return npar;
367 }
368 #include "St_pidCorrectionC.h"
369 MakeChairInstance2(pidCorrection,St_pidCorrectionC,dEdxModel/PiDC/pidCorrection);
370 //________________________________________________________________________________
371 Double_t St_pidCorrectionC::CalcCorrection(Int_t i, Double_t x, Double_t z, Int_t NparMax) const {
372  pidCorrection_st *cor = ((St_pidCorrection *) Table())->GetTable() + i;
373  return SumSeries(cor, x, z, NparMax);
374 }
375 //________________________________________________________________________________
376 Double_t St_pidCorrectionC::SumSeries(pidCorrection_st *cor, Double_t x, Double_t z, Int_t NparMax) const {
377  Double_t Sum = 0;
378  if (! cor) return Sum;
379  Int_t N = TMath::Abs(cor->npar)%100;
380  if (N == 0) return Sum;
381  if (NparMax > 0) N = NparMax;
382  Double_t X = x;
383  if (X < cor->min) return Sum;
384  if (X > cor->max) return Sum;
385  Double_t T0, T1, T2;
386  switch (cor->type) {
387  case 1: // Tchebyshev [-1,1]
388  if (cor->min < cor->max) X = -1 + 2*TMath::Max(0.,TMath::Min(1.,(X - cor->min)/( cor->max - cor->min)));
389  T0 = 1;
390  Sum = cor->a[0]*T0;
391  if (N == 1) break;
392  T1 = X;
393  Sum += cor->a[1]*T1;
394  for (int n = 2; n <= N; n++) {
395  T2 = 2*X*T1 - T0;
396  Sum += cor->a[n]*T2;
397  T0 = T1;
398  T1 = T2;
399  }
400  break;
401  case 2: // Shifted TChebyshev [0,1]
402  if (cor->min < cor->max) X = TMath::Max(0.,TMath::Min(1.,(X - cor->min)/( cor->max - cor->min)));
403  T0 = 1;
404  Sum = cor->a[0]*T0;
405  if (N == 1) break;
406  T1 = 2*X - 1;
407  Sum += cor->a[1]*T1;
408  for (int n = 2; n <= N; n++) {
409  T2 = 2*(2*X - 1)*T1 - T0;
410  Sum += cor->a[n]*T2;
411  T0 = T1;
412  T1 = T2;
413  }
414  break;
415  default: // polynomials
416  Sum = cor->a[N-1];
417  for (int n = N-2; n>=0; n--) Sum = X*Sum + cor->a[n];
418  break;
419  }
420  return Sum;
421 }
422 //________________________________________________________________________________
423 Int_t St_pidCorrectionC::IsActiveChair() const {
424  const St_pidCorrection *tableC = (const St_pidCorrection *) Table();
425  Int_t npar = 0;
426  if (! tableC) return npar;
427  pidCorrection_st *cor = tableC->GetTable();
428  Int_t N = tableC->GetNRows();
429  if (! cor || ! N) {
430  return npar;
431  }
432  N = cor->nrows;
433  for (Int_t i = 0; i < N; i++, cor++) {
434  if (cor->nrows == 0 && cor->idx == 0) continue;
435  if (TMath::Abs(cor->npar) > 0 ||
436  TMath::Abs(cor->OffSet) > 1.e-7 ||
437  TMath::Abs(cor->min) > 1.e-7 ||
438  TMath::Abs(cor->max) > 1.e-7) {
439  npar++;
440  }
441  }
442  return npar;
443 }
444 //________________________________________________________________________________
445 Double_t St_pidCorrectionC::Correction(Double_t X, Int_t part, Int_t det, Int_t charge, Int_t pull, Int_t varT) {
446  Int_t N = nrows();
447  Double_t Correction = 0;
448  for (Int_t l = 0; l < N; l++) {
449  pidCorrection_st *row = Struct(l);
450  if (part != row->particle) continue;
451  if (det != row->det) continue;
452  if (pull != row->pull) continue;
453  if (varT != row->var) continue;
454  if (row->charge != 0 && charge != row->charge) continue;
455  if (row->min < row->max && (X < row->min || X > row->max)) continue;
456  // Correction += CalcCorrection(l, X);
457  Correction += SumSeries(row, X);
458  }
459  return TMath::Exp(Correction);
460 }
461 //________________________________________________________________________________
462 Double_t St_pidCorrectionC::func(Double_t *x, Double_t *p) {
463  Int_t part = p[0];
464  Int_t det = p[1];
465  Int_t charge = p[2];
466  Int_t pull = p[3];
467  Int_t varT = p[4];
468  return TMath::Log(St_pidCorrectionC::instance()->Correction(x[0],part,det,charge,pull,varT));
469 }
470 //________________________________________________________________________________
471 TF1 *St_pidCorrectionC::Func(Int_t part, Int_t det, Int_t charge, Int_t pull, Int_t varT) {
472  TString fName(Form("pidCor_p%i_d%i_c%i_p%i_v%i",part,det,charge,pull,varT));
473  TF1 *f = (TF1 *) gROOT->GetListOfFunctions()->FindObject(fName);
474  if (! f) {
475  f = new TF1(fName, St_pidCorrectionC::func, -1.2, 0.9, 5);
476  if (! varT)
477  f->GetXaxis()->SetTitle("log_{10} P [GeV/c]");
478  else
479  f->GetXaxis()->SetTitle("log_{10} P/M");
480  f->FixParameter(0, part);
481  f->FixParameter(1, det);
482  f->FixParameter(2, charge);
483  f->FixParameter(3, pull);
484  f->FixParameter(4, varT);
485  }
486  return f;
487 }
488 #include "St_TpcRowQC.h"
489 MakeChairInstance2(tpcCorrection,St_TpcRowQC,Calibrations/tpc/TpcRowQ);
490 #include "St_TpcDriftDistOxygenC.h"
491 MakeChairInstance2(tpcCorrection,St_TpcDriftDistOxygenC,Calibrations/tpc/TpcDriftDistOxygen);
492 #include "St_TpcMultiplicityC.h"
493 MakeChairInstance2(tpcCorrection,St_TpcMultiplicityC,Calibrations/tpc/TpcMultiplicity);
494 #include "St_TpcZCorrectionBC.h"
495 MakeChairInstance2(tpcCorrection,St_TpcZCorrectionBC,Calibrations/tpc/TpcZCorrectionB);
496 #include "St_TpcZCorrectionCC.h"
497 MakeChairInstance2(tpcCorrection,St_TpcZCorrectionCC,Calibrations/tpc/TpcZCorrectionC);
498 #include "St_TpcdXCorrectionBC.h"
499 MakeChairInstance2(tpcCorrection,St_TpcdXCorrectionBC,Calibrations/tpc/TpcdXCorrectionB);
500 #include "St_TpcEtaCorrectionC.h"
501 MakeChairInstance2(tpcCorrection,St_TpcEtaCorrectionC,Calibrations/tpc/TpcEtaCorrection);
502 #include "St_TpcEtaCorrectionBC.h"
503 MakeChairInstance2(tpcCorrection,St_TpcEtaCorrectionBC,Calibrations/tpc/TpcEtaCorrectionB);
504 #include "St_tpcPressureBC.h"
505 MakeChairInstance2(tpcCorrection,St_tpcPressureBC,Calibrations/tpc/tpcPressureB);
506 //________________________________________________________________________________
507 #include "St_TpcPadPedRMSC.h"
508 MakeChairInstance2(tpcCorrection,St_TpcPadPedRMSC,Calibrations/tpc/TpcPadPedRMS);
509 #include "St_TpcEdgeC.h"
510 MakeChairInstance2(tpcCorrection,St_TpcEdgeC,Calibrations/tpc/TpcEdge);
511 #include "St_TpcAdcCorrectionBC.h"
512 MakeChairInstance2(tpcCorrection,St_TpcAdcCorrectionBC,Calibrations/tpc/TpcAdcCorrectionB);
513 #include "St_TpcAdcCorrectionCC.h"
514 MakeChairInstance2(tpcCorrection,St_TpcAdcCorrectionCC,Calibrations/tpc/TpcAdcCorrectionC);
515 #include "St_TpcAdcCorrectionMDF.h"
516 MakeChairInstance2(MDFCorrection,St_TpcAdcCorrectionMDF,Calibrations/tpc/TpcAdcCorrectionMDF);
517 #include "St_TpcAdcCorrection3MDF.h"
518 MakeChairInstance2(MDFCorrection3,St_TpcAdcCorrection3MDF,Calibrations/tpc/TpcAdcCorrection3MDF);
519 #include "St_TpcAdcCorrection4MDF.h"
520 MakeChairInstance2(MDFCorrection4,St_TpcAdcCorrection4MDF,Calibrations/tpc/TpcAdcCorrection4MDF);
521 #include "St_TpcAdcCorrection5MDF.h"
522 MakeChairInstance2(MDFCorrection4,St_TpcAdcCorrection5MDF,Calibrations/tpc/TpcAdcCorrection5MDF);
523 #include "St_TpcAdcCorrection6MDF.h"
524 MakeChairInstance2(MDFCorrection4,St_TpcAdcCorrection6MDF,Calibrations/tpc/TpcAdcCorrection6MDF);
525 #include "St_tpcMethaneInC.h"
526 MakeChairInstance2(tpcCorrection,St_tpcMethaneInC,Calibrations/tpc/tpcMethaneIn);
527 #include "St_tpcTimeBucketCorC.h"
528 MakeChairInstance2(tpcCorrection,St_tpcTimeBucketCorC,Calibrations/tpc/tpcTimeBucketCor);
529 #include "St_tpcGasTemperatureC.h"
530 MakeChairInstance2(tpcCorrection,St_tpcGasTemperatureC,Calibrations/tpc/tpcGasTemperature);
531 #include "St_tpcWaterOutC.h"
532 MakeChairInstance2(tpcCorrection,St_tpcWaterOutC,Calibrations/tpc/tpcWaterOut);
533 #include "St_tpcTimeDependenceC.h"
534 MakeChairInstance2(tpcCorrection,St_tpcTimeDependenceC,Calibrations/tpc/tpcTimeDependence);
535 #include "St_TpcdChargeC.h"
536 MakeChairOptionalInstance2(tpcCorrection,St_TpcdChargeC,Calibrations/tpc/TpcdCharge);
537 #include "St_TpcrChargeC.h"
538 MakeChairOptionalInstance2(tpcCorrection,St_TpcrChargeC,Calibrations/tpc/TpcrCharge);
539 #include "St_TpcTanLC.h"
540 MakeChairInstance2(tpcCorrection,St_TpcTanLC,Calibrations/tpc/TpcTanL);
541 #include "St_TpcAdcIC.h"
542 MakeChairInstance2(tpcCorrection,St_TpcAdcIC,Calibrations/tpc/TpcAdcI);
543 #include "St_TpcnPadC.h"
544 MakeChairInstance2(tpcCorrection,St_TpcnPadC,Calibrations/tpc/TpcnPad);
545 #include "St_TpcnTbkC.h"
546 MakeChairInstance2(tpcCorrection,St_TpcnTbkC,Calibrations/tpc/TpcnTbk);
547 #include "St_TpcdZdYC.h"
548 MakeChairInstance2(tpcCorrection,St_TpcdZdYC,Calibrations/tpc/TpcdZdY);
549 #include "St_TpcdXdYC.h"
550 MakeChairInstance2(tpcCorrection,St_TpcdXdYC,Calibrations/tpc/TpcdXdY);
551 #include "St_GatingGridC.h"
552 MakeChairInstance2(GatingGrid,St_GatingGridC,Calibrations/tpc/GatingGrid);
553 //________________________________________________________________________________
554 Double_t St_GatingGridC::CalcCorrection(Int_t i, Double_t x) {// drift time in microseconds
555  Double_t value = -10;
556  GatingGrid_st *cor = ((St_GatingGrid *) Table())->GetTable() + i;
557  if (x <= cor->t0) return value;
558  Double_t corD = 1. - TMath::Exp(-(x-cor->t0)/(cor->settingTime/4.6));
559  if (corD < 1e-4) return value;
560  return TMath::Log(corD);
561 }
562 #include "St_GatingGridBC.h"
563 MakeChairInstance2(tpcCorrection,St_GatingGridBC,Calibrations/tpc/GatingGridB);
564 //________________________________________________________________________________
565 Double_t St_GatingGridBC::CalcCorrection(Int_t i, Double_t x) {// drift time in microseconds
566  const tpcCorrection_st *s = Struct(i);
567  Double_t T0 = s->a[0];
568  Double_t SettingTime = s->a[1];
569  // Double_t tau = (x-t0(i))/(settingTime(i)/4.6);
570  Double_t tau = (x - T0)/(SettingTime/4.6);
571  if (tau > 10) return 0;
572  if (tau > 0) {
573  Double_t corD = 1. - TMath::Exp(-tau);
574  return TMath::Log(corD);
575  } else {
576  return -10;
577  }
578 }
579 #include "St_TpcCurrentCorrectionC.h"
580 //MakeChairInstance2(tpcCorrection,St_TpcCurrentCorrectionC,Calibrations/tpc/TpcCurrentCorrection);
581 ClassImp(St_TpcCurrentCorrectionC);
582 St_TpcCurrentCorrectionC *St_TpcCurrentCorrectionC::fgInstance = 0;
583 St_TpcCurrentCorrectionC *St_TpcCurrentCorrectionC::instance() {
584  if (fgInstance) return fgInstance;
585  St_tpcCorrection *table = (St_tpcCorrection *) StMaker::GetChain()->GetDataBase("Calibrations/tpc/TpcCurrentCorrectionX");
586  if (! table) table = (St_tpcCorrection *) StMaker::GetChain()->GetDataBase("Calibrations/tpc/TpcCurrentCorrection");
587  assert(table); DEBUGTABLE(tpcCorrection);
588  fgInstance = new St_TpcCurrentCorrectionC(table);
589  return fgInstance;
590 }
591 #include "St_TpcZDCC.h"
592 MakeChairInstance2(tpcCorrection,St_TpcZDCC,Calibrations/tpc/TpcZDC);
593 #include "St_TpcSpaceChargeC.h"
594 MakeChairInstance2(tpcCorrection,St_TpcSpaceChargeC,Calibrations/tpc/TpcSpaceCharge);
595 #include "St_TpcPhiDirectionC.h"
596 MakeChairInstance2(tpcCorrection,St_TpcPhiDirectionC,Calibrations/tpc/TpcPhiDirection);
597 #include "St_TpcdEdxCorC.h"
598 MakeChairInstance2(tpcCorrection,St_TpcdEdxCorC,Calibrations/tpc/TpcdEdxCor);
599 #include "St_TpcLengthCorrectionBC.h"
600 MakeChairInstance2(tpcCorrection,St_TpcLengthCorrectionBC,Calibrations/tpc/TpcLengthCorrectionB);
601 #include "St_TpcDriftVelRowCorC.h"
602 MakeChairInstance2(tpcCorrection,St_TpcDriftVelRowCorC,Calibrations/tpc/TpcDriftVelRowCor);
603 #include "St_TpcAccumulatedQC.h"
604 MakeChairInstance2(tpcCorrection,St_TpcAccumulatedQC,Calibrations/tpc/TpcAccumulatedQ);
605 #include "St_TpcLengthCorrectionMDF.h"
606 MakeChairInstance2(MDFCorrection,St_TpcLengthCorrectionMDF,Calibrations/tpc/TpcLengthCorrectionMDF);
607 #include "St_TpcLengthCorrectionMD2.h"
608 MakeChairInstance2(MDFCorrection,St_TpcLengthCorrectionMD2,Calibrations/tpc/TpcLengthCorrectionMD2);
609 #include "St_TpcLengthCorrectionMDN.h"
610 MakeChairInstance2(MDFCorrection,St_TpcLengthCorrectionMDN,Calibrations/tpc/TpcLengthCorrectionMDN);
611 #include "St_TpcPadCorrectionMDF.h"
612 MakeChairInstance2(MDFCorrection,St_TpcPadCorrectionMDF,Calibrations/tpc/TpcPadCorrectionMDF);
613 #include "St_TpcPadCorrectionMDC.h"
614 MakeChairInstance2(MDFCorrection,St_TpcPadCorrectionMDC,Calibrations/tpc/TpcPadCorrectionMDC);
615 ClassImp(St_MDFCorrectionC);
616 St_MDFCorrectionC *St_MDFCorrectionC::fgMDFCorrectionC = 0;
617 //____________________________________________________________________
618 St_MDFCorrectionC::St_MDFCorrectionC(St_MDFCorrection *table) : TChair(table), fFunc(0) {
619  UInt_t N = table->GetNRows();
620  fFunc = new TF1*[N];
621  memset(fFunc, 0, N*sizeof(TF1*));
622 }
623 //____________________________________________________________________
624 St_MDFCorrectionC::~St_MDFCorrectionC() {
625  UInt_t N = Table()->GetNRows();
626  for (UInt_t i = 0; i < N; i++) {SafeDelete(fFunc[i]);}
627  delete [] fFunc;
628 }
629 //____________________________________________________________________
630 Double_t St_MDFCorrectionC::MDFunc(Double_t *x, Double_t *p) {
631  // Evaluate parameterization at point x. Optional argument coeff is
632  // a vector of coefficients for the parameterisation, NCoefficients
633  // elements long.
634  assert(x);
635  UInt_t k = p[0];
636  assert(k >= 0 && k < fgMDFCorrectionC->getNumRows());
637  Double_t returnValue = fgMDFCorrectionC->DMean(k);
638  Double_t term = 0;
639  UChar_t i, j;
640  for (i = 0; i < fgMDFCorrectionC->NCoefficients(k); i++) {
641  // Evaluate the ith term in the expansion
642  term = fgMDFCorrectionC->Coefficients(k)[i];
643  for (j = 0; j < fgMDFCorrectionC->NVariables(k); j++) {
644  // Evaluate the factor (polynomial) in the j-th variable.
645  Int_t p = fgMDFCorrectionC->Powers(k)[i * fgMDFCorrectionC->NVariables(k) + j];
646  Double_t y = 1 + 2. / (fgMDFCorrectionC->XMax(k)[j] - fgMDFCorrectionC->XMin(k)[j])
647  * (x[j] - fgMDFCorrectionC->XMax(k)[j]);
648  term *= fgMDFCorrectionC->EvalFactor(k,p,y);
649  }
650  // Add this term to the final result
651  returnValue += term;
652  }
653  return returnValue;
654 }
655 
656 //____________________________________________________________________
657 Double_t St_MDFCorrectionC::Eval(Int_t k, Double_t x0, Double_t x1) const {
658  Double_t x[2] = {x0, x1};
659  return Eval(k,x);
660 }
661 //____________________________________________________________________
662 Double_t St_MDFCorrectionC::Eval(Int_t k, Double_t *x) const {
663  // Evaluate parameterization at point x. Optional argument coeff is
664  // a vector of coefficients for the parameterisation, NCoefficients
665  // elements long.
666  assert(x);
667  if (! fFunc[k]) {
668  fgMDFCorrectionC = (St_MDFCorrectionC *) this;
669  if (_debug) {
670  MDFCorrection_st *corK = fgMDFCorrectionC->Struct(k);
671  cout << Table()->GetName() << " k = " << k << " Idx = " << (Int_t) corK->idx << " Nvar = " << corK->NVariables << " type = " << corK->PolyType;
672  for (Int_t v = 0; v < corK->NVariables; v++) {
673  cout << "\t" << v << " min = " << corK->XMin[v] << " max = " << corK->XMax[v];
674  }
675  cout << endl;
676  }
677  if (NVariables(k) <= 0) {
678  return 0;
679  } else if (NVariables(k) == 1) {
680  fFunc[k] = new TF1(Form("%s_%i",Table()->GetName(),k),St_MDFCorrectionC::MDFunc,
681  XMin(k)[0],XMax(k)[0],1);
682  fFunc[k]->SetParameter(0,k);
683  fFunc[k]->Save(XMin(k)[0],XMax(k)[0],0,0,0,0);
684  } else if (NVariables(k) == 2) {
685  fFunc[k] = new TF2(Form("%s_%i",Table()->GetName(),k),St_MDFCorrectionC::MDFunc,
686  XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],1);
687  fFunc[k]->SetParameter(0,k);
688  ((TF2 *) fFunc[k])->Save(XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],0,0);
689  } else if (NVariables(k) == 3) {
690  fFunc[k] = new TF3(Form("%s_%i",Table()->GetName(),k),St_MDFCorrectionC::MDFunc,
691  XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],XMin(k)[2],XMax(k)[2],1);
692  fFunc[k]->SetParameter(0,k);
693  ((TF3 *) fFunc[k])->Save(XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],XMin(k)[2],XMax(k)[2]);
694  }
695  }
696  Double_t xx[3];
697  for (Int_t v = 0; v < NVariables(k); v++) {
698  xx[v] = TMath::Max(XMin(k)[v], TMath::Min(XMin(k)[v]+0.999*(XMax(k)[v]-XMin(k)[v]), x[v]));
699  }
700  Double_t returnValue = fFunc[k]->GetSave(xx);
701  return returnValue;
702 }
703 //____________________________________________________________________
704 Double_t St_MDFCorrectionC::EvalError(Int_t k, Double_t *x) const {
705  // Evaluate parameterization error at point x. Optional argument coeff is
706  // a vector of coefficients for the parameterisation, NCoefficients(k)
707  // elements long.
708  assert(x);
709  Double_t returnValue = 0;
710  Double_t term = 0;
711  UChar_t i, j;
712  for (i = 0; i < NCoefficients(k); i++) {
713  // Evaluate the ith term in the expansion
714  term = CoefficientsRMS(k)[i];
715  for (j = 0; j < NVariables(k); j++) {
716  // Evaluate the factor (polynomial) in the j-th variable.
717  Int_t p = Powers(k)[i * NVariables(k) + j];
718  Double_t y = 1 + 2. / (XMax(k)[j] - XMin(k)[j])
719  * (x[j] - XMax(k)[j]);
720  term *= EvalFactor(p,y);
721  }
722  // Add this term to the final result
723  returnValue += term*term;
724  }
725  returnValue = TMath::Sqrt(returnValue);
726  return returnValue;
727 }
728 //____________________________________________________________________
729 Double_t St_MDFCorrectionC::EvalFactor(Int_t k, Int_t p, Double_t x) const {
730  // Evaluate function with power p at variable value x
731  Int_t i = 0;
732  Double_t p1 = 1;
733  Double_t p2 = 0;
734  Double_t p3 = 0;
735  Double_t r = 0;
736 
737  switch(p) {
738  case 1:
739  r = 1;
740  break;
741  case 2:
742  r = x;
743  break;
744  default:
745  p2 = x;
746  for (i = 3; i <= p; i++) {
747  p3 = p2 * x;
748  if (PolyType(k) == kLegendre)
749  p3 = ((2 * i - 3) * p2 * x - (i - 2) * p1) / (i - 1);
750  else if (PolyType(k) == kChebyshev)
751  p3 = 2 * x * p2 - p1;
752  p1 = p2;
753  p2 = p3;
754  }
755  r = p3;
756  }
757  return r;
758 }
759 //________________________________________________________________________________
760 Int_t St_MDFCorrectionC::IsActiveChair() const {
761  Int_t npar = 0;
762  const St_MDFCorrection *tableMDF = (const St_MDFCorrection *) Table();
763  if (! tableMDF) return npar;
764  MDFCorrection_st *corMDF = tableMDF->GetTable();
765  Int_t N = tableMDF->GetNRows();
766  if (! corMDF || ! N) {
767  return npar;
768  }
769  for (Int_t i = 0; i < N; i++, corMDF++) {
770  if (corMDF->nrows == 0 && corMDF->idx == 0) continue;
771  npar++;
772  }
773  return npar;
774 }
775 //________________________________________________________________________________
776 //________________________________________________________________________________
777 ClassImp(St_MDFCorrection3C);
778 St_MDFCorrection3C *St_MDFCorrection3C::fgMDFCorrection3C = 0;
779 //____________________________________________________________________
780 St_MDFCorrection3C::St_MDFCorrection3C(St_MDFCorrection3 *table) : TChair(table), fFunc(0) {
781  UInt_t N = table->GetNRows();
782  fFunc = new TF1*[N];
783  memset(fFunc, 0, N*sizeof(TF1*));
784 }
785 //____________________________________________________________________
786 St_MDFCorrection3C::~St_MDFCorrection3C() {
787  UInt_t N = Table()->GetNRows();
788  for (UInt_t i = 0; i < N; i++) {SafeDelete(fFunc[i]);}
789  delete [] fFunc;
790 }
791 //____________________________________________________________________
792 Double_t St_MDFCorrection3C::MDFunc(Double_t *x, Double_t *p) {
793  // Evaluate parameterization at point x. Optional argument coeff is
794  // a vector of coefficients for the parameterisation, NCoefficients
795  // elements long.
796  assert(x);
797  UInt_t k = p[0];
798  assert(k >= 0 && k < fgMDFCorrection3C->getNumRows());
799  Double_t returnValue = fgMDFCorrection3C->DMean(k);
800  Double_t term = 0;
801  UChar_t i, j;
802  for (i = 0; i < fgMDFCorrection3C->NCoefficients(k); i++) {
803  // Evaluate the ith term in the expansion
804  term = fgMDFCorrection3C->Coefficients(k)[i];
805  for (j = 0; j < fgMDFCorrection3C->NVariables(k); j++) {
806  // Evaluate the factor (polynomial) in the j-th variable.
807  Int_t p = fgMDFCorrection3C->Powers(k)[i * fgMDFCorrection3C->NVariables(k) + j];
808  Double_t y = 1 + 2. / (fgMDFCorrection3C->XMax(k)[j] - fgMDFCorrection3C->XMin(k)[j])
809  * (x[j] - fgMDFCorrection3C->XMax(k)[j]);
810  term *= fgMDFCorrection3C->EvalFactor(k,p,y);
811  }
812  // Add this term to the final result
813  returnValue += term;
814  }
815  return returnValue;
816 }
817 
818 //____________________________________________________________________
819 Double_t St_MDFCorrection3C::Eval(Int_t k, Double_t x0, Double_t x1, Double_t x2) const {
820  Double_t x[3] = {x0, x1, x2};
821  return Eval(k,x);
822 }
823 //____________________________________________________________________
824 Double_t St_MDFCorrection3C::Eval(Int_t k, Double_t *x) const {
825  // Evaluate parameterization at point x. Optional argument coeff is
826  // a vector of coefficients for the parameterisation, NCoefficients
827  // elements long.
828  assert(x);
829  if (! fFunc[k]) {
830  fgMDFCorrection3C = (St_MDFCorrection3C *) this;
831  if (NVariables(k) <= 0) {
832  return 0;
833  } else if (NVariables(k) == 1) {
834  fFunc[k] = new TF1(Form("%s_%i",Table()->GetName(),k),St_MDFCorrection3C::MDFunc,
835  XMin(k)[0],XMax(k)[0],1);
836  fFunc[k]->SetParameter(0,k);
837  fFunc[k]->Save(XMin(k)[0],XMax(k)[0],0,0,0,0);
838  } else if (NVariables(k) == 2) {
839  fFunc[k] = new TF2(Form("%s_%i",Table()->GetName(),k),St_MDFCorrection3C::MDFunc,
840  XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],1);
841  fFunc[k]->SetParameter(0,k);
842  ((TF2 *) fFunc[k])->Save(XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],0,0);
843  } else if (NVariables(k) == 3) {
844  fFunc[k] = new TF3(Form("%s_%i",Table()->GetName(),k),St_MDFCorrection3C::MDFunc,
845  XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],XMin(k)[2],XMax(k)[2],1);
846  fFunc[k]->SetParameter(0,k);
847  ((TF3 *) fFunc[k])->Save(XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],XMin(k)[2],XMax(k)[2]);
848  }
849  }
850  Double_t xx[3];
851  for (Int_t v = 0; v < NVariables(k); v++) {
852  xx[v] = TMath::Max(XMin(k)[v], TMath::Min(XMin(k)[v]+0.999*(XMax(k)[v]-XMin(k)[v]), x[v]));
853  }
854  Double_t returnValue = fFunc[k]->GetSave(xx);
855  return returnValue;
856 }
857 //____________________________________________________________________
858 Double_t St_MDFCorrection3C::EvalError(Int_t k, Double_t *x) const {
859  // Evaluate parameterization error at point x. Optional argument coeff is
860  // a vector of coefficients for the parameterisation, NCoefficients(k)
861  // elements long.
862  assert(x);
863  Double_t returnValue = 0;
864  Double_t term = 0;
865  UChar_t i, j;
866  for (i = 0; i < NCoefficients(k); i++) {
867  // Evaluate the ith term in the expansion
868  term = CoefficientsRMS(k)[i];
869  for (j = 0; j < NVariables(k); j++) {
870  // Evaluate the factor (polynomial) in the j-th variable.
871  Int_t p = Powers(k)[i * NVariables(k) + j];
872  Double_t y = 1 + 2. / (XMax(k)[j] - XMin(k)[j])
873  * (x[j] - XMax(k)[j]);
874  term *= EvalFactor(p,y);
875  }
876  // Add this term to the final result
877  returnValue += term*term;
878  }
879  returnValue = TMath::Sqrt(returnValue);
880  return returnValue;
881 }
882 //____________________________________________________________________
883 Double_t St_MDFCorrection3C::EvalFactor(Int_t k, Int_t p, Double_t x) const {
884  // Evaluate function with power p at variable value x
885  Int_t i = 0;
886  Double_t p1 = 1;
887  Double_t p2 = 0;
888  Double_t p3 = 0;
889  Double_t r = 0;
890 
891  switch(p) {
892  case 1:
893  r = 1;
894  break;
895  case 2:
896  r = x;
897  break;
898  default:
899  p2 = x;
900  for (i = 3; i <= p; i++) {
901  p3 = p2 * x;
902  if (PolyType(k) == kLegendre)
903  p3 = ((2 * i - 3) * p2 * x - (i - 2) * p1) / (i - 1);
904  else if (PolyType(k) == kChebyshev)
905  p3 = 2 * x * p2 - p1;
906  p1 = p2;
907  p2 = p3;
908  }
909  r = p3;
910  }
911  return r;
912 }
913 //________________________________________________________________________________
914 Int_t St_MDFCorrection3C::IsActiveChair() const {
915  Int_t npar = 0;
916  const St_MDFCorrection3 *tableMDF = (const St_MDFCorrection3 *) Table();
917  if (! tableMDF) return npar;
918  MDFCorrection3_st *corMDF = tableMDF->GetTable();
919  Int_t N = tableMDF->GetNRows();
920  if (! corMDF || ! N) {
921  return npar;
922  }
923  for (Int_t i = 0; i < N; i++, corMDF++) {
924  if (corMDF->nrows == 0 && corMDF->idx == 0) continue;
925  npar++;
926  }
927  return npar;
928 }
929 //________________________________________________________________________________
930 //________________________________________________________________________________
931 ClassImp(St_MDFCorrection4C);
932 St_MDFCorrection4C *St_MDFCorrection4C::fgMDFCorrection4C = 0;
933 //____________________________________________________________________
934 St_MDFCorrection4C::St_MDFCorrection4C(St_MDFCorrection4 *table) : TChair(table), fFunc(0) {
935  UInt_t N = table->GetNRows();
936  fFunc = new TF1*[N];
937  memset(fFunc, 0, N*sizeof(TF1*));
938 }
939 //____________________________________________________________________
940 St_MDFCorrection4C::~St_MDFCorrection4C() {
941  UInt_t N = Table()->GetNRows();
942  for (UInt_t i = 0; i < N; i++) {SafeDelete(fFunc[i]);}
943  delete [] fFunc;
944 }
945 //____________________________________________________________________
946 Double_t St_MDFCorrection4C::MDFunc(Double_t *x, Double_t *p) {
947  // Evaluate parameterization at point x. Optional argument coeff is
948  // a vector of coefficients for the parameterisation, NCoefficients
949  // elements long.
950  assert(x);
951  UInt_t k = p[0];
952  assert(k >= 0 && k < fgMDFCorrection4C->getNumRows());
953  Double_t returnValue = fgMDFCorrection4C->DMean(k);
954  Double_t term = 0;
955  UChar_t i, j;
956  for (i = 0; i < fgMDFCorrection4C->NCoefficients(k); i++) {
957  // Evaluate the ith term in the expansion
958  term = fgMDFCorrection4C->Coefficients(k)[i];
959  for (j = 0; j < fgMDFCorrection4C->NVariables(k); j++) {
960  // Evaluate the factor (polynomial) in the j-th variable.
961  Int_t p = fgMDFCorrection4C->Powers(k)[i * fgMDFCorrection4C->NVariables(k) + j];
962  Double_t y = 1 + 2. / (fgMDFCorrection4C->XMax(k)[j] - fgMDFCorrection4C->XMin(k)[j])
963  * (x[j] - fgMDFCorrection4C->XMax(k)[j]);
964  term *= fgMDFCorrection4C->EvalFactor(k,p,y);
965  }
966  // Add this term to the final result
967  returnValue += term;
968  }
969  return returnValue;
970 }
971 
972 //____________________________________________________________________
973 Double_t St_MDFCorrection4C::Eval(Int_t k, Double_t x0, Double_t x1, Double_t x2, Double_t x3) const {
974  Double_t x[4] = {x0, x1, x2, x3};
975  return Eval(k,x);
976 }
977 //____________________________________________________________________
978 Double_t St_MDFCorrection4C::Eval(Int_t k, Double_t *x) const {
979  // Evaluate parameterization at point x. Optional argument coeff is
980  // a vector of coefficients for the parameterisation, NCoefficients
981  // elements long.
982  assert(x);
983  Double_t xx[4];
984  for (Int_t v = 0; v < NVariables(k); v++) {
985  xx[v] = TMath::Max(XMin(k)[v], TMath::Min(XMin(k)[v]+0.999*(XMax(k)[v]-XMin(k)[v]), x[v]));
986  }
987  Double_t returnValue = 0;
988  fgMDFCorrection4C = (St_MDFCorrection4C *) this;
989  if (NVariables(k) <= 3) {
990  if (! fFunc[k]) {
991  if (NVariables(k) <= 0) {
992  return returnValue;
993  } else if (NVariables(k) == 1) {
994  fFunc[k] = new TF1(Form("%s_%i",Table()->GetName(),k),St_MDFCorrection4C::MDFunc,
995  XMin(k)[0],XMax(k)[0],1);
996  fFunc[k]->SetParameter(0,k);
997  fFunc[k]->Save(XMin(k)[0],XMax(k)[0],0,0,0,0);
998  } else if (NVariables(k) == 2) {
999  fFunc[k] = new TF2(Form("%s_%i",Table()->GetName(),k),St_MDFCorrection4C::MDFunc,
1000  XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],1);
1001  fFunc[k]->SetParameter(0,k);
1002  ((TF2 *) fFunc[k])->Save(XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],0,0);
1003  } else if (NVariables(k) == 3) {
1004  fFunc[k] = new TF3(Form("%s_%i",Table()->GetName(),k),St_MDFCorrection4C::MDFunc,
1005  XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],XMin(k)[2],XMax(k)[2],1);
1006  fFunc[k]->SetParameter(0,k);
1007  ((TF3 *) fFunc[k])->Save(XMin(k)[0],XMax(k)[0],XMin(k)[1],XMax(k)[1],XMin(k)[2],XMax(k)[2]);
1008  }
1009  }
1010  returnValue = fFunc[k]->GetSave(xx);
1011  } else {
1012  Double_t par[1] = {(Double_t) k};
1013  returnValue = St_MDFCorrection4C::MDFunc(xx,par);
1014  }
1015  return returnValue;
1016 }
1017 //____________________________________________________________________
1018 Double_t St_MDFCorrection4C::EvalError(Int_t k, Double_t *x) const {
1019  // Evaluate parameterization error at point x. Optional argument coeff is
1020  // a vector of coefficients for the parameterisation, NCoefficients(k)
1021  // elements long.
1022  assert(x);
1023  Double_t returnValue = 0;
1024  Double_t term = 0;
1025  UChar_t i, j;
1026  for (i = 0; i < NCoefficients(k); i++) {
1027  // Evaluate the ith term in the expansion
1028  term = CoefficientsRMS(k)[i];
1029  for (j = 0; j < NVariables(k); j++) {
1030  // Evaluate the factor (polynomial) in the j-th variable.
1031  Int_t p = Powers(k)[i * NVariables(k) + j];
1032  Double_t y = 1 + 2. / (XMax(k)[j] - XMin(k)[j])
1033  * (x[j] - XMax(k)[j]);
1034  term *= EvalFactor(p,y);
1035  }
1036  // Add this term to the final result
1037  returnValue += term*term;
1038  }
1039  returnValue = TMath::Sqrt(returnValue);
1040  return returnValue;
1041 }
1042 //____________________________________________________________________
1043 Double_t St_MDFCorrection4C::EvalFactor(Int_t k, Int_t p, Double_t x) const {
1044  // Evaluate function with power p at variable value x
1045  Int_t i = 0;
1046  Double_t p1 = 1;
1047  Double_t p2 = 0;
1048  Double_t p3 = 0;
1049  Double_t r = 0;
1050 
1051  switch(p) {
1052  case 1:
1053  r = 1;
1054  break;
1055  case 2:
1056  r = x;
1057  break;
1058  default:
1059  p2 = x;
1060  for (i = 3; i <= p; i++) {
1061  p3 = p2 * x;
1062  if (PolyType(k) == kLegendre)
1063  p3 = ((2 * i - 3) * p2 * x - (i - 2) * p1) / (i - 1);
1064  else if (PolyType(k) == kChebyshev)
1065  p3 = 2 * x * p2 - p1;
1066  p1 = p2;
1067  p2 = p3;
1068  }
1069  r = p3;
1070  }
1071  return r;
1072 }
1073 //________________________________________________________________________________
1074 Int_t St_MDFCorrection4C::IsActiveChair() const {
1075  Int_t npar = 0;
1076  const St_MDFCorrection4 *tableMDF = (const St_MDFCorrection4 *) Table();
1077  if (! tableMDF) return npar;
1078  MDFCorrection4_st *corMDF = tableMDF->GetTable();
1079  Int_t N = tableMDF->GetNRows();
1080  if (! corMDF || ! N) {
1081  return npar;
1082  }
1083  for (Int_t i = 0; i < N; i++, corMDF++) {
1084  if (corMDF->nrows == 0 && corMDF->idx == 0) continue;
1085  npar++;
1086  }
1087  return npar;
1088 }
1089 //________________________________________________________________________________
1090 #include "St_tpcEffectiveGeomC.h"
1091 MakeChairAltInstance(tpcEffectiveGeom,Calibrations/tpc/tpcEffectiveGeom,Calibrations/tpc/tpcEffectiveGeomB,gEnv->GetValue("NewTpcAlignment",0));
1092 #include "St_tpcElectronicsC.h"
1093 MakeChairAltInstance(tpcElectronics,Calibrations/tpc/tpcElectronics,Calibrations/tpc/tpcElectronicsB,gEnv->GetValue("NewTpcAlignment",0));
1094 #include "St_tpcPedestalC.h"
1095 MakeChairInstance(tpcPedestal,Calibrations/tpc/tpcPedestal);
1096 #include "St_tpcPadResponseC.h"
1097 MakeChairInstance(tpcPadResponse,Calibrations/tpc/tpcPadResponse);
1098 #include "St_tpcSlowControlSimC.h"
1099 MakeChairInstance(tpcSlowControlSim,Calibrations/tpc/tpcSlowControlSim);
1100 #include "St_tpcGainMonitorC.h"
1101 MakeChairInstance(tpcGainMonitor,Calibrations/tpc/tpcGainMonitor);
1102 #include "St_tpcHighVoltagesC.h"
1103 MakeChairInstance(tpcHighVoltages,Calibrations/tpc/tpcHighVoltages);
1104 #include "St_tpcPadrowT0C.h"
1105 MakeChairAltInstance(tpcPadrowT0,Calibrations/tpc/tpcPadrowT0,Calibrations/tpc/tpcPadrowT0B,gEnv->GetValue("NewTpcAlignment",0));
1106 #include "St_tpcSectorT0offsetC.h"
1107 MakeChairInstance(tpcSectorT0offset,Calibrations/tpc/tpcSectorT0offset);
1108 #include "St_tpcAltroParamsC.h"
1109 MakeChairInstance(tpcAltroParams,Calibrations/tpc/tpcAltroParams);
1110 #include "St_asic_thresholdsC.h"
1111 MakeChairInstance(asic_thresholds,Calibrations/tpc/asic_thresholds);
1112 #include "St_asic_thresholds_tpxC.h"
1113 MakeChairInstance(asic_thresholds_tpx,Calibrations/tpc/asic_thresholds_tpx);
1114 #include "St_tpcAnodeHVC.h"
1115 MakeChairInstance(tpcAnodeHV,Calibrations/tpc/tpcAnodeHV);
1116 #include "St_tpcPadPlanesC.h"
1117 #include "St_itpcPadPlanesC.h"
1118 #include "St_tpcPadConfigC.h"
1119 tpcPadConfig_st *St_tpcPadConfigC::Struct(Int_t i) {return ((St_tpcPadConfig*) Table())->GetTable(i);}
1120 UInt_t St_tpcPadConfigC::getNumRows() {return GetNRows();}
1121 UChar_t St_tpcPadConfigC::iTpc(Int_t sector) {UChar_t iTPC = Struct()->itpc[sector-1]; return iTPC;}
1122 Int_t St_tpcPadConfigC::padRows(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->padRows() :St_itpcPadPlanesC::instance()->padRows();}
1123 Int_t St_tpcPadConfigC::innerPadRows(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerPadRows() :St_itpcPadPlanesC::instance()->innerPadRows();}
1124 Int_t St_tpcPadConfigC::innerPadRows48(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerPadRows48() :St_itpcPadPlanesC::instance()->innerPadRows48();}
1125 Int_t St_tpcPadConfigC::innerPadRows52(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerPadRows52() :St_itpcPadPlanesC::instance()->innerPadRows52();}
1126 Int_t St_tpcPadConfigC::outerPadRows(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerPadRows() :St_itpcPadPlanesC::instance()->outerPadRows();}
1127 Int_t St_tpcPadConfigC::superInnerPadRows(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->superInnerPadRows() :St_itpcPadPlanesC::instance()->superInnerPadRows();}
1128 Int_t St_tpcPadConfigC::superOuterPadRows(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->superOuterPadRows() :St_itpcPadPlanesC::instance()->superOuterPadRows();}
1129 Double_t St_tpcPadConfigC::innerSectorPadWidth(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerSectorPadWidth() :St_itpcPadPlanesC::instance()->innerSectorPadWidth();}
1130 Double_t St_tpcPadConfigC::innerSectorPadLength(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerSectorPadLength() :St_itpcPadPlanesC::instance()->innerSectorPadLength();}
1131 Double_t St_tpcPadConfigC::innerSectorPadPitch(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerSectorPadPitch() :St_itpcPadPlanesC::instance()->innerSectorPadPitch();}
1132 Double_t St_tpcPadConfigC::innerSectorRowPitch1(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerSectorRowPitch1() :St_itpcPadPlanesC::instance()->innerSectorRowPitch1();}
1133 Double_t St_tpcPadConfigC::innerSectorRowPitch2(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerSectorRowPitch2() :St_itpcPadPlanesC::instance()->innerSectorRowPitch2();}
1134 Double_t St_tpcPadConfigC::firstPadRow(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->firstPadRow() :St_itpcPadPlanesC::instance()->firstPadRow();}
1135 Double_t St_tpcPadConfigC::firstOuterSectorPadRow(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->firstOuterSectorPadRow():St_itpcPadPlanesC::instance()->firstOuterSectorPadRow();}
1136 Double_t St_tpcPadConfigC::lastOuterSectorPadRow(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->lastOuterSectorPadRow() :St_itpcPadPlanesC::instance()->lastOuterSectorPadRow();}
1137 Double_t St_tpcPadConfigC::firstRowWidth(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->firstRowWidth() :St_itpcPadPlanesC::instance()->firstRowWidth();}
1138 Double_t St_tpcPadConfigC::lastRowWidth(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->lastRowWidth() :St_itpcPadPlanesC::instance()->lastRowWidth();}
1139 Double_t St_tpcPadConfigC::outerSectorPadWidth(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerSectorPadWidth() :St_itpcPadPlanesC::instance()->outerSectorPadWidth();}
1140 Double_t St_tpcPadConfigC::outerSectorPadLength(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerSectorPadLength() :St_itpcPadPlanesC::instance()->outerSectorPadLength();}
1141 Double_t St_tpcPadConfigC::outerSectorPadPitch(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerSectorPadPitch() :St_itpcPadPlanesC::instance()->outerSectorPadPitch();}
1142 Double_t St_tpcPadConfigC::outerSectorRowPitch(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerSectorRowPitch() :St_itpcPadPlanesC::instance()->outerSectorRowPitch();}
1143 Double_t St_tpcPadConfigC::outerSectorLength(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerSectorLength() :St_itpcPadPlanesC::instance()->outerSectorLength();}
1144 Double_t St_tpcPadConfigC::ioSectorSeparation(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->ioSectorSeparation() :St_itpcPadPlanesC::instance()->ioSectorSeparation();}
1145 Double_t St_tpcPadConfigC::innerSectorEdge(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerSectorEdge() :St_itpcPadPlanesC::instance()->innerSectorEdge();}
1146 Double_t St_tpcPadConfigC::outerSectorEdge(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerSectorEdge() :St_itpcPadPlanesC::instance()->outerSectorEdge();}
1147 Double_t St_tpcPadConfigC::innerSectorPadPlaneZ(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerSectorPadPlaneZ() :St_itpcPadPlanesC::instance()->innerSectorPadPlaneZ();}
1148 Double_t St_tpcPadConfigC::outerSectorPadPlaneZ(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerSectorPadPlaneZ() :St_itpcPadPlanesC::instance()->outerSectorPadPlaneZ();}
1149 Int_t* St_tpcPadConfigC::innerPadsPerRow(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerPadsPerRow() :St_itpcPadPlanesC::instance()->innerPadsPerRow();}
1150 Int_t* St_tpcPadConfigC::outerPadsPerRow(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerPadsPerRow() :St_tpcPadPlanesC::instance()->outerPadsPerRow();}
1151 Int_t St_tpcPadConfigC::padsPerRow(Int_t sector, Int_t row) {
1152  Int_t Ninner = innerPadRows(sector);
1153  return (row <= Ninner) ?
1154  innerPadsPerRow(sector)[row-1] :
1155  outerPadsPerRow(sector)[row-1-Ninner];
1156 }
1157 Double_t* St_tpcPadConfigC::innerRowRadii(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->innerRowRadii() :St_itpcPadPlanesC::instance()->innerRowRadii();}
1158 Double_t* St_tpcPadConfigC::outerRowRadii(Int_t sector) {return (! iTpc(sector)) ? St_tpcPadPlanesC::instance()->outerRowRadii() :St_itpcPadPlanesC::instance()->outerRowRadii();}
1159 // taken from StRItpcPadPlane
1160 Int_t St_tpcPadConfigC::numberOfRows(Int_t sector) {return padRows(sector);}
1161 Int_t St_tpcPadConfigC::numberOfInnerRows(Int_t sector) {return innerPadRows(sector);}
1162 Int_t St_tpcPadConfigC::numberOfInnerRows48(Int_t sector) {return innerPadRows48(sector);}
1163 Int_t St_tpcPadConfigC::numberOfInnerRows52(Int_t sector) {return innerPadRows52(sector);}
1164 Int_t St_tpcPadConfigC::numberOfOuterRows(Int_t sector) {return outerPadRows(sector);}
1165 Bool_t St_tpcPadConfigC::isRowInRange(Int_t sector, Int_t row) {return (row >= 1 && row<=numberOfRows(sector)) ? kTRUE: kFALSE;}
1166 Double_t St_tpcPadConfigC::radialDistanceAtRow(Int_t sector, Int_t row) {
1167  if (! isRowInRange(sector,row)) return 0;
1168  Int_t Ninner = innerPadRows(sector);
1169  if ( row<=Ninner ) return innerRowRadii(sector)[row-1];
1170  else return outerRowRadii(sector)[row-1-Ninner];
1171 }
1172 Int_t St_tpcPadConfigC::numberOfPadsAtRow(Int_t sector, Int_t row) {
1173  if (! isRowInRange(sector, row)) return 0;
1174  Int_t Ninner = innerPadRows(sector);
1175  if ( row<=Ninner ) return innerPadsPerRow(sector)[row-1];
1176  return outerPadsPerRow(sector)[row-1-Ninner];
1177 }
1178 Double_t St_tpcPadConfigC::PadWidthAtRow(Int_t sector, Int_t row) {
1179  if (! isRowInRange(sector,row)) return 0;
1180  Int_t Ninner = innerPadRows(sector);
1181  if ( row<=Ninner) return innerSectorPadWidth(sector);
1182  return outerSectorPadWidth(sector);
1183 }
1184 Double_t St_tpcPadConfigC::PadLengthAtRow(Int_t sector, Int_t row) {
1185  if (! isRowInRange(sector,row)) return 0;
1186  Int_t Ninner = innerPadRows(sector);
1187  if ( row<=Ninner) return innerSectorPadLength(sector);
1188  return outerSectorPadLength(sector);
1189 }
1190 Double_t St_tpcPadConfigC::PadPitchAtRow(Int_t sector, Int_t row) {
1191  if (! isRowInRange(sector,row)) return 0;
1192  Int_t Ninner = innerPadRows(sector);
1193  if ( row<=Ninner) return innerSectorPadPitch(sector);
1194  return outerSectorPadPitch(sector);
1195 }
1196 Double_t St_tpcPadConfigC::RowPitchAtRow(Int_t sector, Int_t row) {
1197  if (! isRowInRange(sector,row)) return 0;
1198  Int_t Ninner = innerPadRows(sector);
1199  if ( row<=numberOfInnerRows48(sector) ) return innerSectorRowPitch1(sector);
1200  else if (row>numberOfInnerRows48(sector)&&row<=Ninner) return innerSectorRowPitch2(sector);
1201  return outerSectorRowPitch(sector);
1202 }
1203 Int_t St_tpcPadConfigC::indexForRowPad(Int_t sector, Int_t row, Int_t pad) {
1204  if (pad >numberOfPadsAtRow(sector,row)) return -1;
1205  Int_t index = 0;
1206  Int_t Ninner = innerPadRows(sector);
1207  if (row>0 && row<=Ninner ) for (Int_t i=1;i<row;i++) index += numberOfPadsAtRow(sector,i);
1208  else
1209  if (row>Ninner&&row<=numberOfRows(sector)) for (Int_t i=Ninner+1;i<row;i++) index += numberOfPadsAtRow(sector,i);
1210  index+=pad-1;
1211  return index;
1212 }
1213 #include "St_TpcAvgPowerSupplyC.h"
1214 //________________________________________________________________________________
1215 void St_tpcAnodeHVC::sockets(Int_t sector, Int_t padrow, Int_t &e1, Int_t &e2, Float_t &f2) {
1216  e1 = (sector-1)*19;
1217  e2 = e1;
1218  f2 = 0;
1219  // sector=1..24 , padrow=1..45
1220  // f2 represents signal couplings from neighboring HV sections
1221  // see: http://www.star.bnl.gov/public/tpc/hard/signals/signal_division.html
1222  if (! St_tpcPadConfigC::instance()->iTPC(sector)) {
1223  switch (padrow) {
1224  case 1: e1+= 1; e2+= 2; f2 = 0.00197; break;
1225  case 2: e1+= 2; break;
1226  case 3: e1+= 3; e2+= 2; f2 = 0.04547; break;
1227  case 4: e1+= 3; break;
1228  case 5: e1+= 4; break;
1229  case 6: e1+= 4; e2+= 5; f2 = 0.00007; break;
1230  case 7: e1+= 5; break;
1231  case 8: e1+= 6; e2+= 5; f2 = 0.04547; break;
1232  case 9: e1+= 6; break;
1233  case 10: e1+= 7; break;
1234  case 11: e1+= 8; e2+= 7; f2 = 0.33523; break;
1235  case 12: e1+= 8; break;
1236  case 13: e1+=17; break;
1237  case 14: e1+= 9; e2+=18; f2 = 0.00312; break;
1238  case 15:
1239  case 16: e1+= 9; break;
1240  case 17: e1+= 9; e2+=10; f2 = 0.40250; break;
1241  case 18:
1242  case 19:
1243  case 20: e1+=10; break;
1244  case 21: e1+=10; e2+=11; f2 = 0.40250; break;
1245  case 22:
1246  case 23:
1247  case 24: e1+=11; break;
1248  case 25: e1+=11; e2+=12; f2 = 0.40250; break;
1249  case 26:
1250  case 27:
1251  case 28: e1+=12; break;
1252  case 29: e1+=12; e2+=13; f2 = 0.40250; break;
1253  case 30:
1254  case 31:
1255  case 32: e1+=13; break;
1256  case 33: e1+=13; e2+=14; f2 = 0.40250; break;
1257  case 34:
1258  case 35:
1259  case 36: e1+=14; break;
1260  case 37: e1+=14; e2+=15; f2 = 0.40250; break;
1261  case 38:
1262  case 39:
1263  case 40: e1+=15; break;
1264  case 41: e1+=15; e2+=16; f2 = 0.40250; break;
1265  case 42:
1266  case 43:
1267  case 44: e1+=16; break;
1268  case 45: e1+=16; e2+=19; f2 = 0.40250; break;
1269  default: e1 = 0; e2 = 0; f2 = 0;
1270  }
1271  } else { // iTPC
1272  switch (padrow) {
1273  case 1:
1274  case 2:
1275  case 3: e1+= 1; e2+= 1; break;
1276  case 4: e1+= 1; e2+= 2; break;
1277  case 5:
1278  case 6:
1279  case 7:
1280  case 8: e1+= 2; e2+= 2; break;
1281  case 9: e1+= 2; e2+= 3; break;
1282  case 10:
1283  case 11:
1284  case 12:
1285  case 13: e1+= 3; e2+= 3; break;
1286  case 14: e1+= 3; e2+= 4; break;
1287  case 15:
1288  case 16:
1289  case 17:
1290  case 18: e1+= 4; e2+= 4; break;
1291  case 19: e1+= 4; e2+= 5; break;
1292  case 20:
1293  case 21:
1294  case 22:
1295  case 23: e1+= 5; e2+= 5; break;
1296  case 24: e1+= 5; e2+= 6; break;
1297  case 25:
1298  case 26:
1299  case 27:
1300  case 28: e1+= 6; e2+= 6; break;
1301  case 29: e1+= 6; e2+= 7; break;
1302  case 30:
1303  case 31:
1304  case 32:
1305  case 33: e1+= 7; e2+= 7; break;
1306  case 34: e1+= 7; e2+= 8; break;
1307  case 35:
1308  case 36:
1309  case 37:
1310  case 38: e1+= 8; e2+= 8; break;
1311  case 39:
1312  case 40: e1+=17; e2+=17; break;
1313  case 41: e1+= 9; e2+=18; break;
1314  case 42:
1315  case 43: e1+= 9; break;
1316  case 44: e1+= 9; e2+=10; break;
1317  case 45:
1318  case 46:
1319  case 47: e1+=10; break;
1320  case 48: e1+=10; e2+=11; break;
1321  case 49:
1322  case 50:
1323  case 51: e1+=11; break;
1324  case 52: e1+=11; e2+=12; f2 = 0.40250; break;
1325  case 53:
1326  case 54:
1327  case 55: e1+=12; break;
1328  case 56: e1+=12; e2+=13; f2 = 0.40250; break;
1329  case 57:
1330  case 58:
1331  case 59: e1+=13; break;
1332  case 60: e1+=13; e2+=14; f2 = 0.40250; break;
1333  case 61:
1334  case 62:
1335  case 63: e1+=14; break;
1336  case 64: e1+=14; e2+=15; f2 = 0.40250; break;
1337  case 65:
1338  case 66:
1339  case 67: e1+=15; break;
1340  case 68: e1+=15; e2+=16; f2 = 0.40250; break;
1341  case 69:
1342  case 70:
1343  case 71: e1+=16; break;
1344  case 72: e1+=16; e2+=19; f2 = 0.40250; break;
1345  default: e1 = 0; e2 = 0; f2 = 0;
1346  }
1347  }
1348 }
1349 //________________________________________________________________________________
1350 Float_t St_tpcAnodeHVC::voltage(Int_t i) const {
1351  if (! St_TpcAvgPowerSupplyC::instance()->Table()->IsMarked()) {
1352  LOG_ERROR << "St_tpcAnodeHVC::voltage(" << i << " is called but the valid St_TpcAvgPowerSupplyC::instance() exists" << endm;
1353  }
1354  return Struct(i)->voltage;
1355 }
1356 //________________________________________________________________________________
1357 Float_t St_tpcAnodeHVC::voltagePadrow(Int_t sector, Int_t padrow) const {
1358  if (! St_TpcAvgPowerSupplyC::instance()->Table()->IsMarked()) {
1359  return St_TpcAvgPowerSupplyC::instance()->voltagePadrow(sector,padrow);
1360  }
1361  Int_t e1 = 0, e2 = 0;
1362  Float_t f2 = 0;
1363  St_tpcAnodeHVC::sockets(sector, padrow, e1, e2, f2);
1364  if (e1==0) return -99;
1365  Float_t v1=voltage(e1-1);
1366  if (f2 < 0.1) return v1;
1367  Float_t v2=voltage(e2-1);
1368  if (TMath::Abs(v2 - v1) > 40) return -99;
1369  if (TMath::Abs(v2 - v1) < 1) return v1;
1370  // different voltages on influencing HVs
1371  // effective voltage is a sum of exponential gains
1372  Float_t B = (padrow <= St_tpcPadConfigC::instance()->innerPadRows(sector) ? 13.05e-3 : 10.26e-3);
1373  Float_t v_eff = TMath::Log((1.0-f2)*TMath::Exp(B*v1) + f2*TMath::Exp(B*v2)) / B;
1374  return v_eff;
1375 }
1376 MakeChairOptionalInstance(TpcAvgPowerSupply,Calibrations/tpc/TpcAvgPowerSupply);
1377 //________________________________________________________________________________
1378 Float_t St_TpcAvgPowerSupplyC::voltagePadrow(Int_t sector, Int_t padrow) const {
1379  Int_t e1 = 0, e2 = 0;
1380  Float_t f2 = 0;
1381  St_tpcAnodeHVC::sockets(sector, padrow, e1, e2, f2);
1382  if (e1==0) return -99;
1383  Int_t ch1 = St_TpcAvgCurrentC::ChannelFromSocket((e1-1)%19+1);
1384  Float_t v1=Voltage()[8*(sector-1)+ch1-1] ;
1385  if (f2==0) return v1;
1386  Int_t ch2 = St_TpcAvgCurrentC::ChannelFromSocket((e2-1)%19 + 1);
1387  if (ch1 == ch2) return v1;
1388  Float_t v2=Voltage()[8*(sector-1)+ch2-1] ;
1389  if (v2==v1) return v1;
1390  // different voltages on influencing HVs
1391  // effective voltage is a sum of exponential gains
1392  Float_t B = (padrow <= St_tpcPadConfigC::instance()->innerPadRows(sector) ? 13.05e-3 : 10.26e-3);
1393  Float_t v_eff = TMath::Log((1.0-f2)*TMath::Exp(B*v1) + f2*TMath::Exp(B*v2)) / B;
1394  return v_eff;
1395 }
1396 //________________________________________________________________________________
1397 Float_t St_TpcAvgPowerSupplyC::AcChargeL(Int_t sector, Int_t channel) {
1398  // static const Double_t RA[2] = { 154.484, 81.42}; // Outer/ Inner average Radii
1399  // static const Double_t WireLenth[2] = { 3.6e5, 1.6e5};
1400  // L Inner = 190222, Outer = 347303
1401  static Float_t Length[8] = {
1402  1307.59, // Channel 1
1403  1650.57, // Channel 2
1404  1993.54, // Channel 3
1405  2974.24, // Channel 4
1406  3324.59, // Channel 5
1407  3202.42, // Channel 6
1408  3545.4 , // Channel 7
1409  4398.53};// Channel 8
1410 
1411  return AcCharge(sector,channel)/Length[channel-1];
1412 }
1413 //________________________________________________________________________________
1414 void St_TpcAvgPowerSupplyC::PrintC() const {
1415  const St_TpcAvgPowerSupply *TpcAvgPowerSupply = (St_TpcAvgPowerSupply *) GetThisTable();
1416  const TpcAvgPowerSupply_st &avgC = *TpcAvgPowerSupply->GetTable();
1417  Double_t AcCharge[2] = {0, 0};
1418  cout << "TpcAvgPowerSupply for run = " << avgC.run << endl;
1419  for (Int_t sec = 1; sec <= 24; sec++) {
1420  cout << "Voltage " << sec;
1421  for (Int_t socket = 1; socket <= 8; socket++) cout << "\t" << Form("%10.3f",avgC.Voltage[8*(sec-1)+socket-1]);
1422  cout << endl;
1423  }
1424  for (Int_t sec = 1; sec <= 24; sec++) {
1425  cout << "Current " << sec;
1426  for (Int_t socket = 1; socket <= 8; socket++) cout << "\t" << Form("%10.5f",avgC.Current[8*(sec-1)+socket-1]);
1427  cout << endl;
1428  }
1429  for (Int_t sec = 1; sec <= 24; sec++) {
1430  cout << "Charge " << sec;
1431  for (Int_t socket = 1; socket <= 8; socket++) {
1432  cout << "\t" << Form("%10.3f",avgC.Charge[8*(sec-1)+socket-1]);
1433  Int_t io = 0;
1434  if (socket > 4) io = 1;
1435  AcCharge[io] += avgC.Charge[8*(sec-1)+socket-1];
1436  }
1437  cout << endl;
1438  }
1439  cout << "Run " << avgC.run << " Accumulated charge Inner = " << AcCharge[0] << " (C), Outer = " << AcCharge[1] << "(C)" << endl;
1440 }
1441 #include "St_tpcAnodeHVavgC.h"
1442 MakeChairInstance(tpcAnodeHVavg,Calibrations/tpc/tpcAnodeHVavg);
1443 //________________________________________________________________________________
1444 Float_t St_tpcAnodeHVavgC::voltage(Int_t i) const {
1445  if (! St_TpcAvgPowerSupplyC::instance()->Table()->IsMarked()) {
1446  LOG_ERROR << "St_tpcAnodeHVavgC::voltage(" << i << " is called but the valid St_TpcAvgPowerSupplyC::instance() exists" << endm;
1447  }
1448  return Struct(i)->voltage;
1449 }
1450 //________________________________________________________________________________
1451 Bool_t St_tpcAnodeHVavgC::tripped(Int_t sector, Int_t padrow) const {
1452  if (! St_TpcAvgPowerSupplyC::instance()->Table()->IsMarked()) {
1453  return St_TpcAvgPowerSupplyC::instance()->tripped(sector,padrow);
1454  }
1455  return (voltage() < -100);
1456 }
1457 //________________________________________________________________________________
1458 Float_t St_tpcAnodeHVavgC::voltagePadrow(Int_t sector, Int_t padrow) const {
1459  if (! St_TpcAvgPowerSupplyC::instance()->Table()->IsMarked()) {
1460  return St_TpcAvgPowerSupplyC::instance()->voltagePadrow(sector,padrow);
1461  }
1462  Int_t e1 = 0, e2 = 0;
1463  Float_t f2 = 0;
1464  St_tpcAnodeHVC::sockets(sector, padrow, e1, e2, f2);
1465  if (e1==0) return -99;
1466  Float_t v1=voltage(e1-1);
1467  if (f2==0) return v1;
1468  Float_t v2=voltage(e2-1);
1469  if (v2==v1) return v1;
1470  // different voltages on influencing HVs
1471  // effective voltage is a sum of exponential gains
1472  Float_t B = (padrow <= St_tpcPadConfigC::instance()->innerPadRows(sector) ? 13.05e-3 : 10.26e-3);
1473  Float_t v_eff = TMath::Log((1.0-f2)*TMath::Exp(B*v1) + f2*TMath::Exp(B*v2)) / B;
1474  return v_eff;
1475 }
1476 //________________________________________________________________________________
1477 #include "St_tpcRDOMasksC.h"
1478 //MakeChairInstance(tpcRDOMasks,RunLog/onl/tpcRDOMasks);
1479 ClassImp(St_tpcRDOMasksC);
1480 St_tpcRDOMasksC *St_tpcRDOMasksC::fgInstance = 0;
1481 St_tpcRDOMasksC *St_tpcRDOMasksC::instance() {
1482  if (fgInstance) return fgInstance;
1483  St_tpcRDOMasks *table = (St_tpcRDOMasks *) StMaker::GetChain()->GetDataBase("RunLog/onl/tpcRDOMasks");
1484  if (! table) {
1485  LOG_WARN << "St_tpcRDOMasksC::instance RunLog/onl/tpcRDOMasks was not found" << endm;
1486  assert(table);
1487  assert(table->GetNRows() == 12);
1488  }
1489  DEBUGTABLE(tpcRDOMasks);
1490  // Take care about unsorted tpcRDOMaks table
1491  Bool_t needReorder = kFALSE;
1492  tpcRDOMasks_st *row = table->GetTable();
1493  UInt_t Nactive = 0;
1494  UInt_t N = table->GetNRows();
1495  if (N != 12) {
1496  needReorder = kTRUE;
1497  LOG_WARN << "St_tpcRDOMasksC::instance RunLog/onl/tpcRDOMasks has NRows = " << N << " =! 12" << endm;
1498  } else {
1499  for (UInt_t i = 0; i < N; i++) {
1500  if ((row+i)->sector == 2*i + 1) continue;
1501  needReorder = kTRUE;
1502  break;
1503  }
1504  }
1505  if (needReorder) {
1506  LOG_WARN << "St_tpcRDOMasksC::instance RunLog/onl/tpcRDOMasks has to be reordered" << endm;
1507  tpcRDOMasks_st rows[12] = {0};
1508  Int_t OldRun = -1;
1509  for (UInt_t i = 0; i < N; i++) {
1510  if ((row+i)->sector == 2*i + 1) {
1511  rows[i] = *(row+i);
1512  if ((row+i)->runNumber > 0 && OldRun < 0) OldRun = (row+i)->runNumber;
1513  Nactive++;
1514  } else {
1515  if ((row+i)->sector > 0 && (row+i)->sector <= 24) {
1516  if ((row+i)->runNumber > 0 && OldRun < 0) OldRun = (row+i)->runNumber;
1517  Int_t j = ((row+i)->sector-1)/2;
1518  if (rows[j].sector != 0) {
1519  LOG_ERROR << "St_tpcRDOMasksC::instance RunLog/onl/tpcRDOMasks has duplicated rows\t" << i << "\tand " << j << endm;
1520  }
1521  rows[j] = *(row+i);
1522  Nactive++;
1523  }
1524  }
1525  }
1526  if (Nactive != 12) { // Add missing rows
1527  delete table;
1528  table = new St_tpcRDOMasks("tpcRDOMasks", 12);
1529  // fill missing rows
1530  for (Int_t i = 0; i < 12; i++) {
1531  if (rows[i].sector == 0) {
1532  rows[i].sector = 2*i + 1;
1533  rows[i].runNumber = OldRun;
1534  if (St_tpcPadConfigC::instance()->iTpc(rows[i].sector)) {
1535  rows[i].mask = 65535;
1536  } else {
1537  rows[i].mask = 4095;
1538  }
1539  }
1540  }
1541  }
1542  for (Int_t i = 0; i < 12; i++) {
1543  table->AddAt(&rows[i],i);
1544  }
1545  table->Print(0,12);
1546  }
1547  fgInstance = new St_tpcRDOMasksC(table);
1548  if (StDetectorDbMaker::instance()) {
1549  fgInstance->SetName("tpcRDOMasksC");
1550  StDetectorDbMaker::instance()->AddConst(fgInstance);
1551  }
1552  return fgInstance;
1553 }
1554 //________________________________________________________________________________
1555 UInt_t St_tpcRDOMasksC::getSectorMask(UInt_t sec) {
1556  static UInt_t Sector = 0;
1557  static UInt_t Mask = 0;
1558  if (Sector == sec) {
1559  return Mask;
1560  }
1561  UInt_t MASK = 0x0000; // default is to mask it out
1562  //UInt_t MASK = 0xFFFF; // change to ON by default ** THIS WAS A HACK
1563  if(sec < 1 || sec > 24 || getNumRows() == 0){
1564  LOG_WARN << "St_tpcRDOMasksC:: getSectorMask : return default mask for "
1565  << "sector= " << sec << " getNumRows()=" << getNumRows() << endm;
1566  Sector = 0;
1567  return MASK;
1568  }
1569  // tpcRDOMasks_st *row = Struct();
1570  // Take care about unsorted tpcRDOMaks table
1571  tpcRDOMasks_st *row = Struct((sec-1)/2);
1572  MASK = row->mask;
1573  Int_t run = row->runNumber;
1574  if (! St_tpcPadConfigC::instance()->iTpc(sec)) {// no iTPC
1575  if (sec == 16 && MASK == 0 && run > 8181000 && run < 9181000) MASK = 4095;
1576  if( sec % 2 == 0){ // if its even relevent bits are 6-11
1577  MASK = MASK >> 6;
1578  }
1579  // Otherwise want lower 6 bits
1580  MASK &= 0x000003F; // Mask out higher order bits
1581  } else if (run < 20000000 && sec == 20) { // Run XVIII, sector 20
1582  MASK = 255;
1583  } else { // Run XIX and higher
1584  if( sec % 2 == 0){ // if its even relevent bits are 8-13
1585  MASK = MASK >> 8;
1586  }
1587  // Otherwise want lower 8 bits
1588  MASK &= 255; // Mask out higher order bits
1589  }
1590  Sector = sec;
1591  Mask = MASK;
1592  return Mask;
1593 }
1594 //________________________________________________________________________________
1595 Bool_t St_tpcRDOMasksC::isOn(Int_t sector,Int_t rdo) {
1596  static Int_t Sector = -1;
1597  static Int_t Rdo = -1;
1598  static Bool_t Mask = kFALSE;
1599  if (Sector == sector && Rdo == rdo) {
1600  return Mask;
1601  }
1602  Mask = kFALSE;
1603  Sector = sector;
1604  Rdo = rdo;
1605  if(sector < 1 || sector > 24 || rdo < 1 || rdo > 8) {
1606  getSectorMask(0);
1607  return 0;
1608  }
1609  tpcRDOMasks_st *row = Struct((sector-1)/2);
1610  assert(row->sector == (UInt_t) 2*((sector-1)/2) + 1);
1611  UInt_t MASK = getSectorMask(sector);
1612  MASK = MASK >> (rdo - 1);
1613  MASK &= 0x00000001;
1614  Mask = MASK;
1615  return Mask;
1616 }
1617 //________________________________________________________________________________
1618 void St_tpcRDOMasksC::setSectorRDOMaskOff(UInt_t sector,Int_t rdo) {
1619  if(sector < 1 || sector > 24 || rdo < 1 || rdo > 8) return;
1620  if (isOn(sector,rdo)) {
1621  tpcRDOMasks_st *row = Struct((sector-1)/2);
1622  assert(row->sector == 2*((sector-1)/2) + 1);
1623  if (! St_tpcPadConfigC::instance()->iTpc(sector)) {// no iTPC
1624  row->mask &= ~(1 << (6*((sector-1)%2) + rdo - 1));
1625  } else { // with iTPC
1626  row->mask &= ~(1 << (8*((sector-1)%2) + rdo - 1));
1627  }
1628  isOn(0,rdo); // Reset saved mask
1629  LOG_WARN << "St_tpcRDOMasksC::setSectorRDOMaskOff(" << sector << "," << rdo << ") = " << isOn(sector,rdo) << endm;
1630  }
1631 }
1632 //________________________________________________________________________________
1633 #include "St_tpcExtraGainCorrectionC.h"
1634 MakeChairInstance(tpcExtraGainCorrection,Calibrations/tpc/tpcExtraGainCorrection);
1635 //________________________________________________________________________________
1636 #include "St_tpcPadGainT0C.h"
1637 //MakeChairInstance(tpcPadGainT0,Calibrations/tpc/tpcPadGainT0);
1638 St_tpcPadGainT0C *St_tpcPadGainT0C::fgInstance = 0;
1639 //________________________________________________________________________________
1640 St_tpcPadGainT0C *St_tpcPadGainT0C::instance() {
1641  if (fgInstance) return fgInstance;
1642  St_tpcPadGainT0 *table = (St_tpcPadGainT0 *) StMaker::GetChain()->GetDataBase("Calibrations/tpc/tpcPadGainT0");
1643  if (! table) {
1644  LOG_WARN << "St_tpcPadGainT0C::instance Calibrations/tpc/tpcPadGainT0\twas not found" << endm;
1645  assert(table);
1646  }
1647  fgInstance = new St_tpcPadGainT0C(table);
1648  if (StDetectorDbMaker::instance()) {
1649  fgInstance->SetName("tpcPadGainT0C");
1650  StDetectorDbMaker::instance()->AddConst(fgInstance);
1651  }
1652  // Apply additional correction for gain tables
1653  Int_t run = StMaker::GetChain()->GetRunNumber();
1654  St_tpcExtraGainCorrectionC *extra = St_tpcExtraGainCorrectionC::instance();
1655  Int_t nrows = extra->nrows();
1656  for (Int_t i = 0; i < nrows; i++) {
1657  if (extra->idx(i) <= 0) continue;
1658  Int_t runMin = extra->runMin(i);
1659  Int_t runMax = extra->runMax(i);
1660  if (run < runMin || run > runMax) continue;
1661  Int_t sector = extra->sector(i);
1662  if (sector < 0 || sector > 24) continue;
1663  Int_t row = extra->row(i);
1664  if (row > 72) row = -1;
1665  Int_t padMin = extra->padMin(i);
1666  Int_t padMax = extra->padMax(i);
1667  Int_t RDO = extra->RDO(i);
1668  Int_t FEE = extra->FEE(i);
1669  Int_t status = extra->status(i);
1670  if (status) continue;
1671  if (padMin < padMax && row > 0) {
1672  Int_t r = row;
1673  if (St_tpcPadConfigC::instance()->iTPC(sector)) {
1674  if (row <= 40) continue;
1675  r = row - 40 + 13;
1676  }
1677  LOG_WARN << "St_tpcPadGainT0C::instance found extra correction for run = " << run << " in [" << runMin << "," << runMax << "]"
1678  << Form(" with sec = %2i, row = %2i, padMin/Max = %3i/%3i, RDO = %2i, FEE = %2i, status = %i",
1679  sector, r, padMin, padMax, RDO, FEE, status) << endm;
1680  Float_t *gains = St_tpcPadGainT0C::instance()->Gains(sector, r);
1681  for (Int_t p = padMin; p <= padMax; p++) {
1682  if (gains[p-1] > 0) {
1683  LOG_WARN << "St_tpcPadGainT0C::instance reset gain[" << sector-1 << "][" << r - 1 << "][" << p-1 << "] = " << gains[p-1] << " to zero" << endm;
1684  }
1685  gains[p-1] = 0;
1686  }
1687  } else if (FEE > 0) { // iTPC stuff, ignorefor tpx
1688  } else if (RDO > 0) {
1689  LOG_WARN << "St_tpcPadGainT0C::instance found extra correction for run = " << run << " in [" << runMin << "," << runMax << "]"
1690  << Form(" reset tpcRDOMasks for sector = %i and RDO = %i to zero with sec = %2i, row = %2i, padMin/Max = %3i/%3i, RDO = %2i, FEE = %2i, status = %i",
1691  sector, RDO, sector, row, padMin, padMax, RDO, FEE, status) << endm;
1692  St_tpcRDOMasksC::instance()->setSectorRDOMaskOff(sector,RDO);
1693  } else {
1694  LOG_WARN << "St_tpcPadGainT0C::instance found extra correction for run = " << run << " in [" << runMin << "," << runMax << "]"
1695  << Form(" with sec = %2i, row = %2i, padMin/Max = %3i/%3i, RDO = %2i, FEE = %2i, status = %i => whole sector is marker as DEAD",
1696  sector, row, padMin, padMax, RDO, FEE, status) << endm;
1697  Int_t rdoMin = 1;
1698  Int_t rdoMax = 6;
1699  if (! St_tpcPadConfigC::instance()->iTPC(sector)) {rdoMin = 5; rdoMax = 8;}
1700  for (Int_t rdoD = rdoMin; rdoD <= rdoMax; rdoD++) {
1701  St_tpcRDOMasksC::instance()->setSectorRDOMaskOff(sector,rdoD);
1702  }
1703  }
1704  }
1705  return fgInstance;
1706 }
1707 //________________________________________________________________________________
1708 #include "St_itpcDeadFEEC.h"
1709 MakeChairInstance(itpcDeadFEE,Calibrations/tpc/itpcDeadFEE);
1710 #include "St_itpcPadGainT0C.h"
1711 //MakeChairInstance(itpcPadGainT0,Calibrations/tpc/itpcPadGainT0);
1712 //#define MakeChairInstance(STRUCT,PATH)
1713 ClassImp(St_itpcPadGainT0C);
1714 St_itpcPadGainT0C *St_itpcPadGainT0C::fgInstance = 0;
1715 rowpadFEEmap_t St_itpcPadGainT0C::rowpadFEE[] = {
1716  //row, padMin, padMax, fee, rdo
1717  { 1, 1, 26, 54, 1},
1718  { 1, 27, 52, 55, 1},
1719  { 2, 1, 27, 54, 1},
1720  { 2, 28, 54, 55, 1},
1721  { 3, 1, 22, 52, 1},
1722  { 3, 23, 28, 54, 1},
1723  { 3, 29, 34, 55, 1},
1724  { 3, 35, 56, 53, 1},
1725  { 4, 1, 24, 52, 1},
1726  { 4, 25, 29, 54, 1},
1727  { 4, 30, 34, 55, 1},
1728  { 4, 35, 58, 53, 1},
1729  { 5, 1, 10, 52, 1},
1730  { 5, 11, 20, 49, 1},
1731  { 5, 21, 40, 50, 1},
1732  { 5, 41, 50, 51, 1},
1733  { 5, 51, 60, 53, 1},
1734  { 6, 1, 8, 52, 1},
1735  { 6, 22, 41, 50, 1},
1736  { 6, 42, 54, 51, 1},
1737  { 6, 55, 62, 53, 1},
1738  { 6, 9, 21, 49, 1},
1739  { 7, 1, 3, 46, 1},
1740  { 7, 26, 37, 50, 1},
1741  { 7, 38, 59, 51, 1},
1742  { 7, 4, 25, 49, 1},
1743  { 7, 60, 62, 48, 1},
1744  { 8, 1, 7, 46, 1},
1745  { 8, 27, 38, 50, 1},
1746  { 8, 39, 57, 51, 1},
1747  { 8, 58, 64, 48, 1},
1748  { 8, 8, 26, 49, 1},
1749  { 9, 1, 25, 46, 1},
1750  { 9, 26, 41, 47, 1},
1751  { 9, 42, 66, 48, 1},
1752  {10, 1, 25, 46, 1},
1753  {10, 26, 43, 47, 1},
1754  {10, 44, 68, 48, 1},
1755 
1756  {11, 1, 27, 43, 2},
1757  {11, 28, 43, 47, 1},
1758  {11, 44, 70, 45, 2},
1759 
1760  {12, 1, 29, 43, 2}, // ? correction from Irakli, 03/09/2020: 29 => 28 ?
1761  {12, 30, 43, 47, 1},
1762  {12, 44, 72, 45, 2},
1763 
1764  {13, 1, 4, 43, 2},
1765  {13, 23, 52, 44, 2},
1766  {13, 5, 22, 40, 2},
1767  {13, 53, 70, 42, 2},
1768  {13, 71, 74, 45, 2},
1769  {14, 1, 22, 40, 2},
1770  {14, 23, 52, 44, 2},
1771  {14, 53, 74, 42, 2},
1772  {15, 1, 8, 36, 2},
1773  {15, 23, 54, 41, 2},
1774  {15, 55, 68, 42, 2},
1775  {15, 69, 76, 39, 2},
1776  {15, 9, 22, 40, 2},
1777  {16, 1, 13, 36, 2},
1778  {16, 14, 23, 40, 2},
1779  {16, 24, 55, 41, 2},
1780  {16, 56, 65, 42, 2},
1781  {16, 66, 78, 39, 2},
1782  {17, 1, 24, 36, 2},
1783  {17, 25, 40, 37, 2},
1784  {17, 41, 56, 38, 2},
1785  {17, 57, 80, 39, 2},
1786  {18, 1, 19, 36, 2},
1787  {18, 20, 41, 37, 2},
1788  {18, 42, 63, 38, 2},
1789  {18, 64, 82, 39, 2},
1790  {19, 1, 26, 32, 2},
1791  {19, 27, 42, 37, 2},
1792  {19, 43, 58, 38, 2},
1793  {19, 59, 84, 35, 2},
1794  {20, 1, 22, 32, 2},
1795  {20, 23, 33, 33, 2},
1796  {20, 34, 43, 37, 2},
1797  {20, 44, 53, 38, 2},
1798  {20, 54, 64, 34, 2},
1799  {20, 65, 86, 35, 2},
1800 
1801  {21, 1, 4, 32, 2},
1802  {21, 25, 43, 33, 2},
1803  {21, 44, 62, 34, 2},
1804  {21, 5, 24, 28, 3},
1805  {21, 63, 82, 31, 4},
1806  {21, 83, 86, 35, 2},
1807 
1808  {22, 1, 8, 32, 2},
1809  {22, 26, 44, 33, 2},
1810  {22, 45, 63, 34, 2},
1811  {22, 64, 80, 31, 4},
1812  {22, 81, 88, 35, 2},
1813  {22, 9, 25, 28, 3},
1814 
1815  {23, 1, 10, 28, 3},
1816  {23, 11, 18, 24, 3},
1817  {23, 19, 36, 29, 3},
1818  {23, 37, 45, 33, 2},
1819  {23, 46, 54, 34, 2},
1820  {23, 55, 72, 30, 4},
1821  {23, 73, 80, 27, 4},
1822  {23, 81, 90, 31, 4},
1823 
1824  {24, 1, 15, 28, 3},
1825  {24, 16, 26, 24, 3},
1826  {24, 27, 44, 29, 3},
1827  {24, 45, 46, 33, 2},
1828  {24, 47, 48, 34, 2},
1829  {24, 49, 66, 30, 4},
1830  {24, 67, 77, 27, 4},
1831  {24, 78, 92, 31, 4},
1832 
1833  {25, 1, 20, 24, 3},
1834  {25, 21, 29, 29, 3},
1835  {25, 30, 47, 25, 3},
1836  {25, 48, 65, 26, 4},
1837  {25, 66, 74, 30, 4},
1838  {25, 75, 94, 27, 4},
1839 
1840  {26, 1, 21, 24, 3},
1841  {26, 22, 35, 29, 3},
1842  {26, 36, 48, 25, 3},
1843  {26, 49, 61, 26, 4},
1844  {26, 62, 75, 30, 4},
1845  {26, 76, 96, 27, 4},
1846 
1847  {27, 1, 24, 19, 3},
1848  {27, 25, 32, 20, 3},
1849  {27, 33, 42, 25, 3},
1850  {27, 43, 56, 21, 3},
1851  {27, 57, 66, 26, 4},
1852  {27, 67, 74, 22, 4},
1853  {27, 75, 98, 23, 4},
1854 
1855  {28, 1, 16, 19, 3},
1856  {28, 17, 24, 20, 3},
1857  {28, 25, 42, 25, 3},
1858  {28, 43, 56, 21, 3},
1859  {28, 57, 74, 26, 4},
1860  {28, 75, 82, 22, 4},
1861  {28, 83, 98, 23, 4},
1862 
1863  {29, 1, 12, 17, 3},
1864  {29, 13, 20, 19, 3},
1865  {29, 21, 42, 20, 3},
1866  {29, 43, 58, 21, 3},
1867  {29, 59, 80, 22, 4},
1868  {29, 81, 88, 23, 4},
1869  {29, 89,100, 18, 4},
1870 
1871  {30, 1, 5, 17, 3},
1872  {30, 22, 43, 20, 3},
1873  {30, 44, 59, 21, 3},
1874  {30, 60, 81, 22, 4},
1875  {30, 6, 21, 19, 3},
1876  {30, 82, 97, 23, 4},
1877  {30, 98,102, 18, 4},
1878 
1879  {31, 1, 20, 17, 3},
1880  {31, 21, 40, 13, 3},
1881  {31, 41, 42, 20, 3},
1882  {31, 43, 62, 14, 4},
1883  {31, 63, 64, 22, 4},
1884  {31, 65, 84, 15, 4},
1885  {31, 85,104, 18, 4},
1886 
1887  {32, 1, 27, 17, 3},
1888  {32, 28, 43, 13, 3},
1889  {32, 44, 63, 14, 4},
1890  {32, 64, 79, 15, 4},
1891  {32, 80,106, 18, 4},
1892 
1893  {33, 1, 32, 12, 3},
1894  {33, 33, 43, 13, 3},
1895  {33, 44, 49, 14, 4},
1896  {33, 50, 59, 9, 4},
1897  {33, 60, 65, 14, 4},
1898  {33, 66, 76, 15, 4},
1899  {33, 77,108, 16, 4},
1900 
1901  {34, 1, 28, 12, 3},
1902  {34, 29, 44, 13, 3},
1903  {34, 45, 49, 14, 4},
1904  {34, 50, 61, 9, 4},
1905  {34, 62, 66, 14, 4},
1906  {34, 67, 82, 15, 4},
1907  {34, 83,110, 16, 4},
1908 
1909  {35, 1, 19, 7, 3},
1910  {35, 20, 44, 8, 3},
1911  {35, 45, 66, 9, 4},
1912  {35, 67, 91, 10, 4},
1913  {35, 92,110, 11, 4},
1914 
1915  {36, 1, 20, 7, 3},
1916  {36, 21, 24, 12, 3},
1917  {36, 25, 46, 8, 3},
1918  {36, 47, 66, 9, 4},
1919  {36, 67, 88, 10, 4},
1920  {36, 89, 92, 16, 4},
1921  {36, 93,112, 11, 4},
1922 
1923  {37,102,114, 6, 4},
1924  {37, 1, 13, 1, 3},
1925  {37, 14, 26, 7, 3},
1926  {37, 27, 38, 2, 3},
1927  {37, 39, 45, 8, 3},
1928  {37, 46, 57, 3, 3},
1929  {37, 58, 69, 4, 4},
1930  {37, 70, 76, 10, 4},
1931  {37, 77, 88, 5, 4},
1932  {37, 89,101, 11, 4},
1933 
1934  {38,105,116, 6, 4},
1935  {38, 1, 12, 1, 3},
1936  {38, 13, 24, 7, 3},
1937  {38, 25, 36, 2, 3},
1938  {38, 37, 46, 8, 3},
1939  {38, 47, 58, 3, 3},
1940  {38, 59, 70, 4, 4},
1941  {38, 71, 80, 10, 4},
1942  {38, 81, 92, 5, 4},
1943  {38, 93,104, 11, 4},
1944 
1945  {39,100,118, 6, 4},
1946  {39, 1, 19, 1, 3},
1947  {39, 20, 39, 2, 3},
1948  {39, 40, 59, 3, 3},
1949  {39, 60, 79, 4, 4},
1950  {39, 80, 99, 5, 4},
1951 
1952  {40,101,120, 6, 4},
1953  {40, 1, 20, 1, 3},
1954  {40, 21, 40, 2, 3},
1955  {40, 41, 60, 3, 3},
1956  {40, 61, 80, 4, 4},
1957  {40, 81,100, 5, 4},
1958  };
1959 Int_t St_itpcPadGainT0C::NCrowpadFEE = sizeof(St_itpcPadGainT0C::rowpadFEE)/sizeof(rowpadFEEmap_t);
1960 //________________________________________________________________________________
1961 St_itpcPadGainT0C *St_itpcPadGainT0C::instance() {
1962  if (fgInstance) return fgInstance;
1963  St_itpcPadGainT0 *table = (St_itpcPadGainT0 *) StMaker::GetChain()->GetDataBase("Calibrations/tpc/itpcPadGainT0");
1964  if (! table) {
1965  LOG_WARN << "St_itpcPadGainT0C::instance Calibrations/tpc/itpcPadGainT0\twas not found" << endm;
1966  assert(table);
1967  }
1968  fgInstance = new St_itpcPadGainT0C(table);
1969  if (StDetectorDbMaker::instance()) {
1970  fgInstance->SetName("itpcPadGainT0C");
1971  StDetectorDbMaker::instance()->AddConst(fgInstance);
1972  }
1973  // Apply additional correction for gain tables
1974  Int_t run = StMaker::GetChain()->GetRunNumber();
1975  St_tpcExtraGainCorrectionC *extra = St_tpcExtraGainCorrectionC::instance();
1976  Int_t nrows = extra->nrows();
1977  for (Int_t i = 0; i < nrows; i++) {
1978  if (extra->idx(i) <= 0) continue;
1979  Int_t runMin = extra->runMin(i);
1980  Int_t runMax = extra->runMax(i);
1981  if (run < runMin || run > runMax) continue;
1982  Int_t sector = extra->sector(i);
1983  if (sector < 0 || sector > 24) continue;
1984  Int_t row = extra->row(i);
1985  if (row > 40) continue; // iTPC only
1986  Int_t padMin = extra->padMin(i);
1987  Int_t padMax = extra->padMax(i);
1988  Int_t RDO = extra->RDO(i);
1989  Int_t FEE = extra->FEE(i);
1990  Int_t status = extra->status(i);
1991  if (status) continue;
1992  if (padMin < padMax && row > 0) {
1993  Int_t r = row;
1994  LOG_WARN << "St_itpcPadGainT0C::instance found extra correction for run = " << run << " in [" << runMin << "," << runMax << "]"
1995  << Form(" with sec = %2i, row = %2i, padMin/Max = %3i/%3i, RDO = %2i, FEE = %2i, status = %i",
1996  sector, r, padMin, padMax, RDO, FEE, status) << endm;
1997  Float_t *gains = St_itpcPadGainT0C::instance()->Gains(sector, r);
1998  for (Int_t p = padMin; p <= padMax; p++) {
1999  if (gains[p-1] > 0) {
2000  LOG_WARN << "St_itpcPadGainT0C::instance reset gain[" << sector-1 << "][" << r - 1 << "][" << p-1 << "] = " << gains[p-1] << " to zero" << endm;
2001  }
2002  gains[p-1] = 0;
2003  }
2004  } else if (FEE > 0) {
2005  for (Int_t j = 0; j < St_itpcPadGainT0C::NCrowpadFEE; j++) {
2006  if (St_itpcPadGainT0C::rowpadFEE[j].fee != FEE) continue;
2007  Int_t r = St_itpcPadGainT0C::rowpadFEE[j].row;
2008  padMin = St_itpcPadGainT0C::rowpadFEE[j].padMin;
2009  padMax = St_itpcPadGainT0C::rowpadFEE[j].padMax;
2010  LOG_WARN << "St_itpcPadGainT0C::instance found extra correction for run = " << run << " in [" << runMin << "," << runMax << "]"
2011  << Form(" with sec = %2i, row = %2i, padMin/Max = %3i/%3i, RDO = %2i, FEE = %2i, status = %i",
2012  sector, r, padMin, padMax, RDO, FEE, status) << endm;
2013  Float_t *gains = St_itpcPadGainT0C::instance()->Gains(sector, r);
2014  for (Int_t p = padMin; p <= padMax; p++) {
2015  if (gains[p-1] > 0) {
2016  LOG_WARN << "St_itpcPadGainT0C::instance reset gain[" << sector-1 << "][" << r - 1 << "][" << p-1 << "] = " << gains[p-1] << " to zero" << endm;
2017  }
2018  gains[p-1] = 0;
2019  }
2020  }
2021  } else if (RDO > 0) {
2022  LOG_WARN << "St_itpcPadGainT0C::instance found extra correction for run = " << run << " in [" << runMin << "," << runMax << "]"
2023  << Form(" reset tpcRDOMasks for sector = %i and RDO = %i to zero with sec = %2i, row = %2i, padMin/Max = %3i/%3i, RDO = %2i, FEE = %2i, status = %i",
2024  sector, RDO, sector, row, padMin, padMax, RDO, FEE, status) << endm;
2025  St_tpcRDOMasksC::instance()->setSectorRDOMaskOff(sector,RDO);
2026  } else {
2027  LOG_WARN << "St_itpcPadGainT0C::instance found extra correction for run = " << run << " in [" << runMin << "," << runMax << "]"
2028  << Form(" with sec = %2i, row = %2i, padMin/Max = %3i/%3i, RDO = %2i, FEE = %2i, status = %i => whole sector is marker as DEAD",
2029  sector, row, padMin, padMax, RDO, FEE, status) << endm;
2030  for (Int_t rdoD = 1; rdoD <= 4; rdoD++) {
2031  St_tpcRDOMasksC::instance()->setSectorRDOMaskOff(sector,rdoD);
2032  }
2033  }
2034  }
2035  return fgInstance;
2036 }
2037 //________________________________________________________________________________
2038 #include "St_tpcPadGainT0BC.h"
2039 // tpcPadGainT0B table (indexed) is not used any more. tpcPadGainT0BChair combines nonindexed tpcPadGainT0 and itpcPadGainT0
2040 St_tpcPadGainT0BC *St_tpcPadGainT0BC::fgInstance = 0;
2041 St_tpcPadGainT0BC *St_tpcPadGainT0BC::instance() {
2042  if (! fgInstance) fgInstance = new St_tpcPadGainT0BC();
2043  return fgInstance;
2044 }
2045 //________________________________________________________________________________
2046 Float_t St_tpcPadGainT0BC::Gain(Int_t sector, Int_t row, Int_t pad) const {
2047  Float_t gain = 0;
2048  if (St_tpcPadConfigC::instance()->iTPC(sector)) {
2049  if (row <= 40) {
2050  gain = St_itpcPadGainT0C::instance()->Gain(sector,row,pad);
2051  } else {
2052  gain = St_tpcPadGainT0C::instance()->Gain(sector,row-40+13,pad);
2053  }
2054  } else { // Tpx
2055  gain = St_tpcPadGainT0C::instance()->Gain(sector,row,pad);
2056  }
2057  return gain;
2058 }
2059 //________________________________________________________________________________
2060 Float_t *St_tpcPadGainT0BC::Gains(Int_t sector, Int_t row) {
2061  Float_t *gains = 0;
2062  if (St_tpcPadConfigC::instance()->iTPC(sector)) {
2063  if (row <= 40) {
2064  gains = St_itpcPadGainT0C::instance()->Gains(sector,row);
2065  } else {
2066  gains = St_tpcPadGainT0C::instance()->Gains(sector,row-40+13);
2067  }
2068  } else { // Tpx
2069  gains = St_tpcPadGainT0C::instance()->Gains(sector,row);
2070  }
2071  return gains;
2072 }
2073 //________________________________________________________________________________
2074 Float_t St_tpcPadGainT0BC::T0(Int_t sector, Int_t row, Int_t pad) const {
2075  Float_t T0 = 0;
2076  if (St_tpcPadConfigC::instance()->iTPC(sector)) {
2077  if (row <= 40)
2078  T0 = St_itpcPadGainT0C::instance()->T0(sector,row,pad);
2079  else
2080  T0 = St_tpcPadGainT0C::instance()->T0(sector,row-40+13,pad);
2081  } else { // Tpx
2082  T0 = St_tpcPadGainT0C::instance()->T0(sector,row,pad);
2083  }
2084  return T0;
2085 }
2086 //________________________________________________________________________________
2087 Bool_t St_tpcPadGainT0BC::livePadrow(Int_t sector, Int_t row) const {
2088  if (St_tpcPadConfigC::instance()->iTPC(sector)) {
2089  if (row <= 40)
2090  return St_itpcPadGainT0C::instance()->livePadrow(sector,row);
2091  else
2092  return St_tpcPadGainT0C::instance()->livePadrow(sector,row-40+13);
2093  }
2094  return St_tpcPadGainT0C::instance()->livePadrow(sector,row);
2095 }
2096 #include "StPath2tpxGain.h"
2097 MakeChairInstance2(FilePath,StPath2tpxGain,Calibrations/tpc/Path2tpxGain);
2098 #include "StPath2itpcGain.h"
2099 MakeChairInstance2(FilePath,StPath2itpcGain,Calibrations/tpc/Path2itpcGain);
2100 //________________________________________________________________________________
2101 const Char_t * St_FilePathC::GetPath(const Char_t *prepend) {
2102  static TString path;
2103  path = prepend;
2104  path += file();
2105  gSystem->ExpandPathName(path);
2106  return path.Data();
2107 }
2108 //________________________________________________________________________________
2109 #include "St_tpcSlewingC.h"
2110 MakeChairInstance(tpcSlewing,Calibrations/tpc/tpcSlewing);
2111 #include "St_tpcAcChargeC.h"
2112 MakeChairInstance(tpcAcCharge,Calibrations/tpc/tpcAcCharge);
2113 #include "St_tpcAvCurrentC.h"
2114 MakeChairInstance(tpcAvCurrent,Calibrations/tpc/tpcAvCurrent);
2115 #include "St_TpcResponseSimulatorC.h"
2116 MakeChairInstance(TpcResponseSimulator,Calibrations/tpc/TpcResponseSimulator);
2117 #include "St_TpcPadCorrectionC.h"
2118 #include "TPolynomial.h"
2119 MakeChairInstance(TpcPadCorrection,Calibrations/tpc/TpcPadCorrection);
2120 St_TpcPadCorrectionC::St_TpcPadCorrectionC(St_TpcPadCorrection *table) : TChair(table), fFunc(0) {
2121  Int_t nrows = GetNRows();
2122  if (nrows) {
2123  fFunc = new TF1*[nrows]; memset(fFunc, 0, nrows*sizeof(TF1*));
2124  for (Int_t i = 0; i < nrows; i++) {
2125  Short_t io = Struct(i)->InOut;
2126  Short_t np = Struct(i)->npads;
2127  Short_t MuOrSigma = -1;
2128  if (Struct(i)->R == 8) MuOrSigma = 0;
2129  if (Struct(i)->R == 7) MuOrSigma = 1;
2130  if ((io < 1 || io > 2) ||
2131  (np < 1 || np > 7) ||
2132  (MuOrSigma < 0 || MuOrSigma > 1)) continue;
2133  Int_t indx = 2*(7*(io-1) + np-1)+MuOrSigma;
2134  assert(indx < nrows);
2135  fFunc[indx] = TPolynomial::MakePoly(Form("%s_%i_%i",Struct(i)->Type,np,io),Struct(i)->N-1,Struct(i)->R);
2136  fFunc[indx]->SetParameters(&Struct(i)->a0);
2137  }
2138  }
2139 }
2140 St_TpcPadCorrectionC::~St_TpcPadCorrectionC() {
2141  fgInstance = 0;
2142  if (fFunc) {
2143  Int_t nrows = GetNRows();
2144  for (Int_t i = 0; i < nrows; i++)
2145  SafeDelete(fFunc[i]);
2146  delete [] fFunc;
2147  }
2148 }
2149 #include "St_tpcGainCorrectionC.h"
2150 MakeChairInstance2(tpcCorrection,St_tpcGainCorrectionC,Calibrations/tpc/tpcGainCorrection);
2151 #include "StTpcHitErrors.h"
2152 StTpcHitErrors *StTpcHitErrors::fgInstance = 0;
2153 StTpcHitErrors *StTpcHitErrors::instance() {
2154  if (! fgInstance) {
2155  StMaker::GetChain()->GetDataBase("Calibrations/tpc/TpcHitErrors");
2156  LOG_INFO << "StTpcHitErrors have been instantiated with\n"
2157  << "StTpcHitErrors fnXZ(" << fgInstance->fXZ << "," << fgInstance->fSec << "," << fgInstance->fRow << ","
2158  << fgInstance->fMS << "," << fgInstance->fPrompt << ") = " << fgInstance->fNxz << endm;
2159  }
2160  return fgInstance;
2161 }
2162 Double_t StTpcHitErrors::calcError(Int_t iXZ, Int_t sec, Int_t row, Double_t _z, Double_t _eta, Double_t _tanl, Int_t Npads, Int_t Ntmbks, Double_t AdcL, Double_t xPad) {
2163  const static Double_t PitchLog[3] = {TMath::Log(0.335), TMath::Log(0.675), TMath::Log(5.78602945878541108e-01)};
2164  /*
2165  X[0] = fit.Npads;
2166  X[1] = fit.Ntmbks;
2167  X[2] = TMath::Tan(fit.phiL);
2168  X[3] = TMath::Tan(fit.dipL);
2169  X[4] = fit.zL;
2170  X[5] = fit.AdcL;
2171  X[6] = fit.xPad;
2172  */
2173  Int_t s = 0, r = 0, p = 0;
2174  if (sec > 12) s = 1;
2175  if (row > St_tpcPadConfigC::instance()->innerPadRows(sec)) r = 1;
2176  Int_t pitch = s;
2177  if (iXZ) pitch = 2;
2178  Double_t Vars[7] = {
2179  (Double_t )Npads, // 0 => no. of pads in cluster
2180  (Double_t )Ntmbks, // 1 => no. of time buckets in cluster
2181  -TMath::Tan(_eta), // 2 => tan(phiL)
2182  _tanl, // 3 => tan(dipL)
2183  _z, // 4 => zL
2184  TMath::Log(AdcL), // 5 => Adc counts
2185  xPad}; // 6=> xPad
2186  if (s) {// East
2187  Vars[3] = - Vars[3];
2188  Vars[4] = - Vars[4];
2189  }
2190  if (Vars[3] > 195) p = 1;
2191  TMDFParameters *mdf = GetSigmaSQ(iXZ,s,r,p);
2192  assert(mdf);
2193  Double_t valueLog = mdf->Eval(Vars);
2194  return TMath::Exp(2*(valueLog + PitchLog[pitch]));
2195 }
2196 #include "St_tpcStatusC.h"
2197 MakeChairInstance(tpcStatus,Calibrations/tpc/tpcStatus);
2198 #include "St_TpcAvgCurrentC.h"
2199 MakeChairInstance(TpcAvgCurrent,Calibrations/tpc/TpcAvgCurrent);
2200 //________________________________________________________________________________
2201 Int_t St_TpcAvgCurrentC::ChannelFromRow(Int_t sector, Int_t row) {
2202  if (row < 1 || row > St_tpcPadConfigC::instance()->padRows(sector)) return -1;
2203  if (! St_tpcPadConfigC::instance()->iTPC(sector)) {
2204  if (row < 3) return 1;
2205  if (row < 7) return 2;
2206  if (row < 10) return 3;
2207  if (row < 14) return 4;
2208  if (row < 22) return 5;
2209  if (row < 30) return 6;
2210  if (row < 38) return 7;
2211  return 8;
2212  } else { // iTPC
2213  // Jim Thomas, mail from 09/27/17
2214  if (row < 10) return 1; // 9 shared 1&2
2215  if (row < 20) return 2; // 19 shared 2&3
2216  if (row < 30) return 3; // 29 shared 3&4
2217  if (row < 14 - 13 + 40) return 4;
2218  if (row < 22 - 13 + 40) return 5;
2219  if (row < 30 - 13 + 40) return 6;
2220  if (row < 38 - 13 + 40) return 7;
2221  return 8;
2222  }
2223  return -1;
2224 }
2225 //________________________________________________________________________________
2226 Int_t St_TpcAvgCurrentC::ChannelFromSocket(Int_t socket) {
2227  Int_t channel = -1;
2228  switch (socket) {
2229  case 1:
2230  case 2 : channel = 1; break;
2231  case 3:
2232  case 4: channel = 2; break;
2233  case 5:
2234  case 6: channel = 3; break;
2235  case 7:
2236  case 8:
2237  case 17: channel = 4; break;
2238  case 9:
2239  case 10:
2240  case 18: channel = 5; break;
2241  case 11:
2242  case 12: channel = 6; break;
2243  case 13:
2244  case 14: channel = 7; break;
2245  case 15:
2246  case 16:
2247  case 19: channel = 8; break;
2248  default: break;
2249  }
2250  return channel;
2251 }
2252 //________________________________________________________________________________
2253 Float_t St_TpcAvgCurrentC::AcChargeL(Int_t sector, Int_t channel) {
2254  if (! St_TpcAvgPowerSupplyC::instance()->Table()->IsMarked()) {
2255  return St_TpcAvgPowerSupplyC::instance()->AcChargeL(sector,channel);
2256  }
2257  // static const Double_t RA[2] = { 154.484, 81.42}; // Outer/ Inner average Radii
2258  // static const Double_t WireLenth[2] = { 3.6e5, 1.6e5};
2259  // L Inner = 190222, Outer = 347303
2260  static Float_t Length[8] = {
2261  1307.59, // Channel 1
2262  1650.57, // Channel 2
2263  1993.54, // Channel 3
2264  2974.24, // Channel 4
2265  3324.59, // Channel 5
2266  3202.42, // Channel 6
2267  3545.4 , // Channel 7
2268  4398.53};// Channel 8
2269  return AcCharge(sector,channel)/Length[channel-1];
2270 }
2271 //________________________________________________________________________________
2272 Float_t St_TpcAvgCurrentC::AvCurrent(Int_t sector, Int_t channel) {
2273  if (! St_TpcAvgPowerSupplyC::instance()->Table()->IsMarked()) {
2274  return St_TpcAvgPowerSupplyC::instance()->AvCurrent(sector,channel);
2275  }
2276  return (sector > 0 && sector <= 24 && channel > 0 && channel <= 8) ?
2277  Struct()->AvCurrent[8*(sector-1)+channel-1] : 0;
2278 }
2279 //________________________________________________________________________________
2280 Float_t St_TpcAvgCurrentC::AcCharge(Int_t sector, Int_t channel) {
2281  if (! St_TpcAvgPowerSupplyC::instance()->Table()->IsMarked()) {
2282  return St_TpcAvgPowerSupplyC::instance()->AcCharge(sector,channel);
2283  }
2284  return (sector > 0 && sector <= 24 && channel > 0 && channel <= 8) ?
2285  Struct()->AcCharge[8*(sector-1)+channel-1] : 0;
2286 }
2287 #include "St_itpcRDOMapC.h"
2288 MakeChairInstance2(tpcRDOMap,St_itpcRDOMapC,Calibrations/tpc/itpcRDOMap);
2289 //________________________________________________________________________________
2290 Int_t St_itpcRDOMapC::rdo(Int_t padrow, Int_t pad) const {
2291  Int_t rdo = 0;
2292  Int_t N = nrows(0);
2293  for (Int_t i = 0; i < N; i++) {
2294  if (padrow != row(i)) continue;
2295  if (pad < padMin(i) || pad > padMax(i)) continue;
2296  rdo = rdoI(i);
2297 
2298  break;
2299  }
2300  return rdo;
2301 }
2302 #include "St_tpcRDOMapC.h"
2303 MakeChairInstance(tpcRDOMap,Calibrations/tpc/tpcRDOMap);
2304 //________________________________________________________________________________
2305 Int_t St_tpcRDOMapC::rdo(Int_t padrow, Int_t pad) const {
2306  Int_t rdo = 0;
2307  Int_t N = nrows(0);
2308  for (Int_t i = 0; i < N; i++) {
2309  if (padrow != row(i)) continue;
2310  if (pad < padMin(i) || pad > padMax(i)) continue;
2311  rdo = rdoI(i);
2312 
2313  break;
2314  }
2315  return rdo;
2316 }
2317 //________________________________________________________________________________
2318 Int_t St_tpcRDOMapC::rdo(Int_t sector, Int_t padrow, Int_t pad) const {
2319  if (St_tpcPadConfigC::instance()->iTpc(sector)) {
2320  Int_t N40 = St_tpcPadConfigC::instance()->innerPadRows(sector);
2321  if (padrow <= N40) {
2322  return St_itpcRDOMapC::instance()->rdo(padrow,pad);
2323  }
2324  return St_tpcRDOMapC::instance()->rdo(padrow-N40+13,pad) + 2;
2325  }
2326  return rdo(padrow, pad);
2327 }
2328 #include "St_tpcRDOT0offsetC.h"
2329 MakeChairInstance(tpcRDOT0offset,Calibrations/tpc/tpcRDOT0offset);
2330 Float_t St_tpcRDOT0offsetC::T0(Int_t sector, Int_t padrow, Int_t pad) const {
2331  Float_t t0 = 0;
2332  if (! IsShfited(sector)) return t0;
2333  if (St_tpcPadConfigC::instance()->iTPC(sector) && padrow <= 40) return t0; // no shift in iTPC
2334  Int_t rdo = St_tpcRDOMapC::instance()->rdo(padrow,pad);
2335  if (!rdo) return t0;
2336  t0 = Struct()->t0[sector-1][rdo-1];
2337  return t0;
2338 }
2339 
2340 #include "St_tpcBXT0CorrEPDC.h"
2341 MakeChairInstance2(tpcBXT0Corr,StTpcBXT0CorrEPDC,Calibrations/tpc/tpcBXT0CorrEPD);
2342 double StTpcBXT0CorrEPDC::getCorrection (double epdTAC, double driftVelocity, double timeBinWidth) {
2343  double timeBucketShiftScale = 500000/(driftVelocity*timeBinWidth);
2344  double generalOffset = a(0)[0];
2345  // printf("%f, %f, %f, %f, %f\n, ", epdTAC, driftVelocity, timeBinWidth, timeBucketShiftScale, generalOffset);
2346  if (epdTAC == -1) return timeBucketShiftScale*generalOffset;
2347  else return timeBucketShiftScale*(generalOffset + a(0)[1] + a(0)[2]*epdTAC);
2348 }
2349 #include "St_tpcT0BXC.h"
2350 MakeChairInstance(tpcT0BX,Calibrations/tpc/tpcT0BX);
2351 Double_t St_tpcT0BXC::getT0(Double_t values[7]) const { // xxxEarliestTDC (W+E)/2 variables for "vpd","bbc","epd","zdc", "TAC", "CAVdt"
2352  Double_t T0 = 0;
2353  Double_t T0W = 0, T0WW = 0;
2354  static Int_t __debug = 0;
2355  if (__debug > 0) {
2356  if (__debug > 1) Table()->Print(0,10);
2357  LOG_INFO << "St_tpcT0BXC::getT0:";
2358  }
2359  for (Int_t i = 0; i < 7; i++) {
2360  if (values[i] < xmin(i) || values[i] > xmax(i)) continue;
2361  if (detId(i) < 0) continue;
2362  // if (detId(i) != 6 && (CountPs(i) < 10 || CountPs(i) > 100)) continue;
2363  if (detId(i) != i+1) {
2364  LOG_WARN << "St_tpcT0BXC::getT0 : table is unsorted detId(" << i << ") != " << i+1 << " Skip entry" << endl;
2365  continue;
2366  }
2367  Double_t t0 = toff(i) + slope(i)*(values[i] - vMean(i));
2368  Double_t w = dtoff(i)* dtoff(i) + dslope(i)*(values[i] - vMean(i)) * dslope(i)*(values[i] - vMean(i));
2369  if (w < 1e-14) continue;
2370  T0W += t0/w;
2371  T0WW += 1./w;
2372  if (__debug > 0) {
2373  LOG_INFO << Form("%s = %7.2f -> %7.2f +/- %7.2f nsec ",name(i),values[i], 1e3*t0, 1e3*TMath::Sqrt(w));
2374  }
2375  }
2376  if (T0WW > 0) {
2377  T0 = T0W/T0WW;
2378  if (__debug > 0) {
2379  LOG_INFO << Form(" : T0 = %7.2f +/- %7.2f nsec", 1e3*T0, 1e3/TMath::Sqrt(T0WW)) << endm;
2380  }
2381  }
2382  return T0;
2383 }
2384 #include "St_starTriggerDelayC.h"
2385 MakeChairOptionalInstance2(starTriggerDelay,St_starTriggerDelayC,Calibrations/tpc/starTriggerDelay);
2386 //________________________________________________________________________________
2387 Float_t St_starTriggerDelayC::TrigT0(Int_t i) const {
2388  return clocks(i)/(1e-6*St_starClockOnlC::instance()->CurrentFrequency()) + tZero(i);
2389 }
2390 //________________________________________________________________________________
2391 Float_t St_starTriggerDelayC::TrigT0GG(Int_t io, Int_t i) const {
2392  Float_t delay = TrigT0(i); // usec add Gating Grid cable
2393  delay += 0.150; // length 30 m, delay 150ns for both Inner and Outer sectors, measured by A.Lebedev 10/13/2023
2394  if (! io) delay += -0.123;
2395  else delay += -0.502;
2396  return delay;
2397 }
2398 //__________________Calibrations/trg______________________________________________________________
2399 #include "St_defaultTrgLvlC.h"
2400 MakeChairInstance(defaultTrgLvl,Calibrations/trg/defaultTrgLvl);
2401 #include "St_trigDetSumsC.h"
2402 St_trigDetSumsC *St_trigDetSumsC::fgInstance = 0;
2403 //________________________________________________________________________________
2404 St_trigDetSumsC::~St_trigDetSumsC() {
2405  fgInstance = 0;
2406 }
2407 //________________________________________________________________________________
2408 St_trigDetSumsC *St_trigDetSumsC::instance() {
2409  if (fgInstance) {
2410 #if 0
2411  static trigDetSums_st *sOld = 0;
2412  static Int_t iBreak = 0;
2413  if (iBreak < 3) {
2414  St_trigDetSums *table = (St_trigDetSums *) fgInstance->Table();
2415  trigDetSums_st *s = table->GetTable();
2416  if (s != sOld) {
2417  LOG_QA << "new trigDetSums" << endm;
2418  DEBUGTABLE("trigDetSums");
2419  sOld = s;
2420  iBreak++;
2421  }
2422  }
2423 #endif
2424  return fgInstance;
2425  }
2426  St_trigDetSums *table = (St_trigDetSums *) StMaker::GetChain()->GetDataSet("inputStream_DAQ/trigDetSums");
2427  if (! table) table = (St_trigDetSums *) StMaker::GetChain()->GetDataSet("StEvent/trigDetSums");
2428  if (table) {
2429  static Int_t iBreak = 0;
2430  if (iBreak < 3) {
2431  LOG_QA << "get trigDetSums from GetDataSet" << endm;
2432  iBreak++;
2433  }
2434  fgInstance = new St_trigDetSumsC(table);
2435  StMaker::GetChain()->AddData(fgInstance);
2436  return fgInstance;
2437  }
2438  table = (St_trigDetSums *) StMaker::GetChain()->GetDataBase("Calibrations/rich/trigDetSums");
2439  assert(table);
2440  LOG_QA << "get trigDetSums from GetDataBase" << endm;
2441  fgInstance = new St_trigDetSumsC(table);
2442  fgInstance->SetName("trigDetSumsC");
2443  StMaker::GetChain()->AddConst(fgInstance);
2444  return fgInstance;
2445 }
2446 ClassImp(St_trigDetSumsC);
2447 #include "St_EbyET0C.h"
2448 MakeChairInstance(EbyET0,Calibrations/trg/EbyET0);
2449 Double_t St_EbyET0C::time(Int_t i, Double_t x) {
2450  Double_t* pars = par(i);
2451  Double_t t = 0;
2452  switch (func(i)) {
2453  case 0 : // polynomial
2454  t = pars[3];
2455  for (Int_t n=2; n>=0; n--) t += x*t + pars[n];
2456  break;
2457  }
2458  return t;
2459 }
2460 //___________________tpc_____________________________________________________________
2461 #include "St_tss_tssparC.h"
2462 MakeChairInstance(tss_tsspar,tpc/tsspars/tsspar);
2463 //________________________________________________________________________________
2464 Float_t St_tss_tssparC::gain(Int_t sector, Int_t row) {
2465  Int_t l = 0;
2466  Double_t V_nominal = 1390;
2467  Float_t V = 0;
2468  Float_t gain = 0;
2469  if (row <= St_tpcPadConfigC::instance()->innerPadRows(sector)) {l = 1; V_nominal = 1170;}
2470  St_tpcGainCorrectionC *gC = St_tpcGainCorrectionC::instance();
2471  Int_t NRows = gC->GetNRows();
2472  if (l >= NRows) return gain;
2473  V = St_tpcAnodeHVavgC::instance()->voltagePadrow(sector,row);
2474  if (V > 0) {
2475  Double_t v = V - V_nominal;
2476 #if 0
2477  // Hack for Run XVI
2478  if ( gC->min(l) > -1 && v > -100 && v < 0) {
2479  if (l == 0) v = 0;
2480  else v = -70;
2481  } else
2482 #endif
2483  if (v < gC->min(l) || v > gC->max(l)) return gain;
2484  if (gC->min(l) < -450) {
2485  // if range was expanded below 150 V then use only the linear approximation
2486  gain = TMath::Exp(gC->CalcCorrection(l,v, 0., 2));
2487  } else {
2488  gain = TMath::Exp(gC->CalcCorrection(l,v));
2489  }
2490  }
2491  return gain;
2492 }
2493 //__________________Calibrations/tracker______________________________________________________________
2494 #include "St_tpcMaxHitsC.h"
2495 MakeChairInstance(tpcMaxHits,Calibrations/tracker/tpcMaxHits);
2496 //__________________Calibrations/rich______________________________________________________________
2497 #include "St_richvoltagesC.h"
2498 MakeChairInstance(richvoltages,Calibrations/rich/richvoltages);
2499 #include "St_y1MultC.h"
2500 MakeChairInstance(y1Mult,Calibrations/rich/y1Mult);
2501 #include "St_spaceChargeCorC.h"
2502 ClassImp(St_spaceChargeCorC);
2503 MakeChairInstance2(spaceChargeCor,St_spaceChargeCorR1C,Calibrations/rich/spaceChargeCor);
2504 MakeChairInstance2(spaceChargeCor,St_spaceChargeCorR2C,Calibrations/rich/spaceChargeCorR2);
2505 //_________________RunLog_____________________________________________________________
2506 #include "St_MagFactorC.h"
2507 MakeChairInstance(MagFactor,RunLog/MagFactor);
2508 //_________________RunLog/onl_______________________________________________________________
2509 MakeChairInstance(starClockOnl,RunLog/onl/starClockOnl);
2510 //________________________________________________________________________________
2511 starClockOnl_st *St_starClockOnlC::Struct(Int_t i) {
2512  starClockOnl_st *s = ((St_starClockOnl* ) instance()->Table())->GetTable();
2513  Int_t N = getNumRows(); // with i < 0 look for positive frequency
2514  if (i >= 0 && i < N) return s + i;
2515  for (Int_t j = 0; j < N; j++, s++) if (s->frequency > 0) break;
2516  assert(s->frequency > 0 && s->frequency < 1e7);
2517  return s;
2518 }
2519 #include "St_starMagOnlC.h"
2520 MakeChairInstance(starMagOnl,RunLog/onl/starMagOnl);
2521 #include "St_starMagAvgC.h"
2522 MakeChairOptionalInstance(starMagAvg,RunLog/onl/starMagAvg);
2523 #include "St_beamInfoC.h"
2524 MakeChairInstance(beamInfo,RunLog/onl/beamInfo);
2525 static Double_t kuAtomicMassUnit = 931.4940054e-3;
2526 static Double_t kProtonMass = kuAtomicMassUnit*1.00727646662;
2527 //________________________________________________________________________________
2528 Bool_t St_beamInfoC::IsFixedTarget() {
2529  Bool_t isFixTag = kFALSE;
2530  Float_t MaxIntensity = TMath::Max(blueIntensity(), yellowIntensity());
2531  Float_t MinIntensity = TMath::Min(blueIntensity(), yellowIntensity());
2532  if (MaxIntensity > 0.5) {
2533  if (MaxIntensity > 1000*MinIntensity) isFixTag = kTRUE;
2534  } else if (yellowIntensity() < 0.5) {
2535  //Fix for beamInfo for fixedTarget with yellowIntensity < 1
2536  if ((runNumber() >= 20181040 && runNumber() <= 20181045) || // 4p59GeV_fixedTarget_2019
2537  (runNumber() >= 20182006 && runNumber() <= 20182018) ||
2538  runNumber() == 22121022 || // tune_3p85GeV_fixedTarget_2021
2539  runNumber() == 22158035 ||
2540  runNumber() == 22166031 // 3p85GeV_fixedTarget_2021
2541  ) isFixTag = kTRUE;
2542  }
2543  return isFixTag;
2544 }
2545 //________________________________________________________________________________
2546 Float_t St_beamInfoC::GammaYellow() {
2547  Float_t gamma = 1;
2548  Int_t N = TMath::Nint(getYellowMassNumber()); // no. of nucleons
2549  if (N < 1) N = 1;
2550  Double_t E = N*getYellowEnergy(); // total energy per nucleon
2551  Double_t M = kuAtomicMassUnit*N;
2552  gamma = E/M;
2553  return gamma;
2554 }
2555 //________________________________________________________________________________
2556 Float_t St_beamInfoC::GammaBlue() {
2557  Float_t gamma = 1;
2558  if (! IsFixedTarget()) {
2559  Int_t N = TMath::Nint(getBlueMassNumber()); // no. of nucleons
2560  if (N < 1) N = 1;
2561  Double_t E = N*getBlueEnergy(); // total energy
2562  Double_t M = kuAtomicMassUnit*N;
2563  if (E < M) E = M;
2564  gamma = E/M;
2565  }
2566  return gamma;
2567 }
2568 //________________________________________________________________________________
2569 Float_t St_beamInfoC::GammaCMS() {
2570  Double_t eBlue = kProtonMass*GammaBlue();
2571  Double_t eYellow = kProtonMass*GammaYellow();
2572  Double_t Etot = eBlue + eYellow;
2573  Double_t Ecm = SqrtS();
2574  Double_t gammaCM = Etot/Ecm;
2575  return gammaCM;
2576 }
2577 //________________________________________________________________________________
2578 Float_t St_beamInfoC::BetaBlue() {
2579  Float_t gamma = GammaBlue();
2580  return TMath::Sqrt(1 - 1./(gamma*gamma));
2581 }
2582 //________________________________________________________________________________
2583 Float_t St_beamInfoC::BetaYellow() {
2584  Float_t gamma = GammaYellow();
2585  return -TMath::Sqrt(1 - 1./(gamma*gamma));
2586 }
2587 //________________________________________________________________________________
2588 Float_t St_beamInfoC::BetaCMS() {
2589  Double_t eBlue = kProtonMass*GammaBlue();
2590  Double_t eYellow = kProtonMass*GammaYellow();
2591  Double_t Etot = eBlue + eYellow;
2592  Double_t betaCM = (eBlue*BetaBlue() + eYellow*BetaYellow())/Etot;
2593  return betaCM;
2594 }
2595 //________________________________________________________________________________
2596 Float_t St_beamInfoC::SqrtS() {
2597  static Double_t mP = kuAtomicMassUnit*1.00727646662; // proton mass
2598  Double_t eBlue = mP*GammaBlue();
2599  Double_t eYellow = mP*GammaYellow();
2600  return TMath::Sqrt(2*mP*mP + 2*eBlue*eYellow*(1 - BetaBlue()*BetaYellow()));
2601 }
2602 //________________________________________________________________________________
2603 Float_t St_beamInfoC::Ycms() {
2604  Double_t gammaCM = GammaCMS();
2605  Double_t betaCM = BetaCMS();
2606  Double_t yCM = TMath::Log(gammaCM*(1 + betaCM));
2607  return yCM;
2608 }
2609 //________________________________________________________________________________
2610 Float_t St_beamInfoC::Frequency() {
2611  static Double_t l = 3833.845*9.99999253982746361e-01;// *9.99988614393081399e-01;// *9.99998896969437556e-01; // RHIC perimetr
2612  static Double_t NB = 120; // no. of buches, can be changed
2613  Double_t frequency = 1e-6*NB*BetaYellow()*TMath::C()/l;
2614  return TMath::Abs(frequency);
2615 }
2616 //________________________________________________________________________________
2617 #include "St_triggerInfoC.h"
2618 MakeChairInstance(triggerInfo,RunLog/onl/triggerInfo);
2619 #include "St_triggerIDC.h"
2620 MakeChairInstance(triggerID,RunLog/onl/triggerID);
2621 //________________________________________________________________________________
2622 #include "St_trigPrescalesC.h"
2623 MakeChairOptionalInstance(trigPrescales,RunLog/onl/trigPrescales);
2624 //________________________________________________________________________________
2625 #include "St_L0TriggerInfoC.h"
2626 MakeChairInstance(L0TriggerInfo,RunLog/onl/L0TriggerInfo);
2627 #include "St_trigL3ExpandedC.h"
2628 MakeChairOptionalInstance(trigL3Expanded,RunLog/onl/trigL3Expanded);
2629 #include "St_dsmPrescalesC.h"
2630 MakeChairOptionalInstance(dsmPrescales,RunLog/onl/dsmPrescales);
2631 #include "St_additionalTriggerIDC.h"
2632 MakeChairOptionalInstance(additionalTriggerID,RunLog/onl/additionalTriggerID);
2633 #include "StDetectorDbTriggerID.h"
2634 StDetectorDbTriggerID *StDetectorDbTriggerID::fgInstance = 0;
2635 //________________________________________________________________________________
2637  map<Int_t,Float_t> value;
2638  // First walk forward through the multiple levels of prescales
2639  for (UInt_t irow=0;irow<getDsmPrescalesNumRows(); ++irow) {
2640  Int_t trgId = getDsmPrescalesTrgId(irow);
2641  value[trgId] = Float_t(getDsmPrescalesDsmPrescale(irow));
2642  }
2643 
2644  for (UInt_t irow=0; irow<getL0NumRows(); ++irow) {
2645  Int_t trgId = getL0OfflineTrgId(irow);
2646  map<Int_t,Float_t>::iterator p=value.find(trgId);
2647  if (p != value.end()) {
2648  (*p).second *= Float_t(getPsL0(irow));
2649  }
2650  else {
2651  value[trgId] = Float_t(getPsL0(irow));
2652  }
2653  }
2654  // For completeness: this one is always unity as far as I can tell
2655  for (UInt_t irow=0; irow<getSNumRows(); ++irow) {
2656  UInt_t idxTrigger = getIdxTrigger(irow);
2657  Int_t trgId = 0;
2658  for (UInt_t jrow=0; jrow<getIDNumRows(); ++jrow) {
2659  if (idxTrigger == getIdxTrg(jrow)) {
2660  trgId = getOfflineTrgId(jrow);
2661  break;
2662  }
2663  }
2664  map<Int_t,Float_t>::iterator p=value.find(trgId);
2665 
2666  if (p != value.end()) {
2667  (*p).second *= Float_t(getPs(irow));
2668  }
2669  else {
2670  value[trgId] = Float_t(getPs(irow));
2671  }
2672  }
2673 
2674  // Now deal with L3Expanded
2675  for (UInt_t irow=0; irow<getTrigL3ExpandedNumRows(); ++irow) {
2676  Int_t oldtid = getTrigL3ExpandedL3TrgId(irow);
2677  Int_t newtid = getTrigL3ExpandedL3ExpandedTrgId(irow);
2678  Float_t l2ps = getTrigL3ExpandedL2Ps(irow);
2679 
2680  map<Int_t,Float_t>::iterator p = value.find(oldtid);
2681  if (p!= value.end()) {
2682  value[newtid] = ((*p).second)*l2ps;
2683  }
2684  else {
2685  value[newtid] = l2ps;
2686  }
2687 
2688  }
2689  return value;
2690 }
2691 //________________________________________________________________________________
2693  map<Int_t,Float_t> theMap = getTotalPrescales();
2694  map<Int_t,Float_t>::const_iterator p = theMap.find(trgId);
2695  if (p != theMap.end()) {
2696  return (*p).second;
2697  }
2698  else {
2699  return 0;
2700  }
2701 }
2702 //________________________________________________________________________________
2703 #include "StDetectorDbIntegratedTriggerID.h"
2704 StDetectorDbIntegratedTriggerID *StDetectorDbIntegratedTriggerID::fgInstance = 0;
2705 //___________________Conditions/trg_____________________________________________________________
2706 #include "St_trgTimeOffsetC.h"
2707 MakeChairAltInstance(trgTimeOffset,Conditions/trg/trgTimeOffset,Conditions/trg/trgTimeOffsetB,gEnv->GetValue("NewTpcAlignment",0));
2708 //___________________Geometry/tpc_____________________________________________________________
2709 #include "St_tpcDimensionsC.h"
2710 MakeChairInstance(tpcDimensions,Geometry/tpc/tpcDimensions);
2711 #include "St_tpcWirePlanesC.h"
2712 MakeChairInstance(tpcWirePlanes,Geometry/tpc/tpcWirePlanes);
2713 #include "St_tpcSectorPositionC.h"
2714 ClassImp(St_tpcSectorPositionC);
2715 St_tpcSectorPositionC *St_tpcSectorPositionC::fgInstance = 0;
2716 St_tpcSectorPosition *St_tpcSectorPositionC::fgTables[24] = {0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0};
2717 St_tpcSectorPositionC *St_tpcSectorPositionC::instance() {
2718  if (fgInstance) return fgInstance;
2719  TDataSet *tpc = StMaker::GetChain()->GetDataBase("Geometry/tpc");
2720  assert(tpc);
2721  for (Int_t sec = 1; sec <= 24; sec++) {
2722  TString path = Form("Sector_%02i/tpcSectorPosition",sec);
2723  fgTables[sec-1] = (St_tpcSectorPosition *) tpc->Find(path.Data());
2724  if (! fgTables[sec-1]) {
2725  LOG_WARN << "St_tpcSectorPositionC::instance " << tpc->GetTitle() << "/" << path.Data()
2726  << "\twas not found" << endm;
2727  assert(fgTables[sec-1]);
2728  }
2729  {
2730  TDatime t[2];
2731  St_db_Maker::GetValidity(fgTables[sec-1],t);
2732  Int_t Nrows = fgTables[sec-1]->GetNRows();
2733  LOG_WARN << "St_tpcSectorPositionC::instance found table " << fgTables[sec-1]->GetName()
2734  << " with NRows = " << Nrows << " in db"
2735  << Form("\tValidity:%08i.%06i --- %08i.%06i",t[0].GetDate(),t[0].GetTime(),t[1].GetDate(),t[1].GetTime()) << endm;
2736  fgTables[sec-1]->Print(0,1);
2737  }
2738  }
2739  fgInstance = new St_tpcSectorPositionC();
2740  return fgInstance;
2741 }
2742 #include "St_tpcFieldCageC.h"
2743 MakeChairInstance(tpcFieldCage,Geometry/tpc/tpcFieldCage);
2744 MakeChairInstance(tpcPadPlanes,Geometry/tpc/tpcPadPlanes);
2745 MakeChairInstance(itpcPadPlanes,Geometry/tpc/itpcPadPlanes);
2746 MakeChairInstance(tpcPadConfig,Geometry/tpc/tpcPadConfig);
2747 #include "St_tpcGlobalPositionC.h"
2748 MakeChairInstance(tpcGlobalPosition,Geometry/tpc/tpcGlobalPosition);
2749 #include "St_tpcFieldCageShortC.h"
2750 MakeChairInstance(tpcFieldCageShort,Geometry/tpc/tpcFieldCageShort);
2751 #include "St_tpcHVPlanesC.h"
2752 MakeChairInstance(tpcHVPlanes,Geometry/tpc/tpcHVPlanes);
2753 #include "St_SurveyC.h"
2754 ClassImp(St_SurveyC);
2755 #include "StSvtSurveyC.h"
2756 MakeChairInstance2(Survey,StSvtOnGlobal,Geometry/svt/SvtOnGlobal);
2757 MakeChairInstance2(Survey,StSvtShellOnGlobal,Geometry/svt/ShellOnGlobal);
2758 MakeChairInstance2(Survey,StSvtLadderOnSurvey,Geometry/svt/LadderOnSurvey);
2759 MakeChairInstance2(Survey,StSvtLadderOnShell,Geometry/svt/LadderOnShell);
2760 MakeChairInstance2(Survey,StSvtWaferOnLadder,Geometry/svt/WaferOnLadder);
2761 #include "StSsdSurveyC.h"
2762 MakeChairInstance2(Survey,StSsdOnGlobal,Geometry/ssd/SsdOnGlobal);
2763 MakeChairInstance2(Survey,StSsdSectorsOnGlobal,Geometry/ssd/SsdSectorsOnGlobal);
2764 MakeChairInstance2(Survey,StSsdLaddersOnSectors,Geometry/ssd/SsdLaddersOnSectors);
2765 MakeChairInstance2(Survey,StSsdWafersOnLadders,Geometry/ssd/SsdWafersOnLadders);
2766 #include "StSstSurveyC.h"
2767 MakeChairInstance2(Survey,StoscOnTpc,Geometry/sst/oscOnTpc);
2768 MakeChairInstance2(Survey,StsstOnOsc,Geometry/sst/sstOnOsc);
2769 MakeChairInstance2(Survey,StsstLadderOnSst,Geometry/sst/sstLadderOnSst);
2770 MakeChairInstance2(Survey,StsstSensorOnLadder,Geometry/sst/sstSensorOnLadder);
2771 #include "StTpcSurveyC.h"
2772 MakeChairAltInstance2(Survey,StTpcInnerSectorPosition,Geometry/tpc/TpcInnerSectorPosition,Geometry/tpc/TpcInnerSectorPositionB,gEnv->GetValue("NewTpcAlignment",0));
2773 MakeChairAltInstance2(Survey,StTpcOuterSectorPosition,Geometry/tpc/TpcOuterSectorPosition,Geometry/tpc/TpcOuterSectorPositionB,gEnv->GetValue("NewTpcAlignment",0));
2774 MakeChairAltInstance2(Survey,StTpcSuperSectorPosition,Geometry/tpc/TpcSuperSectorPosition,Geometry/tpc/TpcSuperSectorPositionB,gEnv->GetValue("NewTpcAlignment",0));
2775 MakeChairInstance2(Survey,StTpcHalfPosition,Geometry/tpc/TpcHalfPosition);
2776 MakeChairInstance2(Survey,StTpcPosition,Geometry/tpc/TpcPosition);
2777 #include "St_iTPCSurveyC.h"
2778 MakeChairInstance(iTPCSurvey,Geometry/tpc/iTPCSurvey);
2779 //____________________________Geometry/gmt____________________________________________________
2780 #include "StGmtSurveyC.h"
2781 MakeChairInstance2(Survey,StGmtOnTpc,Geometry/gmt/GmtOnTpc);
2782 MakeChairInstance2(Survey,StGmtOnModule,Geometry/gmt/GmtOnModule);
2783 //____________________________Geometry/ist____________________________________________________
2784 #include "StIstSurveyC.h"
2785 MakeChairInstance2(Survey,StidsOnTpc,Geometry/ist/idsOnTpc);
2786 MakeChairInstance2(Survey,StpstOnIds,Geometry/ist/pstOnIds);
2787 MakeChairInstance2(Survey,StistOnPst,Geometry/ist/istOnPst);
2788 MakeChairInstance2(Survey,StLadderOnIst,Geometry/ist/istLadderOnIst);
2789 MakeChairInstance2(Survey,StistSensorOnLadder,Geometry/ist/istSensorOnLadder);
2790 //____________________________Geometry/pxl____________________________________________________
2791 #include "StPxlSurveyC.h"
2792 MakeChairInstance2(Survey,StPxlpstOnIds,Geometry/pxl/pstOnIds);
2793 MakeChairInstance2(Survey,StpxlOnPst,Geometry/pxl/pxlOnPst);
2794 MakeChairInstance2(Survey,StpxlHalfOnPxl,Geometry/pxl/pxlHalfOnPxl);
2795 MakeChairInstance2(Survey,StpxlSectorOnHalf,Geometry/pxl/pxlSectorOnHalf);
2796 MakeChairInstance2(Survey,StpxlLadderOnSector,Geometry/pxl/pxlLadderOnSector);
2797 MakeChairInstance2(Survey,StpxlSensorOnLadder,Geometry/pxl/pxlSensorOnLadder);
2798 #include "St_pxlControlC.h"
2799 MakeChairInstance(pxlControl,Geometry/pxl/pxlControl);
2800 #include "St_pxlSensorTpsC.h"
2801 MakeChairInstance(pxlSensorTps,Geometry/pxl/pxlSensorTps);
2802 //________________________________________________________________________________
2803 St_SurveyC::St_SurveyC(St_Survey *table) : TChair(table), fRotations(0) {
2804  UInt_t N = getNumRows();
2805  fRotations = new TGeoHMatrix*[N];
2806  for (UInt_t i = 0; i < N; i++) {
2807  fRotations[i] = new TGeoHMatrix;
2808  TGeoHMatrix &rot = *fRotations[i];
2809  if (N == 1) rot.SetName(Table()->GetName());
2810  else rot.SetName(Form("%s_%i",Table()->GetName(),i+1));
2811  rot.SetRotation(Rotation(i));
2812  rot.SetTranslation(Translation(i));
2813  Normalize(rot);
2814  assert(TMath::Abs(rot.Determinant())-1 < 1.e-3);
2815  }
2816 }
2817 //________________________________________________________________________________
2818 St_SurveyC::~St_SurveyC() {
2819  if (fRotations) {
2820  for (UInt_t i = 0; i < getNumRows(); i++) {
2821  SafeDelete(fRotations[0]);
2822  }
2823  SafeDelete(fRotations);
2824  }
2825 }
2826 //________________________________________________________________________________
2827 Double_t St_SurveyC::IsOrtogonal(const Double_t *r) {
2828 // Perform orthogonality test for rotation.
2829  Double_t cmax = 0;
2830  Double_t cij;
2831  for (Int_t i=0; i<2; i++) {
2832  for (Int_t j=i+1; j<3; j++) {
2833  // check columns
2834  cij = TMath::Abs(r[i]*r[j]+r[i+3]*r[j+3]+r[i+6]*r[j+6]);
2835  if (cij>1E-4) cmax = cij;
2836  // check rows
2837  cij = TMath::Abs(r[3*i]*r[3*j]+r[3*i+1]*r[3*j+1]+r[3*i+2]*r[3*j+2]);
2838  if (cij>cmax) cmax = cij;
2839  }
2840  }
2841  return cmax;
2842 }
2843 //________________________________________________________________________________
2844 void St_SurveyC::Normalize(TGeoHMatrix &R) {
2845 #if 0
2846  Double_t det = R.Determinant();
2847  Double_t ort = IsOrtogonal(R.GetRotationMatrix());
2848  static Double_t eps = 1e-7;
2849  if ( TMath::Abs(TMath::Abs(det) - 1) < eps && ort < eps) return;
2850  LOG_INFO << "St_SurveyC::Normalize matrix " << R.GetName()
2851  << Form(" has determinant-1 = %10.7f\tortoganality %10.7f",TMath::Abs(det)-1,ort) << endm;
2852  cout << "Old\t"; R.Print();
2853  const Double_t *r = R.GetRotationMatrix();
2854  SMatrix<double,3,3> A(r,9); // cout << "A: " << endl << A << endl;
2855  SMatrix<double,3,3> B = A;
2856  A.Det(det); // cout << "Determinant - 1: " << det-1 << endl; cout << "A again: " << endl << A << endl;
2857  A = B;
2858  A.Invert();// cout << "A^-1: " << endl << A << endl;
2859  // check if this is really the inverse: cout << "A^-1 * B: " << endl << A * B << endl;
2860  // the Babylonian method for extracting the square root of a matrix : Q_{n+1} = 2 * M * ((Q_{n}^{-1} * M) + (M^{T} *Q_{n}))^{-1}
2861  SMatrix<double,3,3> Qn1;
2862  SMatrix<double,3,3> Qn2;
2863  SMatrix<double,3,3> M = B;
2864  SMatrix<double,3,3> Qn = M;
2865  Int_t ifail = 0;
2866  Int_t N = 0;
2867  Qn.Det(det); if (_debug) {LOG_INFO << "N " << N << "\tQn Determinant - 1: " << Form("%15.5g",det-1) << endm;}
2868  Qn = M;
2869  while (TMath::Abs(TMath::Abs(det) - 1) > eps) {
2870  SMatrix<double,3> QnInv = Qn.Inverse(ifail);
2871  if (ifail) {
2872  LOG_ERROR << "St_SurveyC::Normalize:: Qn inversion failed" << endm;
2873  break;
2874  }
2875  SMatrix<double,3,3> C1 = QnInv * M;
2876  SMatrix<double,3,3> C2 = Transpose(M) * Qn;
2877  SMatrix<double,3,3> C = C1 + C2;
2878  SMatrix<double,3,3> CInv = C.Inverse(ifail);
2879  if (ifail) {
2880  LOG_ERROR << "St_SurveyC::Normalize:: C inversion failed" << endm;
2881  break;
2882  }
2883  Qn1 = 2 * M * CInv;
2884  Qn2 = Qn1;
2885  N++;
2886  Qn2.Det(det); if (_debug) {LOG_INFO << "N " << N << "\tQn2 Determinant - 1: " << Form("%15.5g",det-1) << endm;}
2887  if (N > 13) break;
2888  Qn = Qn1;
2889  if (_debug) {LOG_INFO << "Qn:" << endl << Qn << endm;}
2890  }
2891  R.SetRotation(Qn.Array()); cout << "New\t"; R.Print();
2892 #endif
2893  if (_debug) {
2894  LOG_INFO << "Matrix:" << endm; R.Print("");
2895  LOG_INFO << "Determinant-1 = " << R.Determinant()-1 << endm;
2896  const Double_t *rr = R.GetRotationMatrix();
2897  LOG_INFO << "Ortogonality " << IsOrtogonal(rr) << endm;
2898  }
2899  return;
2900 }
2901 //________________________________________________________________________________
2902 const TGeoHMatrix &St_SurveyC::GetMatrix(Int_t i) {
2903  assert(fRotations || fRotations[i]);
2904  assert(TMath::Abs(fRotations[i]->Determinant())-1 < 1.e-3);
2905  return *fRotations[i];
2906 }
2907 //________________________________________________________________________________
2908 const TGeoHMatrix &St_SurveyC::GetMatrix4Id(Int_t id) {
2909  for (UInt_t i = 0; i < getNumRows(); i++) {
2910  if (Id(i) == id) {
2911  return GetMatrix(i);
2912  }
2913  }
2914  LOG_INFO << "St_SurveyC::GetMatrix4Id(" << id << ") entry has not been found" << endm;
2915  const TTable *table = Table();
2916  Int_t Nrows = table->GetNRows();
2917  table->Print(0,Nrows);
2918  assert(0);
2919  return GetMatrix(0);
2920 }
2921 //________________________________________________________________________________
2922 const TGeoHMatrix &St_SurveyC::GetMatrixR(Int_t i) {
2923  static TGeoHMatrix rot;
2924  Double_t rotations[9] = {
2925  r00(i), r01(i), 0,
2926  r10(i), r11(i), 0,
2927  0 , 0, r22(i)};
2928  rot.SetName(Form("%s_%i",Table()->GetName(),i));
2929  rot.SetRotation(rotations);
2930  rot.SetTranslation(Translation(i));
2931  return *&rot;
2932 }
2933 //________________________________________________________________________________
2934 void St_SurveyC::GetAngles(Double_t &phi, Double_t &the, Double_t &psi, Int_t i) {
2935  phi = the = psi = 0; // Korn 14.10-5
2936  Double_t cosDelta = (r00(i) + r11(i) + r22(i) - 1)/2; // (Tr(R) - 1)/2
2937  Double_t Delta = TMath::ACos(cosDelta);
2938  if (Delta < 0) Delta += 2*TMath::Pi();
2939  Double_t sinDelta2 = TMath::Sin(Delta/2);
2940  if (TMath::Abs(sinDelta2) < 1.e-7) return;
2941  Double_t c[3] = {
2942  (r21(i) - r12(i))/(2*sinDelta2), // a32-a23
2943  (r02(i) - r20(i))/(2*sinDelta2), // a13-a31
2944  (r10(i) - r01(i))/(2*sinDelta2) // a21-a12
2945  };
2946  Double_t u = TMath::ATan2(c[0],c[1]);
2947  Double_t v = TMath::ATan(c[2]*TMath::Tan(Delta/2));
2948  phi = (v - u)/2 - TMath::Pi()/2;
2949  psi = (v + u)/2 - TMath::Pi()/2;
2950  the = 2*TMath::ATan2(c[0]*TMath::Sin(v),c[2]*TMath::Sin(u));
2951  Double_t raddeg = 180./TMath::Pi();
2952  phi *= raddeg;
2953  the *= raddeg;
2954  psi *= raddeg;
2955 }
2956 //________________________________________________________________________________
2957 St_SurveyC *St_SurveyC::instance(const Char_t *name) {
2958  TString Name(name);
2959  if (Name == "SvtOnGlobal") return (St_SurveyC *) StSvtOnGlobal::instance();
2960  if (Name == "ShellOnGlobal") return (St_SurveyC *) StSvtShellOnGlobal::instance();
2961  if (Name == "LadderOnSurvey") return (St_SurveyC *) StSvtLadderOnSurvey::instance();
2962  if (Name == "LadderOnShell") return (St_SurveyC *) StSvtLadderOnShell::instance();
2963  if (Name == "WaferOnLadder") return (St_SurveyC *) StSvtWaferOnLadder::instance();
2964  if (Name == "SsdOnGlobal") return (St_SurveyC *) StSsdOnGlobal::instance();
2965  if (Name == "SsdSectorsOnGlobal") return (St_SurveyC *) StSsdSectorsOnGlobal::instance();
2966  if (Name == "SsdLaddersOnSectors") return (St_SurveyC *) StSsdLaddersOnSectors::instance();
2967  if (Name == "SsdWafersOnLadders") return (St_SurveyC *) StSsdWafersOnLadders::instance();
2968  if (Name == "TpcInnerSectorPosition") return (St_SurveyC *) StTpcInnerSectorPosition::instance();
2969  if (Name == "TpcOuterSectorPosition") return (St_SurveyC *) StTpcOuterSectorPosition::instance();
2970  if (Name == "TpcSuperSectorPosition") return (St_SurveyC *) StTpcSuperSectorPosition::instance();
2971  if (Name == "TpcHalfPosition") return (St_SurveyC *) StTpcHalfPosition::instance();
2972  if (Name == "idsOnTpc") return (St_SurveyC *) StidsOnTpc::instance();
2973  if (Name == "pstOnIds") return (St_SurveyC *) StpstOnIds::instance();
2974  if (Name == "istOnPst") return (St_SurveyC *) StistOnPst::instance();
2975  if (Name == "LadderOnIst") return (St_SurveyC *) StLadderOnIst::instance();
2976  if (Name == "LadderOnShell") return (St_SurveyC *) StSvtLadderOnShell::instance();
2977  if (Name == "istSensorOnLadder") return (St_SurveyC *) StistSensorOnLadder::instance();
2978  return 0;
2979 }
2980 //__________________Calibrations/rhic______________________________________________________________
2981 #include "St_vertexSeedC.h"
2982 MakeChairInstance(vertexSeed,Calibrations/rhic/vertexSeed);
2983 //__________________Calibrations/tof______________________________________________________________
2984 #include "St_tofCorrC.h"
2985 ClassImp(St_tofCorrC);
2986 St_tofCorrC::St_tofCorrC(TTable *table) : TChair(table), mCalibType(NOTSET) {
2987  Int_t N = 0;
2988  if (table) N = getNumRows();
2989  mCalibType = calibtype(N);
2990  mIndxArray.Set(N);
2991  mNusedArray.Set(N);
2992 }
2993 //________________________________________________________________________________
2994 Float_t St_tofCorrC::Correction(Int_t N, Float_t *xArray, Float_t x, Float_t *yArray, Short_t &NN) {
2995  Float_t dcorr = -9999;
2996  if (! NN) {// Sort
2997  if (N <= 0 || ! xArray || ! yArray) return dcorr;
2998  NN = N;
2999  Bool_t IsSorted = kTRUE;
3000  Int_t nonzero = 0;
3001  for (Int_t bin = N-1; bin >= 0; bin--) {
3002  if (! nonzero && TMath::Abs(xArray[bin]) < 1e-7 && TMath::Abs(yArray[bin]) < 1e-7) {
3003  NN--; // trailing entries
3004  if (! IsSorted) break;
3005  continue;
3006  }
3007  nonzero++;
3008  if (bin > 0 && xArray[bin] < xArray[bin-1]) IsSorted = kFALSE;
3009  }
3010  if (! NN) {
3011  LOG_ERROR << " St_tofCorrC::Correction xArray[" << (Int_t ) NN << "] is empty" << endm;
3012  return dcorr;
3013  }
3014  if (! IsSorted) {
3015  LOG_WARN << " St_tofCorrC::Correction xArray[" << (Int_t ) NN << "] has not been sorted" << endm;
3016  TArrayI Indx(NN);
3017  TMath::Sort((Int_t) NN,xArray,Indx.GetArray(),0);
3018  TArrayF X(NN,xArray);
3019  TArrayF Y(NN,yArray);
3020  for (Int_t i = 0; i < NN; i++) {
3021  xArray[i] = X[Indx[i]];
3022  yArray[i] = Y[Indx[i]];
3023  }
3024  LOG_WARN << " St_tofCorrC::Correction xArray[" << (Int_t ) NN << "] is sorted now" << endm;
3025  }
3026  }
3027  if (NN == 1) {return yArray[NN-1];}
3028  if (x < xArray[0] || x > xArray[NN-1]) {
3029  if (TMath::Abs(x) < 1e-7) dcorr = 0; // Simulation
3030  return dcorr;
3031  }
3032  Int_t bin = TMath::BinarySearch(NN, xArray, x);
3033  if (bin >= 0 && bin < NN) {
3034  if (bin == NN) bin--;
3035  Double_t x1 = xArray[bin];
3036  Double_t x2 = xArray[bin+1];
3037  Double_t y1 = yArray[bin];
3038  Double_t y2 = yArray[bin+1];
3039  dcorr = y1 + (x-x1)*(y2-y1)/(x2-x1);
3040  }
3041  return dcorr;
3042 }
3043 //________________________________________________________________________________
3044 Int_t St_tofCorrC::Index(Int_t tray, Int_t module, Int_t cell) {
3045  assert( tray && module );
3046  Int_t i = -1;
3047  switch (mCalibType) {
3048  case CELLCALIB: assert(cell); i = cell - 1 + mNCell*(module - 1 + mNModule*(tray - 1)) ; break;
3049  case MODULECALIB: i = module - 1 + mNModule*(tray - 1) ; break;
3050  case BOARDCALIB: i = (module - 1 + mNModule*(tray - 1))/4; break;
3051  default: assert(0); break;
3052  }
3053  return i;
3054 }
3055 #include "St_tofTotbCorrC.h"
3056 MakeChairInstance(tofTotbCorr,Calibrations/tof/tofTotbCorr);
3057 St_tofTotbCorrC::St_tofTotbCorrC(St_tofTotbCorr *table) : St_tofCorrC(table) {
3058  Int_t N = 0;
3059  if (table) N = getNumRows();
3060  for (Int_t i = 0; i < N; i++) {
3061  Int_t j = Index(trayId(i), moduleId(i), cellId(i));
3062  if (_debug) {
3063  Table()->Print(i,1);
3064  LOG_INFO << "i = " << i << "\ttray = " << trayId(i) << "\tmodule = " << moduleId(i) << "\tcellId = " << cellId(i) << "\tindex = " << j << endm;
3065  }
3066  if (j >= 0) {
3067  if (! mIndxArray[j]) mIndxArray[j] = i;
3068  else {
3069  Int_t m = mIndxArray[j];
3070  LOG_ERROR << "St_tofTotbCorrC duplicated rows "
3071  << m << " tray:" << trayId(m) << " module:" << moduleId(m)
3072  << " cell:" << cellId(m) << " tot[0] = " << tot(m)[0] << " corr[0] = " << corr(m)[0] << " and \n"
3073  << " "
3074  << i << " tray:" << trayId(i) << " module:" << moduleId(i)
3075  << " cell:" << cellId(i) << " tot[0] = " << tot(i)[0] << " corr[0] = " << corr(i)[0] << endm;
3076  }
3077  }
3078  }
3079 }
3080 //________________________________________________________________________________
3081 Float_t St_tofTotbCorrC::Corr(Int_t tray, Int_t module, Int_t cell, Float_t x) {
3082  Int_t idx = Index(tray,module,cell);
3083  Int_t i = mIndxArray[idx];
3084  if (i < 0) return 0;
3085  Int_t Tray = trayId(i);
3086  Int_t Module = moduleId(i);
3087  Int_t Cell = cellId(i);
3088  assert(i >= 0 && Tray == tray && Module == module && Cell == cell);
3089  Float_t dcorr = St_tofCorrC::Correction(mNBinMax, tot(i), x, corr(i),mNusedArray[idx]);
3090  if (dcorr <= -9999.0) {
3091  LOG_ERROR << "St_tofTotbCorrC::Corr(" << tray << "," << module << "," << cell << "," << x << ") is rejected.";
3092  if (x < tot(i)[0] || x > tot(i)[mNusedArray[idx]-1]) LOG_ERROR << " Out of the range [" << tot(i)[0] << "," << tot(i)[mNusedArray[idx]-1] << "].";
3093  LOG_ERROR << endm;
3094  }
3095  return dcorr;
3096 }
3097 #include "St_tofZbCorrC.h"
3098 MakeChairInstance(tofZbCorr,Calibrations/tof/tofZbCorr);
3099 St_tofZbCorrC::St_tofZbCorrC(St_tofZbCorr *table) : St_tofCorrC(table) {
3100  Int_t N = 0;
3101  if (table) N = getNumRows();
3102  for (Int_t i = 0; i < N; i++) {
3103  Int_t j = Index(trayId(i), moduleId(i), cellId(i));
3104  if (j >= 0) {
3105  if (! mIndxArray[j]) mIndxArray[j] = i;
3106  else {
3107  Int_t m = mIndxArray[j];
3108  LOG_ERROR << "St_tofZbCorrC duplicated rows "
3109  << m << " tray:" << trayId(m) << " module:" << moduleId(m)
3110  << " cell:" << cellId(m) << " z[0] = " << z(m)[0] << " corr[0] = " << corr(m)[0] << " and \n"
3111  << " "
3112  << i << " tray:" << trayId(i) << " module:" << moduleId(i)
3113  << " cell:" << cellId(i) << " z[0] = " << z(i)[0] << " corr[0] = " << corr(i)[0] << endm;
3114  }
3115  }
3116  }
3117 }
3118 //________________________________________________________________________________
3119 Float_t St_tofZbCorrC::Corr(Int_t tray, Int_t module, Int_t cell, Float_t x) {
3120  Int_t idx = Index(tray,module,cell);
3121  Int_t i = mIndxArray[idx];
3122  if (i < 0) return 0;
3123  Int_t Tray = trayId(i);
3124  Int_t Module = moduleId(i);
3125  Int_t Cell = cellId(i);
3126  assert(i >= 0 && Tray == tray && Module == module && Cell == cell);
3127  Float_t dcorr = St_tofCorrC::Correction(mNBinMax, z(i), x, corr(i),mNusedArray[idx]);
3128  if (dcorr <= -9999.0) {
3129  LOG_ERROR << "tofZbCorrC::Corr(" << tray << "," << module << "," << cell << "," << x << ") is rejected.";
3130  if (x < z(i)[0] || x > z(i)[mNusedArray[idx]-1]) {LOG_ERROR << " Out of the range [" << z(i)[0] << "," << z(i)[mNusedArray[idx]-1] << "].";}
3131  LOG_ERROR << endm;
3132 
3133  }
3134  return dcorr;
3135 }
3136 #include "St_tofGeomAlignC.h"
3137 MakeChairInstance(tofGeomAlign,Calibrations/tof/tofGeomAlign);
3138 #include "St_tofStatusC.h"
3139 MakeChairInstance(tofStatus,Calibrations/tof/tofStatus);
3140 #include "St_pvpdStrobeDefC.h"
3141 MakeChairInstance(pvpdStrobeDef,Calibrations/tof/pvpdStrobeDef);
3142 #include "St_tofCamacDaqMapC.h"
3143 MakeChairInstance(tofCamacDaqMap,Calibrations/tof/tofCamacDaqMap);
3144 #include "St_tofDaqMapC.h"
3145 MakeChairInstance(tofDaqMap,Calibrations/tof/tofDaqMap);
3146 #include "St_tofTrayConfigC.h"
3147 MakeChairInstance(tofTrayConfig,Calibrations/tof/tofTrayConfig);
3148 #include "St_tofINLCorrC.h"
3149 MakeChairInstance(tofINLCorr,Calibrations/tof/tofINLCorr);
3150 #include "St_tofINLSCorrC.h"
3151 MakeChairInstance(tofINLSCorr,Calibrations/tof/tofINLSCorr);
3152 #include "St_tofModuleConfigC.h"
3153 MakeChairInstance(tofModuleConfig,Calibrations/tof/tofModuleConfig);
3154 #include "St_tofPedestalC.h"
3155 MakeChairInstance(tofPedestal,Calibrations/tof/tofPedestal);
3156 #include "St_tofr5MaptableC.h"
3157 MakeChairInstance(tofr5Maptable,Calibrations/tof/tofr5Maptable);
3158 #include "St_tofTDIGOnTrayC.h"
3159 MakeChairInstance(tofTDIGOnTray,Calibrations/tof/tofTDIGOnTray);
3160 #include "St_tofTOffsetC.h"
3161 MakeChairInstance(tofTOffset,Calibrations/tof/tofTOffset);
3162 Float_t St_tofTOffsetC::t0(Int_t tray, Int_t module, Int_t cell) const {
3163  // [mNTray][mNModule][mNCell]
3164  Int_t j = cell - 1 + mNCell*(module - 1);
3165  return T0(tray-1)[j];
3166 }
3167 #include "St_tofTrgWindowC.h"
3168 MakeChairInstance(tofTrgWindow,Calibrations/tof/tofTrgWindow);
3169 #include "St_tofTzeroC.h"
3170 MakeChairInstance(tofTzero,Calibrations/tof/tofTzero);
3171 #include "St_tofSimResParamsC.h"
3172 //MakeChairInstance(tofSimResParams,Calibrations/tof/tofSimResParams);
3173 St_tofSimResParamsC *St_tofSimResParamsC::fgInstance = 0;
3174 Double_t St_tofSimResParamsC::params[120][192] = {0};
3175 Double_t St_tofSimResParamsC::mAverageTimeResTof = 0;
3176 
3177 St_tofSimResParamsC *St_tofSimResParamsC::instance() {
3178  if (fgInstance) return fgInstance;
3179  St_tofSimResParams *table = (St_tofSimResParams *) StMaker::GetChain()->GetDataBase("Calibrations/tof/tofSimResParams");
3180  if (! table) {
3181  LOG_WARN << "St_tofSimResParamsC::instance Calibrations/tof/tofSimResParams was not found" << endm;
3182  assert(table);
3183  }
3184  DEBUGTABLE(tofSimResParams);
3185  fgInstance = new St_tofSimResParamsC(table);
3186  mAverageTimeResTof=0;
3187  const tofSimResParams_st *row = fgInstance->Struct(0);
3188  for ( Int_t i = 0; i < 120; i++ ){ // nTrays
3189  for ( Int_t j = 0; j < 192; j++ ){
3190  Int_t index = i * 120 + j;
3191  params[i][j] = row->resolution[index];
3192  mAverageTimeResTof += params[i][j];
3193 #if 0
3194  if (_debug) {
3195  LOG_DEBUG << "tray:" << i << ", mod cell:" << j << " = " << row->resolution[index] << " == " << params[i][j] << endm;
3196  }
3197 #endif
3198  }
3199  }
3200  mAverageTimeResTof=mAverageTimeResTof/(120*192);
3201  LOG_INFO << "Loaded tofSimResParams. Average = " << mAverageTimeResTof << endm;
3202 
3203  if (StDetectorDbMaker::instance()) {
3204  fgInstance->SetName("tofSimResParamsC");
3205  StDetectorDbMaker::instance()->AddConst(fgInstance);
3206  }
3207  return fgInstance;
3208 }
3209 //________________________________________________________________________________
3210 Double_t St_tofSimResParamsC::timeres_tof(UInt_t itray, UInt_t imodule, UInt_t icell) {
3211  /*
3212  * Calculates the average resolution across all 38 tubes (discounts inactive tubes)
3213  * then returns a single vertex resolution (in ps) for use in embedding w/ vpdStart
3214  */
3215  Double_t result = 8.5e-11;
3216  if ( itray > 120 || imodule > 32 || icell > 6 ) return result;
3217  return params[ itray ][ imodule * 6 + icell ];
3218 }
3219 #include "St_vpdDelayC.h"
3220 MakeChairInstance(vpdDelay,Calibrations/tof/vpdDelay);
3221 #include "St_vpdTotCorrC.h"
3222 MakeChairInstance(vpdTotCorr,Calibrations/tof/vpdTotCorr);
3223 Float_t St_vpdTotCorrC::Corr(Int_t i, Float_t x) {
3224  assert(tubeId(i) == i + 1);
3225  Int_t idx = i;
3226  Float_t dcorr = St_tofCorrC::Correction(128, tot(i), x, corr(i),mNusedArray[idx]);
3227  if (dcorr <= -9999.0) {
3228  LOG_ERROR << "St_vpdTotCorrC::Corr(" << i << "," << x << ") is rejected.";
3229  if (x < tot(i)[0] || x > tot(i)[mNusedArray[idx]-1]) {LOG_ERROR << " Out of the range [" << tot(i)[0] << "," << tot(i)[mNusedArray[idx]-1] << "].";}
3230  LOG_ERROR << endm;
3231  }
3232  return dcorr;
3233 }
3234 #include "St_vpdSimParamsC.h"
3235 MakeChairInstance(vpdSimParams,Calibrations/tof/vpdSimParams);
3236 //____________________________Calibrations/emc____________________________________________________
3237 #include "St_emcPedC.h"
3238 MakeChairInstance2(emcPed,St_bemcPedC,Calibrations/emc/y3bemc/bemcPed);
3239 MakeChairInstance2(emcPed,St_bprsPedC,Calibrations/emc/y3bprs/bprsPed);
3240 #include "St_emcStatusC.h"
3241 MakeChairInstance2(emcStatus,St_bemcStatusC,Calibrations/emc/y3bemc/bemcStatus);
3242 MakeChairInstance2(emcStatus,St_bprsStatusC,Calibrations/emc/y3bprs/bprsStatus);
3243 #include "St_emcCalibC.h"
3244 MakeChairInstance2(emcCalib,St_bemcCalibC,Calibrations/emc/y3bemc/bemcCalib);
3245 MakeChairInstance2(emcCalib,St_bprsCalibC,Calibrations/emc/y3bprs/bprsCalib);
3246 #include "St_emcGainC.h"
3247 MakeChairInstance2(emcGain,St_bemcGainC,Calibrations/emc/y3bemc/bemcGain);
3248 MakeChairInstance2(emcGain,St_bprsGainC,Calibrations/emc/y3bprs/bprsGain);
3249 
3250 #include "St_smdPedC.h"
3251 MakeChairInstance2(smdPed,St_bsmdePedC,Calibrations/smd/y3bsmde/bsmdePed);
3252 MakeChairInstance2(smdPed,St_bsmdpPedC,Calibrations/smd/y3bsmdp/bsmdpPed);
3253 #include "St_smdStatusC.h"
3254 MakeChairInstance2(smdStatus,St_bsmdeStatusC,Calibrations/smd/y3bsmde/bsmdeStatus);
3255 MakeChairInstance2(smdStatus,St_bsmdpStatusC,Calibrations/smd/y3bsmdp/bsmdpStatus);
3256 #include "St_smdCalibC.h"
3257 MakeChairInstance2(smdCalib,St_bsmdeCalibC,Calibrations/smd/y3bsmde/bsmdeCalib);
3258 MakeChairInstance2(smdCalib,St_bsmdpCalibC,Calibrations/smd/y3bsmdp/bsmdpCalib);
3259 #include "St_smdGainC.h"
3260 MakeChairInstance2(smdGain,St_bsmdeGainC,Calibrations/smd/y3bsmde/bsmdeGain);
3261 MakeChairInstance2(smdGain,St_bsmdpGainC,Calibrations/smd/y3bsmdp/bsmdpGain);
3262 #include "St_emcTriggerStatusC.h"
3263 MakeChairInstance2(emcTriggerStatus,St_bemcTriggerStatusC,Calibrations/emc/trigger/bemcTriggerStatus);
3264 #include "St_emcTriggerPedC.h"
3265 MakeChairInstance2(emcTriggerPed,St_bemcTriggerPedC,Calibrations/emc/trigger/bemcTriggerPed);
3266 #include "St_emcTriggerLUTC.h"
3267 MakeChairInstance2(emcTriggerLUT,St_bemcTriggerLUTC,Calibrations/emc/trigger/bemcTriggerLUT);
3268 #include "St_bemcMapC.h"
3269 MakeChairInstance(bemcMap,Calibrations/emc/map/bemcMap);
3270 #include "St_bprsMapC.h"
3271 MakeChairInstance(bprsMap,Calibrations/prs/map/bprsMap);
3272 #include "St_bsmdeMapC.h"
3273 MakeChairInstance(bsmdeMap,Calibrations/smde/map/bsmdeMap);
3274 #include "St_bsmdpMapC.h"
3275 MakeChairInstance(bsmdpMap,Calibrations/smdp/map/bsmdpMap);
3276 //____________________________Calibrations/ist____________________________________________________
3277 #include "St_istPedNoiseC.h"
3278 MakeChairInstance(istPedNoise,Calibrations/ist/istPedNoise);
3279 #include "St_istChipConfigC.h"
3280 MakeChairInstance(istChipConfig,Calibrations/ist/istChipConfig);
3281 #include "St_istControlC.h"
3282 MakeChairInstance(istControl,Calibrations/ist/istControl);
3283 #include "St_istGainC.h"
3284 MakeChairInstance(istGain,Calibrations/ist/istGain);
3285 #include "St_istMappingC.h"
3286 MakeChairInstance(istMapping,Calibrations/ist/istMapping);
3287 #include "St_istSimParC.h"
3288 MakeChairInstance(istSimPar,Calibrations/ist/istSimPar);
3289 //____________________________Calibrations/pxl____________________________________________________
3290 #include "St_pxlHotPixelsC.h"
3291 //MakeChairInstance(pxlHotPixels,Calibrations/pxl/pxlHotPixels);
3292 St_pxlHotPixelsC *St_pxlHotPixelsC::fgInstance = 0;
3293 map<UInt_t,Short_t> St_pxlHotPixelsC::mMapHotPixels;
3294 St_pxlHotPixelsC *St_pxlHotPixelsC::instance() {
3295  if (! fgInstance) {
3296  St_pxlHotPixels *table = (St_pxlHotPixels *) StMaker::GetChain()->GetDataBase("Calibrations/pxl/pxlHotPixels");
3297  if (! table) {
3298  LOG_WARN << "St_pxlHotPixelsC::instance Calibrations/pxl/pxlHotPixels\twas not found" << endm;
3299  assert(table);
3300  }
3301  DEBUGTABLE(pxlHotPixels);
3302  fgInstance = new St_pxlHotPixelsC(table);
3303 
3304  mMapHotPixels.clear();
3305  for(Int_t i=0; i<10000; i++){
3306  if(fgInstance->hotPixel()[i]>0){
3307  mMapHotPixels.insert ( std::pair<UInt_t, Short_t>(fgInstance->hotPixel()[i],i) );
3308  }
3309  else break;
3310  }
3311  LOG_INFO << "St_pxlHotPixelsC have been instantiated with " << mMapHotPixels.size() << endm;
3312  }
3313  return fgInstance;
3314 }
3315 //________________________________________________________________________________
3316 Int_t St_pxlHotPixelsC::pixelHot(Int_t sector, Int_t ladder, Int_t sensor, Int_t row, Int_t column) const {
3317  map<UInt_t,Short_t>::const_iterator got;
3318  got = mMapHotPixels.find(1000000*((sector-1)*40+(ladder-1)*10+sensor) + 1000*row + column);
3319  if ( got == mMapHotPixels.end() ) {
3320  return 0;
3321  }
3322  else {
3323  return 1;
3324  }
3325 }
3326 //________________________________________________________________________________
3327 #include "St_pxlRowColumnStatusC.h"
3328 MakeChairInstance(pxlRowColumnStatus,Calibrations/pxl/pxlRowColumnStatus);
3329 #include "St_pxlBadRowColumnsC.h"
3330 MakeChairInstance(pxlBadRowColumns,Calibrations/pxl/pxlBadRowColumns);
3331 #include "St_pxlSensorStatusC.h"
3332 MakeChairInstance(pxlSensorStatus,Calibrations/pxl/pxlSensorStatus);
map< Int_t, Float_t > getTotalPrescales()
virtual void AddData(TDataSet *data, const char *dir=".data")
User methods.
Definition: StMaker.cxx:332
Definition: TChair.h:27
Definition: tof.h:15
Accessor to the database for trigger id information.
virtual Long_t GetNRows() const
Returns the number of the used rows for the wrapped table.
Definition: TTable.cxx:1388
virtual Int_t GetRunNumber() const
Returns the current RunNumber.
Definition: StMaker.cxx:1054
Definition: TTable.h:48
Float_t getTotalPrescaleByTrgId(Int_t trgId)
virtual Char_t * Print(Char_t *buf, Int_t n) const
Create IDL table defintion (to be used for XDF I/O)
Definition: TTable.cxx:1548
virtual TDataSet * Find(const char *path) const
Definition: TDataSet.cxx:362