File indexing completed on 2025-01-31 09:22:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
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
0047
0048 DetectorConstruction::DetectorConstruction()
0049 : G4VUserDetectorConstruction(), fConfiguration(-1) {
0050 DefineCommands();
0051 }
0052
0053
0054
0055 DetectorConstruction::~DetectorConstruction() {}
0056
0057
0058
0059 G4VPhysicalVolume *DetectorConstruction::Construct() {
0060
0061 fMaterials = new HGCalTBMaterials();
0062 fMaterials->SetEventDisplayColorScheme();
0063
0064
0065
0066
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
0081
0082 void DetectorConstruction::ConstructHGCal() {
0083
0084 G4double z0 = -fMaterials->GetBeamLineLength() / 2.;
0085
0086 std::cout << "Constructing configuration " << fConfiguration << std::endl;
0087
0088
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
0095
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
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
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
0159
0160 void DetectorConstruction::SetStepSizeSilicon(G4double val) {
0161
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
0173
0174 void DetectorConstruction::DefineCommands() {
0175
0176 fMessenger = new G4GenericMessenger(this, "/HGCalTestbeam/setup/",
0177 "Configuration specifications");
0178
0179
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