Skip to content

Instantly share code, notes, and snippets.

@jdbrice
Created February 12, 2021 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdbrice/d425410556e9f1ac22d7567872598e90 to your computer and use it in GitHub Desktop.
Save jdbrice/d425410556e9f1ac22d7567872598e90 to your computer and use it in GitHub Desktop.
Rough STAR sTGC geometry using ROOT TGeo
// Globals
TGeoManager *geom;
TGeoElementTable *table;
// Materials
TGeoMedium *mediumAir;
TGeoMedium *mediumG10;
TGeoMedium *mediumNPC02;
TGeoMedium *mediumAl;
// DIMENSIONS
const double PLS = 60.2361; // long side cm
const double PSS = 0.308571429 * PLS; // 18.587139429; // short side cm
const double PDZ = 0.5;
const double FEEL = PSS * 0.70;//8.198156465/12.907735714*1.2;
const double FEES = .635135135 * FEEL; //8.198156465;
// <Mixture name="G10" dens="1.7" >
// <Component name="Si" a="28.08" z="14" w="0.6*1*28./60." />
// <Component name="O" a="16" z="8" w="0.6*2*16./60. + 0.4*4*16./174." />
// <Component name="C" a="12" z="6" w="0.4*8*12./174." />
// <Component name="H" a="1" z="1" w="0.4*14*1./174." />
// </Mixture>
// <Mixture name="NPCO2" dens="0.2529E-02" > <!--g/cm3-->
// <Component name="C" a="12" z="6" w="28" />
// <Component name="H" a="1" z="1" w="54" />
// <Component name="O" a="16" z="8" w="11" />
// </Mixture>
void makeMaterials(){
TGeoMixture *air = new TGeoMixture("air",4, 0.00120479);
air->AddElement(table->GetElement(6),0.000124);
air->AddElement(table->GetElement(7),0.755268);
air->AddElement(table->GetElement(8),0.231781);
air->AddElement(table->GetElement(18),0.012827);
mediumAir = new TGeoMedium("Air",0,air);
TGeoMixture *g10 = new TGeoMixture("g10",4, 1.7);
g10->AddElement(table->GetElement(14),0.6*1*28./60.);
g10->AddElement(table->GetElement(8),0.6*2*16./60. + 0.4*4*16./174.);
g10->AddElement(table->GetElement(6),0.4*8*12./174.);
g10->AddElement(table->GetElement(1),0.4*14*1./174.);
mediumG10 = new TGeoMedium("G10",0,g10);
TGeoMixture *npc02 = new TGeoMixture("npc02",3, 0.2529E-02);
npc02->AddElement(table->GetElement(6),11);
npc02->AddElement(table->GetElement(1),54);
npc02->AddElement(table->GetElement(8),11);
mediumNPC02 = new TGeoMedium("NPC02",0,npc02);
TGeoMixture *al = new TGeoMixture("al",1, 1.0);
al->AddElement(table->GetElement(13),1);
mediumAl = new TGeoMedium("Al",0,al);
}
void makeBrackets( TGeoVolume * top ) {
const double braDZ = 1.0;
const double braW = 9.6/2.0;
const double braH = 3.2/2.0;
TGeoVolume *bra = geom->MakeBox("BR0",mediumAl, braW/2.0, braH/2.0, braDZ/2);
bra->SetLineColor(TColor::GetColor("#9e9e9e"));
bra->SetVisibility(1);
top->AddNode( bra, 1, new TGeoTranslation( braW/2.0,braH/2.0, (PDZ*3) +braDZ/2.0 ) );
TGeoVolume *brb = geom->MakeBox("BR1",mediumAl, braH/2.0, (braW - braH)/2.0, braDZ/2);
brb->SetLineColor(TColor::GetColor("#9e9e9e"));
brb->SetVisibility(1);
top->AddNode( brb, 1, new TGeoTranslation( braH/2.0,(braW - braH), (PDZ*3) + braDZ/2.0) );
const double breDZ = 0.5;
const double breW = 9.6;
const double breH = 3.2;
TGeoVolume *bre0 = geom->MakeBox("BRE0",mediumAl, breW/2.0, breH/2.0, breDZ/2);
bre0->SetLineColor(TColor::GetColor("#9e9e9e"));
bre0->SetVisibility(1);
top->AddNode( bre0, 1, new TGeoTranslation( PLS - breW/2.0 + (breW/3.0),breH/2.0, (PDZ*3) + breDZ/2.) );
top->AddNode( bre0, 2, new TGeoTranslation( PLS - breW/2.0 + (breW/3.0),breH/2.0, -(breDZ/2.0)) );
TGeoVolume *bre1 = geom->MakeBox("BRE1",mediumAl, breDZ/2.0, breH/2.0, (PDZ*3)/2.);
bre1->SetLineColor(TColor::GetColor("#9e9e9e"));
bre1->SetVisibility(1);
top->AddNode( bre1, 1, new TGeoTranslation( PLS + breDZ*2,breH/2.0, +(PDZ*3)/2. ) );
// one is 90 off
auto bretr0 = new TGeoTranslation( breH/2.0, PLS - breW/2.0 + (breW/3.0), (PDZ*3) + breDZ/2.);
auto brer0 = new TGeoRotation( "brer0", -90, 0, 0 );
top->AddNode( bre0, 3, new TGeoCombiTrans( *bretr0, *brer0 ) );
auto bretr1 = new TGeoTranslation( breH/2.0, PLS - breW/2.0 + (breW/3.0), -(breDZ/2.0));
top->AddNode( bre0, 4, new TGeoCombiTrans( *bretr1, *brer0 ) );
auto bretr2 = new TGeoTranslation(breH/2.0, PLS + breDZ*2, +(PDZ*3)/2. );
top->AddNode( bre1, 2, new TGeoCombiTrans( *bretr2, *brer0 ) );
TGeoVolume *bre2 = geom->MakeBox("BRE2",mediumAl, breW/2, breH, breDZ);
bre2->SetLineColor(TColor::GetColor("#9e9e9e"));
bre2->SetVisibility(1);
auto tr1 = new TGeoTranslation( PLS/2.0 + 2*breW/2. + breH/4, PLS/2.0 + 2.*breH/2. + breH, -(breDZ)/2. );
auto r1 = new TGeoRotation( "brer1", -45, 0, 0 );
top->AddNode( bre2, 1, new TGeoCombiTrans( *tr1, *r1 ) );
}
void makeFEES( TGeoVolume * top ){
const double feeSO = 3.2 * (2./3.);
// make the FEES
TGeoVolume *feeVol = geom->MakeBox("FEEV",mediumG10, 0.2, FEEL/2.0, FEES/2.0);
feeVol->SetLineColor(TColor::GetColor("#1a237e"));
feeVol->SetVisibility(1);
TGeoTranslation *feetr0 = new TGeoTranslation(PLS - feeSO, (PSS - FEEL)/2.0 + FEEL/2.0 + (PSS - FEEL)/3.0, FEES/2.0 + (PDZ*3));
top->AddNode( feeVol, 1, feetr0 );
// TGeoTranslation *feetr0 = new TGeoTranslation(PLS, (PSS - FEEL)/2.0 + FEEL/2.0 , FEES/2.0);
TGeoTranslation *feetr1 = new TGeoTranslation( (PSS - FEEL)/2.0 + FEEL/2.0 + (PSS - FEEL)/3.0, PLS - feeSO, FEES/2.0 + (PDZ*3));
TGeoRotation * feer0 = new TGeoRotation( "feer0", 90, 0, 0 );
top->AddNode( feeVol, 2, new TGeoCombiTrans( *feetr1, *feer0 ) );
// first diagonal FEE
double bump = sqrt( pow(FEEL,2)/2.0 );
double fudge = FEEL / 36.0;
size_t iD = 1;
TGeoTranslation *feetr2 = new TGeoTranslation( PSS + iD*(bump/2.0) + (iD*fudge), PLS - iD*(bump/2.0) - (iD*fudge) - feeSO, FEES/2.0 + (PDZ*3));
TGeoRotation * feer1 = new TGeoRotation( "feer0", 45, 0, 0 );
top->AddNode( feeVol, 3, new TGeoCombiTrans( *feetr2, *feer1 ) );
iD = 3;
TGeoTranslation *feetr3 = new TGeoTranslation( PSS + iD*(bump/2.0) + (iD*fudge), PLS - iD*(bump/2.0) - (iD*fudge) - feeSO, FEES/2.0 + (PDZ*3));
top->AddNode( feeVol, 4, new TGeoCombiTrans( *feetr3, *feer1 ) );
iD = 5;
TGeoTranslation *feetr4 = new TGeoTranslation( PSS + iD*(bump/2.0) + (iD*fudge), PLS - iD*(bump/2.0) - (iD*fudge) - feeSO, FEES/2.0 + (PDZ*3));
top->AddNode( feeVol, 5, new TGeoCombiTrans( *feetr4, *feer1 ) );
iD = 7;
TGeoTranslation *feetr5 = new TGeoTranslation( PSS + iD*(bump/2.0) + (iD*fudge), PLS - iD*(bump/2.0) - (iD*fudge) - feeSO, FEES/2.0 + (PDZ*3));
top->AddNode( feeVol, 6, new TGeoCombiTrans( *feetr5, *feer1 ) );
}
void makePlastic( TGeoVolume * top ){
TGeoVolume * plaVol = geom->MakeXtru( "PLAB", mediumG10, 2 );
const double ds = 0.1;
const double th = 2.2;
const double x0 = PLS + ds;
double px[] = {x0, x0 + th*4, x0 + th*4, x0 + th*2, PSS + th*2, PSS + th*2, PSS + th, 0, 0, PSS };
double py[] = {0, 0 , PSS + ds , PSS + ds, PLS, x0, x0 + th, x0 + th, x0 + ds, x0 + ds };
((TGeoXtru*)plaVol->GetShape())->DefinePolygon( 9, px, py );
((TGeoXtru*)plaVol->GetShape())->DefineSection( 0, 0, 0, 0, 1.0 );
((TGeoXtru*)plaVol->GetShape())->DefineSection( 1, PDZ, 0, 0, 1.0 );
plaVol->SetLineColor(TColor::GetColor( "#29b6f6" ));
plaVol->SetVisibility(1);
auto tr = new TGeoTranslation(0.,0., PDZ);
top->AddNode( plaVol, 1, tr );
}
void makeTubes( TGeoVolume * top ){
const double rmin = 1.4;
const double rmax = 1.5;
const double dz = 50.628845533 + 10.0;
TGeoVolume * plaVol = geom->MakeTube( "TUBE0", mediumG10, rmin, rmax, dz/2. );
plaVol->SetLineColor(TColor::GetColor( "#26a69a" ));
plaVol->SetVisibility(1);
auto tr1 = new TGeoTranslation(PLS/2.0 + PSS/1.8 + 2*rmin,PLS/1.8 + PSS/2 - 2*rmin, +3*PDZ + rmin*2);
TGeoRotation * r1 = new TGeoRotation( "tuber1", 45, 90, 0 );
top->AddNode( plaVol, 1, new TGeoCombiTrans( *tr1, *r1 ) );
TGeoVolume * plaVol2 = geom->MakeTube( "TUBE1", mediumG10, rmin, rmax, PSS/2. );
plaVol2->SetLineColor(TColor::GetColor( "#26a69a" ));
plaVol2->SetVisibility(1);
auto tr2 = new TGeoTranslation(PSS/2,PLS + 2*rmin, +3*PDZ + rmin*2);
TGeoRotation * r2 = new TGeoRotation( "tuber2", 90, 90, 0 );
top->AddNode( plaVol2, 2, new TGeoCombiTrans( *tr2, *r2 ) );
}
void rootSTGM(){
geom = new TGeoManager("geom","My first 3D geometry");
table = geom->GetElementTable();
makeMaterials();
TCanvas *c = new TCanvas("c", "c",0,0,600,600);
TGeoVolume *top = geom->MakeBox("TOP",mediumAir,200,200,200);
geom->SetTopVolume(top);
geom->SetTopVisible(0);
top->SetVisibility(0);
TGeoVolume * pentVol = geom->MakeXtru( "PCBP", mediumG10, 2 );
double px[] = {0, PLS, PLS, PSS, 0 };
double py[] = {0, 0 , PSS, PLS, PLS };
((TGeoXtru*)pentVol->GetShape())->DefinePolygon( 5, px, py );
((TGeoXtru*)pentVol->GetShape())->DefineSection( 0, 0, 0, 0, 1.0 );
((TGeoXtru*)pentVol->GetShape())->DefineSection( 1, PDZ, 0, 0, 1.0 );
pentVol->SetLineColor(TColor::GetColor( "#ffee58" ));
pentVol->SetVisibility(1);
TGeoTranslation *tr0 = new TGeoTranslation(0.,0., 0.);
top->AddNode( pentVol, 1, tr0 );
TGeoTranslation *tr1 = new TGeoTranslation(0.,0., 2. * PDZ);
top->AddNode( pentVol, 2, tr1 );
TGeoVolume * pentVolGas = geom->MakeXtru( "GASP", mediumG10, 2 );
((TGeoXtru*)pentVolGas->GetShape())->DefinePolygon( 5, px, py );
((TGeoXtru*)pentVolGas->GetShape())->DefineSection( 0, 0, 0, 0, 1.0 );
((TGeoXtru*)pentVolGas->GetShape())->DefineSection( 1, PDZ, 0, 0, 1.0 );
pentVolGas->SetLineColor(kRed);
pentVolGas->SetVisibility(1);
TGeoTranslation *tr3 = new TGeoTranslation(0.,0., PDZ);
top->AddNode( pentVolGas, 1, tr3 );
makeFEES( top );
makeBrackets( top );
makePlastic( top );
makeTubes( top );
// tunnel->SetLineColor(kBlue);
// tunnel->SetVisibility(1);
geom->CloseGeometry();
top->Draw("ogl");
TView *view = gPad->GetView();
view->ShowAxis();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment