Geant4 Cross Reference |
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 /// \file eventgenerator/HepMC/HepMCEx01/src/ExN04DetectorConstruction.cc 27 /// \brief Implementation of the ExN04DetectorConstruction class 28 // 29 // 30 31 #include "ExN04DetectorConstruction.hh" 32 33 #include "ExN04CalorimeterParametrisation.hh" 34 #include "ExN04CalorimeterROGeometry.hh" 35 #include "ExN04CalorimeterSD.hh" 36 #include "ExN04Field.hh" 37 #include "ExN04MuonSD.hh" 38 #include "ExN04TrackerParametrisation.hh" 39 #include "ExN04TrackerSD.hh" 40 41 #include "G4Box.hh" 42 #include "G4Colour.hh" 43 #include "G4Element.hh" 44 #include "G4FieldManager.hh" 45 #include "G4LogicalVolume.hh" 46 #include "G4Material.hh" 47 #include "G4MaterialTable.hh" 48 #include "G4NistManager.hh" 49 #include "G4PVParameterised.hh" 50 #include "G4PVPlacement.hh" 51 #include "G4RotationMatrix.hh" 52 #include "G4SDManager.hh" 53 #include "G4SystemOfUnits.hh" 54 #include "G4ThreeVector.hh" 55 #include "G4Transform3D.hh" 56 #include "G4TransportationManager.hh" 57 #include "G4Tubs.hh" 58 #include "G4VisAttributes.hh" 59 60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 61 ExN04DetectorConstruction::ExN04DetectorConstruction() : G4VUserDetectorConstruction() 62 { 63 #include "ExN04DetectorParameterDef.icc" 64 } 65 66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 67 ExN04DetectorConstruction::~ExN04DetectorConstruction() {} 68 69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 void ExN04DetectorConstruction::DefineMaterials() 71 { 72 //------------------------------------------------------------------------- 73 // Materials 74 //------------------------------------------------------------------------- 75 G4NistManager* nistManager = G4NistManager::Instance(); 76 fAir = nistManager->FindOrBuildMaterial("G4_AIR"); 77 fLead = nistManager->FindOrBuildMaterial("G4_Pb"); 78 fSilicon = nistManager->FindOrBuildMaterial("G4_Si"); 79 80 G4double a, z, density; 81 G4int nel; 82 83 // Argon gas 84 a = 39.95 * g / mole; 85 density = 1.782e-03 * g / cm3; 86 fAr = new G4Material("ArgonGas", z = 18., a, density); 87 88 // Scintillator 89 G4Element* elH = nistManager->FindOrBuildElement("H"); 90 G4Element* elC = nistManager->FindOrBuildElement("C"); 91 fScinti = new G4Material("Scintillator", density = 1.032 * g / cm3, nel = 2); 92 fScinti->AddElement(elC, 9); 93 fScinti->AddElement(elH, 10); 94 } 95 96 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 97 G4VPhysicalVolume* ExN04DetectorConstruction::Construct() 98 { 99 //------------------------------------------------------------------------- 100 // Magnetic field 101 //------------------------------------------------------------------------- 102 103 static G4bool fieldIsInitialized = false; 104 if (!fieldIsInitialized) { 105 ExN04Field* myField = new ExN04Field; 106 G4FieldManager* fieldMgr = 107 G4TransportationManager::GetTransportationManager()->GetFieldManager(); 108 fieldMgr->SetDetectorField(myField); 109 fieldMgr->CreateChordFinder(myField); 110 fieldIsInitialized = true; 111 } 112 113 //------------------------------------------------------------------------- 114 // Materials 115 //------------------------------------------------------------------------- 116 DefineMaterials(); 117 118 //------------------------------------------------------------------------- 119 // Detector geometry 120 //------------------------------------------------------------------------- 121 122 //------------------------------ experimental hall 123 G4Box* experimentalHall_box = new G4Box("expHall_b", fexpHall_x, fexpHall_y, fexpHall_z); 124 G4LogicalVolume* experimentalHall_log = 125 new G4LogicalVolume(experimentalHall_box, fAir, "expHall_L", 0, 0, 0); 126 G4VPhysicalVolume* experimentalHall_phys = 127 new G4PVPlacement(0, G4ThreeVector(), experimentalHall_log, "expHall_P", 0, false, 0); 128 G4VisAttributes* experimentalHallVisAtt = new G4VisAttributes(G4Colour(1., 1., 1.)); 129 experimentalHallVisAtt->SetForceWireframe(true); 130 experimentalHall_log->SetVisAttributes(experimentalHallVisAtt); 131 132 //------------------------------ tracker 133 G4VSolid* tracker_tubs = new G4Tubs("trkTubs_tubs", ftrkTubs_rmin, ftrkTubs_rmax, ftrkTubs_dz, 134 ftrkTubs_sphi, ftrkTubs_dphi); 135 G4LogicalVolume* tracker_log = new G4LogicalVolume(tracker_tubs, fAr, "trackerT_L", 0, 0, 0); 136 // G4VPhysicalVolume * tracker_phys = 137 new G4PVPlacement(0, G4ThreeVector(), tracker_log, "tracker_phys", experimentalHall_log, false, 138 0); 139 G4VisAttributes* tracker_logVisAtt = new G4VisAttributes(G4Colour(1.0, 0.0, 1.0)); 140 tracker_logVisAtt->SetForceWireframe(true); 141 tracker_log->SetVisAttributes(tracker_logVisAtt); 142 143 //------------------------------ tracker layers 144 // As an example for Parameterised volume 145 // dummy values for G4Tubs -- modified by parameterised volume 146 G4VSolid* trackerLayer_tubs = new G4Tubs("trackerLayer_tubs", ftrkTubs_rmin, ftrkTubs_rmax, 147 ftrkTubs_dz, ftrkTubs_sphi, ftrkTubs_dphi); 148 G4LogicalVolume* trackerLayer_log = 149 new G4LogicalVolume(trackerLayer_tubs, fSilicon, "trackerB_L", 0, 0, 0); 150 G4VPVParameterisation* trackerParam = new ExN04TrackerParametrisation; 151 // dummy value : kXAxis -- modified by parameterised volume 152 // G4VPhysicalVolume *trackerLayer_phys = 153 new G4PVParameterised("trackerLayer_phys", trackerLayer_log, tracker_log, kXAxis, fnotrkLayers, 154 trackerParam); 155 G4VisAttributes* trackerLayer_logVisAtt = new G4VisAttributes(G4Colour(0.5, 0.0, 1.0)); 156 trackerLayer_logVisAtt->SetForceWireframe(true); 157 trackerLayer_log->SetVisAttributes(trackerLayer_logVisAtt); 158 159 //------------------------------ calorimeter 160 G4VSolid* calorimeter_tubs = new G4Tubs("calorimeter_tubs", fcaloTubs_rmin, fcaloTubs_rmax, 161 fcaloTubs_dz, fcaloTubs_sphi, fcaloTubs_dphi); 162 G4LogicalVolume* calorimeter_log = 163 new G4LogicalVolume(calorimeter_tubs, fScinti, "caloT_L", 0, 0, 0); 164 // G4VPhysicalVolume * calorimeter_phys = 165 new G4PVPlacement(0, G4ThreeVector(), calorimeter_log, "caloM_P", experimentalHall_log, false, 0); 166 G4VisAttributes* calorimeter_logVisATT = new G4VisAttributes(G4Colour(1.0, 1.0, 0.0)); 167 calorimeter_logVisATT->SetForceWireframe(true); 168 calorimeter_log->SetVisAttributes(calorimeter_logVisATT); 169 170 //------------------------------- Lead layers 171 // As an example for Parameterised volume 172 // dummy values for G4Tubs -- modified by parameterised volume 173 G4VSolid* caloLayer_tubs = new G4Tubs("caloLayer_tubs", fcaloRing_rmin, fcaloRing_rmax, 174 fcaloRing_dz, fcaloRing_sphi, fcaloRing_dphi); 175 G4LogicalVolume* caloLayer_log = new G4LogicalVolume(caloLayer_tubs, fLead, "caloR_L", 0, 0, 0); 176 G4VPVParameterisation* calorimeterParam = new ExN04CalorimeterParametrisation; 177 // dummy value : kXAxis -- modified by parameterised volume 178 // G4VPhysicalVolume * caloLayer_phys = 179 new G4PVParameterised("caloLayer_phys", caloLayer_log, calorimeter_log, kXAxis, fnocaloLayers, 180 calorimeterParam); 181 G4VisAttributes* caloLayer_logVisAtt = new G4VisAttributes(G4Colour(0.7, 1.0, 0.0)); 182 caloLayer_logVisAtt->SetForceWireframe(true); 183 caloLayer_log->SetVisAttributes(caloLayer_logVisAtt); 184 185 //------------------------------ muon counters 186 // As an example of CSG volumes with rotation 187 G4VSolid* muoncounter_box = 188 new G4Box("muoncounter_box", fmuBox_width, fmuBox_thick, fmuBox_length); 189 G4LogicalVolume* muoncounter_log = 190 new G4LogicalVolume(muoncounter_box, fScinti, "mucounter_L", 0, 0, 0); 191 G4VPhysicalVolume* muoncounter_phys; 192 for (G4int i = 0; i < fnomucounter; i++) { 193 G4double phi, x, y, z; 194 phi = 360. * deg / fnomucounter * i; 195 x = fmuBox_radius * std::sin(phi); 196 y = fmuBox_radius * std::cos(phi); 197 z = 0. * cm; 198 G4RotationMatrix rm; 199 rm.rotateZ(phi); 200 muoncounter_phys = new G4PVPlacement(G4Transform3D(rm, G4ThreeVector(x, y, z)), muoncounter_log, 201 "muoncounter_P", experimentalHall_log, false, i); 202 } 203 G4VisAttributes* muoncounter_logVisAtt = new G4VisAttributes(G4Colour(0.0, 1.0, 1.0)); 204 muoncounter_logVisAtt->SetForceWireframe(true); 205 muoncounter_log->SetVisAttributes(muoncounter_logVisAtt); 206 207 //------------------------------------------------------------------ 208 // Sensitive Detector 209 //------------------------------------------------------------------ 210 211 G4SDManager* SDman = G4SDManager::GetSDMpointer(); 212 213 G4String trackerSDname = "/mydet/tracker"; 214 ExN04TrackerSD* trackerSD = new ExN04TrackerSD(trackerSDname); 215 SDman->AddNewDetector(trackerSD); 216 trackerLayer_log->SetSensitiveDetector(trackerSD); 217 218 G4String calorimeterSDname = "/mydet/calorimeter"; 219 ExN04CalorimeterSD* calorimeterSD = new ExN04CalorimeterSD(calorimeterSDname); 220 G4String ROgeometryName = "CalorimeterROGeom"; 221 G4VReadOutGeometry* calRO = new ExN04CalorimeterROGeometry(ROgeometryName); 222 calRO->BuildROGeometry(); 223 calorimeterSD->SetROgeometry(calRO); 224 SDman->AddNewDetector(calorimeterSD); 225 calorimeter_log->SetSensitiveDetector(calorimeterSD); 226 227 G4String muonSDname = "/mydet/muon"; 228 ExN04MuonSD* muonSD = new ExN04MuonSD(muonSDname); 229 SDman->AddNewDetector(muonSD); 230 muoncounter_log->SetSensitiveDetector(muonSD); 231 232 //------------------------------------------------------------------ 233 // Digitizer modules 234 //------------------------------------------------------------------ 235 236 return experimentalHall_phys; 237 } 238