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 27 // User Classes 28 #include "Par04ParallelFullWorld.hh" 29 30 #include "Par04ParallelFullSensitiveDetector.hh" 31 #include "Par04ParallelMessenger.hh" 32 33 // G4 Classes 34 #include "G4AutoDelete.hh" 35 #include "G4Colour.hh" 36 #include "G4LogicalVolume.hh" 37 #include "G4Material.hh" 38 #include "G4NistManager.hh" 39 #include "G4PVPlacement.hh" 40 #include "G4PVReplica.hh" 41 #include "G4SDManager.hh" 42 #include "G4SystemOfUnits.hh" 43 #include "G4ThreeVector.hh" 44 #include "G4Tubs.hh" 45 #include "G4UnitsTable.hh" 46 #include "G4VPhysicalVolume.hh" 47 #include "G4VisAttributes.hh" 48 #include "globals.hh" 49 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 52 Par04ParallelFullWorld::Par04ParallelFullWorld(G4String aWorldName, 53 const Par04DetectorConstruction* aMassDetector) 54 : G4VUserParallelWorld(aWorldName), fMassDetector(aMassDetector) 55 { 56 fParallelMessenger = new Par04ParallelMessenger(this); 57 fNbOfLayers = fMassDetector->GetNbOfLayers(); 58 } 59 60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 61 62 Par04ParallelFullWorld::~Par04ParallelFullWorld() = default; 63 64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 65 66 void Par04ParallelFullWorld::Construct() 67 { 68 // In parallel world material does not matter 69 G4Material* dummy = nullptr; 70 71 // Build parallel geometry: 72 auto parallelLogicalVolume = GetWorld()->GetLogicalVolume(); 73 74 G4double detectorInnerRadius = fMassDetector->GetInnerRadius(); 75 G4double detectorLength = fMassDetector->GetLength(); 76 G4double fullLayerThickness = 77 fMassDetector->GetAbsorberThickness(0) + fMassDetector->GetAbsorberThickness(1); 78 G4double sensitiveLayerOffset = 0; 79 if (fMassDetector->GetAbsorberSensitivity(0)) 80 fLayerThickness = fMassDetector->GetAbsorberThickness(0); 81 else 82 sensitiveLayerOffset = fMassDetector->GetAbsorberThickness(0); 83 if (fMassDetector->GetAbsorberSensitivity(1)) 84 fLayerThickness += fMassDetector->GetAbsorberThickness(1); 85 86 fNbOfLayers = fMassDetector->GetNbOfLayers(); // Get an updated value 87 G4double detectorRadius = fNbOfLayers * fullLayerThickness; 88 G4double detectorOuterRadius = detectorInnerRadius + detectorRadius; 89 G4double rowThickness = detectorLength / fNbOfRows; 90 G4double full2Pi = 2. * CLHEP::pi * rad; 91 Print(); 92 93 // Insert cells to create a readout structure that contains both passive and active materials 94 // Mostly a copy from the detector construction 95 auto solidDetector = new G4Tubs("Detector", // name 96 detectorInnerRadius, // inner radius 97 detectorOuterRadius, // outer radius 98 detectorLength / 2., // half-width in Z 99 0, // start angle 100 full2Pi); // delta angle 101 auto logicDetector = new G4LogicalVolume(solidDetector, // solid 102 dummy, // material 103 "Detector"); // name 104 new G4PVPlacement(0, // no rotation 105 G4ThreeVector(0, 0, 0), // detector centre at (0,0,0) 106 logicDetector, // logical volume 107 "Detector", // name 108 parallelLogicalVolume, // mother volume 109 false, // not used 110 9999, // copy number 111 true); // check overlaps 112 113 //--------- Detector cylinder (division along z axis) --------- 114 auto solidRow = 115 new G4Tubs("Row", detectorInnerRadius, detectorOuterRadius, rowThickness / 2., 0, full2Pi); 116 117 auto logicRow = new G4LogicalVolume(solidRow, dummy, "Row"); 118 if (fNbOfRows > 1) 119 new G4PVReplica("Row", logicRow, logicDetector, kZAxis, fNbOfRows, rowThickness); 120 else 121 new G4PVPlacement(0, G4ThreeVector(), logicRow, "Row", logicDetector, false, 0); 122 123 //--------- Detector slices (division in azimuthal angle) --------- 124 G4double cellPhi = full2Pi / fNbOfSlices; 125 auto solidSlice = 126 new G4Tubs("Slice", detectorInnerRadius, detectorOuterRadius, rowThickness / 2, 0, cellPhi); 127 auto logicSlice = new G4LogicalVolume(solidSlice, dummy, "Slice"); 128 if (fNbOfLayers > 1 && fullLayerThickness == fLayerThickness) { 129 new G4PVReplica("Slice", logicSlice, logicRow, kPhi, fNbOfSlices, cellPhi, -cellPhi); 130 } 131 else { 132 // full simulation readout, cannot use replica because of gaps between absorbers 133 for (int iSlice = 0; iSlice < fNbOfSlices; iSlice++) { 134 auto rotation = new G4RotationMatrix(); 135 rotation->setPhi((iSlice + 0.5) * cellPhi); 136 new G4PVPlacement(rotation, G4ThreeVector(), logicSlice, "Slice_" + std::to_string(iSlice), 137 logicRow, false, iSlice); 138 } 139 } 140 141 //--------- Detector cells (division along radial axis) --------- 142 G4VisAttributes attribs; 143 attribs.SetColour(G4Colour(0, 1, 0, 0.1)); 144 attribs.SetForceSolid(true); 145 if (fNbOfLayers > 1 && fullLayerThickness == fLayerThickness) { 146 auto solidCell = new G4Tubs("Cell", detectorInnerRadius + sensitiveLayerOffset, 147 detectorInnerRadius + sensitiveLayerOffset + fLayerThickness, 148 rowThickness / 2, 0, cellPhi); 149 fLogicalCell.push_back(new G4LogicalVolume(solidCell, dummy, "Cell_0")); 150 new G4PVReplica("Cell", fLogicalCell.back(), logicSlice, kRho, fNbOfLayers, fLayerThickness, 151 detectorInnerRadius); 152 } 153 else { 154 // full simulation readout, cannot use replica because of gaps between absorbers 155 for (int iLayer = 0; iLayer < fNbOfLayers; iLayer++) { 156 auto solidCell = new G4Tubs( 157 "Cell_" + std::to_string(iLayer), 158 detectorInnerRadius + iLayer * fullLayerThickness + sensitiveLayerOffset, 159 detectorInnerRadius + iLayer * fullLayerThickness + sensitiveLayerOffset + fLayerThickness, 160 rowThickness / 2, 0, cellPhi); 161 fLogicalCell.push_back( 162 new G4LogicalVolume(solidCell, dummy, "Cell_" + std::to_string(iLayer))); 163 fLogicalCell.back()->SetVisAttributes(attribs); 164 new G4PVPlacement(0, G4ThreeVector(), fLogicalCell.back(), "Cell_" + std::to_string(iLayer), 165 logicSlice, false, iLayer); 166 } 167 } 168 Print(); 169 } 170 171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 172 173 void Par04ParallelFullWorld::ConstructSD() 174 { 175 // -- sensitive detectors: 176 G4SDManager* SDman = G4SDManager::GetSDMpointer(); 177 Par04ParallelFullSensitiveDetector* caloSD = 178 new Par04ParallelFullSensitiveDetector("parallelFullSD", fNbOfLayers, fNbOfSlices, fNbOfRows); 179 SDman->AddNewDetector(caloSD); 180 for (const auto& logicalCell : fLogicalCell) 181 logicalCell->SetSensitiveDetector(caloSD); 182 } 183 184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 185 186 void Par04ParallelFullWorld::Print() 187 { 188 G4cout << "\n------------------------------------------------------" 189 << "\n Readout geometry with physics layout is set in parallel geometry:\t" 190 << "\n Cylindrical detector is divided along radius (layers), phi (slices), and z (rows)." 191 << "\n Number of layers is determined by number of layers set in detector construction. " 192 << "\n- Number of layers: " << fNbOfLayers << "\n------- Number of slices: " << fNbOfSlices 193 << "\n- Number of rows: " << fNbOfRows; 194 G4cout << "\n Readout will collect energy for full simulation.\n------- Therefore thickness is " 195 << "only a thickness of sensitive absorbers = " << G4BestUnit(fLayerThickness, "Length") 196 << "\n-----------------------------------------------------" << G4endl; 197 } 198