create_ND_geo.C
1 |
void create_ND_geo()
|
---|---|
2 |
{ |
3 |
TString erPath = gSystem->Getenv("VMCWORKDIR");
|
4 |
|
5 |
// Output paths
|
6 |
TString outGeoFilenameRoot = erPath + "/geometry/ND1ch.geo.root";
|
7 |
TString outGeoFilenameGdml = erPath + "/geometry/ND1ch.gdml";
|
8 |
|
9 |
// Input paths
|
10 |
TString medFile = erPath + "/geometry/media.geo";
|
11 |
|
12 |
// Materials and media
|
13 |
FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader"); |
14 |
FairGeoInterface* geoFace = geoLoad->getGeoInterface(); |
15 |
geoFace->setMediaFile(medFile); |
16 |
geoFace->readMedia(); |
17 |
FairGeoMedia* geoMedia = geoFace->getMedia(); |
18 |
FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder(); |
19 |
|
20 |
// Geometry manager
|
21 |
TGeoManager* geoM = (TGeoManager*)gROOT->FindObject("FAIRGeom");
|
22 |
|
23 |
TString mediumName; |
24 |
|
25 |
mediumName = "Stilbene";
|
26 |
FairGeoMedium* mStilbene = geoMedia->getMedium(mediumName); |
27 |
if (!mStilbene) Fatal("create_ND_geo", "FairMedium %s not found", mediumName.Data()); |
28 |
geoBuild->createMedium(mStilbene); |
29 |
TGeoMedium* pStilbene = geoM->GetMedium(mediumName); |
30 |
if (!pStilbene) Fatal("create_ND_geo", "Medium %s not found", mediumName.Data()); |
31 |
|
32 |
mediumName = "Steel";
|
33 |
FairGeoMedium* mSteel = geoMedia->getMedium(mediumName); |
34 |
if (!mSteel) Fatal("create_ND_geo", "FairMedium %s not found", mediumName.Data()); |
35 |
geoBuild->createMedium(mSteel); |
36 |
TGeoMedium* pSteel = geoM->GetMedium(mediumName); |
37 |
if (!pSteel) Fatal("create_ND_geo", "Medium %s not found", mediumName.Data()); |
38 |
|
39 |
mediumName = "aluminium";
|
40 |
FairGeoMedium* maluminium = geoMedia->getMedium(mediumName); |
41 |
if (!maluminium) Fatal("create_ND_geo", "FairMedium %s not found", mediumName.Data()); |
42 |
geoBuild->createMedium(maluminium); |
43 |
TGeoMedium* paluminium = geoM->GetMedium(mediumName); |
44 |
if (!paluminium) Fatal("create_ND_geo", "Medium %s not found", mediumName.Data()); |
45 |
|
46 |
mediumName = "vacuum";
|
47 |
FairGeoMedium* mvacuum = geoMedia->getMedium(mediumName); |
48 |
if (!mvacuum) Fatal("create_ND_geo", "FairMedium %s not found", mediumName.Data()); |
49 |
geoBuild->createMedium(mvacuum); |
50 |
TGeoMedium* pvacuum = geoM->GetMedium(mediumName); |
51 |
if (!pvacuum) Fatal("create_ND_geo", "Medium %s not found", mediumName.Data()); |
52 |
|
53 |
// General dimensions
|
54 |
Double_t R_min_Crystal = 0.0; // cm |
55 |
Double_t R_max_Crystal = 4.0; // cm |
56 |
Double_t HeightZ_Crystal = 5.0; // cm |
57 |
Double_t R_min_Shell = 0.0; // cm |
58 |
Double_t R_max_Shell = 4.2; // cm |
59 |
Double_t HeightZ_Shell = 5.2; // cm |
60 |
Double_t R_min_Housing = 0.0; // cm |
61 |
Double_t R_max_Housing = 4.8; // cm |
62 |
Double_t HeightZ_Housing = 5.4; // cm |
63 |
|
64 |
// Shapes
|
65 |
TGeoTube* crystalSh = new TGeoTube("crystalSh", R_min_Crystal, R_max_Crystal, HeightZ_Crystal/2.); |
66 |
TGeoTube* shellSh = new TGeoTube("shellSh", R_min_Shell, R_max_Shell, HeightZ_Shell/2.); |
67 |
TGeoTube* housingSh = new TGeoTube("housingSh", R_min_Housing, R_max_Housing, HeightZ_Housing/2.); |
68 |
|
69 |
// Volumes
|
70 |
TGeoVolume* crystalVol = new TGeoVolume("crystalVol", crystalSh, pStilbene); |
71 |
TGeoVolume* shellVol = new TGeoVolume("shellVol", shellSh, pvacuum); |
72 |
// TGeoVolume* housingVol = new TGeoVolume("housingVol", housingSh, pSteel);
|
73 |
TGeoVolume* housingVol = new TGeoVolume("housingVol", housingSh, pvacuum); |
74 |
TGeoVolume* moduleVol = new TGeoVolumeAssembly("moduleVol"); |
75 |
|
76 |
// Matrices
|
77 |
TGeoRotation* rotNoRot = new TGeoRotation("rotNoRot", 0., 0., 0.); |
78 |
rotNoRot->RegisterYourself(); |
79 |
|
80 |
// Structure
|
81 |
// Crystal in shell
|
82 |
shellVol->AddNode(crystalVol, 1, new TGeoCombiTrans("mCrystalInShell", 0., 0., (HeightZ_Shell-HeightZ_Crystal)/2., rotNoRot)); |
83 |
|
84 |
// Shell in housing
|
85 |
housingVol->AddNode(shellVol, 1);
|
86 |
// housing in Module
|
87 |
moduleVol->AddNode(housingVol, 1);
|
88 |
|
89 |
// Module in ND
|
90 |
// This is the one but last level in the hierarchy
|
91 |
// This volume-assembly is the only volume to be inserted into TOP
|
92 |
TGeoVolumeAssembly* subdetectorVolAss = new TGeoVolumeAssembly("neutrondet1ch"); |
93 |
subdetectorVolAss->AddNode(moduleVol, 1);
|
94 |
|
95 |
// for (UInt_t iX=0; iX<iXmax; iX++) {
|
96 |
// for (UInt_t iY=0; iY<iYmax; iY++) {
|
97 |
// matrixName.Form("mHousingInND_%d", iX*iYmax+iY);
|
98 |
// moduleVol->AddNode(submoduleVol, iX*2+iY, new TGeoCombiTrans(matrixName,
|
99 |
// Modules' Positioning Here
|
100 |
// -submoduleXsize/2.+submoduleXsize*iX, -submoduleYsize/2.+submoduleYsize*iY, 0., rotNoRot));
|
101 |
// Modules' Positioning Here
|
102 |
// }
|
103 |
// }
|
104 |
// Regular positioning below
|
105 |
/*
|
106 |
for(Int_t i=0; i<3; i++){
|
107 |
for(Int_t j=0; j<3; j++){
|
108 |
//1. Central cylinder:
|
109 |
if((i==0)&&(j==0)){
|
110 |
NDVol->AddNode(ModuleVol, 26, new TGeoCombiTrans("r1",0,0,r,new TGeoRotation("r2",0,0,0)));
|
111 |
}
|
112 |
//2. Cylinders along the Y-axis:
|
113 |
else if((i==0)&&!(j==0)){
|
114 |
alpha[j]= j*(l/r);
|
115 |
l1[j] =r*sin(alpha[j]);
|
116 |
h[j] = sqrt(4*r*r*sin(alpha[j]/2)*sin(alpha[j]/2) - r*r*sin(alpha[j])*sin(alpha[j]));
|
117 |
NDVol->AddNode(ModuleVol,2*j, new TGeoCombiTrans("r1",0,l1[j], r-h[j], new TGeoRotation("r2",0, -(alpha[j]*rad),0)));
|
118 |
NDVol->AddNode(ModuleVol,2*j+1, new TGeoCombiTrans("r1",0, -l1[j], r-h[j], new TGeoRotation("r2",0, (alpha[j]*rad),0)));
|
119 |
//3. Cylinders along the X-axis:
|
120 |
}else if((j==0)&&!(i==0)){
|
121 |
alpha[i]= i*(l/r);
|
122 |
l1[i] =r*sin(alpha[i]);
|
123 |
h[i] = sqrt(4*r*r*sin(alpha[i]/2)*sin(alpha[i]/2) - r*r*sin(alpha[i])*sin(alpha[i]));
|
124 |
NDVol->AddNode(ModuleVol,2*i+4, new TGeoCombiTrans("r1",l1[i],0, r-h[i], new TGeoRotation("r2",0, 0,-(alpha[i]*rad))));
|
125 |
NDVol->AddNode(ModuleVol,2*i+5, new TGeoCombiTrans("r1",-l1[i],0, r-h[i], new TGeoRotation("r2",0,0, (alpha[i]*rad))));
|
126 |
//4. Cylinders placed on quadrants:
|
127 |
}
|
128 |
else {
|
129 |
NDVol->AddNode(ModuleVol,8*i+2*j,
|
130 |
new TGeoCombiTrans("r1",l1[i],l1[j], r-h[j]-h[i],
|
131 |
new TGeoRotation("r2",0, -(alpha[j]*rad),-(alpha[i]*rad))));
|
132 |
NDVol->AddNode(ModuleVol,8*i+2*j+1,
|
133 |
new TGeoCombiTrans("r1",l1[i], -l1[j], r-h[j]-h[i],
|
134 |
new TGeoRotation("r2",0,(alpha[j]*rad), -(alpha[i]*rad))));
|
135 |
NDVol->AddNode(ModuleVol,8*i+2*j+4,
|
136 |
new TGeoCombiTrans("r1",-l1[i],-l1[j], r-h[j]-h[i],
|
137 |
new TGeoRotation("r2",0, (alpha[j]*rad),(alpha[i]*rad))));
|
138 |
NDVol->AddNode(ModuleVol,8*i+2*j+5,
|
139 |
new TGeoCombiTrans("r1",-l1[i], l1[j], r-h[j]-h[i],
|
140 |
new TGeoRotation("r2",0, -(alpha[j]*rad),(alpha[i]*rad))));
|
141 |
}//else
|
142 |
}//for j
|
143 |
}//for i
|
144 |
*/
|
145 |
|
146 |
// World ------------------------------------
|
147 |
TGeoVolumeAssembly* topVolAss = new TGeoVolumeAssembly("TOP"); |
148 |
topVolAss->AddNode(subdetectorVolAss, 1);
|
149 |
|
150 |
// Finalize
|
151 |
geoM->SetTopVolume(topVolAss); |
152 |
geoM->CloseGeometry(); |
153 |
geoM->CheckOverlaps(); |
154 |
geoM->PrintOverlaps(); |
155 |
//geoM->CheckGeometry();
|
156 |
//geoM->CheckGeometryFull();
|
157 |
//geoM->Test();
|
158 |
|
159 |
// Export
|
160 |
//geoM->Export(outGeoFilenameGdml);
|
161 |
TFile* outGeoFileRoot = new TFile(outGeoFilenameRoot, "RECREATE"); |
162 |
geoM->GetTopVolume()->Write(); |
163 |
outGeoFileRoot->Close(); |
164 |
|
165 |
// Draw
|
166 |
TBrowser* bro = new TBrowser("bro", "bro"); |
167 |
geoM->GetTopVolume()->Draw("ogl");
|
168 |
} |