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"
56 #include "StTpcDb/StTpcDb.h"
58 THashList *StSsdDbMaker::fRotList = 0;
63 StMaker(name), mySsd(0), m_dimensions(0), m_positions(0), m_config(0), m_ctrl(0)
65 gStSsdDbMaker =
this; mode = 0;
68 StSsdDbMaker::~StSsdDbMaker() {SafeDelete(mySsd); gStSsdDbMaker = 0;}
70 Int_t StSsdDbMaker::Init()
72 LOG_DEBUG <<
"Init - Start - " << endm;
76 LOG_INFO <<
"Init setting WafersPositions to simulation" << endm;
78 SetFlavor(
"sim",
"SsdOnGlobal");
79 SetFlavor(
"sim",
"SsdSectorsOnGlobal");
80 SetFlavor(
"sim",
"SsdLaddersOnSectors");
81 SetFlavor(
"sim",
"SsdWafersOnLadders");
85 LOG_DEBUG <<
"StSsdDbMaker::Init() - Done - " << endm;
86 return StMaker::Init();
89 Int_t StSsdDbMaker::InitRun(Int_t runNumber)
92 m_ctrl = ((St_slsCtrl *) GetInputDB(
"Geometry/ssd/slsCtrl"))->GetTable();
95 gMessMgr->Error() <<
"No access to control parameters" << endm;
99 m_dimensions = (St_ssdDimensions *) GetInputDB(
"Geometry/ssd/ssdDimensions");
100 m_positions = CalculateWafersPosition();
102 if ((!m_dimensions) || (!m_positions)) {
103 gMessMgr->Error() <<
"No access to geometry parameters" << endm;
107 LOG_DEBUG <<
" geometry loaded " << endm;
108 St_ssdConfiguration *configTable = (St_ssdConfiguration *) GetInputDB(
"Geometry/ssd/ssdConfiguration");
111 gMessMgr->Error() <<
"InitRun : No access to ssdConfiguration database" << endm;
116 m_config = (ssdConfiguration_st *) configTable->GetTable() ;
117 ssdDimensions_st *dimensions = m_dimensions->GetTable();
120 if (Debug()) mySsd->SetDebug(Debug());
122 mySsd->initLadders(m_positions);
123 LOG_DEBUG <<
" StSsdBarrel built " << endm;
129 LOG_DEBUG <<
"Make" << endm;
135 void StSsdDbMaker::Clear(
const char *)
137 LOG_DEBUG <<
"Clear" << endm;
144 LOG_DEBUG <<
"Finish" << endm;
148 St_ssdWafersPosition *StSsdDbMaker::CalculateWafersPosition()
150 SafeDelete(fRotList);
151 fRotList =
new THashList(100, 0);
152 fRotList->SetOwner(kFALSE);
154 St_ssdWafersPosition *ssdWafersPosition = (St_ssdWafersPosition *) GetDataBase(
"Geometry/ssd/ssdWafersPosition");
156 if (! ssdWafersPosition) {cout <<
"ssdWafersPosition has not been found" << endl;
return 0;}
158 ssdWafersPosition_st *WafersPosition = ssdWafersPosition->GetTable();
159 Int_t NoWafers = ssdWafersPosition->GetNRows();
161 St_Survey *SsdOnGlobal = (St_Survey *) GetDataBase(
"Geometry/ssd/SsdOnGlobal");
163 if (! SsdOnGlobal) {cout <<
"SsdOnGlobal has not been found" << endl;
return 0;}
165 TGeoHMatrix GL, LS, SG, LA, WG;
166 Survey_st *OnGlobal = SsdOnGlobal->GetTable();
167 GL.SetRotation(&OnGlobal->r00);
168 GL.SetTranslation(&OnGlobal->t0);
170 const TGeoHMatrix &Tpc2Global = gStTpcDb->Tpc2GlobalMatrix();
172 St_Survey *SsdSectorsOnGlobal = (St_Survey *) GetDataBase(
"Geometry/ssd/SsdSectorsOnGlobal");
174 if (! SsdSectorsOnGlobal) {cout <<
"SsdSectorsOnGlobal has not been found" << endl;
return 0;}
176 St_Survey *SsdLaddersOnSectors = (St_Survey *) GetDataBase(
"Geometry/ssd/SsdLaddersOnSectors");
178 if (! SsdLaddersOnSectors) {cout <<
"SsdLaddersOnSectors has not been found" << endl;
return 0;}
180 St_Survey *SsdWafersOnLadders = (St_Survey *) GetDataBase(
"Geometry/ssd/SsdWafersOnLadders");
182 if (! SsdWafersOnLadders) {cout <<
"SsdWafersOnLadders has not been found" << endl;
return 0;}
184 Survey_st *SectorsOnGlobal = SsdSectorsOnGlobal->GetTable();
185 Survey_st *LaddersOnSectors = SsdLaddersOnSectors->GetTable();
186 Survey_st *WafersOnLadders = SsdWafersOnLadders->GetTable();
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);
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));
211 TGeoHMatrix *comb = (TGeoHMatrix *) fRotList->FindObject(Form(
"R%04i", Id));
215 comb =
new TGeoHMatrix(Form(
"R%04i", Id));
216 Int_t layer = Id / 1000;
218 if (layer > 7) layer = 7;
220 Int_t ladder = Id % 100;
222 WLL.SetRotation(&WafersOnLadders->r00);
223 WLL.SetTranslation(&WafersOnLadders->t0);
224 TGeoHMatrix *WL = (TGeoHMatrix *) fRotList->FindObject(Form(
"WL%04i", Id));
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],
234 WL->SetRotation(rot);
235 WL->SetTranslation(WLL.GetTranslation());
239 LaddersOnSectors = SsdLaddersOnSectors->GetTable();
243 for (Int_t l = 0; l < NoLadders; l++, LaddersOnSectors++) {
245 Ladder = LaddersOnSectors->Id % 100;
247 if (Ladder == ladder) {
248 Sector = LaddersOnSectors->Id / 100;
249 LS.SetRotation(&LaddersOnSectors->r00);
250 LS.SetTranslation(&LaddersOnSectors->t0);
256 if (Sector <= 0 || Sector > 4) {cout <<
"Sector has not been defined" << endl;
continue;}
258 SectorsOnGlobal = SsdSectorsOnGlobal->GetTable();
261 for (Int_t s = 0; s < NoSectors; s++, SectorsOnGlobal++) {
263 if (SectorsOnGlobal->Id != Sector)
continue;
266 SG.SetRotation(&SectorsOnGlobal->r00);
267 SG.SetTranslation(&SectorsOnGlobal->t0);
271 if (! sector) {cout <<
"Sector\t" << Sector <<
" has not been found" << endl;
continue;}
276 cout <<
"Tpc2Global "; Tpc2Global.Print();
277 cout <<
"GL "; GL.Print();
278 TGeoHMatrix test = Tpc2Global * GL; cout <<
"test "; test.Print();
281 WG = Tpc2Global * GL * SG * LS * WLL;
287 row.num_chip = (num - 1) % 16 + 1;
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];
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);
300 if (c.Dot(n) < 0) c *= -1;
302 d.GetXYZ(row.driftDirection);
303 t.GetXYZ(row.transverseDirection);
304 c.GetXYZ(row.normalDirection);
306 Double_t *wgtr = WG.GetTranslation();
307 memcpy(row.centerPosition, wgtr, 3 *
sizeof(Double_t));
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]
313 Double_t tr[3] = {row.centerPosition[0],
314 row.centerPosition[1],
315 row.centerPosition[2]
317 comb->SetRotation(rot);
318 comb->SetTranslation(tr);
320 ssdwafer->AddAt(&row);
virtual void Clear(Option_t *option="")
User defined functions.