BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_rootgeom_MWPC_SCAN.C
Go to the documentation of this file.
1#include "TFile.h"
2#include "TGeoBBox.h"
3#include "TGeoManager.h"
4#include "TGeoShape.h"
5#include "TMath.h"
6#include "TString.h"
7
8using namespace TMath;
9
11
12// Number of active planes with wires
13const Int_t NofPlanes = 20;
14
15// Detector's position
16const Double_t MWPC1_Xpos = 0.0;
17const Double_t MWPC1_Ypos = 0.0;
18const Double_t MWPC1_Zpos = 0.0;
19
20// Detector's construct parameters
21const Double_t GapZsize = 1.0; // cm
22const Double_t GapWireOnePlane = 0.25; // cm
23const Double_t GapWireTwoPlanes = GapWireOnePlane / 2.0; // cm // 0.125
24
28
30{
31
32 // Load the necessary FairRoot libraries
33 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
34 bmnloadlibs(); // load libraries
35
36 // ------- Load media from media file -----------------------------------
37 FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader");
38 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
39 TString geoPath = TString(gSystem->Getenv("VMCWORKDIR")) + "/geometry/";
40 TString medFile = geoPath + "media.geo";
41 geoFace->setMediaFile(medFile);
42 geoFace->readMedia();
44 // --------------------------------------------------------------------------
45
46 // ------- Geometry file name (output) ----------------------------------
47 const TString geoDetectorName = "mwpc_scan";
48 const TString geoDetectorVersion = "v1";
49 TString geoFileName = geoPath + geoDetectorName + "_" + geoDetectorVersion + ".root";
50 // --------------------------------------------------------------------------
51
52 // ----------------- Get and create the required media -----------------
53 FairGeoMedia* geoMedia = geoFace->getMedia();
54 FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
55
56 FairGeoMedium* mAir = geoMedia->getMedium("air");
57 if (!mAir)
58 Fatal("Main", "FairMedium air not found");
59 geoBuild->createMedium(mAir);
60 TGeoMedium* pMedAir = gGeoMan->GetMedium("air");
61 if (!pMedAir)
62 Fatal("Main", "Medium air not found");
63
64 FairGeoMedium* mArCO27030 = geoMedia->getMedium("arco27030");
65 if (!mArCO27030)
66 Fatal("Main", "FairMedium arco27030 not found");
67 geoBuild->createMedium(mArCO27030);
68 TGeoMedium* pMedArCO27030 = gGeoMan->GetMedium("arco27030");
69 if (!pMedArCO27030)
70 Fatal("Main", "Medium arco27030 not found");
71
72 // --------------------------------------------------------------------------
73
74 // -------------- Create geometry and top volume -------------------------
75 gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
76 gGeoMan->SetName(geoDetectorName + "_geom");
77 TGeoVolume* top = new TGeoVolumeAssembly("TOP");
78 top->SetMedium(pMedAir);
79 gGeoMan->SetTopVolume(top);
80 // gGeoMan->SetTopVisible(1);
81 // --------------------------------------------------------------------------
82
83 // Define TOP Geometry
84 TGeoVolume* MWPC1Top = new TGeoVolumeAssembly(geoDetectorName);
85 MWPC1Top->SetMedium(pMedAir);
86
87 // Transformations (translations, rotations and scales)
88 TGeoTranslation* DetPos_trans = new TGeoTranslation("DetPos_trans", MWPC1_Xpos, MWPC1_Ypos, MWPC1_Zpos);
89
90 // Solids (shapes)
91
92 // TGeoBBox *MWPC1ContainerS = new TGeoBBox("MWPC1ContainerS", XSizeOfActiveVolume / 2.0 + 1.0,
93 // YSizeOfActiveVolume / 2.0 + 1.0, 0.005 + 0.01);
94 TGeoBBox* MWPC1ActivePlaneS =
95 new TGeoBBox("MWPC1ActivePlaneS", XSizeOfActiveVolume / 2.0, YSizeOfActiveVolume / 2.0, 0.005);
96
97 // Volumes
98 // TGeoVolume *MWPC1ContainerV = new TGeoVolume("MWPC1ContainerV", MWPC1ContainerS);
99 // MWPC1ContainerV->SetMedium(pMedAir);
100 // MWPC1ContainerV->SetVisibility(kTRUE);
101
102 TGeoVolume* MWPC1ActivePlaneV = new TGeoVolume("MWPC1ActivePlaneV", MWPC1ActivePlaneS);
103 MWPC1ActivePlaneV->SetMedium(pMedArCO27030);
104 MWPC1ActivePlaneV->SetLineColor(kBlue);
105
106 // Adding volumes to the TOP Volume
107 top->AddNode(MWPC1Top, 1, DetPos_trans);
108 // MWPC1Top->AddNode(MWPC1ContainerV, 1);
109 const Float_t a = 10.0; // cm
110 const Float_t b = 300.0; // cm
111 for (Int_t iPlane = 1; iPlane <= NofPlanes; ++iPlane) {
112 TGeoTranslation t1(0.0, 0.0, (b - a) / NofPlanes * (iPlane - 1));
113 TGeoRotation r1("r1", 0.0, 0.0, 0.0);
114 MWPC1Top->AddNode(MWPC1ActivePlaneV, iPlane, new TGeoCombiTrans(t1, r1));
115 // MWPC1ContainerV->AddNode(MWPC1ActivePlaneV, iPlane, new TGeoCombiTrans(t1, r1));
116 }
117
119
120 // --------------- Finish -----------------------------------------------
121 gGeoMan->CloseGeometry();
122 gGeoMan->CheckOverlaps(0.001);
123 gGeoMan->PrintOverlaps();
124 gGeoMan->Test();
125
126 TFile* geoFile = new TFile(geoFileName, "RECREATE");
127 top->Write();
128 geoFile->Close();
129 top->Draw("ogl");
130}
int Int_t
float Float_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="")
void Draw(Option_t *option="") override
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)
TGeoManager * gGeoMan
const Double_t XSizeOfActiveVolume
const Double_t GapWireOnePlane
const Double_t YSizeOfActiveVolume
const Double_t ZSizeOfActiveVolume
const Int_t NofPlanes
const Double_t MWPC1_Ypos
const Double_t MWPC1_Xpos
const Double_t GapZsize
const Double_t MWPC1_Zpos
const Double_t GapWireTwoPlanes
void create_rootgeom_MWPC_SCAN()