Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-24 09:10:47

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 // G4FieldTrack inline methods implementation
0027 //
0028 // Author: John Apostolakis (CERN), 14.10.1996 - First version
0029 // -------------------------------------------------------------------
0030 
0031 inline
0032 G4FieldTrack::G4FieldTrack( const G4FieldTrack& rStVec )
0033  : fDistanceAlongCurve( rStVec.fDistanceAlongCurve),
0034    fKineticEnergy( rStVec.fKineticEnergy ),
0035    fRestMass_c2( rStVec.fRestMass_c2),
0036    fLabTimeOfFlight( rStVec.fLabTimeOfFlight ), 
0037    fProperTimeOfFlight( rStVec.fProperTimeOfFlight ), 
0038    fPolarization( rStVec.fPolarization ), 
0039    fMomentumDir( rStVec.fMomentumDir ),
0040    fChargeState( rStVec.fChargeState )
0041 {
0042   SixVector[0]= rStVec.SixVector[0];
0043   SixVector[1]= rStVec.SixVector[1];
0044   SixVector[2]= rStVec.SixVector[2];
0045   SixVector[3]= rStVec.SixVector[3];
0046   SixVector[4]= rStVec.SixVector[4];
0047   SixVector[5]= rStVec.SixVector[5];
0048 
0049   // fpChargeState= new G4ChargeState( *rStVec.fpChargeState );
0050   // Can share charge state only when using handles etc
0051   // fpChargeState = rStVec.fpChargeState;  
0052 }
0053 
0054 inline
0055 G4FieldTrack& G4FieldTrack::operator= ( const G4FieldTrack& rStVec )
0056 {
0057   if (&rStVec == this) { return *this; }
0058 
0059   SixVector[0]= rStVec.SixVector[0];
0060   SixVector[1]= rStVec.SixVector[1];
0061   SixVector[2]= rStVec.SixVector[2];
0062   SixVector[3]= rStVec.SixVector[3];
0063   SixVector[4]= rStVec.SixVector[4];
0064   SixVector[5]= rStVec.SixVector[5];
0065   SetCurveLength( rStVec.GetCurveLength() );
0066 
0067   fKineticEnergy= rStVec.fKineticEnergy;
0068   fRestMass_c2= rStVec.fRestMass_c2;
0069   SetLabTimeOfFlight( rStVec.GetLabTimeOfFlight()  ); 
0070   SetProperTimeOfFlight( rStVec.GetProperTimeOfFlight()  ); 
0071   SetPolarization( rStVec.GetPolarization() );
0072   fMomentumDir= rStVec.fMomentumDir;
0073 
0074   fChargeState= rStVec.fChargeState;
0075   // (*fpChargeState)= *(rStVec.fpChargeState);
0076   // fpChargeState= rStVec.fpChargeState; // Handles!!
0077   return *this;
0078 }
0079 
0080 inline
0081 G4FieldTrack::G4FieldTrack(G4FieldTrack&& from) noexcept
0082  : fDistanceAlongCurve( from.fDistanceAlongCurve),
0083    fKineticEnergy( from.fKineticEnergy ),
0084    fRestMass_c2( from.fRestMass_c2),
0085    fLabTimeOfFlight( from.fLabTimeOfFlight ), 
0086    fProperTimeOfFlight( from.fProperTimeOfFlight ), 
0087    fChargeState( from.fChargeState )
0088 {
0089   SixVector[0]= from.SixVector[0];
0090   SixVector[1]= from.SixVector[1];
0091   SixVector[2]= from.SixVector[2];
0092   SixVector[3]= from.SixVector[3];
0093   SixVector[4]= from.SixVector[4];
0094   SixVector[5]= from.SixVector[5];
0095 
0096   fPolarization = std::move( from.fPolarization );
0097   fMomentumDir = std::move( from.fMomentumDir );
0098 }
0099 
0100 inline
0101 G4FieldTrack& G4FieldTrack::operator=(G4FieldTrack&& from) noexcept
0102 {
0103   if (&from == this) { return *this; }
0104 
0105   SixVector[0]= from.SixVector[0];
0106   SixVector[1]= from.SixVector[1];
0107   SixVector[2]= from.SixVector[2];
0108   SixVector[3]= from.SixVector[3];
0109   SixVector[4]= from.SixVector[4];
0110   SixVector[5]= from.SixVector[5];
0111 
0112   fDistanceAlongCurve = from.fDistanceAlongCurve;
0113   fKineticEnergy = from.fKineticEnergy;
0114   fRestMass_c2 = from.fRestMass_c2;
0115   fLabTimeOfFlight = from.fLabTimeOfFlight;
0116   fProperTimeOfFlight = from.fProperTimeOfFlight;
0117   fChargeState = from.fChargeState;
0118 
0119   fPolarization = std::move( from.fPolarization );
0120   fMomentumDir = std::move( from.fMomentumDir );
0121 
0122   return *this;
0123 }
0124 
0125 inline G4FieldTrack& 
0126 G4FieldTrack::SetCurvePnt(const G4ThreeVector& pPosition, 
0127                           const G4ThreeVector& pMomentum,  
0128                                 G4double       s_curve )
0129 {
0130   SixVector[0] = pPosition.x(); 
0131   SixVector[1] = pPosition.y(); 
0132   SixVector[2] = pPosition.z(); 
0133 
0134   SixVector[3] = pMomentum.x(); 
0135   SixVector[4] = pMomentum.y(); 
0136   SixVector[5] = pMomentum.z(); 
0137 
0138   fMomentumDir = (pMomentum.mag2() > 0.0)
0139                ? pMomentum.unit() : G4ThreeVector( 0.0, 0.0, 0.0 ); 
0140 
0141   fDistanceAlongCurve = s_curve;
0142 
0143   return *this;
0144 } 
0145 
0146 inline
0147 void G4FieldTrack::SetPDGSpin(G4double pdgSpin)
0148 {
0149    fChargeState.SetPDGSpin(pdgSpin);
0150 } 
0151 
0152 inline
0153 G4double G4FieldTrack::GetPDGSpin()
0154 {
0155    return fChargeState.GetPDGSpin();
0156 } 
0157 
0158 inline
0159 G4ThreeVector G4FieldTrack::GetPosition() const
0160 {
0161    G4ThreeVector myPosition( SixVector[0], SixVector[1], SixVector[2] );
0162    return myPosition;
0163 } 
0164 
0165 inline
0166 void G4FieldTrack::SetPosition( const G4ThreeVector& pPosition) 
0167 {
0168    SixVector[0] = pPosition.x(); 
0169    SixVector[1] = pPosition.y(); 
0170    SixVector[2] = pPosition.z(); 
0171 } 
0172 
0173 inline
0174 const G4ThreeVector& G4FieldTrack::GetMomentumDir() const 
0175 {
0176    return fMomentumDir;
0177 } 
0178 
0179 inline
0180 G4ThreeVector G4FieldTrack::GetMomentumDirection() const 
0181 {
0182    return fMomentumDir;
0183 } 
0184 
0185 inline
0186 G4double  G4FieldTrack::GetCurveLength() const 
0187 {
0188    return  fDistanceAlongCurve;  
0189 }
0190 
0191 inline
0192 void G4FieldTrack::SetCurveLength(G4double nCurve_s)
0193 {
0194    fDistanceAlongCurve = nCurve_s;  
0195 }
0196 
0197 inline
0198 G4double  G4FieldTrack::GetKineticEnergy() const
0199 {
0200    return fKineticEnergy;
0201 }
0202 
0203 inline
0204 void G4FieldTrack::SetKineticEnergy(G4double newKinEnergy)
0205 {
0206    fKineticEnergy = newKinEnergy;
0207 }
0208 
0209 inline
0210 G4ThreeVector G4FieldTrack::GetPolarization() const
0211 {
0212    return fPolarization;
0213 }
0214 
0215 inline
0216 void G4FieldTrack::SetPolarization(const G4ThreeVector& vecPlz)
0217 {
0218    fPolarization = vecPlz;
0219 }
0220 
0221 inline
0222 const G4ChargeState* G4FieldTrack::GetChargeState() const
0223 {
0224    return &fChargeState;
0225 }
0226 
0227 inline
0228 G4double G4FieldTrack::GetLabTimeOfFlight() const
0229 {
0230    return fLabTimeOfFlight;
0231 }
0232 
0233 inline
0234 void G4FieldTrack::SetLabTimeOfFlight(G4double nTOF)
0235 {
0236    fLabTimeOfFlight = nTOF;
0237 }
0238 
0239 inline
0240 G4double  G4FieldTrack::GetProperTimeOfFlight() const
0241 {
0242    return fProperTimeOfFlight;
0243 }
0244 
0245 inline
0246 void G4FieldTrack::SetProperTimeOfFlight(G4double nTOF)
0247 {
0248    fProperTimeOfFlight = nTOF;
0249 }
0250 
0251 inline
0252 void G4FieldTrack::SetMomentumDir(const G4ThreeVector& newMomDir)
0253 {
0254    fMomentumDir = newMomDir;
0255 }
0256 
0257 inline
0258 G4ThreeVector G4FieldTrack::GetMomentum() const 
0259 {
0260    return { SixVector[3], SixVector[4], SixVector[5] };
0261 } 
0262 
0263 inline
0264 void G4FieldTrack::SetMomentum(const G4ThreeVector& pMomentum)
0265 {
0266   SixVector[3] = pMomentum.x(); 
0267   SixVector[4] = pMomentum.y(); 
0268   SixVector[5] = pMomentum.z(); 
0269 
0270   if( pMomentum.mag2() > 0.0 ) { fMomentumDir = pMomentum.unit(); }
0271   else { fMomentumDir = G4ThreeVector( 0.0, 0.0, 0.0 ); }
0272 }
0273 
0274 inline
0275 G4double G4FieldTrack::GetCharge() const
0276 {
0277   return fChargeState.GetCharge();
0278 }
0279 
0280 inline
0281 G4double G4FieldTrack::GetRestMass() const
0282 {
0283   return fRestMass_c2;
0284 }
0285 
0286 inline
0287 void G4FieldTrack::SetRestMass(G4double Mass_c2)
0288 {
0289   fRestMass_c2 = Mass_c2;
0290 }
0291    
0292 // Dump values to array
0293 //  
0294 // Note that momentum direction is not saved 
0295 //
0296 inline
0297 void G4FieldTrack::DumpToArray(G4double valArr[ncompSVEC] ) const
0298 {
0299   valArr[0]=SixVector[0];
0300   valArr[1]=SixVector[1];
0301   valArr[2]=SixVector[2];
0302   valArr[3]=SixVector[3];
0303   valArr[4]=SixVector[4];
0304   valArr[5]=SixVector[5];
0305 
0306   G4ThreeVector Momentum(valArr[3],valArr[4],valArr[5]);
0307 
0308   // G4double mass_in_Kg;
0309   // mass_in_Kg = fEnergy / velocity_mag_sq * (1-velocity_mag_sq/c_squared);
0310   // valArr[6]= mass_in_Kg;
0311 
0312   // The following components may or may not be integrated.
0313   //
0314   valArr[6]= fKineticEnergy; 
0315 
0316   // valArr[6]=fEnergy;  // When it is integrated over, do this ...
0317   valArr[7]=fLabTimeOfFlight;
0318   valArr[8]=fProperTimeOfFlight;
0319   valArr[9]=fPolarization.x();
0320   valArr[10]=fPolarization.y();
0321   valArr[11]=fPolarization.z();
0322   // valArr[13]=fMomentumDir.x(); 
0323   // valArr[14]=fMomentumDir.y();
0324   // valArr[15]=fMomentumDir.z();
0325   // valArr[]=fDistanceAlongCurve; 
0326 }
0327 
0328 inline
0329 void G4FieldTrack::UpdateFourMomentum( G4double kineticEnergy, 
0330                  const G4ThreeVector& momentumDirection )
0331 {
0332   G4double momentum_mag  = std::sqrt(kineticEnergy*kineticEnergy
0333                                     +2.0*fRestMass_c2*kineticEnergy);
0334   G4ThreeVector momentumVector = momentum_mag * momentumDirection; 
0335 
0336   SixVector[3] = momentumVector.x(); 
0337   SixVector[4] = momentumVector.y(); 
0338   SixVector[5] = momentumVector.z(); 
0339 
0340   fMomentumDir=   momentumDirection; // Set directly to avoid inaccuracy.
0341   fKineticEnergy= kineticEnergy;
0342 }
0343 
0344 inline
0345 void G4FieldTrack::UpdateState( const G4ThreeVector& position, 
0346                 G4double laboratoryTimeOfFlight,
0347                 const G4ThreeVector& momentumDirection,
0348                 G4double kineticEnergy )
0349 { 
0350   SetPosition( position); 
0351   fLabTimeOfFlight = laboratoryTimeOfFlight;
0352   fDistanceAlongCurve = 0.0;
0353   UpdateFourMomentum( kineticEnergy, momentumDirection); 
0354 }
0355 
0356 inline
0357 void G4FieldTrack::InitialiseSpin( const G4ThreeVector& vecPolarization )
0358 {
0359   SetPolarization( vecPolarization );
0360 } 
0361 
0362 inline G4ThreeVector G4FieldTrack::GetSpin() const
0363 {
0364   return GetPolarization();
0365 }
0366 
0367 inline
0368 void G4FieldTrack::SetSpin(const G4ThreeVector& vSpin)
0369 {
0370   SetPolarization(vSpin);
0371 }