StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSstDbMaker.cxx
1 //$Id: StSstDbMaker.cxx,v 1.23 2017/09/01 22:22:14 yiguo Exp $
2 //
3 //$Log: StSstDbMaker.cxx,v $
4 //Revision 1.23 2017/09/01 22:22:14 yiguo
5 //corresponding to DB table change sstOnTpc = oscOnTpc*sstOnOsc by Yi Guo
6 //
7 //Revision 1.22 2016/06/20 18:48:31 bouchet
8 //coverity : STACK_USE ; heap allocation for sstWafersPosition
9 //
10 //Revision 1.21 2016/05/31 21:51:49 bouchet
11 //coverity : UNINIT_CTOR (m_positions)
12 //
13 //Revision 1.20 2015/08/03 13:07:20 bouchet
14 //getSstDimensions() returns the table data, not the structure
15 //
16 //Revision 1.19 2015/06/23 17:17:38 bouchet
17 //move to SST tables ; cpp-checked
18 //
19 //Revision 1.6 2015/06/10 13:59:15 bouchet
20 //cppcheck style-issues for pointer casting ; properly renamed some methods
21 //
22 //Revision 1.5 2015/05/20 13:29:25 bouchet
23 //mapping fixed when decoding and setting the maskChip table
24 //
25 //Revision 1.4 2015/05/08 14:14:34 bouchet
26 //cosmetic
27 //
28 //Revision 1.3 2015/04/27 20:07:51 bouchet
29 //ssdHotChip --> sstMaskChip (final name) ; get and set methods enabled
30 //
31 //Revision 1.2 2015/04/21 20:02:24 bouchet
32 //CVS tags added
33 //
34 /***************************************************************************
35  * Author: J. Bouchet (KSU)
36  * Description: SST DB access Maker
37  **************************************************************************/
38 #include "StSstDbMaker.h"
39 #include "TDataSetIter.h"
40 #include "StMessMgr.h"
41 #include "tables/St_sstWafersPosition_Table.h"
42 #include "tables/St_sstConfiguration_Table.h"
43 #include "tables/St_sstDimensions_Table.h"
44 #include "tables/St_sstMaskChip_Table.h"
45 #include "tables/St_sstSlsCtrl_Table.h"
46 #include "tables/St_Survey_Table.h"
47 #include "TMath.h"
48 #include "TVector3.h"
49 #include "StTpcDb/StTpcDb.h"
50 #include "StSstUtil/StSstConsts.h"
51 
52 StSstDbMaker *gStSstDbMaker = NULL;
53 THashList *StSstDbMaker::fRotList = 0;
54 
55 ClassImp(StSstDbMaker)
56 //_____________________________________________________________________________
57  StSstDbMaker::StSstDbMaker(const char *name):
58  StMaker(name), mySst(0), dimensions(0), config(0), ctrl(0), mode(0),
59  mReady(kStErr),m_positions(0)
60 {
61  gStSstDbMaker = this;
62 }
63 //_____________________________________________________________________________
64 StSstDbMaker::~StSstDbMaker() {SafeDelete(mySst); gStSstDbMaker = 0;}
65 //_____________________________________________________________________________
66 Int_t StSstDbMaker::InitRun(Int_t runNumber)
67 {
68  mode = m_Mode;
69 
70  St_sstMaskChip *maskChipTable = (St_sstMaskChip*)GetDataBase("Calibrations/sst/sstMaskChip");
71  if (maskChipTable) {
72  LOG_INFO << "sst mask chips table found ... initialize" << endm;
73  setMaskChips(maskChipTable->GetTable());}
74  else {LOG_ERROR << " no sst masking chips table " << endm;
75  mReady = kStFatal;
76  return kStFatal;}
77 
78  St_sstSlsCtrl *m_ctrl = (St_sstSlsCtrl *)GetDataBase("Geometry/sst/sstSlsCtrl");
79  if (!m_ctrl) {
80  LOG_ERROR << "InitRun: No relevant entry found in 'Geometry/sst/sstSlsCtrl' table" << endm;
81  mReady = kStFatal;
82  return kStFatal;
83  }
84  ctrl = m_ctrl->GetTable();
85 
86  St_sstDimensions *m_dimensions = (St_sstDimensions *) GetDataBase("Geometry/sst/sstDimensions");
87 
88  if (!m_dimensions) {
89  LOG_ERROR << "InitRun: No relevant entry found in 'Geometry/sst/sstDimensions' table" << endm;
90  mReady = kStFatal;
91  return kStFatal;
92  }
93 
94  dimensions = m_dimensions->GetTable();
95 
96  m_positions = calculateWafersPosition();
97 
98  if (!m_positions) {
99  mReady = kStFatal;
100  return kStFatal;
101  }
102 
103  St_sstConfiguration *configTable = (St_sstConfiguration *) GetDataBase("Geometry/sst/sstConfiguration");
104 
105  if (!configTable) {
106  LOG_ERROR << "InitRun: No relevant entry found in 'Geometry/sst/sstConfiguration' table" << endm;
107  mReady = kStFatal;
108  return kStFatal;
109  }
110 
111  config = configTable->GetTable() ;
112  sstDimensions_st *dimensions = m_dimensions->GetTable();
113  mySst = new StSstBarrel(dimensions, config);
114 
115  if (Debug()) mySst->SetDebug(Debug());
116 
117  mySst->initLadders(m_positions);
118 
119  // Set the return code for Make() to kStOk since we managed to get to the end of this routine
120  mReady = kStOk;
121 
122  return kStOK;
123 }
124 //_____________________________________________________________________________
126 {
127  return mReady;
128 }
129 //_____________________________________________________________________________
130 St_sstWafersPosition *StSstDbMaker::calculateWafersPosition()
131 {
132  SafeDelete(fRotList);
133  fRotList = new THashList(320, 0);
134  fRotList->SetOwner(kFALSE);
135 
137  // matrix LS ~ ladderOnSst
138  // OT ~ oscOnTpc
139  // SO ~ sstOnOsc
140  // SG = OT*SO
141 
142  TGeoHMatrix LS, OT, SO, SG, LA, WG;
143  assert(gStTpcDb);
144  const TGeoHMatrix &Tpc2Global = gStTpcDb->Tpc2GlobalMatrix();
145 
146  // SSD
147  St_Survey *sstOnOsc = (St_Survey *) GetDataBase("Geometry/sst/sstOnOsc"); // sst in Osc
148 
149  if (!sstOnOsc) {
150  LOG_ERROR << "CalculateWafersPosition: No relevant entry found in 'Geometry/sst/sstOnOsc' table" << endm;
151  return 0;
152  }
153 
154  St_Survey *oscOnTpc = (St_Survey *) GetDataBase("Geometry/sst/oscOnTpc"); // osc in tpc
155  if (!oscOnTpc) {
156  LOG_ERROR << "CalculateWafersPosition: No relevant entry found in 'Geometry/sst/oscOnTpc' table" << endm;
157  return 0;
158  }
159 
160  St_Survey *sstLadderOnSst = (St_Survey *) GetDataBase("Geometry/sst/sstLadderOnSst");// ladders in the SST sector coordinate systems
161 
162  if (!sstLadderOnSst) {
163  LOG_ERROR << "CalculateWafersPosition: No relevant entry found in 'Geometry/sst/sstLadderOnSst' table" << endm;
164  return 0;
165  }
166 
167  St_Survey *sstSensorOnLadder = (St_Survey *) GetDataBase("Geometry/sst/sstSensorOnLadder"); // wafers in the SST ladder coordinate systems
168 
169  if (!sstSensorOnLadder) {
170  LOG_ERROR << "CalculateWafersPosition: No relevant entry found in 'Geometry/sst/sstSensorOnLadder' table" << endm;
171  return 0;
172  }
173 
174  Survey_st *oscOnTpc_st = oscOnTpc->GetTable();
175  Survey_st *sstOnOsc_st = sstOnOsc->GetTable();
176  Survey_st *ladderOnSst = sstLadderOnSst->GetTable();
177  Survey_st *sensorOnLadder = sstSensorOnLadder->GetTable();
178 
179  Int_t NoOsc = sstOnOsc->GetNRows();
180  Int_t NoLadders = sstLadderOnSst->GetNRows();
181  Int_t NoSensors = sstSensorOnLadder->GetNRows();
182 
183  LOG_DEBUG << "CalculateWafersPosition:\n"
184  << " Number of Osc: " << NoOsc << "\n"
185  << " Number of Ladders: " << NoLadders << "\n"
186  << " Number of Sensors: " << NoSensors << endm;
187 
188  St_sstWafersPosition *sstwafer = new St_sstWafersPosition("sstWafersPosition", NoSensors);
189  AddConst(sstwafer);
190  Int_t num = 0;
191  sstWafersPosition_st *row = new sstWafersPosition_st();
192  memset(row,0, 4*960*sizeof(Double_t));
193 
194  OT.SetRotation(&oscOnTpc_st->r00);
195  OT.SetTranslation(&oscOnTpc_st->t0);
196 
197  for (Int_t i = 0; i < NoSensors; i++, sensorOnLadder++) {
198  Int_t Id = sensorOnLadder->Id;
199 
200  TGeoHMatrix *comb = (TGeoHMatrix *) fRotList->FindObject(Form("R%04i", Id));
201 
202  if (comb) continue;
203 
204  comb = new TGeoHMatrix(Form("R%04i", Id));
205  Int_t layer = Id / 1000;
206 
207  if (layer > 7) layer = 7;
208 
209  Int_t ladder = Id % 100;
210  TGeoHMatrix WLL;
211  WLL.SetRotation(&sensorOnLadder->r00);
212  WLL.SetTranslation(&sensorOnLadder->t0);
213 
214  if (Debug() >= 2) {
215  LOG_DEBUG << "CalculateWafersPosition: WL" << endm;
216  WLL.Print();
217  }
218 
219  TGeoHMatrix *WL = (TGeoHMatrix *) fRotList->FindObject(Form("WL%04i", Id));
220 
221  if (! WL) {
222  WL = new TGeoHMatrix(Form("WL%04i", Id));
223  Double_t *r = WLL.GetRotationMatrix();
224  Double_t rot[9] = {r[0], r[1], r[2],
225  r[3], r[4], r[5],
226  r[6], r[7], r[8]
227  };
228  WL->SetRotation(rot);
229  WL->SetTranslation(WLL.GetTranslation());
230  fRotList->Add(WL);
231  }
232 
233  ladderOnSst = sstLadderOnSst->GetTable();
234  Int_t Ladder = 0;
235  Int_t OSC = 0;
236 
237  for (Int_t l = 0; l < NoLadders; l++, ladderOnSst++) {
238  Ladder = ladderOnSst->Id % 100;
239 
240  if (Ladder == ladder) {
241  OSC = ladderOnSst->Id / 100;
242  LS.SetRotation(&ladderOnSst->r00);
243  LS.SetTranslation(&ladderOnSst->t0);
244 
245  if (Debug() >= 2) {
246  LOG_DEBUG << "CalculateWafersPosition: LS" << endm;
247  LS.Print();
248  }
249 
250  break;
251  }
252  }
253 
254  if (OSC != 1) {
255  LOG_WARN << "CalculateWafersPosition: OSC has not been defined. Skipping to next sensor..." << endm;
256  continue;
257  }
258 
259  sstOnOsc_st = sstOnOsc->GetTable();
260  Int_t osc = 0;
261 
262  for (Int_t s = 0; s < NoOsc; s++, sstOnOsc_st++) {
263  if (sstOnOsc_st->Id != OSC) continue;
264 
265  osc = OSC;
266  SO.SetRotation(&sstOnOsc_st->r00);
267  SO.SetTranslation(&sstOnOsc_st->t0);
268  break;
269  }
270 
271  SG = OT * SO;
272 
273  if (!osc) {
274  LOG_WARN << "CalculateWafersPosition: OSC " << OSC << " has not been found. Skipping to next sensor..." << endm;
275  continue;
276  }
277 
278  if (Debug() >= 2) {
279  LOG_DEBUG << "CalculateWafersPosition: Tpc2Global" << endm;
280  Tpc2Global.Print();
281  }
282 
283  WG = Tpc2Global * SG * LS * WLL;
284 
285  if (Debug() >= 2) {
286  LOG_DEBUG << "CalculateWafersPosition: WG" << endm;
287  WG.Print();
288  }
289 
290  Double_t *r = WG.GetRotationMatrix();
291  Int_t index = num*3;
292  row->driftDirection[index+0] = r[0];
293  row->driftDirection[index+1] = r[3];
294  row->driftDirection[index+2] = r[6];
295 
296  row->normalDirection[index+0] = r[1];
297  row->normalDirection[index+1] = r[4];
298  row->normalDirection[index+2] = r[7];
299 
300  row->transverseDirection[index+0] = r[2];
301  row->transverseDirection[index+1] = r[5];
302  row->transverseDirection[index+2] = r[8];
303 
304  Double_t *wgtr = WG.GetTranslation();
305  row->centerPosition[index+0] = wgtr[0];
306  row->centerPosition[index+1] = wgtr[1];
307  row->centerPosition[index+2] = wgtr[2];
308 
309  comb->SetRotation(WG.GetRotationMatrix());
310  comb->SetTranslation(WG.GetTranslation());
311 
312  fRotList->Add(comb);
313  num++;
314 
315  if (Debug() >= 1) {
316  LOG_DEBUG << "CalculateWafersPosition: R" << endm;
317  comb->Print();
318  }
319  }
320  sstwafer->AddAt(row);
321  delete row;
322  return sstwafer;
323 }
324 //_____________________________________________________________________________
335 const TGeoHMatrix *StSstDbMaker::getHMatrixSensorOnGlobal(int ladder, int sensor)
336 {
337  if (ladder < 1 || ladder > kSstNumLadders || sensor < 1 || sensor > kSstNumSensorsPerLadder)
338  return 0;
339 
340  int id = 7000 + 100*sensor + ladder;
341  return fRotList ? (TGeoHMatrix *) fRotList->FindObject(Form("R%04i", id)) : 0;
342 }
343 //_____________________________________________________________________________
344 Int_t StSstDbMaker::maskChip(Int_t side, Int_t ladder, Int_t wafer, Int_t chip) const
345 {
346  map<unsigned int,short>::const_iterator got;
347  got = mMapMaskChips.find(side*1920 + ladder*96 + wafer*6 + chip);
348  if ( got == mMapMaskChips.end() ) {
349  return 0;
350  }
351  else {
352  return 1;
353  }
354 }
355 //_____________________________________________________________________________
356 void StSstDbMaker::setMaskChips(sstMaskChip_st *maskChipTable)
357 {
358  for(Int_t i=0; i<3840; ++i){
359  if(maskChipTable[0].chip[i]>0){
360  mMapMaskChips.insert ( std::pair<unsigned long, short>(i,maskChipTable[0].chip[i]) );
361  LOG_DEBUG <<" found chip to mask : adress : " << i << endm;
362  }
363  //else break;
364  }
365 }
366 
Int_t m_Mode
counters
Definition: StMaker.h:81
Definition: Stypes.h:40
static const TGeoHMatrix * getHMatrixSensorOnGlobal(int ladder, int sensor)
virtual Int_t Make()
Definition: Stypes.h:44
Definition: Stypes.h:41