ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExN02DetectorConstruction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ExN02DetectorConstruction.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 //
28 //
29 //
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
37 #include "ExN02MagneticField.hh"
38 #include "ExN02TrackerSD.hh"
39 
40 #include "G4Material.hh"
41 #include "G4Box.hh"
42 #include "G4LogicalVolume.hh"
43 #include "G4PVPlacement.hh"
44 #include "G4PVParameterised.hh"
45 #include "G4SDManager.hh"
46 #include "G4GeometryTolerance.hh"
47 #include "G4GeometryManager.hh"
48 
49 #include "G4UserLimits.hh"
50 #include "G4SystemOfUnits.hh"
51 
52 #include "G4VisAttributes.hh"
53 #include "G4Colour.hh"
54 
55 #include "G4ios.hh"
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 :solidWorld(0), logicWorld(0), physiWorld(0),
61  solidTarget(0), logicTarget(0), physiTarget(0),
62  solidTracker(0),logicTracker(0),physiTracker(0),
63  solidChamber(0),logicChamber(0),physiChamber(0),
64  TargetMater(0), ChamberMater(0),chamberParam(0),
65  stepLimit(0), fpMagField(0),
66  fWorldLength(0.), fTargetLength(0.), fTrackerLength(0.),
67  NbOfChambers(0) , ChamberWidth(0.), ChamberSpacing(0.)
68 {
71 }
72 
73 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
74 
76 {
77  delete fpMagField;
78  delete stepLimit;
79  delete chamberParam;
80  delete detectorMessenger;
81 }
82 
83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
84 
86 {
87 //--------- Material definition ---------
88 
89  G4double a, z;
90  G4double density, temperature, pressure;
91  G4int nel;
92 
93  //Air
94  G4Element* N = new G4Element("Nitrogen", "N", z=7., a= 14.01*g/mole);
95  G4Element* O = new G4Element("Oxygen" , "O", z=8., a= 16.00*g/mole);
96 
97  G4Material* Air = new G4Material("Air", density= 1.29*mg/cm3, nel=2);
98  Air->AddElement(N, 70*perCent);
99  Air->AddElement(O, 30*perCent);
100 
101  //Lead
102  G4Material* Pb =
103  new G4Material("Lead", z=82., a= 207.19*g/mole, density= 11.35*g/cm3);
104 
105  //Xenon gas
106  G4Material* Xenon =
107  new G4Material("XenonGas", z=54., a=131.29*g/mole, density= 5.458*mg/cm3,
108  kStateGas, temperature= 293.15*kelvin, pressure= 1*atmosphere);
109 
110  // Print all the materials defined.
111  //
112  G4cout << G4endl << "The materials defined are : " << G4endl << G4endl;
113  G4cout << *(G4Material::GetMaterialTable()) << G4endl;
114 
115 //--------- Sizes of the principal geometrical components (solids) ---------
116 
117  NbOfChambers = 5;
118  ChamberWidth = 20*cm;
119  ChamberSpacing = 80*cm;
120 
121  fTrackerLength = (NbOfChambers+1)*ChamberSpacing; // Full length of Tracker
122  fTargetLength = 5.0 * cm; // Full length of Target
123 
124  TargetMater = Pb;
125  ChamberMater = Xenon;
126 
128 
129  G4double targetSize = 0.5*fTargetLength; // Half length of the Target
130  G4double trackerSize = 0.5*fTrackerLength; // Half length of the Tracker
131 
132 //--------- Definitions of Solids, Logical Volumes, Physical Volumes ---------
133 
134  //------------------------------
135  // World
136  //------------------------------
137 
138  G4double HalfWorldLength = 0.5*fWorldLength;
139 
141  G4cout << "Computed tolerance = "
143  << " mm" << G4endl;
144 
145  solidWorld= new G4Box("world",HalfWorldLength,HalfWorldLength,HalfWorldLength);
146  logicWorld= new G4LogicalVolume( solidWorld, Air, "World", 0, 0, 0);
147 
148  // Must place the World Physical volume unrotated at (0,0,0).
149  //
150  physiWorld = new G4PVPlacement(0, // no rotation
151  G4ThreeVector(), // at (0,0,0)
152  logicWorld, // its logical volume
153  "World", // its name
154  0, // its mother volume
155  false, // no boolean operations
156  0); // copy number
157 
158  //------------------------------
159  // Target
160  //------------------------------
161 
162  G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetSize+trackerSize));
163 
164  solidTarget = new G4Box("target",targetSize,targetSize,targetSize);
165  logicTarget = new G4LogicalVolume(solidTarget,TargetMater,"Target",0,0,0);
166  physiTarget = new G4PVPlacement(0, // no rotation
167  positionTarget, // at (x,y,z)
168  logicTarget, // its logical volume
169  "Target", // its name
170  logicWorld, // its mother volume
171  false, // no boolean operations
172  0); // copy number
173 
174  G4cout << "Target is " << fTargetLength/cm << " cm of "
175  << TargetMater->GetName() << G4endl;
176 
177  //------------------------------
178  // Tracker
179  //------------------------------
180 
181  G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
182 
183  solidTracker = new G4Box("tracker",trackerSize,trackerSize,trackerSize);
184  logicTracker = new G4LogicalVolume(solidTracker , Air, "Tracker",0,0,0);
185  physiTracker = new G4PVPlacement(0, // no rotation
186  positionTracker, // at (x,y,z)
187  logicTracker, // its logical volume
188  "Tracker", // its name
189  logicWorld, // its mother volume
190  false, // no boolean operations
191  0); // copy number
192 
193  //------------------------------
194  // Tracker segments
195  //------------------------------
196  //
197  // An example of Parameterised volumes
198  // dummy values for G4Box -- modified by parameterised volume
199 
200  solidChamber = new G4Box("chamber", 100*cm, 100*cm, 10*cm);
201  logicChamber = new G4LogicalVolume(solidChamber,ChamberMater,"Chamber",0,0,0);
202 
203  G4double firstPosition = -trackerSize + 0.5*ChamberWidth;
204  G4double firstLength = fTrackerLength/10;
205  G4double lastLength = fTrackerLength;
206 
208  NbOfChambers, // NoChambers
209  firstPosition, // Z of center of first
210  ChamberSpacing, // Z spacing of centers
211  ChamberWidth, // Width Chamber
212  firstLength, // lengthInitial
213  lastLength); // lengthFinal
214 
215  // dummy value : kZAxis -- modified by parameterised volume
216  //
218  "Chamber", // their name
219  logicChamber, // their logical volume
220  logicTracker, // Mother logical volume
221  kZAxis, // Are placed along this axis
222  NbOfChambers, // Number of chambers
223  chamberParam); // The parametrisation
224 
225  G4cout << "There are " << NbOfChambers << " chambers in the tracker region. "
226  << "The chambers are " << ChamberWidth/mm << " mm of "
227  << ChamberMater->GetName() << "\n The distance between chamber is "
228  << ChamberSpacing/cm << " cm" << G4endl;
229 
230  //------------------------------------------------
231  // Sensitive detectors
232  //------------------------------------------------
233 
235 
236  G4String trackerChamberSDname = "ExN02/TrackerChamberSD";
237  ExN02TrackerSD* aTrackerSD = new ExN02TrackerSD( trackerChamberSDname );
238  SDman->AddNewDetector( aTrackerSD );
239  logicChamber->SetSensitiveDetector( aTrackerSD );
240 
241 //--------- Visualization attributes -------------------------------
242 
243  G4VisAttributes* BoxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
244  logicWorld ->SetVisAttributes(BoxVisAtt);
245  logicTarget ->SetVisAttributes(BoxVisAtt);
246  logicTracker->SetVisAttributes(BoxVisAtt);
247 
248  G4VisAttributes* ChamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0));
249  logicChamber->SetVisAttributes(ChamberVisAtt);
250 
251 //--------- example of User Limits -------------------------------
252 
253  // below is an example of how to set tracking constraints in a given
254  // logical volume(see also in N02PhysicsList how to setup the processes
255  // G4StepLimiter or G4UserSpecialCuts).
256 
257  // Sets a max Step length in the tracker region, with G4StepLimiter
258  //
259  G4double maxStep = 0.5*ChamberWidth;
260  stepLimit = new G4UserLimits(maxStep);
262 
263  // Set additional contraints on the track, with G4UserSpecialCuts
264  //
265  // G4double maxLength = 2*fTrackerLength, maxTime = 0.1*ns, minEkin = 10*MeV;
266  // logicTracker->SetUserLimits(new G4UserLimits(maxStep,maxLength,maxTime,
267  // minEkin));
268 
269  return physiWorld;
270 }
271 
272 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
273 
275 {
276  // search the material by its name
277  G4Material* pttoMaterial = G4Material::GetMaterial(materialName);
278  if (pttoMaterial)
279  {TargetMater = pttoMaterial;
280  logicTarget->SetMaterial(pttoMaterial);
281  G4cout << "\n----> The target is " << fTargetLength/cm << " cm of "
282  << materialName << G4endl;
283  }
284 }
285 
286 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
287 
289 {
290  // search the material by its name
291  G4Material* pttoMaterial = G4Material::GetMaterial(materialName);
292  if (pttoMaterial)
293  {ChamberMater = pttoMaterial;
294  logicChamber->SetMaterial(pttoMaterial);
295  G4cout << "\n----> The chambers are " << ChamberWidth/cm << " cm of "
296  << materialName << G4endl;
297  }
298 }
299 
300 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
301 
303 {
304  fpMagField->SetMagFieldValue(fieldValue);
305 }
306 
307 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
308 
310 {
311  if ((stepLimit)&&(maxStep>0.)) stepLimit->SetMaxAllowedStep(maxStep);
312 }
313 
314 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......