BmnRoot 26.10.0-18-g4e3414f9
Software framework of the BM@N experiment
Loading...
Searching...
No Matches
create_rootgeom_MWPC_RunWinter2016.C
Go to the documentation of this file.
1/**
2 * @brief
3 * Macro for creating geometry root-file for MWPC
4 * @author Sergey Merts
5 * @date 15.02.2017
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
28 BmnMwpcGeometry* mwpcGeo = new BmnMwpcGeometry();
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 // 2
43 // A______B
44 // / \ |\
45 // 3 / \ | \ 1
46 // / \ | \
47 // \ \ | /
48 // 4 \ \ | / 0
49 // \______\|/
50 // C
51 // 5
52
53 // X
54 // _____ <----1----> _____ <-2-> _____
55 // | | | | | | |
56 // | | | | | | |
57 // | | | | | | |
58 // | | | | | | |
59 // |_____|_____|_____|_____|_____|_____|
60 // X'
61 //
62 // 1 - GapWireOnePlane
63 // 2 - GapWireTwoPlanes
64
65 // Detector's construct parameters
66 const Double_t ABsize = mwpcGeo->GetPlaneWidth(); // cm
67 const Double_t BCsize = mwpcGeo->GetPlaneHeight(); // cm
68 const Double_t GapZsize = mwpcGeo->GetPlaneStep(); // cm
69
70 const Double_t XSizeOfActiveVolume = ABsize;
71 const Double_t YSizeOfActiveVolume = BCsize;
72 const Double_t ZSizeOfActiveVolume = GapZsize * NofPlanes; // cm
73
74 // FIXME!!! make sure! sizes of frame
75 const Double_t ZLengthChamber = ZSizeOfActiveVolume + 1.0;
76
77 // ------- Load media from media file -----------------------------------
78 FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader");
79 FairGeoInterface* geoFace = geoLoad->getGeoInterface();
80 TString geoPath = TString(gSystem->Getenv("VMCWORKDIR")) + "/geometry/";
81 TString medFile = geoPath + "media.geo";
82 geoFace->setMediaFile(medFile);
83 geoFace->readMedia();
85 // --------------------------------------------------------------------------
86
87 // ------- Geometry file name (output) ----------------------------------
88 const TString geoDetectorName = "MWPC";
89 const TString geoDetectorVersion = "RunWinter2016";
90 TString geoFileName = geoPath + geoDetectorName + "_" + geoDetectorVersion + ".root";
91 // --------------------------------------------------------------------------
92
93 // ----------------- Get and create the required media -----------------
94 FairGeoMedia* geoMedia = geoFace->getMedia();
95 FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
96
97 FairGeoMedium* mAir = geoMedia->getMedium("air");
98 if (!mAir)
99 Fatal("Main", "FairMedium air not found");
100 geoBuild->createMedium(mAir);
101 TGeoMedium* pMedAir = gGeoMan->GetMedium("air");
102 if (!pMedAir)
103 Fatal("Main", "Medium air not found");
104
105 FairGeoMedium* mArCO27030 = geoMedia->getMedium("arco27030");
106 if (!mArCO27030)
107 Fatal("Main", "FairMedium arco27030 not found");
108 geoBuild->createMedium(mArCO27030);
109 TGeoMedium* pMedArCO27030 = gGeoMan->GetMedium("arco27030");
110 if (!pMedArCO27030)
111 Fatal("Main", "Medium arco27030 not found");
112
113 // --------------------------------------------------------------------------
114
115 // -------------- Create geometry and top volume -------------------------
116 gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
117 gGeoMan->SetName(geoDetectorName + "_geom");
118 TGeoVolume* top = new TGeoVolumeAssembly("TOP");
119 top->SetMedium(pMedAir);
120 gGeoMan->SetTopVolume(top);
121 // gGeoMan->SetTopVisible(1);
122 // --------------------------------------------------------------------------
123
124 // Define TOP Geometry
125 TGeoVolume* MWPC = new TGeoVolumeAssembly(geoDetectorName);
126 MWPC->SetMedium(pMedAir);
127 MWPC->SetTransparency(50);
128
129 // Transformations (translations, rotations and scales)
130 TGeoTranslation* DetPos0_trans = new TGeoTranslation("DetPos0_trans", MWPC0_Xpos, MWPC0_Ypos, MWPC0_Zpos);
131 TGeoTranslation* DetPos1_trans = new TGeoTranslation("DetPos1_trans", MWPC1_Xpos, MWPC1_Ypos, MWPC1_Zpos);
132
133 // Solids (shapes)
134 // hexagon which contains active wire planes
135 TGeoPgon* MWPCContainerS = new TGeoPgon("MWPCContainerS", 0, 360, NofPlanes, 2);
136 MWPCContainerS->DefineSection(0, -ZLengthChamber / 2.0, 0.0, YSizeOfActiveVolume / 2.0 + 1.0);
137 MWPCContainerS->DefineSection(1, ZLengthChamber / 2.0, 0.0, YSizeOfActiveVolume / 2.0 + 1.0);
138
139 // active wire plane
140 TGeoBBox* MWPCActivePlaneS =
141 new TGeoBBox("MWPCActivePlaneS", XSizeOfActiveVolume / 2.0, YSizeOfActiveVolume / 2.0, 0.1);
142
143 // Volumes
144 TGeoVolume* MWPCContainerV = new TGeoVolume("MWPCContainerV", MWPCContainerS);
145 MWPCContainerV->SetMedium(pMedAir);
146 MWPCContainerV->SetVisibility(kTRUE);
147 MWPCContainerV->SetTransparency(75);
148
149 TGeoVolume* MWPCActivePlaneV = new TGeoVolume("MWPCActivePlaneV", MWPCActivePlaneS);
150 MWPCActivePlaneV->SetMedium(pMedArCO27030);
151 MWPCActivePlaneV->SetLineColor(kBlue);
152 MWPCActivePlaneV->SetTransparency(40);
153
154 for (Int_t iPlane = 1; iPlane <= NofPlanes; ++iPlane) {
155 TGeoTranslation t0(0.0, 0.0, GapZsize * (iPlane - (NofPlanes + 1) / 2.0));
156 TGeoRotation r0("r0", 0.0, 0.0, (iPlane - 1) * 60.0);
157 MWPCContainerV->AddNode(MWPCActivePlaneV, iPlane - 1, new TGeoCombiTrans(t0, r0));
158 }
159
160 MWPC->AddNode(MWPCContainerV, 0, DetPos0_trans);
161 MWPC->AddNode(MWPCContainerV, 0, DetPos1_trans);
162 // Adding volumes to the TOP Volume
163 top->AddNode(MWPC, 0);
164
166
167 // --------------- Finish -----------------------------------------------
168 gGeoMan->CloseGeometry();
169 gGeoMan->CheckOverlaps(0.001);
170 gGeoMan->PrintOverlaps();
171 gGeoMan->Test();
172
173 TFile* geoFile = new TFile(geoFileName, "RECREATE");
174 top->Write();
175 geoFile->Close();
176 top->Draw("ogl");
177}
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
Double_t GetPlaneWidth()
TVector3 GetChamberCenter(Int_t chamber)
Double_t GetPlaneStep()
Double_t GetPlaneHeight()
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_RunWinter2016()