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] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 #include "DetectorConstruction.hh"
 27 
 28 #include "HGCalTBMaterials.hh"
 29 #include "SiPMSD.hh"
 30 #include "SiliconPixelSD.hh"
 31 #include "DetectorConstruction0.hh"
 32 #include "DetectorConstruction1.hh"
 33 #include "DetectorConstruction2.hh"
 34 
 35 #include "G4Box.hh"
 36 #include "G4PVPlacement.hh"
 37 #include "G4GenericMessenger.hh"
 38 #include "G4LogicalVolume.hh"
 39 #include "G4ProductionCuts.hh"
 40 #include "G4RunManager.hh"
 41 #include "G4SDManager.hh"
 42 #include "G4UImanager.hh"
 43 #include "G4UserLimits.hh"
 44 #include "G4String.hh"
 45 
 46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 47 
 48 DetectorConstruction::DetectorConstruction()
 49     : G4VUserDetectorConstruction(), fConfiguration(-1) {
 50   DefineCommands();
 51 }
 52 
 53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 54 
 55 DetectorConstruction::~DetectorConstruction() {}
 56 
 57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 58 
 59 G4VPhysicalVolume *DetectorConstruction::Construct() {
 60   // definition of the fMaterials
 61   fMaterials = new HGCalTBMaterials();
 62   fMaterials->SetEventDisplayColorScheme();
 63 
 64   /***** Definition of the world = beam line *****/
 65 
 66   // World = Beam line
 67   G4Box *solidWorld = new G4Box("World", 0.5 * fMaterials->GetBeamLineXY(),
 68                                 0.5 * fMaterials->GetBeamLineXY(),
 69                                 0.5 * fMaterials->GetBeamLineLength());
 70 
 71   G4Material *world_mat = fMaterials->GetAir();
 72   fLogicWorld = new G4LogicalVolume(solidWorld, world_mat, "World");
 73 
 74   G4VPhysicalVolume *physWorld = new G4PVPlacement(
 75       0, G4ThreeVector(0., 0., 0.), fLogicWorld, "World", 0, false, 0, true);
 76 
 77   return physWorld;
 78 }
 79 
 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 81 
 82 void DetectorConstruction::ConstructHGCal() {
 83 
 84   G4double z0 = -fMaterials->GetBeamLineLength() / 2.;
 85 
 86   std::cout << "Constructing configuration " << fConfiguration << std::endl;
 87 
 88   /*****    START GENERIC PLACEMENT ALGORITHM  FOR THE SETUP  *****/
 89   for (size_t item_index = 0; item_index < fElementsMap.size(); item_index++) {
 90     std::string item_type = fElementsMap[item_index].first;
 91     G4double dz = fElementsMap[item_index].second;
 92     z0 += dz;
 93 
 94     // places the item at inside the world at z0, z0 is incremented by the
 95     // item's thickness
 96     fMaterials->PlaceItemInLogicalVolume(item_type, z0, fLogicWorld);
 97   }
 98 
 99   G4RunManager::GetRunManager()->GeometryHasBeenModified();
100   G4UImanager *UImanager = G4UImanager::GetUIpointer();
101   UImanager->ApplyCommand("/vis/drawVolume");
102   UImanager->ApplyCommand("/vis/viewer/set/targetPoint 0 0 " +
103                           std::to_string(fVisViewpoint / CLHEP::m) + " m");
104   UImanager->ApplyCommand("/vis/scene/add/trajectories smooth");
105   UImanager->ApplyCommand("/vis/scene/add/hits");
106 }
107 
108 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
109 
110 void DetectorConstruction::ConstructSDandField() {
111   G4SDManager *sdman = G4SDManager::GetSDMpointer();
112 
113   SiliconPixelSD *sensitiveSilicon = new SiliconPixelSD(
114       (fMaterials->GetSiPixelLogical()->GetName() + "_sensitive").c_str());
115   sdman->AddNewDetector(sensitiveSilicon);
116   fMaterials->GetSiPixelLogical()->SetSensitiveDetector(sensitiveSilicon);
117 
118   SiPMSD *sensitiveSiPM = new SiPMSD(
119       (fMaterials->GetAHCALSiPMlogical()->GetName() + "_sensitive").c_str());
120   sdman->AddNewDetector(sensitiveSiPM);
121   fMaterials->GetAHCALSiPMlogical()->SetSensitiveDetector(sensitiveSiPM);
122 }
123 
124 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
125 
126 void DetectorConstruction::SelectConfiguration(G4int val) {
127 
128   if (fConfiguration != -1) {
129     G4ExceptionDescription msg;
130     msg << "Configuration " << fConfiguration << " is already placed.\n"
131         << "Configuration can be set only once. Please restart (and\n"
132         << "edit your macro if necessary).\n";
133     G4Exception("DetectorConstruction::SelectConfiguration()", "MultipleConfig",
134                 JustWarning, msg);
135     return;
136   }
137 
138   fVisViewpoint = 0;
139   if (val == 0)
140     DetectorConstruction0(fElementsMap, fVisViewpoint);
141   else if (val == 1)
142     DetectorConstruction1(fElementsMap, fVisViewpoint);
143   else if (val == 2)
144     DetectorConstruction2(fElementsMap, fVisViewpoint);
145   else {
146     G4ExceptionDescription msg;
147     msg << "Configuration " << val << " is not implemented.\n"
148         << "Choose between configuration 0, 1, and 2.\n";
149     G4Exception("DetectorConstruction::SelectConfiguration()", "WrongConfig",
150                 JustWarning, msg);
151     return;
152   }
153   fConfiguration = val;
154 
155   ConstructHGCal();
156 }
157 
158 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
159 
160 void DetectorConstruction::SetStepSizeSilicon(G4double val) {
161   // setting the step size in silicon:
162   G4double maxTrackLength = val * 0.001 * CLHEP::mm;
163   fMaterials->GetSiPixelLogical()->SetUserLimits(
164       new G4UserLimits(0, maxTrackLength));
165 
166   G4Region *reg = fMaterials->GetSiPixelLogical()->GetRegion();
167   G4ProductionCuts *cuts = new G4ProductionCuts;
168   cuts->SetProductionCut(maxTrackLength);
169   reg->SetProductionCuts(cuts);
170 }
171 
172 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
173 
174 void DetectorConstruction::DefineCommands() {
175   // define command directory using generic messenger class
176   fMessenger = new G4GenericMessenger(this, "/HGCalTestbeam/setup/",
177                                       "Configuration specifications");
178 
179   // configuration command
180   auto &configCmd = fMessenger->DeclareMethod(
181       "configuration", &DetectorConstruction::SelectConfiguration,
182       "Select the configuration (0 for HGCal test beam, 1 for same HGCal"
183       " with beamline (upstream material), or 2 for simple test setup)");
184   configCmd.SetParameterName("index", true);
185   configCmd.SetDefaultValue("0");
186 
187   auto &SiStepSizeCmd = fMessenger->DeclareMethod(
188       "stepSilicon", &DetectorConstruction::SetStepSizeSilicon,
189       "Maximum step size in silicon pixels, unit: microns");
190   SiStepSizeCmd.SetParameterName("size", true);
191   SiStepSizeCmd.SetDefaultValue("30.");
192 }
193 
194 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
195