Geant4 examples
basic/B2/B2b/src/B2bDetectorConstruction.cc
Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00030  
00031 #include "B2bDetectorConstruction.hh"
00032 #include "B2bDetectorMessenger.hh"
00033 #include "B2bChamberParameterisation.hh"
00034 #include "B2MagneticField.hh"
00035 #include "B2TrackerSD.hh"
00036 
00037 #include "G4Material.hh"
00038 #include "G4NistManager.hh"
00039 
00040 #include "G4Box.hh"
00041 #include "G4Tubs.hh"
00042 #include "G4LogicalVolume.hh"
00043 #include "G4PVPlacement.hh"
00044 #include "G4PVParameterised.hh"
00045 
00046 #include "G4SDManager.hh"
00047 
00048 #include "G4GeometryTolerance.hh"
00049 #include "G4GeometryManager.hh"
00050 
00051 #include "G4UserLimits.hh"
00052 
00053 #include "G4VisAttributes.hh"
00054 #include "G4Colour.hh"
00055 
00056 //#include "G4ios.hh"
00057 
00058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00059  
00060 B2bDetectorConstruction::B2bDetectorConstruction()
00061 : 
00062  fLogicTarget(NULL), fLogicChamber(NULL), 
00063  fTargetMaterial(NULL), fChamberMaterial(NULL), 
00064  fStepLimit(NULL),
00065  fCheckOverlaps(true)
00066 {
00067   fMessenger = new B2bDetectorMessenger(this);
00068   fMagField  = new B2MagneticField();
00069 }
00070 
00071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00072  
00073 B2bDetectorConstruction::~B2bDetectorConstruction()
00074 {
00075   delete fMagField;
00076   delete fStepLimit;
00077   delete fMessenger;             
00078 }
00079 
00080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00081  
00082 G4VPhysicalVolume* B2bDetectorConstruction::Construct()
00083 {
00084   // Define materials
00085   DefineMaterials();
00086 
00087   // Define volumes
00088   return DefineVolumes();
00089 }
00090 
00091 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00092 
00093 void B2bDetectorConstruction::DefineMaterials()
00094 {
00095   // Material definition 
00096 
00097   G4NistManager* nistManager = G4NistManager::Instance();
00098 
00099   G4bool fromIsotopes = false;
00100 
00101   // Air defined using NIST Manager
00102   nistManager->FindOrBuildMaterial("G4_AIR", fromIsotopes);
00103   
00104   // Lead defined using NIST Manager
00105   fTargetMaterial  = nistManager->FindOrBuildMaterial("G4_Pb", fromIsotopes);
00106 
00107   // Xenon gas defined using NIST Manager
00108   fChamberMaterial = nistManager->FindOrBuildMaterial("G4_Xe", fromIsotopes);
00109 
00110   // Print materials
00111   G4cout << *(G4Material::GetMaterialTable()) << G4endl;
00112 }
00113 
00114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00115 
00116 G4VPhysicalVolume* B2bDetectorConstruction::DefineVolumes()
00117 {
00118   G4Material* air  = G4Material::GetMaterial("G4_AIR");
00119 
00120   // Sizes of the principal geometrical components (solids)
00121   
00122   G4int NbOfChambers = 5;
00123   G4double chamberSpacing = 80*cm; // from chamber center to center!
00124 
00125   G4double chamberWidth = 20.0*cm; // width of the chambers
00126   G4double targetLength =  5.0*cm; // full length of Target
00127   
00128   G4double trackerLength = (NbOfChambers+1)*chamberSpacing;
00129 
00130   G4double worldLength = 1.2 * (2*targetLength + trackerLength);
00131 
00132   G4double targetRadius  = 0.5*targetLength;   // Radius of Target
00133   targetLength = 0.5*targetLength;             // Half length of the Target  
00134   G4double trackerSize   = 0.5*trackerLength;  // Half length of the Tracker
00135 
00136   // Definitions of Solids, Logical Volumes, Physical Volumes
00137 
00138   // World
00139 
00140   G4GeometryManager::GetInstance()->SetWorldMaximumExtent(worldLength);
00141 
00142   G4cout << "Computed tolerance = "
00143          << G4GeometryTolerance::GetInstance()->GetSurfaceTolerance()/mm
00144          << " mm" << G4endl;
00145 
00146   G4Box* worldS
00147     = new G4Box("world",                                    //its name
00148                 worldLength/2,worldLength/2,worldLength/2); //its size
00149   G4LogicalVolume* worldLV
00150     = new G4LogicalVolume(
00151                  worldS,   //its solid
00152                  air,      //its material
00153                  "World"); //its name
00154   
00155   //  Must place the World Physical volume unrotated at (0,0,0).
00156   // 
00157   G4VPhysicalVolume* worldPV
00158     = new G4PVPlacement(
00159                  0,               // no rotation
00160                  G4ThreeVector(), // at (0,0,0)
00161                  worldLV,         // its logical volume
00162                  "World",         // its name
00163                  0,               // its mother  volume
00164                  false,           // no boolean operations
00165                  0,               // copy number
00166                  fCheckOverlaps); // checking overlaps 
00167 
00168   // Target
00169   
00170   G4ThreeVector positionTarget = G4ThreeVector(0,0,-(targetLength+trackerSize));
00171 
00172   G4Tubs* targetS
00173     = new G4Tubs("target",0.,targetRadius,targetLength,0.*deg,360.*deg);
00174   fLogicTarget
00175     = new G4LogicalVolume(targetS, fTargetMaterial,"Target",0,0,0);
00176   new G4PVPlacement(0,              // no rotation
00177                     positionTarget, // at (x,y,z)
00178                     fLogicTarget,   // its logical volume
00179                     "Target",       // its name
00180                     worldLV,        // its mother volume
00181                     false,          // no boolean operations
00182                     0,              // copy number
00183                     fCheckOverlaps); // checking overlaps 
00184 
00185   G4cout << "Target is " << 2*targetLength/cm << " cm of "
00186          << fTargetMaterial->GetName() << G4endl;
00187 
00188   // Tracker
00189  
00190   G4ThreeVector positionTracker = G4ThreeVector(0,0,0);
00191 
00192   G4Tubs* trackerS
00193     = new G4Tubs("tracker",0,trackerSize,trackerSize, 0.*deg, 360.*deg);
00194   G4LogicalVolume* trackerLV
00195     = new G4LogicalVolume(trackerS, air, "Tracker",0,0,0);  
00196   new G4PVPlacement(0,               // no rotation
00197                     positionTracker, // at (x,y,z)
00198                     trackerLV,       // its logical volume
00199                     "Tracker",       // its name
00200                     worldLV,         // its mother  volume
00201                     false,           // no boolean operations
00202                     0,               // copy number
00203                     fCheckOverlaps); // checking overlaps 
00204 
00205   // Tracker segments
00206   
00207   // An example of Parameterised volumes
00208   // Dummy values for G4Tubs -- modified by parameterised volume
00209 
00210   G4Tubs* chamberS
00211     = new G4Tubs("tracker",0, 100*cm, 100*cm, 0.*deg, 360.*deg);
00212   fLogicChamber 
00213     = new G4LogicalVolume(chamberS,fChamberMaterial,"Chamber",0,0,0);
00214   
00215   G4double firstPosition = -trackerSize + chamberSpacing;
00216   G4double firstLength   = trackerLength/10;
00217   G4double lastLength    = trackerLength;
00218 
00219   G4VPVParameterisation* chamberParam =
00220     new B2bChamberParameterisation(
00221                                   NbOfChambers,   // NoChambers
00222                                   firstPosition,  // Z of center of first
00223                                   chamberSpacing, // Z spacing of centers
00224                                   chamberWidth,  // chamber width
00225                                   firstLength,    // initial length 
00226                                   lastLength);    // final length
00227                            
00228   // dummy value : kZAxis -- modified by parameterised volume
00229 
00230   new G4PVParameterised("Chamber",       // their name
00231                         fLogicChamber,   // their logical volume
00232                         trackerLV,       // Mother logical volume
00233                         kZAxis,          // Are placed along this axis 
00234                         NbOfChambers,    // Number of chambers
00235                         chamberParam,    // The parametrisation
00236                         fCheckOverlaps); // checking overlaps 
00237 
00238   G4cout << "There are " << NbOfChambers << " chambers in the tracker region. "
00239          << "\nThe chambers are " << chamberWidth/cm << " cm of " 
00240          << fChamberMaterial->GetName() << "\nThe distance between chamber is "
00241          << chamberSpacing/cm << " cm" << G4endl;
00242 
00243   // Sensitive detectors
00244 
00245   G4String trackerChamberSDname = "B2/TrackerChamberSD";
00246   B2TrackerSD* aTrackerSD = new B2TrackerSD(trackerChamberSDname,
00247                                             "TrackerHitsCollection");
00248   G4SDManager::GetSDMpointer()->AddNewDetector( aTrackerSD );
00249   fLogicChamber->SetSensitiveDetector( aTrackerSD );
00250 
00251   // Visualization attributes
00252 
00253   G4VisAttributes* boxVisAtt= new G4VisAttributes(G4Colour(1.0,1.0,1.0));
00254   worldLV   ->SetVisAttributes(boxVisAtt);  
00255   fLogicTarget ->SetVisAttributes(boxVisAtt);
00256   trackerLV ->SetVisAttributes(boxVisAtt);
00257 
00258   G4VisAttributes* chamberVisAtt = new G4VisAttributes(G4Colour(1.0,1.0,0.0));
00259   fLogicChamber->SetVisAttributes(chamberVisAtt);
00260   
00261   // Example of User Limits
00262   //
00263   // Below is an example of how to set tracking constraints in a given
00264   // logical volume
00265   //
00266   // Sets a max step length in the tracker region, with G4StepLimiter
00267 
00268   G4double maxStep = 0.5*chamberWidth;
00269   fStepLimit = new G4UserLimits(maxStep);
00270   trackerLV->SetUserLimits(fStepLimit);
00271   
00279 
00280   // Always return the physical world
00281 
00282   return worldPV;
00283 }
00284 
00285 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00286  
00287 void B2bDetectorConstruction::SetTargetMaterial(G4String materialName)
00288 {
00289   G4NistManager* nistManager = G4NistManager::Instance();
00290   G4bool fromIsotopes = false;
00291 
00292   G4Material* pttoMaterial =
00293               nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
00294 
00295   if (fTargetMaterial != pttoMaterial) {
00296      if ( pttoMaterial ) {
00297         fTargetMaterial = pttoMaterial;
00298         if (fLogicTarget) fLogicTarget->SetMaterial(fTargetMaterial);
00299         G4cout << "\n----> The target is made of " << materialName << G4endl;
00300      } else {
00301         G4cout << "\n-->  WARNING from SetTargetMaterial : "
00302                << materialName << " not found" << G4endl;
00303      }
00304   }
00305 }
00306  
00307 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00308 
00309 void B2bDetectorConstruction::SetChamberMaterial(G4String materialName)
00310 {
00311   G4NistManager* nistManager = G4NistManager::Instance();
00312   G4bool fromIsotopes = false;
00313 
00314   G4Material* pttoMaterial =
00315               nistManager->FindOrBuildMaterial(materialName, fromIsotopes);
00316 
00317   if (fChamberMaterial != pttoMaterial) {
00318      if ( pttoMaterial ) {
00319         fChamberMaterial = pttoMaterial;
00320         if (fLogicChamber) fLogicChamber->SetMaterial(fChamberMaterial);
00321         G4cout << "\n----> The chambers are made of " << materialName << G4endl;
00322      } else {
00323         G4cout << "\n-->  WARNING from SetChamberMaterial : "
00324                << materialName << " not found" << G4endl;
00325      }
00326   }
00327 }
00328 
00329 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00330  
00331 void B2bDetectorConstruction::SetMagField(G4double fieldValue)
00332 {
00333   fMagField->SetMagFieldValue(fieldValue);
00334 }
00335 
00336 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
00337 
00338 void B2bDetectorConstruction::SetMaxStep(G4double maxStep)
00339 {
00340   if ((fStepLimit)&&(maxStep>0.)) fStepLimit->SetMaxAllowedStep(maxStep);
00341 }
00342 
00343 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines