BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_rootgeom_MWPC_SRC2018.C
Go to the documentation of this file.
1/**
2 * @brief
3 * Macro for creating geometry root-file for MWPC
4 * @author Maria Patsyuk
5 * @date 15.02.2018
6 *
7 */
8
9#include "TFile.h"
10#include "TGeoBBox.h"
11#include "TGeoManager.h"
12#include "TGeoShape.h"
13#include "TMath.h"
14#include "TString.h"
15// #include "BmnMwpcGeometry.h"
16
17using namespace TMath;
18
20
22{
23
24 // Load the necessary FairRoot libraries
25 gROOT->LoadMacro("$VMCWORKDIR/macro/run/bmnloadlibs.C");
26 bmnloadlibs(); // load libraries
27
29
30 // Number of active planes with wires
31 const Int_t NofPlanes = mwpcGeo->GetNPlanes();
32
33 // Detector's position
34 const Double_t MWPC0_Xpos = mwpcGeo->GetChamberCenter(0).X();
35 const Double_t MWPC0_Ypos = mwpcGeo->GetChamberCenter(0).Y();
36 const Double_t MWPC0_Zpos = mwpcGeo->GetChamberCenter(0).Z();
37
38 const Double_t MWPC1_Xpos = mwpcGeo->GetChamberCenter(1).X();
39 const Double_t MWPC1_Ypos = mwpcGeo->GetChamberCenter(1).Y();
40 const Double_t MWPC1_Zpos = mwpcGeo->GetChamberCenter(1).Z();
41
42 const Double_t MWPC2_Xpos = mwpcGeo->GetChamberCenter(2).X();
43 const Double_t MWPC2_Ypos = mwpcGeo->GetChamberCenter(2).Y();
44 const Double_t MWPC2_Zpos = mwpcGeo->GetChamberCenter(2).Z();
45
46 const Double_t MWPC3_Xpos = mwpcGeo->GetChamberCenter(3).X();
47 const Double_t MWPC3_Ypos = mwpcGeo->GetChamberCenter(3).Y();
48 const Double_t MWPC3_Zpos = mwpcGeo->GetChamberCenter(3).Z();
49
50 // 2
51 // A______B
52 // / \ |\
53 // 3 / \ | \ 1
54 // / \ | \
55 // \ \ | /
56 // 4 \ \ | / 0
57 // \______\|/
58 // C
59 // 5
60
61 // X
62 // _____ <----1----> _____ <-2-> _____
63 // | | | | | | |
64 // | | | | | | |
65 // | | | | | | |
66 // | | | | | | |
67 // |_____|_____|_____|_____|_____|_____|
68 // X'
69 //
70 // 1 - GapWireOnePlane
71 // 2 - GapWireTwoPlanes
72
73 // Detector's construct parameters
74 const Double_t ABsize = mwpcGeo->GetPlaneWidth(); // cm
75 const Double_t BCsize = mwpcGeo->GetPlaneHeight(); // cm
76 const Double_t GapZsize = mwpcGeo->GetPlaneStep(); // cm
77
78 const Double_t XSizeOfActiveVolume = ABsize;
79 const Double_t YSizeOfActiveVolume = BCsize;
80 const Double_t ZSizeOfActiveVolume = GapZsize * NofPlanes; // cm
81
82 // FIXME!!! make sure! sizes of frame
83 const Double_t ZLengthChamber = ZSizeOfActiveVolume + 1.0;
84
85 // ------- Load media from media file -----------------------------------
86 FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader");
87 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
88 TString geoPath = TString(gSystem->Getenv("VMCWORKDIR")) + "/geometry/";
89 TString medFile = geoPath + "media.geo";
90 geoFace->setMediaFile(medFile);
91 geoFace->readMedia();
93 // --------------------------------------------------------------------------
94
95 // ------- Geometry file name (output) ----------------------------------
96 const TString geoDetectorName = "MWPC";
97 const TString geoDetectorVersion = "SRC2018";
98 TString geoFileName = geoPath + geoDetectorName + "_" + geoDetectorVersion + ".root";
99 // --------------------------------------------------------------------------
100
101 // ----------------- Get and create the required media -----------------
102 FairGeoMedia* geoMedia = geoFace->getMedia();
103 FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
104
105 FairGeoMedium* mAir = geoMedia->getMedium("air");
106 if (!mAir)
107 Fatal("Main", "FairMedium air not found");
108 geoBuild->createMedium(mAir);
109 TGeoMedium* pMedAir = gGeoMan->GetMedium("air");
110 if (!pMedAir)
111 Fatal("Main", "Medium air not found");
112
113 FairGeoMedium* mArCO27030 = geoMedia->getMedium("arco27030");
114 if (!mArCO27030)
115 Fatal("Main", "FairMedium arco27030 not found");
116 geoBuild->createMedium(mArCO27030);
117 TGeoMedium* pMedArCO27030 = gGeoMan->GetMedium("arco27030");
118 if (!pMedArCO27030)
119 Fatal("Main", "Medium arco27030 not found");
120
121 // --------------------------------------------------------------------------
122
123 // -------------- Create geometry and top volume -------------------------
124 gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
125 gGeoMan->SetName(geoDetectorName + "_geom");
126 TGeoVolume* top = new TGeoVolumeAssembly("TOP");
127 top->SetMedium(pMedAir);
128 gGeoMan->SetTopVolume(top);
129 // gGeoMan->SetTopVisible(1);
130 // --------------------------------------------------------------------------
131
132 // Define TOP Geometry
133 TGeoVolume* MWPC = new TGeoVolumeAssembly(geoDetectorName);
134 MWPC->SetMedium(pMedAir);
135 MWPC->SetTransparency(50);
136
137 // Transformations (translations, rotations and scales)
138 TGeoTranslation* DetPos0_trans = new TGeoTranslation("DetPos0_trans", MWPC0_Xpos, MWPC0_Ypos, MWPC0_Zpos);
139 TGeoTranslation* DetPos1_trans = new TGeoTranslation("DetPos1_trans", MWPC1_Xpos, MWPC1_Ypos, MWPC1_Zpos);
140 TGeoTranslation* DetPos2_trans = new TGeoTranslation("DetPos2_trans", MWPC2_Xpos, MWPC2_Ypos, MWPC2_Zpos);
141 TGeoTranslation* DetPos3_trans = new TGeoTranslation("DetPos3_trans", MWPC3_Xpos, MWPC3_Ypos, MWPC3_Zpos);
142
143 // Solids (shapes)
144 // hexagon which contains active wire planes
145 TGeoPgon* MWPCContainerS = new TGeoPgon("MWPCContainerS", 0, 360, NofPlanes, 2);
146 MWPCContainerS->DefineSection(0, -ZLengthChamber / 2.0, 0.0, YSizeOfActiveVolume / 2.0 + 1.0);
147 MWPCContainerS->DefineSection(1, ZLengthChamber / 2.0, 0.0, YSizeOfActiveVolume / 2.0 + 1.0);
148
149 // active wire plane
150 TGeoBBox* MWPCActivePlaneS =
151 new TGeoBBox("MWPCActivePlaneS", XSizeOfActiveVolume / 2.0, YSizeOfActiveVolume / 2.0, 0.1);
152
153 // Volumes
154 TGeoVolume* MWPCContainerV = new TGeoVolume("MWPCContainerV", MWPCContainerS);
155 MWPCContainerV->SetMedium(pMedAir);
156 MWPCContainerV->SetVisibility(kTRUE);
157 MWPCContainerV->SetTransparency(75);
158
159 TGeoVolume* MWPCActivePlaneV = new TGeoVolume("MWPCActivePlaneV", MWPCActivePlaneS);
160 MWPCActivePlaneV->SetMedium(pMedArCO27030);
161 MWPCActivePlaneV->SetLineColor(kBlue);
162 MWPCActivePlaneV->SetTransparency(40);
163
164 for (Int_t iPlane = 1; iPlane <= NofPlanes; ++iPlane) {
165 TGeoTranslation t0(0.0, 0.0, GapZsize * (iPlane - (NofPlanes + 1) / 2.0));
166 TGeoRotation r0("r0", 0.0, 0.0, (iPlane - 1) * 60.0);
167 MWPCContainerV->AddNode(MWPCActivePlaneV, iPlane - 1, new TGeoCombiTrans(t0, r0));
168 }
169
170 MWPC->AddNode(MWPCContainerV, 0, DetPos0_trans);
171 MWPC->AddNode(MWPCContainerV, 0, DetPos1_trans);
172 MWPC->AddNode(MWPCContainerV, 0, DetPos2_trans);
173 MWPC->AddNode(MWPCContainerV, 0, DetPos3_trans);
174
175 // Adding volumes to the TOP Volume
176 top->AddNode(MWPC, 0);
177
179
180 // --------------- Finish -----------------------------------------------
181 gGeoMan->CloseGeometry();
182 gGeoMan->CheckOverlaps(0.001);
183 gGeoMan->PrintOverlaps();
184 gGeoMan->Test();
185
186 TFile* geoFile = new TFile(geoFileName, "RECREATE");
187 top->Write();
188 geoFile->Close();
189 top->Draw("ogl");
190}
int Int_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
TVector3 GetChamberCenter(Int_t chamber)
void Close(Option_t *option="") override
virtual void DefineSection(Int_t snum, Double_t z, Double_t rmin, Double_t rmax)
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
void SetTransparency(Char_t transparency=0)
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)
Double_t Z() const
Double_t Y() const
Double_t X() const
TGeoManager * gGeoMan
void create_rootgeom_MWPC_SRC2018()