00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #include "StSsdDbMaker.h"
00044 #include "TDataSetIter.h"
00045 #include "StMessMgr.h"
00046 #include "tables/St_ssdWafersPosition_Table.h"
00047 #include "tables/St_ssdConfiguration_Table.h"
00048 #include "tables/St_ssdDimensions_Table.h"
00049 #include "tables/St_slsCtrl_Table.h"
00050 #include "tables/St_Survey_Table.h"
00051 #include "TMath.h"
00052 #include "TVector3.h"
00053 #include "StTpcDb/StTpcDb.h"
00054 StSsdDbMaker* gStSsdDbMaker=NULL;
00055 THashList *StSsdDbMaker::fRotList = 0;
00056
00057 ClassImp(StSsdDbMaker)
00058
00059 StSsdDbMaker::StSsdDbMaker(const char *name) :
00060 StMaker(name), mySsd(0),m_dimensions(0),m_positions(0),m_config(0),m_ctrl(0){
00061 gStSsdDbMaker = this;mode=0;
00062 }
00063
00064 StSsdDbMaker::~StSsdDbMaker() {SafeDelete(mySsd); gStSsdDbMaker = 0;}
00065
00066 Int_t StSsdDbMaker::Init()
00067 {
00068 LOG_DEBUG << "Init - Start - " << endm;
00069 #if 0
00070 if( m_Mode == 1) {
00071 LOG_INFO << "Init setting WafersPositions to simulation" << endm;
00072
00073 SetFlavor("sim","SsdOnGlobal");
00074 SetFlavor("sim","SsdSectorsOnGlobal");
00075 SetFlavor("sim","SsdLaddersOnSectors");
00076 SetFlavor("sim","SsdWafersOnLadders");
00077 }
00078 #endif
00079 LOG_DEBUG << "StSsdDbMaker::Init() - Done - "<<endm;
00080 return StMaker::Init();
00081 }
00082
00083 Int_t StSsdDbMaker::InitRun(Int_t runNumber) {
00084 mode = m_Mode;
00085 m_ctrl = ((St_slsCtrl *) GetInputDB("Geometry/ssd/slsCtrl"))->GetTable();
00086 if (!m_ctrl) {
00087 gMessMgr->Error() << "No access to control parameters" << endm;
00088 return kStFatal;
00089 }
00090 m_dimensions = (St_ssdDimensions *) GetInputDB("Geometry/ssd/ssdDimensions");
00091 m_positions = CalculateWafersPosition();
00092
00093 if ((!m_dimensions)||(!m_positions)) {
00094 gMessMgr->Error() << "No access to geometry parameters" << endm;
00095 return kStFatal;
00096 }
00097 LOG_DEBUG << " geometry loaded " << endm;
00098 St_ssdConfiguration* configTable = (St_ssdConfiguration*) GetInputDB("Geometry/ssd/ssdConfiguration");
00099 if (!configTable) {
00100 gMessMgr->Error() << "InitRun : No access to ssdConfiguration database" << endm;
00101 return kStFatal;
00102 }
00103
00104 m_config = (ssdConfiguration_st*) configTable->GetTable() ;
00105 ssdDimensions_st *dimensions = m_dimensions->GetTable();
00106 mySsd = new StSsdBarrel(dimensions, m_config);
00107 if (Debug()) mySsd->SetDebug(Debug());
00108 mySsd->initLadders(m_positions);
00109 LOG_DEBUG << " StSsdBarrel built " << endm;
00110 return kStOK;
00111 }
00112
00113 Int_t StSsdDbMaker::Make()
00114 {
00115 LOG_DEBUG << "Make" << endm;
00116
00117 return kStOK;
00118 }
00119
00120
00121 void StSsdDbMaker::Clear(const char*)
00122 {
00123 LOG_DEBUG << "Clear" << endm;
00124 StMaker::Clear();
00125 }
00126
00127
00128 Int_t StSsdDbMaker::Finish()
00129 {
00130 LOG_DEBUG << "Finish" << endm;
00131 return kStOK;
00132 }
00133
00134 St_ssdWafersPosition *StSsdDbMaker::CalculateWafersPosition(){
00135 SafeDelete(fRotList);
00136 fRotList = new THashList(100,0);
00137 fRotList->SetOwner(kFALSE);
00138 #if 0
00139 St_ssdWafersPosition *ssdWafersPosition = (St_ssdWafersPosition *) GetDataBase("Geometry/ssd/ssdWafersPosition");
00140 if (! ssdWafersPosition) {cout << "ssdWafersPosition has not been found" << endl; return 0;}
00141 ssdWafersPosition_st *WafersPosition = ssdWafersPosition->GetTable();
00142 Int_t NoWafers = ssdWafersPosition->GetNRows();
00143 #endif
00144 St_Survey *SsdOnGlobal = (St_Survey *) GetDataBase("Geometry/ssd/SsdOnGlobal");
00145 if (! SsdOnGlobal) {cout << "SsdOnGlobal has not been found" << endl; return 0;}
00146 TGeoHMatrix GL, LS,SG,LA,WG;
00147 Survey_st *OnGlobal = SsdOnGlobal->GetTable();
00148 GL.SetRotation(&OnGlobal->r00);
00149 GL.SetTranslation(&OnGlobal->t0);
00150 assert(gStTpcDb);
00151 const TGeoHMatrix &Tpc2Global = gStTpcDb->Tpc2GlobalMatrix();
00152
00153 St_Survey *SsdSectorsOnGlobal = (St_Survey *) GetDataBase("Geometry/ssd/SsdSectorsOnGlobal");
00154 if (! SsdSectorsOnGlobal) {cout << "SsdSectorsOnGlobal has not been found" << endl; return 0;}
00155 St_Survey *SsdLaddersOnSectors = (St_Survey *) GetDataBase("Geometry/ssd/SsdLaddersOnSectors");
00156 if (! SsdLaddersOnSectors) {cout << "SsdLaddersOnSectors has not been found" << endl; return 0;}
00157 St_Survey *SsdWafersOnLadders = (St_Survey *) GetDataBase("Geometry/ssd/SsdWafersOnLadders");
00158 if (! SsdWafersOnLadders) {cout << "SsdWafersOnLadders has not been found" << endl; return 0;}
00159 Survey_st *SectorsOnGlobal = SsdSectorsOnGlobal->GetTable();
00160 Survey_st *LaddersOnSectors = SsdLaddersOnSectors->GetTable();
00161 Survey_st *WafersOnLadders = SsdWafersOnLadders->GetTable();
00162 Int_t NoSectors = SsdSectorsOnGlobal->GetNRows();
00163 Int_t NoLadders = SsdLaddersOnSectors->GetNRows();
00164 Int_t NoWafers = SsdWafersOnLadders->GetNRows();
00165 St_ssdWafersPosition *ssdwafer = new St_ssdWafersPosition("ssdWafersPosition",NoWafers);
00166 AddConst(ssdwafer);
00167 Int_t num = 0;
00168
00169 for (Int_t i = 0; i < NoWafers; i++,WafersOnLadders++) {
00170 Int_t Id = WafersOnLadders->Id;
00171 ssdWafersPosition_st row;
00172 memset (&row, 0, sizeof(ssdWafersPosition_st));
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 TGeoHMatrix *comb = (TGeoHMatrix *) fRotList->FindObject(Form("R%04i",Id));
00186 if (comb) continue;
00187 comb = new TGeoHMatrix(Form("R%04i",Id));
00188 Int_t layer = Id/1000;
00189 if (layer > 7) layer = 7;
00190 Int_t ladder = Id%100;
00191 TGeoHMatrix WLL;
00192 WLL.SetRotation(&WafersOnLadders->r00);
00193 WLL.SetTranslation(&WafersOnLadders->t0);
00194 TGeoHMatrix *WL = (TGeoHMatrix *) fRotList->FindObject(Form("WL%04i",Id));
00195 if (! WL) {
00196 WL = new TGeoHMatrix(Form("WL%04i",Id));
00197 Double_t *r = WLL.GetRotationMatrix();
00198 Double_t rot[9] = {r[0], r[2], r[1],
00199 r[3], r[5], r[4],
00200 r[6], r[8], r[7]};
00201
00202 WL->SetRotation(rot);
00203 WL->SetTranslation(WLL.GetTranslation());
00204 fRotList->Add(WL);
00205 }
00206 LaddersOnSectors = SsdLaddersOnSectors->GetTable();
00207 Int_t Ladder = 0;
00208 Int_t Sector = 0;
00209 for (Int_t l = 0; l < NoLadders; l++, LaddersOnSectors++) {
00210
00211 Ladder = LaddersOnSectors->Id%100;
00212 if (Ladder == ladder) {
00213 Sector = LaddersOnSectors->Id/100;
00214 LS.SetRotation(&LaddersOnSectors->r00);
00215 LS.SetTranslation(&LaddersOnSectors->t0);
00216
00217 break;
00218 }
00219 }
00220 if (Sector <= 0 || Sector > 4) {cout << "Sector has not been defined" << endl; continue;}
00221 SectorsOnGlobal = SsdSectorsOnGlobal->GetTable();
00222 Int_t sector = 0;
00223 for (Int_t s = 0; s <NoSectors; s++, SectorsOnGlobal++) {
00224
00225 if (SectorsOnGlobal->Id != Sector) continue;
00226 sector = Sector;
00227 SG.SetRotation(&SectorsOnGlobal->r00);
00228 SG.SetTranslation(&SectorsOnGlobal->t0);
00229 break;
00230 }
00231 if (! sector) {cout << "Sector\t" << Sector << " has not been found" << endl; continue;}
00232
00233
00234 if (Debug()) {
00235 cout << "Tpc2Global "; Tpc2Global.Print();
00236 cout << "GL "; GL.Print();
00237 TGeoHMatrix test = Tpc2Global * GL; cout << "test "; test.Print();
00238 }
00239 WG = Tpc2Global * GL * SG * LS * WLL;
00240 row.id = Id;
00241 row.id_shape = 2;
00242 row.ladder = ladder;
00243 row.layer = layer;
00244 num++;
00245 row.num_chip = (num-1)%16 + 1;
00246
00247
00248 Double_t *r = WG.GetRotationMatrix();
00249 row.driftDirection[0] = r[0]; row.normalDirection[0] = r[1]; row.transverseDirection[0] = r[2];
00250 row.driftDirection[1] = r[3]; row.normalDirection[1] = r[4]; row.transverseDirection[1] = r[5];
00251 row.driftDirection[2] = r[6]; row.normalDirection[2] = r[7]; row.transverseDirection[2] = r[8];
00252 Double_t norm;
00253 TVector3 d(row.driftDirection); norm = 1/d.Mag(); d *= norm;
00254 TVector3 t(row.transverseDirection); norm = 1/t.Mag(); t *= norm;
00255 TVector3 n(row.normalDirection);
00256 TVector3 c = d.Cross(t);
00257 if (c.Dot(n) < 0) c *= -1;
00258 d.GetXYZ(row.driftDirection);
00259 t.GetXYZ(row.transverseDirection);
00260 c.GetXYZ(row.normalDirection);
00261
00262 Double_t *wgtr = WG.GetTranslation();
00263 memcpy(row.centerPosition,wgtr, 3*sizeof(Double_t));
00264 Double_t rot[9] = {
00265 row.driftDirection[0], row.transverseDirection[0], row.normalDirection[0],
00266 row.driftDirection[1], row.transverseDirection[1], row.normalDirection[1],
00267 row.driftDirection[2], row.transverseDirection[2], row.normalDirection[2]};
00268 Double_t tr[3] = {row.centerPosition[0],
00269 row.centerPosition[1],
00270 row.centerPosition[2]};
00271 comb->SetRotation(rot);
00272 comb->SetTranslation(tr);
00273 fRotList->Add(comb);
00274 ssdwafer->AddAt(&row);
00275
00276 }
00277 return ssdwafer;
00278 }