Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:22:37

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file persistency/P01/src/ExP01DetectorConstruction.cc
0027 /// \brief Implementation of the ExP01DetectorConstruction class
0028 //
0029 //
0030 //
0031 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0032 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0033 
0034 #include "ExP01DetectorConstruction.hh"
0035 
0036 #include "ExP01ChamberParameterisation.hh"
0037 #include "ExP01DetectorMessenger.hh"
0038 #include "ExP01MagneticField.hh"
0039 #include "ExP01TrackerSD.hh"
0040 
0041 #include "G4Box.hh"
0042 #include "G4Colour.hh"
0043 #include "G4LogicalVolume.hh"
0044 #include "G4Material.hh"
0045 #include "G4PVParameterised.hh"
0046 #include "G4PVPlacement.hh"
0047 #include "G4SDManager.hh"
0048 #include "G4SystemOfUnits.hh"
0049 #include "G4UserLimits.hh"
0050 #include "G4VisAttributes.hh"
0051 #include "G4ios.hh"
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 ExP01DetectorConstruction::ExP01DetectorConstruction()
0056   : G4VUserDetectorConstruction(),
0057     fSolidWorld(0),
0058     fLogicWorld(0),
0059     fPhysiWorld(0),
0060     fSolidTarget(0),
0061     fLogicTarget(0),
0062     fPhysiTarget(0),
0063     fSolidTracker(0),
0064     fLogicTracker(0),
0065     fPhysiTracker(0),
0066     fSolidChamber(0),
0067     fLogicChamber(0),
0068     fPhysiChamber(0),
0069     fTargetMater(0),
0070     fChamberMater(0),
0071     fPMagField(0),
0072     fDetectorMessenger(0),
0073     fWorldLength(0.),
0074     fTargetLength(0.),
0075     fTrackerLength(0.),
0076     fNbOfChambers(0),
0077     fChamberWidth(0.),
0078     fChamberSpacing(0.)
0079 {
0080   fPMagField = new ExP01MagneticField();
0081   fDetectorMessenger = new ExP01DetectorMessenger(this);
0082 }
0083 
0084 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0085 
0086 ExP01DetectorConstruction::~ExP01DetectorConstruction()
0087 {
0088   delete fPMagField;
0089   delete fDetectorMessenger;
0090 }
0091 
0092 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0093 
0094 G4VPhysicalVolume* ExP01DetectorConstruction::Construct()
0095 {
0096   //--------- Material definition ---------
0097 
0098   G4double a, z;
0099   G4double density, temperature, pressure;
0100   G4int nel;
0101 
0102   // Air
0103   G4Element* N = new G4Element("Nitrogen", "N", z = 7., a = 14.01 * g / mole);
0104   G4Element* O = new G4Element("Oxygen", "O", z = 8., a = 16.00 * g / mole);
0105 
0106   G4Material* Air = new G4Material("Air", density = 1.29 * mg / cm3, nel = 2);
0107   Air->AddElement(N, 70 * perCent);
0108   Air->AddElement(O, 30 * perCent);
0109 
0110   // Lead
0111   G4Material* Pb =
0112     new G4Material("Lead", z = 82., a = 207.19 * g / mole, density = 11.35 * g / cm3);
0113 
0114   // Xenon gas
0115   G4Material* Xenon =
0116     new G4Material("XenonGas", z = 54., a = 131.29 * g / mole, density = 5.458 * mg / cm3,
0117                    kStateGas, temperature = 293.15 * kelvin, pressure = 1 * atmosphere);
0118 
0119   // Print all the materials defined.
0120   //
0121   G4cout << G4endl << "The materials defined are : " << G4endl << G4endl;
0122   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0123 
0124   //--------- Sizes of the principal geometrical components (solids)  ---------
0125 
0126   fNbOfChambers = 5;
0127   fChamberWidth = 20 * cm;
0128   fChamberSpacing = 80 * cm;
0129 
0130   fTrackerLength = (fNbOfChambers + 1) * fChamberSpacing;  // Full length of Tracker
0131   fTargetLength = 5.0 * cm;  // Full length of Target
0132 
0133   fTargetMater = Pb;
0134   fChamberMater = Xenon;
0135 
0136   fWorldLength = 1.2 * (fTargetLength + fTrackerLength);
0137 
0138   G4double targetSize = 0.5 * fTargetLength;  // Half length of the Target
0139   G4double trackerSize = 0.5 * fTrackerLength;  // Half length of the Tracker
0140 
0141   //--------- Definitions of Solids, Logical Volumes, Physical Volumes ---------
0142 
0143   //------------------------------
0144   // World
0145   //------------------------------
0146 
0147   G4double HalfWorldLength = 0.5 * fWorldLength;
0148 
0149   fSolidWorld = new G4Box("world", HalfWorldLength, HalfWorldLength, HalfWorldLength);
0150   fLogicWorld = new G4LogicalVolume(fSolidWorld, Air, "World", 0, 0, 0);
0151 
0152   //  Must place the World Physical volume unrotated at (0,0,0).
0153   //
0154   fPhysiWorld = new G4PVPlacement(0,  // no rotation
0155                                   G4ThreeVector(),  // at (0,0,0)
0156                                   fLogicWorld,  // its logical volume
0157                                   "World",  // its name
0158                                   0,  // its mother  volume
0159                                   false,  // no boolean operations
0160                                   0);  // copy number
0161 
0162   //------------------------------
0163   // Target
0164   //------------------------------
0165 
0166   G4ThreeVector positionTarget = G4ThreeVector(0, 0, -(targetSize + trackerSize));
0167 
0168   fSolidTarget = new G4Box("target", targetSize, targetSize, targetSize);
0169   fLogicTarget = new G4LogicalVolume(fSolidTarget, fTargetMater, "Target", 0, 0, 0);
0170   fPhysiTarget = new G4PVPlacement(0,  // no rotation
0171                                    positionTarget,  // at (x,y,z)
0172                                    fLogicTarget,  // its logical volume
0173                                    "Target",  // its name
0174                                    fLogicWorld,  // its mother  volume
0175                                    false,  // no boolean operations
0176                                    0);  // copy number
0177 
0178   G4cout << "Target is " << fTargetLength / cm << " cm of " << fTargetMater->GetName() << G4endl;
0179 
0180   //------------------------------
0181   // Tracker
0182   //------------------------------
0183 
0184   G4ThreeVector positionTracker = G4ThreeVector(0, 0, 0);
0185 
0186   fSolidTracker = new G4Box("tracker", trackerSize, trackerSize, trackerSize);
0187   fLogicTracker = new G4LogicalVolume(fSolidTracker, Air, "Tracker", 0, 0, 0);
0188   fPhysiTracker = new G4PVPlacement(0,  // no rotation
0189                                     positionTracker,  // at (x,y,z)
0190                                     fLogicTracker,  // its logical volume
0191                                     "Tracker",  // its name
0192                                     fLogicWorld,  // its mother  volume
0193                                     false,  // no boolean operations
0194                                     0);  // copy number
0195 
0196   //------------------------------
0197   // Tracker segments
0198   //------------------------------
0199   //
0200   // An example of Parameterised volumes
0201   // dummy values for G4Box -- modified by parameterised volume
0202 
0203   fSolidChamber = new G4Box("chamber", 100 * cm, 100 * cm, 10 * cm);
0204   fLogicChamber = new G4LogicalVolume(fSolidChamber, fChamberMater, "Chamber", 0, 0, 0);
0205 
0206   G4double firstPosition = -trackerSize + 0.5 * fChamberWidth;
0207   G4double firstLength = fTrackerLength / 10;
0208   G4double lastLength = fTrackerLength;
0209 
0210   G4VPVParameterisation* chamberParam =
0211     new ExP01ChamberParameterisation(fNbOfChambers,  // NoChambers
0212                                      firstPosition,  // Z of center of first
0213                                      fChamberSpacing,  // Z spacing of centers
0214                                      fChamberWidth,  // Width Chamber
0215                                      firstLength,  // lengthInitial
0216                                      lastLength);  // lengthFinal
0217 
0218   // dummy value : kZAxis -- modified by parameterised volume
0219   //
0220   fPhysiChamber = new G4PVParameterised("Chamber",  // their name
0221                                         fLogicChamber,  // their logical volume
0222                                         fLogicTracker,  // Mother logical volume
0223                                         kZAxis,  // Are placed along this axis
0224                                         fNbOfChambers,  // Number of chambers
0225                                         chamberParam);  // The parametrisation
0226 
0227   G4cout << "There are " << fNbOfChambers << " chambers in the tracker region. "
0228          << "The chambers are " << fChamberWidth / mm << " mm of " << fChamberMater->GetName()
0229          << "\n The distance between chamber is " << fChamberSpacing / cm << " cm" << G4endl;
0230 
0231   //------------------------------------------------
0232   // Sensitive detectors
0233   //------------------------------------------------
0234 
0235   G4SDManager* SDman = G4SDManager::GetSDMpointer();
0236 
0237   G4String trackerChamberSDname = "ExP01/TrackerChamberSD";
0238   ExP01TrackerSD* aTrackerSD = new ExP01TrackerSD(trackerChamberSDname);
0239   SDman->AddNewDetector(aTrackerSD);
0240   fLogicChamber->SetSensitiveDetector(aTrackerSD);
0241 
0242   //--------- Visualization attributes -------------------------------
0243 
0244   G4VisAttributes* BoxVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
0245   fLogicWorld->SetVisAttributes(BoxVisAtt);
0246   fLogicTarget->SetVisAttributes(BoxVisAtt);
0247   fLogicTracker->SetVisAttributes(BoxVisAtt);
0248 
0249   G4VisAttributes* ChamberVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 0.0));
0250   fLogicChamber->SetVisAttributes(ChamberVisAtt);
0251 
0252   //--------- example of User Limits -------------------------------
0253 
0254   // below is an example of how to set tracking constraints in a given
0255   // logical volume(see also in N02PhysicsList how to setup the processes
0256   // G4StepLimiter or G4UserSpecialCuts).
0257 
0258   // Sets a max Step length in the tracker region, with G4StepLimiter
0259   //
0260   G4double maxStep = 0.5 * fChamberWidth;
0261   fLogicTracker->SetUserLimits(new G4UserLimits(maxStep));
0262 
0263   // Set additional contraints on the track, with G4UserSpecialCuts
0264   //
0265   // G4double maxLength = 2*fTrackerLength, maxTime = 0.1*ns, minEkin = 10*MeV;
0266   // logicTracker->SetUserLimits(new G4UserLimits(maxStep,maxLength,maxTime,
0267   //                                               minEkin));
0268 
0269   return fPhysiWorld;
0270 }
0271 
0272 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0273 
0274 void ExP01DetectorConstruction::SetTargetMaterial(G4String materialName)
0275 {
0276   // search the material by its name
0277   G4Material* pttoMaterial = G4Material::GetMaterial(materialName);
0278   if (pttoMaterial) {
0279     fTargetMater = pttoMaterial;
0280     fLogicTarget->SetMaterial(pttoMaterial);
0281     G4cout << "\n----> The target is " << fTargetLength / cm << " cm of " << materialName << G4endl;
0282   }
0283 }
0284 
0285 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0286 
0287 void ExP01DetectorConstruction::SetChamberMaterial(G4String materialName)
0288 {
0289   // search the material by its name
0290   G4Material* pttoMaterial = G4Material::GetMaterial(materialName);
0291   if (pttoMaterial) {
0292     fChamberMater = pttoMaterial;
0293     fLogicChamber->SetMaterial(pttoMaterial);
0294     G4cout << "\n----> The chambers are " << fChamberWidth / cm << " cm of " << materialName
0295            << G4endl;
0296   }
0297 }
0298 
0299 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0300 
0301 void ExP01DetectorConstruction::SetMagField(G4double fieldValue)
0302 {
0303   fPMagField->SetFieldValue(fieldValue);
0304 }
0305 
0306 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......