Back to home page

EIC code displayed by LXR

 
 

    


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

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 //
0027 /// \file B2bDetectorConstruction.cc
0028 /// \brief Implementation of the B2bDetectorConstruction class
0029 
0030 #include "B2bDetectorConstruction.hh"
0031 
0032 #include "B2TrackerSD.hh"
0033 #include "B2bChamberParameterisation.hh"
0034 #include "B2bDetectorMessenger.hh"
0035 
0036 #include "G4Box.hh"
0037 #include "G4Colour.hh"
0038 #include "G4GeometryManager.hh"
0039 #include "G4GeometryTolerance.hh"
0040 #include "G4GlobalMagFieldMessenger.hh"
0041 #include "G4LogicalVolume.hh"
0042 #include "G4Material.hh"
0043 #include "G4NistManager.hh"
0044 #include "G4PVParameterised.hh"
0045 #include "G4PVPlacement.hh"
0046 #include "G4SDManager.hh"
0047 #include "G4SystemOfUnits.hh"
0048 #include "G4Tubs.hh"
0049 #include "G4UserLimits.hh"
0050 #include "G4VisAttributes.hh"
0051 
0052 // #include "G4ios.hh"
0053 
0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0055 
0056 G4ThreadLocal G4GlobalMagFieldMessenger* B2bDetectorConstruction::fMagFieldMessenger = 0;
0057 
0058 B2bDetectorConstruction::B2bDetectorConstruction()
0059   : G4VUserDetectorConstruction(),
0060     fLogicTarget(NULL),
0061     fLogicChamber(NULL),
0062     fTargetMaterial(NULL),
0063     fChamberMaterial(NULL),
0064     fStepLimit(NULL),
0065     fCheckOverlaps(true)
0066 {
0067   fMessenger = new B2bDetectorMessenger(this);
0068 }
0069 
0070 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0071 
0072 B2bDetectorConstruction::~B2bDetectorConstruction()
0073 {
0074   delete fStepLimit;
0075   delete fMessenger;
0076   delete fMagFieldMessenger;
0077   fMagFieldMessenger = 0;
0078 }
0079 
0080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0081 
0082 G4VPhysicalVolume* B2bDetectorConstruction::Construct()
0083 {
0084   // Define materials
0085   DefineMaterials();
0086 
0087   // Define volumes
0088   return DefineVolumes();
0089 }
0090 
0091 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0092 
0093 void B2bDetectorConstruction::DefineMaterials()
0094 {
0095   // Material definition
0096 
0097   G4NistManager* nistManager = G4NistManager::Instance();
0098 
0099   // Air defined using NIST Manager
0100   nistManager->FindOrBuildMaterial("G4_AIR");
0101 
0102   // Lead defined using NIST Manager
0103   fTargetMaterial = nistManager->FindOrBuildMaterial("G4_Pb");
0104 
0105   // Xenon gas defined using NIST Manager
0106   fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe");
0107 
0108   // Print materials
0109   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
0110 }
0111 
0112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0113 
0114 G4VPhysicalVolume* B2bDetectorConstruction::DefineVolumes()
0115 {
0116   G4Material* air = G4Material::GetMaterial("G4_AIR");
0117 
0118   // Sizes of the principal geometrical components (solids)
0119 
0120   G4int NbOfChambers = 5;
0121   G4double chamberSpacing = 80 * cm;  // from chamber center to center!
0122 
0123   G4double chamberWidth = 20.0 * cm;  // width of the chambers
0124   G4double targetLength = 5.0 * cm;  // full length of Target
0125 
0126   G4double trackerLength = (NbOfChambers + 1) * chamberSpacing;
0127 
0128   G4double worldLength = 1.2 * (2 * targetLength + trackerLength);
0129 
0130   G4double targetRadius = 0.5 * targetLength;  // Radius of Target
0131   targetLength = 0.5 * targetLength;  // Half length of the Target
0132   G4double trackerSize = 0.5 * trackerLength;  // Half length of the Tracker
0133 
0134   // Definitions of Solids, Logical Volumes, Physical Volumes
0135 
0136   // World
0137 
0138   G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength);
0139 
0140   G4cout << "Computed tolerance = "
0141          << G4GeometryTolerance::GetInstance()->GetSurfaceTolerance() / mm << " mm" << G4endl;
0142 
0143   G4Box* worldS = new G4Box("world",  // its name
0144                             worldLength / 2, worldLength / 2, worldLength / 2);  // its size
0145   G4LogicalVolume* worldLV = new G4LogicalVolume(worldS,  // its solid
0146                                                  air,  // its material
0147                                                  "World");  // its name
0148 
0149   //  Must place the World Physical volume unrotated at (0,0,0).
0150   //
0151   G4VPhysicalVolume* worldPV = new G4PVPlacement(0,  // no rotation
0152                                                  G4ThreeVector(),  // at (0,0,0)
0153                                                  worldLV,  // its logical volume
0154                                                  "World",  // its name
0155                                                  0,  // its mother  volume
0156                                                  false,  // no boolean operations
0157                                                  0,  // copy number
0158                                                  fCheckOverlaps);  // checking overlaps
0159 
0160   // Target
0161 
0162   G4ThreeVector positionTarget = G4ThreeVector(0, 0, -(targetLength + trackerSize));
0163 
0164   G4Tubs* targetS = new G4Tubs("target", 0., targetRadius, targetLength, 0. * deg, 360. * deg);
0165   fLogicTarget = new G4LogicalVolume(targetS, fTargetMaterial, "Target", 0, 0, 0);
0166   new G4PVPlacement(0,  // no rotation
0167                     positionTarget,  // at (x,y,z)
0168                     fLogicTarget,  // its logical volume
0169                     "Target",  // its name
0170                     worldLV,  // its mother volume
0171                     false,  // no boolean operations
0172                     0,  // copy number
0173                     fCheckOverlaps);  // checking overlaps
0174 
0175   G4cout << "Target is " << 2 * targetLength / cm << " cm of " << fTargetMaterial->GetName()
0176          << G4endl;
0177 
0178   // Tracker
0179 
0180   G4ThreeVector positionTracker = G4ThreeVector(0, 0, 0);
0181 
0182   G4Tubs* trackerS = new G4Tubs("tracker", 0, trackerSize, trackerSize, 0. * deg, 360. * deg);
0183   G4LogicalVolume* trackerLV = new G4LogicalVolume(trackerS, air, "Tracker", 0, 0, 0);
0184   new G4PVPlacement(0,  // no rotation
0185                     positionTracker,  // at (x,y,z)
0186                     trackerLV,  // its logical volume
0187                     "Tracker",  // its name
0188                     worldLV,  // its mother  volume
0189                     false,  // no boolean operations
0190                     0,  // copy number
0191                     fCheckOverlaps);  // checking overlaps
0192 
0193   // Tracker segments
0194 
0195   // An example of Parameterised volumes
0196   // Dummy values for G4Tubs -- modified by parameterised volume
0197 
0198   G4Tubs* chamberS = new G4Tubs("tracker", 0, 100 * cm, 100 * cm, 0. * deg, 360. * deg);
0199   fLogicChamber = new G4LogicalVolume(chamberS, fChamberMaterial, "Chamber", 0, 0, 0);
0200 
0201   G4double firstPosition = -trackerSize + chamberSpacing;
0202   G4double firstLength = trackerLength / 10;
0203   G4double lastLength = trackerLength;
0204 
0205   G4VPVParameterisation* chamberParam =
0206     new B2bChamberParameterisation(NbOfChambers,  // NoChambers
0207                                    firstPosition,  // Z of center of first
0208                                    chamberSpacing,  // Z spacing of centers
0209                                    chamberWidth,  // chamber width
0210                                    firstLength,  // initial length
0211                                    lastLength);  // final length
0212 
0213   // dummy value : kZAxis -- modified by parameterised volume
0214 
0215   new G4PVParameterised("Chamber",  // their name
0216                         fLogicChamber,  // their logical volume
0217                         trackerLV,  // Mother logical volume
0218                         kZAxis,  // Are placed along this axis
0219                         NbOfChambers,  // Number of chambers
0220                         chamberParam,  // The parametrisation
0221                         fCheckOverlaps);  // checking overlaps
0222 
0223   G4cout << "There are " << NbOfChambers << " chambers in the tracker region. "
0224          << "\nThe chambers are " << chamberWidth / cm << " cm of " << fChamberMaterial->GetName()
0225          << "\nThe distance between chamber is " << chamberSpacing / cm << " cm" << G4endl;
0226 
0227   // Visualization attributes
0228 
0229   G4VisAttributes* boxVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 1.0));
0230   worldLV->SetVisAttributes(boxVisAtt);
0231   fLogicTarget->SetVisAttributes(boxVisAtt);
0232   trackerLV->SetVisAttributes(boxVisAtt);
0233 
0234   G4VisAttributes* chamberVisAtt = new G4VisAttributes(G4Colour(1.0, 1.0, 0.0));
0235   fLogicChamber->SetVisAttributes(chamberVisAtt);
0236 
0237   // Example of User Limits
0238   //
0239   // Below is an example of how to set tracking constraints in a given
0240   // logical volume
0241   //
0242   // Sets a max step length in the tracker region, with G4StepLimiter
0243 
0244   G4double maxStep = 0.5 * chamberWidth;
0245   fStepLimit = new G4UserLimits(maxStep);
0246   trackerLV->SetUserLimits(fStepLimit);
0247 
0248   /// Set additional contraints on the track, with G4UserSpecialCuts
0249   ///
0250   /// G4double maxLength = 2*trackerLength, maxTime = 0.1*ns, minEkin = 10*MeV;
0251   /// trackerLV->SetUserLimits(new G4UserLimits(maxStep,
0252   ///                                           maxLength,
0253   ///                                           maxTime,
0254   ///                                           minEkin));
0255 
0256   // Always return the physical world
0257 
0258   return worldPV;
0259 }
0260 
0261 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0262 
0263 void B2bDetectorConstruction::ConstructSDandField()
0264 {
0265   // Sensitive detectors
0266 
0267   G4String trackerChamberSDname = "B2/TrackerChamberSD";
0268   B2TrackerSD* aTrackerSD = new B2TrackerSD(trackerChamberSDname, "TrackerHitsCollection");
0269   G4SDManager::GetSDMpointer()->AddNewDetector(aTrackerSD);
0270   SetSensitiveDetector(fLogicChamber, aTrackerSD);
0271 
0272   // Create global magnetic field messenger.
0273   // Uniform magnetic field is then created automatically if
0274   // the field value is not zero.
0275   G4ThreeVector fieldValue = G4ThreeVector();
0276   fMagFieldMessenger = new G4GlobalMagFieldMessenger(fieldValue);
0277   fMagFieldMessenger->SetVerboseLevel(1);
0278 }
0279 
0280 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0281 
0282 void B2bDetectorConstruction::SetTargetMaterial(G4String materialName)
0283 {
0284   G4NistManager* nistManager = G4NistManager::Instance();
0285 
0286   G4Material* pttoMaterial = nistManager->FindOrBuildMaterial(materialName);
0287 
0288   if (fTargetMaterial != pttoMaterial) {
0289     if (pttoMaterial) {
0290       fTargetMaterial = pttoMaterial;
0291       if (fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
0292       G4cout << "\n----> The target is made of " << materialName << G4endl;
0293     }
0294     else {
0295       G4cout << "\n-->  WARNING from SetTargetMaterial : " << materialName << " not found"
0296              << G4endl;
0297     }
0298   }
0299 }
0300 
0301 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0302 
0303 void B2bDetectorConstruction::SetChamberMaterial(G4String materialName)
0304 {
0305   G4NistManager* nistManager = G4NistManager::Instance();
0306 
0307   G4Material* pttoMaterial = nistManager->FindOrBuildMaterial(materialName);
0308 
0309   if (fChamberMaterial != pttoMaterial) {
0310     if (pttoMaterial) {
0311       fChamberMaterial = pttoMaterial;
0312       if (fLogicChamber) fLogicChamber->SetMaterial(fChamberMaterial);
0313       G4cout << "\n----> The chambers are made of " << materialName << G4endl;
0314     }
0315     else {
0316       G4cout << "\n-->  WARNING from SetChamberMaterial : " << materialName << " not found"
0317              << G4endl;
0318     }
0319   }
0320 }
0321 
0322 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0323 
0324 void B2bDetectorConstruction::SetMaxStep(G4double maxStep)
0325 {
0326   if ((fStepLimit) && (maxStep > 0.)) fStepLimit->SetMaxAllowedStep(maxStep);
0327 }
0328 
0329 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......