BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_rootgeom_bmnzdc_104mods_v1.C
Go to the documentation of this file.
1//---------------------------
2// M.Golubeva (INR RAS), February 2019
3// S.Morozov (INR RAS), April 2019 (code optimisation)
4//---------------------------
5
6#include "../run/bmnloadlibs.C"
7#include "TFile.h"
8#include "TGeoManager.h"
9#include "TGeoMedium.h"
10#include "TGeoVolume.h"
11
12// Detector's construct parameters ===================
13
15
16// Global dimensions for ZDC in cm
17Double_t Zdc_X_size = 82.5; // 165./2.
18Double_t Zdc_Y_size = 52.5; // 105./2.
19Double_t Zdc_Z_size = 52.5; // 68 scint
20
21Double_t Zdc_X_size_small = 22.5; // 45./2. //small mods
22Double_t Zdc_Y_size_small = 22.5; // 45./2.
23
24// Modules small //small modules
30
31// Modules //large modules
36Double_t Zdc_module_Z_size = 52.5; // 105./2.
37
38// media ============================================
46
47class FairGeoMedia;
48class FairGeoBuilder;
49
50void DefineRequiredMedia(FairGeoMedia* geoMedia, FairGeoBuilder* geoBuild)
51{
52 // vacuum medium
53 FairGeoMedium* mVacuum = geoMedia->getMedium("vacuum");
54 if (!mVacuum)
55 Fatal("Main", "FairMedium vacuum not found");
56 geoBuild->createMedium(mVacuum);
57 pMedVacuum = gGeoManager->GetMedium("vacuum");
58 if (!pMedVacuum)
59 Fatal("Main", "Medium vacuum not found");
60
61 // air medium
62 FairGeoMedium* mAir = geoMedia->getMedium("air");
63 if (!mAir)
64 Fatal("Main", "FairMedium air not found");
65 geoBuild->createMedium(mAir);
66 pMedAir = gGeoManager->GetMedium("air");
67 if (!pMedAir)
68 Fatal("Main", "Medium air not found");
69
70 // iron medium
71 FairGeoMedium* mIron = geoMedia->getMedium("iron");
72 if (!mIron)
73 Fatal("Main", "FairMedium iron not found");
74 geoBuild->createMedium(mIron);
75 pMedIron = gGeoManager->GetMedium("iron");
76 if (!pMedIron)
77 Fatal("Main", "Medium iron not found");
78
79 // tyvec medium
80 FairGeoMedium* mTyvec = geoMedia->getMedium("tyvec_ZDC");
81 if (!mTyvec)
82 Fatal("Main", "FairMedium tyvec_ZDC not found");
83 geoBuild->createMedium(mTyvec);
84 pMedTyvec = gGeoManager->GetMedium("tyvec_ZDC");
85 if (!pMedTyvec)
86 Fatal("Main", "Medium tyvec not found");
87
88 // lead medium
89 FairGeoMedium* mLead = geoMedia->getMedium("lead");
90 if (!mLead)
91 Fatal("Main", "FairMedium lead not found");
92 geoBuild->createMedium(mLead);
93 pMedLead = gGeoManager->GetMedium("lead");
94 if (!pMedLead)
95 Fatal("Main", "Medium lead not found");
96
97 // medium polystyrene (Scint.)
98 FairGeoMedium* mPolystyrene = geoMedia->getMedium("polystyrene");
99 if (!mPolystyrene)
100 Fatal("Main", "FairMedium polystyrene not found");
101 geoBuild->createMedium(mPolystyrene);
102 pMedScint = gGeoManager->GetMedium("polystyrene");
103 if (!pMedScint)
104 Fatal("Main", "Medium polystyrene not found");
105
106 /*
107 // medium FscScint (Scint.)
108 FairGeoMedium* mPolystyrene = geoMedia->getMedium("FscScint");
109 if ( ! mPolystyrene ) Fatal("Main", "FairMedium FscScint not found");
110 geoBuild->createMedium(mPolystyrene);
111 pMedScint = gGeoManager->GetMedium("FscScint");
112 if ( ! pMedScint ) Fatal("Main", "Medium FscScint not found");
113 */
114
115 // medium plastic (slot)
116 FairGeoMedium* mPlastic = geoMedia->getMedium("plasticWLS_ZDC");
117 if (!mPlastic)
118 Fatal("Main", "FairMedium plastic not found");
119 geoBuild->createMedium(mPlastic);
120 pMedSlot = gGeoManager->GetMedium("plasticWLS_ZDC");
121 if (!pMedSlot)
122 Fatal("Main", "Medium plasticWLS_ZDC not found");
123
124} // DefineRequiredMedia
125
126void FillModule_small(TGeoVolume* zdcModuleV_small); // small modules
127void FillModule(TGeoVolume* zdcModuleV); // large modules
128
129void create_rootgeom_bmnzdc_104mods_v1(Double_t ZDC_Xpos = 0, Double_t ZDC_Ypos = 0, Double_t ZDC_Zpos = 900)
130{
131
132 bmnloadlibs(); // load libraries
133
134 // ---- set working directory --------------------------------------------
135 TString gPath = gSystem->Getenv("VMCWORKDIR");
136
137 // ------- Geometry file name (output) ---------------------------------
138 const TString geoDetectorName = "rootgeom_bmnzdc_104mods";
139 const TString geoDetectorVersion = "v1";
140 Double_t ZDC_center_Zpos = ZDC_Zpos + Zdc_Z_size; // cm
141 TString sXshift = "";
142 TString sYshift = "";
143 TString sZshift = "";
144 Int_t Xshift = Int_t(ZDC_Xpos * 10.); // mm
145 Int_t Yshift = Int_t(ZDC_Ypos * 10.); // mm
146 Int_t Zshift = Int_t(ZDC_Zpos * 10.); // mm
147 sXshift += Xshift;
148 sYshift += Yshift;
149 sZshift += Zshift;
150 TString geoFileName = gPath + "/geometry/" + geoDetectorName + "_" + geoDetectorVersion + "_" + "Zpos_" + sZshift
151 + "mm" + "_" + "Xshift_" + sXshift + "mm" + "_" + "Yshift_" + sYshift + "mm" + ".root";
152 // -------------------------------------------------------------------------
153
154 // ---- global geometry parameters ---------------------------------------
155 FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader");
156 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
157
158 // ------- Load media from media file ----------------------------------
159 TString medFile = gPath + "/geometry/media.geo";
160 geoFace->setMediaFile(medFile);
161 geoFace->readMedia();
162 FairGeoMedia* geoMedia = geoFace->getMedia();
163 FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
164 geoMedia->list();
165 geoMedia->print();
166 DefineRequiredMedia(geoMedia, geoBuild);
167 // -------------------------------------------------------------------------
168
169 // -------------- Create geometry and global top volume -------------
170 gGeoManager = (TGeoManager*)gROOT->FindObject("FAIRGeom");
171 gGeoManager->SetName(geoDetectorName + "_geom");
172 TGeoVolume* top = new TGeoVolumeAssembly("TOP");
173 top->SetMedium(pMedAir);
174 gGeoManager->SetTopVolume(top);
175 // gGeoMan->SetTopVisible(1);
176 // ------------------------------------------------------------------------
177
178 // Define ZDC Geometry
179 TString zdc_common_name = "ZDC_common";
180 TGeoVolume* ZDC_common = new TGeoVolumeAssembly(zdc_common_name);
181 ZDC_common->SetMedium(pMedAir);
182 // ZDC_common->SetMedium(pMedVacuum);
183
184 TString zdc_name = "zdc01";
185 TGeoBBox* ZDCS = new TGeoBBox(zdc_name, Zdc_X_size, Zdc_Y_size, Zdc_Z_size);
186 TGeoVolume* ZDCV = new TGeoVolume(zdc_name, ZDCS);
187 ZDCV->SetMedium(pMedAir);
188
189 TString zdcModule_name = "zdc01m"; // large mods
190 TGeoBBox* zdcModuleS = new TGeoBBox(zdcModule_name, Zdc_module_X_size, Zdc_module_Y_size, Zdc_module_Z_size);
191 TGeoVolume* zdcModuleV = new TGeoVolume(zdcModule_name, zdcModuleS);
192 zdcModuleV->SetMedium(pMedIron);
193
194 TString zdcModule_name_small = "zdc01m_small"; // small mods
195 TGeoBBox* zdcModuleS_small =
197 TGeoVolume* zdcModuleV_small = new TGeoVolume(zdcModule_name_small, zdcModuleS_small);
198 zdcModuleV_small->SetMedium(pMedIron);
199
200 cout << "ZDC_pos " << ZDC_Xpos << " " << ZDC_Ypos << endl;
201
202 int iMod = 0;
203
204 for (int i = 0; i < 77; i++) {
205 int iCol = i / 7;
206 int iRow = i % 7;
207 if ((i >= 30 && i <= 32) || (i >= 37 && i <= 39) || (i >= 44 && i <= 46))
208 continue;
209 Double_t xMod = 75. - 15. * iCol;
210 Double_t yMod = -45. + 15. * iRow;
211 TGeoTranslation* zdcModuleV_position = new TGeoTranslation(xMod, yMod, 0.);
212 ZDCV->AddNode(zdcModuleV, iMod + 1, zdcModuleV_position);
213 std::cout << "iMod = " << iMod + 1 << " at " << xMod << ", " << yMod << std::endl;
214 iMod++;
215 }
216
217 for (int i = 0; i < 36; i++) {
218 int iCol = i / 6;
219 int iRow = i % 6;
220 Double_t xMod = 18.75 - 7.5 * iCol;
221 Double_t yMod = -18.75 + 7.5 * iRow;
222 TGeoTranslation* zdcModuleV_position = new TGeoTranslation(xMod, yMod, 0.);
223 ZDCV->AddNode(zdcModuleV_small, iMod + 1, zdcModuleV_position);
224 std::cout << "iMod = " << iMod + 1 << " at " << xMod << ", " << yMod << std::endl;
225 iMod++;
226 }
227
228 // Fill module with Fe-Sc-Lead slices
229 FillModule_small(zdcModuleV_small);
230 FillModule(zdcModuleV);
231
232 // Adding the zdc mother volume to the global TOP Volume
233 TGeoTranslation* zdcZDC = new TGeoTranslation("zdcZDC", ZDC_Xpos, ZDC_Ypos, ZDC_center_Zpos);
234 ZDC_common->AddNode(ZDCV, 1, zdcZDC); // ZDC
235
236 top->AddNode(ZDC_common, 0);
238
239 // --------------- Finish ----------------------------------------------
240 gGeoManager->CloseGeometry();
241 gGeoManager->CheckOverlaps(0.001);
242 gGeoManager->PrintOverlaps();
243
244 gGeoManager->Test();
245
246 TFile* geoFile = new TFile(geoFileName, "RECREATE");
247 top->Write();
248 geoFile->Close();
249
250 // TString gdmlname = gPath + "/geometry/zdc_v1.gdml";
251 // gGeoManager->Export(gdmlname);
252
253 // top->Draw("ogl");
254 // TGLViewer *v = (TGLViewer*)gPad->GetViewer3D();
255 // v->SetStyle(TGLRnrCtx::kOutline);
256 // top->Draw("");
257
258} // create_rootgeom_zdc_v1
259
260void FillModule(TGeoVolume* mother_volume)
261{
262
263 // Fe slices //large modules
264 Double_t Zdc_Fe_X_size = 7.3; //(15.-2.*0.2)/2.
265 Double_t Zdc_Fe_Y_size = 7.3; //(15.-2.*0.2)/2.
266 Double_t Zdc_Fe_Z_size = 1.; // 2./2.
267
268 // Pb slices //large modules
269 Double_t Zdc_Pb_X_size = 7.3; //(15.-2.*0.2)/2.
270 Double_t Zdc_Pb_Y_size = 7.1; //(15.-2.*0.2-0.4)/2.
271 Double_t Zdc_Pb_Z_size = 0.5; // 1./2.
272
273 // Scin. slices //large modules
274 Double_t Zdc_Sc_X_size = 7.3; //(15.-2.*0.2)/2.
275 Double_t Zdc_Sc_Y_size = 7.1; //(15.-2.*0.2-0.4)/2.
276 Double_t Zdc_Sc_Z_size = 0.25; // 0.5/2.
277
278 Double_t Zdc_Y_Pb_Sc_position = -0.2;
279
280 // Slot slices (divided by 2)
281 Double_t Zdc_VRMM_X_size = 7.3; // Mod
282 Double_t Zdc_VRMM_Y_size = 0.2;
283 Double_t Zdc_VRMM_Z_size = 50.5;
284
285 Double_t Zdc_Y_slot_position;
286 Zdc_Y_slot_position = Zdc_Fe_Y_size - Zdc_VRMM_Y_size; // 7.1
287 cout << "Zdc_Y_slot_position " << Zdc_Y_slot_position << endl;
288
289 TString Fe_name = "Fe";
290 TString Pb_name = "zdc01a";
291 TString SensitiveVolume_name = "zdc01s";
292 TString slot_Mod_name = "Mod_slot";
293
294 // Shapes
295 TGeoShape* FeS = new TGeoBBox(Fe_name, Zdc_Fe_X_size, Zdc_Fe_Y_size, Zdc_Fe_Z_size);
296 TGeoVolume* FeV = new TGeoVolume(Fe_name, FeS);
297 TGeoMedium* Fe_medium = pMedIron; // set medium
298 if (Fe_medium)
299 FeV->SetMedium(Fe_medium);
300 else
301 Fatal("Main", "Invalid medium for Fe!");
302
303 TGeoShape* PbS = new TGeoBBox(Pb_name, Zdc_Pb_X_size, Zdc_Pb_Y_size, Zdc_Pb_Z_size);
304 TGeoVolume* PbV = new TGeoVolume(Pb_name, PbS);
305 TGeoMedium* Pb_medium = pMedLead; // set medium
306 if (Pb_medium)
307 PbV->SetMedium(Pb_medium);
308 else
309 Fatal("Main", "Invalid medium for Pb!");
310
311 TGeoShape* zdcSensitiveVolumeS = new TGeoBBox(SensitiveVolume_name, Zdc_Sc_X_size, Zdc_Sc_Y_size, Zdc_Sc_Z_size);
312 TGeoVolume* zdcSensitiveVolumeV = new TGeoVolume(SensitiveVolume_name, zdcSensitiveVolumeS);
313 TGeoMedium* Sc_medium = pMedScint; // set medium
314 if (Sc_medium)
315 zdcSensitiveVolumeV->SetMedium(Sc_medium);
316 else
317 Fatal("Main", "Invalid medium for Sc!");
318
319 // Slot shape
320 TGeoShape* slot_ModS = new TGeoBBox(slot_Mod_name, Zdc_VRMM_X_size, Zdc_VRMM_Y_size, Zdc_VRMM_Z_size);
321 TGeoVolume* slot_ModV = new TGeoVolume(slot_Mod_name, slot_ModS);
322 TGeoMedium* slot_Mod_medium = pMedSlot; // set medium
323 if (slot_Mod_medium)
324 slot_ModV->SetMedium(slot_Mod_medium);
325 else
326 Fatal("Main", "Invalid medium for slot_Mod!");
327
328 Double_t zPos = -Zdc_module_Z_size + Zdc_Fe_Z_size;
329
330 // insert Fe
331 mother_volume->AddNode(FeV, 1, new TGeoTranslation(0, 0, zPos));
332 zPos = zPos + Zdc_Fe_Z_size;
333
334 // insert Mod_slot
335 mother_volume->AddNode(slot_ModV, 1, new TGeoTranslation(0, Zdc_Y_slot_position, 0));
336 slot_ModV->SetLineColor(kBlue);
337
338 // insert 1st Scint
339 zPos = zPos + Zdc_Sc_Z_size;
340 mother_volume->AddNode(zdcSensitiveVolumeV, 1, new TGeoTranslation(0, Zdc_Y_Pb_Sc_position, zPos));
341 cout << "Sc 1 " << zPos << endl;
342 zPos = zPos + Zdc_Sc_Z_size;
343
344 for (Int_t iSlice = 0; iSlice < (nSlicesInModule - 1); iSlice++) {
345
346 // insert Pb
347 zPos = zPos + Zdc_Pb_Z_size;
348 mother_volume->AddNode(PbV, iSlice + 1, new TGeoTranslation(0, Zdc_Y_Pb_Sc_position, zPos));
349 cout << "Pb " << iSlice + 1 << " " << zPos << endl;
350 zPos = zPos + Zdc_Pb_Z_size;
351
352 // insert Sc
353 zPos = zPos + Zdc_Sc_Z_size;
354 mother_volume->AddNode(zdcSensitiveVolumeV, iSlice + 2, new TGeoTranslation(0, Zdc_Y_Pb_Sc_position, zPos));
355 cout << "Sc " << iSlice + 2 << " " << zPos << endl;
356 zPos = zPos + Zdc_Sc_Z_size;
357 }
358
359} // FillModule
360
361void FillModule_small(TGeoVolume* mother_volume_small)
362{
363
364 // Detector's construct parameters ===================
365
366 // Fe slices
367 Double_t Zdc_Fe_X_size = 3.55; //(7.5-2.*0.2)/2.
368 Double_t Zdc_Fe_Y_size = 3.55; //(7.5-2.*0.2)/2.
369 Double_t Zdc_Fe_Z_size = 1.; // 2./2.
370
371 // Pb slices
372 Double_t Zdc_Pb_X_size = 3.55; //(7.5-2.*0.2)/2.
373 Double_t Zdc_Pb_Y_size = 3.35; //(7.5-2.*0.2-0.4)/2.
374 Double_t Zdc_Pb_Z_size = 0.5; // 1./2.
375
376 // Scin. slices
377 Double_t Zdc_Sc_X_size = 3.55; //(7.5-2.*0.2)/2.
378 Double_t Zdc_Sc_Y_size = 3.35; //(7.5-2.*0.2-0.4)/2.
379 Double_t Zdc_Sc_Z_size = 0.25; // 0.5/2.
380
381 Double_t Zdc_Y_Pb_Sc_position = -0.2;
382
383 // Slot slices (divided by 2)
384 Double_t Zdc_VRMM_X_size = 3.55;
385 Double_t Zdc_VRMM_Y_size = 0.2;
386 Double_t Zdc_VRMM_Z_size = 50.5;
387
388 Double_t Zdc_Y_slot_position;
389
390 Zdc_Y_slot_position = Zdc_Fe_Y_size - Zdc_VRMM_Y_size; // 3.35
391 cout << "Zdc_Y_slot_position small " << Zdc_Y_slot_position << endl;
392
393 TString Fe_name_small = "Fe_small";
394 TString Pb_name_small = "zdc01a_small";
395 TString SensitiveVolume_name_small = "zdc01s_small";
396 TString slot_Mod_name = "Mod_slot";
397
398 // Shapes
399 TGeoShape* FeS_small = new TGeoBBox(Fe_name_small, Zdc_Fe_X_size, Zdc_Fe_Y_size, Zdc_Fe_Z_size);
400 TGeoVolume* FeV_small = new TGeoVolume(Fe_name_small, FeS_small);
401 TGeoMedium* Fe_medium_small = pMedIron; // set medium
402 if (Fe_medium_small)
403 FeV_small->SetMedium(Fe_medium_small);
404 else
405 Fatal("Main", "Invalid medium for Fe_small!");
406
407 TGeoShape* PbS_small = new TGeoBBox(Pb_name_small, Zdc_Pb_X_size, Zdc_Pb_Y_size, Zdc_Pb_Z_size);
408 TGeoVolume* PbV_small = new TGeoVolume(Pb_name_small, PbS_small);
409 TGeoMedium* Pb_medium_small = pMedLead; // set medium
410 if (Pb_medium_small)
411 PbV_small->SetMedium(Pb_medium_small);
412 else
413 Fatal("Main", "Invalid medium for Pb_small!");
414
415 TGeoShape* zdcSensitiveVolumeS_small =
416 new TGeoBBox(SensitiveVolume_name_small, Zdc_Sc_X_size, Zdc_Sc_Y_size, Zdc_Sc_Z_size);
417 TGeoVolume* zdcSensitiveVolumeV_small = new TGeoVolume(SensitiveVolume_name_small, zdcSensitiveVolumeS_small);
418 TGeoMedium* Sc_medium_small = pMedScint; // set medium
419 if (Sc_medium_small)
420 zdcSensitiveVolumeV_small->SetMedium(Sc_medium_small);
421 else
422 Fatal("Main", "Invalid medium for Sc_small!");
423
424 // Slot's shape
425 TGeoShape* slot_ModS = new TGeoBBox(slot_Mod_name, Zdc_VRMM_X_size, Zdc_VRMM_Y_size, Zdc_VRMM_Z_size);
426 TGeoVolume* slot_ModV = new TGeoVolume(slot_Mod_name, slot_ModS);
427 TGeoMedium* slot_Mod_medium = pMedSlot; // set medium
428 if (slot_Mod_medium)
429 slot_ModV->SetMedium(slot_Mod_medium);
430 else
431 Fatal("Main", "Invalid medium for slot_Mod!");
432
433 Double_t zPos = -Zdc_module_Z_size_small + Zdc_Fe_Z_size;
434
435 // insert Fe
436 mother_volume_small->AddNode(FeV_small, 1, new TGeoTranslation(0, 0, zPos));
437 zPos = zPos + Zdc_Fe_Z_size;
438
439 // insert Mod_slot
440 mother_volume_small->AddNode(slot_ModV, 1, new TGeoTranslation(0, Zdc_Y_slot_position, 0));
441 slot_ModV->SetLineColor(kBlue);
442
443 // insert 1st Scint
444 zPos = zPos + Zdc_Sc_Z_size;
445 mother_volume_small->AddNode(zdcSensitiveVolumeV_small, 1, new TGeoTranslation(0, Zdc_Y_Pb_Sc_position, zPos));
446 cout << "Sc 1 " << zPos << endl;
447 zPos = zPos + Zdc_Sc_Z_size;
448
449 for (Int_t iSlice = 0; iSlice < (nSlicesInModule - 1); iSlice++) {
450
451 // insert Pb
452 zPos = zPos + Zdc_Pb_Z_size;
453 mother_volume_small->AddNode(PbV_small, iSlice + 1, new TGeoTranslation(0, Zdc_Y_Pb_Sc_position, zPos));
454 cout << "Pb " << iSlice + 1 << " " << zPos << endl;
455 zPos = zPos + Zdc_Pb_Z_size;
456
457 // insert Sc
458 zPos = zPos + Zdc_Sc_Z_size;
459 mother_volume_small->AddNode(zdcSensitiveVolumeV_small, iSlice + 2,
460 new TGeoTranslation(0, Zdc_Y_Pb_Sc_position, zPos));
461 cout << "Sc " << iSlice + 2 << " " << zPos << endl;
462 zPos = zPos + Zdc_Sc_Z_size;
463 }
464
465} // FillModule_small
int i
Definition P4_F32vec4.h:22
int Int_t
double Double_t
constexpr Bool_t kTRUE
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="")
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)
TGeoMedium * pMedAir
TGeoMedium * pMedScint
void FillModule_small(TGeoVolume *zdcModuleV_small)
Double_t Zdc_X_size_small
Double_t Zdc_module_X_size
TGeoMedium * pMedTyvec
TGeoMedium * pMedSlot
void FillModule(TGeoVolume *zdcModuleV)
TGeoMedium * pMedLead
Double_t Zdc_NColumns_small
Double_t Zdc_module_Y_size
Double_t Zdc_module_Z_size_small
TGeoMedium * pMedIron
void DefineRequiredMedia(FairGeoMedia *geoMedia, FairGeoBuilder *geoBuild)
TGeoMedium * pMedVacuum
Double_t Zdc_module_Y_size_small
Double_t Zdc_module_X_size_small
Double_t Zdc_Y_size_small
Double_t Zdc_module_Z_size
void create_rootgeom_bmnzdc_104mods_v1(Double_t ZDC_Xpos=0, Double_t ZDC_Ypos=0, Double_t ZDC_Zpos=900)