BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_rootgeom_MAGNET_SP57.C
Go to the documentation of this file.
1// Creating MAGNET SP57 geometry. Macro writes geometry to 'geometry/magnet_sp57.root'
2#include "TFile.h"
3#include "TGeoManager.h"
4#include "TGeoMedium.h"
5#include "TGeoXtru.h"
6#include "TMath.h"
7
8using namespace TMath;
9//---------------------------
10
12
13//--------Magnet position-------------------------------------------------------
14const double XMagnetPos =
15 0.5055 - 0.167 + 7.
16 - 3.521; // cm x=0.5055 cm - Z SRC relative to Z BMN in X direction (D. Baranov), x=-0.167 - coordinate of the
17 // mark in SRC coordinate system (A. Kolesnikov), x = 7 cm - center of the magnet relative to the mark in
18 // X direction (M. Patsyuk), x=-3.521 - difference with A. Kolesnikov's measurements (T. Atovullaev)
19const double YMagnetPos =
20 -4.62 - 20.53 + 5. + 19.
21 + 4.9285; // cm x=-4.62 cm - Z SRC relative to Z BMN in Y direction (D. Baranov), x=-20.53 - coordinate of the
22 // mark in SRC coordinate system (A. Kolesnikov), x = 5+19 cm - center of the magnet relative to the
23 // mark in Y direction (S. Piyadin, technical drawing), x=4.9285 - difference with A. Kolesnikov's
24 // measurements (T. Atovullaev)
25const double ZMagnetPos = -576.2; // cm
26//--------Magnet construct parameters-------------------------------------------
27
28// Yoke parameters:
29const double XSizeYoke = 300.0; // cm
30const double YSizeYoke = 211.0;
31const double ZSizeYoke = 120.0;
32
33const double XSizeInnerSpaceInYoke = 189.0; // x-inner size of empty space in yoke
34const double YSizeInnerSpaceInYoke = 112.0; // y-inner size of empty space in yoke
35const double ZSizeInnerSpaceInYoke = ZSizeYoke + 0.01; // z-inner size of empty space in yoke
36
37// Coil parameters:
38const double HCoil = 32.0;
39const double RCoil = 155.0 / 2.;
40const double YDistanceBetweenCoils = 48.0;
41
42// Pole parameters
43const double HPole = 5.0;
44const double RPole = 105.0 / 2.;
45const double YDistanceBetweenPoles = 38.0;
46
48{
49
50 // ------- Load media from media file -----------------------------------
51 FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader");
52 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
53 TString geoPath = gSystem->Getenv("VMCWORKDIR");
54 TString medFile = geoPath + "/geometry/media.geo";
55 geoFace->setMediaFile(medFile);
56 geoFace->readMedia();
58 // --------------------------------------------------------------------------
59
60 // ------- Geometry file name (output) ----------------------------------
61 const TString geoObjectName = "magnetSP57";
62 const TString geoObjectVersion = "1";
63 const TString geoFileName = geoPath + "/geometry/" + geoObjectName + "_" + geoObjectVersion + ".root";
64 // --------------------------------------------------------------------------
65
66 // ----------------- Get and create the required media -----------------
67 FairGeoMedia* geoMedia = geoFace->getMedia();
68 FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
69
70 FairGeoMedium* mAir = geoMedia->getMedium("air");
71 if (!mAir)
72 Fatal("Main", "FairMedium air not found");
73 geoBuild->createMedium(mAir);
74 TGeoMedium* pMedAir = gGeoMan->GetMedium("air");
75 if (!pMedAir)
76 Fatal("Main", "Medium air not found");
77
78 FairGeoMedium* mIron = geoMedia->getMedium("iron");
79 if (!mIron)
80 Fatal("Main", "FairMedium iron not found");
81 geoBuild->createMedium(mIron);
82 TGeoMedium* pMedIron = gGeoMan->GetMedium("iron");
83 if (!pMedIron)
84 Fatal("Main", "Medium iron not found");
85
86 FairGeoMedium* mSteel = geoMedia->getMedium("steel");
87 if (!mSteel)
88 Fatal("Main", "FairMedium steel not found");
89 geoBuild->createMedium(mSteel);
90 TGeoMedium* pMedSteel = gGeoMan->GetMedium("steel");
91 if (!pMedSteel)
92 Fatal("Main", "Medium steel not found");
93
94 // the structure of the SP57 coil includes copper and iron with pores for water cooling.
95 // To simplify that we assume there is a copper with 0.75 density of real copper, which is called copperSP57.
96 FairGeoMedium* mCopper = geoMedia->getMedium("copperSP75");
97 if (!mCopper)
98 Fatal("Main", "FairMedium copper not found");
99 geoBuild->createMedium(mCopper);
100 TGeoMedium* pMedCopper = gGeoMan->GetMedium("copperSP75");
101 if (!pMedCopper)
102 Fatal("Main", "Medium copper not found");
103
104 // --------------------------------------------------------------------------
105
106 // -------------- Create geometry and top volume -------------------------
107 gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
108 gGeoMan->SetName(geoObjectName + "_geom");
109 // gGeoMan->SetTopVisible(1);
110 // --------------------------------------------------------------------------
111
112 // Define TOP Geometry
113 TGeoVolume* top = new TGeoVolumeAssembly(geoObjectName);
114 top->SetMedium(pMedAir);
115 gGeoMan->SetTopVolume(top);
116
117 //-----------Solids (shapes)----------------------------------------------------
118
119 TGeoBBox* YokeContainerS = new TGeoBBox("YokeContainerS", XSizeYoke / 2., YSizeYoke / 2., ZSizeYoke / 2.);
120 TGeoShape* InnerSpaceInYokeS = new TGeoBBox("InnerSpaceInYokeS", XSizeInnerSpaceInYoke / 2,
122 TGeoCompositeShape* YokeS = new TGeoCompositeShape("YokeS", "YokeContainerS-InnerSpaceInYokeS");
123
124 TGeoShape* CoilS = new TGeoTube("CoilS", 0., RCoil, HCoil / 2.);
125 TGeoRotation* rotCoil = new TGeoRotation("rotCoil", 180.0, 90.0, 0.0);
126
127 TGeoShape* PoleS = new TGeoTube("PoleS", 0., RPole, HPole / 2.);
128
129 //------------Volumes-----------------------------------------------------------
130 TGeoVolume* MagnetContainerV = new TGeoVolumeAssembly("Magnet");
131 MagnetContainerV->SetMedium(pMedAir);
132
133 TGeoVolume* YokeV = new TGeoVolume("Yoke", YokeS);
134 YokeV->SetMedium(pMedSteel);
135 YokeV->SetLineColor(kGreen);
136 // YokeV->SetVisLeaves(kTRUE);
137 // YokeV->SetTransparency(60);
138
139 TGeoVolume* CoilV =
140 new TGeoVolume("Coil", CoilS); // copper + steel, the coil has pores for water cooling. density = 0.75!!!!
141 CoilV->SetMedium(pMedCopper);
142 CoilV->SetLineColor(kRed);
143 // CoilV->SetVisLeaves(kTRUE);
144 // CoilV->SetTransparency(0);
145
146 TGeoVolume* PoleV = new TGeoVolume("Pole", PoleS);
147 PoleV->SetMedium(pMedIron);
148 PoleV->SetLineColor(kBlue);
149 // PoleV->SetVisLeaves(kTRUE);
150 // PoleV->SetTransparency(0);
151
152 //--------------Adding volumes to the TOP Volume--------------------------------
153 MagnetContainerV->AddNode(CoilV, 1, new TGeoCombiTrans(0, -(YDistanceBetweenCoils / 2 + HCoil / 2), 0, rotCoil));
154 MagnetContainerV->AddNode(CoilV, 2, new TGeoCombiTrans(0, YDistanceBetweenCoils / 2 + HCoil / 2, 0, rotCoil));
155
156 MagnetContainerV->AddNode(PoleV, 1, new TGeoCombiTrans(0, -(YDistanceBetweenPoles / 2 + HPole / 2), 0, rotCoil));
157 MagnetContainerV->AddNode(PoleV, 2, new TGeoCombiTrans(0, YDistanceBetweenPoles / 2 + HPole / 2, 0, rotCoil));
158
159 MagnetContainerV->AddNode(YokeV, 0);
160
161 top->AddNode(MagnetContainerV, 0, new TGeoTranslation(XMagnetPos, YMagnetPos, ZMagnetPos));
162
164
165 //---------------- Finish------------------------------------------------------
166 gGeoMan->CloseGeometry();
167 gGeoMan->CheckOverlaps(0.001);
168 gGeoMan->PrintOverlaps();
169 gGeoMan->Test();
170
171 TFile* geoFile = new TFile(geoFileName, "RECREATE");
172 top->Write();
173 geoFile->Close();
174 top->Draw("ogl");
175}
constexpr Bool_t kTRUE
kRed
kGreen
kBlue
void Fatal(const char *location, const char *msgfmt,...)
R__EXTERN TGeoManager * gGeoManager
#define gROOT
R__EXTERN TSystem * gSystem
void Close(Option_t *option="") override
void SetVisContainers(Bool_t flag=kTRUE) override
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
void Draw(Option_t *option="") override
virtual void SetMedium(TGeoMedium *medium)
void SetLineColor(Color_t lcolor) override
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
TGeoManager * gGeoMan
const double YMagnetPos
const double YSizeYoke
const double ZMagnetPos
const double ZSizeInnerSpaceInYoke
const double YDistanceBetweenCoils
const double XMagnetPos
const double XSizeYoke
const double ZSizeYoke
const double XSizeInnerSpaceInYoke
const double YSizeInnerSpaceInYoke
const double YDistanceBetweenPoles
const double HCoil
void create_rootgeom_MAGNET_SP57()
const double HPole
const double RPole
const double RCoil