Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DNAScavengerMaterial Class Reference

#include <G4DNAScavengerMaterial.hh>

+ Inheritance diagram for G4DNAScavengerMaterial:

Public Types

using NbMoleculeInTime
 
using MolType = const G4MolecularConfiguration*
 
using MaterialMap = std::map<MolType, int64_t>
 
using ReactantList = std::vector<MolType>
 
using CounterMapType = std::map<MolType, NbMoleculeInTime>
 

Public Member Functions

 G4DNAScavengerMaterial ()=default
 
 G4DNAScavengerMaterial (G4VChemistryWorld *)
 
 ~G4DNAScavengerMaterial () override=default
 
 G4DNAScavengerMaterial (const G4DNAScavengerMaterial &right)=delete
 
G4DNAScavengerMaterialoperator= (const G4DNAScavengerMaterial &)=delete
 
void Initialize ()
 
void ReduceNumberMoleculePerVolumeUnitForMaterialConf (MolType, G4double)
 
void AddNumberMoleculePerVolumeUnitForMaterialConf (MolType, G4double)
 
G4double GetNumberMoleculePerVolumeUnitForMaterialConf (MolType) const
 
void AddAMoleculeAtTime (MolType, G4double time, const G4ThreeVector *position=nullptr, G4int number=1)
 
void RemoveAMoleculeAtTime (MolType, G4double time, const G4ThreeVector *position=nullptr, G4int number=1)
 
void Reset () override
 
void PrintInfo ()
 
MaterialMap::iterator end ()
 
MaterialMap::iterator begin ()
 
size_t size ()
 
G4bool find (MolType type)
 
void SetCounterAgainstTime ()
 
void SetpH (const G4int &ph)
 
G4double GetpH ()
 
std::vector< MolTypeGetScavengerList () const
 
void Dump ()
 
int64_t GetNMoleculesAtTime (MolType molecule, G4double time)
 
G4bool SearchTimeMap (MolType molecule)
 
int64_t SearchUpperBoundTime (G4double time, G4bool sameTypeOfMolecule)
 
- Public Member Functions inherited from G4VScavengerMaterial
 G4VScavengerMaterial ()=default
 
virtual ~G4VScavengerMaterial ()=default
 

Detailed Description

Definition at line 41 of file G4DNAScavengerMaterial.hh.

Member Typedef Documentation

◆ CounterMapType

◆ MaterialMap

using G4DNAScavengerMaterial::MaterialMap = std::map<MolType, int64_t>

Definition at line 47 of file G4DNAScavengerMaterial.hh.

◆ MolType

◆ NbMoleculeInTime

Initial value:
std::map<G4double, int64_t, G4::MoleculeCounter::TimePrecision>

Definition at line 44 of file G4DNAScavengerMaterial.hh.

◆ ReactantList

Definition at line 48 of file G4DNAScavengerMaterial.hh.

Constructor & Destructor Documentation

◆ G4DNAScavengerMaterial() [1/3]

G4DNAScavengerMaterial::G4DNAScavengerMaterial ( )
default

◆ G4DNAScavengerMaterial() [2/3]

G4DNAScavengerMaterial::G4DNAScavengerMaterial ( G4VChemistryWorld * pChemistryInfo)
explicit

Definition at line 45 of file G4DNAScavengerMaterial.cc.

46 : fpChemistryInfo(pChemistryInfo), fIsInitialized(false), fCounterAgainstTime(false), fVerbose(0)
47{
48 Initialize();
49}

◆ ~G4DNAScavengerMaterial()

G4DNAScavengerMaterial::~G4DNAScavengerMaterial ( )
overridedefault

◆ G4DNAScavengerMaterial() [3/3]

G4DNAScavengerMaterial::G4DNAScavengerMaterial ( const G4DNAScavengerMaterial & right)
delete

Member Function Documentation

◆ AddAMoleculeAtTime()

void G4DNAScavengerMaterial::AddAMoleculeAtTime ( MolType molecule,
G4double time,
const G4ThreeVector * position = nullptr,
G4int number = 1 )

Definition at line 196 of file G4DNAScavengerMaterial.cc.

198{
199 if (fVerbose != 0) {
200 G4cout << "G4DNAScavengerMaterial::AddAMoleculeAtTime : " << molecule->GetName()
201 << " at time : " << G4BestUnit(time, "Time") << G4endl;
202 }
203
204 auto counterMap_i = fCounterMap.find(molecule);
205
206 if (counterMap_i == fCounterMap.end()) {
207 fCounterMap[molecule][time] = number;
208 }
209 else if (counterMap_i->second.empty()) {
210 counterMap_i->second[time] = number;
211 }
212 else {
213 auto end = counterMap_i->second.rbegin();
214
215 if (end->first <= time
216 || fabs(end->first - time) <= G4::MoleculeCounter::TimePrecision::fPrecision) {
217 G4double newValue = end->second + number;
218 counterMap_i->second[time] = newValue;
219 if (newValue != (floor)(fScavengerTable[molecule])) // protection
220 {
221 G4String errMsg = "You are trying to add wrong molecule ";
222 G4Exception("AddAMoleculeAtTime", "", FatalErrorInArgument, errMsg);
223 }
224 }
225 }
226}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define G4BestUnit(a, b)
double G4double
Definition G4Types.hh:83
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
MaterialMap::iterator end()
static G4ThreadLocal double fPrecision

Referenced by AddNumberMoleculePerVolumeUnitForMaterialConf().

◆ AddNumberMoleculePerVolumeUnitForMaterialConf()

void G4DNAScavengerMaterial::AddNumberMoleculePerVolumeUnitForMaterialConf ( MolType matConf,
G4double time )

Definition at line 115 of file G4DNAScavengerMaterial.cc.

117{
118 // no change these molecules
119
120 if (fH2O == matConf || fH3Op == matConf || // pH has no change
121 G4MoleculeTable::Instance()->GetConfiguration("OHm(B)") == matConf)
122 {
123 // G4cout<<"moletype : "<<matConf->GetName()<<G4endl;
124 // kobs is already counted these molecule concentrations
125 return;
126 }
127
128 auto it = fScavengerTable.find(matConf);
129 if (it == fScavengerTable.end()) // matConf must be in fScavengerTable
130 {
131 return;
132 }
133 fScavengerTable[matConf]++;
134
135 if (fCounterAgainstTime) {
136 AddAMoleculeAtTime(matConf, time);
137 }
138}
void AddAMoleculeAtTime(MolType, G4double time, const G4ThreeVector *position=nullptr, G4int number=1)
static G4MoleculeTable * Instance()

◆ begin()

MaterialMap::iterator G4DNAScavengerMaterial::begin ( )
inline

Definition at line 73 of file G4DNAScavengerMaterial.hh.

73{ return fScavengerTable.begin(); }

◆ Dump()

void G4DNAScavengerMaterial::Dump ( )

Definition at line 287 of file G4DNAScavengerMaterial.cc.

288{
289 auto pConfinedBox = fpChemistryInfo->GetChemistryBoundary();
290 auto V = pConfinedBox->Volume();
291 for (const auto& it : fCounterMap) {
292 auto pReactant = it.first;
293
294 G4cout << " --- > For " << pReactant->GetName() << G4endl;
295
296 for (const auto& it2 : it.second) {
297 G4cout << " " << G4BestUnit(it2.first, "Time") << " "
298 << it2.second / (Avogadro * V * 1.0e-6 /*mm3 to L*/) << G4endl;
299 }
300 }
301}
G4double Volume() const
G4DNABoundingBox * GetChemistryBoundary() const

Referenced by PrintInfo(), and RemoveAMoleculeAtTime().

◆ end()

MaterialMap::iterator G4DNAScavengerMaterial::end ( )
inline

Definition at line 72 of file G4DNAScavengerMaterial.hh.

72{ return fScavengerTable.end(); }

Referenced by AddAMoleculeAtTime().

◆ find()

G4bool G4DNAScavengerMaterial::find ( MolType type)
inline

Definition at line 76 of file G4DNAScavengerMaterial.hh.

77 {
78 auto it = fScavengerTable.find(type);
79 if(it != fScavengerTable.end())
80 {
81 return it->second > 0;
82 }
83
84 return false;
85
86 }

Referenced by ReduceNumberMoleculePerVolumeUnitForMaterialConf().

◆ GetNMoleculesAtTime()

int64_t G4DNAScavengerMaterial::GetNMoleculesAtTime ( MolType molecule,
G4double time )

Definition at line 303 of file G4DNAScavengerMaterial.cc.

304{
305 if (!fCounterAgainstTime) {
306 G4cout << "fCounterAgainstTime == false" << G4endl;
307 assert(false);
308 }
309
310 G4bool sameTypeOfMolecule = SearchTimeMap(molecule);
311 auto output = SearchUpperBoundTime(time, sameTypeOfMolecule);
312 if (output < 0) {
314 errMsg << "N molecules not valid < 0 : " << molecule->GetName() << " N : " << output << G4endl;
315 G4Exception("G4DNAScavengerMaterial::GetNMoleculesAtTime", "", FatalErrorInArgument, errMsg);
316 }
317 return output;
318}
std::ostringstream G4ExceptionDescription
bool G4bool
Definition G4Types.hh:86
int64_t SearchUpperBoundTime(G4double time, G4bool sameTypeOfMolecule)
G4bool SearchTimeMap(MolType molecule)

◆ GetNumberMoleculePerVolumeUnitForMaterialConf()

G4double G4DNAScavengerMaterial::GetNumberMoleculePerVolumeUnitForMaterialConf ( MolType matConf) const

Definition at line 67 of file G4DNAScavengerMaterial.cc.

68{
69 // no change these molecules
70 if (fH2O == matConf) {
71 G4ExceptionDescription exceptionDescription;
72 exceptionDescription << "matConf : " << matConf->GetName();
73 G4Exception("G4DNAScavengerMaterial::GetNumberMoleculePerVolumeUnitForMaterialConf",
74 "G4DNAScavengerMaterial001", FatalErrorInArgument, exceptionDescription);
75 }
76
77 auto iter = fScavengerTable.find(matConf);
78 if (iter == fScavengerTable.end()) {
79 return 0;
80 }
81
82 if (iter->second >= 1) {
83 return (floor)(iter->second);
84 }
85
86 return 0;
87}

Referenced by G4DNAScavengerProcess::PostStepGetPhysicalInteractionLength().

◆ GetpH()

G4double G4DNAScavengerMaterial::GetpH ( )

Definition at line 410 of file G4DNAScavengerMaterial.cc.

411{
412 G4double volumeInLiter = fpChemistryInfo->GetChemistryBoundary()->Volume() / liter;
413 G4double Cion = (G4double)fScavengerTable[fH3Op] / (Avogadro * volumeInLiter);
414 G4double pH = std::log10(Cion);
415 // G4cout<<"OH- : "<<fScavengerTable[fHOm]<<" H3O+ : "<<fScavengerTable[fH3Op]<<" pH :
416 // "<<-pH<<G4endl;
417 if (fScavengerTable[fH3Op] < 0) // protect me
418 {
419 G4Exception("G4DNAScavengerMaterial::GetpH()", "G4DNAScavengerMaterial001", JustWarning,
420 "H3O+ < 0");
421 fScavengerTable[fH3Op] = 0;
422 }
423 if (fScavengerTable[fHOm] < 0) // protect me
424 {
425 G4Exception("G4DNAScavengerMaterial::GetpH()", "G4DNAScavengerMaterial001", JustWarning,
426 "HO- < 0");
427 fScavengerTable[fHOm] = 0;
428 }
429 return -pH;
430}
@ JustWarning

◆ GetScavengerList()

std::vector< MolType > G4DNAScavengerMaterial::GetScavengerList ( ) const
inline

Definition at line 92 of file G4DNAScavengerMaterial.hh.

93 {
94 std::vector<MolType> output;
95 for(const auto& it : fScavengerTable)
96 {
97 output.push_back(it.first);
98 }
99 return output;
100 }

◆ Initialize()

void G4DNAScavengerMaterial::Initialize ( )

Definition at line 53 of file G4DNAScavengerMaterial.cc.

54{
55 if (fIsInitialized) {
56 return;
57 }
58
59 if (fpChemistryInfo->size() == 0) {
60 G4cout << "G4DNAScavengerMaterial existed but empty" << G4endl;
61 }
62 Reset();
63 fIsInitialized = true;
64}

Referenced by G4DNAScavengerMaterial().

◆ operator=()

G4DNAScavengerMaterial & G4DNAScavengerMaterial::operator= ( const G4DNAScavengerMaterial & )
delete

◆ PrintInfo()

void G4DNAScavengerMaterial::PrintInfo ( )

Definition at line 140 of file G4DNAScavengerMaterial.cc.

141{
142 auto pConfinedBox = fpChemistryInfo->GetChemistryBoundary();
143 auto iter = fpChemistryInfo->begin();
144 G4cout << "**************************************************************" << G4endl;
145 for (; iter != fpChemistryInfo->end(); iter++) {
146 auto containedConf = iter->first;
147 // auto concentration = iter->second;
148 auto concentration = fScavengerTable[containedConf] / (Avogadro * pConfinedBox->Volume());
149 G4cout << "Scavenger:" << containedConf->GetName() << " : "
150 << concentration / 1.0e-6 /*mm3 to L*/ << " (M) with : "
151 << fScavengerTable[containedConf] << " (molecules)"
152 << "in: " << pConfinedBox->Volume() / (um * um * um) << " (um3)" << G4endl;
153 if (fScavengerTable[containedConf] < 1) {
154 G4cout << "!!!!!!!!!!!!! this molecule has less one molecule for "
155 "considered volume"
156 << G4endl;
157 // assert(false);
158 }
159 if (fVerbose != 0) {
160 Dump();
161 }
162 }
163 G4cout << "**************************************************************" << G4endl;
164}
std::map< MolType, double >::iterator begin()
std::map< MolType, double >::iterator end()

Referenced by Reset().

◆ ReduceNumberMoleculePerVolumeUnitForMaterialConf()

void G4DNAScavengerMaterial::ReduceNumberMoleculePerVolumeUnitForMaterialConf ( MolType matConf,
G4double time )

Definition at line 89 of file G4DNAScavengerMaterial.cc.

91{
92 // no change these molecules
93 if (fH2O == matConf || fH3Op == matConf || // suppose that pH is not changed during simu
94 fHOm == matConf)
95 {
96 // G4cout<<"moletype : "<<matConf->GetName()<<G4endl;
97 // kobs is already counted these molecule concentrations
98 return;
99 }
100 if (!find(matConf)) // matConf must greater than 0
101 {
102 return;
103 }
104 fScavengerTable[matConf]--;
105 if (fScavengerTable[matConf] < 0) // projection
106 {
107 assert(false);
108 }
109
110 if (fCounterAgainstTime) {
111 RemoveAMoleculeAtTime(matConf, time);
112 }
113}
void RemoveAMoleculeAtTime(MolType, G4double time, const G4ThreeVector *position=nullptr, G4int number=1)

Referenced by G4DNAScavengerProcess::PostStepDoIt().

◆ RemoveAMoleculeAtTime()

void G4DNAScavengerMaterial::RemoveAMoleculeAtTime ( MolType pMolecule,
G4double time,
const G4ThreeVector * position = nullptr,
G4int number = 1 )

Definition at line 230 of file G4DNAScavengerMaterial.cc.

232{
233 NbMoleculeInTime& nbMolPerTime = fCounterMap[pMolecule];
234
235 if (fVerbose != 0) {
236 auto it_ = nbMolPerTime.rbegin();
237 G4cout << "G4DNAScavengerMaterial::RemoveAMoleculeAtTime : " << pMolecule->GetName()
238 << " at time : " << G4BestUnit(time, "Time")
239
240 << " form : " << it_->second << G4endl;
241 }
242
243 if (nbMolPerTime.empty()) {
244 Dump();
245 G4String errMsg = "You are trying to remove molecule " +
246 pMolecule->GetName() +
247 " from the counter while this kind of molecules has not "
248 "been registered yet";
249 G4Exception("G4DNAScavengerMaterial::RemoveAMoleculeAtTime", "", FatalErrorInArgument, errMsg);
250
251 return;
252 }
253
254 auto it = nbMolPerTime.rbegin();
255
256 if (it == nbMolPerTime.rend()) {
257 it--;
258
259 G4String errMsg = "There was no " + pMolecule->GetName()
260 + " recorded at the time or even before the time asked";
261 G4Exception("G4DNAScavengerMaterial::RemoveAMoleculeAtTime", "", FatalErrorInArgument, errMsg);
262 }
263
264 G4double finalN = it->second - number;
265 if (finalN < 0) {
266 Dump();
267
268 G4cout << "fScavengerTable : " << pMolecule->GetName() << " : " << (fScavengerTable[pMolecule])
269 << G4endl;
270
272 errMsg << "After removal of " << number << " species of "
273 << " " << it->second << " " << pMolecule->GetName() << " the final number at time "
274 << G4BestUnit(time, "Time") << " is less than zero and so not valid." << G4endl;
275 G4cout << " Global time is " << G4BestUnit(G4Scheduler::Instance()->GetGlobalTime(), "Time")
276 << ". Previous selected time is " << G4BestUnit(it->first, "Time") << G4endl;
277 G4Exception("G4DNAScavengerMaterial::RemoveAMoleculeAtTime", "N_INF_0", FatalException, errMsg);
278 }
279 nbMolPerTime[time] = finalN;
280
281 if (finalN != (floor)(fScavengerTable[pMolecule])) // protection
282 {
283 assert(false);
284 }
285}
@ FatalException
std::map< G4double, int64_t, G4::MoleculeCounter::TimePrecision > NbMoleculeInTime
static G4Scheduler * Instance()

Referenced by ReduceNumberMoleculePerVolumeUnitForMaterialConf().

◆ Reset()

void G4DNAScavengerMaterial::Reset ( )
overridevirtual

Implements G4VScavengerMaterial.

Definition at line 166 of file G4DNAScavengerMaterial.cc.

167{
168 if (fpChemistryInfo == nullptr) {
169 return;
170 }
171
172 if (fpChemistryInfo->size() == 0) {
173 return;
174 }
175
176 fScavengerTable.clear();
177 fCounterMap.clear();
178 fpLastSearch.reset(nullptr);
179
180 auto pConfinedBox = fpChemistryInfo->GetChemistryBoundary();
181 auto iter = fpChemistryInfo->begin();
182 for (; iter != fpChemistryInfo->end(); iter++) {
183 auto containedConf = iter->first;
184 auto concentration = iter->second;
185 fScavengerTable[containedConf] = floor(Avogadro * concentration * pConfinedBox->Volume());
186 fCounterMap[containedConf][1 * picosecond] =
187 floor(Avogadro * concentration * pConfinedBox->Volume());
188 }
189 if (fVerbose != 0) {
190 PrintInfo();
191 }
192}

Referenced by Initialize().

◆ SearchTimeMap()

G4bool G4DNAScavengerMaterial::SearchTimeMap ( MolType molecule)

Definition at line 320 of file G4DNAScavengerMaterial.cc.

321{
322 if (fpLastSearch == nullptr) {
323 fpLastSearch = std::make_unique<Search>();
324 }
325 else {
326 if (fpLastSearch->fLowerBoundSet && fpLastSearch->fLastMoleculeSearched->first == molecule) {
327 return true;
328 }
329 }
330
331 auto mol_it = fCounterMap.find(molecule);
332 fpLastSearch->fLastMoleculeSearched = mol_it;
333
334 if (mol_it != fCounterMap.end()) {
335 fpLastSearch->fLowerBoundTime = fpLastSearch->fLastMoleculeSearched->second.end();
336 fpLastSearch->fLowerBoundSet = true;
337 }
338 else {
339 fpLastSearch->fLowerBoundSet = false;
340 }
341
342 return false;
343}

Referenced by GetNMoleculesAtTime().

◆ SearchUpperBoundTime()

int64_t G4DNAScavengerMaterial::SearchUpperBoundTime ( G4double time,
G4bool sameTypeOfMolecule )

Definition at line 347 of file G4DNAScavengerMaterial.cc.

348{
349 auto mol_it = fpLastSearch->fLastMoleculeSearched;
350 if (mol_it == fCounterMap.end()) {
351 return 0;
352 }
353
354 NbMoleculeInTime& timeMap = mol_it->second;
355 if (timeMap.empty()) {
356 return 0;
357 }
358
359 if (sameTypeOfMolecule) {
360 if (fpLastSearch->fLowerBoundSet && fpLastSearch->fLowerBoundTime != timeMap.end()) {
361 if (fpLastSearch->fLowerBoundTime->first < time) {
362 auto upperToLast = fpLastSearch->fLowerBoundTime;
363 upperToLast++;
364
365 if (upperToLast == timeMap.end()) {
366 return fpLastSearch->fLowerBoundTime->second;
367 }
368
369 if (upperToLast->first > time) {
370 return fpLastSearch->fLowerBoundTime->second;
371 }
372 }
373 }
374 }
375
376 auto up_time_it = timeMap.upper_bound(time);
377
378 if (up_time_it == timeMap.end()) {
379 auto last_time = timeMap.rbegin();
380 return last_time->second;
381 }
382 if (up_time_it == timeMap.begin()) {
383 return 0;
384 }
385
386 up_time_it--;
387
388 fpLastSearch->fLowerBoundTime = up_time_it;
389 fpLastSearch->fLowerBoundSet = true;
390
391 return fpLastSearch->fLowerBoundTime->second;
392}

Referenced by GetNMoleculesAtTime().

◆ SetCounterAgainstTime()

void G4DNAScavengerMaterial::SetCounterAgainstTime ( )
inline

Definition at line 88 of file G4DNAScavengerMaterial.hh.

88{ fCounterAgainstTime = true; }

◆ SetpH()

void G4DNAScavengerMaterial::SetpH ( const G4int & ph)

Definition at line 403 of file G4DNAScavengerMaterial.cc.

404{
405 auto volume = fpChemistryInfo->GetChemistryBoundary()->Volume();
406 fScavengerTable[fH3Op] = floor(Avogadro * std::pow(10, -ph) * volume / liter);
407 fScavengerTable[fHOm] = floor(Avogadro * std::pow(10, -(14 - ph)) * volume / liter);
408}

◆ size()

size_t G4DNAScavengerMaterial::size ( )
inline

Definition at line 74 of file G4DNAScavengerMaterial.hh.

74{ return fScavengerTable.size(); }

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