Geant4 Cross Reference |
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 /// \file Par01/src/Par01PionShowerModel.cc 26 /// \file Par01/src/Par01PionShowerModel.cc 27 /// \brief Implementation of the Par01PionShow 27 /// \brief Implementation of the Par01PionShowerModel class 28 // 28 // 29 // 29 // 30 // 30 // 31 #include "Par01PionShowerModel.hh" 31 #include "Par01PionShowerModel.hh" 32 << 33 #include "Par01EnergySpot.hh" 32 #include "Par01EnergySpot.hh" 34 33 35 #include "G4Colour.hh" << 34 #include "Randomize.hh" 36 #include "G4PhysicalConstants.hh" << 35 37 #include "G4PionMinus.hh" 36 #include "G4PionMinus.hh" 38 #include "G4PionPlus.hh" 37 #include "G4PionPlus.hh" 39 #include "G4SystemOfUnits.hh" << 40 #include "G4TouchableHistory.hh" << 41 #include "G4TransportationManager.hh" 38 #include "G4TransportationManager.hh" 42 #include "G4VSensitiveDetector.hh" 39 #include "G4VSensitiveDetector.hh" 43 #include "Randomize.hh" << 40 #include "G4TouchableHistory.hh" >> 41 >> 42 #include "G4Colour.hh" >> 43 #include "G4PhysicalConstants.hh" >> 44 #include "G4SystemOfUnits.hh" 44 45 45 //....oooOO0OOooo........oooOO0OOooo........oo 46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 46 47 47 Par01PionShowerModel::Par01PionShowerModel(G4S 48 Par01PionShowerModel::Par01PionShowerModel(G4String modelName, G4Region* envelope) 48 : G4VFastSimulationModel(modelName, envelope << 49 : G4VFastSimulationModel(modelName, envelope) 49 { 50 { 50 fFakeStep = new G4Step(); << 51 fFakeStep = new G4Step(); 51 fFakePreStepPoint = fFakeStep->GetPreStepPoi << 52 fFakePreStepPoint = fFakeStep->GetPreStepPoint(); 52 fFakePostStepPoint = fFakeStep->GetPostStepP 53 fFakePostStepPoint = fFakeStep->GetPostStepPoint(); 53 fTouchableHandle = new G4TouchableHistory(); << 54 fTouchableHandle = new G4TouchableHistory(); 54 fpNavigator = new G4Navigator(); << 55 fpNavigator = new G4Navigator(); 55 fNaviSetup = false; << 56 fNaviSetup = false; 56 } 57 } 57 58 58 //....oooOO0OOooo........oooOO0OOooo........oo 59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 60 60 Par01PionShowerModel::Par01PionShowerModel(G4S << 61 Par01PionShowerModel::Par01PionShowerModel(G4String modelName) >> 62 : G4VFastSimulationModel(modelName) 61 { 63 { 62 fFakeStep = new G4Step(); << 64 fFakeStep = new G4Step(); 63 fFakePreStepPoint = fFakeStep->GetPreStepPoi << 65 fFakePreStepPoint = fFakeStep->GetPreStepPoint(); 64 fFakePostStepPoint = fFakeStep->GetPostStepP 66 fFakePostStepPoint = fFakeStep->GetPostStepPoint(); 65 fTouchableHandle = new G4TouchableHistory(); << 67 fTouchableHandle = new G4TouchableHistory(); 66 fpNavigator = new G4Navigator(); << 68 fpNavigator = new G4Navigator(); 67 fNaviSetup = false; << 69 fNaviSetup = false; 68 } 70 } 69 71 70 //....oooOO0OOooo........oooOO0OOooo........oo 72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 71 73 72 Par01PionShowerModel::~Par01PionShowerModel() 74 Par01PionShowerModel::~Par01PionShowerModel() 73 { 75 { 74 delete fFakeStep; 76 delete fFakeStep; 75 delete fpNavigator; 77 delete fpNavigator; 76 } 78 } 77 79 78 //....oooOO0OOooo........oooOO0OOooo........oo 80 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 81 80 G4bool Par01PionShowerModel::IsApplicable(cons 82 G4bool Par01PionShowerModel::IsApplicable(const G4ParticleDefinition& particleType) 81 { 83 { 82 return &particleType == G4PionMinus::PionMin << 84 return 83 || &particleType == G4PionPlus::PionP << 85 &particleType == G4PionMinus::PionMinusDefinition() || >> 86 &particleType == G4PionPlus::PionPlusDefinition(); 84 } 87 } 85 88 86 //....oooOO0OOooo........oooOO0OOooo........oo 89 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 87 90 88 G4bool Par01PionShowerModel::ModelTrigger(cons 91 G4bool Par01PionShowerModel::ModelTrigger(const G4FastTrack&) 89 { 92 { 90 // Applies the parameterisation always: 93 // Applies the parameterisation always: 91 // ie as soon as the pion enters the envelop 94 // ie as soon as the pion enters the envelope 92 return true; 95 return true; 93 } 96 } 94 97 95 //....oooOO0OOooo........oooOO0OOooo........oo 98 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 96 99 97 void Par01PionShowerModel::DoIt(const G4FastTr << 100 void Par01PionShowerModel::DoIt(const G4FastTrack& fastTrack, >> 101 G4FastStep& fastStep) 98 { 102 { 99 // G4cout << "Par01PionShowerModel::DoIt" < 103 // G4cout << "Par01PionShowerModel::DoIt" << G4endl; 100 104 101 // Kill the parameterised particle: 105 // Kill the parameterised particle: 102 fastStep.KillPrimaryTrack(); 106 fastStep.KillPrimaryTrack(); 103 fastStep.ProposePrimaryTrackPathLength(0.0); 107 fastStep.ProposePrimaryTrackPathLength(0.0); 104 fastStep.ProposeTotalEnergyDeposited(fastTra 108 fastStep.ProposeTotalEnergyDeposited(fastTrack.GetPrimaryTrack()->GetKineticEnergy()); 105 109 106 // split into "energy spots" energy accordin 110 // split into "energy spots" energy according to the shower shape: 107 Explode(fastTrack); 111 Explode(fastTrack); 108 << 112 109 // and put those energy spots into the cryst 113 // and put those energy spots into the crystals: 110 BuildDetectorResponse(); 114 BuildDetectorResponse(); 111 } 115 } 112 116 113 //....oooOO0OOooo........oooOO0OOooo........oo 117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 114 118 115 void Par01PionShowerModel::Explode(const G4Fas 119 void Par01PionShowerModel::Explode(const G4FastTrack& fastTrack) 116 { 120 { 117 //------------------------------------------ 121 //----------------------------------------------------- 118 // Non-physical shower generated: exp along 122 // Non-physical shower generated: exp along z and 119 // transverse. 123 // transverse. 120 //------------------------------------------ 124 //----------------------------------------------------- 121 125 122 // center of the shower, we put at the middl 126 // center of the shower, we put at the middle of the ghost: 123 G4ThreeVector showerCenter; 127 G4ThreeVector showerCenter; 124 G4double distOut; 128 G4double distOut; 125 distOut = fastTrack.GetEnvelopeSolid()->Dist << 129 distOut = fastTrack.GetEnvelopeSolid()-> 126 << 130 DistanceToOut(fastTrack.GetPrimaryTrackLocalPosition(), 127 showerCenter = fastTrack.GetPrimaryTrackLoca << 131 fastTrack.GetPrimaryTrackLocalDirection()); 128 + (distOut / 2.) * fastTrack. << 132 showerCenter = fastTrack.GetPrimaryTrackLocalPosition() + >> 133 (distOut/2.)*fastTrack.GetPrimaryTrackLocalDirection(); 129 134 130 showerCenter = fastTrack.GetInverseAffineTra << 135 showerCenter = fastTrack.GetInverseAffineTransformation()-> >> 136 TransformPoint(showerCenter); 131 137 132 // axis of the shower, in global reference f 138 // axis of the shower, in global reference frame: 133 G4ThreeVector xShower, yShower, zShower; 139 G4ThreeVector xShower, yShower, zShower; 134 zShower = fastTrack.GetPrimaryTrack()->GetMo 140 zShower = fastTrack.GetPrimaryTrack()->GetMomentumDirection(); 135 xShower = zShower.orthogonal(); 141 xShower = zShower.orthogonal(); 136 yShower = zShower.cross(xShower); 142 yShower = zShower.cross(xShower); 137 << 143 138 // shoot the energy spots: 144 // shoot the energy spots: 139 G4double Energy = fastTrack.GetPrimaryTrack( 145 G4double Energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy(); 140 G4int nSpot = 50; 146 G4int nSpot = 50; 141 G4double deposit = Energy / double(nSpot); << 147 G4double deposit = Energy/double(nSpot); 142 Par01EnergySpot eSpot; 148 Par01EnergySpot eSpot; 143 eSpot.SetEnergy(deposit); 149 eSpot.SetEnergy(deposit); 144 G4ThreeVector ePoint; 150 G4ThreeVector ePoint; 145 151 146 // clear the spot list before use 152 // clear the spot list before use 147 feSpotList.clear(); 153 feSpotList.clear(); 148 154 149 G4double z, r, phi; 155 G4double z, r, phi; 150 for (int i = 0; i < nSpot; i++) { << 156 for (int i = 0; i < nSpot; i++) 151 z = G4RandGauss::shoot(0, 20 * cm); << 157 { 152 r = G4RandGauss::shoot(0, 10 * cm); << 158 z = G4RandGauss::shoot(0,20*cm); 153 phi = G4UniformRand() * twopi; << 159 r = G4RandGauss::shoot(0,10*cm); 154 ePoint = showerCenter + z * zShower + r * << 160 phi = G4UniformRand()*twopi; 155 eSpot.SetPosition(ePoint); << 161 ePoint = showerCenter + 156 feSpotList.push_back(eSpot); << 162 z*zShower + 157 } << 163 r*std::cos(phi)*xShower + r*std::sin(phi)*yShower; >> 164 eSpot.SetPosition(ePoint); >> 165 feSpotList.push_back(eSpot); >> 166 } 158 } 167 } 159 168 160 //....oooOO0OOooo........oooOO0OOooo........oo 169 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 161 170 162 void Par01PionShowerModel::BuildDetectorRespon 171 void Par01PionShowerModel::BuildDetectorResponse() 163 { 172 { 164 // Does the assignation of the energy spots 173 // Does the assignation of the energy spots to the sensitive volumes: 165 for (size_t i = 0; i < feSpotList.size(); i+ << 174 for (size_t i = 0; i < feSpotList.size(); i++) 166 // Draw the energy spot: << 175 { 167 // G4Colour red(1.,0.,0.); << 176 // Draw the energy spot: 168 // feSpotList[i].Draw(&red); << 177 // G4Colour red(1.,0.,0.); 169 // feSpotList[i].Print(); << 178 // feSpotList[i].Draw(&red); 170 << 179 // feSpotList[i].Print(); 171 // "converts" the energy spot into the fak << 180 172 // G4Step to pass to sensitive detector: << 181 // "converts" the energy spot into the fake 173 AssignSpotAndCallHit(feSpotList[i]); << 182 // G4Step to pass to sensitive detector: 174 } << 183 AssignSpotAndCallHit(feSpotList[i]); >> 184 } 175 } 185 } 176 186 177 //....oooOO0OOooo........oooOO0OOooo........oo 187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 178 188 179 void Par01PionShowerModel::AssignSpotAndCallHi << 189 void Par01PionShowerModel::AssignSpotAndCallHit(const Par01EnergySpot &eSpot) 180 { 190 { 181 // 191 // 182 // "converts" the energy spot into the fake 192 // "converts" the energy spot into the fake 183 // G4Step to pass to sensitive detector: 193 // G4Step to pass to sensitive detector: 184 // 194 // 185 FillFakeStep(eSpot); 195 FillFakeStep(eSpot); 186 196 187 // 197 // 188 // call sensitive part: taken/adapted from t 198 // call sensitive part: taken/adapted from the stepping: 189 // Send G4Step information to Hit/Dig if the 199 // Send G4Step information to Hit/Dig if the volume is sensitive 190 // 200 // 191 G4VPhysicalVolume* pCurrentVolume = fFakeSte << 201 G4VPhysicalVolume* pCurrentVolume = >> 202 fFakeStep->GetPreStepPoint()->GetPhysicalVolume(); 192 G4VSensitiveDetector* pSensitive; 203 G4VSensitiveDetector* pSensitive; 193 << 204 194 if (pCurrentVolume != nullptr) { << 205 if( pCurrentVolume != 0 ) 195 pSensitive = pCurrentVolume->GetLogicalVol << 206 { 196 if (pSensitive != nullptr) { << 207 pSensitive = pCurrentVolume->GetLogicalVolume()-> 197 pSensitive->Hit(fFakeStep); << 208 GetSensitiveDetector(); >> 209 if( pSensitive != 0 ) >> 210 { >> 211 pSensitive->Hit(fFakeStep); >> 212 } 198 } 213 } 199 } << 200 } 214 } 201 215 202 //....oooOO0OOooo........oooOO0OOooo........oo 216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 203 217 204 void Par01PionShowerModel::FillFakeStep(const << 218 void Par01PionShowerModel::FillFakeStep(const Par01EnergySpot &eSpot) 205 { 219 { 206 //------------------------------------------ 220 //----------------------------------------------------------- 207 // find in which volume the spot is. 221 // find in which volume the spot is. 208 //------------------------------------------ 222 //----------------------------------------------------------- 209 if (!fNaviSetup) { << 223 if (!fNaviSetup) 210 fpNavigator->SetWorldVolume(G4Transportati << 224 { 211 ->GetNavigat << 225 fpNavigator-> 212 ->GetWorldVo << 226 SetWorldVolume(G4TransportationManager::GetTransportationManager()-> 213 fpNavigator->LocateGlobalPointAndUpdateTou << 227 GetNavigatorForTracking()->GetWorldVolume()); 214 eSpot.GetPosition(), G4ThreeVector(0., 0 << 228 fpNavigator-> 215 fNaviSetup = true; << 229 LocateGlobalPointAndUpdateTouchableHandle(eSpot.GetPosition(), 216 } << 230 G4ThreeVector(0.,0.,0.), 217 else { << 231 fTouchableHandle, 218 fpNavigator->LocateGlobalPointAndUpdateTou << 232 false); 219 eSpot.GetPosition(), G4ThreeVector(0., 0 << 233 fNaviSetup = true; 220 } << 234 } >> 235 else >> 236 { >> 237 fpNavigator-> >> 238 LocateGlobalPointAndUpdateTouchableHandle(eSpot.GetPosition(), >> 239 G4ThreeVector(0.,0.,0.), >> 240 fTouchableHandle); >> 241 } 221 //-------------------------------------- 242 //-------------------------------------- 222 // Fills attribute of the G4Step needed 243 // Fills attribute of the G4Step needed 223 // by our sensitive detector: 244 // by our sensitive detector: 224 //------------------------------------- 245 //------------------------------------- 225 // set touchable volume at PreStepPoint: 246 // set touchable volume at PreStepPoint: 226 fFakePreStepPoint->SetTouchableHandle(fTouch 247 fFakePreStepPoint->SetTouchableHandle(fTouchableHandle); 227 // set total energy deposit: 248 // set total energy deposit: 228 fFakeStep->SetTotalEnergyDeposit(eSpot.GetEn 249 fFakeStep->SetTotalEnergyDeposit(eSpot.GetEnergy()); 229 } 250 } 230 251