Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4DNAScavengerProcess.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//
28#include <G4VScheduler.hh>
29#include <memory>
30#include "G4Molecule.hh"
32#include "G4UnitsTable.hh"
36#include "G4DNABoundingBox.hh"
38#include "G4MoleculeFinder.hh"
39#include "G4Scheduler.hh"
41
42#ifndef State
43# define State(theXInfo) (GetState<G4DNAScavengerProcessState>()->theXInfo)
44#endif
64
66{
67 for(auto& iter : fConfMap)
68 {
69 for(auto& iter2 : iter.second)
70 {
71 delete iter2.second;
72 }
73 }
74}
75
91
93{
95 G4VITProcess::fpState = std::make_shared<G4DNAScavengerProcessState>();
97}
98
100{
102 {
103 G4ExceptionDescription exceptionDescription;
104 exceptionDescription
105 << "G4DNASecondOrderReaction was already initialised. ";
106 exceptionDescription << "You cannot set a reaction after initialisation.";
107 G4Exception("G4DNASecondOrderReaction::SetReaction",
108 "G4DNASecondOrderReaction001", FatalErrorInArgument,
109 exceptionDescription);
110 }
111 auto materialConf = pData->GetReactant1() == molConf ? pData->GetReactant2()
112 : pData->GetReactant1();
113 if(verboseLevel > 0)
114 {
115 G4cout << "G4DNAScavengerProcess::SetReaction : " << molConf->GetName()
116 << " materialConf : " << materialConf->GetName() << G4endl;
117 }
118 fConfMap[molConf][materialConf] = pData;
119}
120
122 const G4Track& track, G4double /*previousStepSize*/,
123 G4ForceCondition* pForceCond)
124{
125 G4Molecule* molecule = GetMolecule(track);
126 auto molConf = molecule->GetMolecularConfiguration();
127 // this because process for moleculeDifinition not for configuration
128 // TODO: need change this
129 auto it = fConfMap.find(molConf);
130 if(it == fConfMap.end())
131 {
132 return DBL_MAX;
133 }
134 fpMolecularConfiguration = nullptr;
135 fpMaterialConf = nullptr;
136
137 fpMolecularConfiguration = molConf;
138 auto MaterialMap = it->second;
139
140 G4double r1 = G4UniformRand();
141 std::map<G4double /*Propensity*/, std::pair<MolType, G4double>>
142 ReactionDataMap;
143 G4double alpha0 = 0;
144
145 for(const auto& mat_it : MaterialMap)
146 {
147 auto matConf = mat_it.first;
148 G4double numMol =
149 fpScavengerMaterial->GetNumberMoleculePerVolumeUnitForMaterialConf(
150 matConf);
151 if(numMol == 0 && matConf != fH2O){
152 continue;}
153 auto data = mat_it.second;
154 auto reactionRate = data->GetObservedReactionRateConstant(); //_const
155 G4double propensity =
156 numMol * reactionRate / (fpBoundingBox->Volume() * Avogadro);
157
158 if(fH2O == matConf){
159 auto factor = reactionRate;
160 propensity = factor;
161 }
162
163 if(verboseLevel > 1)
164 {
165 G4cout << " Material of " << matConf->GetName() << " : " << propensity
166 << G4endl;
167 }
168
169 auto reactionData = std::make_pair(mat_it.first, propensity);
170 if(propensity == 0)
171 {
172 continue;
173 }
174 alpha0 += propensity;
175 ReactionDataMap[alpha0] = reactionData;
176 }
177 if(alpha0 == 0)
178 {
179 if(State(fIsInGoodMaterial))
180 {
182 State(fIsInGoodMaterial) = false;
183 }
184 return DBL_MAX;
185 }
186 auto rSelectedIter = ReactionDataMap.upper_bound(r1 * alpha0);
187
188 fpMaterialConf = rSelectedIter->second.first;
189
190
191 auto type = fConfMap[fpMolecularConfiguration][fpMaterialConf]->GetReactionType();
192 if(!fpScavengerMaterial->IsEquilibrium(type))
193 {
194 return DBL_MAX;
195 }
196
197 State(fIsInGoodMaterial) = true;
198 G4double previousTimeStep(-1.);
199
200 if(State(fPreviousTimeAtPreStepPoint) != -1)
201 {
202 previousTimeStep =
203 track.GetGlobalTime() - State(fPreviousTimeAtPreStepPoint);
204 }
205
206 State(fPreviousTimeAtPreStepPoint) = track.GetGlobalTime();
207
208 // condition is set to "Not Forced"
209 *pForceCond = NotForced;
210
211 if((previousTimeStep <= 0.0) ||
212 (fpState->theNumberOfInteractionLengthLeft <= 0.0))
213 {
215 }
216 else if(previousTimeStep > 0.0)
217 {
219 }
220
221 fpState->currentInteractionLength = 1 / (rSelectedIter->second.second);
222 G4double value = DBL_MAX;
223 if(fpState->currentInteractionLength < DBL_MAX)
224 {
225 value = fpState->theNumberOfInteractionLengthLeft *
226 (fpState->currentInteractionLength);
227 }
228#ifdef G4VERBOSE
229 if(verboseLevel > 2)
230 {
231 G4cout << "Material : " << fpMaterialConf->GetName()
232 << " ID: " << track.GetTrackID()
233 << " Track Time : " << track.GetGlobalTime()
234 << " name : " << molConf->GetName()
235 << " Track Position : " << track.GetPosition()
236 << " Returned time : " << G4BestUnit(value, "Time") << G4endl;
237 }
238#endif
239
240 if(value < fReturnedValue)
241 {
242 fReturnedValue = value;
243 }
244
245 return value * -1;
246 // multiple by -1 to indicate to the tracking system that we are returning a
247 // time
248}
249
251 const G4Step& /*step*/)
252{
253 G4Molecule* molecule = GetMolecule(track);
254 auto molConf = molecule->GetMolecularConfiguration();
255 std::vector<G4Track*> products;
256#ifdef G4VERBOSE
257 if(verboseLevel > 1)
258 {
259 G4cout << ">>> Beginning of G4DNAScavengerProcess verbose>>> Returned value : " << G4BestUnit(fReturnedValue, "Time")
260 <<"molecule: "<<molConf->GetName()<<G4endl;
261 G4cout<<" selected Mat : "<<fpMaterialConf->GetName()<< G4endl;
262 }
263#endif
264
265 G4double reactionTime = track.GetGlobalTime();
266 auto data = fConfMap[molConf][fpMaterialConf];
267
268 if(data == nullptr)
269 {
270 G4ExceptionDescription exceptionDescription;
271 exceptionDescription
272 << "No reaction data for scavenger reaction between : "<<fpMaterialConf->GetName()
273 <<" + "<<molConf->GetName()<<G4endl;
274 G4Exception("G4DNAScavengerProcess::PostStepDoIt",
275 "G4DNAScavengerProcess0001111", FatalErrorInArgument,
276 exceptionDescription);
277 }
278
279 fpScavengerMaterial->SetEquilibrium(data, track.GetGlobalTime());
280
281 auto nbSecondaries = data->GetNbProducts();
282
283 for(G4int j = 0; j < nbSecondaries; ++j)
284 {
285 auto product = data->GetProduct(j);
286 auto isScavenger = fpScavengerMaterial->find(product);
287 if(isScavenger){
289 AddNumberMoleculePerVolumeUnitForMaterialConf(product,track.GetGlobalTime());
290 continue;
291 }
292 auto pProduct = new G4Molecule(data->GetProduct(j));
293 auto pProductTrack =
294 pProduct->BuildTrack(reactionTime, track.GetPosition());
295 pProductTrack->SetTrackStatus(fAlive);
296 G4ITTrackHolder::Instance()->Push(pProductTrack);
297 if(!G4ChemicalMoleculeFinder::Instance()->IsOctreeUsed()){
298 G4MoleculeFinder::Instance()->Push(pProductTrack);
299 }
300 products.push_back(pProductTrack);
301 }
302
303#ifdef G4VERBOSE
304 if(verboseLevel != 0)
305 {
306 G4cout << "At time : " << std::setw(7) << G4BestUnit(reactionTime, "Time")
307 << " Reaction : " << GetIT(track)->GetName() << " ("
308 << track.GetTrackID() << ") + " << fpMaterialConf->GetName() << " ("
309 << "B"
310 << ") -> ";
311 }
312#endif
313 if(nbSecondaries > 0)
314 {
315 for(G4int i = 0; i < nbSecondaries; ++i)
316 {
317#ifdef G4VERBOSE
318 if((verboseLevel != 0) && i != 0)
319 {
320 G4cout << " + ";
321 }
322
323 if(verboseLevel != 0)
324 {
325 auto product = data->GetProduct(i);
326 auto isScavenger = fpScavengerMaterial->find(product);
327 if(isScavenger)
328 {
329 G4cout<<product->GetName()<<" (B)";
330 }
331 else
332 {
333 auto trackSize = products.size();
334 if(trackSize > 0)
335 {
336 for(G4int it = 0; it < (G4int)trackSize; ++it)
337 {
338 if((verboseLevel != 0) && it != 0)
339 {
340 G4cout << " + ";
341 }
342 G4cout << GetIT(products.at(it))->GetName() << " ("
343 << products.at(it)->GetTrackID() << ")";
344 }
345 }
346 }
347 }
348#endif
349 }
350 }
351 else
352 {
353#ifdef G4VERBOSE
354 if(verboseLevel != 0)
355 {
356 G4cout << "No product";
357 }
358#endif
359 }
360#ifdef G4VERBOSE
361 if(verboseLevel != 0)
362 {
363 G4cout << G4endl;
364 }
365#endif
366
368 fParticleChange.Initialize(track);
369 fParticleChange.ProposeTrackStatus(fStopAndKill);
370 fpScavengerMaterial->ReduceNumberMoleculePerVolumeUnitForMaterialConf(
371 fpMaterialConf, reactionTime);
372 State(fPreviousTimeAtPreStepPoint) = -1;
373
375 || fpMaterialConf == fH2O
376 || fpMaterialConf == fHOm) { // these scavengers are not changed
378 }
379
380 return &fParticleChange;
381}
@ FatalErrorInArgument
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4ForceCondition
@ NotForced
#define State(X)
G4IT * GetIT(const G4Track *track)
Definition G4IT.cc:48
G4Molecule * GetMolecule(const G4Track &track)
Definition G4Molecule.cc:75
G4ProcessType
#define G4BestUnit(a, b)
@ fAlive
@ fStopAndKill
double G4double
Definition G4Types.hh:83
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
#define G4UniformRand()
Definition Randomize.hh:52
G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &) override
const G4MolecularConfiguration * MolType
void StartTracking(G4Track *) override
std::map< MolType, std::map< MolType, Data * > > fConfMap
const G4DNABoundingBox * fpBoundingBox
const G4MolecularConfiguration * fpMolecularConfiguration
G4DNAScavengerProcess(const G4String &aName, const G4DNABoundingBox &box, G4ProcessType type=fUserDefined)
G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition) override
G4DNAScavengerMaterial * fpScavengerMaterial
void BuildPhysicsTable(const G4ParticleDefinition &) override
void SetReaction(MolType, Data *pData)
const G4DNAMolecularReactionData Data
void Push(G4Track *track) override
static G4ITFinder * Instance()
void Push(G4Track *) override
static G4ITTrackHolder * Instance()
virtual const G4String & GetName() const =0
const G4String & GetName() const
const G4MolecularConfiguration * GetMolecularConfiguration() const
static G4OctreeFinder * Instance()
void SetInteractionStep(G4bool InteractionStep)
static G4Scheduler * Instance()
G4VScavengerMaterial * GetScavengerMaterial() const
G4int GetTrackID() const
const G4ThreeVector & GetPosition() const
G4double GetGlobalTime() const
void SetInstantiateProcessState(G4bool flag)
virtual void SubtractNumberOfInteractionLengthLeft(G4double previousStepSize)
G4shared_ptr< G4ProcessState > fpState
void StartTracking(G4Track *) override
G4VITProcess(const G4String &name, G4ProcessType type=fNotDefined)
G4bool fProposesTimeStep
void ResetNumberOfInteractionLengthLeft() override
G4bool enableAtRestDoIt
G4int verboseLevel
G4bool enableAlongStepDoIt
void SetProcessSubType(G4int)
virtual void StartTracking(G4Track *)
Definition G4VProcess.cc:87
G4bool enablePostStepDoIt
G4VParticleChange * pParticleChange
#define DBL_MAX
Definition templates.hh:62