ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B2bDetectorConstruction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file B2bDetectorConstruction.cc
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 //
29 
30 #include "B2bDetectorConstruction.hh"
31 #include "B2bDetectorMessenger.hh"
32 #include "B2bChamberParameterisation.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"
43 #include "G4PVParameterised.hh"
45 #include "G4AutoDelete.hh"
46 
47 #include "G4GeometryTolerance.hh"
48 #include "G4GeometryManager.hh"
49 
50 #include "G4UserLimits.hh"
51 
52 #include "G4VisAttributes.hh"
53 #include "G4Colour.hh"
54 
55 #include "G4SystemOfUnits.hh"
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
61 
64  fLogicTarget(NULL), fLogicChamber(NULL),
65  fTargetMaterial(NULL), fChamberMaterial(NULL),
66  fStepLimit(NULL),
67  fCheckOverlaps(true)
68 {
69  fMessenger = new B2bDetectorMessenger(this);
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
75 {
76  delete fStepLimit;
77  delete fMessenger;
78 }
79 
80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
81 
83 {
84  // Define materials
86 
87  // Define volumes
88  return DefineVolumes();
89 }
90 
91 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
92 
94 {
95  // Material definition
96 
97  G4NistManager* nistManager = G4NistManager::Instance();
98 
99  // Air defined using NIST Manager
100  nistManager->FindOrBuildMaterial("G4_AIR");
101 
102  // Lead defined using NIST Manager
103  fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb");
104 
105  // Xenon gas defined using NIST Manager
106  fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe");
107 
108  // Print materials
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113 
115 {
116  G4Material* air = G4Material::GetMaterial("G4_AIR");
117 
118  // Sizes of the principal geometrical components (solids)
119 
120  G4int NbOfChambers = 5;
121  G4double chamberSpacing = 80*cm; // from chamber center to center!
122 
123  G4double chamberWidth = 20.0*cm; // width of the chambers
124  G4double targetLength = 5.0*cm; // full length of Target
125 
126  G4double trackerLength = (NbOfChambers+1)*chamberSpacing;
127 
128  G4double worldLength = 1.2 * (2*targetLength + trackerLength);
129 
130  G4double targetRadius = 0.5*targetLength; // Radius of Target
131  targetLength = 0.5*targetLength; // Half length of the Target
132  G4double trackerSize = 0.5*trackerLength; // Half length of the Tracker
133 
134  // Definitions of Solids, Logical Volumes, Physical Volumes
135 
136  // World
137 
139 
140  G4cout << "Computed tolerance = "
142  << " mm" << G4endl;
143 
144  G4Box* worldS
145  = new G4Box("world", //its name
146  worldLength/2,worldLength/2,worldLength/2); //its size
147  G4LogicalVolume* worldLV
148  = new G4LogicalVolume(
149  worldS, //its solid
150  air, //its material
151  "World"); //its name
152 
153  // Must place the World Physical volume unrotated at (0,0,0).
154  //
155  G4VPhysicalVolume* worldPV
156  = new G4PVPlacement(
157  0, // no rotation
158  G4ThreeVector(), // at (0,0,0)
159  worldLV, // its logical volume
160  "World", // its name
161  0, // its mother volume
162  false, // no boolean operations
163  0, // copy number
164  fCheckOverlaps); // checking overlaps
165 
166  // Target
167 
168  G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetLength+trackerSize));
169 
170  G4Tubs* targetS
171  = new G4Tubs("target",0.,targetRadius,targetLength,0.*deg,360.*deg);
173  = new G4LogicalVolume(targetS, fTargetMaterial,"Target",0,0,0);
174  new G4PVPlacement(0, // no rotation
175  positionTarget, // at (x,y,z)
176  fLogicTarget, // its logical volume
177  "Target", // its name
178  worldLV, // its mother volume
179  false, // no boolean operations
180  0, // copy number
181  fCheckOverlaps); // checking overlaps
182 
183  G4cout << "Target is " << 2*targetLength/cm << " cm of "
184  << fTargetMaterial->GetName() << G4endl;
185 
186  // Tracker
187 
188  G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
189 
190  G4Tubs* trackerS
191  = new G4Tubs("tracker",0,trackerSize,trackerSize, 0.*deg, 360.*deg);
192  G4LogicalVolume* trackerLV
193  = new G4LogicalVolume(trackerS, air, "Tracker",0,0,0);
194  new G4PVPlacement(0, // no rotation
195  positionTracker, // at (x,y,z)
196  trackerLV, // its logical volume
197  "Tracker", // its name
198  worldLV, // its mother volume
199  false, // no boolean operations
200  0, // copy number
201  fCheckOverlaps); // checking overlaps
202 
203  // Tracker segments
204 
205  // An example of Parameterised volumes
206  // Dummy values for G4Tubs -- modified by parameterised volume
207 
208  G4Tubs* chamberS
209  = new G4Tubs("tracker",0, 100*cm, 100*cm, 0.*deg, 360.*deg);
211  = new G4LogicalVolume(chamberS,fChamberMaterial,"Chamber",0,0,0);
212 
213  G4double firstPosition = -trackerSize + chamberSpacing;
214  G4double firstLength = trackerLength/10;
215  G4double lastLength = trackerLength;
216 
217  G4VPVParameterisation* chamberParam =
219  NbOfChambers, // NoChambers
220  firstPosition, // Z of center of first
221  chamberSpacing, // Z spacing of centers
222  chamberWidth, // chamber width
223  firstLength, // initial length
224  lastLength); // final length
225 
226  // dummy value : kZAxis -- modified by parameterised volume
227 
228  new G4PVParameterised("Chamber", // their name
229  fLogicChamber, // their logical volume
230  trackerLV, // Mother logical volume
231  kZAxis, // Are placed along this axis
232  NbOfChambers, // Number of chambers
233  chamberParam, // The parametrisation
234  fCheckOverlaps); // checking overlaps
235 
236  G4cout << "There are " << NbOfChambers << " chambers in the tracker region. "
237  << G4endl
238  << "The chambers are " << chamberWidth/cm << " cm of "
239  << fChamberMaterial->GetName() << G4endl
240  << "The distance between chamber is " << chamberSpacing/cm << " cm"
241  << G4endl;
242 
243  // Visualization attributes
244 
245  G4VisAttributes* boxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
246  worldLV ->SetVisAttributes(boxVisAtt);
247  fLogicTarget ->SetVisAttributes(boxVisAtt);
248  trackerLV ->SetVisAttributes(boxVisAtt);
249 
250  G4VisAttributes* chamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0));
251  fLogicChamber->SetVisAttributes(chamberVisAtt);
252 
253  // Example of User Limits
254  //
255  // Below is an example of how to set tracking constraints in a given
256  // logical volume
257  //
258  // Sets a max step length in the tracker region, with G4StepLimiter
259 
260  G4double maxStep = 0.5*chamberWidth;
261  fStepLimit = new G4UserLimits(maxStep);
262  trackerLV->SetUserLimits(fStepLimit);
263 
271 
272  // Always return the physical world
273 
274  return worldPV;
275 }
276 
277 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
278 
280 {
281  // Sensitive detectors
282 
283  G4String trackerChamberSDname = "B2/TrackerChamberSD";
284  B2TrackerSD* aTrackerSD = new B2TrackerSD(trackerChamberSDname,
285  "TrackerHitsCollection");
287  SetSensitiveDetector( fLogicChamber, aTrackerSD );
288 
289  // Create global magnetic field messenger.
290  // Uniform magnetic field is then created automatically if
291  // the field value is not zero.
292  G4ThreeVector fieldValue = G4ThreeVector();
295 
296  // Register the field messenger for deleting
298 }
299 
300 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
301 
303 {
304  G4NistManager* nistManager = G4NistManager::Instance();
305 
306  G4Material* pttoMaterial =
307  nistManager->FindOrBuildMaterial(materialName);
308 
309  if (fTargetMaterial != pttoMaterial) {
310  if ( pttoMaterial ) {
311  fTargetMaterial = pttoMaterial;
313  G4cout
314  << G4endl
315  << "----> The target is made of " << materialName << G4endl;
316  } else {
317  G4cout
318  << G4endl
319  << "--> WARNING from SetTargetMaterial : "
320  << materialName << " not found" << G4endl;
321  }
322  }
323 }
324 
325 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
326 
328 {
329  G4NistManager* nistManager = G4NistManager::Instance();
330 
331  G4Material* pttoMaterial =
332  nistManager->FindOrBuildMaterial(materialName);
333 
334  if (fChamberMaterial != pttoMaterial) {
335  if ( pttoMaterial ) {
336  fChamberMaterial = pttoMaterial;
338  G4cout
339  << G4endl
340  << "----> The chambers are made of " << materialName << G4endl;
341  } else {
342  G4cout
343  << G4endl
344  << "--> WARNING from SetChamberMaterial : "
345  << materialName << " not found" << G4endl;
346  }
347  }
348 }
349 
350 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
351 
353 {
354  if ((fStepLimit)&&(maxStep>0.)) fStepLimit->SetMaxAllowedStep(maxStep);
355 }
356 
357 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......