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