Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // ------------------------------------------- 23 // ------------------------------------------------------------ 27 // GEANT 4 class header file 24 // GEANT 4 class header file 28 // 25 // 29 // History: 26 // History: 30 // 17 August 2004 P. Gumplinger, T. MacP 27 // 17 August 2004 P. Gumplinger, T. MacPhail 31 // 11 April 2008 Kamil Sedlak (PSI), To << 32 // ------------------------------------------- 28 // ------------------------------------------------------------ 33 // 29 // 34 #include "G4DecayWithSpin.hh" 30 #include "G4DecayWithSpin.hh" 35 31 36 #include "G4Step.hh" 32 #include "G4Step.hh" 37 #include "G4Track.hh" 33 #include "G4Track.hh" 38 #include "G4DecayTable.hh" 34 #include "G4DecayTable.hh" 39 #include "G4MuonDecayChannelWithSpin.hh" 35 #include "G4MuonDecayChannelWithSpin.hh" 40 36 41 #include "G4PhysicalConstants.hh" << 42 #include "G4SystemOfUnits.hh" << 43 #include "G4Vector3D.hh" 37 #include "G4Vector3D.hh" 44 38 45 #include "G4TransportationManager.hh" 39 #include "G4TransportationManager.hh" 46 #include "G4PropagatorInField.hh" 40 #include "G4PropagatorInField.hh" 47 #include "G4FieldManager.hh" 41 #include "G4FieldManager.hh" 48 #include "G4Field.hh" 42 #include "G4Field.hh" 49 43 50 #include "G4Transform3D.hh" 44 #include "G4Transform3D.hh" 51 45 52 G4DecayWithSpin::G4DecayWithSpin(const G4Strin << 46 G4DecayWithSpin::G4DecayWithSpin(const G4String& processName):G4Decay(processName){} 53 { << 54 // set Process Sub Type << 55 SetProcessSubType(static_cast<int>(DECAY_Wit << 56 << 57 } << 58 47 59 G4DecayWithSpin::~G4DecayWithSpin(){} 48 G4DecayWithSpin::~G4DecayWithSpin(){} 60 49 61 G4VParticleChange* G4DecayWithSpin::PostStepDo << 50 G4VParticleChange* G4DecayWithSpin::DecayIt(const G4Track& aTrack, const G4Step& aStep) 62 { 51 { 63 if ( (aTrack.GetTrackStatus() == fStopButAli << 64 (aTrack.GetTrackStatus() == fStopAndKil << 65 fParticleChangeForDecay.Initialize(aTrack) << 66 return &fParticleChangeForDecay; << 67 } << 68 52 69 // get particle 53 // get particle 70 const G4DynamicParticle* aParticle = aTrack. 54 const G4DynamicParticle* aParticle = aTrack.GetDynamicParticle(); 71 const G4ParticleDefinition* aParticleDef = a << 55 G4ParticleDefinition* aParticleDef = aParticle->GetDefinition(); 72 56 73 // get parent_polarization 57 // get parent_polarization 74 G4ThreeVector parent_polarization = aParticl 58 G4ThreeVector parent_polarization = aParticle->GetPolarization(); 75 59 76 if(parent_polarization == G4ThreeVector(0,0, << 60 if(parent_polarization == G4ThreeVector(0,0,0)) >> 61 { 77 // Generate random polarization direction 62 // Generate random polarization direction 78 G4double cost = 1. - 2.*G4UniformRand(); << 79 G4double sint = std::sqrt((1.-cost)*(1.+co << 80 << 81 G4double phi = twopi*G4UniformRand(); << 82 G4double sinp = std::sin(phi); << 83 G4double cosp = std::cos(phi); << 84 << 85 G4double px = sint*cosp; << 86 G4double py = sint*sinp; << 87 G4double pz = cost; << 88 63 89 parent_polarization.setX(px); << 90 parent_polarization.setY(py); << 91 parent_polarization.setZ(pz); << 92 } << 93 << 94 // decay table << 95 G4DecayTable *decaytable = aParticleDef->Get << 96 if (decaytable != nullptr) { << 97 for (G4int ip=0; ip<decaytable->entries(); << 98 decaytable->GetDecayChannel(ip)->SetPola << 99 } << 100 } << 101 << 102 G4ParticleChangeForDecay* pParticleChangeFor << 103 pParticleChangeForDecay = (G4ParticleChangeF << 104 pParticleChangeForDecay->ProposePolarization << 105 << 106 return pParticleChangeForDecay; << 107 } << 108 << 109 G4VParticleChange* G4DecayWithSpin::AtRestDoIt << 110 { << 111 << 112 // get particle << 113 const G4DynamicParticle* aParticle = aTrack. << 114 const G4ParticleDefinition* aParticleDef = a << 115 << 116 // get parent_polarization << 117 G4ThreeVector parent_polarization = aParticl << 118 << 119 if(parent_polarization == G4ThreeVector(0,0, << 120 // Generate random polarization direction << 121 G4double cost = 1. - 2.*G4UniformRand(); 64 G4double cost = 1. - 2.*G4UniformRand(); 122 G4double sint = std::sqrt((1.-cost)*(1.+co 65 G4double sint = std::sqrt((1.-cost)*(1.+cost)); 123 66 124 G4double phi = twopi*G4UniformRand(); 67 G4double phi = twopi*G4UniformRand(); 125 G4double sinp = std::sin(phi); 68 G4double sinp = std::sin(phi); 126 G4double cosp = std::cos(phi); 69 G4double cosp = std::cos(phi); 127 70 128 G4double px = sint*cosp; 71 G4double px = sint*cosp; 129 G4double py = sint*sinp; 72 G4double py = sint*sinp; 130 G4double pz = cost; 73 G4double pz = cost; 131 74 132 parent_polarization.setX(px); 75 parent_polarization.setX(px); 133 parent_polarization.setY(py); 76 parent_polarization.setY(py); 134 parent_polarization.setZ(pz); 77 parent_polarization.setZ(pz); 135 78 136 }else{ 79 }else{ 137 80 138 G4FieldManager* fieldMgr = aStep.GetTrack( 81 G4FieldManager* fieldMgr = aStep.GetTrack()->GetVolume()-> 139 GetLogica 82 GetLogicalVolume()->GetFieldManager(); 140 if (fieldMgr == nullptr) { << 83 >> 84 if (!fieldMgr) { 141 G4TransportationManager *transportMgr = 85 G4TransportationManager *transportMgr = 142 G4TransportationManag 86 G4TransportationManager::GetTransportationManager(); 143 G4PropagatorInField* fFieldPropagator = 87 G4PropagatorInField* fFieldPropagator = 144 transp 88 transportMgr->GetPropagatorInField(); 145 if (fFieldPropagator) fieldMgr = 89 if (fFieldPropagator) fieldMgr = 146 fFieldPropag 90 fFieldPropagator->GetCurrentFieldManager(); 147 } 91 } 148 92 149 const G4Field* field = nullptr; << 93 const G4Field* field = NULL; 150 if (fieldMgr != nullptr) field = fieldMgr- << 94 if(fieldMgr)field = fieldMgr->GetDetectorField(); >> 95 >> 96 if (field && !(fieldMgr->DoesFieldChangeEnergy())) { 151 97 152 if ( field != nullptr ) { << 153 G4double point[4]; 98 G4double point[4]; 154 point[0] = (aStep.GetPostStepPoint()->G 99 point[0] = (aStep.GetPostStepPoint()->GetPosition())[0]; 155 point[1] = (aStep.GetPostStepPoint()->G 100 point[1] = (aStep.GetPostStepPoint()->GetPosition())[1]; 156 point[2] = (aStep.GetPostStepPoint()->G 101 point[2] = (aStep.GetPostStepPoint()->GetPosition())[2]; 157 point[3] = aTrack.GetGlobalTime(); 102 point[3] = aTrack.GetGlobalTime(); 158 103 159 G4double fieldValue[6] ={ 0., 0., 0., 0 << 104 G4double fieldValue[3]; 160 field -> GetFieldValue(point,fieldValue 105 field -> GetFieldValue(point,fieldValue); >> 106 161 G4ThreeVector B(fieldValue[0],fieldValu 107 G4ThreeVector B(fieldValue[0],fieldValue[1],fieldValue[2]); 162 108 163 // Call the spin precession only for no << 109 parent_polarization = Spin_Precession(aStep,B,fRemainderLifeTime); 164 if (B.mag2() > 0.) parent_polarization << 165 Spin_Precessi << 166 110 167 } 111 } 168 } 112 } 169 113 170 // decay table 114 // decay table 171 G4DecayTable *decaytable = aParticleDef->Get 115 G4DecayTable *decaytable = aParticleDef->GetDecayTable(); 172 if ( decaytable != nullptr) { << 116 173 for (G4int ip=0; ip<decaytable->entries(); << 117 if (decaytable) { 174 decaytable->GetDecayChannel(ip)->SetPola << 118 G4MuonDecayChannelWithSpin *decaychannel; 175 } << 119 decaychannel = (G4MuonDecayChannelWithSpin*)decaytable->SelectADecayChannel(); 176 } << 120 if (decaychannel) decaychannel->SetPolarization(parent_polarization); >> 121 } 177 122 178 G4ParticleChangeForDecay* pParticleChangeFor 123 G4ParticleChangeForDecay* pParticleChangeForDecay; >> 124 179 pParticleChangeForDecay = (G4ParticleChangeF 125 pParticleChangeForDecay = (G4ParticleChangeForDecay*)G4Decay::DecayIt(aTrack,aStep); >> 126 180 pParticleChangeForDecay->ProposePolarization 127 pParticleChangeForDecay->ProposePolarization(parent_polarization); 181 128 182 return pParticleChangeForDecay; 129 return pParticleChangeForDecay; 183 130 184 } 131 } 185 132 186 G4ThreeVector G4DecayWithSpin::Spin_Precession 133 G4ThreeVector G4DecayWithSpin::Spin_Precession( const G4Step& aStep, 187 G4Thre 134 G4ThreeVector B, G4double deltatime ) 188 { 135 { 189 G4double Bnorm = std::sqrt(sqr(B[0]) + sqr( 136 G4double Bnorm = std::sqrt(sqr(B[0]) + sqr(B[1]) +sqr(B[2]) ); 190 137 191 G4double q = aStep.GetTrack()->GetDefinition 138 G4double q = aStep.GetTrack()->GetDefinition()->GetPDGCharge(); 192 G4double a = 1.165922e-3; 139 G4double a = 1.165922e-3; 193 G4double s_omega = 8.5062e+7*rad/(s*kilogaus 140 G4double s_omega = 8.5062e+7*rad/(s*kilogauss); 194 141 195 G4double omega = -(q*s_omega)*(1.+a) * Bnorm 142 G4double omega = -(q*s_omega)*(1.+a) * Bnorm; 196 143 197 G4double rotationangle = deltatime * omega; 144 G4double rotationangle = deltatime * omega; 198 145 199 G4Transform3D SpinRotation = G4Rotate3D(rota 146 G4Transform3D SpinRotation = G4Rotate3D(rotationangle,B.unit()); 200 147 201 G4Vector3D Spin = aStep.GetTrack() -> GetPol 148 G4Vector3D Spin = aStep.GetTrack() -> GetPolarization(); 202 149 203 G4Vector3D newSpin = SpinRotation * Spin; 150 G4Vector3D newSpin = SpinRotation * Spin; 204 151 205 #ifdef G4VERBOSE 152 #ifdef G4VERBOSE 206 if (GetVerboseLevel()>2) { << 153 207 G4double normspin = std::sqrt(Spin*Spin); << 154 // G4double normspin = std::sqrt(Spin*Spin); 208 G4double normnewspin = std::sqrt(newSpin*n << 155 // G4double normnewspin = std::sqrt(newSpin*newSpin); 209 //G4double cosalpha = Spin*newSpin/normspi << 156 // G4double cosalpha = Spin*newSpin/normspin/normnewspin; 210 //G4double alpha = std::acos(cosalpha); << 157 // G4double alpha = std::acos(cosalpha); 211 << 158 212 G4cout << "AT REST::: PARAMETERS " << G4en << 159 // G4cout<< "AT REST::: PARAMETERS\n" 213 G4cout << "Initial spin : " << Spin << G << 160 // << "Initial spin : " << Spin <<"\n" 214 G4cout << "Delta time : " << deltatime << 161 // << "Delta time : " << deltatime <<"\n" 215 G4cout << "Rotation angle: " << rotationan << 162 // << "Rotation angle: " << rotationangle/rad <<"\n" 216 G4cout << "New spin : " << newSpin < << 163 // << "New spin : " << newSpin <<"\n" 217 G4cout << "Checked norms : " << normspin < << 164 // << "Checked norms : " << normspin <<" " << normnewspin <<" \n" 218 } << 165 // << G4endl; >> 166 219 #endif 167 #endif 220 168 221 return newSpin; 169 return newSpin; 222 170 223 } << 224 << 225 void G4DecayWithSpin::ProcessDescription(std:: << 226 { << 227 outFile << GetProcessName() << 228 << ": Decay of particles considering paren << 229 << "kinematics of daughters are dertermine << 230 } 171 } 231 172