StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
insertAlignedGeom.C
1 //
2 // macro to transfer data from old geometry tables to new data base structures
3 //
4 
5 #define NUMBER_OF_WAFERS 216
6 #include "/afs/rhic/star/packages/DEV/StRoot/StDbLib/StDbDefs.hh"
7 
8 void insertAlignedGeom(char* unixTime = 0, Bool_t write = kFALSE, Bool_t writeHtml = kTRUE)
9 {
10  int numberOfBarrels = 3;
11  int numberOfLadders[3] = {8,12,16};
12  int numberOfWafers[3] = {4,6,7};
13  int barrelRadius[6] = {6.125,7.185,10.185,11.075,13.995,14.935};
14  double theta_xy = 0.0;
15  double theta_xz = 0.0;
16  double theta_yz = 0.0;
17  double delta_x = 0.2332;
18  double delta_y = 0.0;
19  double delta_z = 0;
20 
21  if (writeHtml) {
22  ofstream file("svt_geometry_comp.html");
23  //ofstream file("svt_geometry_after3.html");
24  //ofstream file2("svt_geometry_before2.html");
25  }
26 
27  ntuple = new TNtuple("ntuple","ntuple","x:y:z:xa:ya:za:nx:ny:nz:nxa:nya:nza:dx:dy:dz:dxa:dya:dza:tx:ty:tz:txa:tya:tza:barrel:ladder:wafer");
28  float nt[27];
29 
30  // Baseline shared libraries
31  gSystem->Load("St_base");
32  gSystem->Load("StChain");
33  gSystem->Load("StUtilities");
34 
35  // DB-specific libs
36  gSystem->Load("libStDb_Tables.so");
37  gSystem->Load("St_Tables.so");
38  gSystem->Load("StDbLib");
39  gSystem->Load("StDbBroker");
40  gSystem->Load("geometry");
41  gSystem->Load("St_db_Maker");
42  gSystem->Load("StSvtDbMaker");
43  gSystem->Load("StSvtClassLibrary");
44 
45  chain = new StChain("StChain");
46 
47  St_db_Maker *dbMk = new St_db_Maker("StarDb","MySQL:StarDb");
48  StSvtDbMaker *svtDbMk = new StSvtDbMaker("svtDb");
49 
50  // Make reaquests for data
51  // choose timestamp
52  // dbMk->SetDateTime(20010617,000000); // pp 2001
53  // dbMk->SetDateTime(20011023,000000); // pp 2001 - simu
54  dbMk->SetDateTime(20030102,000000);
55 
56  chain->Init();
57  chain->InitRun(0);
58  svtDbMk->InitRun(0);
59 
60  chain->Make();
61 
62  St_DataSet* dataSet = chain->GetDataSet("StSvtGeometry");
63  StSvtGeometry* mSvtGeom;
64  if (dataSet)
65  mSvtGeom = (StSvtGeometry*)dataSet->GetObject();
66  int* rowIDs=new int[NUMBER_OF_WAFERS];
67  svtWafersPosition_st *wafersPosition;
68 
69  if (mSvtGeom) { // if geometry object exists
70 
71  if (writeHtml) {
72  file << "<p>" << endl;
73  file << "<b> Time stamp = " << "2003-10-31 00:00:00" << endl;
74  file << "<p>" << endl;
75  file << "<table BORDER=1 WIDTH=\"100%\" >" << endl;
76 
77  file << "<tr>" ;
78  file << "<td><center><b><font color=\"#FF0000\">barrel</font></b></center></td>"<< endl;
79  file << "<td><center><b><font color=\"#FF0000\">ladder</font></b></center></td>"<< endl;
80  file << "<td><center><b><font color=\"#FF0000\">wafer</font></b></center></td>"<< endl;
81  file << "<td><center><b><font color=\"#FF0000\"> x </font></b></center></td>"<< endl;
82  file << "<td><center><b><font color=\"#FF0000\"> y </font></b></center></td>"<< endl;
83  file << "<td><center><b><font color=\"#FF0000\"> z </font></b></center></td>"<< endl;
84  file << "<td><center><b><font color=\"#FF0000\"> nx </font></b></center></td>"<< endl;
85  file << "<td><center><b><font color=\"#FF0000\"> ny </font></b></center></td>"<< endl;
86  file << "<td><center><b><font color=\"#FF0000\"> nz </font></b></center></td>"<< endl;
87  file << "<td><center><b><font color=\"#FF0000\"> dx </font></b></center></td>"<< endl;
88  file << "<td><center><b><font color=\"#FF0000\"> dy </font></b></center></td>"<< endl;
89  file << "<td><center><b><font color=\"#FF0000\"> dz </font></b></center></td>"<< endl;
90  file << "<td><center><b><font color=\"#FF0000\"> tx </font></b></center></td>"<< endl;
91  file << "<td><center><b><font color=\"#FF0000\"> ty </font></b></center></td>"<< endl;
92  file << "<td><center><b><font color=\"#FF0000\"> tz </font></b></center></td>"<< endl;
93  file << "</tr>" << endl;
94  }
95 
96  // define new table to be stored
97  wafersPosition = new svtWafersPosition_st[NUMBER_OF_WAFERS];
98 
99  // define IDs
100  int layer, HardWarePos, index = 0;
101  StSvtWaferGeometry* waferGeom;
102 
103  for (int barrel =1;barrel <= numberOfBarrels;barrel++) {
104  for (int ladder =1;ladder <= numberOfLadders[barrel-1];ladder++) {
105  for (int wafer =1;wafer <= numberOfWafers[barrel-1];wafer++) {
106 
107  index = mSvtGeom->getWaferIndex(barrel,ladder,wafer);
108  waferGeom = (StSvtWaferGeometry*)mSvtGeom->at(index);
109 
110  if (!waferGeom) {
111  cout << "No wafer geometry information! Fatal error!!!" << endl;
112  return;
113  }
114 
115 
116  switch (barrel) {
117 
118  case 1:
119  if (ladder%2)
120  layer = 2;
121  else
122  layer = 1;
123 
124  break;
125 
126  case 2:
127  if (ladder%2)
128  //layer = 3; // MDC4
129  layer = 4; // real installation
130  else
131  //layer = 4; // MDC4
132  layer = 3; // real installation
133 
134  break;
135 
136  case 3:
137  if (ladder%2)
138  layer = 6;
139  else
140  layer = 5;
141 
142  break;
143  }
144 
145  wafersPosition[index].ID = 1000*layer+100*wafer+ladder;
146  rowIDs[index]=index;
147 
148  float dx, dy, dz, nx, ny, nz, tx, ty, tz;
149 
150  // xy rotation
151  nx = waferGeom->n(0)*cos(theta_xy) - waferGeom->n(1)*sin(theta_xy);
152  ny = waferGeom->n(0)*sin(theta_xy) + waferGeom->n(1)*cos(theta_xy);
153  nz = waferGeom->n(2);
154  dx = waferGeom->d(0)*cos(theta_xy) - waferGeom->d(1)*sin(theta_xy);
155  dy = waferGeom->d(0)*sin(theta_xy) + waferGeom->d(1)*cos(theta_xy);
156  dz = waferGeom->d(2);
157  tx = waferGeom->t(0)*cos(theta_xy) - waferGeom->t(1)*sin(theta_xy);
158  ty = waferGeom->t(0)*sin(theta_xy) + waferGeom->t(1)*cos(theta_xy);
159  tz = waferGeom->t(2);
160 
161  // xz rotation
162  nx = nx*cos(theta_xz) - nz*sin(theta_xz);
163  ny = ny;
164  nz = nx*sin(theta_xz) + nz*cos(theta_xz);
165  dx = dx*cos(theta_xz) - dz*sin(theta_xz);
166  dy = dy;
167  dz = dx*sin(theta_xz) + dz*cos(theta_xz);
168  tx = tx*cos(theta_xz) - tz*sin(theta_xz);
169  ty = ty;
170  tz = tx*sin(theta_xz) + tz*cos(theta_xz);
171 
172  // yz rotation
173  nx = nx;
174  ny = ny*cos(theta_yz) - nz*sin(theta_yz);
175  nz = ny*sin(theta_yz) + nz*cos(theta_yz);
176  dx = dx;
177  dy = dy*cos(theta_yz) - dz*sin(theta_yz);
178  dz = dy*sin(theta_yz) + dz*cos(theta_yz);
179  tx = tx;
180  ty = ty*cos(theta_yz) - tz*sin(theta_yz);
181  tz = ty*sin(theta_yz) + tz*cos(theta_yz);
182 
183  float rx, ry, rz, d;
184 
185  switch (barrel) {
186 
187  case 1:
188  d = 3.1525*(2*(2.5-wafer));
189  break;
190 
191  case 2:
192  d = 3.1525*(2*(3.5-wafer));
193  break;
194 
195  case 3:
196  d = 3.1525*(2*(4-wafer));
197  break;
198  }
199 
200  //xy rotation
201  rx = waferGeom->x(0)*cos(theta_xy) - waferGeom->x(1)*sin(theta_xy);
202  ry = waferGeom->x(0)*sin(theta_xy) + waferGeom->x(1)*cos(theta_xy);
203  rz = waferGeom->x(2);
204 
205  // xz rotation
206  rx = rx + d*sin(theta_xz);
207  ry = ry;
208  rz = rz + d*(1-cos(theta_xz));
209 
210  // yz rotation
211  rx = rx;
212  ry = ry + d*sin(theta_yz);
213  rz = rz + d*(1-cos(theta_yz));
214 
215  // shifts
216  rx += delta_x;
217  ry += delta_y;
218  rz += delta_z;
219 
220  wafersPosition[index].driftDirection[0] = dx;
221  wafersPosition[index].driftDirection[1] = dy;
222  wafersPosition[index].driftDirection[2] = dz;
223  wafersPosition[index].normalDirection[0] = nx;
224  wafersPosition[index].normalDirection[1] = ny;
225  wafersPosition[index].normalDirection[2] = nz;
226  wafersPosition[index].transverseDirection[0] = tx;
227  wafersPosition[index].transverseDirection[1] = ty;
228  wafersPosition[index].transverseDirection[2] = tz;
229 
230  wafersPosition[index].centerPosition[0] = rx;
231  wafersPosition[index].centerPosition[1] = ry;
232  wafersPosition[index].centerPosition[2] = rz;
233 
234  nt[0] = waferGeom->x(0);
235  nt[1] = waferGeom->x(1);
236  nt[2] = waferGeom->x(2);
237  nt[3] = rx;
238  nt[4] = ry;
239  nt[5] = rz;
240  nt[6] = waferGeom->n(0);
241  nt[7] = waferGeom->n(1);
242  nt[8] = waferGeom->n(2);
243  nt[9] = nx;
244  nt[10] = ny;
245  nt[11] = nz;
246  nt[12] = waferGeom->d(0);
247  nt[13] = waferGeom->d(1);
248  nt[14] = waferGeom->d(2);
249  nt[15] = dx;
250  nt[16] = dy;
251  nt[17] = dz;
252  nt[18] = waferGeom->t(0);
253  nt[19] = waferGeom->t(1);
254  nt[20] = waferGeom->t(2);
255  nt[21] = tx;
256  nt[22] = ty;
257  nt[23] = tz;
258  nt[24] = barrel;
259  nt[25] = ladder;
260  nt[26] = wafer;
261  ntuple->Fill(nt);
262 
263  if (writeHtml) {
264  file << "<tr>"
265  << "<td><center><b>" << barrel << "</b></center></td>"
266  << "<td><center><b>" << ladder << "</b></center></td>"
267  << "<td><center><b>" << wafer << "</b></center></td>"
268  << "<td><center><b>" << rx << "</b></center></td>"
269  << "<td><center><b>" << ry << "</b></center></td>"
270  << "<td><center><b>" << rz << "</b></center></td>"
271  << "<td><center><b>" << nx << "</b></center></td>"
272  << "<td><center><b>" << ny << "</b></center></td>"
273  << "<td><center><b>" << nz << "</b></center></td>"
274  << "<td><center><b>" << dx << "</b></center></td>"
275  << "<td><center><b>" << dy << "</b></center></td>"
276  << "<td><center><b>" << dz << "</b></center></td>"
277  << "<td><center><b>" << tx << "</b></center></td>"
278  << "<td><center><b>" << ty << "</b></center></td>"
279  << "<td><center><b>" << tz << "</b></center></td>"
280  << "</tr></b>" << endl;
281 
282  //file2 << "<tr>"
283  file << "<tr>"
284  << "<td><center>" << barrel << "</center></td>"
285  << "<td><center>" << ladder << "</center></td>"
286  << "<td><center>" << wafer << "</center></td>"
287  << "<td><center>" << waferGeom->x(0) << "</center></td>"
288  << "<td><center>" << waferGeom->x(1) << "</center></td>"
289  << "<td><center>" << waferGeom->x(2) << "</center></td>"
290  << "<td><center>" << waferGeom->n(0) << "</center></td>"
291  << "<td><center>" << waferGeom->n(1) << "</center></td>"
292  << "<td><center>" << waferGeom->n(2) << "</center></td>"
293  << "<td><center>" << waferGeom->d(0) << "</center></td>"
294  << "<td><center>" << waferGeom->d(1) << "</center></td>"
295  << "<td><center>" << waferGeom->d(2) << "</center></td>"
296  << "<td><center>" << waferGeom->t(0) << "</center></td>"
297  << "<td><center>" << waferGeom->t(1) << "</center></td>"
298  << "<td><center>" << waferGeom->t(2) << "</center></td>"
299  << "</tr>" << endl;
300  }
301 
302  /*
303  cout << "barrel = " << barrel << ", ladder = " << ladder << ", wafer = " << wafer << endl;
304  cout << "x = " << rx << ", y = " << ry << ", z = " << rz << endl;
305  cout << "nx = " << nx << ", ny = " << ny << ", nz = " << nz << endl;
306  cout << "dx = " << dx << ", dy = " << dy << ", dz = " << dz << endl;
307  cout << "tx = " << tx << ", ty = " << ty << ", tz = " << tz << endl;
308  */
309 
310  cout << "index = " << index << ", ID = " << wafersPosition[index].ID << endl;
311  }
312  }
313  }
314 
315  if (writeHtml)
316  file << "</table>" << endl;
317  }
318 
319  if (write) {
321 
322  // connect to Geometry_svt database
323  //StDbConfigNode* svtGeomNode = mgr->initConfig("Geometry_svt","reconV1"); // reconV1 might change in the future
324  StDbConfigNode* svtGeomNode = mgr->initConfig(dbGeometry,dbSvt); // use this line then
325 
326  // print out some info
327  //mgr->setVerbose(true);
328  //svtGeomNode->printTree(0);
329 
330  // request db-table by name
331  StDbTable* svtGeomTable = svtGeomNode->addDbTable("svtWafersPosition");
332  svtGeomTable->SetTable((char*)wafersPosition,NUMBER_OF_WAFERS,rowIDs);
333 
334  mgr->setStoreTime(unixTime);
335  cout<<" Will attempt store with timestamp="<<mgr->getDateStoreTime()<<endl;
336  mgr->storeDbTable(svtGeomTable);
337 
338  delete [] wafersPosition;
339  }
340 }
virtual void SetTable(char *data, int nrows, int *idList=0)
calloc&#39;d version of data for StRoot
Definition: StDbTable.cc:550
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
virtual Int_t Make()
Definition: StChain.cxx:110
static StDbManager * Instance()
strdup(..) is not ANSI
Definition: StDbManager.cc:155