BLCoordinates::ReferenceCoordinates Class Reference

Inheritance diagram for BLCoordinates::ReferenceCoordinates:

BLManager::TrackingAction BLManager::SteppingAction

List of all members.

Public Member Functions

 ReferenceCoordinates ()
virtual ~ReferenceCoordinates ()
void PreUserTrackingAction (const G4Track *track)
void PostUserTrackingAction (const G4Track *track)
void UserSteppingAction (const G4Step *step)
void addStep (const G4ThreeVector &pos, G4double z, bool final=false)

Private Attributes

BLManagermanager
G4ThreeVector prevDir
G4double prevZ
G4ThreeVector prevPos
G4double stepZ
G4ThreeVector stepPos
G4ThreeVector prevStepPos

Static Private Attributes

static G4ThreeVector unitZ


Constructor & Destructor Documentation

BLCoordinates::ReferenceCoordinates::ReferenceCoordinates (  ) 

virtual BLCoordinates::ReferenceCoordinates::~ReferenceCoordinates (  )  [inline, virtual]

00039 { }


Member Function Documentation

void BLCoordinates::ReferenceCoordinates::PreUserTrackingAction ( const G4Track *  track  )  [virtual]

Implements BLManager::TrackingAction.

References BEAM, BLCOORD_CENTERLINE, BLCoordinates::getCoords(), BLManager::getObject(), BLCoordinates::isValid(), prevDir, prevPos, prevStepPos, prevZ, REFERENCE, BLCoordinates::segmentRC, BLCoordinates::setMostRecentReferenceZ(), stepPos, stepZ, and BLCoordinates::validRC.

00453 {
00454         BLCoordinates *coord = (BLCoordinates *)track->GetUserInformation();
00455         if(!coord || !coord->isValid()) {
00456                 G4Exception("BLCoordinates","Coordinate Object Missing in Reference Track",
00457                                                         FatalException, "");
00458         }
00459 
00460         coord->segmentRC = 99999999;
00461 
00462         if(BLManager::getObject()->getState() == BEAM) {
00463                 if(!validRC) {
00464                         G4Exception("BLCoordinates","Reference Coordinates not available",
00465                                                         FatalException, "");
00466                 }
00467                 return;
00468         }
00469 
00470         if(BLManager::getObject()->getState() != REFERENCE) return;
00471 
00472         // @@@ need to handle multiple reference particles !!!!
00473 
00474         prevPos = track->GetPosition();
00475         prevDir = track->GetMomentumDirection();
00476 
00477         // initial Z is same as Centerline Coord value.
00478         G4ThreeVector cl;
00479         coord->getCoords(BLCOORD_CENTERLINE,cl);
00480         prevZ = cl[2];
00481         coord->setMostRecentReferenceZ(prevZ);
00482 
00483         // fake initial step of 1 mm 
00484         // (ensures sanity if reference bends in first step)
00485         stepPos = prevPos - prevDir;
00486         prevStepPos = stepPos - prevDir;
00487         stepZ = prevZ - 1.0;
00488 }

void BLCoordinates::ReferenceCoordinates::PostUserTrackingAction ( const G4Track *  track  )  [virtual]

Implements BLManager::TrackingAction.

References addStep(), BLManager::getObject(), BLCoordinates::global, REFERENCE, BLCoordinates::segmentRCVector, and BLCoordinates::validRC.

00491 {
00492         if(BLManager::getObject()->getState() != REFERENCE) return;
00493 
00494         // add 1 mm to final step
00495         // (ensures sanity if reference bends in final step)
00496         G4ThreeVector pos = track->GetPosition()+track->GetMomentumDirection();
00497         G4double z = track->GetTrackLength() + 1.0;
00498         addStep(pos,z,true);
00499 
00500         validRC = true;
00501 
00502         // for debugging -- dump segmentRCVector
00503         printf("\n# segmentRCVector\n#N minZ maxZ globX globY globZ axisX axisY axisZ angleDeg\n");
00504         G4double local[4];
00505         local[0] = local[1] = local[2] = local[3] = 0.0;
00506         for(unsigned i=0; i<segmentRCVector.size(); ++i) {
00507                 G4double global[4];
00508                 local[2] = (i==0 ? 0.0 : segmentRCVector[i].minZ);
00509                 segmentRCVector[i].transform.getGlobal(local,global);
00510                 G4ThreeVector axis = 
00511                         segmentRCVector[i].transform.getRotation().getAxis();
00512                 printf("%d %.4g %.4g %.4g %.4g %.4g %.4f %.4f %.4f %.1f\n",i,
00513                         segmentRCVector[i].minZ,segmentRCVector[i].maxZ,
00514                         global[0],global[1],global[2],axis[0],axis[1],axis[2],
00515                         segmentRCVector[i].transform.getRotation().getDelta()/deg);
00516         }
00517         printf("\n");
00518         fflush(stdout);
00519 }

void BLCoordinates::ReferenceCoordinates::UserSteppingAction ( const G4Step *  step  )  [virtual]

Implements BLManager::SteppingAction.

References addStep(), BLManager::getObject(), prevDir, prevPos, prevZ, REFERENCE, BLCoordinates::setMostRecentReferenceZ(), and BLCoordinates::tolerance.

00522 {
00523         // handle all states
00524         if(BLManager::getObject()->getState() != REFERENCE) return;
00525 
00526         G4Track *track = step->GetTrack();
00527         G4ThreeVector dir = track->GetMomentumDirection();
00528         if((dir-prevDir).mag2() > tolerance*tolerance)
00529                 addStep(prevPos, prevZ);
00530 
00531         prevDir = dir;
00532         prevPos = track->GetPosition();
00533         prevZ = track->GetTrackLength();
00534         BLCoordinates::setMostRecentReferenceZ(prevZ);
00535 }

void BLCoordinates::ReferenceCoordinates::addStep ( const G4ThreeVector &  pos,
G4double  z,
bool  final = false 
)

References BLCoordinates::currentCL, M_PI, prevStepPos, BLCoordinates::segmentCLVector, BLCoordinates::segmentRCVector, stepPos, stepZ, BLCoordinates::tolerance, and unitZ.

Referenced by PostUserTrackingAction(), and UserSteppingAction().

00539 {
00540         G4ThreeVector delta = pos - stepPos;
00541         G4double magDelta = delta.mag();
00542 
00543         // protect against delta being too small (should never happen,
00544         // as momentum direction changed significantly or first/final step
00545         // is >= 1 mm).
00546         if(magDelta < tolerance) return;
00547 
00548         // logic for rings is in CL coordinates; when we are lost, use CL
00549         // segment as starting point
00550         if(segmentCLVector[currentCL].firstRCSegment > segmentRCVector.size())
00551                 segmentCLVector[currentCL].firstRCSegment = 
00552                                                         segmentRCVector.size();
00553 
00554         G4ThreeVector rot = unitZ.cross(delta.unit());
00555         G4double a = asin(rot.mag());
00556         rot = rot.unit();
00557         // handle all 4 quadrants
00558         G4double b = unitZ.dot(delta.unit());
00559         if(a >= 0.0) {
00560                 if(b >= 0.0)
00561                         a = a;
00562                 else
00563                         a = M_PI - a;
00564         } else {
00565                 if(b >= 0.0)
00566                         a = a;
00567                 else
00568                         a = -M_PI + a;
00569         }
00570 
00571         G4RotationMatrix *p = 0;
00572         if(a > tolerance)
00573                 p = new G4RotationMatrix(rot,a);
00574         G4ThreeVector tmp(0,0,-stepZ);
00575         if(p)
00576                 tmp = *p * tmp;
00577         tmp += stepPos;
00578 
00579         G4double minZ = (segmentRCVector.size()==0 ? -DBL_MAX : stepZ);
00580         G4double maxZ = (final ? DBL_MAX : z);
00581         G4double interpPrev = stepZ + (z-stepZ)/4.0;
00582         G4double interpThis = z - (z-stepZ)/4.0;
00583         G4double correction = (z-stepZ)/magDelta;
00584 //printf("addStep minZ=%.4g maxZ=%.4g start x,y,z=%.3f,%.3f,%.3f  axis=%.3f,%.3f,%.3f aDeg=%.1f  corr=%.6f\n",minZ,maxZ,stepPos.x(),stepPos.y(),stepPos.z(),rot[0],rot[1],rot[2],a/deg,correction);
00585         segmentRCVector.push_back(RCSegment(minZ,maxZ,
00586                 BLCoordinateTransform(p,tmp),correction,interpPrev,interpThis));
00587 
00588         // set previous interpolate
00589         if(segmentRCVector.size() >= 2) {
00590                 delta = (pos-prevStepPos);
00591                 rot = unitZ.cross(delta.unit());
00592                 a = asin(rot.mag());
00593                 rot = rot.unit();
00594                 // handle all 4 quadrants
00595                 b = unitZ.dot(delta.unit());
00596                 if(a >= 0.0) {
00597                         if(b >= 0.0)
00598                                 a = a;
00599                         else
00600                                 a = M_PI - a;
00601                 } else {
00602                         if(b >= 0.0)
00603                                 a = a;
00604                         else
00605                                 a = -M_PI + a;
00606                 }
00607                 p = 0;
00608                 if(a > tolerance)
00609                         p = new G4RotationMatrix(rot,a);
00610                 tmp = G4ThreeVector(0,0,-stepZ);
00611                 if(p)
00612                         tmp = *p * tmp;
00613                 tmp += stepPos;
00614 //printf("addStep prev interpolate x,y,z=%.3f,%.3f,%.3f  axis=%.3f,%.3f,%.3f aDeg=%.1f\n",stepPos.x(),stepPos.y(),stepPos.z(),rot[0],rot[1],rot[2],a/deg);
00615                 segmentRCVector[segmentRCVector.size()-2].interpolate
00616                                                 = BLCoordinateTransform(p,tmp);
00617         }
00618 
00619         // update after this segment
00620         prevStepPos = stepPos;
00621         stepPos = pos;
00622         stepZ = z;
00623 }


Member Data Documentation

Referenced by ReferenceCoordinates().

Referenced by addStep(), and PreUserTrackingAction().

Referenced by addStep(), and PreUserTrackingAction().

G4ThreeVector BLCoordinates::ReferenceCoordinates::unitZ [static, private]

Referenced by addStep().


The documentation for this class was generated from the following file:
g4beamline