StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StSsdDbMaker.cxx
1 // $Id: StSsdDbMaker.cxx,v 1.17 2014/12/05 21:59:25 smirnovd Exp $
2 //
3 // $Log: StSsdDbMaker.cxx,v $
4 // Revision 1.17 2014/12/05 21:59:25 smirnovd
5 // Fixed style with astyle -s3 -p -H -A3 -k3 -O -o -y -Y -f
6 //
7 // Revision 1.16 2010/09/01 21:04:06 fisyak
8 // Disable sim flavor, now sim parameters is coming via DB associated with simulation time stamp
9 //
10 // Revision 1.15 2008/08/12 22:45:47 bouchet
11 // use of SsdLaddersOnSectors,SsdOnGlobal,SsdSectorsOnGlobal,SsdWafersOnLadders tables to calculate ssdWafersPositions;add Get methods to access the tables
12 //
13 // Revision 1.14 2008/08/01 22:07:31 bouchet
14 // fix bug for geometry : simulation takes ideal geometry
15 //
16 // Revision 1.13 2007/09/25 13:36:51 bouchet
17 // add m_Mode to constructor
18 //
19 // Revision 1.12 2007/07/12 20:01:15 fisyak
20 // Don't read whole database but only the table requested
21 //
22 // Revision 1.11 2007/03/21 17:17:16 fisyak
23 // use TGeoHMatrix for coordinate transformation, eliminate ssdWafersPostion
24 //
25 // Revision 1.10 2007/02/18 13:32:35 bouchet
26 // Changes for the new Logger
27 //
28 // Revision 1.9 2006/10/16 19:53:24 fisyak
29 // Adjust for new Ssd chain
30 //
31 // Revision 1.8 2006/09/18 16:40:14 fisyak
32 // Add sim flag for ssdWafersPosition
33 //
34 // Revision 1.7 2005/06/03 21:30:41 perev
35 // Move configuration Init()==>InitRun()
36 //
37 // Revision 1.6 2005/05/10 12:48:06 reinnart
38 // The new StSsdDbMaker without DirectDataBase Access
39 //
40 
41 /***************************************************************************
42  * Author: christelle roy
43  * Description: SSD DB access Maker
44  **************************************************************************/
45 
46 #include "StSsdDbMaker.h"
47 #include "TDataSetIter.h"
48 #include "StMessMgr.h"
49 #include "tables/St_ssdWafersPosition_Table.h"
50 #include "tables/St_ssdConfiguration_Table.h"
51 #include "tables/St_ssdDimensions_Table.h"
52 #include "tables/St_slsCtrl_Table.h"
53 #include "tables/St_Survey_Table.h"
54 #include "TMath.h"
55 #include "TVector3.h"
56 #include "StTpcDb/StTpcDb.h"
57 StSsdDbMaker *gStSsdDbMaker = NULL;
58 THashList *StSsdDbMaker::fRotList = 0;
59 
60 ClassImp(StSsdDbMaker)
61 //_____________________________________________________________________________
62 StSsdDbMaker::StSsdDbMaker(const char *name) :
63  StMaker(name), mySsd(0), m_dimensions(0), m_positions(0), m_config(0), m_ctrl(0)
64 {
65  gStSsdDbMaker = this; mode = 0;
66 }
67 //_____________________________________________________________________________
68 StSsdDbMaker::~StSsdDbMaker() {SafeDelete(mySsd); gStSsdDbMaker = 0;}
69 //_____________________________________________________________________________
70 Int_t StSsdDbMaker::Init()
71 {
72  LOG_DEBUG << "Init - Start - " << endm;
73 #if 0
74 
75  if ( m_Mode == 1) {
76  LOG_INFO << "Init setting WafersPositions to simulation" << endm;
77  //SetFlavor("sim","ssdWafersPosition");
78  SetFlavor("sim", "SsdOnGlobal");
79  SetFlavor("sim", "SsdSectorsOnGlobal");
80  SetFlavor("sim", "SsdLaddersOnSectors");
81  SetFlavor("sim", "SsdWafersOnLadders");
82  }
83 
84 #endif
85  LOG_DEBUG << "StSsdDbMaker::Init() - Done - " << endm;
86  return StMaker::Init();
87 }
88 //_____________________________________________________________________________
89 Int_t StSsdDbMaker::InitRun(Int_t runNumber)
90 {
91  mode = m_Mode;
92  m_ctrl = ((St_slsCtrl *) GetInputDB("Geometry/ssd/slsCtrl"))->GetTable();
93 
94  if (!m_ctrl) {
95  gMessMgr->Error() << "No access to control parameters" << endm;
96  return kStFatal;
97  }
98 
99  m_dimensions = (St_ssdDimensions *) GetInputDB("Geometry/ssd/ssdDimensions");
100  m_positions = CalculateWafersPosition();
101 
102  if ((!m_dimensions) || (!m_positions)) {
103  gMessMgr->Error() << "No access to geometry parameters" << endm;
104  return kStFatal;
105  }
106 
107  LOG_DEBUG << " geometry loaded " << endm;
108  St_ssdConfiguration *configTable = (St_ssdConfiguration *) GetInputDB("Geometry/ssd/ssdConfiguration");
109 
110  if (!configTable) {
111  gMessMgr->Error() << "InitRun : No access to ssdConfiguration database" << endm;
112  return kStFatal;
113  }
114 
115  //mConfig = new StSsdConfig();
116  m_config = (ssdConfiguration_st *) configTable->GetTable() ;
117  ssdDimensions_st *dimensions = m_dimensions->GetTable();
118  mySsd = new StSsdBarrel(dimensions, m_config);
119 
120  if (Debug()) mySsd->SetDebug(Debug());
121 
122  mySsd->initLadders(m_positions);
123  LOG_DEBUG << " StSsdBarrel built " << endm;
124  return kStOK;
125 }
126 //_____________________________________________________________________________
128 {
129  LOG_DEBUG << "Make" << endm;
130 
131  return kStOK;
132 }
133 
134 //_____________________________________________________________________________
135 void StSsdDbMaker::Clear(const char *)
136 {
137  LOG_DEBUG << "Clear" << endm;
138  StMaker::Clear();
139 }
140 
141 //_____________________________________________________________________________
143 {
144  LOG_DEBUG << "Finish" << endm;
145  return kStOK;
146 }
147 //_____________________________________________________________________________
148 St_ssdWafersPosition *StSsdDbMaker::CalculateWafersPosition()
149 {
150  SafeDelete(fRotList);
151  fRotList = new THashList(100, 0);
152  fRotList->SetOwner(kFALSE);
153 #if 0
154  St_ssdWafersPosition *ssdWafersPosition = (St_ssdWafersPosition *) GetDataBase("Geometry/ssd/ssdWafersPosition");
155 
156  if (! ssdWafersPosition) {cout << "ssdWafersPosition has not been found" << endl; return 0;}
157 
158  ssdWafersPosition_st *WafersPosition = ssdWafersPosition->GetTable();
159  Int_t NoWafers = ssdWafersPosition->GetNRows();
160 #endif
161  St_Survey *SsdOnGlobal = (St_Survey *) GetDataBase("Geometry/ssd/SsdOnGlobal");
162 
163  if (! SsdOnGlobal) {cout << "SsdOnGlobal has not been found" << endl; return 0;}
164 
165  TGeoHMatrix GL, LS, SG, LA, WG;
166  Survey_st *OnGlobal = SsdOnGlobal->GetTable(); // SSD and SVT as whole
167  GL.SetRotation(&OnGlobal->r00);
168  GL.SetTranslation(&OnGlobal->t0);
169  assert(gStTpcDb);
170  const TGeoHMatrix &Tpc2Global = gStTpcDb->Tpc2GlobalMatrix();
171  // SSD
172  St_Survey *SsdSectorsOnGlobal = (St_Survey *) GetDataBase("Geometry/ssd/SsdSectorsOnGlobal");
173 
174  if (! SsdSectorsOnGlobal) {cout << "SsdSectorsOnGlobal has not been found" << endl; return 0;}
175 
176  St_Survey *SsdLaddersOnSectors = (St_Survey *) GetDataBase("Geometry/ssd/SsdLaddersOnSectors");// ladders in the SSD sector coordinate systems
177 
178  if (! SsdLaddersOnSectors) {cout << "SsdLaddersOnSectors has not been found" << endl; return 0;}
179 
180  St_Survey *SsdWafersOnLadders = (St_Survey *) GetDataBase("Geometry/ssd/SsdWafersOnLadders"); // wafers in the SSD ladder coordinate systems
181 
182  if (! SsdWafersOnLadders) {cout << "SsdWafersOnLadders has not been found" << endl; return 0;}
183 
184  Survey_st *SectorsOnGlobal = SsdSectorsOnGlobal->GetTable(); // sectors in the SSD barrel coordinate system
185  Survey_st *LaddersOnSectors = SsdLaddersOnSectors->GetTable();// ladders in the SSD sector coordinate systems
186  Survey_st *WafersOnLadders = SsdWafersOnLadders->GetTable(); // wafers in the SSD ladder coordinate systems
187  Int_t NoSectors = SsdSectorsOnGlobal->GetNRows();
188  Int_t NoLadders = SsdLaddersOnSectors->GetNRows();
189  Int_t NoWafers = SsdWafersOnLadders->GetNRows();
190  St_ssdWafersPosition *ssdwafer = new St_ssdWafersPosition("ssdWafersPosition", NoWafers);
191  AddConst(ssdwafer);
192  Int_t num = 0;
193 
194  //#if 1
195  for (Int_t i = 0; i < NoWafers; i++, WafersOnLadders++) {
196  Int_t Id = WafersOnLadders->Id;
197  ssdWafersPosition_st row;
198  memset (&row, 0, sizeof(ssdWafersPosition_st));
199  // #else
200  // for (Int_t w = 0; w < NoWafers; w++, WafersPosition++) {
201  // ssdWafersPosition_st row = *WafersPosition;
202  // WafersOnLadders = SsdWafersOnLadders->GetTable();
203  // Int_t Id = 0;
204  // for (Int_t i = 0; i < NoWafers; i++,WafersOnLadders++) {
205  // if (WafersOnLadders->Id != row.id) continue;
206  // Id = row.id;
207  // break;
208  // }
209  // if (! Id ) {cout << "Wafer Id\t" << Id << " has not been found" << endl; continue;}
210  //#endif
211  TGeoHMatrix *comb = (TGeoHMatrix *) fRotList->FindObject(Form("R%04i", Id));
212 
213  if (comb) continue;
214 
215  comb = new TGeoHMatrix(Form("R%04i", Id));
216  Int_t layer = Id / 1000;
217 
218  if (layer > 7) layer = 7;
219 
220  Int_t ladder = Id % 100;
221  TGeoHMatrix WLL;
222  WLL.SetRotation(&WafersOnLadders->r00);
223  WLL.SetTranslation(&WafersOnLadders->t0); //cout << "WL\t"; WL.Print();
224  TGeoHMatrix *WL = (TGeoHMatrix *) fRotList->FindObject(Form("WL%04i", Id));
225 
226  if (! WL) {
227  WL = new TGeoHMatrix(Form("WL%04i", Id));
228  Double_t *r = WLL.GetRotationMatrix();
229  Double_t rot[9] = {r[0], r[2], r[1],
230  r[3], r[5], r[4],
231  r[6], r[8], r[7]
232  };
233  // {7101, 1.000000,0, 0.000052,0, 1,0,-0.000052,0, 1.000000,-0.000600,0,-32.625900,
234  WL->SetRotation(rot);
235  WL->SetTranslation(WLL.GetTranslation());
236  fRotList->Add(WL);
237  }
238 
239  LaddersOnSectors = SsdLaddersOnSectors->GetTable();
240  Int_t Ladder = 0;
241  Int_t Sector = 0;
242 
243  for (Int_t l = 0; l < NoLadders; l++, LaddersOnSectors++) {
244  //cout << "LaddersOnSectors Id\t" << LaddersOnSectors->Id << endl;
245  Ladder = LaddersOnSectors->Id % 100;
246 
247  if (Ladder == ladder) {
248  Sector = LaddersOnSectors->Id / 100;
249  LS.SetRotation(&LaddersOnSectors->r00);
250  LS.SetTranslation(&LaddersOnSectors->t0);
251  //cout << "LS\t"; LS.Print();
252  break;
253  }
254  }
255 
256  if (Sector <= 0 || Sector > 4) {cout << "Sector has not been defined" << endl; continue;}
257 
258  SectorsOnGlobal = SsdSectorsOnGlobal->GetTable();
259  Int_t sector = 0;
260 
261  for (Int_t s = 0; s < NoSectors; s++, SectorsOnGlobal++) {
262  //cout << "SectorsOnGlobal Id\t" << SectorsOnGlobal->Id << endl;
263  if (SectorsOnGlobal->Id != Sector) continue;
264 
265  sector = Sector;
266  SG.SetRotation(&SectorsOnGlobal->r00);
267  SG.SetTranslation(&SectorsOnGlobal->t0); //cout << "Sector\t" << Sector << "\tSG\t"; SG.Print();
268  break;
269  }
270 
271  if (! sector) {cout << "Sector\t" << Sector << " has not been found" << endl; continue;}
272 
273  // WG = SG * LS * WL * LA; //cout << "WG\t"; WG.Print();
274  // WG = SG * LS * WL * LA = SG * ( LS * WL * LA * WL**-1 ) *WL
275  if (Debug()) {
276  cout << "Tpc2Global "; Tpc2Global.Print();
277  cout << "GL "; GL.Print();
278  TGeoHMatrix test = Tpc2Global * GL; cout << "test "; test.Print();
279  }
280 
281  WG = Tpc2Global * GL * SG * LS * WLL; //cout << "WG\t"; WG.Print();
282  row.id = Id;
283  row.id_shape = 2;
284  row.ladder = ladder;
285  row.layer = layer;
286  num++;
287  row.num_chip = (num - 1) % 16 + 1;
288  // TGeoHMatrix WGInv = WG.Inverse();
289  // Double_t *wgrot = WGInv.GetRotationMatrix();
290  Double_t *r = WG.GetRotationMatrix();
291  row.driftDirection[0] = r[0]; row.normalDirection[0] = r[1]; row.transverseDirection[0] = r[2];
292  row.driftDirection[1] = r[3]; row.normalDirection[1] = r[4]; row.transverseDirection[1] = r[5];
293  row.driftDirection[2] = r[6]; row.normalDirection[2] = r[7]; row.transverseDirection[2] = r[8];
294  Double_t norm;
295  TVector3 d(row.driftDirection); norm = 1 / d.Mag(); d *= norm;
296  TVector3 t(row.transverseDirection); norm = 1 / t.Mag(); t *= norm;
297  TVector3 n(row.normalDirection);
298  TVector3 c = d.Cross(t);
299 
300  if (c.Dot(n) < 0) c *= -1;
301 
302  d.GetXYZ(row.driftDirection);
303  t.GetXYZ(row.transverseDirection);
304  c.GetXYZ(row.normalDirection);
305 
306  Double_t *wgtr = WG.GetTranslation();
307  memcpy(row.centerPosition, wgtr, 3 * sizeof(Double_t));
308  Double_t rot[9] = {
309  row.driftDirection[0], row.transverseDirection[0], row.normalDirection[0],
310  row.driftDirection[1], row.transverseDirection[1], row.normalDirection[1],
311  row.driftDirection[2], row.transverseDirection[2], row.normalDirection[2]
312  };
313  Double_t tr[3] = {row.centerPosition[0],
314  row.centerPosition[1],
315  row.centerPosition[2]
316  };
317  comb->SetRotation(rot);
318  comb->SetTranslation(tr);
319  fRotList->Add(comb);
320  ssdwafer->AddAt(&row);
321 
322  }
323 
324  return ssdwafer;
325 }
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 Make()
virtual Int_t Finish()
Definition: Stypes.h:40