Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:22:21

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 #include "DetectorConstruction.hh"
0027 
0028 #include "HGCalTBMaterials.hh"
0029 #include "SiPMSD.hh"
0030 #include "SiliconPixelSD.hh"
0031 #include "DetectorConstruction0.hh"
0032 #include "DetectorConstruction1.hh"
0033 #include "DetectorConstruction2.hh"
0034 
0035 #include "G4Box.hh"
0036 #include "G4PVPlacement.hh"
0037 #include "G4GenericMessenger.hh"
0038 #include "G4LogicalVolume.hh"
0039 #include "G4ProductionCuts.hh"
0040 #include "G4RunManager.hh"
0041 #include "G4SDManager.hh"
0042 #include "G4UImanager.hh"
0043 #include "G4UserLimits.hh"
0044 #include "G4String.hh"
0045 
0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0047 
0048 DetectorConstruction::DetectorConstruction()
0049     : G4VUserDetectorConstruction(), fConfiguration(-1) {
0050   DefineCommands();
0051 }
0052 
0053 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0054 
0055 DetectorConstruction::~DetectorConstruction() {}
0056 
0057 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0058 
0059 G4VPhysicalVolume *DetectorConstruction::Construct() {
0060   // definition of the fMaterials
0061   fMaterials = new HGCalTBMaterials();
0062   fMaterials->SetEventDisplayColorScheme();
0063 
0064   /***** Definition of the world = beam line *****/
0065 
0066   // World = Beam line
0067   G4Box *solidWorld = new G4Box("World", 0.5 * fMaterials->GetBeamLineXY(),
0068                                 0.5 * fMaterials->GetBeamLineXY(),
0069                                 0.5 * fMaterials->GetBeamLineLength());
0070 
0071   G4Material *world_mat = fMaterials->GetAir();
0072   fLogicWorld = new G4LogicalVolume(solidWorld, world_mat, "World");
0073 
0074   G4VPhysicalVolume *physWorld = new G4PVPlacement(
0075       0, G4ThreeVector(0., 0., 0.), fLogicWorld, "World", 0, false, 0, true);
0076 
0077   return physWorld;
0078 }
0079 
0080 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0081 
0082 void DetectorConstruction::ConstructHGCal() {
0083 
0084   G4double z0 = -fMaterials->GetBeamLineLength() / 2.;
0085 
0086   std::cout << "Constructing configuration " << fConfiguration << std::endl;
0087 
0088   /*****    START GENERIC PLACEMENT ALGORITHM  FOR THE SETUP  *****/
0089   for (size_t item_index = 0; item_index < fElementsMap.size(); item_index++) {
0090     std::string item_type = fElementsMap[item_index].first;
0091     G4double dz = fElementsMap[item_index].second;
0092     z0 += dz;
0093 
0094     // places the item at inside the world at z0, z0 is incremented by the
0095     // item's thickness
0096     fMaterials->PlaceItemInLogicalVolume(item_type, z0, fLogicWorld);
0097   }
0098 
0099   G4RunManager::GetRunManager()->GeometryHasBeenModified();
0100   G4UImanager *UImanager = G4UImanager::GetUIpointer();
0101   UImanager->ApplyCommand("/vis/drawVolume");
0102   UImanager->ApplyCommand("/vis/viewer/set/targetPoint 0 0 " +
0103                           std::to_string(fVisViewpoint / CLHEP::m) + " m");
0104   UImanager->ApplyCommand("/vis/scene/add/trajectories smooth");
0105   UImanager->ApplyCommand("/vis/scene/add/hits");
0106 }
0107 
0108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0109 
0110 void DetectorConstruction::ConstructSDandField() {
0111   G4SDManager *sdman = G4SDManager::GetSDMpointer();
0112 
0113   SiliconPixelSD *sensitiveSilicon = new SiliconPixelSD(
0114       (fMaterials->GetSiPixelLogical()->GetName() + "_sensitive").c_str());
0115   sdman->AddNewDetector(sensitiveSilicon);
0116   fMaterials->GetSiPixelLogical()->SetSensitiveDetector(sensitiveSilicon);
0117 
0118   SiPMSD *sensitiveSiPM = new SiPMSD(
0119       (fMaterials->GetAHCALSiPMlogical()->GetName() + "_sensitive").c_str());
0120   sdman->AddNewDetector(sensitiveSiPM);
0121   fMaterials->GetAHCALSiPMlogical()->SetSensitiveDetector(sensitiveSiPM);
0122 }
0123 
0124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0125 
0126 void DetectorConstruction::SelectConfiguration(G4int val) {
0127 
0128   if (fConfiguration != -1) {
0129     G4ExceptionDescription msg;
0130     msg << "Configuration " << fConfiguration << " is already placed.\n"
0131         << "Configuration can be set only once. Please restart (and\n"
0132         << "edit your macro if necessary).\n";
0133     G4Exception("DetectorConstruction::SelectConfiguration()", "MultipleConfig",
0134                 JustWarning, msg);
0135     return;
0136   }
0137 
0138   fVisViewpoint = 0;
0139   if (val == 0)
0140     DetectorConstruction0(fElementsMap, fVisViewpoint);
0141   else if (val == 1)
0142     DetectorConstruction1(fElementsMap, fVisViewpoint);
0143   else if (val == 2)
0144     DetectorConstruction2(fElementsMap, fVisViewpoint);
0145   else {
0146     G4ExceptionDescription msg;
0147     msg << "Configuration " << val << " is not implemented.\n"
0148         << "Choose between configuration 0, 1, and 2.\n";
0149     G4Exception("DetectorConstruction::SelectConfiguration()", "WrongConfig",
0150                 JustWarning, msg);
0151     return;
0152   }
0153   fConfiguration = val;
0154 
0155   ConstructHGCal();
0156 }
0157 
0158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0159 
0160 void DetectorConstruction::SetStepSizeSilicon(G4double val) {
0161   // setting the step size in silicon:
0162   G4double maxTrackLength = val * 0.001 * CLHEP::mm;
0163   fMaterials->GetSiPixelLogical()->SetUserLimits(
0164       new G4UserLimits(0, maxTrackLength));
0165 
0166   G4Region *reg = fMaterials->GetSiPixelLogical()->GetRegion();
0167   G4ProductionCuts *cuts = new G4ProductionCuts;
0168   cuts->SetProductionCut(maxTrackLength);
0169   reg->SetProductionCuts(cuts);
0170 }
0171 
0172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0173 
0174 void DetectorConstruction::DefineCommands() {
0175   // define command directory using generic messenger class
0176   fMessenger = new G4GenericMessenger(this, "/HGCalTestbeam/setup/",
0177                                       "Configuration specifications");
0178 
0179   // configuration command
0180   auto &configCmd = fMessenger->DeclareMethod(
0181       "configuration", &DetectorConstruction::SelectConfiguration,
0182       "Select the configuration (0 for HGCal test beam, 1 for same HGCal"
0183       " with beamline (upstream material), or 2 for simple test setup)");
0184   configCmd.SetParameterName("index", true);
0185   configCmd.SetDefaultValue("0");
0186 
0187   auto &SiStepSizeCmd = fMessenger->DeclareMethod(
0188       "stepSilicon", &DetectorConstruction::SetStepSizeSilicon,
0189       "Maximum step size in silicon pixels, unit: microns");
0190   SiStepSizeCmd.SetParameterName("size", true);
0191   SiStepSizeCmd.SetDefaultValue("30.");
0192 }
0193 
0194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......