Geant4  10.00.p03
B2aDetectorConstruction.cc
Go to the documentation of this file.
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 // $Id: B2aDetectorConstruction.cc 77603 2013-11-26 17:11:49Z gcosmo $
27 //
30 
32 #include "B2aDetectorMessenger.hh"
33 #include "B2TrackerSD.hh"
34 
35 #include "G4Material.hh"
36 #include "G4NistManager.hh"
37 
38 #include "G4Box.hh"
39 #include "G4Tubs.hh"
40 #include "G4LogicalVolume.hh"
41 #include "G4PVPlacement.hh"
43 #include "G4AutoDelete.hh"
44 
45 #include "G4GeometryTolerance.hh"
46 #include "G4GeometryManager.hh"
47 
48 #include "G4UserLimits.hh"
49 
50 #include "G4VisAttributes.hh"
51 #include "G4Colour.hh"
52 
53 #include "G4SystemOfUnits.hh"
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
59 
62  fNbOfChambers(0),
63  fLogicTarget(NULL), fLogicChamber(NULL),
64  fTargetMaterial(NULL), fChamberMaterial(NULL),
65  fStepLimit(NULL),
66  fCheckOverlaps(true)
67 {
68  fMessenger = new B2aDetectorMessenger(this);
69 
70  fNbOfChambers = 5;
72 }
73 
74 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
75 
77 {
78  delete [] fLogicChamber;
79  delete fStepLimit;
80  delete fMessenger;
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
86 {
87  // Define materials
89 
90  // Define volumes
91  return DefineVolumes();
92 }
93 
94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
95 
97 {
98  // Material definition
99 
100  G4NistManager* nistManager = G4NistManager::Instance();
101 
102  // Air defined using NIST Manager
103  nistManager->FindOrBuildMaterial("G4_AIR");
104 
105  // Lead defined using NIST Manager
106  fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb");
107 
108  // Xenon gas defined using NIST Manager
109  fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe");
110 
111  // Print materials
113 }
114 
115 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
116 
118 {
119  G4Material* air = G4Material::GetMaterial("G4_AIR");
120 
121  // Sizes of the principal geometrical components (solids)
122 
123  G4double chamberSpacing = 80*cm; // from chamber center to center!
124 
125  G4double chamberWidth = 20.0*cm; // width of the chambers
126  G4double targetLength = 5.0*cm; // full length of Target
127 
128  G4double trackerLength = (fNbOfChambers+1)*chamberSpacing;
129 
130  G4double worldLength = 1.2 * (2*targetLength + trackerLength);
131 
132  G4double targetRadius = 0.5*targetLength; // Radius of Target
133  targetLength = 0.5*targetLength; // Half length of the Target
134  G4double trackerSize = 0.5*trackerLength; // Half length of the Tracker
135 
136  // Definitions of Solids, Logical Volumes, Physical Volumes
137 
138  // World
139 
141 
142  G4cout << "Computed tolerance = "
144  << " mm" << G4endl;
145 
146  G4Box* worldS
147  = new G4Box("world", //its name
148  worldLength/2,worldLength/2,worldLength/2); //its size
149  G4LogicalVolume* worldLV
150  = new G4LogicalVolume(
151  worldS, //its solid
152  air, //its material
153  "World"); //its name
154 
155  // Must place the World Physical volume unrotated at (0,0,0).
156  //
157  G4VPhysicalVolume* worldPV
158  = new G4PVPlacement(
159  0, // no rotation
160  G4ThreeVector(), // at (0,0,0)
161  worldLV, // its logical volume
162  "World", // its name
163  0, // its mother volume
164  false, // no boolean operations
165  0, // copy number
166  fCheckOverlaps); // checking overlaps
167 
168  // Target
169 
170  G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetLength+trackerSize));
171 
172  G4Tubs* targetS
173  = new G4Tubs("target",0.,targetRadius,targetLength,0.*deg,360.*deg);
175  = new G4LogicalVolume(targetS, fTargetMaterial,"Target",0,0,0);
176  new G4PVPlacement(0, // no rotation
177  positionTarget, // at (x,y,z)
178  fLogicTarget, // its logical volume
179  "Target", // its name
180  worldLV, // its mother volume
181  false, // no boolean operations
182  0, // copy number
183  fCheckOverlaps); // checking overlaps
184 
185  G4cout << "Target is " << 2*targetLength/cm << " cm of "
186  << fTargetMaterial->GetName() << G4endl;
187 
188  // Tracker
189 
190  G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
191 
192  G4Tubs* trackerS
193  = new G4Tubs("tracker",0,trackerSize,trackerSize, 0.*deg, 360.*deg);
194  G4LogicalVolume* trackerLV
195  = new G4LogicalVolume(trackerS, air, "Tracker",0,0,0);
196  new G4PVPlacement(0, // no rotation
197  positionTracker, // at (x,y,z)
198  trackerLV, // its logical volume
199  "Tracker", // its name
200  worldLV, // its mother volume
201  false, // no boolean operations
202  0, // copy number
203  fCheckOverlaps); // checking overlaps
204 
205  // Visualization attributes
206 
207  G4VisAttributes* boxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
208  G4VisAttributes* chamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0));
209 
210  worldLV ->SetVisAttributes(boxVisAtt);
211  fLogicTarget ->SetVisAttributes(boxVisAtt);
212  trackerLV ->SetVisAttributes(boxVisAtt);
213 
214  // Tracker segments
215 
216  G4cout << "There are " << fNbOfChambers << " chambers in the tracker region. "
217  << "\nThe chambers are " << chamberWidth/cm << " cm of "
218  << fChamberMaterial->GetName() << "\nThe distance between chamber is "
219  << chamberSpacing/cm << " cm" << G4endl;
220 
221  G4double firstPosition = -trackerSize + chamberSpacing;
222  G4double firstLength = trackerLength/10;
223  G4double lastLength = trackerLength;
224 
225  G4double halfWidth = 0.5*chamberWidth;
226  G4double rmaxFirst = 0.5 * firstLength;
227 
228  G4double rmaxIncr = 0.0;
229  if( fNbOfChambers > 0 ){
230  rmaxIncr = 0.5 * (lastLength-firstLength)/(fNbOfChambers-1);
231  if (chamberSpacing < chamberWidth) {
232  G4Exception("B2aDetectorConstruction::DefineVolumes()",
233  "InvalidSetup", FatalException,
234  "Width>Spacing");
235  }
236  }
237 
238  for (G4int copyNo=0; copyNo<fNbOfChambers; copyNo++) {
239 
240  G4double Zposition = firstPosition + copyNo * chamberSpacing;
241  G4double rmax = rmaxFirst + copyNo * rmaxIncr;
242 
243  G4Tubs* chamberS
244  = new G4Tubs("Chamber_solid", 0, rmax, halfWidth, 0.*deg, 360.*deg);
245 
246  fLogicChamber[copyNo] =
247  new G4LogicalVolume(chamberS,fChamberMaterial,"Chamber_LV",0,0,0);
248 
249  fLogicChamber[copyNo]->SetVisAttributes(chamberVisAtt);
250 
251  new G4PVPlacement(0, // no rotation
252  G4ThreeVector(0,0,Zposition), // at (x,y,z)
253  fLogicChamber[copyNo], // its logical volume
254  "Chamber_PV", // its name
255  trackerLV, // its mother volume
256  false, // no boolean operations
257  copyNo, // copy number
258  fCheckOverlaps); // checking overlaps
259 
260  }
261 
262  // Example of User Limits
263  //
264  // Below is an example of how to set tracking constraints in a given
265  // logical volume
266  //
267  // Sets a max step length in the tracker region, with G4StepLimiter
268 
269  G4double maxStep = 0.5*chamberWidth;
270  fStepLimit = new G4UserLimits(maxStep);
271  trackerLV->SetUserLimits(fStepLimit);
272 
280 
281  // Always return the physical world
282 
283  return worldPV;
284 }
285 
286 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
287 
289 {
290  // Sensitive detectors
291 
292  G4String trackerChamberSDname = "B2/TrackerChamberSD";
293  B2TrackerSD* aTrackerSD = new B2TrackerSD(trackerChamberSDname,
294  "TrackerHitsCollection");
295  // Setting aTrackerSD to all logical volumes with the same name
296  // of "Chamber_LV".
297  SetSensitiveDetector("Chamber_LV", aTrackerSD, true);
298 
299  // Create global magnetic field messenger.
300  // Uniform magnetic field is then created automatically if
301  // the field value is not zero.
302  G4ThreeVector fieldValue = G4ThreeVector();
305 
306  // Register the field messenger for deleting
308 }
309 
310 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
311 
313 {
314  G4NistManager* nistManager = G4NistManager::Instance();
315 
316  G4Material* pttoMaterial =
317  nistManager->FindOrBuildMaterial(materialName);
318 
319  if (fTargetMaterial != pttoMaterial) {
320  if ( pttoMaterial ) {
321  fTargetMaterial = pttoMaterial;
323  G4cout << "\n----> The target is made of " << materialName << G4endl;
324  } else {
325  G4cout << "\n--> WARNING from SetTargetMaterial : "
326  << materialName << " not found" << G4endl;
327  }
328  }
329 }
330 
331 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
332 
334 {
335  G4NistManager* nistManager = G4NistManager::Instance();
336 
337  G4Material* pttoMaterial =
338  nistManager->FindOrBuildMaterial(materialName);
339 
340  if (fChamberMaterial != pttoMaterial) {
341  if ( pttoMaterial ) {
342  fChamberMaterial = pttoMaterial;
343  for (G4int copyNo=0; copyNo<fNbOfChambers; copyNo++) {
344  if (fLogicChamber[copyNo]) fLogicChamber[copyNo]->
345  SetMaterial(fChamberMaterial);
346  }
347  G4cout << "\n----> The chambers are made of " << materialName << G4endl;
348  } else {
349  G4cout << "\n--> WARNING from SetChamberMaterial : "
350  << materialName << " not found" << G4endl;
351  }
352  }
353 }
354 
355 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
356 
358 {
359  if ((fStepLimit)&&(maxStep>0.)) fStepLimit->SetMaxAllowedStep(maxStep);
360 }
361 
362 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
363 
365 {
366  fCheckOverlaps = checkOverlaps;
367 }
static const double cm
Definition: G4SIunits.hh:106
void SetVerboseLevel(G4int verboseLevel)
G4Material * FindOrBuildMaterial(const G4String &name, G4bool isotopes=true, G4bool warning=false)
virtual void SetMaxAllowedStep(G4double ustepMax)
Definition of the B2aDetectorMessenger class.
CLHEP::Hep3Vector G4ThreeVector
static G4Material * GetMaterial(const G4String &name, G4bool warning=true)
Definition: G4Material.cc:602
Definition: G4Box.hh:64
const G4String & GetName() const
Definition: G4Material.hh:176
void SetUserLimits(G4UserLimits *pULimits)
Definition: G4Tubs.hh:85
G4double GetSurfaceTolerance() const
static G4MaterialTable * GetMaterialTable()
Definition: G4Material.cc:587
#define G4ThreadLocal
Definition: tls.hh:52
void SetWorldMaximumExtent(G4double worldExtent)
int G4int
Definition: G4Types.hh:78
static G4NistManager * Instance()
B2Tracker sensitive detector class.
Definition: B2TrackerSD.hh:51
void Register(T *inst)
Definition: G4AutoDelete.hh:65
Messenger class that defines commands for B2aDetectorConstruction.
G4GLOB_DLL std::ostream G4cout
Definition of the B2aDetectorConstruction class.
static const double deg
Definition: G4SIunits.hh:133
bool G4bool
Definition: G4Types.hh:79
static G4GeometryManager * GetInstance()
void SetSensitiveDetector(const G4String &logVolName, G4VSensitiveDetector *aSD, G4bool multi=false)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
virtual G4VPhysicalVolume * Construct()
static G4ThreadLocal G4GlobalMagFieldMessenger * fMagFieldMessenger
B2aDetectorMessenger * fMessenger
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void SetMaterial(G4Material *pMaterial)
static const double mm
Definition: G4SIunits.hh:102
void SetVisAttributes(const G4VisAttributes *pVA)
static G4GeometryTolerance * GetInstance()
G4VPhysicalVolume * DefineVolumes()