source: trunk/examples/extended/visualization/userVisAction/src/UVA_DetectorConstruction.cc @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 11.3 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: UVA_DetectorConstruction.cc,v 1.2 2006/06/29 17:46:39 gunter Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
31//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 
33#include "UVA_DetectorConstruction.hh"
34#include "UVA_DetectorMessenger.hh"
35#include "UVA_ChamberParameterisation.hh"
36#include "UVA_MagneticField.hh"
37#include "UVA_TrackerSD.hh"
38
39#include "G4Material.hh"
40#include "G4Box.hh"
41#include "G4LogicalVolume.hh"
42#include "G4PVPlacement.hh"
43#include "G4PVParameterised.hh"
44#include "G4SDManager.hh"
45
46#include "G4UserLimits.hh"
47
48#include "G4VisAttributes.hh"
49#include "G4Colour.hh"
50
51#include "G4ios.hh"
52
53//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
55UVA_DetectorConstruction::UVA_DetectorConstruction()
56:solidWorld(0),  logicWorld(0),  physiWorld(0),
57 solidTarget(0), logicTarget(0), physiTarget(0), 
58 solidTracker(0),logicTracker(0),physiTracker(0), 
59 solidChamber(0),logicChamber(0),physiChamber(0), 
60 TargetMater(0), ChamberMater(0),fpMagField(0),
61 fWorldLength(0.),  fTargetLength(0.), fTrackerLength(0.),
62 NbOfChambers(0) ,  ChamberWidth(0.),  ChamberSpacing(0.)
63{
64  fpMagField = new UVA_MagneticField();
65  detectorMessenger = new UVA_DetectorMessenger(this);
66}
67
68//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69 
70UVA_DetectorConstruction::~UVA_DetectorConstruction()
71{
72  delete fpMagField;
73  delete detectorMessenger;             
74}
75
76//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77 
78G4VPhysicalVolume* UVA_DetectorConstruction::Construct()
79{
80//--------- Material definition ---------
81
82  G4double a, z;
83  G4double density, temperature, pressure;
84  G4int nel;
85
86  //Air
87  G4Element* N = new G4Element("Nitrogen", "N", z=7., a= 14.01*g/mole);
88  G4Element* O = new G4Element("Oxygen"  , "O", z=8., a= 16.00*g/mole);
89   
90  G4Material* Air = new G4Material("Air", density= 1.29*mg/cm3, nel=2);
91  Air->AddElement(N, 70*perCent);
92  Air->AddElement(O, 30*perCent);
93
94  //Lead
95  G4Material* Pb = 
96  new G4Material("Lead", z=82., a= 207.19*g/mole, density= 11.35*g/cm3);
97   
98  //Xenon gas
99  G4Material* Xenon = 
100  new G4Material("XenonGas", z=54., a=131.29*g/mole, density= 5.458*mg/cm3,
101                 kStateGas, temperature= 293.15*kelvin, pressure= 1*atmosphere);
102
103  // Print all the materials defined.
104  //
105  G4cout << G4endl << "The materials defined are : " << G4endl << G4endl;
106  G4cout << *(G4Material::GetMaterialTable()) << G4endl;
107
108//--------- Sizes of the principal geometrical components (solids)  ---------
109 
110  NbOfChambers = 5;
111  ChamberWidth = 20*cm;
112  ChamberSpacing = 80*cm;
113 
114  fTrackerLength = (NbOfChambers+1)*ChamberSpacing; // Full length of Tracker
115  fTargetLength  = 5.0 * cm;                        // Full length of Target
116 
117  TargetMater  = Pb;
118  ChamberMater = Xenon;
119 
120  fWorldLength= 1.2 *(fTargetLength+fTrackerLength);
121   
122  G4double targetSize  = 0.5*fTargetLength;    // Half length of the Target 
123  G4double trackerSize = 0.5*fTrackerLength;   // Half length of the Tracker
124     
125//--------- Definitions of Solids, Logical Volumes, Physical Volumes ---------
126 
127  //------------------------------
128  // World
129  //------------------------------
130
131  G4double HalfWorldLength = 0.5*fWorldLength;
132 
133 solidWorld= new G4Box("world",HalfWorldLength,HalfWorldLength,HalfWorldLength);
134 logicWorld= new G4LogicalVolume( solidWorld, Air, "World", 0, 0, 0);
135 
136  //  Must place the World Physical volume unrotated at (0,0,0).
137  //
138  physiWorld = new G4PVPlacement(0,               // no rotation
139                                 G4ThreeVector(), // at (0,0,0)
140                                 logicWorld,      // its logical volume
141                                 "World",         // its name
142                                 0,               // its mother  volume
143                                 false,           // no boolean operations
144                                 0);              // copy number
145                                 
146  //------------------------------
147  // Target
148  //------------------------------
149 
150  G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetSize+trackerSize));
151   
152  solidTarget = new G4Box("target",targetSize,targetSize,targetSize);
153  logicTarget = new G4LogicalVolume(solidTarget,TargetMater,"Target",0,0,0);
154  physiTarget = new G4PVPlacement(0,               // no rotation
155                                  positionTarget,  // at (x,y,z)
156                                  logicTarget,     // its logical volume                                 
157                                  "Target",        // its name
158                                  logicWorld,      // its mother  volume
159                                  false,           // no boolean operations
160                                  0);              // copy number
161
162  G4cout << "Target is " << fTargetLength/cm << " cm of " 
163         << TargetMater->GetName() << G4endl;
164
165  //------------------------------
166  // Tracker
167  //------------------------------
168 
169  G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
170 
171  solidTracker = new G4Box("tracker",trackerSize,trackerSize,trackerSize);
172  logicTracker = new G4LogicalVolume(solidTracker , Air, "Tracker",0,0,0); 
173  physiTracker = new G4PVPlacement(0,              // no rotation
174                                  positionTracker, // at (x,y,z)
175                                  logicTracker,    // its logical volume                                 
176                                  "Tracker",       // its name
177                                  logicWorld,      // its mother  volume
178                                  false,           // no boolean operations
179                                  0);              // copy number
180
181  //------------------------------
182  // Tracker segments
183  //------------------------------
184  //
185  // An example of Parameterised volumes
186  // dummy values for G4Box -- modified by parameterised volume
187
188  solidChamber = new G4Box("chamber", 100*cm, 100*cm, 10*cm); 
189  logicChamber = new G4LogicalVolume(solidChamber,ChamberMater,"Chamber",0,0,0);
190 
191  G4double firstPosition = -trackerSize + 0.5*ChamberWidth;
192  G4double firstLength = fTrackerLength/10;
193  G4double lastLength  = fTrackerLength;
194   
195  G4VPVParameterisation* chamberParam = new UVA_ChamberParameterisation( 
196                           NbOfChambers,          // NoChambers
197                           firstPosition,         // Z of center of first
198                           ChamberSpacing,        // Z spacing of centers
199                           ChamberWidth,          // Width Chamber
200                           firstLength,           // lengthInitial
201                           lastLength);           // lengthFinal
202                           
203  // dummy value : kZAxis -- modified by parameterised volume
204  //
205  physiChamber = new G4PVParameterised(
206                            "Chamber",       // their name
207                            logicChamber,    // their logical volume
208                            logicTracker,    // Mother logical volume
209                            kZAxis,          // Are placed along this axis
210                            NbOfChambers,    // Number of chambers
211                            chamberParam);   // The parametrisation
212
213  G4cout << "There are " << NbOfChambers << " chambers in the tracker region. "
214         << "The chambers are " << ChamberWidth/mm << " mm of " 
215         << ChamberMater->GetName() << "\n The distance between chamber is "
216         << ChamberSpacing/cm << " cm" << G4endl;
217         
218  //------------------------------------------------
219  // Sensitive detectors
220  //------------------------------------------------
221
222  G4SDManager* SDman = G4SDManager::GetSDMpointer();
223
224  G4String trackerChamberSDname = "UVA_/TrackerChamberSD";
225  UVA_TrackerSD* aTrackerSD = new UVA_TrackerSD( trackerChamberSDname );
226  SDman->AddNewDetector( aTrackerSD );
227  logicChamber->SetSensitiveDetector( aTrackerSD );
228
229//--------- Visualization attributes -------------------------------
230
231  G4VisAttributes* BoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
232  logicWorld  ->SetVisAttributes(BoxVisAtt); 
233  logicTarget ->SetVisAttributes(BoxVisAtt);
234  logicTracker->SetVisAttributes(BoxVisAtt);
235 
236  G4VisAttributes* ChamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0));
237  logicChamber->SetVisAttributes(ChamberVisAtt);
238 
239//--------- example of User Limits -------------------------------
240
241  // below is an example of how to set tracking constraints in a given
242  // logical volume(see also in N02PhysicsList how to setup the processes
243  // G4StepLimiter or G4UserSpecialCuts).
244   
245  // Sets a max Step length in the tracker region, with G4StepLimiter
246  //
247  G4double maxStep = 0.5*ChamberWidth; 
248  logicTracker->SetUserLimits(new G4UserLimits(maxStep));
249 
250  // Set additional contraints on the track, with G4UserSpecialCuts
251  //
252  // G4double maxLength = 2*fTrackerLength, maxTime = 0.1*ns, minEkin = 10*MeV;
253  // logicTracker->SetUserLimits(new G4UserLimits(maxStep,maxLength,maxTime,
254  //                                               minEkin));
255 
256  return physiWorld;
257}
258
259//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
260 
261void UVA_DetectorConstruction::setTargetMaterial(G4String materialName)
262{
263  // search the material by its name
264  G4Material* pttoMaterial = G4Material::GetMaterial(materialName); 
265  if (pttoMaterial)
266     {TargetMater = pttoMaterial;
267      logicTarget->SetMaterial(pttoMaterial); 
268      G4cout << "\n----> The target is " << fTargetLength/cm << " cm of "
269             << materialName << G4endl;
270     }             
271}
272 
273//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
274
275void UVA_DetectorConstruction::setChamberMaterial(G4String materialName)
276{
277  // search the material by its name
278  G4Material* pttoMaterial = G4Material::GetMaterial(materialName); 
279  if (pttoMaterial)
280     {ChamberMater = pttoMaterial;
281      logicChamber->SetMaterial(pttoMaterial); 
282      G4cout << "\n----> The chambers are " << ChamberWidth/cm << " cm of "
283             << materialName << G4endl;
284     }             
285}
286 
287//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
288 
289void UVA_DetectorConstruction::SetMagField(G4double fieldValue)
290{
291  fpMagField->SetFieldValue(fieldValue);
292}
293
294//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
Note: See TracBrowser for help on using the repository browser.