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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 /// \file persistency/P01/src/ExP01DetectorConstruction.cc
 27 /// \brief Implementation of the ExP01DetectorConstruction class
 28 //
 29 //
 30 //
 31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 33 
 34 #include "ExP01DetectorConstruction.hh"
 35 
 36 #include "ExP01ChamberParameterisation.hh"
 37 #include "ExP01DetectorMessenger.hh"
 38 #include "ExP01MagneticField.hh"
 39 #include "ExP01TrackerSD.hh"
 40 
 41 #include "G4Box.hh"
 42 #include "G4Colour.hh"
 43 #include "G4LogicalVolume.hh"
 44 #include "G4Material.hh"
 45 #include "G4PVParameterised.hh"
 46 #include "G4PVPlacement.hh"
 47 #include "G4SDManager.hh"
 48 #include "G4SystemOfUnits.hh"
 49 #include "G4UserLimits.hh"
 50 #include "G4VisAttributes.hh"
 51 #include "G4ios.hh"
 52 
 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 54 
 55 ExP01DetectorConstruction::ExP01DetectorConstruction()
 56   : G4VUserDetectorConstruction(),
 57     fSolidWorld(0),
 58     fLogicWorld(0),
 59     fPhysiWorld(0),
 60     fSolidTarget(0),
 61     fLogicTarget(0),
 62     fPhysiTarget(0),
 63     fSolidTracker(0),
 64     fLogicTracker(0),
 65     fPhysiTracker(0),
 66     fSolidChamber(0),
 67     fLogicChamber(0),
 68     fPhysiChamber(0),
 69     fTargetMater(0),
 70     fChamberMater(0),
 71     fPMagField(0),
 72     fDetectorMessenger(0),
 73     fWorldLength(0.),
 74     fTargetLength(0.),
 75     fTrackerLength(0.),
 76     fNbOfChambers(0),
 77     fChamberWidth(0.),
 78     fChamberSpacing(0.)
 79 {
 80   fPMagField = new ExP01MagneticField();
 81   fDetectorMessenger = new ExP01DetectorMessenger(this);
 82 }
 83 
 84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 85 
 86 ExP01DetectorConstruction::~ExP01DetectorConstruction()
 87 {
 88   delete fPMagField;
 89   delete fDetectorMessenger;
 90 }
 91 
 92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 93 
 94 G4VPhysicalVolume* ExP01DetectorConstruction::Construct()
 95 {
 96   //--------- Material definition ---------
 97 
 98   G4double a, z;
 99   G4double density, temperature, pressure;
100   G4int nel;
101 
102   // Air
103   G4Element* N = new G4Element("Nitrogen", "N", z = 7., a = 14.01 * g / mole);
104   G4Element* O = new G4Element("Oxygen", "O", z = 8., a = 16.00 * g / mole);
105 
106   G4Material* Air = new G4Material("Air", density = 1.29 * mg / cm3, nel = 2);
107   Air->AddElement(N, 70 * perCent);
108   Air->AddElement(O, 30 * perCent);
109 
110   // Lead
111   G4Material* Pb =
112     new G4Material("Lead", z = 82., a = 207.19 * g / mole, density = 11.35 * g / cm3);
113 
114   // Xenon gas
115   G4Material* Xenon =
116     new G4Material("XenonGas", z = 54., a = 131.29 * g / mole, density = 5.458 * mg / cm3,
117                    kStateGas, temperature = 293.15 * kelvin, pressure = 1 * atmosphere);
118 
119   // Print all the materials defined.
120   //
121   G4cout << G4endl << "The materials defined are : " << G4endl << G4endl;
122   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
123 
124   //--------- Sizes of the principal geometrical components (solids)  ---------
125 
126   fNbOfChambers = 5;
127   fChamberWidth = 20 * cm;
128   fChamberSpacing = 80 * cm;
129 
130   fTrackerLength = (fNbOfChambers + 1) * fChamberSpacing;  // Full length of Tracker
131   fTargetLength = 5.0 * cm;  // Full length of Target
132 
133   fTargetMater = Pb;
134   fChamberMater = Xenon;
135 
136   fWorldLength = 1.2 * (fTargetLength + fTrackerLength);
137 
138   G4double targetSize = 0.5 * fTargetLength;  // Half length of the Target
139   G4double trackerSize = 0.5 * fTrackerLength;  // Half length of the Tracker
140 
141   //--------- Definitions of Solids, Logical Volumes, Physical Volumes ---------
142 
143   //------------------------------
144   // World
145   //------------------------------
146 
147   G4double HalfWorldLength = 0.5 * fWorldLength;
148 
149   fSolidWorld = new G4Box("world", HalfWorldLength, HalfWorldLength, HalfWorldLength);
150   fLogicWorld = new G4LogicalVolume(fSolidWorld, Air, "World", 0, 0, 0);
151 
152   //  Must place the World Physical volume unrotated at (0,0,0).
153   //
154   fPhysiWorld = new G4PVPlacement(0,  // no rotation
155                                   G4ThreeVector(),  // at (0,0,0)
156                                   fLogicWorld,  // its logical volume
157                                   "World",  // its name
158                                   0,  // its mother  volume
159                                   false,  // no boolean operations
160                                   0);  // copy number
161 
162   //------------------------------
163   // Target
164   //------------------------------
165 
166   G4ThreeVector positionTarget = G4ThreeVector(0, 0, -(targetSize + trackerSize));
167 
168   fSolidTarget = new G4Box("target", targetSize, targetSize, targetSize);
169   fLogicTarget = new G4LogicalVolume(fSolidTarget, fTargetMater, "Target", 0, 0, 0);
170   fPhysiTarget = new G4PVPlacement(0,  // no rotation
171                                    positionTarget,  // at (x,y,z)
172                                    fLogicTarget,  // its logical volume
173                                    "Target",  // its name
174                                    fLogicWorld,  // its mother  volume
175                                    false,  // no boolean operations
176                                    0);  // copy number
177 
178   G4cout << "Target is " << fTargetLength / cm << " cm of " << fTargetMater->GetName() << G4endl;
179 
180   //------------------------------
181   // Tracker
182   //------------------------------
183 
184   G4ThreeVector positionTracker = G4ThreeVector(0, 0, 0);
185 
186   fSolidTracker = new G4Box("tracker", trackerSize, trackerSize, trackerSize);
187   fLogicTracker = new G4LogicalVolume(fSolidTracker, Air, "Tracker", 0, 0, 0);
188   fPhysiTracker = new G4PVPlacement(0,  // no rotation
189                                     positionTracker,  // at (x,y,z)
190                                     fLogicTracker,  // its logical volume
191                                     "Tracker",  // its name
192                                     fLogicWorld,  // its mother  volume
193                                     false,  // no boolean operations
194                                     0);  // copy number
195 
196   //------------------------------
197   // Tracker segments
198   //------------------------------
199   //
200   // An example of Parameterised volumes
201   // dummy values for G4Box -- modified by parameterised volume
202 
203   fSolidChamber = new G4Box("chamber", 100 * cm, 100 * cm, 10 * cm);
204   fLogicChamber = new G4LogicalVolume(fSolidChamber, fChamberMater, "Chamber", 0, 0, 0);
205 
206   G4double firstPosition = -trackerSize + 0.5 * fChamberWidth;
207   G4double firstLength = fTrackerLength / 10;
208   G4double lastLength = fTrackerLength;
209 
210   G4VPVParameterisation* chamberParam =
211     new ExP01ChamberParameterisation(fNbOfChambers,  // NoChambers
212                                      firstPosition,  // Z of center of first
213                                      fChamberSpacing,  // Z spacing of centers
214                                      fChamberWidth,  // Width Chamber
215                                      firstLength,  // lengthInitial
216                                      lastLength);  // lengthFinal
217 
218   // dummy value : kZAxis -- modified by parameterised volume
219   //
220   fPhysiChamber = new G4PVParameterised("Chamber",  // their name
221                                         fLogicChamber,  // their logical volume
222                                         fLogicTracker,  // Mother logical volume
223                                         kZAxis,  // Are placed along this axis
224                                         fNbOfChambers,  // Number of chambers
225                                         chamberParam);  // The parametrisation
226 
227   G4cout << "There are " << fNbOfChambers << " chambers in the tracker region. "
228          << "The chambers are " << fChamberWidth / mm << " mm of " << fChamberMater->GetName()
229          << "\n The distance between chamber is " << fChamberSpacing / cm << " cm" << G4endl;
230 
231   //------------------------------------------------
232   // Sensitive detectors
233   //------------------------------------------------
234 
235   G4SDManager* SDman = G4SDManager::GetSDMpointer();
236 
237   G4String trackerChamberSDname = "ExP01/TrackerChamberSD";
238   ExP01TrackerSD* aTrackerSD = new ExP01TrackerSD(trackerChamberSDname);
239   SDman->AddNewDetector(aTrackerSD);
240   fLogicChamber->SetSensitiveDetector(aTrackerSD);
241 
242   //--------- Visualization attributes -------------------------------
243 
244   G4VisAttributes* BoxVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
245   fLogicWorld->SetVisAttributes(BoxVisAtt);
246   fLogicTarget->SetVisAttributes(BoxVisAtt);
247   fLogicTracker->SetVisAttributes(BoxVisAtt);
248 
249   G4VisAttributes* ChamberVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 0.0));
250   fLogicChamber->SetVisAttributes(ChamberVisAtt);
251 
252   //--------- example of User Limits -------------------------------
253 
254   // below is an example of how to set tracking constraints in a given
255   // logical volume(see also in N02PhysicsList how to setup the processes
256   // G4StepLimiter or G4UserSpecialCuts).
257 
258   // Sets a max Step length in the tracker region, with G4StepLimiter
259   //
260   G4double maxStep = 0.5 * fChamberWidth;
261   fLogicTracker->SetUserLimits(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 fPhysiWorld;
270 }
271 
272 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
273 
274 void ExP01DetectorConstruction::SetTargetMaterial(G4String materialName)
275 {
276   // search the material by its name
277   G4Material* pttoMaterial = G4Material::GetMaterial(materialName);
278   if (pttoMaterial) {
279     fTargetMater = pttoMaterial;
280     fLogicTarget->SetMaterial(pttoMaterial);
281     G4cout << "\n----> The target is " << fTargetLength / cm << " cm of " << materialName << G4endl;
282   }
283 }
284 
285 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
286 
287 void ExP01DetectorConstruction::SetChamberMaterial(G4String materialName)
288 {
289   // search the material by its name
290   G4Material* pttoMaterial = G4Material::GetMaterial(materialName);
291   if (pttoMaterial) {
292     fChamberMater = pttoMaterial;
293     fLogicChamber->SetMaterial(pttoMaterial);
294     G4cout << "\n----> The chambers are " << fChamberWidth / cm << " cm of " << materialName
295            << G4endl;
296   }
297 }
298 
299 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
300 
301 void ExP01DetectorConstruction::SetMagField(G4double fieldValue)
302 {
303   fPMagField->SetFieldValue(fieldValue);
304 }
305 
306 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
307