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