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