BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_rootgeom_TOF700_run7_with_support.C
Go to the documentation of this file.
1#include "../run/bmnloadlibs.C"
2//---------------------------
3
4#define TOF2_MAX_CHAMBERS 59
5#define TOF2_MAX_STRIPS_IN_CHAMBER 32
6
23
24// Number of chambers
26
27// Detector's construct parameters
39
41
45
46int readGeom(char* geomfile);
48
50{
51
52 // Load the necessary FairRoot libraries
53#if ROOT_VERSION_CODE < ROOT_VERSION(5, 99, 99)
54 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
55#endif
56 bmnloadlibs(); // load libraries
57
58 // ------- Load media from media file -----------------------------------
59 FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader");
60 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
61 TString geoPath = gSystem->Getenv("VMCWORKDIR");
62 TString medFile = geoPath + "/geometry/media.geo";
63 geoFace->setMediaFile(medFile);
64 geoFace->readMedia();
66 // ------- Geometry text file name (input) ----------------------------------
67 TOF2_Nmodules = readGeom((char*)"TOF700_geometry_run7.txt");
68 // ------- Geometry file name (output) ----------------------------------
69 TString geoDetectorName = "tof700";
70 TString geoDetectorVersion = "run7_with_support";
71 TString geoFileName = geoPath + "/geometry/" + geoDetectorName + "_" + geoDetectorVersion + ".root";
72 // --------------------------------------------------------------------------
73 // Modules Y centers
74 Double_t dy = 0.;
75 for (int i = 0; i < TOF2_Nmodules; i++) {
76 dy = (ymins[i][nstrips[i] - 1] - ymaxs[i][nstrips[i] - 2]) / 2.;
77 TOF2_X_center[i] = xcens[i][nstrips[i] - 1];
78 TOF2_Y_center[i] = (ycens[i][nstrips[i] - 1] + ycens[i][0]) / 2.;
80 // printf("Chamber %d Z = %f\n", i+1, TOF2_Z_center[i]);
82 YActWidthOfModule_TOF2[chtype[i]] = ymaxs[i][nstrips[i] - 1] - ymins[i][0] + dy;
83 XWidthOfModule_TOF2[chtype[i]] = xmaxs[i][0] - xmins[i][0] + 3.0;
84 YWidthOfModule_TOF2[chtype[i]] = ymaxs[i][nstrips[i] - 1] - ymins[i][0] + dy + 3.0;
85 }
86 // Container size calculations
87 Double_t xmin = 10000., ymin = 10000., zmin = 10000.;
88 Double_t xmax = -10000., ymax = -10000., zmax = -10000.;
89 for (int i = 0; i < TOF2_Nmodules; i++) {
90 if (TOF2_X_center[i] < xmin)
91 xmin = TOF2_X_center[i];
92 if (TOF2_Y_center[i] < ymin)
93 ymin = TOF2_Y_center[i];
94 if (TOF2_Z_center[i] < zmin)
95 zmin = TOF2_Z_center[i];
96 if (TOF2_X_center[i] > xmax)
97 xmax = TOF2_X_center[i];
98 if (TOF2_Y_center[i] > ymax)
99 ymax = TOF2_Y_center[i];
100 if (TOF2_Z_center[i] > zmax)
101 zmax = TOF2_Z_center[i];
102 }
103 Double_t TOF2_X_min = xmin - XWidthOfModule_TOF2[1] / 2.;
104 Double_t TOF2_Y_min = ymin - YWidthOfModule_TOF2[1] / 2.;
105 Double_t TOF2_Z_min = zmin - ZWidthOfModule_TOF2 / 2.;
106 Double_t TOF2_X_max = xmax + XWidthOfModule_TOF2[1] / 2.;
107 Double_t TOF2_Y_max = ymax + YWidthOfModule_TOF2[1] / 2.;
108 Double_t TOF2_Z_max = zmax + ZWidthOfModule_TOF2 / 2.;
109
110 Double_t TOF2_XWidth =
111 TMath::Abs(TOF2_X_max) > TMath::Abs(TOF2_X_min) ? (2 * TMath::Abs(TOF2_X_max)) : (2 * TMath::Abs(TOF2_X_min));
112 Double_t TOF2_YWidth =
113 TMath::Abs(TOF2_Y_max) > TMath::Abs(TOF2_Y_min) ? (2 * TMath::Abs(TOF2_Y_max)) : (2 * TMath::Abs(TOF2_Y_min));
114 Double_t TOF2_ZWidth =
115 TMath::Abs(TOF2_Z_max) > TMath::Abs(TOF2_Z_min) ? (2 * TMath::Abs(TOF2_Z_max)) : (2 * TMath::Abs(TOF2_Z_min));
116
117 Double_t TOF2_X = (TOF2_X_max + TOF2_X_min) / 2.; // + TOF2_Xpos;
118 Double_t TOF2_Y = (TOF2_Y_max + TOF2_Y_min) / 2.; // + TOF2_Ypos;
119 Double_t TOF2_Z = (TOF2_Z_max + TOF2_Z_min) / 2.; // + TOF2_Zpos;
120
121 // ----------------- Get and create the required media -----------------
122 FairGeoMedia* geoMedia = geoFace->getMedia();
123 FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
124
125 FairGeoMedium* mAir = geoMedia->getMedium("air");
126 if (!mAir)
127 Fatal("Main", "FairMedium air not found");
128 geoBuild->createMedium(mAir);
129 pMedAir = gGeoMan->GetMedium("air");
130 if (!pMedAir)
131 Fatal("Main", "Medium air not found");
132
133 FairGeoMedium* mRPCglass = geoMedia->getMedium("RPCglass");
134 if (!mRPCglass)
135 Fatal("Main", "FairMedium RPCglass not found");
136 geoBuild->createMedium(mRPCglass);
137 TGeoMedium* pMedRPCglass = gGeoMan->GetMedium("RPCglass");
138 if (!pMedRPCglass)
139 Fatal("Main", "Medium RPCglass not found");
140
141 FairGeoMedium* mRPCgas = geoMedia->getMedium("RPCgas");
142 if (!mRPCgas)
143 Fatal("Main", "FairMedium RPCgas not found");
144 geoBuild->createMedium(mRPCgas);
145 TGeoMedium* pMedRPCgas = gGeoMan->GetMedium("RPCgas");
146 if (!pMedRPCgas)
147 Fatal("Main", "Medium RPCgas not found");
148
149 // aluminium
150 FairGeoMedium* matAl = geoMedia->getMedium("aluminium");
151 if (!matAl)
152 Fatal("Main", "FairMedium aluminium not found");
153 geoBuild->createMedium(matAl);
154 medAl = gGeoMan->GetMedium("aluminium");
155 if (!medAl)
156 Fatal("Main", "Medium aluminium not found");
157
158 // G10
159 FairGeoMedium* matG10 = geoMedia->getMedium("G10");
160 if (!matG10)
161 Fatal("Main", "FairMedium G10 not found");
162 geoBuild->createMedium(matG10);
163 TGeoMedium* medG10 = gGeoMan->GetMedium("G10");
164 if (!medG10)
165 Fatal("Main", "Medium G10 not found");
166
167 // --------------------------------------------------------------------------
168
169 // -------------- Create geometry and top volume -------------------------
170 gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
171 gGeoMan->SetName(geoDetectorName + "_geom");
172 TGeoVolume* top = new TGeoVolumeAssembly("TOP");
173 top->SetMedium(pMedAir);
174 gGeoMan->SetTopVolume(top);
175 // gGeoMan->SetTopVisible(1);
176 // --------------------------------------------------------------------------
177
178 // Define TOP Geometry
179 TOF2Top = new TGeoVolumeAssembly(geoDetectorName);
180 TOF2Top->SetMedium(pMedAir);
181
182 // Transformations (translations, rotations and scales)
183 // TGeoTranslation *DetPos_trans = new TGeoTranslation("DetPos_trans", xoffs, yoffs, zoffs);
184 // DetPos_trans->RegisterYourself();
185 TGeoTranslation* ModulePosTOF2_trans[TOF2_MAX_CHAMBERS] = {NULL};
186 TGeoTranslation* LayerPosTOF2_trans = 0;
187 char name[64];
188 for (int i = 0; i < TOF2_Nmodules; i++) {
189 sprintf(name, "Module_%d_PosTOF2_trans", i + 1);
190 ModulePosTOF2_trans[i] = new TGeoTranslation(name, TOF2_X_center[i], TOF2_Y_center[i], TOF2_Z_center[i]);
191 // ModulePosTOF2_trans[i]->RegisterYourself();
192 }
194 sprintf(name, "GlassLayer1PosTOF2_trans");
195 TGeoTranslation* GlassLayer1PosTOF2_trans = new TGeoTranslation(name, 0., 0., GlassLayer1Pos);
196 Double_t GasLayerPos =
198 sprintf(name, "GasLayerPosTOF2_trans");
199 TGeoTranslation* GasLayerPosTOF2_trans = new TGeoTranslation(name, 0., 0., GasLayerPos);
202 sprintf(name, "GlassLayer2PosTOF2_trans");
203 TGeoTranslation* GlassLayer2PosTOF2_trans = new TGeoTranslation(name, 0., 0., GlassLayer2Pos);
206 sprintf(name, "G10LayerPosTOF2_trans");
207 TGeoTranslation* G10LayerPosTOF2_trans = new TGeoTranslation(name, 0., 0., G10LayerPos);
208
209 // Solids (shapes)
210 // TGeoBBox *TOF2ContainerS = new TGeoBBox("TOF2ContainerS", TOF2_XWidth/2, TOF2_YWidth/2, TOF2_ZWidth/2);
211 // TGeoVolume *TOF2ContainerV = new TGeoVolume("TOF2ContainerV", TOF2ContainerS);
212 // TOF2ContainerV->SetMedium(pMedAir);
213 // TOF2ContainerV->SetVisibility(kFALSE);
214 // top->AddNode(TOF2Top, 1, DetPos_trans);
215 // TOF2Top->AddNode(TOF2ContainerV, 1, ContainerPos_trans);
216 // TOF2Top->AddNode(TOF2ContainerV, 1);
217
218 char nTOF2ModuleS[2][32] = {"TOF2ChamberS0", "TOF2ChamberS1"};
219 char nTOF2GlassVolumeS[2][32] = {"TOF2GlassVolumeS0", "TOF2GlassVolumeS1"};
220 char nTOF2G10VolumeS[2][32] = {"TOF2G10VolumeS0", "TOF2G10VolumeS1"};
221 char nTOF2ActiveGasVolumeS[2][32] = {"TOF2ActiveGasVolumeS0", "TOF2ActiveGasVolumeS1"};
222 char nTOF2ModuleV[2][32] = {"TOF2ChamberV0", "TOF2ChamberV1"};
223 char nTOF2GlassVolumeV[2][32] = {"TOF2GlassVolumeV0", "TOF2GlassVolumeV1"};
224 char nTOF2G10VolumeV[2][32] = {"TOF2G10VolumeV0", "TOF2G10VolumeV1"};
225 char nTOF2ActiveGasVolumeV[2][32] = {"TOF2ActiveGasVolumeV0", "TOF2ActiveGasVolumeV1"};
226 TGeoBBox* TOF2ModuleS[2];
227 TGeoBBox* TOF2GlassVolumeS[2];
228 TGeoBBox* TOF2ActiveGasVolumeS[2];
229 TGeoBBox* TOF2G10VolumeS[2];
230 TGeoVolume* TOF2ModuleV[2];
231 TGeoVolume* TOF2GlassVolumeV[2];
232 TGeoVolume* TOF2ActiveGasVolumeV[2];
233 TGeoVolume* TOF2G10VolumeV[2];
234
235 int nstr[2] = {32, 16};
236 for (int i = 0; i < 2; i++) {
237 TOF2ModuleS[i] = new TGeoBBox(nTOF2ModuleS[i], XWidthOfModule_TOF2[i] / 2 + 0.001,
238 YWidthOfModule_TOF2[i] / 2 + 0.001, ZWidthOfModule_TOF2 / 2 + 0.001);
239 TOF2GlassVolumeS[i] = new TGeoBBox(nTOF2GlassVolumeS[i], XActWidthOfModule_TOF2[i] / 2,
241 TOF2ActiveGasVolumeS[i] = new TGeoBBox(nTOF2ActiveGasVolumeS[i], XActWidthOfModule_TOF2[i] / 2,
243 TOF2G10VolumeS[i] = new TGeoBBox(nTOF2G10VolumeS[i], XActWidthOfModule_TOF2[i] / 2,
245
246 // Composite solids (shapes)
247
248 // Volumes
249
250 TOF2ModuleV[i] = new TGeoVolume(nTOF2ModuleV[i], TOF2ModuleS[i]);
251 TOF2ModuleV[i]->SetMedium(medAl);
252 TOF2ModuleV[i]->SetLineColor(kBlue);
253 TOF2ModuleV[i]->SetVisibility(kTRUE);
254 // TOF2ModuleV[i]->SetTransparency(80);
255
256 TOF2GlassVolumeV[i] = new TGeoVolume(nTOF2GlassVolumeV[i], TOF2GlassVolumeS[i]);
257 TOF2GlassVolumeV[i]->SetMedium(pMedRPCglass);
258 TOF2GlassVolumeV[i]->SetLineColor(kGreen);
259
260 TOF2ActiveGasVolumeV[i] = new TGeoVolume(nTOF2ActiveGasVolumeV[i], TOF2ActiveGasVolumeS[i]);
261 TOF2ActiveGasVolumeV[i]->SetMedium(pMedRPCgas);
262 TOF2ActiveGasVolumeV[i]->SetLineColor(kYellow);
263 TOF2ActiveGasVolumeV[i]->Divide("ActiveGasStrip", 2, nstr[i], 0, -1);
264
265 TOF2G10VolumeV[i] = new TGeoVolume(nTOF2G10VolumeV[i], TOF2G10VolumeS[i]);
266 TOF2G10VolumeV[i]->SetMedium(medG10);
267 TOF2G10VolumeV[i]->SetLineColor(kMagenta);
268
269 TOF2ModuleV[i]->AddNode(TOF2GlassVolumeV[i], 1, GlassLayer1PosTOF2_trans);
270 TOF2ModuleV[i]->AddNode(TOF2ActiveGasVolumeV[i], 1, GasLayerPosTOF2_trans);
271 TOF2ModuleV[i]->AddNode(TOF2GlassVolumeV[i], 2, GlassLayer2PosTOF2_trans);
272 TOF2ModuleV[i]->AddNode(TOF2G10VolumeV[i], 1, G10LayerPosTOF2_trans);
273 }
274
275 // Adding volumes to the TOP Volume
276 Int_t nm[2] = {0};
277 for (int i = 0; i < TOF2_Nmodules; i++) {
278 // TOF2Top->AddNode(TOF2ModuleV[chtype[i]], nm[chtype[i]]+1, ModulePosTOF2_trans[i]);
279 // nm[chtype[i]]++;
280 TOF2Top->AddNode(TOF2ModuleV[chtype[i]], nm[0] + 1, ModulePosTOF2_trans[i]);
281 nm[0]++;
282 }
283
285
286 top->AddNode(TOF2Top, 0);
288
289 // --------------- Finish -----------------------------------------------
290 gGeoMan->CloseGeometry();
291 gGeoMan->CheckOverlaps(0.001);
292 gGeoMan->PrintOverlaps();
293 gGeoMan->Test();
294
295 TFile* geoFile = new TFile(geoFileName, "RECREATE");
296 top->Write();
297 geoFile->Close();
298 top->Draw("ogl");
299}
300int readGeom(char* geomfile)
301{
302 char fname[128];
303 FILE* fg = 0;
304 char ic[16] = {""};
305 int n = 0;
306 Double_t step, sx, sy, x, y, z;
307 if (strlen(geomfile) == 0) {
308 printf("TOF700 geometry file name not defined!\n");
309 return 0;
310 }
311 TString dir = getenv("VMCWORKDIR");
312 sprintf(fname, "%s/geometry/%s", dir.Data(), geomfile);
313 fg = fopen(fname, "r");
314 if (fg == NULL) {
315 printf("TOF700 geometry file %s open error!\n", fname);
316 return 0;
317 }
318 if (fscanf(fg, "%lf %lf %lf\n", &xoffs, &yoffs, &zoffs) != 3) {
319 printf("Wrong first line in TOF700 geometry file %s\n", fname);
320 return 0;
321 };
322 printf("Zoffs = %f\n", zoffs);
323 for (int i = 0; i < TOF2_MAX_CHAMBERS; i++)
324 nstrips[i] = 0;
325 int c = 0;
326 while (fscanf(fg, "%s %d %lf %lf %lf %lf %lf %lf\n", &ic[0], &n, &step, &sy, &sx, &x, &y, &z) == 8) {
327 strcpy(TOF2_Module_Names[c], ic);
328 halfxwidth[c] = sx / 20.;
329 halfywidth[c] = sy / 20.;
330 zchamb[c] = z / 10. + zoffs;
331 nstrips[c] = n;
332 if (n == 32)
333 chtype[c] = 0;
334 else
335 chtype[c] = 1;
336 for (int ns = n - 1; ns >= 0; ns--) {
337 xcens[c][ns] = -x / 10. + xoffs;
338 ycens[c][ns] = y / 10. + yoffs - (n - ns - 1) * step / 10.;
339 xmins[c][ns] = xcens[c][ns] - halfxwidth[c];
340 xmaxs[c][ns] = xcens[c][ns] + halfxwidth[c];
341 ymins[c][ns] = ycens[c][ns] - halfywidth[c];
342 ymaxs[c][ns] = ycens[c][ns] + halfywidth[c];
343 // printf("C %d S %d %f %f %f %f
344 //%f\n",ic,n,zchamb[c],xmins[c][ns],xmaxs[c][ns],ymins[c][ns],ymaxs[c][ns]);
345 }
346 printf("%s ns=%d step=%f sx=%f sy=%f x=%f y=%f z=%f\n", ic, n, step, sx, sy, x, y, z);
347 c++;
348 if (c >= TOF2_MAX_CHAMBERS)
349 break;
350 }
351 fclose(fg);
352 return c;
353}
#define TOF2_MAX_STRIPS_IN_CHAMBER
#define TOF2_MAX_CHAMBERS
int i
Definition P4_F32vec4.h:22
int Int_t
char Char_t
double Double_t
constexpr Bool_t kTRUE
kGreen
kMagenta
kBlue
kYellow
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
void SetVisibility(Bool_t vis=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 TGeoVolume * Divide(const char *divname, Int_t iaxis, Int_t ndiv, Double_t start, Double_t step, Int_t numed=0, Option_t *option="")
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
const char * Data() const
Double_t YActWidthOfModule_TOF2[2]
Double_t zchamb[TOF2_MAX_CHAMBERS]
Double_t ymins[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
Double_t xcens[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
Double_t xmins[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
Double_t TOF2_X_center[TOF2_MAX_CHAMBERS]
Char_t TOF2_Module_Names[TOF2_MAX_CHAMBERS][8]
Int_t nstrips[TOF2_MAX_CHAMBERS]
Double_t xmaxs[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
Double_t XActWidthOfModule_TOF2[2]
Double_t TOF2_Y_center[TOF2_MAX_CHAMBERS]
Double_t ymaxs[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
Double_t TOF2_Z_center[TOF2_MAX_CHAMBERS]
Double_t ycens[TOF2_MAX_CHAMBERS][TOF2_MAX_STRIPS_IN_CHAMBER]
Double_t halfywidth[TOF2_MAX_CHAMBERS]
Int_t chtype[TOF2_MAX_CHAMBERS]
Double_t halfxwidth[TOF2_MAX_CHAMBERS]
*brief user defined string literal for JSON values *sa std::size_t n
Definition json.hpp:20362
void create_rootgeom_TOF700_run7_with_support()
int readGeom(char *geomfile)
void create_rootgeom_TOF700_support()
Double_t Abs(Double_t d)