Loading...
Searching...
No Matches
Classes | Public Member Functions | Protected Member Functions | Private Types | Private Attributes | List of all members
scavenger::ScoreSpecies Class Reference

Primitive scorer class for scoring the radiolytic species produced after irradiation in a water volume. More...

#include <Doxymodules_medical.h>

Inheritance diagram for scavenger::ScoreSpecies:
G4VPrimitiveScorer G4UImessenger

Classes

struct  SpeciesInfo
 

Public Member Functions

 ScoreSpecies (const G4String &name, const G4int &depth=0)
 
 ~ScoreSpecies () override=default
 
void AddTimeToRecord (const G4double &time)
 Add a time at which the number of species should be recorded.
 
void ClearTimeToRecord ()
 Remove all times to record, must be reset by user.
 
G4int GetNumberOfRecordedEvents () const
 Get number of recorded events.
 
void Initialize (G4HCofThisEvent *) override
 
void EndOfEvent (G4HCofThisEvent *) override
 
void DrawAll () override
 
void PrintAll () override
 
void AbsorbResultsFromWorkerScorer (G4VPrimitiveScorer *)
 Method used in multithreading mode in order to merge the results.
 
void OutputAndClear ()
 
void SetNewValue (G4UIcommand *, G4String) override
 
void WriteWithAnalysisManager (G4VAnalysisManager *)
 Write results to whatever chosen file format.
 

Protected Member Functions

G4bool ProcessHits (G4Step *, G4TouchableHistory *) override
 

Private Types

typedef const G4MolecularConfiguration Species
 
typedef std::map< Species *, SpeciesInfoInnerSpeciesMap
 
typedef std::map< G4double, InnerSpeciesMapSpeciesMap
 

Private Attributes

SpeciesMap fSpeciesInfoPerTime
 
std::set< G4double > fTimeToRecord
 
G4int fNEvent = 0
 
G4double fEdep = 0
 
G4String fOutputType = "root"
 
G4int fHCID = -1
 
G4THitsMap< G4double > * fEvtMap = nullptr
 
std::unique_ptr< G4UIdirectoryfpSpeciesdir
 
std::unique_ptr< G4UIcmdWithAnIntegerfpTimeBincmd
 
std::unique_ptr< G4UIcmdWithADoubleAndUnitfpAddTimeToRecordcmd
 
std::unique_ptr< G4UIcmdWithAStringfpSetResultsFileNameCmd
 
G4String fRootFileName = "scorer.root"
 

Detailed Description

Primitive scorer class for scoring the radiolytic species produced after irradiation in a water volume.

This is a primitive scorer class for molecular species. The number of species is recorded for all times (predetermined or user chosen). It also scores the energy deposition in order to compute the radiochemical yields.

Definition at line 353 of file Doxymodules_medical.h.

Member Typedef Documentation

◆ Species

Definition at line 115 of file ScoreSpecies.hh.

◆ InnerSpeciesMap

Definition at line 116 of file ScoreSpecies.hh.

◆ SpeciesMap

typedef std::map<G4double, InnerSpeciesMap> scavenger::ScoreSpecies::SpeciesMap
private

Definition at line 117 of file ScoreSpecies.hh.

Constructor & Destructor Documentation

◆ ScoreSpecies()

scavenger::ScoreSpecies::ScoreSpecies ( const G4String name,
const G4int &  depth = 0 
)
explicit

Definition at line 47 of file ScoreSpecies.cc.

48 : G4VPrimitiveScorer(name, depth),
50 fpSpeciesdir(new G4UIdirectory("/scorer/species/")),
51 fpTimeBincmd(new G4UIcmdWithAnInteger("/scorer/species/nOfTimeBins", this)),
53 new G4UIcmdWithADoubleAndUnit("/scorer/species/addTimeToRecord", this)),
55 new G4UIcmdWithAString("/scorer/species/setRootFileName", this)) {
56 fpSpeciesdir->SetGuidance("ScoreSpecies commands");
57 fpSetResultsFileNameCmd->SetGuidance("Set the root file name");
58 G4MoleculeCounter::Instance()->ResetCounter();
59}
std::unique_ptr< G4UIcmdWithAnInteger > fpTimeBincmd
std::unique_ptr< G4UIdirectory > fpSpeciesdir
std::unique_ptr< G4UIcmdWithAString > fpSetResultsFileNameCmd
std::unique_ptr< G4UIcmdWithADoubleAndUnit > fpAddTimeToRecordcmd

◆ ~ScoreSpecies()

scavenger::ScoreSpecies::~ScoreSpecies ( )
overridedefault

Member Function Documentation

◆ AddTimeToRecord()

void scavenger::ScoreSpecies::AddTimeToRecord ( const G4double &  time)
inline

Add a time at which the number of species should be recorded.

Default times are set up to 1 microsecond.

Definition at line 67 of file ScoreSpecies.hh.

68 {
69 fTimeToRecord.insert(time);
70 }
std::set< G4double > fTimeToRecord

◆ ClearTimeToRecord()

void scavenger::ScoreSpecies::ClearTimeToRecord ( )
inline

Remove all times to record, must be reset by user.

Definition at line 73 of file ScoreSpecies.hh.

73{ fTimeToRecord.clear(); }

◆ GetNumberOfRecordedEvents()

G4int scavenger::ScoreSpecies::GetNumberOfRecordedEvents ( ) const
inline

Get number of recorded events.

Definition at line 76 of file ScoreSpecies.hh.

77 {
78 return fNEvent;
79 }

◆ Initialize()

void scavenger::ScoreSpecies::Initialize ( G4HCofThisEvent HCE)
override

Definition at line 101 of file ScoreSpecies.cc.

101 {
102 fEvtMap = new G4THitsMap<G4double>(GetMultiFunctionalDetector()->GetName(),
103 GetName());
104 if (fHCID < 0) {
105 fHCID = GetCollectionID(0);
106 }
107 HCE->AddHitsCollection(fHCID, (G4VHitsCollection *) fEvtMap);
108 G4MoleculeCounter::Instance()->ResetCounter();
109}
G4THitsMap< G4double > * fEvtMap

◆ EndOfEvent()

void scavenger::ScoreSpecies::EndOfEvent ( G4HCofThisEvent )
override

Definition at line 113 of file ScoreSpecies.cc.

113 {
114 if (G4EventManager::GetEventManager()->GetConstCurrentEvent()->IsAborted()) {
115 fEdep = 0.;
116 G4MoleculeCounter::Instance()->ResetCounter();
117 return;
118 }
119
120 auto species = G4MoleculeCounter::Instance()->GetRecordedMolecules();
121
122 if (species == nullptr || species->empty()) {
123 G4cout << "No molecule recorded, energy deposited= "
124 << G4BestUnit(fEdep, "Energy") << G4endl;
125 ++fNEvent;
126 fEdep = 0.;
127 G4MoleculeCounter::Instance()->ResetCounter();
128 return;
129 }
130 for (auto molecule: *species) {
131 for (auto time_mol: fTimeToRecord) {
132 G4double n_mol =
133 G4MoleculeCounter::Instance()->GetNMoleculesAtTime(molecule,
134 time_mol);
135 if (n_mol < 0) {
136 G4cerr << "N molecules not valid < 0 " << G4endl;
137 G4Exception("", "N<0", FatalException, "");
138 }
139 SpeciesInfo &molInfo = fSpeciesInfoPerTime[time_mol][molecule];
140 molInfo.fNumber += n_mol;
141 G4double gValue = (n_mol / (fEdep / eV)) * 100.;
142 molInfo.fG += gValue;
143 molInfo.fG2 += gValue * gValue;
144 }
145 }
146 ++fNEvent;
147 fEdep = 0.;
148 G4MoleculeCounter::Instance()->ResetCounter();
149}

◆ DrawAll()

void scavenger::ScoreSpecies::DrawAll ( )
inlineoverride

Definition at line 85 of file ScoreSpecies.hh.

85{};

◆ PrintAll()

void scavenger::ScoreSpecies::PrintAll ( )
override

Definition at line 188 of file ScoreSpecies.cc.

188 {
189 G4cout << " MultiFunctionalDet " << detector->GetName() << G4endl;
190 G4cout << " PrimitiveScorer " << GetName() << G4endl;
191 G4cout << " Number of events " << fNEvent << G4endl;
192 G4cout << " Number of energy deposition recorded "
193 << fEvtMap->entries() << G4endl;
194
195 for (auto itr : *fEvtMap->GetMap()) {
196 G4cout << " copy no.: " << itr.first
197 << " energy deposit: "
198 << *(itr.second) / GetUnitValue()
199 << " [" << GetUnit() << "]"
200 << G4endl;
201 }
202}

◆ AbsorbResultsFromWorkerScorer()

void scavenger::ScoreSpecies::AbsorbResultsFromWorkerScorer ( G4VPrimitiveScorer workerScorer)

Method used in multithreading mode in order to merge the results.

Definition at line 154 of file ScoreSpecies.cc.

154 {
155 auto right = dynamic_cast<ScoreSpecies *>(dynamic_cast<G4VPrimitiveScorer *>(workerScorer));
156
157 if (right == nullptr) {
158 return;
159 }
160 if (right == this) {
161 return;
162 }
163
164 auto it_map1 = right->fSpeciesInfoPerTime.begin();
165 auto end_map1 = right->fSpeciesInfoPerTime.end();
166
167 for (; it_map1 != end_map1; ++it_map1) {
168 InnerSpeciesMap &map2 = it_map1->second;
169 auto it_map2 = map2.begin();
170 auto end_map2 = map2.end();
171
172 for (; it_map2 != end_map2; ++it_map2) {
173 SpeciesInfo &molInfo =
174 fSpeciesInfoPerTime[it_map1->first][it_map2->first];
175 molInfo.fNumber += it_map2->second.fNumber;
176 molInfo.fG += it_map2->second.fG;
177 molInfo.fG2 += it_map2->second.fG2;
178 }
179 }
180 right->fSpeciesInfoPerTime.clear();
181 fNEvent += right->fNEvent;
182 right->fNEvent = 0;
183 right->fEdep = 0.;
184}
std::map< Species *, SpeciesInfo > InnerSpeciesMap
ScoreSpecies(const G4String &name, const G4int &depth=0)

◆ OutputAndClear()

void scavenger::ScoreSpecies::OutputAndClear ( )

Definition at line 206 of file ScoreSpecies.cc.

206 {
207 if (G4Threading::IsWorkerThread()) {
208 return;
209 }
210
211 auto analysisManager = G4AnalysisManager::Instance();
212 analysisManager->SetDefaultFileType(fOutputType);
213 this->WriteWithAnalysisManager(analysisManager);
214 fNEvent = 0;
215 fSpeciesInfoPerTime.clear();
216}
void WriteWithAnalysisManager(G4VAnalysisManager *)
Write results to whatever chosen file format.

◆ SetNewValue()

void scavenger::ScoreSpecies::SetNewValue ( G4UIcommand command,
G4String  newValue 
)
override

Definition at line 63 of file ScoreSpecies.cc.

63 {
64 if (command == fpAddTimeToRecordcmd.get()) {
65 G4double cmdTime = fpAddTimeToRecordcmd->GetNewDoubleValue(newValue);
66 AddTimeToRecord(cmdTime);
67 }
68 if (command == fpTimeBincmd.get()) {
70 G4int cmdBins = fpTimeBincmd->GetNewIntValue(newValue);
71 G4double timeMin = 1 * ps;
72 G4double timeMax = G4Scheduler::Instance()->GetEndTime() - timeMin;
73 G4double timeLogMin = std::log10(timeMin);
74 G4double timeLogMax = std::log10(timeMax);
75 for (G4int i = 0; i < cmdBins; i++) {
76 AddTimeToRecord(std::pow(10, timeLogMin +
77 i * (timeLogMax - timeLogMin) / (cmdBins - 1)));
78 }
79 }
80 if (command == fpSetResultsFileNameCmd.get()) {
81 fRootFileName = newValue;
82 }
83}
void AddTimeToRecord(const G4double &time)
Add a time at which the number of species should be recorded.
void ClearTimeToRecord()
Remove all times to record, must be reset by user.

◆ WriteWithAnalysisManager()

void scavenger::ScoreSpecies::WriteWithAnalysisManager ( G4VAnalysisManager analysisManager)

Write results to whatever chosen file format.

Definition at line 221 of file ScoreSpecies.cc.

221 {
222 analysisManager->OpenFile(fRootFileName);
223 G4int fNtupleID = analysisManager->CreateNtuple("species", "species");
224 analysisManager->CreateNtupleIColumn(fNtupleID, "speciesID");
225 analysisManager->CreateNtupleIColumn(fNtupleID, "number");
226 analysisManager->CreateNtupleIColumn(fNtupleID, "nEvent");
227 analysisManager->CreateNtupleSColumn(fNtupleID, "speciesName");
228 analysisManager->CreateNtupleDColumn(fNtupleID, "time");
229 analysisManager->CreateNtupleDColumn(fNtupleID, "sumG");
230 analysisManager->CreateNtupleDColumn(fNtupleID, "sumG2");
231 analysisManager->FinishNtuple(fNtupleID);
232
233 for (const auto &it_map1: fSpeciesInfoPerTime) {
234 const InnerSpeciesMap &map2 = it_map1.second;
235
236 for (const auto &it_map2 : map2) {
237 G4double time = it_map1.first;
238 auto species = it_map2.first;
239 const G4String &name = species->GetName();
240 auto molID = it_map2.first->GetMoleculeID();
241 auto number = it_map2.second.fNumber;
242 auto G = it_map2.second.fG;
243 auto G2 = it_map2.second.fG2;
244 analysisManager->FillNtupleIColumn(fNtupleID, 0, molID); // MolID
245 analysisManager->FillNtupleIColumn(fNtupleID, 1, number); // Number
246 analysisManager->FillNtupleIColumn(fNtupleID, 2, fNEvent); // Total nb events
247 analysisManager->FillNtupleSColumn(fNtupleID, 3, name); // molName
248 analysisManager->FillNtupleDColumn(fNtupleID, 4, time); // time
249 analysisManager->FillNtupleDColumn(fNtupleID, 5, G); // G
250 analysisManager->FillNtupleDColumn(fNtupleID, 6, G2); // G2
251 analysisManager->AddNtupleRow(fNtupleID);
252 }
253 }
254
255 analysisManager->Write();
256 analysisManager->CloseFile();
257}

◆ ProcessHits()

G4bool scavenger::ScoreSpecies::ProcessHits ( G4Step aStep,
G4TouchableHistory  
)
overrideprotected

Definition at line 87 of file ScoreSpecies.cc.

87 {
88 G4double edep = aStep->GetTotalEnergyDeposit();
89 if (edep == 0.) {
90 return FALSE;
91 }
92 edep *= aStep->GetPreStepPoint()->GetWeight(); // (Particle Weight)
93 auto index = GetIndex(aStep);
94 fEvtMap->add(index, edep);
95 fEdep += edep;
96 return TRUE;
97}

Member Data Documentation

◆ fSpeciesInfoPerTime

SpeciesMap scavenger::ScoreSpecies::fSpeciesInfoPerTime
private

Definition at line 118 of file ScoreSpecies.hh.

◆ fTimeToRecord

std::set<G4double> scavenger::ScoreSpecies::fTimeToRecord
private

Definition at line 119 of file ScoreSpecies.hh.

◆ fNEvent

G4int scavenger::ScoreSpecies::fNEvent = 0
private

Definition at line 120 of file ScoreSpecies.hh.

◆ fEdep

G4double scavenger::ScoreSpecies::fEdep = 0
private

Definition at line 121 of file ScoreSpecies.hh.

◆ fOutputType

G4String scavenger::ScoreSpecies::fOutputType = "root"
private

Definition at line 122 of file ScoreSpecies.hh.

◆ fHCID

G4int scavenger::ScoreSpecies::fHCID = -1
private

Definition at line 123 of file ScoreSpecies.hh.

◆ fEvtMap

G4THitsMap<G4double>* scavenger::ScoreSpecies::fEvtMap = nullptr
private

Definition at line 124 of file ScoreSpecies.hh.

◆ fpSpeciesdir

std::unique_ptr<G4UIdirectory> scavenger::ScoreSpecies::fpSpeciesdir
private

Definition at line 125 of file ScoreSpecies.hh.

◆ fpTimeBincmd

std::unique_ptr<G4UIcmdWithAnInteger> scavenger::ScoreSpecies::fpTimeBincmd
private

Definition at line 126 of file ScoreSpecies.hh.

◆ fpAddTimeToRecordcmd

std::unique_ptr<G4UIcmdWithADoubleAndUnit> scavenger::ScoreSpecies::fpAddTimeToRecordcmd
private

Definition at line 127 of file ScoreSpecies.hh.

◆ fpSetResultsFileNameCmd

std::unique_ptr<G4UIcmdWithAString> scavenger::ScoreSpecies::fpSetResultsFileNameCmd
private

Definition at line 128 of file ScoreSpecies.hh.

◆ fRootFileName

G4String scavenger::ScoreSpecies::fRootFileName = "scorer.root"
private

Definition at line 129 of file ScoreSpecies.hh.


The documentation for this class was generated from the following files:

Applications | User Support | Publications | Collaboration