00001
00002
00003
00004
00006 #include "Swimmer/SwimStepOnceAction.h"
00007 #include "Swimmer/SwimParticle.h"
00008 #include "Swimmer/SwimStepData.h"
00009 #include "Swimmer/SwimStepper.h"
00010 #include "Swimmer/SwimGeo.h"
00011 #include <cmath>
00012
00013 #include "MessageService/MsgService.h"
00014
00015 CVSID("$Id: SwimStepOnceAction.cxx,v 1.16 2006/08/03 18:10:41 musser Exp $");
00016
00017 void SwimStepOnceAction::Perform(SwimParticle& particle,
00018 SwimStepData* stepData)
00019 {
00020
00021
00022
00023
00024 SwimGeo::SwimMaterial_t material = stepData->GetSwimMaterial();
00025 if (particle.GetMomentumModulus()!=0.0) {
00026 if (material==SwimGeo::kAir ||
00027 material==SwimGeo::kScint)
00028 {
00029
00030 double density = SwimGeo::GetSwimMaterialDensity(material);
00031 TVector3 startpos, path;
00032 startpos = particle.GetPosition();
00033
00034
00035
00036
00037 TVector3 position;
00038 double xNext[3];
00039 double stepSize = stepData->GetStepSize();
00040
00041 if (stepData->GetIsForward()) {
00042 xNext[0] =
00043 particle.GetPosition().X()+stepSize*particle.GetDirection().X();
00044 xNext[1] =
00045 particle.GetPosition().Y()+stepSize*particle.GetDirection().Y();
00046 xNext[2] =
00047 particle.GetPosition().Z()+stepSize*particle.GetDirection().Z();
00048 }
00049 else {
00050 xNext[0] =
00051 particle.GetPosition().X()-stepSize*particle.GetDirection().X();
00052 xNext[1] =
00053 particle.GetPosition().Y()-stepSize*particle.GetDirection().Y();
00054 xNext[2] =
00055 particle.GetPosition().Z()-stepSize*particle.GetDirection().Z();
00056 }
00057
00058
00059
00060
00061 position.SetXYZ(xNext[0],xNext[1],xNext[2]);
00062 particle.SetPosition(position);
00063
00064
00065 path = particle.GetPosition();
00066 double endz = path[2];
00067 path -= startpos;
00068 particle.AddS(path.Mag());
00069 particle.AddRange(density*path.Mag()/(Munits::g/Munits::cm2));
00070 MSG("Swim",Msg::kDebug) << " start/end z " << startpos[2] << "/" << endz << " density " << density/1000. << " dzds " << fabs(path[2]/path.Mag()) << " dRange " << density*path.Mag() << endl;
00071 }
00072 else {
00073 MSG("Swim",Msg::kDebug) << "StepOnce\n";
00074
00075 bool stepOk = stepData->GetStepper()->StepOnce(particle, stepData);
00076 MSG("Swim",Msg::kDebug) << "StepOnce complete\n";
00077
00078 if (stepOk == false) {
00079
00080 MSG("Swim",Msg::kWarning) << "Step error\n";
00081 }
00082 }
00083 }
00084 }
00085