StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BadDriftRegions.C
1 // void BadDriftRegions(const Char_t *macro =
2 // "/afs/rhic.bnl.gov/star/packages/.DEV2/StarDb/Calibrations/svt/svtHybridDriftVelocity.20070524.000208.C",
3 // const Char_t *badF = "/star/data07/calib/fisyak/SvtSsdAlignment/RF.Bad.Drift",
4 // Int_t date = 20070524, Int_t time = 209) {
5 void BadDriftRegions(const Char_t *macro =
6  "/afs/rhic.bnl.gov/star/packages/.DEV2/StarDb/Calibrations/svt/svtHybridDriftVelocity.20070321.000207.C",
7  const Char_t *badF = "/star/data07/calib/fisyak/SvtSsdAlignment/FF.Bad.Drift",
8  Int_t date = 20070321, Int_t time = 209) {
9  gSystem->Load("libStDb_Tables.so");
10  gROOT->LoadMacro(macro);
11  St_svtHybridDriftVelocity *svtHybridDriftVelocity = (St_svtHybridDriftVelocity *) CreateTable();
12  Int_t NN = svtHybridDriftVelocity->GetNRows();
13  FILE *fp = fopen(badF,"r");
14  if (! fp) return;
15  Int_t Barrel, Ladder, Wafer, Hybrid;
16  Float_t xmin, xmax;
17  Char_t line[120];
18  while (fgets(&line[0],120,fp)) {
19  cout << line;
20  TString T(line);
21  Int_t iok = 0;
22  if (T.Contains("BAD")) iok = 1;
23  else if (T.Contains("DEAD")) iok = 2;
24  else if (T.Contains("GOOD")) iok = 3;
25  xmin = xmax = -99;
26  if (! iok) {
27  sscanf(&line[0],"| B%1dL%02dW%1dH%1d| [%f,%f]",&Barrel,&Ladder,&Wafer,&Hybrid,&xmin,&xmax);
28  if (Hybrid == 1) {
29  xmin += 0.1;
30  xmax += 0.1;
31  Float_t temp = - xmin;
32  xmin = - xmax;
33  xmax = temp;
34  } else {
35  xmin -= 0.1;
36  xmax -= 0.1;
37  }
38  Int_t K = 100*(xmin + 0.005);
39  xmin = K/100.;
40  K = 100*(xmax + 0.005);
41  xmax = K/100.;
42  } else {
43  sscanf(&line[0],"| B%1dL%02dW%1dH%1d|",&Barrel,&Ladder,&Wafer,&Hybrid);
44  }
45  cout << "B"<< Barrel << "L" << Ladder << "W" << Wafer << "H" << Hybrid;
46  cout << " xmin " << xmin << " xmax " << xmax;
47  if (! iok ) cout << " O.K";
48  if ( iok == 1) cout << " BAD";
49  if ( iok == 2) cout << " DEAD";
50  cout << endl;
51  svtHybridDriftVelocity_st *row = svtHybridDriftVelocity->GetTable();
52  for (Int_t i = 0; i < NN; i++) {
53  if (row[i].barrel == Barrel &&
54  row[i].ladder == Ladder &&
55  row[i].wafer == Wafer &&
56  row[i].hybrid == Hybrid) {
57  svtHybridDriftVelocity->Print(i,1);
58  if (iok == 1) row[i].npar = -1;
59  if (iok == 2) row[i].npar = -2;
60  if (iok == 0) {
61  row[i].npar += 100;
62  row[i].dtmin = xmin;
63  row[i].dtmax = xmax;
64  } else {
65  if (iok == 3) {
66  row[i].dtmin = 0;
67  row[i].dtmax = 1;
68  } else {
69  row[i].dtmin = 0;
70  row[i].dtmax = 0;
71  }
72  }
73  svtHybridDriftVelocity->Print(i,1);
74  goto ENDL;
75  }
76  }
77  ENDL:
78  continue;
79  }
80  fclose(fp);
81 
82 #if 1
83  Char_t Out[132];
84  sprintf(Out,"%s.%8i.%06i.C",svtHybridDriftVelocity->GetName(),date,time);
85  ofstream out;
86  out.open(Out);
87  cout << "Create " << Out << endl;
88  out << "TDataSet *CreateTable() {" << endl;
89  out << " if (!gROOT->GetClass(\"St_svtHybridDriftVelocity\")) return 0;" << endl;
90  out << " svtHybridDriftVelocity_st row[" << NN << "] = {//Clean up" << endl;
91  for (Int_t i = 0; i < NN; i++) {
92  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);
93  out << Form(",%1i,%2i,%1i,%1i",row[i].barrel,row[i].ladder,row[i].wafer,row[i].hybrid);
94  out << Form(",%6.3f,%5.3f,%7.3f,%6.3f",row[i].tmin,row[i].dtmin,row[i].tmax,row[i].dtmax);
95  Double_t *v = &row[i].v0;
96  for (Int_t j = 0; j < 10; j++) {
97  if (v[j]) out << Form(",%8.5f",v[j]);
98  else out << ", 0.00000";
99  }
100  if (i < NN - 1) out << "},";
101  else out << "}";
102  out << Form("// B%iL%02iW%iH%i",row[i].barrel,row[i].ladder,row[i].wafer,row[i].hybrid) << endl;
103  }
104  out << " };" << endl;
105  out << " St_svtHybridDriftVelocity *tableSet = new St_svtHybridDriftVelocity(\"" << svtHybridDriftVelocity->GetName() << "\"," << NN << ");" << endl;
106  out << " for (Int_t i = 0; i < " << NN << "; i++) tableSet->AddAt(&row[i].type, i);" << endl;
107  out << " return (TDataSet *)tableSet;" << endl;
108  out << "}" << endl;
109  out.close();
110 #endif
111 }
112