StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
MakeSvtLadderOnShell.C
1 class St_db_Maker;
2 class TTable;
3 St_db_Maker *dbMk = 0;
4 TTable *table = 0;
5 struct data_t {
6  Int_t barrel, layer, ladder, wafer, type;
7  Double_t u, Du, v, Dv, w, Dw, alpha, Dalpha, beta, Dbeta, gamma, Dgamma;
8  Char_t *Comment;
9 };
10 const Int_t N = 36;
11 Int_t date = 20070321;
12 Int_t time = 206; //
13 #define CutSTEP
14 const Char_t *Pass = "Pass217 FFK";
15 data_t Data[N] = {
16  {1,2, 1, 0,-1, -9.48, 0.54, -0.72, 0.90, -3.00, 3.55, -0.16, 0.03, 0.02, 0.11, 0.01, 0.01,"Average"},
17  {1,1, 2, 0,-1, 1.27, 0.39, 4.36, 0.61, -21.58, 2.39, 0.17, 0.03, 0.20, 0.08, 0.08, 0.01,"Average"},
18  {1,2, 3, 0,-1, 15.49, 0.67, 92.52, 1.06, 1.50, 4.56, 0.59, 0.06, 0.33, 0.14, -0.33, 0.02,"Average"},
19  {1,1, 4, 0,-1, -6.76, 0.76, 124.26, 1.04, -44.76, 4.58, 0.00, 0.10, -9.65, 0.14, 0.05, 0.03,"Average"},
20  {1,2, 5, 0,-1, 0.34, 0.44, 10.93, 0.93, 8.23, 2.12, 0.10, 0.03, 0.15, 0.12, 0.05, 0.01,"Average"},
21  {1,1, 6, 0,-1, -2.25, 0.38, -1.03, 0.80, -25.70, 3.12, -0.01, 0.03, 0.10, 0.11, 0.02, 0.01,"Average"},
22  {1,2, 7, 0,-1, -4.12, 0.43, -5.81, 0.81, -48.57, 3.19, 0.02, 0.04, 0.08, 0.12, 0.06, 0.01,"Average"},
23  {1,1, 8, 0,-1, 1.11, 0.54, -6.15, 0.95, -22.24, 3.63, 0.00, 0.08, -0.10, 0.12, -0.08, 0.02,"Average"},
24  {2,4, 1, 0,-1, 0,-9.99, 0,-9.99, 0,-9.99, 0,-9.99, 0,-9.99, 0,-9.99,"Average"},
25  {2,3, 2, 0,-1, 5.14, 0.40, -3.33, 0.81, -8.41, 1.74, -0.04, 0.03, 0.14, 0.14, 0.05, 0.01,"Average"},
26  {2,4, 3, 0,-1, -6.41, 0.48, -0.78, 0.71, 5.24, 1.73, -0.03, 0.03, 0.28, 0.13, 0.01, 0.01,"Average"},
27  {2,3, 4, 0,-1, 6.07, 0.50, 14.45, 1.16, 8.63, 2.04, 0.08, 0.02, -0.44, 0.13, -0.00, 0.01,"Average"},
28  {2,4, 5, 0,-1, -0.43, 0.46, -7.11, 0.94, -1.55, 2.10, 0.23, 0.04, -0.41, 0.16, 0.06, 0.01,"Average"},
29  {2,3, 6, 0,-1, -2.56, 0.50, 17.87, 0.85, -8.84, 2.10, 0.07, 0.03, -0.19, 0.15, 0.02, 0.01,"Average"},
30  {2,4, 7, 0,-1, -3.78, 0.42, 10.61, 0.86, 7.32, 2.07, -0.01, 0.03, -0.95, 0.18, 0.02, 0.01,"Average"},
31  {2,3, 8, 0,-1, -24.64, 1.25, 9.69, 1.81, -17.04, 3.93, 0.20, 0.07, -0.04, 0.24, 0.20, 0.03,"Average"},
32  {2,4, 9, 0,-1, -1.06, 0.49, 1.26, 1.09, -22.13, 2.56, 0.12, 0.04, -0.43, 0.23, 0.05, 0.01,"Average"},
33  {2,3,10, 0,-1, -7.14, 0.39, -0.95, 0.94, -2.87, 2.22, -0.16, 0.05, 0.16, 0.16, 0.05, 0.01,"Average"},
34  {2,4,11, 0,-1, 0,-9.99, 0,-9.99, 0,-9.99, 0,-9.99, 0,-9.99, 0,-9.99,"Average"},
35  {2,3,12, 0,-1, -10.84, 0.54, -8.63, 1.02, 11.48, 2.72, 0.02, 0.05, 0.38, 0.18, 0.03, 0.01,"Average"},
36  {3,6, 1, 0,-1, -1.07, 0.62, -3.47, 1.24, 7.32, 3.47, -0.02, 0.03, 0.08, 0.18, 0.05, 0.01,"Average"},
37  {3,5, 2, 0,-1, -9.15, 0.64, -3.33, 1.10, -8.51, 2.81, 0.09, 0.04, -0.57, 0.18, 0.00, 0.01,"Average"},
38  {3,6, 3, 0,-1, 0.35, 0.29, -2.25, 0.92, -10.24, 2.06, -0.16, 0.03, 0.10, 0.16, 0.01, 0.00,"Average"},
39  {3,5, 4, 0,-1, 1.25, 0.50, -9.99, 0.74, 0.58, 1.92, 0.01, 0.03, 0.10, 0.16, -0.03, 0.01,"Average"},
40  {3,6, 5, 0,-1, -3.02, 0.89, -0.41, 1.32, 21.32, 3.31, 0.02, 0.03, -0.12, 0.18, 0.03, 0.01,"Average"},
41  {3,5, 6, 0,-1, -0.52, 0.51, 1.77, 1.02, 9.28, 2.60, 0.08, 0.03, 0.17, 0.18, -0.02, 0.01,"Average"},
42  {3,6, 7, 0,-1, 0.90, 0.86, -11.78, 1.93, -26.40, 4.59, -0.27, 0.14, -0.84, 0.40, 0.08, 0.03,"Average"},
43  {3,5, 8, 0,-1, -12.29, 0.76, 14.79, 1.47, 9.28, 3.55, 0.03, 0.04, -0.46, 0.24, 0.01, 0.01,"Average"},
44  {3,6, 9, 0,-1, 1.04, 0.43, 8.78, 1.18, -13.74, 3.00, 0.08, 0.04, -0.23, 0.10, 0.04, 0.01,"Average"},
45  {3,5,10, 0,-1, 1.38, 0.54, -0.63, 1.22, 10.68, 3.29, 0.02, 0.03, 0.18, 0.18, 0.02, 0.01,"Average"},
46  {3,6,11, 0,-1, -0.19, 0.97, 5.35, 2.00, 22.98, 5.27, -0.07, 0.10, 0.12, 0.31, -0.06, 0.03,"Average"},
47  {3,5,12, 0,-1, -0.97, 0.54, -2.64, 1.27, -12.72, 3.48, 0.09, 0.05, 0.51, 0.27, 0.06, 0.01,"Average"},
48  {3,6,13, 0,-1, 2.09, 0.31, 13.83, 1.19, 5.42, 2.59, -0.42, 0.04, 0.65, 0.19, 0.01, 0.00,"Average"},
49  {3,5,14, 0,-1, -2.63, 0.67, -0.55, 1.76, -40.93, 3.56, -0.00, 0.04, 1.63, 0.27, -0.01, 0.01,"Average"},
50  {3,6,15, 0,-1, -9.77, 0.73, -12.88, 1.73, -11.78, 3.90, 0.25, 0.09, -0.44, 0.29, -0.03, 0.02,"Average"},
51  {3,5,16, 0,-1, -15.85, 0.72, -15.55, 1.47, -24.82, 1.84, -0.41, 0.09, -0.02, 0.29, 0.21, 0.02,"Average"}
52 };
53 //________________________________________________________________________________
54 void MakeSvtLadderOnShell(){//, Int_t time = 38 ){ // combine SvtBarrelOnGlobal and SvtShellsOnBarrel into SvtShellsOnGlobal
55  gROOT->LoadMacro("bfc.C");
56  bfc(0,"mysql,db,nodefault");
57  StMaker *dbMk = chain->Maker("db");
58  if (! dbMk) return;
59  dbMk->SetDebug(1);
60  StEvtHddr *header = chain->GetEvtHddr();
61  header->SetRunNumber(1);
62  dbMk->SetDateTime(date,time);
63  header->SetDateTime(date,time);
64  chain->MakeEvent();
65  dbMk->SetDebug(2);
66  dbMk->SetDateTime(date,time);
67  St_Survey *LadderOnShellOld = (St_Survey *) dbMk->GetDataBase("Geometry/svt/LadderOnShell"); // shells in the SVT barrel coordinate system
68  if (! (LadderOnShellOld)) return;
69  Survey_st *LaddersOnShells = LadderOnShellOld->GetTable(); // shells in the SVT barrel coordinate system
70  Int_t NoLadders = LadderOnShellOld->GetNRows();
71  St_Survey *LadderOnShell = new St_Survey("LadderOnShell",NoLadders);
72 #ifdef CutSTEP
73  cout << "============================ CutSTEP =========================" << endl;
74 #endif
75  TGeoHMatrix T;
76  Double_t tr[3] = {0,0, 23.525};
77  // Double_t tr[3] = {0,0, -23.525};
78  T.SetTranslation(tr);
79  TGeoHMatrix F;
80  Double_t flip[9] = {
81  1, 0, 0,
82  0, 0, 1,
83  0, 1, 0
84  };
85  F.SetRotation(flip);
86  TGeoHMatrix TInv = T.Inverse();
87  for (Int_t s = 0; s < NoLadders; s++, LaddersOnShells++) {
88  TGeoHMatrix LSold, LS, dR, ddR, dddR;
89  // LadderOnShellOld->Print(s,1);
90  LSold.SetRotation(&LaddersOnShells->r00);
91  LSold.SetTranslation(&LaddersOnShells->t0); cout << "===================== Ladder \t" << s+1 << endl; cout << "\tLSold\t"; LSold.Print();
92  Int_t i = -1;
93  for (Int_t k = 0; k < N; k++) {
94  if (LaddersOnShells->Id == 1000*Data[k].barrel + Data[k].ladder) {i = k; break;}
95  }
96  if (i < 0) {
97  cout << "Correction for " << LaddersOnShells->Id << " is not found" << endl;
98  } else {
99  cout << "Ladder " << LaddersOnShells->Id << "\ti " << i
100  << "\talpha " << Data[i].alpha << "+/-" << Data[i].Dalpha
101  << "\tbeta " << Data[i].beta << "+/-" << Data[i].Dbeta
102  << "\tgamma " << Data[i].gamma << "+/-" << Data[i].Dgamma
103  << "\tu " << Data[i].u << "\tv " << Data[i].v << "\tw " << Data[i].w << endl;
104  Double_t xyz[3] = {0, 0, 0};
105  // if (Data[i].Dalpha < 2 && Data[i].Dbeta < 2 && Data[i].Dgamma < 2) {
106 #ifndef CutSTEP
107  if (Data[i].Dalpha > 0) dR.RotateX(-180./TMath::Pi()*Data[i].alpha*1e-3);
108  if (Data[i].Dbeta > 0) dR.RotateZ(-180./TMath::Pi()*Data[i].beta*1e-3);
109  if (Data[i].Dgamma > 0) dR.RotateY(-180./TMath::Pi()*Data[i].gamma*1e-3);
110  if (Data[i].Du > 0) xyz[0] = 1e-4*Data[i].u;
111  if (Data[i].Dv > 0) xyz[2] = 1e-4*Data[i].v;
112  if (Data[i].Dw > 0) xyz[1] = 1e-4*Data[i].w;
113 #else
114  if (Data[i].Dalpha > 0) dR.RotateX(-180./TMath::Pi()*Data[i].alpha*0.5e-3);
115  if (Data[i].Dbeta > 0) dR.RotateZ(-180./TMath::Pi()*Data[i].beta*0.5e-3);
116  if (Data[i].Dgamma > 0) dR.RotateY(-180./TMath::Pi()*Data[i].gamma*0.5e-3);
117  if (Data[i].Du > 0) xyz[0] = 0.5e-4*Data[i].u;
118  if (Data[i].Dv > 0) xyz[2] = 0.5e-4*Data[i].v;
119  if (Data[i].Dw > 0) xyz[1] = 0.5e-4*Data[i].w;
120 #endif
121  // }
122  dR.SetTranslation(xyz);
123  cout << "dR\t"; dR.Print();
124  }
125  // shellOnGlobal * ladderOnShell * T * dR * T**-1 * ladderOnSurvey * waferOnLadder
126  // shellOnGlobal * ( ladderOnShell * F * T * dR * T**-1 * F ) * ladderOnSurvey * waferOnLadder
127  ddR = T * dR * TInv; cout << "ddR\t" << ddR.Print();
128  dddR = F * T * dR * TInv * F; cout << "dddR\t" << dddR.Print();
129  // LS = LSold * dR; cout << "LS_old\t"; LS.Print();
130  // LS = LSold * dddR; cout << "LS_new\t"; LS.Print();
131  LS = LSold * ddR; cout << "LS_new\t"; LS.Print();
132  Survey_st row = *LaddersOnShells;
133  Double_t *r = LS.GetRotationMatrix();
134  memcpy(&row.r00, r, 9*sizeof(Double_t));
135  Double_t *t = LS.GetTranslation();
136  memcpy(&row.t0, t, 3*sizeof(Double_t));
137  LadderOnShell->AddAt(&row);
138  // LadderOnShell->Print(LadderOnShell->GetNRows()-1,1);
139  }
140  TString fOut = Form("%s.%8i.%06i.C",LadderOnShell->GetName(),date,time);
141  ofstream out;
142  cout << "Create " << fOut << endl;
143  out.open(fOut.Data());
144  out << "TDataSet *CreateTable() {" << endl;
145  out << " if (!gROOT->GetClass(\"St_Survey\")) return 0;" << endl;
146  out << " Survey_st row[" << NoLadders << "] = {" << endl;
147  Survey_st *LaddersOnShells = LadderOnShell->GetTable();
148  for (Int_t i = 0; i < NoLadders; i++, LaddersOnShells++) {
149  out << " {" << Form("%1i",LaddersOnShells->Id);
150  Double_t *r = &(LaddersOnShells->r00);
151  for (Int_t j = 0; j < 9; j++) out << Form(",%8.5f",r[j]);
152  for (Int_t j = 9; j < 12; j++) out << Form(",%8.4f",r[j]);
153  for (Int_t j = 12; j < 18; j++) out << Form(",%3.1f",r[j]);
154  out << ",\"" << Pass << "\"}";
155  if (i != NoLadders - 1) out << ",";
156  out << endl;
157  }
158  out << " };" << endl;
159  out << " St_Survey *tableSet = new St_Survey(\"" << LadderOnShell->GetName() << "\"," << NoLadders << ");" << endl;
160  out << " for (Int_t i = 0; i < " << NoLadders << "; i++) tableSet->AddAt(&row[i].Id, i);" << endl;
161  out << " return (TDataSet *)tableSet;" << endl;
162  out << "}" << endl;
163  out.close();
164 }
Definition: TTable.h:48