StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSvtDbMaker.cxx
1 /***************************************************************************
2  *
3  * $Id: StSvtDbMaker.cxx,v 1.26 2010/09/01 21:07:07 fisyak Exp $
4  *
5  * Author: Marcelo Munhoz
6  ***************************************************************************
7  *
8  * Description: SVT DB access Maker
9  *
10  ***************************************************************************
11  *
12  * $Log: StSvtDbMaker.cxx,v $
13  * Revision 1.26 2010/09/01 21:07:07 fisyak
14  * Disable simu flavor, now sim parameters is coming via DB associated with simulation time stamp
15  *
16  * Revision 1.25 2007/12/24 17:35:39 fisyak
17  * spelling error StSvtRmsPedestal => StSvtRMSPedestal
18  *
19  * Revision 1.24 2007/07/31 16:38:11 fisyak
20  * Make request for SvtGeometry from GetRotations
21  *
22  * Revision 1.23 2007/07/12 20:07:49 fisyak
23  * Move to access on demand of Db tables
24  *
25  * Revision 1.22 2007/05/15 19:23:21 perev
26  * Init local pointers by 0
27  *
28  * Revision 1.20 2007/04/28 17:57:09 perev
29  * Redundant StChain.h removed
30  *
31  * Revision 1.19 2007/03/27 20:01:22 fisyak
32  * remove senseless print outs
33  *
34  * Revision 1.18 2007/03/21 23:02:13 fisyak
35  * add StSvtGeometry to const area
36  *
37  * Revision 1.17 2007/03/21 17:23:24 fisyak
38  * Ivan Kotov's drift velocities, use TGeoHMatrix for coordinate transformation
39  *
40  * Revision 1.16 2006/02/14 17:49:25 perev
41  * Add initialization =0
42  *
43  * Revision 1.15 2004/07/31 00:50:22 munhoz
44  * adding anode drift veloc correction factor
45  *
46  * Revision 1.14 2004/07/29 01:36:00 caines
47  * Changes for the drift curve usage
48  *
49  * Revision 1.13 2004/07/26 00:06:08 munhoz
50  * read drift curve
51  *
52  * Revision 1.12 2004/03/30 21:16:17 caines
53  * Get daq parameters
54  *
55  * Revision 1.10 2004/01/30 07:22:06 munhoz
56  * adding rms and daq parameters reading
57  *
58  * Revision 1.9 2003/04/14 15:51:39 munhoz
59  * reading t0 from DB
60  *
61  * Revision 1.8 2003/01/28 20:19:57 munhoz
62  * including InitRun()
63  *
64  * Revision 1.7 2002/05/06 00:42:51 munhoz
65  * adding bad anode list reading
66  *
67  * Revision 1.6 2002/02/28 20:41:37 caines
68  * Fix filling of global coord from fortran
69  *
70  * Revision 1.5 2002/02/20 17:10:06 caines
71  * Added fortran2c code from StDbUtilities so library depedancies removed
72  *
73  * Revision 1.4 2002/02/15 22:45:43 munhoz
74  * introducing drift velocity reading capability
75  *
76  * Revision 1.3 2002/02/05 23:30:52 caines
77  * fixing configuration bug
78  *
79  * Revision 1.2 2002/01/31 17:57:17 munhoz
80  * removed incorrect line
81  *
82  * Revision 1.1 2001/10/29 18:53:13 munhoz
83  * starting SVT Data base
84  *
85  *
86  **************************************************************************/
87 #include <assert.h>
88 #include "StSvtDbMaker.h"
89 
90 #include "St_DataSetIter.h"
91 #include "St_ObjectSet.h"
92 #include "StMessMgr.h"
93 
94 #include "StSvtClassLibrary/StSvtEnumerations.hh"
95 
96 #include "StDbUtilities/StCoordinates.hh"
97 #include "StDbUtilities/StSvtCoordinateTransform.hh"
98 #include "StSvtClassLibrary/StSvtGeometry.hh"
99 #include "StSvtClassLibrary/StSvtT0.hh"
100 
101 #include "TMath.h"
102 #include "TVector3.h"
103 #include "StSvtClassLibrary/StSvtConfig.hh"
104 #include "StSvtClassLibrary/StSvtHybridPed.hh"
105 #include "StSvtClassLibrary/StSvtHybridDriftVelocity.hh"
106 #include "StSvtClassLibrary/StSvtHybridDriftCurve.hh"
107 #include "StSvtClassLibrary/StSvtHybridAnodeDriftCorr.hh"
108 #include "StSvtClassLibrary/StSvtHybridCollection.hh"
109 #include "StSvtClassLibrary/StSvtHybridBadAnodes.hh"
110 #include "StSvtClassLibrary/StSvtGeometry.hh"
111 #include "StSvtClassLibrary/StSvtWaferGeometry.hh"
112 #include "StSvtClassLibrary/StSvtT0.hh"
113 #include "StSvtClassLibrary/StSvtDaq.hh"
114 
115 #include "tables/St_svtConfiguration_Table.h"
116 #include "tables/St_svtDriftVelAvg_Table.h"
117 #include "tables/St_svtDriftCurve_Table.h"
118 #include "tables/St_svtBadAnodes_Table.h"
119 #include "tables/St_svtAnodeDriftCorr_Table.h"
120 #include "tables/St_svtPedestals_Table.h"
121 #include "tables/St_svtRms_Table.h"
122 #if 0
123 #include "tables/St_svtWafersPosition_Table.h"
124 #else
125 #include "tables/St_Survey_Table.h"
126 #endif
127 #include "tables/St_svtDimensions_Table.h"
128 #include "tables/St_svtElectronics_Table.h"
129 #include "tables/St_svtDaq_Table.h"
130 #include "tables/St_svtHybridDriftVelocity_Table.h"
131 #include "StDbUtilities/St_svtRDOstrippedC.h"
132 #include "StDbUtilities/St_svtHybridDriftVelocityC.h"
133 #include "StTpcDb/StTpcDb.h"
134 
135 svtElectronics_st *electronic = NULL;
136 THashList *StSvtDbMaker::fRotList = 0;
137 StSvtDbMaker* gStSvtDbMaker = 0;
138 //C and fortran routines
139 
140 //_______________________________________________________________________
141 int type_of_call SvtGtoL_(float *x,float *xp, int* index){
142 
143  StThreeVector<double> a(x[0], x[1], x[2]);
144  StSvtCoordinateTransform transform;
145  St_DataSet* dataSet;
146  dataSet = gStSvtDbMaker->GetDataSet("StSvtGeometry");
147  StSvtGeometry *GeomDataBase = (StSvtGeometry*)dataSet->GetObject();
148  if(GeomDataBase) transform.setParamPointers(GeomDataBase, NULL, NULL, NULL, NULL); // RW added 2 NULLs to remove ambiguity
150 
151  transform.GlobaltoLocal(a, b,*index, -1);
152 
153  xp[0] = b.position().x();
154  xp[1] = b.position().y();
155  xp[2] = b.position().z();
156 
157  return 0;
158 
159 }
160 //____________________________________________________________________________
161 int type_of_call SvtLtoG_(float *xp, float *x, int* index){
163  int layer,ladder,wafer;
164 
165  a.setPosition(StThreeVector<double>(xp[0],xp[1],xp[2]));
166  StSvtCoordinateTransform transform;
167  St_DataSet* dataSet;
168  dataSet = gStSvtDbMaker->GetDataSet("StSvtGeometry");
169  StSvtGeometry *GeomDataBase = (StSvtGeometry*)dataSet->GetObject();
170  if(GeomDataBase) transform.setParamPointers(GeomDataBase, NULL, NULL, NULL, NULL); // RW added 2 NULLs to remove ambiguity
171 
172  StThreeVector<double> b(0,0,0);
174 
175  layer = *index/1000;
176  wafer = (*index -1000*layer)/100;
177  ladder = *index -1000*layer -100*wafer;
178  a.setLayer(layer);
179  a.setLadder(ladder);
180  a.setWafer(wafer);
181  a.setHybrid(1);
182 
183  transform.LocaltoGlobal(a, b, -1);
184 
185  x[0] = b.x();
186  x[1] = b.y();
187  x[2] = b.z();
188 
189  return 0;
190 }
191 
192 ClassImp(StSvtDbMaker)
193 //_____________________________________________________________________________
194 StSvtDbMaker::StSvtDbMaker(const char *name):StMaker(name) { gStSvtDbMaker = this;}
195 //_____________________________________________________________________________
196 StSvtDbMaker::~StSvtDbMaker() { gStSvtDbMaker = NULL;}
197 //_____________________________________________________________________________
198 Int_t StSvtDbMaker::Init()
199 {
200  if (Debug()) gMessMgr->Debug() << "StSvtDbMaker::Init" << endm;
201 #if 0
202  if( m_Mode == 1) {
203  const Char_t *tabNames[3] = {"svtWafersPosition","svtDriftCorrection","svtRDOstripped"};
204  for (Int_t i = 0; i < 3; i++) {
205  gMessMgr->Message() <<
206  "StSvtDbMaker::Init setting " << tabNames[i] << " to simu" << endm;
207  SetFlavor("simu",tabNames[i]);
208  }
209  }
210 #endif
211  return StMaker::Init();
212 }
213 
214 //_____________________________________________________________________________
215 Int_t StSvtDbMaker::InitRun(int runumber)
216 {
217  gMessMgr->Info() << "StSvtDbMaker::InitRun" << endm;
218 
219  St_svtRDOstrippedC *svtRDOstrippedC = St_svtRDOstrippedC::instance();
220  if (! svtRDOstrippedC) {
221  St_svtRDOstripped *svtRDOstripped = (St_svtRDOstripped *) GetDataBase("Calibrations/svt/svtRDOstripped");
222  if (svtRDOstripped) svtRDOstrippedC = new St_svtRDOstrippedC(svtRDOstripped);
223  }
224  assert(St_svtRDOstrippedC::instance());
225 
226  St_svtHybridDriftVelocityC *svtHybridDriftVelocityC = St_svtHybridDriftVelocityC::instance();
227  if (! svtHybridDriftVelocityC) {
228  St_svtHybridDriftVelocity *svtHybridDriftVelocity =
229  (St_svtHybridDriftVelocity *) GetDataBase("Calibrations/svt/svtHybridDriftVelocity");
230  if (svtHybridDriftVelocity) svtHybridDriftVelocityC = new St_svtHybridDriftVelocityC(svtHybridDriftVelocity);
231  }
232  assert(St_svtHybridDriftVelocityC::instance());
233  return kStOk;
234 }
235 
236 //_____________________________________________________________________________
238 {
239  if (Debug()) gMessMgr->Debug() << "StSvtDbMaker::Make" << endm;
240  St_svtRDOstrippedC *svtRDOstrippedC = St_svtRDOstrippedC::instance();
241  if (svtRDOstrippedC) {
242  UInt_t ut = GetDateTime().Convert();
243  svtRDOstrippedC->SetDate(ut); // if you need to cut 1 hours after burn in has been finished
244  if (Debug() > 2) svtRDOstrippedC->PrintRDOmap();
245  }
246  return kStOK;
247 }
248 
249 //_____________________________________________________________________________
250 void StSvtDbMaker::Clear(const char*)
251 {
252  if (Debug()) gMessMgr->Debug() << "StSvtDaqMaker::Clear" << endm;
253 
254  StMaker::Clear();
255 }
256 
257 //_____________________________________________________________________________
259 {
260  if (Debug()) gMessMgr->Debug() << "StSvtDbMaker::Finish" << endm;
261  return kStOK;
262 }
263 
264 //_____________________________________________________________________________
265 StSvtConfig* StSvtDbMaker::getConfiguration()
266 {
267  gMessMgr->Info() << "StSvtDbMaker::getConfiguration" << endm;
268 
269  St_svtConfiguration *configuration = (St_svtConfiguration*) GetDataBase("Geometry/svt/svtConfiguration");
270  if (!(configuration && configuration->HasData()) ){
271  gMessMgr->Message("Error Finding SVT Configuration","E");
272  return 0;
273  }
274 
275  svtConfiguration_st* config = configuration->GetTable();
276 
277  gMessMgr->Info() << "numberOfBarrels = " << config->numberOfBarrels << endm;
278  gMessMgr->Info() << "numberOfLadders = " << config->numberOfLadders << endm;
279  gMessMgr->Info() << "numberOfWafers = " << config->numberOfWafers << endm;
280  gMessMgr->Info() << "numberOfHybrids = " << config->numberOfHybrids << endm;
281 
282  gMessMgr->Info() << "numberOfLaddersPerBarrel[0] = " << config->numberOfLaddersPerBarrel[0] << endm;
283  gMessMgr->Info() << "numberOfLaddersPerBarrel[1] = " << config->numberOfLaddersPerBarrel[1] << endm;
284  gMessMgr->Info() << "numberOfLaddersPerBarrel[2] = " << config->numberOfLaddersPerBarrel[2] << endm;
285  gMessMgr->Info() << "numberOfWafersPerLadder[0] = " << config->numberOfWafersPerLadder[0] << endm;
286  gMessMgr->Info() << "numberOfWafersPerLadder[1] = " << config->numberOfWafersPerLadder[1] << endm;
287  gMessMgr->Info() << "numberOfWafersPerLadder[2] = " << config->numberOfWafersPerLadder[2] << endm;
288  gMessMgr->Info() << "numberOfHybridsPerWafer = " << config->numberOfHybridsPerWafer << endm;
289 
290  StSvtConfig *mSvtConfig = new StSvtConfig();
291  mSvtConfig->setNumberOfBarrels(config->numberOfBarrels);
292 
293  for (int i=0; i<config->numberOfBarrels; i++) {
294  mSvtConfig->setNumberOfLadders(i+1,config->numberOfLaddersPerBarrel[i]);
295  mSvtConfig->setNumberOfWafers(i+1, config->numberOfWafersPerLadder[i]);
296  }
297  mSvtConfig->setNumberOfHybrids(config->numberOfHybridsPerWafer);
298  mSvtConfig->setTotalNumberOfHybrids(config->numberOfHybrids);
299 
300  //temporary. Must read electronics db and fill these quantities
301  mSvtConfig->setNumberOfAnodes(240);
302  mSvtConfig->setNumberOfTimeBins(128);
303 
304  mSvtConfig->setConfiguration();
305 
306  return mSvtConfig;
307 }
308 
309 
310 //_____________________________________________________________________________
311 StSvtHybridCollection* StSvtDbMaker::getDriftCurve()
312 {
313  gMessMgr->Info() << "StSvtDbMaker::getDriftVelocityCurve" << endm;
314  StSvtConfig *mSvtConfig = (StSvtConfig *) (((TObjectSet *) GetDataSet("StSvtConfig"))->GetObject());
315  StSvtHybridCollection *mSvtDriftCurve = (StSvtHybridCollection *) new StSvtHybridCollection(mSvtConfig);
316 
317  St_svtDriftCurve *driftVelocityCurve=0;
318 
319  svtDriftCurve_st *driftCurve=0;
320  StSvtHybridDriftCurve* hybridDriftCurve=0;
321 
322  char path[100];
323  int index;
324 
325  for (int barrel = 1;barrel <= mSvtConfig->getNumberOfBarrels();barrel++) {
326  for (int ladder = 1;ladder <= mSvtConfig->getNumberOfLadders(barrel);ladder++) {
327  for (int wafer = 1;wafer <= mSvtConfig->getNumberOfWafers(barrel);wafer++) {
328  for (int hybrid = 1;hybrid <= mSvtConfig->getNumberOfHybrids();hybrid++) {
329 
330  index = mSvtConfig->getHybridIndex(barrel,ladder,wafer,hybrid);
331 
332  if (index < 0) continue;
333 
334  switch (barrel) {
335  case 1:
336  sprintf(path,"InnerBarrel/Ladder_0%d/Wafer_0%d/Hybrid_0%d/svtDriftCurve",ladder,wafer,hybrid);
337  break;
338  case 2:
339  if (ladder < 10)
340  sprintf(path,"MiddleBarrel/Ladder_0%d/Wafer_0%d/Hybrid_0%d/svtDriftCurve",ladder,wafer,hybrid);
341  else
342  sprintf(path,"MiddleBarrel/Ladder_%d/Wafer_0%d/Hybrid_0%d/svtDriftCurve",ladder,wafer,hybrid);
343  break;
344  case 3:
345  if (ladder < 10)
346  sprintf(path,"OuterBarrel/Ladder_0%d/Wafer_0%d/Hybrid_0%d/svtDriftCurve",ladder,wafer,hybrid);
347  else
348  sprintf(path,"OuterBarrel/Ladder_%d/Wafer_0%d/Hybrid_0%d/svtDriftCurve",ladder,wafer,hybrid);
349  break;
350  }
351 
352  // get wafers position table
353  TString Path("Calibrations/svt/");
354  Path += path;
355  driftVelocityCurve = (St_svtDriftCurve*) GetDataBase(Path);
356  if (!(driftVelocityCurve && driftVelocityCurve->HasData()) ){
357  gMessMgr->Message("Error Finding SVT drift velocity curve","E");
358  return NULL;
359  }
360 
361  driftCurve = driftVelocityCurve->GetTable();
362 
363  hybridDriftCurve = (StSvtHybridDriftCurve*)mSvtDriftCurve->at(index);
364  if (!hybridDriftCurve)
365  hybridDriftCurve = new StSvtHybridDriftCurve(barrel,ladder,wafer,hybrid);
366 
367  // loop over data
368  for (int i=1; i<=3; i++)
369  for (int j=1; j<=10; j++) {
370  hybridDriftCurve->setParameter(i,j,driftCurve->driftCurve[i-1][j-1]);
371  // cout << "adc = " << i << ", parameter = " << j << ", value = " << driftCurve->driftCurve[i-1][j-1] << endl;
372  }
373 
374  mSvtDriftCurve->put_at(hybridDriftCurve,index);
375 
376  } // end of loop over hybrids
377  } // end of loop over wafers
378  } // end of loop over ladders
379  } // end of loop over barrels
380 
381  return mSvtDriftCurve;
382 }
383 
384 //_____________________________________________________________________________
385 StSvtHybridCollection* StSvtDbMaker::getAnodeDriftCorr()
386 {
387  gMessMgr->Info() << "StSvtDbMaker::getAnodeDriftCorr" << endm;
388 
389  // get svt dimensions table
390  St_svtAnodeDriftCorr *anodeDriftCorr;
391  svtAnodeDriftCorr_st *driftCorr;
392 
393  // Create all pedestal objects
394  StSvtConfig *mSvtConfig = (StSvtConfig *) (((TObjectSet *) GetDataSet("StSvtConfig"))->GetObject());
395  StSvtHybridCollection *mSvtAnodeDriftCorr = new StSvtHybridCollection(mSvtConfig);
396  StSvtHybridAnodeDriftCorr* hybridAnodeDriftCorr;
397 
398  char path[100];
399  int index;
400 
401  for (int barrel = 1;barrel <= mSvtConfig->getNumberOfBarrels();barrel++) {
402  for (int ladder = 1;ladder <= mSvtConfig->getNumberOfLadders(barrel);ladder++) {
403  for (int wafer = 1;wafer <= mSvtConfig->getNumberOfWafers(barrel);wafer++) {
404  for (int hybrid = 1;hybrid <= mSvtConfig->getNumberOfHybrids();hybrid++) {
405 
406  index = mSvtConfig->getHybridIndex(barrel,ladder,wafer,hybrid);
407 
408  if (index < 0) continue;
409 
410  switch (barrel) {
411  case 1:
412  sprintf(path,"InnerBarrel/Ladder_0%d/Wafer_0%d/Hybrid_0%d/svtAnodeDriftCorr",ladder,wafer,hybrid);
413  break;
414  case 2:
415  if (ladder < 10)
416  sprintf(path,"MiddleBarrel/Ladder_0%d/Wafer_0%d/Hybrid_0%d/svtAnodeDriftCorr",ladder,wafer,hybrid);
417  else
418  sprintf(path,"MiddleBarrel/Ladder_%d/Wafer_0%d/Hybrid_0%d/svtAnodeDriftCorr",ladder,wafer,hybrid);
419  break;
420  case 3:
421  if (ladder < 10)
422  sprintf(path,"OuterBarrel/Ladder_0%d/Wafer_0%d/Hybrid_0%d/svtAnodeDriftCorr",ladder,wafer,hybrid);
423  else
424  sprintf(path,"OuterBarrel/Ladder_%d/Wafer_0%d/Hybrid_0%d/svtAnodeDriftCorr",ladder,wafer,hybrid);
425  break;
426  }
427 
428  // get wafers position table
429  TString Path("Calibrations/svt/");
430  Path += path;
431  anodeDriftCorr = (St_svtAnodeDriftCorr*) GetDataBase(Path);
432  if (!(anodeDriftCorr && anodeDriftCorr->HasData()) ){
433  gMessMgr->Message("Error Finding SVT bad anodes","E");
434  return 0;
435  }
436  driftCorr = anodeDriftCorr->GetTable();
437 
438  hybridAnodeDriftCorr = (StSvtHybridAnodeDriftCorr*)mSvtAnodeDriftCorr->at(index);
439  if (!hybridAnodeDriftCorr)
440  hybridAnodeDriftCorr = new StSvtHybridAnodeDriftCorr(barrel,ladder,wafer,hybrid);
441 
442  // loop over anodes
443  for (int anode=1;anode<=mSvtConfig->getNumberOfAnodes();anode++) {
444  hybridAnodeDriftCorr->setValue(anode,driftCorr->driftVelocCorr[anode-1]);
445  //if (anode==120)
446  // cout << "index = " << index << ", drift corr = " << driftCorr->driftVelocCorr[anode-1] << endl;
447  }
448 
449  mSvtAnodeDriftCorr->put_at(hybridAnodeDriftCorr,index);
450 
451  } // end of loop over hybrids
452  } // end of loop over wafers
453  } // end of loop over ladders
454  } // end of loop over barrels
455 
456  return mSvtAnodeDriftCorr;
457 }
458 
459 //_____________________________________________________________________________
460 StSvtHybridCollection* StSvtDbMaker::getPedestals()
461 {
462  gMessMgr->Info() << "StSvtDbMaker::getPedestals" << endm;
463 
464  St_svtPedestals *pedestals = (St_svtPedestals*)GetDataBase("Calibrations/svt/svtPedestals");
465  if (!(pedestals && pedestals->HasData()) ){
466  gMessMgr->Message("Error Finding SVT Pedestals","E");
467  return 0;
468  }
469 
470  svtPedestals_st *pedestal = pedestals->GetTable();
471 
472  // Create all pedestal objects
473  StSvtConfig *mSvtConfig = (StSvtConfig *) (((TObjectSet *) GetDataSet("StSvtConfig"))->GetObject());
474  StSvtHybridCollection *mSvtPed = new StSvtHybridCollection(mSvtConfig);
475  StSvtHybridPed* hybridPed;
476  int index;
477 
478  for (int barrel = 1;barrel <= mSvtConfig->getNumberOfBarrels();barrel++) {
479  for (int ladder = 1;ladder <= mSvtConfig->getNumberOfLadders(barrel);ladder++) {
480  for (int wafer = 1;wafer <= mSvtConfig->getNumberOfWafers(barrel);wafer++) {
481  for (int hybrid = 1;hybrid <= mSvtConfig->getNumberOfHybrids();hybrid++) {
482 
483  index = mSvtConfig->getHybridIndex(barrel,ladder,wafer,hybrid);
484 
485  if (index < 0) continue;
486 
487  hybridPed = (StSvtHybridPed*)mSvtPed->at(index);
488  if (!hybridPed)
489  hybridPed = new StSvtHybridPed(barrel,ladder,wafer,hybrid);
490  hybridPed->reset();
491 
492  // loop over anodes
493  for (int anode = 1; anode <= mSvtConfig->getNumberOfAnodes(); anode++)
494  for (int time = 0; time < mSvtConfig->getNumberOfTimeBins(); time++) {
495  hybridPed->addToPixel(anode,time,pedestal[index].pedestal[anode-1][time]);
496  //gMessMgr->Info() << anode << " " << time << " " << pedestal[index].pedestal[anode-1][time] << endm;
497  }
498 
499  mSvtPed->put_at(hybridPed,index);
500 
501  } // end of loop over hybrids
502  } // end of loop over wafers
503  } // end of loop over ladders
504  } // end of loop over barrels
505 
506  return mSvtPed;
507 }
508 
509 
510 //_____________________________________________________________________________
511 StSvtHybridCollection* StSvtDbMaker::getRms()
512 {
513  gMessMgr->Info() << "StSvtDbMaker::getRms" << endm;
514 
515  St_svtRms *st_rms = (St_svtRms*)GetDataBase("Calibrations/svt/svtRms");
516  if (!(st_rms && st_rms->HasData()) ){
517  gMessMgr->Message("Error Finding SVT RMS","E");
518  return 0;
519  }
520 
521  svtRms_st *rms = st_rms->GetTable();
522 
523  // Create all pedestal objects
524  StSvtConfig *mSvtConfig = (StSvtConfig *) (((TObjectSet *) GetDataSet("StSvtConfig"))->GetObject());
525  StSvtHybridCollection *mSvtRms = new StSvtHybridCollection(mSvtConfig);
526  StSvtHybridPixels* hybridRms;
527  int index;
528 
529  for (int barrel = 1;barrel <= mSvtConfig->getNumberOfBarrels();barrel++) {
530  for (int ladder = 1;ladder <= mSvtConfig->getNumberOfLadders(barrel);ladder++) {
531  for (int wafer = 1;wafer <= mSvtConfig->getNumberOfWafers(barrel);wafer++) {
532  for (int hybrid = 1;hybrid <= mSvtConfig->getNumberOfHybrids();hybrid++) {
533 
534  index = mSvtConfig->getHybridIndex(barrel,ladder,wafer,hybrid);
535 
536  if (index < 0) continue;
537 
538  hybridRms = (StSvtHybridPixels*)mSvtRms->at(index);
539  if (!hybridRms)
540  hybridRms = new StSvtHybridPixels(barrel,ladder,wafer,hybrid);
541  hybridRms->reset();
542 
543  // loop over anodes
544  for (int anode = 1; anode <= mSvtConfig->getNumberOfAnodes(); anode++)
545  for (int time = 0; time < mSvtConfig->getNumberOfTimeBins(); time++) {
546  hybridRms->addToPixel(anode,time,rms[index].rms[anode-1][time]);
547  //gMessMgr->Info() << anode << " " << time << " " << rms[index].rms[anode-1][time] << endm;
548  }
549 
550  mSvtRms->put_at(hybridRms,index);
551 
552  } // end of loop over hybrids
553  } // end of loop over wafers
554  } // end of loop over ladders
555  } // end of loop over barrels
556 
557  return mSvtRms;
558 }
559 
560 //_____________________________________________________________________________
561 StSvtGeometry* StSvtDbMaker::getGeometry()
562 {
563  gMessMgr->Info() << "StSvtDbMaker::getGeometry" << endm;
564 
565  // get svt dimensions table
566  St_svtDimensions *dimensions = (St_svtDimensions*)GetDataBase("Geometry/svt/svtDimensions");
567  if (!(dimensions && dimensions->HasData()) ){
568  gMessMgr->Message("Error Finding SVT Dimensions","E");
569  return 0;
570  }
571 
572  svtDimensions_st *dimension = dimensions->GetTable();
573 
574  // Create all pedestal objects
575  StSvtConfig *mSvtConfig = (StSvtConfig *) (((TObjectSet *) GetDataSet("StSvtConfig"))->GetObject());
576  StSvtGeometry *mSvtGeom = new StSvtGeometry(mSvtConfig);
577  mSvtGeom->setBarrelRadius(dimension->barrelRadius);
578  mSvtGeom->setWaferLength(dimension->waferLength);
579  mSvtGeom->setWaferThickness(dimension->waferThickness);
580  mSvtGeom->setWaferWidth(dimension->waferWidth);
581  //mSvtGeom->setAnodePitch(dimension->anodePitch);
582  mSvtGeom->setAnodePitch(0.025);
583  mSvtGeom->setFocusRegionLength(dimension->focusRegionLength);
584  mSvtGeom->setDistanceInjector(dimension->distanceInjector);
585  mSvtGeom->setLaserPosition(dimension->laserPosition);
586  fRotList = new THashList(100,0);
587  fRotList->SetOwner(kFALSE);
588  St_Survey *SvtOnGlobal = (St_Survey *) GetDataBase("Geometry/svt/SvtOnGlobal");
589  if (! SvtOnGlobal) {cout << "SvtOnGlobal has not been found" << endl; return 0;}
590 
591  TGeoHMatrix GL, LS,SG,LA,WG;
592  Survey_st *OnGlobal = SvtOnGlobal->GetTable(); // SSD and SVT as whole
593  GL.SetRotation(&OnGlobal->r00);
594  GL.SetTranslation(&OnGlobal->t0);
595  const TGeoHMatrix &Tpc2Global = gStTpcDb->Tpc2GlobalMatrix();
596 
597  // SVT
598  St_Survey *WaferOnLadder = (St_Survey *) GetDataBase("Geometry/svt/WaferOnLadder");
599  St_Survey *LadderOnSurvey = (St_Survey *) GetDataBase("Geometry/svt/LadderOnSurvey");
600  St_Survey *LadderOnShell = (St_Survey *) GetDataBase("Geometry/svt/LadderOnShell");
601  St_Survey *ShellOnGlobal = (St_Survey *) GetDataBase("Geometry/svt/ShellOnGlobal");
602  Int_t NW = WaferOnLadder->GetNRows();
603  Int_t NL = LadderOnSurvey->GetNRows();
604  Survey_st *waferOnLadder = WaferOnLadder->GetTable();
605  Survey_st *shellOnGlobal0 = ShellOnGlobal->GetTable(0);
606  Survey_st *shellOnGlobal1 = ShellOnGlobal->GetTable(1);
607  TGeoHMatrix LSU, LSH, SHG[2];
608  SHG[0].SetRotation(&shellOnGlobal0->r00);
609  SHG[0].SetTranslation(&shellOnGlobal0->t0);
610  SHG[1].SetRotation(&shellOnGlobal1->r00);
611  SHG[1].SetTranslation(&shellOnGlobal1->t0);
612  TGeoHMatrix *comb;
613 #if 0
614  Double_t swap[9] = { 1, 0, 0, 0, 0, 1, 0, 1, 0};
615  TGeoHMatrix SWAP("SWAP");
616  SWAP.SetRotation(swap);
617 #endif
618  for (Int_t i = 0; i < NW; i++, waferOnLadder++) {
619  Int_t id = waferOnLadder->Id;
620  Int_t wbarrel = id/1000;
621  Int_t wwafer = (id - 1000*wbarrel)/100;
622  Int_t wladder = id%100;
623  Int_t wlayer = 2*wbarrel + wladder%2 - 1;
624  // Id = 1000* layer + 100* wafer + ladder;
625  Int_t Id = 1000*wlayer + 100*wwafer + wladder;
626  Int_t index = mSvtGeom->getWaferIndex(wbarrel,wladder,wwafer);
627  if (index < 0) continue;
628  StSvtWaferGeometry *waferGeom = (StSvtWaferGeometry *) fRotList->FindObject(Form("R%04i",Id));
629  if (waferGeom) continue;
630  waferGeom = new StSvtWaferGeometry(wbarrel,wladder,wwafer);
631  mSvtGeom->put_at(waferGeom,index);
632  Int_t Found = 0;
633  Survey_st *ladderOnSurvey = LadderOnSurvey->GetTable();
634  for ( Int_t j = 0; j < NL; j++, ladderOnSurvey++) {
635  Int_t Idl = ladderOnSurvey->Id;
636  Int_t lbarrel = Idl/1000;
637  Int_t lladder = Idl%100;
638  if( wladder != lladder || wbarrel != lbarrel) continue;
639  Survey_st *ladderOnShell = LadderOnShell->GetTable();
640  Int_t found = 0;
641  for ( Int_t l = 0; l < NL; l++, ladderOnShell++) if (ladderOnShell->Id == ladderOnSurvey->Id) {found++; break;}
642  if (! found) continue;
643  LSH.SetRotation(&ladderOnShell->r00);
644  LSH.SetTranslation(&ladderOnShell->t0);
645  Int_t Shell = 1;
646  if( (wbarrel == 1 && wladder <= 4) || (wbarrel == 2 && wladder <= 6) || (wbarrel == 3 && wladder <= 8) ) Shell = 0;
647  // shellOnGlobal * ladderOnShell * ladderOnSurvey * waferOnLadder
648 
649  TGeoHMatrix wL;
650  wL.SetRotation(&waferOnLadder->r00);
651  wL.SetTranslation(&waferOnLadder->t0);
652  LSU.SetRotation(&ladderOnSurvey->r00);
653  LSU.SetTranslation(&ladderOnSurvey->t0);
654  // LSU - ladderOnSurvey {1001,1.000000,-0.000923, 0.000074, 0.000923, 1.000000,-0.000036,-0.000074, 0.000036, 1, 0.0071, 7.1686, -1.2355
655  // wL - waferOnLadder {1101,0.999999, 0.001235, 0.000003,-0.001235, 0.999999,-0.000124,-0.000003, 0.000124, 1,-0.0005, 0.2404, 15.3065,
656  TGeoHMatrix WLL = LSU * wL;
657 
658  TGeoHMatrix *WL = (TGeoHMatrix *) fRotList->FindObject(Form("WL%04i",Id));
659  if (! WL) {
660  WL = new TGeoHMatrix(Form("WL%04i",Id));
661  Double_t *r = WLL.GetRotationMatrix();
662  Double_t rot[9] = {r[0], r[2], r[1],
663  r[3], r[5], r[4],
664  r[6], r[8], r[7]};
665  // {7101, 1.000000,0, 0.000052,0, 1,0,-0.000052,0, 1.000000,-0.000600,0,-32.625900,
666  WL->SetRotation(rot);
667  WL->SetTranslation(WLL.GetTranslation());
668  fRotList->Add(WL);
669  }
670  // WG = GL * SHG * LSH * LSU * (*WL); // WG.Print();
671  // GL - SvtOnGlobal
672  // SHG - ShellOnGlobal { 0, 0.999850, 0.01733, 0.000019, -0.01733, 0.999850,-0.00071, -0.000019, 0.00071, 0.999999, -0.2105, -0.0160, -0.1244
673  // LSH - ladderOnShell {1001, 0.707107,0.707107, 0. , -0.707107,0.707107, 0. , 0 , 0, 1 , 0, 0 ,-23.5250
674  //
675  if (Debug()) {
676  cout << "Tpc2Global "; Tpc2Global.Print();
677  cout << "GL "; GL.Print();
678  TGeoHMatrix test = Tpc2Global * GL; cout << "test "; test.Print();
679  }
680  WG = Tpc2Global * GL * SHG[Shell] * LSH * WLL;// * SWAP; // WG.Print();
681  Double_t *r = WG.GetRotationMatrix();
682  Int_t fail = 0;
683  for (int l = 0; l < 9; l++) {
684  if (TMath::Abs(r[l]) >= 1.000001) fail++;
685  }
686  if (fail && Debug()) {
687  cout << "===============" << waferOnLadder->Id << " "<< id << " " << Id <<endl;
688  cout << "WG\t"; WG.Print();
689  }
690  Double_t norm;
691  TVector3 d(r[0],r[3],r[6]); norm = 1/d.Mag(); d *= norm;
692  TVector3 t(r[2],r[5],r[8]); norm = 1/t.Mag(); t *= norm;
693  TVector3 n(r[1],r[4],r[7]); norm = 1/n.Mag(); n *= norm;
694  TVector3 c = d.Cross(t);
695  if (c.Dot(n) < 0) c *= -1;
696 
697  Double_t *wgtr = WG.GetTranslation();
698  Double_t rot[9] = {
699  d[0], t[0], n[0],
700  d[1], t[1], n[1],
701  d[2], t[2], n[2]};
702  waferGeom->SetRotation(rot);
703  waferGeom->SetTranslation(wgtr);
704  if (Debug()) waferGeom->print();
705  fRotList->Add(waferGeom);
706  Found++;
707  break;
708  }
709  assert(Found);
710  }
711  TIter next(fRotList);
712  Int_t fail = 0;
713  // TGeoHMatrix *comb;
714  while ((comb = (TGeoHMatrix *) next())) {
715  TString Name(comb->GetName());
716  if (Name.BeginsWith("R")) {
717  TGeoHMatrix *WL = (TGeoHMatrix *) fRotList->FindObject(Form("WL%s",Name.Data()+1));
718  if (! WL) {
719  cout << Form("WL%s",Name.Data()+1) << " has not been found" << endl;
720  fail++;
721  }
722  }
723  }
724  assert(! fail);
725  return mSvtGeom;
726 }
727 
728 //_____________________________________________________________________________
729 StSvtHybridCollection* StSvtDbMaker::getBadAnodes()
730 {
731  gMessMgr->Info() << "StSvtDbMaker::getBadAnodes" << endm;
732 
733  // get svt dimensions table
734  St_svtBadAnodes *badAnodes;
735  svtBadAnodes_st *badAnode;
736  StSvtConfig *mSvtConfig = (StSvtConfig *) (((TObjectSet *) GetDataSet("StSvtConfig"))->GetObject());
737  // Create all pedestal objects
738  StSvtHybridCollection *mSvtBadAnodes = new StSvtHybridCollection(mSvtConfig);
739  StSvtHybridBadAnodes* hybridBadAnodes;
740 
741  char path[100];
742  int index;
743 
744  for (int barrel = 1;barrel <= mSvtConfig->getNumberOfBarrels();barrel++) {
745  for (int ladder = 1;ladder <= mSvtConfig->getNumberOfLadders(barrel);ladder++) {
746  for (int wafer = 1;wafer <= mSvtConfig->getNumberOfWafers(barrel);wafer++) {
747  for (int hybrid = 1;hybrid <= mSvtConfig->getNumberOfHybrids();hybrid++) {
748 
749  index = mSvtConfig->getHybridIndex(barrel,ladder,wafer,hybrid);
750 
751  if (index < 0) continue;
752 
753  switch (barrel) {
754  case 1:
755  sprintf(path,"InnerBarrel/Ladder_0%d/Wafer_0%d/Hybrid_0%d/svtBadAnodes",ladder,wafer,hybrid);
756  break;
757  case 2:
758  if (ladder < 10)
759  sprintf(path,"MiddleBarrel/Ladder_0%d/Wafer_0%d/Hybrid_0%d/svtBadAnodes",ladder,wafer,hybrid);
760  else
761  sprintf(path,"MiddleBarrel/Ladder_%d/Wafer_0%d/Hybrid_0%d/svtBadAnodes",ladder,wafer,hybrid);
762  break;
763  case 3:
764  if (ladder < 10)
765  sprintf(path,"OuterBarrel/Ladder_0%d/Wafer_0%d/Hybrid_0%d/svtBadAnodes",ladder,wafer,hybrid);
766  else
767  sprintf(path,"OuterBarrel/Ladder_%d/Wafer_0%d/Hybrid_0%d/svtBadAnodes",ladder,wafer,hybrid);
768  break;
769  }
770 
771  // get wafers position table
772  TString Path("Calibrations/svt/");
773  Path += path;
774  badAnodes = (St_svtBadAnodes*) GetDataBase(Path);
775  if (!(badAnodes && badAnodes->HasData()) ){
776  gMessMgr->Message("Error Finding SVT bad anodes","E");
777  return 0;
778  }
779 
780  badAnode = badAnodes->GetTable();
781 
782  hybridBadAnodes = (StSvtHybridBadAnodes*)mSvtBadAnodes->at(index);
783  if (!hybridBadAnodes)
784  hybridBadAnodes = new StSvtHybridBadAnodes(barrel,ladder,wafer,hybrid);
785 
786  // loop over anodes
787  for (int anode=1;anode<=mSvtConfig->getNumberOfAnodes();anode++) {
788  if (badAnode->isBadAnode[anode-1]) {
789  hybridBadAnodes->setBadAnode(anode);
790  //gMessMgr->Info() << "hybrid = "<< index << ", anode = " << anode << endm;
791  }
792  }
793 
794  mSvtBadAnodes->put_at(hybridBadAnodes,index);
795 
796  } // end of loop over hybrids
797  } // end of loop over wafers
798  } // end of loop over ladders
799  } // end of loop over barrels
800 
801  return mSvtBadAnodes;
802 }
803 
804 //_____________________________________________________________________________
805 int StSvtDbMaker::getElectronics()
806 {
807  // get svt electronics table
808  St_svtElectronics *electronics = (St_svtElectronics*)GetDataBase("Calibrations/svt/svtElectronics");
809  if (!(electronics && electronics->HasData()) ){
810  gMessMgr->Message("Error Finding SVT Electronics","E");
811  return kFALSE;
812  }
813 
814  electronic = electronics->GetTable();
815  return kTRUE;
816 }
817 
818 //_____________________________________________________________________________
819 StSvtT0* StSvtDbMaker::getT0()
820 {
821  StSvtT0 *mSvtT0 = new StSvtT0();
822 
823  if (getElectronics()) {
824  for (int i=0;i<24;i++)
825  mSvtT0->setT0(electronic->tZero[i],i+1);
826  mSvtT0->setFsca(electronic->samplingFrequency);
827 
828  gMessMgr->Info() << "t0 = " << mSvtT0->getT0(1) << ", fsca = " << mSvtT0->getFsca() << endm;
829 
830  }
831 
832  return mSvtT0;
833 }
834 
835 
836 //_____________________________________________________________________________
837 StSvtDaq* StSvtDbMaker::getDaqParameters()
838 {
839  gMessMgr->Info() << "StSvtDbMaker::getDaqParameters" << endm;
840 
841  St_svtDaq *daq = (St_svtDaq*)GetDataBase("Calibrations/svt/svtDaq");
842  if (!(daq && daq->HasData()) ){
843  gMessMgr->Message("Error Finding SVT Daq","E");
844  return 0;
845  }
846 
847  svtDaq_st* daqParam = daq->GetTable();
848 
849  gMessMgr->Info() << "clearedTimeBins = " << daqParam->clearedTimeBins<< endm;
850  gMessMgr->Info() << "pixelsBefore = " << daqParam->pixelsBefore << endm;
851  gMessMgr->Info() << "pixelsAfter = " << daqParam->pixelsAfter << endm;
852  gMessMgr->Info() << "pedOffset = " << daqParam->pedOffset << endm;
853  gMessMgr->Info() << "seqLo = " << daqParam->seqLo << endm;
854  gMessMgr->Info() << "seqHi = " << daqParam->seqHi << endm;
855  gMessMgr->Info() << "threshLo = " << daqParam->threshLo << endm;
856  gMessMgr->Info() << "threshHi = " << daqParam->threshHi << endm;
857 
858  StSvtDaq *mSvtDaq = new StSvtDaq();
859 
860  mSvtDaq->setClearedTimeBins(daqParam->clearedTimeBins);
861  mSvtDaq->setSavedBlackAnodes(daqParam->savedBlackAnodes[0],0);
862  mSvtDaq->setSavedBlackAnodes(daqParam->savedBlackAnodes[1],1);
863  mSvtDaq->setSavedBlackAnodes(daqParam->savedBlackAnodes[2],2);
864  mSvtDaq->setSavedBlackAnodes(daqParam->savedBlackAnodes[2],3);
865  mSvtDaq->setPixelsBefore(daqParam->pixelsBefore);
866  mSvtDaq->setPixelsAfter(daqParam->pixelsAfter);
867  mSvtDaq->setPedOffset(daqParam->pedOffset);
868  mSvtDaq->setSeqLo(daqParam->seqLo);
869  mSvtDaq->setSeqHi(daqParam->seqHi);
870  mSvtDaq->setThreshLo(daqParam->threshLo);
871  mSvtDaq->setThreshHi(daqParam->threshHi);
872 
873  return mSvtDaq;
874 }
875 
876 //_____________________________________________________________________________
877 TDataSet *StSvtDbMaker::FindDataSet (const char* logInput,const StMaker *uppMk,
878  const StMaker *dowMk) const
879 {
880  TDataSet *ds = StMaker::FindDataSet(logInput,uppMk,dowMk);
881  if (ds) return ds;
882  static const Char_t *SetNames[] = {"StSvtConfig", "StSvtDriftVelocity", "StSvtDriftCurve",
883  "StSvtAnodeDriftCorr", "StSvtPedestal","StSvtRMSPedestal",
884  "StSvtGeometry", "StSvtBadAnodes", "StSvtT0", "StSvtDaq",
885  "StSvtGeometry", 0};
886  TString Input(logInput);
887  if (! Input.Contains("StSvt")) return ds;
888  St_ObjectSet *objs = 0;
889  StSvtDbMaker *This = (StSvtDbMaker *) this;
890  for (Int_t i = 0; SetNames[i]; i++) {
891  if (Input.CompareTo(SetNames[i])) continue;
892  objs = new St_ObjectSet(SetNames[i]);
893  This->AddConst(objs);
894  TObject *o = 0;
895  if (! Input.CompareTo("StSvtConfig")) o = This->getConfiguration();
896  else if (! Input.CompareTo("StSvtDriftVelocity")) o = 0;
897  else if (! Input.CompareTo("StSvtDriftCurve")) o = This->getDriftCurve();
898  else if (! Input.CompareTo("StSvtAnodeDriftCorr"))o = This->getAnodeDriftCorr();
899  else if (! Input.CompareTo("StSvtPedestal")) o = This->getPedestals();
900  else if (! Input.CompareTo("StSvtRMSPedestal")) o = This->getRms();
901  else if (! Input.CompareTo("StSvtGeometry")) o = This->getGeometry();
902  else if (! Input.CompareTo("StSvtBadAnodes")) o = This->getBadAnodes();
903  else if (! Input.CompareTo("StSvtT0")) o = This->getT0();
904  else if (! Input.CompareTo("StSvtDaq")) o = This->getDaqParameters();
905  else if (! Input.CompareTo("StSvtGeometry")) o = This->getGeometry();
906  if (o) objs->SetObject(o);
907  break;
908  }
909  return (TDataSet *) objs;
910 }
911 //________________________________________________________________________________
912 THashList *StSvtDbMaker::GetRotations() {
913  FindDataSet("StSvtGeometry");
914  return fRotList;
915 }
Int_t m_Mode
counters
Definition: StMaker.h:81
virtual void Clear(Option_t *option="")
User defined functions.
Definition: StMaker.cxx:634
virtual Int_t Finish()
virtual void SetObject(TObject *obj)
The depricated method (left here for the sake of the backward compatibility)
Definition: TObjectSet.h:59
virtual TObject * GetObject() const
The depricated method (left here for the sake of the backward compatibility)
Definition: TDataSet.cxx:428
Definition: Stypes.h:40
virtual TString Path() const
return the full path of this data set
Definition: TDataSet.cxx:626
virtual Int_t Make()
Definition: Stypes.h:41