BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_rootgeom_wall_oldnames_vacuum_zdc_12x12cm.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
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 = 829.6,
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_oldnames_vacuum_zdc_12x12cm";
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_1 = "";
112 TString sYshift_2 = "";
113 // TString sYshift_3 = "";
114
115 TString sZshift_1 = "";
116 TString sZshift_2 = "";
117
118 TString sRotY_1 = "";
119 TString sRotY_2 = "";
120
121 Int_t Xshift_1 = Int_t(WALL_Xpos); // cm
122 // Int_t Xshift_2 = Int_t(0.1+10*(WALL_Xpos-Int_t(WALL_Xpos))); //cm
123 // Int_t Xshift_2 = Int_t(0.5+100*(WALL_Xpos-Int_t(WALL_Xpos))); //cm
124 // Int_t Xshift_2 = Int_t(0.5+100*(TMath::Abs(WALL_Xpos)-Int_t(TMath::Abs(WALL_Xpos)))); //cm
125 Int_t Xshift_2 = Int_t(0.5 + 1000 * (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 Int_t Xshift_3 = 0; // cm
131
132 Int_t Yshift_1 = Int_t(WALL_Ypos); // cm
133 // Int_t Yshift_2 = Int_t(100*(WALL_Ypos-Int_t(WALL_Ypos)))+1; //cm
134 // Int_t Yshift_2 = Int_t(100*(WALL_Ypos-Int_t(WALL_Ypos))); //cm
135 Int_t Yshift_2 = Int_t(1000 * (WALL_Ypos - Int_t(WALL_Ypos))); // cm
136
137 Int_t Zshift_1 = Int_t(WALL_Zpos); // cm
138 // Int_t Zshift_2 = Int_t(100*(WALL_Zpos-Int_t(WALL_Zpos))); //cm
139 // Int_t Zshift_2 = Int_t(100*(WALL_Zpos-Int_t(WALL_Zpos)))+1; //cm
140 // Int_t Zshift_2 = Int_t(10*(WALL_Zpos-Int_t(WALL_Zpos)))+1; //cm
141 // Int_t Zshift_2 = Int_t(10*(WALL_Zpos-Int_t(WALL_Zpos))); //cm
142 // Int_t Zshift_2 = Int_t(1000*(WALL_Zpos-Int_t(WALL_Zpos)))+1; //cm
143 Int_t Zshift_2 = Int_t(1000 * (WALL_Zpos - Int_t(WALL_Zpos))); // cm
144
145 cout << "Zshift_1,Zshift_2 " << Zshift_1 << " " << 10 * (WALL_Zpos - Int_t(WALL_Zpos)) << " " << Zshift_2 << endl;
146
147 Int_t rotY_1 = Int_t(rotY); // 2 from 2.9
148 // Int_t rotY_2 = Int_t(100*(rotY-Int_t(rotY)));//9 from 2.9
149 // Int_t rotY_2 = Int_t(100*(rotY-Int_t(rotY)))+1;//9 from 2.9
150 Int_t rotY_2 = TMath::Abs(Int_t(100 * (rotY - Int_t(rotY)))) + 1; // 9 from 2.9
151 // Int_t rotY_2 = TMath::Abs(Int_t(100*(rotY-Int_t(rotY))));//9 from 2.9
152 // Int_t rotY_2 = TMath::Abs(Int_t(10*(rotY-Int_t(rotY))));
153
154 sXshift_1 += Xshift_1;
155 sXshift_2 += Xshift_3;
156 sXshift_2 += Xshift_2;
157 sYshift_1 += Yshift_1;
158 sYshift_2 += Yshift_2;
159 sZshift_1 += Zshift_1;
160 sZshift_2 += Zshift_2;
161
162 sRotY_1 += rotY_1;
163 sRotY_2 += rotY_2;
164
165 // TString geoFileName = gPath + "/geometry/" + geoDetectorName + "_" + "Zpos_" + sZshift + "mm" + "_" + "Xshift_" +
166 // sXshift + "mm" + "_" + "Yshift_" + sYshift + "mm" + "_" + geoDetectorVersion + ".root";
167 TString geoFileName = gPath + "/geometry/" + geoDetectorName + "_" + "Zpos_" + sZshift_1 + "." + sZshift_2 + "cm"
168 + "_" + "Xshift_" + sXshift_1 + "." + sXshift_2 + "cm" + "_" + "Yshift_" + sYshift_1 + "."
169 + sYshift_2 + "cm" + "_" + "rotationY_" + sRotY_1 + "." + sRotY_2 + "deg_"
170 + geoDetectorVersion + ".root";
171 // TString geoFileName = gPath + "/geometry/" + geoDetectorName + "_" + "Zpos_" + sZshift_1 + "." + sZshift_2 + "cm"
172 // + "_" + "Xshift_" + sXshift_1 + "." + sXshift_2 + sXshift_3 + "cm" + "_" + "Yshift_" + sYshift_1 + "." +
173 // sYshift_2 + "cm" + "_" + "rotationY_" + sRotY_1 + "." + sRotY_2 + "deg_" + geoDetectorVersion + ".root";
174 // -------------------------------------------------------------------------
175
176 // ---- global geometry parameters ---------------------------------------
177 FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader");
178 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
179
180 // ------- Load media from media file ----------------------------------
181 TString medFile = gPath + "/geometry/media.geo";
182 geoFace->setMediaFile(medFile);
183 geoFace->readMedia();
184 FairGeoMedia* geoMedia = geoFace->getMedia();
185 FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
186 // geoMedia->list();
187 // geoMedia->print();
188 DefineRequiredMedia(geoMedia, geoBuild);
189 // -------------------------------------------------------------------------
190
191 // -------------- Create geometry and global top volume ------------------------
192 gGeoManager = (TGeoManager*)gROOT->FindObject("FAIRGeom");
193 gGeoManager->SetName(geoDetectorName + "_geom");
194 TGeoVolume* top = new TGeoVolumeAssembly("TOP");
195 top->SetMedium(pMedAir);
196 // top->SetMedium(pMedVacuum);
197 gGeoManager->SetTopVolume(top);
198 // gGeoMan->SetTopVisible(1);
199 // --------------------------------------------------------------------------
200
201 // Define WALL Geometry
202 // TString wall_common_name = "WALL_common";
203 TString wall_common_name = "ZDC_common";
204 TGeoVolume* ZDC_common = new TGeoVolumeAssembly(wall_common_name);
205 ZDC_common->SetMedium(pMedAir);
206 // HO_common->SetMedium(pMedVacuum);
207
208 TString wall_name = "zdc01";
209 // TGeoTube *WALLS = new TGeoTube(wall_name, Wall_inner_radius, Wall_outer_radius, Wall_Z_size);
210 TGeoBBox* WALLS = new TGeoBBox(wall_name, Wall_X_size, Wall_Y_size, Wall_Z_size);
211 TGeoVolume* WALLV = new TGeoVolume(wall_name, WALLS);
212 // WALLV->SetMedium(pMedAir);
213 WALLV->SetMedium(pMedVacuum);
214 // WALLV->SetMedium(pMedScint);
215
216 TString wallSensitive_name = "zdc01s";
217 // TGeoTube *wallSensitiveVolumeS = new TGeoTube(wallSensitive_name, Wall_inner_radius, Wall_outer_radius,
218 // Wall_Z_size);
219 TGeoBBox* wallSensitiveVolumeS = new TGeoBBox(wallSensitive_name, Wall_X_size, Wall_Y_size, Wall_Z_size);
220 TGeoVolume* wallSensitiveVolumeV = new TGeoVolume(wallSensitive_name, wallSensitiveVolumeS);
221 // wallSensitiveVolumeV->SetMedium(pMedScint);
222 wallSensitiveVolumeV->SetMedium(pMedVacuum);
223
224 // insert wallSensitiveVolumeV into WALLV
225 TGeoTranslation* wall_position = new TGeoTranslation(0., 0., 0.);
226 WALLV->AddNode(wallSensitiveVolumeV, 1, wall_position);
227
228 // Adding the wall mother volume to the global TOP Volume
229 // TGeoTranslation *wallWALL = new TGeoTranslation("wallWALL",WALL_Xpos, WALL_Ypos, WALL_center_Zpos);
230
231 TGeoRotation* rot = new TGeoRotation("rot");
232 rot->RotateY(rotY);
233 TGeoCombiTrans* wallWALL = new TGeoCombiTrans("wallWALL", WALL_Xpos, WALL_Ypos, WALL_center_Zpos, rot);
234 ZDC_common->AddNode(WALLV, 1, wallWALL); // WALL right
235
236 /*
237 TGeoRotation *rotWALL = new TGeoRotation();
238 rotWALL->RotateY(30.);
239 TGeoCombiTrans *wallWALL2 = new TGeoCombiTrans(WALL_Xpos, WALL_Ypos, -WALL_center_Zpos, rotWALL);
240 WALL_common->AddNode(WALLV, 2, wallWALL2);//WALL left
241 */
242
243 // top->AddNode(WALL_common, 0);
244 top->AddNode(ZDC_common, 0);
245
247
248 // --------------- Finish ----------------------------------------------
249 gGeoManager->CloseGeometry();
250 gGeoManager->CheckOverlaps(0.001);
251 gGeoManager->PrintOverlaps();
252
253 gGeoManager->Test();
254
255 TFile* geoFile = new TFile(geoFileName, "RECREATE");
256 top->Write();
257 geoFile->Close();
258
259 // TString gdmlname = gPath + "/geometry/tpc_v7.gdml";
260 // gGeoManager->Export(gdmlname);
261
262 // top->Draw("ogl");
263 // TGLViewer *v = (TGLViewer*)gPad->GetViewer3D();
264 // v->SetStyle(TGLRnrCtx::kOutline);
265 // top->Draw("");
266
267} // 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_12x12cm(Double_t WALL_Xpos=0, Double_t WALL_Ypos=0, Double_t WALL_Zpos=829.6, Double_t rotY=0)
void DefineRequiredMedia(FairGeoMedia *geoMedia, FairGeoBuilder *geoBuild)
Double_t Abs(Double_t d)