forked from OpenGATE/Gate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
441 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/*---------------------- | ||
GATE version name: gate_v6 | ||
Copyright (C): OpenGATE Collaboration | ||
This software is distributed under the terms | ||
of the GNU Lesser General Public Licence (LGPL) | ||
See GATE/LICENSE.txt for further details | ||
----------------------*/ | ||
|
||
|
||
/*! | ||
\class GateDoseActor | ||
\author fabien.baldacci@creatis.insa-lyon.fr | ||
*/ | ||
|
||
#ifndef GATETLEDOSEACTOR_HH | ||
#define GATETLEDOSEACTOR_HH | ||
|
||
#include "GateVImageActor.hh" | ||
#include "GateActorManager.hh" | ||
#include "G4UnitsTable.hh" | ||
#include "GateTLEDoseActorMessenger.hh" | ||
#include "GateImageWithStatistic.hh" | ||
#include "GateMaterialMuHandler.hh" | ||
|
||
class GateTLEDoseActor : public GateVImageActor | ||
{ | ||
public: | ||
|
||
//----------------------------------------------------------------------------- | ||
// Actor name | ||
virtual ~GateTLEDoseActor(); | ||
|
||
FCT_FOR_AUTO_CREATOR_ACTOR(GateTLEDoseActor) | ||
|
||
//----------------------------------------------------------------------------- | ||
// Constructs the sensor | ||
virtual void Construct(); | ||
|
||
void EnableEdepImage(bool b) { mIsEdepImageEnabled = b; } | ||
void EnableDoseUncertaintyImage(bool b) { mIsDoseUncertaintyImageEnabled = b; } | ||
void EnableEdepSquaredImage(bool b) { mIsEdepSquaredImageEnabled = b; } | ||
void EnableEdepUncertaintyImage(bool b) { mIsEdepUncertaintyImageEnabled = b; } | ||
void EnableDoseImage(bool b) { mIsDoseImageEnabled = b; } | ||
void EnableDoseSquaredImage(bool b) { mIsDoseSquaredImageEnabled = b; } | ||
|
||
virtual void BeginOfRunAction(const G4Run*r); | ||
virtual void BeginOfEventAction(const G4Event * event); | ||
|
||
//virtual void PostUserTrackingAction(const GateVVolume *, const G4Track* t); | ||
virtual void UserSteppingAction(const GateVVolume *, const G4Step*); | ||
virtual void UserSteppingActionInVoxel(const int index, const G4Step* step); | ||
virtual void UserPreTrackActionInVoxel(const int /*index*/, const G4Track* /*t*/) {} | ||
virtual void UserPostTrackActionInVoxel(const int /*index*/, const G4Track* /*t*/) {} | ||
|
||
/// Saves the data collected to the file | ||
virtual void SaveData(); | ||
virtual void ResetData(); | ||
|
||
///Scorer related | ||
//virtual G4bool ProcessHits(G4Step *, G4TouchableHistory*); | ||
virtual void clear(){ResetData();} | ||
virtual void Initialize(G4HCofThisEvent*){} | ||
virtual void EndOfEvent(G4HCofThisEvent*){} | ||
|
||
protected: | ||
GateTLEDoseActor(G4String name, G4int depth=0); | ||
GateTLEDoseActorMessenger * pMessenger; | ||
|
||
GateImageWithStatistic mDoseImage; | ||
//GateImageWithStatistic mPrimaryDoseImage; | ||
//GateImageWithStatistic mSecondaryDoseImage; | ||
GateImageWithStatistic mEdepImage; | ||
GateImage mLastHitEventImage; | ||
|
||
GateMaterialMuHandler* mMaterialHandler; | ||
G4String mDoseFilename; | ||
G4String mPDoseFilename; | ||
G4String mSDoseFilename; | ||
G4String mEdepFilename; | ||
G4double ConversionFactor; | ||
G4double VoxelVolume; | ||
bool mIsEdepImageEnabled; | ||
bool mIsDoseUncertaintyImageEnabled; | ||
bool mIsLastHitEventImageEnabled; | ||
bool mIsEdepSquaredImageEnabled; | ||
bool mIsEdepUncertaintyImageEnabled; | ||
bool mIsDoseImageEnabled; | ||
bool mIsDoseSquaredImageEnabled; | ||
int mCurrentEvent; | ||
G4double outputEnergy; | ||
G4double totalEnergy; | ||
G4double mEdep; | ||
G4String lastMaterial; | ||
G4double lastedep; | ||
G4int lastindex; | ||
G4bool firstdeposit; | ||
G4int primaryindex; | ||
std::vector<G4double> primarydeposition; | ||
std::vector<G4double> secondarydeposition; | ||
}; | ||
|
||
MAKE_AUTO_CREATOR_ACTOR(TLEDoseActor,GateTLEDoseActor) | ||
|
||
#endif /* end #define GATETLEDOSEACTOR_HH */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/*---------------------- | ||
GATE version name: gate_v6 | ||
Copyright (C): OpenGATE Collaboration | ||
This software is distributed under the terms | ||
of the GNU Lesser General Public Licence (LGPL) | ||
See GATE/LICENSE.txt for further details | ||
----------------------*/ | ||
|
||
/* | ||
\class GateTLEDoseActorMessenger | ||
\author fabien.baldacci@creatis.insa-lyon.fr | ||
*/ | ||
|
||
#ifndef GATETLEDOSEACTORMESSENGER_HH | ||
#define GATETLEDOSEACTORMESSENGER_HH | ||
|
||
#include "G4UIcmdWithABool.hh" | ||
#include "GateImageActorMessenger.hh" | ||
|
||
class GateTLEDoseActor; | ||
class GateTLEDoseActorMessenger : public GateImageActorMessenger | ||
{ | ||
public: | ||
GateTLEDoseActorMessenger(GateTLEDoseActor* sensor); | ||
virtual ~GateTLEDoseActorMessenger(); | ||
|
||
void BuildCommands(G4String base); | ||
void SetNewValue(G4UIcommand*, G4String); | ||
|
||
protected: | ||
GateTLEDoseActor * pDoseActor; | ||
|
||
G4UIcmdWithABool * pEnableDoseCmd; | ||
G4UIcmdWithABool * pEnableEdepCmd; | ||
G4UIcmdWithABool * pEnableDoseUncertaintyCmd; | ||
G4UIcmdWithABool * pEnableDoseSquaredCmd; | ||
G4UIcmdWithABool * pEnableEdepSquaredCmd; | ||
G4UIcmdWithABool * pEnableEdepUncertaintyCmd; | ||
|
||
}; | ||
|
||
#endif /* end #define GATETLEDOSEACTORMESSENGER_HH*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
/*---------------------- | ||
GATE version name: gate_v6 | ||
Copyright (C): OpenGATE Collaboration | ||
This software is distributed under the terms | ||
of the GNU Lesser General Public Licence (LGPL) | ||
See GATE/LICENSE.txt for further details | ||
----------------------*/ | ||
|
||
|
||
/* | ||
\brief Class GateTLEDoseActor : | ||
\brief | ||
*/ | ||
|
||
#ifndef GATETLEDOSEACTOR_CC | ||
#define GATETLEDOSEACTOR_CC | ||
|
||
#include "GateTLEDoseActor.hh" | ||
#include "GateMiscFunctions.hh" | ||
#include "GateMaterialMuHandler.hh" | ||
|
||
//----------------------------------------------------------------------------- | ||
GateTLEDoseActor::GateTLEDoseActor(G4String name, G4int depth): | ||
GateVImageActor(name,depth) { | ||
mCurrentEvent=-1; | ||
pMessenger = new GateTLEDoseActorMessenger(this); | ||
mMaterialHandler = new GateMaterialMuHandler(100); | ||
mIsEdepImageEnabled = false; | ||
mIsDoseUncertaintyImageEnabled = false; | ||
mIsLastHitEventImageEnabled = false; | ||
mIsEdepSquaredImageEnabled = false; | ||
mIsEdepUncertaintyImageEnabled = false; | ||
mIsDoseSquaredImageEnabled = false; | ||
|
||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
|
||
//----------------------------------------------------------------------------- | ||
/// Destructor | ||
GateTLEDoseActor::~GateTLEDoseActor() { | ||
delete pMessenger; | ||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
//----------------------------------------------------------------------------- | ||
/// Construct | ||
void GateTLEDoseActor::Construct() { | ||
GateVImageActor::Construct(); | ||
|
||
// Enable callbacks | ||
EnableBeginOfRunAction(true); | ||
EnableBeginOfEventAction(true); | ||
EnablePreUserTrackingAction(false); | ||
EnablePostUserTrackingAction(true); | ||
EnableUserSteppingAction(true); | ||
|
||
if (!mIsEdepImageEnabled && | ||
!mIsDoseImageEnabled) { | ||
GateError("The TLEDoseActor " << GetObjectName() << " does not have any image enabled ...\n Please select at least one ('enableEdep true' for example)"); | ||
} | ||
|
||
// Output Filename | ||
mDoseFilename = G4String(removeExtension(mSaveFilename))+"-Dose."+G4String(getExtension(mSaveFilename)); | ||
mEdepFilename = G4String(removeExtension(mSaveFilename))+"-Edep."+G4String(getExtension(mSaveFilename)); | ||
if(mIsEdepSquaredImageEnabled || mIsEdepUncertaintyImageEnabled || | ||
mIsDoseSquaredImageEnabled || mIsDoseUncertaintyImageEnabled){ | ||
mLastHitEventImage.SetResolutionAndHalfSize(mResolution, mHalfSize, mPosition); | ||
mLastHitEventImage.Allocate(); | ||
mIsLastHitEventImageEnabled = true; | ||
} | ||
|
||
|
||
if (mIsEdepImageEnabled) { | ||
mEdepImage.EnableSquaredImage(mIsEdepSquaredImageEnabled); | ||
mEdepImage.EnableUncertaintyImage(mIsEdepUncertaintyImageEnabled); | ||
mEdepImage.SetResolutionAndHalfSize(mResolution, mHalfSize, mPosition); | ||
mEdepImage.Allocate(); | ||
mEdepImage.SetFilename(mEdepFilename); | ||
} | ||
|
||
if (mIsDoseImageEnabled) { | ||
mDoseImage.EnableSquaredImage(mIsDoseSquaredImageEnabled); | ||
mDoseImage.EnableUncertaintyImage(mIsDoseUncertaintyImageEnabled); | ||
mDoseImage.SetResolutionAndHalfSize(mResolution, mHalfSize, mPosition); | ||
mDoseImage.Allocate(); | ||
mDoseImage.SetFilename(mDoseFilename); | ||
} | ||
|
||
|
||
ConversionFactor = 1.60217653e-19 * 1.e6 * 1.e2 * 1.e3; | ||
VoxelVolume = GetDoselVolume(); | ||
ResetData(); | ||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
|
||
//----------------------------------------------------------------------------- | ||
/// Save data | ||
void GateTLEDoseActor::SaveData() { | ||
if (mIsDoseImageEnabled) mDoseImage.SaveData(mCurrentEvent+1, false); | ||
if (mIsEdepImageEnabled) mEdepImage.SaveData(mCurrentEvent+1, false); | ||
if (mIsLastHitEventImageEnabled) mLastHitEventImage.Fill(-1); | ||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
//----------------------------------------------------------------------------- | ||
void GateTLEDoseActor::ResetData() { | ||
if (mIsLastHitEventImageEnabled) mLastHitEventImage.Fill(-1); | ||
if (mIsEdepImageEnabled) mEdepImage.Reset(); | ||
if (mIsDoseImageEnabled) mDoseImage.Reset(); | ||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
void GateTLEDoseActor::UserSteppingAction(const GateVVolume *, const G4Step* step) | ||
{ | ||
int index = GetIndexFromStepPosition(GetVolume(), step); | ||
UserSteppingActionInVoxel(index, step); | ||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
//----------------------------------------------------------------------------- | ||
void GateTLEDoseActor::BeginOfRunAction(const G4Run * r) { | ||
GateVActor::BeginOfRunAction(r); | ||
GateDebugMessage("Actor", 3, "GateDoseActor -- Begin of Run" << G4endl); | ||
// ResetData(); // Do no reset here !! (when multiple run); | ||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
//----------------------------------------------------------------------------- | ||
// Callback at each event | ||
void GateTLEDoseActor::BeginOfEventAction(const G4Event * e) { | ||
GateVActor::BeginOfEventAction(e); | ||
mCurrentEvent++; | ||
|
||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
//----------------------------------------------------------------------------- | ||
void GateTLEDoseActor::UserSteppingActionInVoxel(const int index, const G4Step* step) { | ||
G4StepPoint *PreStep(step->GetPreStepPoint()); | ||
G4StepPoint *PostStep(step->GetPostStepPoint()); | ||
G4ThreeVector prePosition=PreStep->GetPosition(); | ||
G4ThreeVector postPosition=PostStep->GetPosition(); | ||
if(step->GetTrack()->GetDefinition()->GetParticleName() == "gamma"){ | ||
G4double distance = step->GetStepLength(); | ||
G4double energy = PreStep->GetKineticEnergy(); | ||
double mu_en = mMaterialHandler->GetAttenuation(PreStep->GetMaterial(), energy); | ||
G4double dose = ConversionFactor*energy*mu_en*distance/VoxelVolume; | ||
G4double edep = 0.1*energy*mu_en*distance*PreStep->GetMaterial()->GetDensity()/(g/cm3); | ||
bool sameEvent=true; | ||
|
||
if (mIsLastHitEventImageEnabled) { | ||
if (mCurrentEvent != mLastHitEventImage.GetValue(index)) { | ||
sameEvent = false; | ||
mLastHitEventImage.SetValue(index, mCurrentEvent); | ||
} | ||
} | ||
|
||
if(energy <= .001){ | ||
edep=energy; | ||
step->GetTrack()->SetTrackStatus(fStopAndKill); | ||
} | ||
|
||
if (mIsDoseImageEnabled) { | ||
if (mIsDoseUncertaintyImageEnabled || mIsDoseSquaredImageEnabled) { | ||
if (sameEvent) mDoseImage.AddTempValue(index, dose); | ||
else mDoseImage.AddValueAndUpdate(index, dose); | ||
} | ||
else | ||
mDoseImage.AddValue(index, dose); | ||
} | ||
if(mIsEdepImageEnabled){ | ||
if (mIsEdepUncertaintyImageEnabled || mIsEdepSquaredImageEnabled) { | ||
if (sameEvent) mEdepImage.AddTempValue(index, edep); | ||
else mEdepImage.AddValueAndUpdate(index, edep); | ||
} | ||
else | ||
mEdepImage.AddValue(index, edep); | ||
} | ||
|
||
} | ||
} | ||
//----------------------------------------------------------------------------- | ||
|
||
#endif /* end #define GATETLEDOSEACTOR_CC */ |
Oops, something went wrong.