Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-14 08:52:45

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 - First version, 14.10.1996
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    // fMomentumModulus( rStVec.fMomentumModulus ),
0039    fPolarization( rStVec.fPolarization ), 
0040    fMomentumDir( rStVec.fMomentumDir ),
0041    fChargeState( rStVec.fChargeState )
0042 {
0043   SixVector[0]= rStVec.SixVector[0];
0044   SixVector[1]= rStVec.SixVector[1];
0045   SixVector[2]= rStVec.SixVector[2];
0046   SixVector[3]= rStVec.SixVector[3];
0047   SixVector[4]= rStVec.SixVector[4];
0048   SixVector[5]= rStVec.SixVector[5];
0049 
0050   // fpChargeState= new G4ChargeState( *rStVec.fpChargeState );
0051   // Can share charge state only when using handles etc
0052   // fpChargeState = rStVec.fpChargeState;  
0053 }
0054 
0055 inline
0056 G4FieldTrack& G4FieldTrack::operator= ( const G4FieldTrack& rStVec )
0057 {
0058   if (&rStVec == this) { return *this; }
0059 
0060   SixVector[0]= rStVec.SixVector[0];
0061   SixVector[1]= rStVec.SixVector[1];
0062   SixVector[2]= rStVec.SixVector[2];
0063   SixVector[3]= rStVec.SixVector[3];
0064   SixVector[4]= rStVec.SixVector[4];
0065   SixVector[5]= rStVec.SixVector[5];
0066   SetCurveLength( rStVec.GetCurveLength() );
0067 
0068   fKineticEnergy= rStVec.fKineticEnergy;
0069   fRestMass_c2= rStVec.fRestMass_c2;
0070   SetLabTimeOfFlight( rStVec.GetLabTimeOfFlight()  ); 
0071   SetProperTimeOfFlight( rStVec.GetProperTimeOfFlight()  ); 
0072   SetPolarization( rStVec.GetPolarization() );
0073   fMomentumDir= rStVec.fMomentumDir;
0074 
0075   fChargeState= rStVec.fChargeState;
0076   // (*fpChargeState)= *(rStVec.fpChargeState);
0077   // fpChargeState= rStVec.fpChargeState; // Handles!!
0078   return *this;
0079 }
0080 
0081 inline
0082 G4FieldTrack::G4FieldTrack(G4FieldTrack&& from) noexcept
0083  : fDistanceAlongCurve( from.fDistanceAlongCurve),
0084    fKineticEnergy( from.fKineticEnergy ),
0085    fRestMass_c2( from.fRestMass_c2),
0086    fLabTimeOfFlight( from.fLabTimeOfFlight ), 
0087    fProperTimeOfFlight( from.fProperTimeOfFlight ), 
0088    fChargeState( from.fChargeState )
0089 {
0090   SixVector[0]= from.SixVector[0];
0091   SixVector[1]= from.SixVector[1];
0092   SixVector[2]= from.SixVector[2];
0093   SixVector[3]= from.SixVector[3];
0094   SixVector[4]= from.SixVector[4];
0095   SixVector[5]= from.SixVector[5];
0096 
0097   fPolarization = std::move( from.fPolarization );
0098   fMomentumDir = std::move( from.fMomentumDir );
0099 }
0100 
0101 inline
0102 G4FieldTrack& G4FieldTrack::operator=(G4FieldTrack&& from) noexcept
0103 {
0104   if (&from == this) { return *this;
0105 }
0106 
0107   SixVector[0]= from.SixVector[0];
0108   SixVector[1]= from.SixVector[1];
0109   SixVector[2]= from.SixVector[2];
0110   SixVector[3]= from.SixVector[3];
0111   SixVector[4]= from.SixVector[4];
0112   SixVector[5]= from.SixVector[5];
0113 
0114   fDistanceAlongCurve = from.fDistanceAlongCurve;
0115   fKineticEnergy = from.fKineticEnergy;
0116   fRestMass_c2 = from.fRestMass_c2;
0117   fLabTimeOfFlight = from.fLabTimeOfFlight;
0118   fProperTimeOfFlight = from.fProperTimeOfFlight;
0119   fChargeState = from.fChargeState;
0120 
0121   fPolarization = std::move( from.fPolarization );
0122   fMomentumDir = std::move( from.fMomentumDir );
0123 
0124   return *this;
0125 }
0126 
0127 inline G4FieldTrack& 
0128 G4FieldTrack::SetCurvePnt(const G4ThreeVector& pPosition, 
0129                           const G4ThreeVector& pMomentum,  
0130                                 G4double       s_curve )
0131 {
0132   SixVector[0] = pPosition.x(); 
0133   SixVector[1] = pPosition.y(); 
0134   SixVector[2] = pPosition.z(); 
0135 
0136   SixVector[3] = pMomentum.x(); 
0137   SixVector[4] = pMomentum.y(); 
0138   SixVector[5] = pMomentum.z(); 
0139 
0140   fMomentumDir = (pMomentum.mag2() > 0.0)
0141                ? pMomentum.unit() : G4ThreeVector( 0.0, 0.0, 0.0 ); 
0142 
0143   fDistanceAlongCurve = s_curve;
0144 
0145   return *this;
0146 } 
0147 
0148 inline
0149 void G4FieldTrack::SetPDGSpin(G4double pdgSpin)
0150 {
0151    fChargeState.SetPDGSpin(pdgSpin);
0152 } 
0153 
0154 inline
0155 G4double G4FieldTrack::GetPDGSpin()
0156 {
0157    return fChargeState.GetPDGSpin();
0158 } 
0159 
0160 inline
0161 G4ThreeVector G4FieldTrack::GetPosition() const
0162 {
0163    G4ThreeVector myPosition( SixVector[0], SixVector[1], SixVector[2] );
0164    return myPosition;
0165 } 
0166 
0167 inline
0168 void G4FieldTrack::SetPosition( const G4ThreeVector& pPosition) 
0169 {
0170    SixVector[0] = pPosition.x(); 
0171    SixVector[1] = pPosition.y(); 
0172    SixVector[2] = pPosition.z(); 
0173 } 
0174 
0175 inline
0176 const G4ThreeVector& G4FieldTrack::GetMomentumDir() const 
0177 {
0178    // G4ThreeVector myMomentum( SixVector[3], SixVector[4], SixVector[5] );
0179    // return myVelocity;
0180    return fMomentumDir;
0181 } 
0182 
0183 inline
0184 G4ThreeVector G4FieldTrack::GetMomentumDirection() const 
0185 {
0186    return fMomentumDir;
0187 } 
0188 
0189 inline
0190 G4double  G4FieldTrack::GetCurveLength() const 
0191 {
0192    return  fDistanceAlongCurve;  
0193 }
0194 
0195 inline
0196 void G4FieldTrack::SetCurveLength(G4double nCurve_s)
0197 {
0198    fDistanceAlongCurve = nCurve_s;  
0199 }
0200 
0201 inline
0202 G4double  G4FieldTrack::GetKineticEnergy() const
0203 {
0204    return fKineticEnergy;
0205 }
0206 
0207 inline
0208 void G4FieldTrack::SetKineticEnergy(G4double newKinEnergy)
0209 {
0210    fKineticEnergy = newKinEnergy;
0211 }
0212 
0213 inline
0214 G4ThreeVector G4FieldTrack::GetPolarization() const
0215 {
0216    return fPolarization;
0217 }
0218 
0219 inline
0220 void G4FieldTrack::SetPolarization(const G4ThreeVector& vecPlz)
0221 {
0222    fPolarization = vecPlz;
0223 }
0224 
0225 inline
0226 const G4ChargeState* G4FieldTrack::GetChargeState() const
0227 {
0228    return &fChargeState;
0229 }
0230 
0231 inline
0232 G4double G4FieldTrack::GetLabTimeOfFlight() const
0233 {
0234    return fLabTimeOfFlight;
0235 }
0236 
0237 inline
0238 void G4FieldTrack::SetLabTimeOfFlight(G4double nTOF)
0239 {
0240    fLabTimeOfFlight = nTOF;
0241 }
0242 
0243 inline
0244 G4double  G4FieldTrack::GetProperTimeOfFlight() const
0245 {
0246    return fProperTimeOfFlight;
0247 }
0248 
0249 inline
0250 void G4FieldTrack::SetProperTimeOfFlight(G4double nTOF)
0251 {
0252    fProperTimeOfFlight = nTOF;
0253 }
0254 
0255 inline
0256 void G4FieldTrack::SetMomentumDir(const G4ThreeVector& newMomDir)
0257 {
0258    fMomentumDir = newMomDir;
0259 }
0260 
0261 inline
0262 G4ThreeVector G4FieldTrack::GetMomentum() const 
0263 {
0264    return { SixVector[3], SixVector[4], SixVector[5] };
0265 } 
0266 
0267 inline
0268 void G4FieldTrack::SetMomentum(const G4ThreeVector& pMomentum)
0269 {
0270   SixVector[3] = pMomentum.x(); 
0271   SixVector[4] = pMomentum.y(); 
0272   SixVector[5] = pMomentum.z(); 
0273 
0274   if( pMomentum.mag2() > 0.0 ) { fMomentumDir = pMomentum.unit(); }
0275   else { fMomentumDir = G4ThreeVector( 0.0, 0.0, 0.0 ); }
0276 }
0277 
0278 inline
0279 G4double G4FieldTrack::GetCharge() const
0280 {
0281   return fChargeState.GetCharge();
0282 }
0283 
0284 inline
0285 G4double G4FieldTrack::GetRestMass() const
0286 {
0287   return fRestMass_c2;
0288 }
0289 
0290 inline
0291 void G4FieldTrack::SetRestMass(G4double Mass_c2)
0292 {
0293   fRestMass_c2 = Mass_c2;
0294 }
0295    
0296 // Dump values to array
0297 //  
0298 // Note that momentum direction is not saved 
0299 //
0300 inline
0301 void G4FieldTrack::DumpToArray(G4double valArr[ncompSVEC] ) const
0302 {
0303   valArr[0]=SixVector[0];
0304   valArr[1]=SixVector[1];
0305   valArr[2]=SixVector[2];
0306   valArr[3]=SixVector[3];
0307   valArr[4]=SixVector[4];
0308   valArr[5]=SixVector[5];
0309 
0310   G4ThreeVector Momentum(valArr[3],valArr[4],valArr[5]);
0311 
0312   // G4double mass_in_Kg;
0313   // mass_in_Kg = fEnergy / velocity_mag_sq * (1-velocity_mag_sq/c_squared);
0314   // valArr[6]= mass_in_Kg;
0315 
0316   // The following components may or may not be integrated.
0317   //
0318   valArr[6]= fKineticEnergy; 
0319 
0320   // valArr[6]=fEnergy;  // When it is integrated over, do this ...
0321   valArr[7]=fLabTimeOfFlight;
0322   valArr[8]=fProperTimeOfFlight;
0323   valArr[9]=fPolarization.x();
0324   valArr[10]=fPolarization.y();
0325   valArr[11]=fPolarization.z();
0326   // valArr[13]=fMomentumDir.x(); 
0327   // valArr[14]=fMomentumDir.y();
0328   // valArr[15]=fMomentumDir.z();
0329   // valArr[]=fDistanceAlongCurve; 
0330 }
0331 
0332 inline
0333 void G4FieldTrack::UpdateFourMomentum( G4double kineticEnergy, 
0334                  const G4ThreeVector& momentumDirection )
0335 {
0336   G4double momentum_mag  = std::sqrt(kineticEnergy*kineticEnergy
0337                                     +2.0*fRestMass_c2*kineticEnergy);
0338   G4ThreeVector momentumVector = momentum_mag * momentumDirection; 
0339 
0340   // SetMomentum( momentumVector );
0341     // Set direction (from unit): used sqrt, div
0342   SixVector[3] = momentumVector.x(); 
0343   SixVector[4] = momentumVector.y(); 
0344   SixVector[5] = momentumVector.z(); 
0345 
0346   fMomentumDir=   momentumDirection; // Set directly to avoid inaccuracy.
0347   fKineticEnergy= kineticEnergy;
0348 }
0349 
0350 inline
0351 void G4FieldTrack::UpdateState( const G4ThreeVector& position, 
0352                 G4double laboratoryTimeOfFlight,
0353                 const G4ThreeVector& momentumDirection,
0354                 G4double kineticEnergy )
0355 { 
0356   // SetCurvePnt( position, momentumVector, s_curve=0.0);     
0357   SetPosition( position); 
0358   fLabTimeOfFlight = laboratoryTimeOfFlight;
0359   fDistanceAlongCurve = 0.0;
0360 
0361   UpdateFourMomentum( kineticEnergy, momentumDirection); 
0362 }
0363 
0364 inline
0365 void G4FieldTrack::InitialiseSpin( const G4ThreeVector& vecPolarization )
0366 {
0367   SetPolarization( vecPolarization );
0368 } 
0369 
0370 inline G4ThreeVector G4FieldTrack::GetSpin() const
0371 {
0372   return GetPolarization();
0373 }
0374 
0375 inline
0376 void G4FieldTrack::SetSpin(const G4ThreeVector& vSpin)
0377 {
0378   SetPolarization(vSpin);
0379 }