//________________________________________________________________________________ //void Db(const Char_t *tabNam = "Calibrations/tpc/noiseElim", // void DbS(const Char_t *tabNam = // "Survey/svt/LadderOnSurvey",Int_t date = 20051101, Int_t time = 0 void MakeSvtWaferOnGlobal(Int_t date = 20050101, Int_t time = 65 ){ TGeoHMatrix GL, WL,LSU,LSH,SHG,WG; if (dbMk == 0) Load(); dbMk->SetDebug(2); dbMk->SetDateTime(date,time); // dbMk->SetFlavor("ofl+laserDV","tpcDriftVelocity"); // dbMk->SetMaxEntryTime(20040520,0); // to browse 1 database, use this one TDataSet *set = dbMk->GetDataBase("Geometry/ssd"); if (! set) return; // Positioning of the SSD: St_Survey *SsdOnGlobal = (St_Survey *) set->Find("SsdOnGlobal"); if (! SsdOnGlobal) {cout << "SsdOnGlobal has not been found" << endl; return;} Survey_st *OnGlobal = SsdOnGlobal->GetTable(); // SSD and SVT as whole GL.SetRotation(&OnGlobal->r00); GL.SetTranslation(&OnGlobal->t0); //cout << "WL\t"; WL.Print(); set = dbMk->GetDataBase("Geometry/svt"); St_Survey *WaferOnLadder = (St_Survey *) set->Find("WaferOnLadder"); St_Survey *LadderOnSurvey = (St_Survey *) set->Find("LadderOnSurvey"); St_Survey *LadderOnShell = (St_Survey *) set->Find("LadderOnShell"); St_Survey *ShellOnGlobal = (St_Survey *) set->Find("ShellOnGlobal"); Int_t NW = WaferOnLadder->GetNRows(); Int_t NL = LadderOnSurvey->GetNRows(); Survey_st *waferOnLadder = WaferOnLadder->GetTable(); Survey_st *ladderOnSurvey = LadderOnSurvey->GetTable(); Survey_st *ladderOnShell = LadderOnShell->GetTable(); Survey_st *shellOnGlobal0 = ShellOnGlobal->GetTable(0); Survey_st *shellOnGlobal1 = ShellOnGlobal->GetTable(1); St_svtWafersPosition *svtwafer = new St_svtWafersPosition("svtWafersPosition",216); svtWafersPosition_st row; for (Int_t i = 0; i < NW; i++, waferOnLadder++) { Int_t Idw = waferOnLadder->Id; WL.SetRotation(&waferOnLadder->r00); WL.SetTranslation(&waferOnLadder->t0); // if (i==0) WL.Print(); Int_t wshell = 0; Int_t wbarrel = Idw/1000; Int_t wwafer = (Idw - 1000*wbarrel)/100; Int_t wladder = Idw%100; Int_t wlayer = 2*wbarrel + wladder%2 - 1; // cout << waferOnLadder->Id << " "<< Idw<< " " << 100*wwafer + wladder + 1000*wlayer <<endl; for ( Int_t j = 0; j < NL; j++, ladderOnSurvey++, ladderOnShell++) { Int_t Idl = ladderOnSurvey->Id; Int_t lbarrel = Idl/1000; Int_t lladder = Idl%100; if( wladder == lladder ) { LSU.SetRotation(&ladderOnSurvey->r00); LSU.SetTranslation(&ladderOnSurvey->t0); LSH.SetRotation(&ladderOnShell->r00); LSH.SetTranslation(&ladderOnShell->t0); if( (wbarrel == 1 && wladder <= 4) || (wbarrel == 2 && wladder <= 6) || (wbarrel == 3 && wladder <= 8) ) { SHG.SetRotation(&shellOnGlobal0->r00); SHG.SetTranslation(&shellOnGlobal0->t0); }else { SHG.SetRotation(&shellOnGlobal1->r00); SHG.SetTranslation(&shellOnGlobal1->t0); } // SsdOnGlobal * ShellOnGlobal * LadderOnShell * LadderOnSurvey * WaferOnLadder WG = GL * SHG * LSH * LSU * WL; // WG.Print(); // TGeoHMatrix WGInv = WG.Inverse(); Double_t *r = WG.GetRotationMatrix(); Int_t fail = 0; for (int l = 0; l < 9; l++) { if (TMath::Abs(r[l]) >= 1.000001) fail++; } if (fail) { cout << "===============" << waferOnLadder->Id << " "<< Idw << " " << 100*wwafer + wladder + 1000*wlayer <<endl; cout << "WG\t"; WG.Print(); // cout << "SHG\t"; SHG.Print(); // cout << "LSH\t"; LSH.Print(); // cout << "LSU\t"; LSU.Print(); // cout << "WL\t"; WL.Print(); } row.driftDirection[0] = r[0]; row.normalDirection[0] = r[1]; row.transverseDirection[0] = r[2]; row.driftDirection[1] = r[3]; row.normalDirection[1] = r[4]; row.transverseDirection[1] = r[5]; row.driftDirection[2] = r[6]; row.normalDirection[2] = r[7]; row.transverseDirection[2] = r[8]; Double_t norm; TVector3 d(row.driftDirection); norm = 1/d.Mag(); d *= norm; TVector3 t(row.transverseDirection); norm = 1/t.Mag(); t *= norm; TVector3 n(row.normalDirection); TVector3 c = d.Cross(t); if (c.Dot(n) < 0) c *= -1; d.GetXYZ(row.driftDirection); t.GetXYZ(row.transverseDirection); c.GetXYZ(row.normalDirection); row.ID = 100*wwafer + wladder + 1000*wlayer; Double_t *wgtr = WG.GetTranslation(); memcpy(row.centerPosition,wgtr, 3*sizeof(Double_t)); svtwafer->AddAt(&row); break; } } } ofstream out; out.open(Form("svtWafersPosition.%8i.%06i.C",date,time)); svtwafer->SavePrimitive(out,""); out.close(); }
//________________________________________________________________________________ void MakeSvtLadderOnShell(){//, Int_t time = 38 ){ // combine SvtBarrelOnGlobal and SvtShellsOnBarrel into SvtShellsOnGlobal gROOT->LoadMacro("bfc.C"); bfc(0,"mysql,db,nodefault"); StMaker *dbMk = chain->Maker("db"); if (! dbMk) return; dbMk->SetDebug(1); StEvtHddr *header = chain->GetEvtHddr(); header->SetRunNumber(1); dbMk->SetDateTime(date,time); header->SetDateTime(date,time); chain->MakeEvent(); dbMk->SetDebug(2); dbMk->SetDateTime(date,time); St_Survey *LadderOnShellOld = (St_Survey *) dbMk->GetDataBase("Geometry/svt/LadderOnShell"); // shells in the SVT barrel coordinate system if (! (LadderOnShellOld)) return; Survey_st *LaddersOnShells = LadderOnShellOld->GetTable(); // shells in the SVT barrel coordinate system Int_t NoLadders = LadderOnShellOld->GetNRows(); St_Survey *LadderOnShell = new St_Survey("LadderOnShell",NoLadders); #ifdef CutSTEP cout << "============================ CutSTEP =========================" << endl; #endif TGeoHMatrix T; Double_t tr[3] = {0,0, 23.525}; // Double_t tr[3] = {0,0, -23.525}; T.SetTranslation(tr); TGeoHMatrix F; Double_t flip[9] = { 1, 0, 0, 0, 0, 1, 0, 1, 0 }; F.SetRotation(flip); TGeoHMatrix TInv = T.Inverse(); for (Int_t s = 0; s < NoLadders; s++, LaddersOnShells++) { TGeoHMatrix LSold, LS, dR, ddR, dddR; // LadderOnShellOld->Print(s,1); LSold.SetRotation(&LaddersOnShells->r00); LSold.SetTranslation(&LaddersOnShells->t0); cout << "===================== Ladder \t" << s+1 << endl; cout << "\tLSold\t"; LSold.Print(); Int_t i = -1; for (Int_t k = 0; k < N; k++) { if (LaddersOnShells->Id == 1000*Data[k].barrel + Data[k].ladder) {i = k; break;} } if (i < 0) { cout << "Correction for " << LaddersOnShells->Id << " is not found" << endl; } else { cout << "Ladder " << LaddersOnShells->Id << "\ti " << i << "\talpha " << Data[i].alpha << "+/-" << Data[i].Dalpha << "\tbeta " << Data[i].beta << "+/-" << Data[i].Dbeta << "\tgamma " << Data[i].gamma << "+/-" << Data[i].Dgamma << "\tu " << Data[i].u << "\tv " << Data[i].v << "\tw " << Data[i].w << endl; Double_t xyz[3] = {0, 0, 0}; // if (Data[i].Dalpha < 2 && Data[i].Dbeta < 2 && Data[i].Dgamma < 2) { #ifndef CutSTEP if (Data[i].Dalpha > 0) dR.RotateX(-180./TMath::Pi()*Data[i].alpha*1e-3); if (Data[i].Dbeta > 0) dR.RotateZ(-180./TMath::Pi()*Data[i].beta*1e-3); if (Data[i].Dgamma > 0) dR.RotateY(-180./TMath::Pi()*Data[i].gamma*1e-3); if (Data[i].Du > 0) xyz[0] = 1e-4*Data[i].u; if (Data[i].Dv > 0) xyz[2] = 1e-4*Data[i].v; if (Data[i].Dw > 0) xyz[1] = 1e-4*Data[i].w; #else if (Data[i].Dalpha > 0) dR.RotateX(-180./TMath::Pi()*Data[i].alpha*0.5e-3); if (Data[i].Dbeta > 0) dR.RotateZ(-180./TMath::Pi()*Data[i].beta*0.5e-3); if (Data[i].Dgamma > 0) dR.RotateY(-180./TMath::Pi()*Data[i].gamma*0.5e-3); if (Data[i].Du > 0) xyz[0] = 0.5e-4*Data[i].u; if (Data[i].Dv > 0) xyz[2] = 0.5e-4*Data[i].v; if (Data[i].Dw > 0) xyz[1] = 0.5e-4*Data[i].w; #endif // } dR.SetTranslation(xyz); cout << "dR\t"; dR.Print(); } // shellOnGlobal * ladderOnShell * T * dR * T**-1 * ladderOnSurvey * waferOnLadder // shellOnGlobal * ( ladderOnShell * F * T * dR * T**-1 * F ) * ladderOnSurvey * waferOnLadder ddR = T * dR * TInv; cout << "ddR\t" << ddR.Print(); dddR = F * T * dR * TInv * F; cout << "dddR\t" << dddR.Print(); // LS = LSold * dR; cout << "LS_old\t"; LS.Print(); // LS = LSold * dddR; cout << "LS_new\t"; LS.Print(); LS = LSold * ddR; cout << "LS_new\t"; LS.Print(); Survey_st row = *LaddersOnShells; Double_t *r = LS.GetRotationMatrix(); memcpy(&row.r00, r, 9*sizeof(Double_t)); Double_t *t = LS.GetTranslation(); memcpy(&row.t0, t, 3*sizeof(Double_t)); LadderOnShell->AddAt(&row); // LadderOnShell->Print(LadderOnShell->GetNRows()-1,1); } TString fOut = Form("%s.%8i.%06i.C",LadderOnShell->GetName(),date,time); ofstream out; cout << "Create " << fOut << endl; out.open(fOut.Data()); out << "TDataSet *CreateTable() {" << endl; out << " if (!gROOT->GetClass(\"St_Survey\")) return 0;" << endl; out << " Survey_st row[" << NoLadders << "] = {" << endl; Survey_st *LaddersOnShells = LadderOnShell->GetTable(); for (Int_t i = 0; i < NoLadders; i++, LaddersOnShells++) { out << " {" << Form("%1i",LaddersOnShells->Id); Double_t *r = &(LaddersOnShells->r00); for (Int_t j = 0; j < 9; j++) out << Form(",%8.5f",r[j]); for (Int_t j = 9; j < 12; j++) out << Form(",%8.4f",r[j]); for (Int_t j = 12; j < 18; j++) out << Form(",%3.1f",r[j]); out << ",\"" << Pass << "\"}"; if (i != NoLadders - 1) out << ","; out << endl; } out << " };" << endl; out << " St_Survey *tableSet = new St_Survey(\"" << LadderOnShell->GetName() << "\"," << NoLadders << ");" << endl; out << " for (Int_t i = 0; i < " << NoLadders << "; i++) tableSet->AddAt(&row[i].Id, i);" << endl; out << " return (TDataSet *)tableSet;" << endl; out << "}" << endl; out.close(); }