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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 ]

Diff markup

Differences between /examples/advanced/HGCal_testbeam/src/DetectorConstruction.cc (Version 11.3.0) and /examples/advanced/HGCal_testbeam/src/DetectorConstruction.cc (Version 11.0.p1)


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