53fpReactionModel(nullptr),
72 xiniIndex = 0, yiniIndex = 0, ziniIndex = 0;
73 xendIndex = 0, yendIndex = 0, zendIndex = 0;
76 1.45 * nm + 2 * std::sqrt(8*9.46e9*nm*nm/s * timeMax);
129 if(fReactionSet->
Empty())
155 fNx =
G4int((fXMax-fXMin)/fRCutOff) == 0 ? 1 :
G4int((fXMax-fXMin)/fRCutOff);
156 fNy =
G4int((fYMax-fYMin)/fRCutOff) == 0 ? 1 :
G4int((fYMax-fYMin)/fRCutOff);
157 fNz =
G4int((fZMax-fZMin)/fRCutOff) == 0 ? 1 :
G4int((fZMax-fZMin)/fRCutOff);
165 G4int I =
FindBin(fNx, fXMin, fXMax, it_begin->GetPosition().x());
166 G4int J =
FindBin(fNy, fYMin, fYMax, it_begin->GetPosition().y());
167 G4int K =
FindBin(fNz, fZMin, fZMax, it_begin->GetPosition().z());
169 spaceBinned[I][J][K].push_back(*it_begin);
181 const vector<const G4MolecularConfiguration*>* reactivesVector =
184 if(reactivesVector ==
nullptr)
return;
196 for (
int ii = xiniIndex; ii <= xendIndex; ii++ ) {
197 for (
int jj = yiniIndex; jj <= yendIndex; jj++ ) {
198 for (
int kk = ziniIndex; kk <= zendIndex; kk++ ) {
200 std::vector<G4Track*> spaceBin = spaceBinned[ii][jj][kk];
201 for (
int n = 0; n < (int)spaceBinned[ii][jj][kk].size(); n++ ) {
202 if(!spaceBin[n] || track == spaceBin[n])
continue;
211 auto it = std::find(reactivesVector->begin(), reactivesVector->end(), molConfB);
212 if(it == reactivesVector->end())
continue;
222 sigma = std::sqrt(2.0 * diffusionCoefficient * dt);
224 x = G4RandGauss::shoot(0., 1.0)*sigma;
225 y = G4RandGauss::shoot(0., 1.0)*sigma;
226 z = G4RandGauss::shoot(0., 1.0)*sigma;
229 }
else if(dt < 0)
continue;
235 if(irt>=0 && irt<timeMax - globalTime)
238 if(irt < minTime) minTime = irt;
261 for(
size_t u=0; u<fReactionDatas->size();u++){
262 if((*fReactionDatas)[u]->GetReactant2()->GetDiffusionCoefficient() == 0){
263 G4double kObs = (*fReactionDatas)[u]->GetObservedReactionRateConstant();
264 if(kObs == 0)
continue;
266 if( time < minTime && time >= globalTime && time < timeMax){
275 G4cout<<
"scavenged: "<<minTime<<
'\t'<<molConfA->
GetName()<<it_begin->GetTrackID()<<
'\n';
279 fTrackHolder->
Push(fakeTrack);
280 fReactionSet->
AddReaction(minTime, track, fakeTrack);
286 const auto pMoleculeA = molA;
287 const auto pMoleculeB = molB;
291 if(r0 == 0) r0 += 1e-3*nm;
295 if(
D == 0)
D += 1e-20*(m2/s);
296 G4double rc = fReactionData->GetOnsagerRadius();
298 if ( reactionType == 0){
299 G4double sigma = fReactionData->GetEffectiveReactionRadius();
301 if(sigma > r0)
return 0;
302 if( rc != 0) r0 = -rc / (1-std::exp(rc/r0));
307 if (
W > 0 &&
W < Winf ) irt = (0.25/
D) * std::pow( (r0-sigma)/erfc->
erfcInv(r0*
W/sigma), 2 );
311 else if ( reactionType == 1 ){
312 G4double sigma = fReactionData->GetReactionRadius();
313 G4double kact = fReactionData->GetActivationRateConstant();
314 G4double kdif = fReactionData->GetDiffusionRateConstant();
315 G4double kobs = fReactionData->GetObservedReactionRateConstant();
320 a = 1/sigma * kact / kobs;
321 b = (r0 - sigma) / 2;
323 G4double v = kact/Avogadro/(4*CLHEP::pi*pow(sigma,2) * exp(-rc / sigma));
324 G4double alpha = v+rc*
D/(pow(sigma,2)*(1-exp(-rc/sigma)));
325 a = 4*pow(sigma,2)*alpha/(
D*pow(rc,2))*pow(sinh(rc/(2*sigma)),2);
326 b = rc/4*(cosh(rc/(2*r0))/sinh(rc/(2*r0))-cosh(rc/(2*sigma))/sinh(rc/(2*sigma)));
327 r0 = -rc/(1-std::exp(rc/r0));
328 sigma = fReactionData->GetEffectiveReactionRadius();
332 if(fReactionData->GetProbability() >
G4UniformRand())
return 0;
335 Winf = sigma / r0 * kobs / kdif;
349 else if ( value >= xmax)
352 bin =
G4int( n * ( value - xmin )/( xmax - xmin ) );
354 if ( bin < 0 ) bin = 0;
355 if ( bin >= n ) bin = n-1;
362 G4double p = 2.0 * std::sqrt(2.0*b/a);
363 G4double q = 2.0 / std::sqrt(2.0*b/a);
373 if ( U < p/(p + q *
M) ) X = pow(U * (p + q *
M) / 2, 2);
374 else X = pow(2/((1-U)*(p+q*
M)/
M),2);
378 lambdax = std::exp(-b*b/X) * ( 1.0 - a * std::sqrt(CLHEP::pi * X) * erfc->
erfcx(b/std::sqrt(X) + a*std::sqrt(X)));
380 if ((X <= 2.0*b/a && U <= lambdax) ||
381 (X >= 2.0*b/a && U*
M/X <= lambdax))
break;
385 if ( ntrials > 10000 ){
386 G4cout<<
"Totally rejected"<<
'\n';
398 pChanges->Initialize(trackA, trackB);
405 G4double effectiveReactionRadius = pReactionData->GetEffectiveReactionRadius();
407 const G4double D1 = pMoleculeA->GetDiffusionCoefficient();
408 const G4double D2 = pMoleculeB->GetDiffusionCoefficient();
419 S1.
setMag(effectiveReactionRadius);
423 if(dt != 0 && (D1 + D2) != 0 && r0 != 0){
426 if(s12 == 0) r2 = r1;
427 else if(s22 == 0) r1 = r2;
429 G4double alpha = effectiveReactionRadius * r0 / (2*(D1 + D2)*dt);
431 G4RandGauss::shoot(0, s12 + s22 * s22 / s12),
432 G4RandGauss::shoot(0, s12 + s22 * s22 / s12));
438 S1.
setTheta(rad * std::acos(1.0 + 1./alpha * std::log(1.0 -
G4UniformRand() * (1 - std::exp(-2.0 * alpha)))));
440 r1 = (D1 * S1 + D2 * S2) / (D1 + D2);
441 r2 = D2 * (S2 - S1) / (D1 + D2);
445 auto pTrackA =
const_cast<G4Track*
>(pChanges->GetTrackA());
446 auto pTrackB =
const_cast<G4Track*
>(pChanges->GetTrackB());
449 pTrackB->SetPosition(r2);
451 pTrackA->SetGlobalTime(globalTime);
452 pTrackB->SetGlobalTime(globalTime);
457 const G4int nbProducts = pReactionData->GetNbProducts();
461 const G4double sqrD1 = D1 == 0. ? 0. : std::sqrt(D1);
462 const G4double sqrD2 = D2 == 0. ? 0. : std::sqrt(D2);
463 if((sqrD1 + sqrD2) == 0){
466 const G4double inv_numerator = 1./(sqrD1 + sqrD2);
470 std::vector<G4ThreeVector>
position;
474 }
else if(nbProducts == 2){
477 }
else if (nbProducts == 3){
483 for(
G4int u = 0; u < nbProducts; u++){
485 auto product =
new G4Molecule(pReactionData->GetProduct(u));
486 auto productTrack = product->BuildTrack(globalTime,
489 productTrack->SetTrackStatus(
fAlive);
490 fTrackHolder->
Push(productTrack);
492 pChanges->AddSecondary(productTrack);
498 spaceBinned[I][J][K].push_back(productTrack);
505 pChanges->KillParents(
true);
516 std::vector<std::unique_ptr<G4ITReactionChange>> fReactionInfo;
517 fReactionInfo.clear();
519 if (pReactionSet ==
nullptr)
521 return fReactionInfo;
525 assert(fReactionsetInTime.begin() != fReactionsetInTime.end());
527 auto it_begin = fReactionsetInTime.begin();
528 while(it_begin != fReactionsetInTime.end())
530 G4double irt = it_begin->get()->GetTime();
532 if(fGlobalTime < irt)
break;
536 G4Track* pTrackA = it_begin->get()->GetReactants().first;
537 G4Track* pTrackB = it_begin->get()->GetReactants().second;
538 auto pReactionChange =
MakeReaction(*pTrackA, *pTrackB);
541 fReactionInfo.push_back(std::move(pReactionChange));
545 it_begin = fReactionsetInTime.begin();
548 return fReactionInfo;
G4double D(G4double temp)
G4Molecule * GetMolecule(const G4Track &track)
ReturnType & reference_cast(OriginalType &source)
CLHEP::Hep3Vector G4ThreeVector
G4GLOB_DLL std::ostream G4cout
void SetReactionModel(G4VDNAReactionModel *)
G4bool TestReactibility(const G4Track &, const G4Track &, G4double, G4bool) override
G4double SamplePDC(G4double, G4double)
const G4DNAMolecularReactionTable *& fMolReactionTable
void Initialize() override
G4int FindBin(G4int, G4double, G4double, G4double)
G4double GetIndependentReactionTime(const G4MolecularConfiguration *, const G4MolecularConfiguration *, G4double)
std::vector< std::unique_ptr< G4ITReactionChange > > FindReaction(G4ITReactionSet *, const G4double, const G4double, const G4bool) override
std::unique_ptr< G4ITReactionChange > MakeReaction(const G4Track &, const G4Track &) override
G4VDNAReactionModel * fpReactionModel
G4int GetReactionType() const
Data * GetReactionData(Reactant *, Reactant *) const
const ReactantList * CanReactWith(Reactant *) const
static G4double erfcx(G4double x)
static G4double erfcInv(G4double x)
void AddReaction(G4double time, G4Track *trackA, G4Track *trackB)
static G4ITReactionSet * Instance()
void SelectThisReaction(G4ITReactionPtr reaction)
G4ITReactionPerTime & GetReactionsPerTime()
G4TrackList * GetMainList(Key)
virtual void Push(G4Track *)
void MergeSecondariesWithMainList()
static G4ITTrackHolder * Instance()
const G4String & GetName() const
G4double GetDiffusionCoefficient() const
static G4Molecule * GetMolecule(const G4Track *)
const G4MolecularConfiguration * GetMolecularConfiguration() const
G4Track * BuildTrack(G4double globalTime, const G4ThreeVector &Position)
G4double GetDiffusionCoefficient() const
static G4Scheduler * Instance()
G4double GetEndTime() const
G4double GetGlobalTime() const
G4double GetStartTime() const
void SetPosition(const G4ThreeVector &aValue)
const G4ThreeVector & GetPosition() const
G4double GetGlobalTime() const