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 // ------------------------------------------- 26 // ------------------------------------------------------------ 27 // GEANT 4 class header file 27 // GEANT 4 class header file 28 // 28 // 29 // History: 29 // History: 30 // 17 August 2004 P. Gumplinger, T. MacP 30 // 17 August 2004 P. Gumplinger, T. MacPhail 31 // 11 April 2008 Kamil Sedlak (PSI), To 31 // 11 April 2008 Kamil Sedlak (PSI), Toni Shiroka (PSI) 32 // ------------------------------------------- 32 // ------------------------------------------------------------ 33 // 33 // 34 #include "G4DecayWithSpin.hh" 34 #include "G4DecayWithSpin.hh" 35 35 36 #include "G4Step.hh" 36 #include "G4Step.hh" 37 #include "G4Track.hh" 37 #include "G4Track.hh" 38 #include "G4DecayTable.hh" 38 #include "G4DecayTable.hh" 39 #include "G4MuonDecayChannelWithSpin.hh" 39 #include "G4MuonDecayChannelWithSpin.hh" 40 40 41 #include "G4PhysicalConstants.hh" 41 #include "G4PhysicalConstants.hh" 42 #include "G4SystemOfUnits.hh" 42 #include "G4SystemOfUnits.hh" 43 #include "G4Vector3D.hh" 43 #include "G4Vector3D.hh" 44 44 45 #include "G4TransportationManager.hh" 45 #include "G4TransportationManager.hh" 46 #include "G4PropagatorInField.hh" 46 #include "G4PropagatorInField.hh" 47 #include "G4FieldManager.hh" 47 #include "G4FieldManager.hh" 48 #include "G4Field.hh" 48 #include "G4Field.hh" 49 49 50 #include "G4Transform3D.hh" 50 #include "G4Transform3D.hh" 51 51 52 G4DecayWithSpin::G4DecayWithSpin(const G4Strin 52 G4DecayWithSpin::G4DecayWithSpin(const G4String& processName):G4Decay(processName) 53 { 53 { 54 // set Process Sub Type 54 // set Process Sub Type 55 SetProcessSubType(static_cast<int>(DECAY_Wit 55 SetProcessSubType(static_cast<int>(DECAY_WithSpin)); 56 56 57 } 57 } 58 58 59 G4DecayWithSpin::~G4DecayWithSpin(){} 59 G4DecayWithSpin::~G4DecayWithSpin(){} 60 60 61 G4VParticleChange* G4DecayWithSpin::PostStepDo 61 G4VParticleChange* G4DecayWithSpin::PostStepDoIt(const G4Track& aTrack, const G4Step& aStep) 62 { 62 { 63 if ( (aTrack.GetTrackStatus() == fStopButAli 63 if ( (aTrack.GetTrackStatus() == fStopButAlive ) || 64 (aTrack.GetTrackStatus() == fStopAndKil 64 (aTrack.GetTrackStatus() == fStopAndKill ) ){ 65 fParticleChangeForDecay.Initialize(aTrack) 65 fParticleChangeForDecay.Initialize(aTrack); 66 return &fParticleChangeForDecay; 66 return &fParticleChangeForDecay; 67 } 67 } 68 68 69 // get particle 69 // get particle 70 const G4DynamicParticle* aParticle = aTrack. 70 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle(); 71 const G4ParticleDefinition* aParticleDef = a 71 const G4ParticleDefinition* aParticleDef = aParticle->GetDefinition(); 72 72 73 // get parent_polarization 73 // get parent_polarization 74 G4ThreeVector parent_polarization = aParticl 74 G4ThreeVector parent_polarization = aParticle->GetPolarization(); 75 75 76 if(parent_polarization == G4ThreeVector(0,0, << 76 if(parent_polarization == G4ThreeVector(0,0,0)) >> 77 { 77 // Generate random polarization direction 78 // Generate random polarization direction >> 79 78 G4double cost = 1. - 2.*G4UniformRand(); 80 G4double cost = 1. - 2.*G4UniformRand(); 79 G4double sint = std::sqrt((1.-cost)*(1.+co 81 G4double sint = std::sqrt((1.-cost)*(1.+cost)); 80 82 81 G4double phi = twopi*G4UniformRand(); 83 G4double phi = twopi*G4UniformRand(); 82 G4double sinp = std::sin(phi); 84 G4double sinp = std::sin(phi); 83 G4double cosp = std::cos(phi); 85 G4double cosp = std::cos(phi); 84 86 85 G4double px = sint*cosp; 87 G4double px = sint*cosp; 86 G4double py = sint*sinp; 88 G4double py = sint*sinp; 87 G4double pz = cost; 89 G4double pz = cost; 88 90 89 parent_polarization.setX(px); 91 parent_polarization.setX(px); 90 parent_polarization.setY(py); 92 parent_polarization.setY(py); 91 parent_polarization.setZ(pz); 93 parent_polarization.setZ(pz); >> 94 92 } 95 } 93 96 94 // decay table 97 // decay table 95 G4DecayTable *decaytable = aParticleDef->Get 98 G4DecayTable *decaytable = aParticleDef->GetDecayTable(); 96 if (decaytable != nullptr) { << 99 if (decaytable) { 97 for (G4int ip=0; ip<decaytable->entries(); 100 for (G4int ip=0; ip<decaytable->entries(); ip++){ 98 decaytable->GetDecayChannel(ip)->SetPola 101 decaytable->GetDecayChannel(ip)->SetPolarization(parent_polarization); 99 } 102 } 100 } << 103 } 101 104 102 G4ParticleChangeForDecay* pParticleChangeFor 105 G4ParticleChangeForDecay* pParticleChangeForDecay; 103 pParticleChangeForDecay = (G4ParticleChangeF 106 pParticleChangeForDecay = (G4ParticleChangeForDecay*)G4Decay::DecayIt(aTrack,aStep); >> 107 104 pParticleChangeForDecay->ProposePolarization 108 pParticleChangeForDecay->ProposePolarization(parent_polarization); 105 109 >> 110 //G4cout << parent_polarization.x() << ", " >> 111 // << parent_polarization.y() << ", " >> 112 // << parent_polarization.z() << G4endl; >> 113 106 return pParticleChangeForDecay; 114 return pParticleChangeForDecay; 107 } 115 } 108 116 109 G4VParticleChange* G4DecayWithSpin::AtRestDoIt 117 G4VParticleChange* G4DecayWithSpin::AtRestDoIt(const G4Track& aTrack, const G4Step& aStep) 110 { 118 { 111 119 112 // get particle 120 // get particle 113 const G4DynamicParticle* aParticle = aTrack. 121 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle(); 114 const G4ParticleDefinition* aParticleDef = a 122 const G4ParticleDefinition* aParticleDef = aParticle->GetDefinition(); 115 123 116 // get parent_polarization 124 // get parent_polarization 117 G4ThreeVector parent_polarization = aParticl 125 G4ThreeVector parent_polarization = aParticle->GetPolarization(); 118 126 119 if(parent_polarization == G4ThreeVector(0,0, << 127 if(parent_polarization == G4ThreeVector(0,0,0)) >> 128 { 120 // Generate random polarization direction 129 // Generate random polarization direction >> 130 121 G4double cost = 1. - 2.*G4UniformRand(); 131 G4double cost = 1. - 2.*G4UniformRand(); 122 G4double sint = std::sqrt((1.-cost)*(1.+co 132 G4double sint = std::sqrt((1.-cost)*(1.+cost)); 123 133 124 G4double phi = twopi*G4UniformRand(); 134 G4double phi = twopi*G4UniformRand(); 125 G4double sinp = std::sin(phi); 135 G4double sinp = std::sin(phi); 126 G4double cosp = std::cos(phi); 136 G4double cosp = std::cos(phi); 127 137 128 G4double px = sint*cosp; 138 G4double px = sint*cosp; 129 G4double py = sint*sinp; 139 G4double py = sint*sinp; 130 G4double pz = cost; 140 G4double pz = cost; 131 141 132 parent_polarization.setX(px); 142 parent_polarization.setX(px); 133 parent_polarization.setY(py); 143 parent_polarization.setY(py); 134 parent_polarization.setZ(pz); 144 parent_polarization.setZ(pz); 135 145 136 }else{ 146 }else{ 137 147 138 G4FieldManager* fieldMgr = aStep.GetTrack( 148 G4FieldManager* fieldMgr = aStep.GetTrack()->GetVolume()-> 139 GetLogica 149 GetLogicalVolume()->GetFieldManager(); 140 if (fieldMgr == nullptr) { << 150 >> 151 if (!fieldMgr) { 141 G4TransportationManager *transportMgr = 152 G4TransportationManager *transportMgr = 142 G4TransportationManag 153 G4TransportationManager::GetTransportationManager(); 143 G4PropagatorInField* fFieldPropagator = 154 G4PropagatorInField* fFieldPropagator = 144 transp 155 transportMgr->GetPropagatorInField(); 145 if (fFieldPropagator) fieldMgr = 156 if (fFieldPropagator) fieldMgr = 146 fFieldPropag 157 fFieldPropagator->GetCurrentFieldManager(); 147 } 158 } 148 159 149 const G4Field* field = nullptr; << 160 const G4Field* field = NULL; 150 if (fieldMgr != nullptr) field = fieldMgr- << 161 if(fieldMgr)field = fieldMgr->GetDetectorField(); >> 162 >> 163 if (field) { 151 164 152 if ( field != nullptr ) { << 153 G4double point[4]; 165 G4double point[4]; 154 point[0] = (aStep.GetPostStepPoint()->G 166 point[0] = (aStep.GetPostStepPoint()->GetPosition())[0]; 155 point[1] = (aStep.GetPostStepPoint()->G 167 point[1] = (aStep.GetPostStepPoint()->GetPosition())[1]; 156 point[2] = (aStep.GetPostStepPoint()->G 168 point[2] = (aStep.GetPostStepPoint()->GetPosition())[2]; 157 point[3] = aTrack.GetGlobalTime(); 169 point[3] = aTrack.GetGlobalTime(); 158 170 159 G4double fieldValue[6] ={ 0., 0., 0., 0 << 171 G4double fieldValue[6]; 160 field -> GetFieldValue(point,fieldValue 172 field -> GetFieldValue(point,fieldValue); >> 173 161 G4ThreeVector B(fieldValue[0],fieldValu 174 G4ThreeVector B(fieldValue[0],fieldValue[1],fieldValue[2]); 162 175 163 // Call the spin precession only for no 176 // Call the spin precession only for non-zero mag. field 164 if (B.mag2() > 0.) parent_polarization 177 if (B.mag2() > 0.) parent_polarization = 165 Spin_Precessi 178 Spin_Precession(aStep,B,fRemainderLifeTime); 166 179 167 } 180 } 168 } 181 } 169 182 170 // decay table 183 // decay table 171 G4DecayTable *decaytable = aParticleDef->Get 184 G4DecayTable *decaytable = aParticleDef->GetDecayTable(); 172 if ( decaytable != nullptr) { << 185 if (decaytable) { 173 for (G4int ip=0; ip<decaytable->entries(); 186 for (G4int ip=0; ip<decaytable->entries(); ip++){ 174 decaytable->GetDecayChannel(ip)->SetPola 187 decaytable->GetDecayChannel(ip)->SetPolarization(parent_polarization); 175 } 188 } 176 } 189 } 177 190 178 G4ParticleChangeForDecay* pParticleChangeFor 191 G4ParticleChangeForDecay* pParticleChangeForDecay; 179 pParticleChangeForDecay = (G4ParticleChangeF 192 pParticleChangeForDecay = (G4ParticleChangeForDecay*)G4Decay::DecayIt(aTrack,aStep); >> 193 180 pParticleChangeForDecay->ProposePolarization 194 pParticleChangeForDecay->ProposePolarization(parent_polarization); 181 195 182 return pParticleChangeForDecay; 196 return pParticleChangeForDecay; 183 197 184 } 198 } 185 199 186 G4ThreeVector G4DecayWithSpin::Spin_Precession 200 G4ThreeVector G4DecayWithSpin::Spin_Precession( const G4Step& aStep, 187 G4Thre 201 G4ThreeVector B, G4double deltatime ) 188 { 202 { 189 G4double Bnorm = std::sqrt(sqr(B[0]) + sqr( 203 G4double Bnorm = std::sqrt(sqr(B[0]) + sqr(B[1]) +sqr(B[2]) ); 190 204 191 G4double q = aStep.GetTrack()->GetDefinition 205 G4double q = aStep.GetTrack()->GetDefinition()->GetPDGCharge(); 192 G4double a = 1.165922e-3; 206 G4double a = 1.165922e-3; 193 G4double s_omega = 8.5062e+7*rad/(s*kilogaus 207 G4double s_omega = 8.5062e+7*rad/(s*kilogauss); 194 208 195 G4double omega = -(q*s_omega)*(1.+a) * Bnorm 209 G4double omega = -(q*s_omega)*(1.+a) * Bnorm; 196 210 197 G4double rotationangle = deltatime * omega; 211 G4double rotationangle = deltatime * omega; 198 212 199 G4Transform3D SpinRotation = G4Rotate3D(rota 213 G4Transform3D SpinRotation = G4Rotate3D(rotationangle,B.unit()); 200 214 201 G4Vector3D Spin = aStep.GetTrack() -> GetPol 215 G4Vector3D Spin = aStep.GetTrack() -> GetPolarization(); 202 216 203 G4Vector3D newSpin = SpinRotation * Spin; 217 G4Vector3D newSpin = SpinRotation * Spin; 204 218 205 #ifdef G4VERBOSE 219 #ifdef G4VERBOSE 206 if (GetVerboseLevel()>2) { 220 if (GetVerboseLevel()>2) { 207 G4double normspin = std::sqrt(Spin*Spin); 221 G4double normspin = std::sqrt(Spin*Spin); 208 G4double normnewspin = std::sqrt(newSpin*n 222 G4double normnewspin = std::sqrt(newSpin*newSpin); 209 //G4double cosalpha = Spin*newSpin/normspi 223 //G4double cosalpha = Spin*newSpin/normspin/normnewspin; 210 //G4double alpha = std::acos(cosalpha); 224 //G4double alpha = std::acos(cosalpha); 211 225 212 G4cout << "AT REST::: PARAMETERS " << G4en 226 G4cout << "AT REST::: PARAMETERS " << G4endl; 213 G4cout << "Initial spin : " << Spin << G 227 G4cout << "Initial spin : " << Spin << G4endl; 214 G4cout << "Delta time : " << deltatime 228 G4cout << "Delta time : " << deltatime << G4endl; 215 G4cout << "Rotation angle: " << rotationan 229 G4cout << "Rotation angle: " << rotationangle/rad << G4endl; 216 G4cout << "New spin : " << newSpin < 230 G4cout << "New spin : " << newSpin << G4endl; 217 G4cout << "Checked norms : " << normspin < 231 G4cout << "Checked norms : " << normspin <<" " << normnewspin << G4endl; 218 } 232 } 219 #endif 233 #endif 220 234 221 return newSpin; 235 return newSpin; 222 236 223 } << 224 << 225 void G4DecayWithSpin::ProcessDescription(std:: << 226 { << 227 outFile << GetProcessName() << 228 << ": Decay of particles considering paren << 229 << "kinematics of daughters are dertermine << 230 } 237 } 231 238