BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_rootgeom_wall_oldnames_vacuum_zdc_270x120cm.C
Go to the documentation of this file.
1//---------------------------
2// M.Golubeva (INR RAS), May 2016
3//---------------------------
4
6#include "TFile.h"
7#include "TGeoManager.h"
8#include "TGeoMedium.h"
9#include "TGeoVolume.h"
10
11// Detector's position
12// const Double_t WALL_Xpos = 0.0;
13// const Double_t WALL_Ypos = 0.0;
14// const Double_t WALL_Zpos = 950.;//cm to WALL surface
15// const Double_t WALL_center_Zpos = 950.5;//9.505 m (950+0.5);//cm
16// const Double_t WALL_Zpos = 900.;//cm to WALL surface
17// const Double_t WALL_center_Zpos = 900.01;//9.001 m (900+0.01);//cm
18// const Double_t WALL_Zpos = 878.1;//cm to WALL surface
19// const Double_t WALL_center_Zpos = 878.11;//8.7811 m (878.1+0.01);//cm//vac
20// const Double_t WALL_center_Zpos = 878.3;//8.783 m (878.1+0.2);//cm//sc
21
22// Detector's construct parameters ===================
23
24// Global dimensions for WALL in cm
25Double_t Wall_X_size = 135; // 270/2
26Double_t Wall_Y_size = 60; // 120/2
27// Double_t Wall_Z_size = 0.01; //0.02/2.//vac
28Double_t Wall_Z_size = 0.00001; // 0.02/2.//vac
29
30// media ============================================
34
35class FairGeoMedia;
36class FairGeoBuilder;
37
38void DefineRequiredMedia(FairGeoMedia* geoMedia, FairGeoBuilder* geoBuild)
39{
40 // vacuum medium
41 FairGeoMedium* mVacuum = geoMedia->getMedium("vacuum");
42 if (!mVacuum)
43 Fatal("Main", "FairMedium vacuum not found");
44 geoBuild->createMedium(mVacuum);
45 pMedVacuum = gGeoManager->GetMedium("vacuum");
46 if (!pMedVacuum)
47 Fatal("Main", "Medium vacuum not found");
48
49 // air medium
50 FairGeoMedium* mAir = geoMedia->getMedium("air");
51 if (!mAir)
52 Fatal("Main", "FairMedium air not found");
53 geoBuild->createMedium(mAir);
54 pMedAir = gGeoManager->GetMedium("air");
55 if (!pMedAir)
56 Fatal("Main", "Medium air not found");
57
58 // medium polystyrene (Scint.)
59 FairGeoMedium* mPolystyrene = geoMedia->getMedium("polystyrene");
60 if (!mPolystyrene)
61 Fatal("Main", "FairMedium polystyrene not found");
62 geoBuild->createMedium(mPolystyrene);
63 pMedScint = gGeoManager->GetMedium("polystyrene");
64 if (!pMedScint)
65 Fatal("Main", "Medium polystyrene not found");
66 /*
67 // medium FscScint (Scint.)
68 FairGeoMedium* mPolystyrene = geoMedia->getMedium("FscScint");
69 if ( ! mPolystyrene ) Fatal("Main", "FairMedium FscScint not found");
70 geoBuild->createMedium(mPolystyrene);
71 pMedScint = gGeoManager->GetMedium("FscScint");
72 if ( ! pMedScint ) Fatal("Main", "Medium FscScint not found");
73 */
74} // DefineRequiredMedia
75
77 Double_t WALL_Ypos = 0,
78 Double_t WALL_Zpos = 900,
79 Double_t rotY = 0)
80{
81
82 // Load necessary libraries
83 // gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
84 bmnloadlibs(); // load libraries
85
86 // ---- set working directory --------------------------------------------
87 TString gPath = gSystem->Getenv("VMCWORKDIR");
88
89 // ------- Geometry file name (output) ---------------------------------
90 const TString geoDetectorName = "wall_vacuum_zdc_270x120cm";
91 const TString geoDetectorVersion = "v1";
92 // TString geoFileName = gPath + "/geometry/" + geoDetectorName + geoDetectorVersion + ".root";
93 // Double_t WALL_center_Zpos = WALL_Zpos + Wall_Z_size;;//8.7811 m (878.1+0.01);//cm//vac
94 Double_t WALL_center_Zpos = WALL_Zpos; // cm//vac
95 /*
96 TString sXshift = "";
97 TString sYshift = "";
98 TString sZshift = "";
99 Int_t Xshift = Int_t(WALL_Xpos*10.); //mm
100 Int_t Yshift = Int_t(WALL_Ypos*10.); //mm
101 Int_t Zshift = Int_t(WALL_Zpos*10.); //mm
102 sXshift += Xshift;
103 sYshift += Yshift;
104 sZshift += Zshift;
105 */
106
107 TString sXshift_1 = "";
108 TString sXshift_2 = "";
109 TString sXshift_3 = "";
110
111 TString sYshift_0 = "-";
112 TString sYshift_1 = "";
113 TString sYshift_2 = "";
114 // TString sYshift_3 = "";
115
116 TString sZshift_1 = "";
117 TString sZshift_2 = "";
118
119 TString sRotY_1 = "";
120 TString sRotY_2 = "";
121
122 Int_t Xshift_1 = Int_t(WALL_Xpos); // cm
123 // Int_t Xshift_2 = Int_t(0.1+10*(WALL_Xpos-Int_t(WALL_Xpos))); //cm
124 // Int_t Xshift_2 = Int_t(0.5+100*(WALL_Xpos-Int_t(WALL_Xpos))); //cm
125 Int_t Xshift_2 = Int_t(0.5 + 100 * (TMath::Abs(WALL_Xpos) - Int_t(TMath::Abs(WALL_Xpos)))); // cm
126 // Int_t Xshift_2 = Int_t(100*(WALL_Xpos-Int_t(WALL_Xpos))); //cm
127 // Int_t Xshift_2 = 0; //cm
128 // Int_t Xshift_2 = Int_t(100*(WALL_Xpos-Int_t(WALL_Xpos)))+1; //cm
129 // Int_t Xshift_3 = Int_t(100*(WALL_Xpos-Int_t(WALL_Xpos)))+1; //cm
130 sXshift_1 += Xshift_1;
131 sXshift_2 += Xshift_2;
132 // sXshift_3 += Xshift_3;
133
134 Int_t Zshift_1 = Int_t(WALL_Zpos); // cm
135 // Int_t Zshift_2 = Int_t(100*(WALL_Zpos-Int_t(WALL_Zpos))); //cm
136 Int_t Zshift_2 = Int_t(100 * (WALL_Zpos - Int_t(WALL_Zpos))) + 1; // cm
137 // Int_t Zshift_2 = Int_t(10*(WALL_Zpos-Int_t(WALL_Zpos)))+1; //cm
138 // Int_t Zshift_2 = Int_t(10*(WALL_Zpos-Int_t(WALL_Zpos))); //cm
139 cout << "Zshift_1,Zshift_2 " << Zshift_1 << " " << 10 * (WALL_Zpos - Int_t(WALL_Zpos)) << " " << Zshift_2 << endl;
140 sZshift_1 += Zshift_1;
141 sZshift_2 += Zshift_2;
142
143 Int_t rotY_1 = Int_t(rotY); // 2 from 2.9
144 Int_t rotY_2 = Int_t(100 * (rotY - Int_t(rotY))); // 9 from 2.9
145 // Int_t rotY_2 = Int_t(100*(rotY-Int_t(rotY)))+1;//9 from 2.9
146 sRotY_1 += rotY_1;
147 sRotY_2 += rotY_2;
148
149 /*
150 //no Y shift
151 Int_t Yshift_1 = Int_t(WALL_Ypos); //cm
152 //Int_t Yshift_2 = Int_t(100*(WALL_Ypos-Int_t(WALL_Ypos)))+1; //cm
153 Int_t Yshift_2 = Int_t(100*(WALL_Ypos-Int_t(WALL_Ypos))); //cm
154 sYshift_1 += Yshift_1;
155 sYshift_2 += Yshift_2;
156
157 TString geoFileName = gPath + "/geometry/" + geoDetectorName + "_" + "Zpos_" + sZshift_1 + "." + sZshift_2 + "cm" +
158 "_" + "Xshift_" + sXshift_1 + "." + sXshift_2 + "cm" + "_" + "Yshift_" + sYshift_1 + "." + sYshift_2 + "cm" + "_" +
159 "rotationY_" + sRotY_1 + "." + sRotY_2 + "deg_" + geoDetectorVersion + ".root";
160 */
161
162 // with Y shift
163 Int_t Yshift_1 = Int_t(WALL_Ypos); // cm
164 sYshift_1 += Yshift_1;
165 // Int_t Yshift_2 = Int_t(100*(WALL_Ypos-Int_t(WALL_Ypos))); //cm
166 // Int_t Yshift_2 = TMath::Abs(Int_t(10*(WALL_Ypos))); //cm
167 Int_t Yshift_2 = TMath::Abs(Int_t(100 * (WALL_Ypos))); // cm
168 sYshift_2 += Yshift_2;
169
170 TString geoFileName = gPath + "/geometry/" + geoDetectorName + "_" + "Zpos_" + sZshift_1 + "." + sZshift_2 + "cm"
171 + "_" + "Xshift_" + sXshift_1 + "." + sXshift_2 + "cm" + "_" + "Yshift" + sYshift_0
172 + sYshift_1 + "." + sYshift_2 + "cm" + "_" + "rotationY_" + sRotY_1 + "." + sRotY_2 + "deg_"
173 + geoDetectorVersion + ".root";
174
175 // TString geoFileName = gPath + "/geometry/" + geoDetectorName + "_" + "Zpos_" + sZshift + "mm" + "_" + "Xshift_" +
176 // sXshift + "mm" + "_" + "Yshift_" + sYshift + "mm" + "_" + geoDetectorVersion + ".root";
177 ////TString geoFileName = gPath + "/geometry/" + geoDetectorName + "_" + "Zpos_" + sZshift_1 + "." + sZshift_2 +
178 ///"cm" + "_" + "Xshift_" + sXshift_1 + "." + sXshift_2 + "cm" + "_" + "Yshift_" + sYshift_1 + "." + sYshift_2 +
179 ///"cm" + "_" + "rotationY_" + sRotY_1 + "." + sRotY_2 + "deg_" + geoDetectorVersion + ".root";
180 // TString geoFileName = gPath + "/geometry/" + geoDetectorName + "_" + "Zpos_" + sZshift_1 + "." + sZshift_2 + "cm"
181 // + "_" + "Xshift_" + sXshift_1 + "." + sXshift_2 + sXshift_3 + "cm" + "_" + "Yshift_" + sYshift_1 + "." +
182 // sYshift_2 + "cm" + "_" + "rotationY_" + sRotY_1 + "." + sRotY_2 + "deg_" + geoDetectorVersion + ".root";
183 // -------------------------------------------------------------------------
184
185 // ---- global geometry parameters ---------------------------------------
186 FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader");
187 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
188
189 // ------- Load media from media file ----------------------------------
190 TString medFile = gPath + "/geometry/media.geo";
191 geoFace->setMediaFile(medFile);
192 geoFace->readMedia();
193 FairGeoMedia* geoMedia = geoFace->getMedia();
194 FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
195 // geoMedia->list();
196 // geoMedia->print();
197 DefineRequiredMedia(geoMedia, geoBuild);
198 // -------------------------------------------------------------------------
199
200 // -------------- Create geometry and global top volume ------------------------
201 gGeoManager = (TGeoManager*)gROOT->FindObject("FAIRGeom");
202 gGeoManager->SetName(geoDetectorName + "_geom");
203 TGeoVolume* top = new TGeoVolumeAssembly("TOP");
204 top->SetMedium(pMedAir);
205 // top->SetMedium(pMedVacuum);
206 gGeoManager->SetTopVolume(top);
207 // gGeoMan->SetTopVisible(1);
208 // --------------------------------------------------------------------------
209
210 // Define WALL Geometry
211 // TString wall_common_name = "WALL_common";
212 TString wall_common_name = "ZDC_common";
213 TGeoVolume* ZDC_common = new TGeoVolumeAssembly(wall_common_name);
214 ZDC_common->SetMedium(pMedAir);
215 // ZDC_common->SetMedium(pMedVacuum);
216
217 TString wall_name = "zdc01";
218 // TGeoTube *WALLS = new TGeoTube(wall_name, Wall_inner_radius, Wall_outer_radius, Wall_Z_size);
219 TGeoBBox* WALLS = new TGeoBBox(wall_name, Wall_X_size, Wall_Y_size, Wall_Z_size);
220 TGeoVolume* WALLV = new TGeoVolume(wall_name, WALLS);
221 // WALLV->SetMedium(pMedAir);
222 WALLV->SetMedium(pMedVacuum);
223 // WALLV->SetMedium(pMedScint);
224
225 TString wallSensitive_name = "zdc01s";
226 // TGeoTube *wallSensitiveVolumeS = new TGeoTube(wallSensitive_name, Wall_inner_radius, Wall_outer_radius,
227 // Wall_Z_size);
228 TGeoBBox* wallSensitiveVolumeS = new TGeoBBox(wallSensitive_name, Wall_X_size, Wall_Y_size, Wall_Z_size);
229 TGeoVolume* wallSensitiveVolumeV = new TGeoVolume(wallSensitive_name, wallSensitiveVolumeS);
230 // wallSensitiveVolumeV->SetMedium(pMedScint);
231 wallSensitiveVolumeV->SetMedium(pMedVacuum);
232
233 // insert wallSensitiveVolumeV into WALLV
234 TGeoTranslation* wall_position = new TGeoTranslation(0., 0., 0.);
235 WALLV->AddNode(wallSensitiveVolumeV, 1, wall_position);
236
237 // Adding the wall mother volume to the global TOP Volume
238 // TGeoTranslation *wallWALL = new TGeoTranslation("wallWALL",WALL_Xpos, WALL_Ypos, WALL_center_Zpos);
239
240 TGeoRotation* rot = new TGeoRotation("rot");
241 rot->RotateY(rotY);
242 TGeoCombiTrans* wallWALL = new TGeoCombiTrans("wallWALL", WALL_Xpos, WALL_Ypos, WALL_center_Zpos, rot);
243 ZDC_common->AddNode(WALLV, 1, wallWALL); // WALL right
244
245 /*
246 TGeoRotation *rotWALL = new TGeoRotation();
247 rotWALL->RotateY(30.);
248 TGeoCombiTrans *wallWALL2 = new TGeoCombiTrans(WALL_Xpos, WALL_Ypos, -WALL_center_Zpos, rotWALL);
249 WALL_common->AddNode(WALLV, 2, wallWALL2);//WALL left
250 */
251
252 // top->AddNode(WALL_common, 0);
253 top->AddNode(ZDC_common, 0);
254
256
257 // --------------- Finish ----------------------------------------------
258 gGeoManager->CloseGeometry();
259 gGeoManager->CheckOverlaps(0.001);
260 gGeoManager->PrintOverlaps();
261
262 gGeoManager->Test();
263
264 TFile* geoFile = new TFile(geoFileName, "RECREATE");
265 top->Write();
266 geoFile->Close();
267
268 // TString gdmlname = gPath + "/geometry/tpc_v7.gdml";
269 // gGeoManager->Export(gdmlname);
270
271 // top->Draw("ogl");
272 // TGLViewer *v = (TGLViewer*)gPad->GetViewer3D();
273 // v->SetStyle(TGLRnrCtx::kOutline);
274 // top->Draw("");
275
276} // create_rootgeom_zdc_v1
int Int_t
double Double_t
constexpr Bool_t kTRUE
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 RotateY(Double_t angle) override
void SetVisContainers(Bool_t flag=kTRUE) override
virtual TGeoNode * AddNode(TGeoVolume *vol, Int_t copy_no, TGeoMatrix *mat=nullptr, Option_t *option="")
virtual void SetMedium(TGeoMedium *medium)
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
void bmnloadlibs()
Definition bmnloadlibs.C:4
void create_rootgeom_wall_oldnames_vacuum_zdc_270x120cm(Double_t WALL_Xpos=0, Double_t WALL_Ypos=0, Double_t WALL_Zpos=900, Double_t rotY=0)
void DefineRequiredMedia(FairGeoMedia *geoMedia, FairGeoBuilder *geoBuild)
Double_t Abs(Double_t d)