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