Loading...
Searching...
No Matches
ScoreSpecies.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26/// \file scavenger/src/ScoreSpecies.cc
27/// \brief Implementation of the scavenger::ScoreSpecies class
28
29#include "ScoreSpecies.hh"
30
31#include <G4MolecularConfiguration.hh>
32#include <G4MoleculeCounter.hh>
33#include <G4SystemOfUnits.hh>
34#include <G4EventManager.hh>
35#include <globals.hh>
36#include "G4UnitsTable.hh"
37#include "G4Scheduler.hh"
38#include "G4AnalysisManager.hh"
39#include "G4Event.hh"
40#include "G4UImessenger.hh"
41
42namespace scavenger
43{
44
45//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
46
47ScoreSpecies::ScoreSpecies(const G4String &name, const G4int &depth)
48 : G4VPrimitiveScorer(name, depth),
50 fpSpeciesdir(new G4UIdirectory("/scorer/species/")),
51 fpTimeBincmd(new G4UIcmdWithAnInteger("/scorer/species/nOfTimeBins", this)),
52 fpAddTimeToRecordcmd(
53 new G4UIcmdWithADoubleAndUnit("/scorer/species/addTimeToRecord", this)),
54 fpSetResultsFileNameCmd(
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}
60
61//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
62
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}
84
85//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
86
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}
98
99//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
100
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}
110
111//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
112
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}
150
151//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
152
153void
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}
185
186//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
187
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}
203
204//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
205
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}
217
218//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
219
220void
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}
258
259//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
260
261}
Definition of the scavenger::ScoreSpecies class.
Primitive scorer class for scoring the radiolytic species produced after irradiation in a water volum...
std::set< G4double > fTimeToRecord
std::map< Species *, SpeciesInfo > InnerSpeciesMap
void AbsorbResultsFromWorkerScorer(G4VPrimitiveScorer *)
Method used in multithreading mode in order to merge the results.
void AddTimeToRecord(const G4double &time)
Add a time at which the number of species should be recorded.
G4THitsMap< G4double > * fEvtMap
std::unique_ptr< G4UIcmdWithAnInteger > fpTimeBincmd
G4bool ProcessHits(G4Step *, G4TouchableHistory *) override
void WriteWithAnalysisManager(G4VAnalysisManager *)
Write results to whatever chosen file format.
void SetNewValue(G4UIcommand *, G4String) override
std::unique_ptr< G4UIdirectory > fpSpeciesdir
void EndOfEvent(G4HCofThisEvent *) override
void PrintAll() override
void Initialize(G4HCofThisEvent *) override
void ClearTimeToRecord()
Remove all times to record, must be reset by user.
std::unique_ptr< G4UIcmdWithAString > fpSetResultsFileNameCmd
ScoreSpecies(const G4String &name, const G4int &depth=0)
std::unique_ptr< G4UIcmdWithADoubleAndUnit > fpAddTimeToRecordcmd

Applications | User Support | Publications | Collaboration