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