FairRoot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Create_Tutorial4_Geometry.C
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 // in root all sizes are given in cm
9 
10 #include <TFile.h>
11 #include <TGeoCompositeShape.h>
12 #include <TGeoManager.h>
13 #include <TGeoMaterial.h>
14 #include <TGeoMatrix.h>
15 #include <TGeoMedium.h>
16 #include <TGeoPgon.h>
17 #include <TGeoVolume.h>
18 #include <TList.h>
19 #include <TROOT.h>
20 #include <TString.h>
21 #include <TSystem.h>
22 #include <iostream>
23 
24 // Name of geometry version and output file
25 const TString geoVersion = "tutorial4";
26 const TString FileName = geoVersion + ".root";
27 const TString FileName1 = geoVersion + "_geomanager.root";
28 
29 // Names of the different used materials which are used to build the modules
30 // The materials are defined in the global media.geo file
31 const TString KeepingVolumeMedium = "air";
32 const TString BoxVolumeMedium = "silicon";
33 
34 // Distance of the center of the first detector layer [cm];
35 const Float_t First_Z_Position = 10;
36 const Float_t Z_Distance = 10;
37 
38 // Silicon box for both module types
39 const Float_t Module_Size_X = 80.;
40 const Float_t Module_Size_Y = 80.;
41 const Float_t Module_Size_Z = .04;
42 
43 // some global variables
44 TGeoManager* gGeoMan = NULL; // Pointer to TGeoManager instance
45 TGeoVolume* gModules; // Global storage for module types
46 
47 // Forward declarations
49 TGeoVolume* create_detector();
50 void position_detector();
52 
54 {
55  // Load needed material definition from media.geo file
57 
58  // Get the GeoManager for later usage
59  gGeoMan = (TGeoManager*)gROOT->FindObject("FAIRGeom");
60  gGeoMan->SetVisLevel(7);
61 
62  // Create the top volume
63 
64  TGeoVolume* top = new TGeoVolumeAssembly("TOP");
65  gGeoMan->SetTopVolume(top);
66 
67  TGeoVolume* tut4 = new TGeoVolumeAssembly(geoVersion);
68  top->AddNode(tut4, 1);
69 
71 
73 
74  cout << "Voxelizing." << endl;
75  top->Voxelize("");
76  gGeoMan->CloseGeometry();
77 
79 
80  gGeoMan->CheckOverlaps(0.001);
81  gGeoMan->PrintOverlaps();
82  gGeoMan->Test();
83 
84  TFile* outfile = TFile::Open(FileName, "RECREATE");
85  top->Write();
86  outfile->Close();
87 
88  TFile* outfile1 = TFile::Open(FileName1, "RECREATE");
89  gGeoMan->Write();
90  outfile1->Close();
91 
92  // ------------------------------------------------------------------------
93 }
94 
96 {
97  // Use the FairRoot geometry interface to load the media which are already defined
98  FairGeoLoader* geoLoad = new FairGeoLoader("TGeo", "FairGeoLoader");
99  FairGeoInterface* geoFace = geoLoad->getGeoInterface();
100  TString geoPath = gSystem->Getenv("VMCWORKDIR");
101  TString geoFile = geoPath + "/common/geometry/media.geo";
102  geoFace->setMediaFile(geoFile);
103  geoFace->readMedia();
104 
105  // Read the required media and create them in the GeoManager
106  FairGeoMedia* geoMedia = geoFace->getMedia();
107  FairGeoBuilder* geoBuild = geoLoad->getGeoBuilder();
108 
109  FairGeoMedium* air = geoMedia->getMedium("air");
110  FairGeoMedium* silicon = geoMedia->getMedium("silicon");
111 
112  // include check if all media are found
113 
114  geoBuild->createMedium(air);
115  geoBuild->createMedium(silicon);
116 }
117 
118 TGeoVolume* create_detector()
119 {
120 
121  // needed materials
122  TGeoMedium* SiliconVolMed = gGeoMan->GetMedium(BoxVolumeMedium);
123 
124  // Single detector_layer
125  TGeoBBox* det_plane = new TGeoBBox("", Module_Size_X / 2., Module_Size_Y / 2., Module_Size_Z / 2.);
126  TGeoVolume* det_plane_vol = new TGeoVolume("tut4_det", det_plane, SiliconVolMed);
127  det_plane_vol->SetLineColor(kBlue); // set line color
128  det_plane_vol->SetTransparency(70); // set transparency
129  TGeoTranslation* det_plane_trans = new TGeoTranslation("", 0., 0., 0.);
130 
131  return det_plane_vol;
132 }
133 
135 {
136 
137  TGeoTranslation* det_trans = NULL;
138 
139  Int_t numDets = 0;
140  for (Int_t detectorPlanes = 0; detectorPlanes < 40; detectorPlanes++) {
141  det_trans = new TGeoTranslation("", 0., 0., First_Z_Position + (numDets * Z_Distance));
142  gGeoMan->GetVolume(geoVersion)->AddNode(gModules, numDets, det_trans);
143  numDets++;
144  }
145 }
146 
148 {
149 
150  TString volPath;
151  TString symName;
152  TString detStr = "Tutorial4/det";
153  TString volStr = "/TOP_1/tutorial4_1/tut4_det_";
154 
155  for (Int_t detectorPlanes = 0; detectorPlanes < 40; detectorPlanes++) {
156 
157  volPath = volStr;
158  volPath += detectorPlanes;
159 
160  symName = detStr;
161  symName += Form("%02d", detectorPlanes);
162 
163  cout << "Path: " << volPath << ", " << symName << endl;
164  // gGeoMan->cd(volPath);
165 
166  gGeoMan->SetAlignableEntry(symName.Data(), volPath.Data());
167  }
168  cout << "Nr of alignable objects: " << gGeoMan->GetNAlignable() << endl;
169 }
void setMediaFile(const char *file)
TGeoVolume * gModules
FairGeoMedia * getMedia()
const Float_t Module_Size_Z
const Float_t Z_Distance
TGeoManager * gGeoMan
FairGeoMedium * getMedium(const char *)
FairGeoInterface * getGeoInterface()
Definition: FairGeoLoader.h:34
void position_detector()
const TString BoxVolumeMedium
const TString FileName
const Float_t Module_Size_X
void create_materials_from_media_file()
const Float_t Module_Size_Y
void add_alignable_volumes()
const Float_t First_Z_Position
TGeoVolume * create_detector()
const TString KeepingVolumeMedium
FairGeoBuilder * getGeoBuilder()
Definition: FairGeoLoader.h:35
const TString geoVersion
void Create_Tutorial4_Geometry()
const TString FileName1
virtual Int_t createMedium(FairGeoMedium *)=0