StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MakeSvtDriftVelocities.C
1 //#define DEBUG
2 #include "Riostream.h"
3 class St_db_Maker;
4 class TTable;
5 St_db_Maker *dbMk = 0;
6 TTable *table = 0;
7 #if 0
8 // lines which should be added to Drift_ALL.h
9 Int_t Drift = 1;
10 Int_t time = 207;
11 Int_t date = 20070321;
12 const Char_t *Pass = "Pass217 FFK";
13 #endif
14 #include "Drift_ALL.h"
15 static const Int_t N = sizeof(Data)/sizeof(data_t);
16 
17 
18 //________________________________________________________________________________
19 void MakeSvtDriftVelocities(){
20  cout << "Date " << date << "\t Time " << time << endl;
21  gROOT->LoadMacro("bfc.C");
22  bfc(0,"mysql,db,nodefault");
23  StMaker *dbMk = chain->Maker("db");
24  if (! dbMk) return;
25  dbMk->SetDebug(1);
26  StEvtHddr *header = chain->GetEvtHddr();
27  header->SetRunNumber(1);
28  dbMk->SetDateTime(date,time);
29  header->SetDateTime(date,time);
30  chain->MakeEvent();
31  St_svtHybridDriftVelocity *svtHybridDriftVelocity = (St_svtHybridDriftVelocity *) dbMk->GetDataBase("Calibrations/svt/svtHybridDriftVelocity");
32  if (! (svtHybridDriftVelocity)) return;
33  Int_t NN = svtHybridDriftVelocity->GetNRows();
34 #ifdef DEBUG
35  cout << "NN row from svtHybridDriftVelocity " << NN << " N corrections " << N << endl;
36 #endif
37  svtHybridDriftVelocity_st *row = svtHybridDriftVelocity->GetTable();
38  Double_t drift[10];
39  Double_t anode[10];
40  for (Int_t i = 0; i < NN; i++) {
41  for (Int_t j = 0; j < N; j++) {
42  if (Data[j].barrel == row[i].barrel &&
43  Data[j].ladder == row[i].ladder &&
44  Data[j].wafer == row[i].wafer &&
45  Data[j].hybrid == row[i].hybrid) {
46  Double_t *par = &row[i].v0;
47  Double_t *cor = &Data[j].v0;
48  Int_t nu = row[i].npar%10;
49  Int_t nv = (row[i].npar/10)%10;
50  Int_t I = (row[i].npar/100)%10;
51 #ifdef DEBUG
52  cout << "Found Match" << endl;
53  svtHybridDriftVelocity->Print(i,1);
54  cout << Data[j].type << ",\t" << Data[j].idx << ",\t" << Data[j].nrows<< ",\t"
55  << Data[j].barrel << ",\t" << Data[j].layer << ",\t" << Data[j].ladder<< ",\t"
56  << Data[j].wafer << ",\t" << Data[j].hybrid<< ",\t"
57  << Data[j].Npar << ",\t";
58  cout << "\tnu = " << nu << "\tnv = " << nv << "\tNpar = " << Data[j].Npar;
59  for (Int_t l = 0; l <= Data[j].Npar; l++) cout << ",\t" << cor[l];
60  cout << "\t" << Data[j].Comment << endl;
61 #endif
62  if (row[i].type == 0 && row[i].npar == 0) {
63  row[i].type = 2; row[i].v0 = 0;
64  }
65  if (row[i].type == 2) {
66 // svtHybridDriftVelocity->Print(i,1);
67  row[i].type = 2;
68  // cout << "nu = " << nu << " nv = " << nv << endl;
69  memset(drift, 0, 10*sizeof(Double_t));
70  memset(anode, 0, 10*sizeof(Double_t));
71  if (nu) memcpy (drift, &par[0], nu*sizeof(Double_t));
72  if (nv) memcpy (anode, &par[nu], nv*sizeof(Double_t));
73  if (Drift) {
74  for (Int_t k = 0; k <= Data[j].Npar; k++) {
75  drift[k] += cor[k];
76  }
77  if (nu <= Data[j].Npar) nu = Data[j].Npar+1;
78  } else {
79  for (Int_t k = 0; k <= Data[j].Npar; k++) {
80  anode[k] += cor[k];
81  }
82  if (nv <= Data[j].Npar) nv = Data[j].Npar+1;
83 
84  }
85 #ifdef DEBUG
86  for (Int_t k = 0; k < nu+nv; k++) {
87  if (k < nu) cout << "\td:" << par[k] << "\t" << drift[k];
88  else cout << "\ta:" << par[k] << "\t" << anode[k-nu];
89  }
90  cout << endl;
91 #endif
92  row[i].npar = 100*I + 10*nv + nu;
93  memset(par, 0, 10*sizeof(Double_t));
94  for (Int_t k = 0; k < nu + nv; k++) {
95  if (k >= 10) break;
96  if (k < nu) par[k] = drift[k];
97  else par[k] = anode[k-nu];
98  }
99  }
100 #ifdef DEBUG
101  svtHybridDriftVelocity->Print(i,1);
102 #endif
103  }
104  }
105  }
106  // Merge Drift velocities
107  Char_t Out[132];
108  sprintf(Out,"%s.%8i.%06i.C",svtHybridDriftVelocity->GetName(),date,time);
109  ofstream out;
110  out.open(Out);
111  cout << "Create " << Out << endl;
112  out << "TDataSet *CreateTable() {" << endl;
113  out << " if (!gROOT->GetClass(\"St_svtHybridDriftVelocity\")) return 0;" << endl;
114  out << " svtHybridDriftVelocity_st row[" << NN << "] = {//" << Pass << endl;
115  for (Int_t i = 0; i < NN; i++) {
116  out << Form("{%2i,%1i,%4i,%4i,%3i,%7i",row[i].type,row[i].status,row[i].idx,row[i].nrows,row[i].npar,row[i].Id);
117  out << Form(",%1i,%2i,%1i,%1i",row[i].barrel,row[i].ladder,row[i].wafer,row[i].hybrid);
118  out << Form(",%6.3f,%5.3f,%7.3f,%6.3f",row[i].tmin,row[i].dtmin,row[i].tmax,row[i].dtmax);
119  Double_t *v = &row[i].v0;
120  for (Int_t j = 0; j < 10; j++) {
121  if (v[j]) out << Form(",%8.5f",v[j]);
122  else out << ", 0.00000";
123  }
124  if (i < NN - 1) out << "},";
125  else out << "}";
126  out << Form("// B%iL%02iW%iH%i",row[i].barrel,row[i].ladder,row[i].wafer,row[i].hybrid) << endl;
127  }
128  out << " };" << endl;
129  out << " St_svtHybridDriftVelocity *tableSet = new St_svtHybridDriftVelocity(\"" << svtHybridDriftVelocity->GetName() << "\"," << NN << ");" << endl;
130  out << " for (Int_t i = 0; i < " << NN << "; i++) tableSet->AddAt(&row[i].type, i);" << endl;
131  out << " return (TDataSet *)tableSet;" << endl;
132  out << "}" << endl;
133  out.close();
134 }
virtual EDataSetPass Pass(EDataSetPass(*callback)(TDataSet *), Int_t depth=0)
Definition: TDataSet.cxx:689
Definition: TTable.h:48