Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions source/digits_hits/scorer/include/G4PSCellFlux.hh
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ class G4PSCellFlux : public G4VPrimitivePlotter
G4PSCellFlux(G4String name, G4int depth = 0);
G4PSCellFlux(G4String name, const G4String& unit, G4int depth = 0);
~G4PSCellFlux() override = default;

// Use particle general weight
inline void Weighted(G4bool flg = true) { weighted = flg; }
// Multiply track weight

// Usee specific weight for scoring
inline void ScoreWeighted(G4bool flg = false) { scoreWeighted = flg; }
//
void Initialize(G4HCofThisEvent*) override;
void clear() override;
void PrintAll() override;

virtual void SetUnit(const G4String& unit);

protected:
Expand All @@ -79,5 +79,6 @@ class G4PSCellFlux : public G4VPrimitivePlotter
G4int HCID;
G4THitsMap<G4double>* EvtMap;
G4bool weighted;
G4bool scoreWeighted;
};
#endif
17 changes: 13 additions & 4 deletions source/digits_hits/scorer/src/G4PSCellFlux.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
Expand Down Expand Up @@ -35,6 +34,7 @@
#include "G4VPVParameterisation.hh"
#include "G4UnitsTable.hh"
#include "G4VScoreHistFiller.hh"
#include "G4FluenceWeightCalculator.hh"

///////////////////////////////////////////////////////////////////////////////
// (Description)
Expand Down Expand Up @@ -64,6 +64,7 @@ G4PSCellFlux::G4PSCellFlux(G4String name, const G4String& unit, G4int depth)
, HCID(-1)
, EvtMap(nullptr)
, weighted(true)
, scoreWeighted(false)
{
DefineUnitAndCategory();
SetUnit(unit);
Expand All @@ -78,13 +79,19 @@ G4bool G4PSCellFlux::ProcessHits(G4Step* aStep, G4TouchableHistory*)
G4int idx = ((G4TouchableHistory*) (aStep->GetPreStepPoint()->GetTouchable()))
->GetReplicaNumber(indexDepth);
G4double cubicVolume = ComputeVolume(aStep, idx);

G4double CellFlux = stepLength / cubicVolume;
const G4Track* track = aStep->GetTrack();
G4double pWeight = 1.;
if (scoreWeighted) {
G4double kineticEnergy = track->GetKineticEnergy();
const auto* particle = track->GetParticleDefinition();
pWeight = G4FluenceWeightCalculator::GetInstance()->GetWeight(particle, kineticEnergy);
}
G4double CellFlux = stepLength / cubicVolume * pWeight;
if(weighted)
CellFlux *= aStep->GetPreStepPoint()->GetWeight();
G4int index = GetIndex(aStep);
EvtMap->add(index, CellFlux);

if(!hitIDMap.empty() && hitIDMap.find(index) != hitIDMap.end())
{
auto filler = G4VScoreHistFiller::Instance();
Expand Down Expand Up @@ -148,3 +155,5 @@ G4double G4PSCellFlux::ComputeVolume(G4Step* aStep, G4int idx)
assert(solid);
return solid->GetCubicVolume();
}


28 changes: 28 additions & 0 deletions source/digits_hits/utils/include/G4FluenceWeightCalculator.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

#ifndef G4FluenceWeightCalculator_h
#define G4FluenceWeightCalculator_h

#include "G4Types.hh"
#include "G4ParticleDefinition.hh"

class G4FluenceWeightCalculator {
public:
virtual ~G4FluenceWeightCalculator() = default;

virtual G4double GetWeight(const G4ParticleDefinition*, G4double) const = 0;

static void SetInstance(G4FluenceWeightCalculator* instance);
static const G4FluenceWeightCalculator* GetInstance();

private:
static G4FluenceWeightCalculator* fInstance;
};

class G4DefaultFluenceWeightCalculator : public G4FluenceWeightCalculator {
public:
virtual G4double GetWeight(const G4ParticleDefinition*, G4double) const override {
return 1.0;
}
};

#endif
2 changes: 2 additions & 0 deletions source/digits_hits/utils/sources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
geant4_add_module(G4detutils
PUBLIC_HEADERS
G4DefaultLinearColorMap.hh
G4FluenceWeightCalculator.hh
G4ScoreLogColorMap.hh
G4VScoreNtupleWriter.hh
G4TScoreNtupleWriter.hh
Expand All @@ -22,6 +23,7 @@ geant4_add_module(G4detutils
G4VScoringMesh.hh
SOURCES
G4DefaultLinearColorMap.cc
G4FluenceWeightCalculator.cc
G4ScoreLogColorMap.cc
G4VScoreNtupleWriter.cc
G4ScoreQuantityMessenger.cc
Expand Down
15 changes: 15 additions & 0 deletions source/digits_hits/utils/src/G4FluenceWeightCalculator.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "G4FluenceWeightCalculator.hh"

G4FluenceWeightCalculator* G4FluenceWeightCalculator::fInstance = nullptr;

const G4FluenceWeightCalculator* G4FluenceWeightCalculator::GetInstance() {
if (!fInstance) {
static G4DefaultFluenceWeightCalculator defaultCalculator;
fInstance = &defaultCalculator;
}
return fInstance;
}

void G4FluenceWeightCalculator::SetInstance(G4FluenceWeightCalculator* instance) {
fInstance = instance;
}
4 changes: 4 additions & 0 deletions source/digits_hits/utils/src/G4ScoreQuantityMessenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ void G4ScoreQuantityMessenger::QuantityCommands()
param = new G4UIparameter("unit", 's', true);
param->SetDefaultValue("percm2");
qCellFluxCmd->SetParameter(param);
param = new G4UIparameter("scoreweighted", 'b', true);
param->SetDefaultValue("false");
qCellFluxCmd->SetParameter(param);
//
qPassCellFluxCmd = new G4UIcommand("/score/quantity/passageCellFlux", this);
qPassCellFluxCmd->SetGuidance("Passage cell flux scorer");
Expand Down Expand Up @@ -635,6 +638,7 @@ void G4ScoreQuantityMessenger::SetNewValue(G4UIcommand* command,
ps = new G4PSCellFlux(token[0]);
}
ps->SetUnit(token[1]);
ps->ScoreWeighted(StoB(token[2]));
mesh->SetPrimitiveScorer(ps);
}
}
Expand Down