87 if (cosl < 1.
E-30) cosl = 1.E-30;
90 G4Vector3D vVN(-vTN.
z()*vUN.y(), vTN.
z()*vUN.x(), cosl );
94 vUperp *= 1./vUperp.
mag();
95 vVperp *= 1./vVperp.
mag();
99 G4cout <<
" CHECK: vUN " << vUN <<
" = " << vUperp <<
" diff " << (vUN-vUperp).mag() <<
G4endl;
100 G4cout <<
" CHECK: vVN " << vVN <<
" = " << vVperp <<
" diff " << (vVN-vVperp).mag() <<
G4endl;
116 G4cout <<
" dir="<<dir<<
" invCosTheta "<<invCosTheta <<
G4endl;
126 if( magHPre != 0. ) {
130 G4double sinz = -HPre*vUperp * magHPreM2;
131 G4double cosz = HPre*vVperp * magHPreM2;
133 transfM[1][3] = -Q*dir.
y()*sinz;
134 transfM[1][4] = -Q*dir.
z()*sinz;
135 transfM[2][3] = -Q*dir.
y()*cosz*invCosTheta;
136 transfM[2][4] = -Q*dir.
z()*cosz*invCosTheta;
141 transfM[1][1] = dir.
x()*dVU;
142 transfM[1][2] = dir.
x()*dVV;
143 transfM[2][1] = dir.
x()*dUU*invCosTheta;
144 transfM[2][2] = dir.
x()*dUV*invCosTheta;
187 std::ios::fmtflags orig_flags = out.flags();
189 out.setf(std::ios::fixed,std::ios::floatfield);
195 out.flags(orig_flags);
209 if( std::fabs(stepLengthCm) <= kCarTolerance/
cm )
return 0;
224 if( vpPre.
mag() == vpPre.
z() ) vpPre.
setX( 1.E-6*
MeV );
225 if( vpPost.
mag() == vpPost.
z() ) vpPost.
setX( 1.E-6*
MeV );
231 G4cout <<
"G4EP: vposPre " << vposPre << G4endl
232 <<
"G4EP: vposPost " << vposPost <<
G4endl;
233 G4cout <<
"G4EP: vpPre " << vpPre << G4endl
234 <<
"G4EP: vpPost " << vpPost <<
G4endl;
236 G4cout <<
"G4EP: stepLengthCm " << stepLengthCm <<
G4endl;
240 if( pPre == 0. || pPost == 0 )
return 2;
243 G4double deltaPInv = pInvPost - pInvPre;
244 if(
iverbose >= 2 )
G4cout <<
"G4EP: pInvPre" << pInvPre<<
" pInvPost:" << pInvPost<<
" deltaPInv:" << deltaPInv<<
G4endl;
249 if(
iverbose >= 2 )
G4cout <<
"G4EP: vpPreNorm " << vpPreNorm <<
" vpPostNorm " << vpPostNorm <<
G4endl;
251 if( 1. - std::fabs(vpPreNorm.
z()) < kCarTolerance )
return 4;
252 if( 1. - std::fabs(vpPostNorm.
z()) < kCarTolerance )
return 4;
264 transf[3][2] = stepLengthCm * sinpPost;
265 transf[4][1] = stepLengthCm;
266 for(
size_t ii=0;ii < 5; ii++ ){
271 G4cout <<
"G4EP: transf matrix neutral " << transf;
287 G4double pos1[3]; pos1[0] = vposPre.
x()*
cm; pos1[1] = vposPre.
y()*
cm; pos1[2] = vposPre.
z()*
cm;
288 G4double pos2[3]; pos2[0] = vposPost.
x()*
cm; pos2[1] = vposPost.
y()*
cm; pos2[2] = vposPost.
z()*
cm;
292 if( !field )
return 0;
297 if( charge != 0. && field ) {
308 << h1[0] <<
", " << h1[1] <<
", " << h1[2] <<
G4endl;
309 G4cout <<
"G4EP: pos1/mm = "
310 << pos1[0] <<
", " << pos1[1] <<
", " << pos1[2] <<
G4endl;
311 G4cout <<
"G4EP: pos2/mm = "
312 << pos2[0] <<
", " << pos2[1] <<
", " << pos2[2] <<
G4endl;
313 G4cout <<
"G4EP: B-filed in KGauss HPre " << HPre << G4endl
314 <<
"G4EP: in KGauss HPost " << HPost <<
G4endl;
318 if( magHPre + magHPost != 0. ) {
322 if( magHPost != 0. ){
323 gam = HPost * vpPostNorm / magHPost;
325 gam = HPre * vpPreNorm / magHPre;
330 G4double diffHSqr = ( HPre * pInvPre - HPost * pInvPost ).mag2();
334 G4cout <<
" G4EP: gam " << gam <<
" alphaSqr " << alphaSqr
335 <<
" diffHSqr " << diffHSqr <<
G4endl;
339 if( diffHSqr * alphaSqr > delhp6Sqr )
return 3;
343 G4double pInvAver = 1./(pInvPre + pInvPost );
346 G4ThreeVector vHAverNorm( (HPre*pInvPre + HPost*pInvPost ) * pInvAver * charge * CFACT8 );
349 vHAverNorm *= invHAver;
351 if(
iverbose >= 2 )
G4cout <<
" G4EP: HaverNorm " << vHAverNorm <<
" magHAver " << HAver <<
" charge " << charge<<
G4endl;
356 G4double thetaAver = QAver * stepLengthCm;
357 G4double sinThetaAver = std::sin(thetaAver);
358 G4double cosThetaAver = std::cos(thetaAver);
359 G4double gamma = vHAverNorm * vpPostNorm;
363 if(
iverbose >= 2 )
G4cout <<
" G4EP: AN2 " << AN2 <<
" gamma:"<<gamma<<
" theta="<< thetaAver<<
G4endl;
371 vpPreNorm.
z()*vUPre.x(),
372 vpPreNorm.
x()*vUPre.y() - vpPreNorm.
y()*vUPre.x() );
375 AU = 1./vpPostNorm.
perp();
381 vpPostNorm.z()*vUPost.x(),
382 vpPostNorm.x()*vUPost.y() - vpPostNorm.y()*vUPost.x() );
385 if(
iverbose >= 2 )
G4cout <<
" G4EP: AU " << AU <<
" vUPre " << vUPre <<
" vVPre " << vVPre <<
" vUPost " << vUPost <<
" vVPost " << vVPost <<
G4endl;
387 G4Point3D deltaPos( vposPre - vposPost );
395 if(
iverbose >= 2)
G4cout <<
" G4EP: QP " << QP <<
" QAver " << QAver <<
" pAver " << pAver <<
G4endl;
397 G4double ANV = -( vHAverNorm.
x()*vUPost.x() + vHAverNorm.
y()*vUPost.y() );
398 G4double ANU = ( vHAverNorm.
x()*vVPost.x() + vHAverNorm.
y()*vVPost.y() + vHAverNorm.
z()*vVPost.z() );
399 G4double OMcosThetaAver = 1. - cosThetaAver;
401 if(
iverbose >= 2)
G4cout <<
"G4EP: OMcosThetaAver " << OMcosThetaAver <<
" cosThetaAver " << cosThetaAver <<
" thetaAver " << thetaAver <<
" QAver " << QAver <<
" stepLengthCm " << stepLengthCm <<
G4endl;
403 G4double TMSINT = thetaAver - sinThetaAver;
409 vHAverNorm.
z() * vUPre.x(),
410 vHAverNorm.
x() * vUPre.y() - vHAverNorm.
y() * vUPre.x() );
414 G4ThreeVector vHVPre( vHAverNorm.
y() * vVPre.z() - vHAverNorm.
z() * vVPre.y(),
415 vHAverNorm.
z() * vVPre.x() - vHAverNorm.
x() * vVPre.z(),
416 vHAverNorm.
x() * vVPre.y() - vHAverNorm.
y() * vVPre.x() );
424 transf[0][0] = 1.-deltaPInv*pAver*(1.+(vpPostNorm.x()*deltaPos.
x()+vpPostNorm.y()*deltaPos.
y()+vpPostNorm.z()*deltaPos.
z())/stepLengthCm)
427 transf[0][1] = -deltaPInv/thetaAver*
428 ( TMSINT*gamma*(vHAverNorm.
x()*vVPre.x()+vHAverNorm.
y()*vVPre.y()+vHAverNorm.
z()*vVPre.z()) +
429 sinThetaAver*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z()) +
430 OMcosThetaAver*(vHVPre.x()*vpPostNorm.x()+vHVPre.y()*vpPostNorm.y()+vHVPre.z()*vpPostNorm.z()) );
432 transf[0][2] = -sinpPre*deltaPInv/thetaAver*
433 ( TMSINT*gamma*(vHAverNorm.
x()*vUPre.x()+vHAverNorm.
y()*vUPre.y() ) +
434 sinThetaAver*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y() ) +
435 OMcosThetaAver*(vHUPre.x()*vpPostNorm.x()+vHUPre.y()*vpPostNorm.y()+vHUPre.z()*vpPostNorm.z()) );
437 transf[0][3] = -deltaPInv/stepLengthCm*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y() );
439 transf[0][4] = -deltaPInv/stepLengthCm*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z());
442 transf[1][0] = -QP*ANV*(vpPostNorm.x()*deltaPos.
x()+vpPostNorm.y()*deltaPos.
y()+vpPostNorm.z()*deltaPos.
z())
443 *(1.+deltaPInv*pAver);
445 if(
iverbose >= 3)
G4cout <<
"ctransf10= " << transf[1][0] <<
" " << -QP<<
" " << ANV<<
" " << vpPostNorm.x()<<
" " << deltaPos.
x()<<
" " << vpPostNorm.y()<<
" " << deltaPos.
y()<<
" " << vpPostNorm.z()<<
" " << deltaPos.
z()
446 <<
" " << deltaPInv<<
" " << pAver <<
G4endl;
449 transf[1][1] = cosThetaAver*(vVPre.x()*vVPost.x()+vVPre.y()*vVPost.y()+vVPre.z()*vVPost.z()) +
450 sinThetaAver*(vHVPre.x()*vVPost.x()+vHVPre.y()*vVPost.y()+vHVPre.z()*vVPost.z()) +
451 OMcosThetaAver*(vHAverNorm.
x()*vVPre.x()+vHAverNorm.
y()*vVPre.y()+vHAverNorm.
z()*vVPre.z())*
452 (vHAverNorm.
x()*vVPost.x()+vHAverNorm.
y()*vVPost.y()+vHAverNorm.
z()*vVPost.z()) +
453 ANV*( -sinThetaAver*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z()) +
454 OMcosThetaAver*(vVPre.x()*AN2.
x()+vVPre.y()*AN2.
y()+vVPre.z()*AN2.
z()) -
455 TMSINT*gamma*(vHAverNorm.
x()*vVPre.x()+vHAverNorm.
y()*vVPre.y()+vHAverNorm.
z()*vVPre.z()) );
457 transf[1][2] = cosThetaAver*(vUPre.x()*vVPost.x()+vUPre.y()*vVPost.y() ) +
458 sinThetaAver*(vHUPre.x()*vVPost.x()+vHUPre.y()*vVPost.y()+vHUPre.z()*vVPost.z()) +
459 OMcosThetaAver*(vHAverNorm.
x()*vUPre.x()+vHAverNorm.
y()*vUPre.y() )*
460 (vHAverNorm.
x()*vVPost.x()+vHAverNorm.
y()*vVPost.y()+vHAverNorm.
z()*vVPost.z()) +
461 ANV*( -sinThetaAver*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y() ) +
462 OMcosThetaAver*(vUPre.x()*AN2.
x()+vUPre.y()*AN2.
y() ) -
463 TMSINT*gamma*(vHAverNorm.
x()*vUPre.x()+vHAverNorm.
y()*vUPre.y() ) );
464 transf[1][2] = sinpPre*transf[1][2];
466 transf[1][3] = -QAver*ANV*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y() );
468 transf[1][4] = -QAver*ANV*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z());
472 transf[2][0] = -QP*ANU*(vpPostNorm.x()*deltaPos.
x()+vpPostNorm.y()*deltaPos.
y()+vpPostNorm.z()*deltaPos.
z())*sinpPostInv
473 *(1.+deltaPInv*pAver);
475 if(
iverbose >= 3)
G4cout <<
"ctransf20= " << transf[2][0] <<
" "<< -QP<<
" "<<ANU<<
" "<<vpPostNorm.x()<<
" "<<deltaPos.
x()<<
" "<<vpPostNorm.y()<<
" "<<deltaPos.
y()<<
" "<<vpPostNorm.z()<<
" "<<deltaPos.
z()<<
" "<<sinpPostInv
476 <<
" "<<deltaPInv<<
" "<<pAver<<
G4endl;
478 transf[2][1] = cosThetaAver*(vVPre.x()*vUPost.x()+vVPre.y()*vUPost.y() ) +
479 sinThetaAver*(vHVPre.x()*vUPost.x()+vHVPre.y()*vUPost.y() ) +
480 OMcosThetaAver*(vHAverNorm.
x()*vVPre.x()+vHAverNorm.
y()*vVPre.y()+vHAverNorm.
z()*vVPre.z())*
481 (vHAverNorm.
x()*vUPost.x()+vHAverNorm.
y()*vUPost.y() ) +
482 ANU*( -sinThetaAver*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z()) +
483 OMcosThetaAver*(vVPre.x()*AN2.
x()+vVPre.y()*AN2.
y()+vVPre.z()*AN2.
z()) -
484 TMSINT*gamma*(vHAverNorm.
x()*vVPre.x()+vHAverNorm.
y()*vVPre.y()+vHAverNorm.
z()*vVPre.z()) );
485 transf[2][1] = sinpPostInv*transf[2][1];
487 transf[2][2] = cosThetaAver*(vUPre.x()*vUPost.x()+vUPre.y()*vUPost.y() ) +
488 sinThetaAver*(vHUPre.x()*vUPost.x()+vHUPre.y()*vUPost.y() ) +
489 OMcosThetaAver*(vHAverNorm.
x()*vUPre.x()+vHAverNorm.
y()*vUPre.y() )*
490 (vHAverNorm.
x()*vUPost.x()+vHAverNorm.
y()*vUPost.y() ) +
491 ANU*( -sinThetaAver*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y() ) +
492 OMcosThetaAver*(vUPre.x()*AN2.
x()+vUPre.y()*AN2.
y() ) -
493 TMSINT*gamma*(vHAverNorm.
x()*vUPre.x()+vHAverNorm.
y()*vUPre.y() ) );
494 transf[2][2] = sinpPostInv*sinpPre*transf[2][2];
496 transf[2][3] = -QAver*ANU*(vUPre.x()*vpPostNorm.x()+vUPre.y()*vpPostNorm.y() )*sinpPostInv;
498 if(
iverbose >= 3)
G4cout <<
"ctransf23= " << transf[2][3] <<
" "<< -QAver<<
" "<<ANU<<
" "<<vUPre.x()<<
" "<<vpPostNorm.x()<<
" "<< vUPre.y()<<
" "<<vpPostNorm.y()<<
" "<<sinpPostInv<<
G4endl;
501 transf[2][4] = -QAver*ANU*(vVPre.x()*vpPostNorm.x()+vVPre.y()*vpPostNorm.y()+vVPre.z()*vpPostNorm.z())*sinpPostInv;
505 transf[3][0] = pAver*(vUPost.x()*deltaPos.
x()+vUPost.y()*deltaPos.
y() )
506 *(1.+deltaPInv*pAver);
508 if(
iverbose >= 3)
G4cout <<
"ctransf30= " << transf[3][0] <<
" "<< pAver<<
" "<<vUPost.x()<<
" "<<deltaPos.
x()<<
" "<<vUPost.y()<<
" "<<deltaPos.
y()
509 <<
" "<<deltaPInv<<
" "<<pAver<<
G4endl;
512 transf[3][1] = ( sinThetaAver*(vVPre.x()*vUPost.x()+vVPre.y()*vUPost.y() ) +
513 OMcosThetaAver*(vHVPre.x()*vUPost.x()+vHVPre.y()*vUPost.y() ) +
514 TMSINT*(vHAverNorm.
x()*vUPost.x()+vHAverNorm.
y()*vUPost.y() )*
515 (vHAverNorm.
x()*vVPre.x()+vHAverNorm.
y()*vVPre.y()+vHAverNorm.
z()*vVPre.z()) )/QAver;
517 transf[3][2] = ( sinThetaAver*(vUPre.x()*vUPost.x()+vUPre.y()*vUPost.y() ) +
518 OMcosThetaAver*(vHUPre.x()*vUPost.x()+vHUPre.y()*vUPost.y() ) +
519 TMSINT*(vHAverNorm.
x()*vUPost.x()+vHAverNorm.
y()*vUPost.y() )*
520 (vHAverNorm.
x()*vUPre.x()+vHAverNorm.
y()*vUPre.y() ) )*sinpPre/QAver;
522 if(
iverbose >= 3)
G4cout <<
"ctransf32= " << transf[3][2] <<
" "<< sinThetaAver<<
" "<<vUPre.x()<<
" "<<vUPost.x()<<
" "<<vUPre.y()<<
" "<<vUPost.y() <<
" "<<
523 OMcosThetaAver<<
" "<<vHUPre.x()<<
" "<<vUPost.x()<<
" "<<vHUPre.y()<<
" "<<vUPost.y() <<
" "<<
524 TMSINT<<
" "<<vHAverNorm.
x()<<
" "<<vUPost.x()<<
" "<<vHAverNorm.
y()<<
" "<<vUPost.y() <<
" "<<
525 vHAverNorm.
x()<<
" "<<vUPre.x()<<
" "<<vHAverNorm.
y()<<
" "<<vUPre.y() <<
" "<<sinpPre<<
" "<<QAver<<
G4endl;
528 transf[3][3] = (vUPre.x()*vUPost.x()+vUPre.y()*vUPost.y() );
530 transf[3][4] = (vVPre.x()*vUPost.x()+vVPre.y()*vUPost.y() );
533 transf[4][0] = pAver*(vVPost.x()*deltaPos.
x()+vVPost.y()*deltaPos.
y()+vVPost.z()*deltaPos.
z())
534 *(1.+deltaPInv*pAver);
536 transf[4][1] = ( sinThetaAver*(vVPre.x()*vVPost.x()+vVPre.y()*vVPost.y()+vVPre.z()*vVPost.z()) +
537 OMcosThetaAver*(vHVPre.x()*vVPost.x()+vHVPre.y()*vVPost.y()+vHVPre.z()*vVPost.z()) +
538 TMSINT*(vHAverNorm.
x()*vVPost.x()+vHAverNorm.
y()*vVPost.y()+vHAverNorm.
z()*vVPost.z())*
539 (vHAverNorm.
x()*vVPre.x()+vHAverNorm.
y()*vVPre.y()+vHAverNorm.
z()*vVPre.z()) )/QAver;
541 if(
iverbose >= 3)
G4cout <<
"ctransf41= " << transf[4][1] <<
" "<< sinThetaAver<<
" "<< OMcosThetaAver <<
" "<<TMSINT<<
" "<< vVPre <<
" "<<vVPost <<
" "<<vHVPre<<
" "<<vHAverNorm <<
" "<< QAver<<
G4endl;
544 transf[4][2] = ( sinThetaAver*(vUPre.x()*vVPost.x()+vUPre.y()*vVPost.y() ) +
545 OMcosThetaAver*(vHUPre.x()*vVPost.x()+vHUPre.y()*vVPost.y()+vHUPre.z()*vVPost.z()) +
546 TMSINT*(vHAverNorm.
x()*vVPost.x()+vHAverNorm.
y()*vVPost.y()+vHAverNorm.
z()*vVPost.z())*
547 (vHAverNorm.
x()*vUPre.x()+vHAverNorm.
y()*vUPre.y() ) )*sinpPre/QAver;
549 transf[4][3] = (vUPre.x()*vVPost.x()+vUPre.y()*vVPost.y() );
551 transf[4][4] = (vVPre.x()*vVPost.x()+vVPre.y()*vVPost.y()+vVPre.z()*vVPost.z());
616 <<
" effZ:" << effZ <<
" effA:" << effA
622 if(
iverbose >= 4 )
G4cout << std::setprecision(6) << std::setw(6) <<
"G4EP:MSC: RI=X/X0 " << RI <<
" stepLengthCm " << stepLengthCm <<
" radlen/cm " << (mate->
GetRadlen()/
cm) <<
" RI*1.e10:" << RI*1.e10 << G4endl;
625 G4double DD = 1.8496E-4*RI*(charge/pBeta * charge/pBeta );
629 G4double S1 = DD*stepLengthCm*stepLengthCm/3.;
633 G4double CLA = std::sqrt( vpPre.
x() * vpPre.
x() + vpPre.
y() * vpPre.
y() )/pPre;
635 if(
iverbose >= 2 )
G4cout << std::setw(6) <<
"G4EP:MSC: RI " << RI <<
" S1 " << S1 <<
" S2 " << S2 <<
" S3 " << S3 <<
" CLA " << CLA <<
G4endl;
639 fError[2][2] += S2/CLA/CLA;
659 for(ii=0; ii < nelem; ii++ ) {
673 if( stepLengthCm < 1.
E-7 ) {
693 G4cout <<
"G4EP:IONI: XI/keV " << XI <<
" beta " << beta <<
" gamma " << gamma <<
G4endl;
694 G4cout <<
" density " << (mate->
GetDensity()/
mg*
mole) <<
" effA " << effA <<
" step " << stepLengthCm << G4endl;
703 G4double F2 = 1. + 2. * massRatio * gamma + massRatio * massRatio;
707 G4double dedxSq = XI*Emax*(1.-(beta*beta/2.))*1.
E-12;
718 if (XI/Emax<0.01) dedxSq *=XI/Emax*100 ;
721 if(
iverbose >= 2 )
G4cout <<
"G4EP:IONI: DEDX^2(GeV^2) " << dedxSq <<
" emass/GeV: " << eMass <<
" Emax/keV: " << Emax
722 <<
" k=Xi/Emax="<< XI/Emax<<
G4endl;
727 pPre6 = std::pow(pPre6, 6 );
729 fError[0][0] += Etot*Etot*dedxSq / pPre6;
731 if(
iverbose >= 2 )
G4cout <<
"G4:IONI Etot/GeV: " << Etot <<
" err_dedx^2/GeV^2: " << dedxSq <<
" p^6: " << pPre6 <<
G4endl;
732 if(
iverbose >= 2 )
G4cout <<
"G4EP:IONI: error2_from_ionisation " << (Etot*Etot*dedxSq) / pPre6 << G4endl;