Import Geant4 11.4.0.beta source tree
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
//
|
||||
// Created by ngoc hoang tran on 03/08/2023.
|
||||
//
|
||||
|
||||
#ifndef G4ChemEquilibrium_hh
|
||||
#define G4ChemEquilibrium_hh 1
|
||||
#include "globals.hh"
|
||||
#include "G4MoleculeTable.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
|
||||
class G4DNAMolecularReactionData;
|
||||
class G4ChemEquilibrium //for each Equilibrium process
|
||||
{
|
||||
public:
|
||||
using MolType = const G4MolecularConfiguration*;
|
||||
using Reaction = const G4DNAMolecularReactionData*;
|
||||
explicit G4ChemEquilibrium(const G4int& type, const G4double& time);
|
||||
~G4ChemEquilibrium() = default;
|
||||
void Initialize();
|
||||
inline G4bool IsStatusChanged()
|
||||
{
|
||||
if(fStatus == fAddEquilibrium){
|
||||
return false;
|
||||
}else
|
||||
{
|
||||
fStatus = fAddEquilibrium;
|
||||
if(fVerbose > 0)
|
||||
{
|
||||
PrintInfo();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
inline void Reset()
|
||||
{
|
||||
fStatus = false;
|
||||
fAddEquilibrium = false;
|
||||
fEquilibriumTime = 0;
|
||||
fGlobalTime = 0;
|
||||
}
|
||||
|
||||
inline void SetVerbose(const G4int& verbose)
|
||||
{
|
||||
fVerbose = verbose;
|
||||
}
|
||||
|
||||
inline void SetGlobalTime(const G4double& time)
|
||||
{
|
||||
fGlobalTime = time;
|
||||
|
||||
if(fGlobalTime - fEquilibriumTime > fEquilibriumDuration && fAddEquilibrium)
|
||||
{
|
||||
fAddEquilibrium = false;
|
||||
if(fVerbose) {
|
||||
G4cout << "SetEquilibrium : off " << fRectionType
|
||||
<< " fGlobalTime : " << G4BestUnit(fGlobalTime, "Time")
|
||||
<< " fEquilibriumTime8 : " << G4BestUnit(fEquilibriumTime, "Time")
|
||||
<< " fAddEquilibrium : " << fAddEquilibrium << G4endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
void SetEquilibrium(Reaction pReaction);
|
||||
|
||||
inline G4bool GetEquilibriumStatus() const
|
||||
{
|
||||
return fAddEquilibrium;
|
||||
}
|
||||
|
||||
void PrintInfo() const;
|
||||
private:
|
||||
G4bool fStatus = false;
|
||||
G4bool fAddEquilibrium = false;
|
||||
G4double fEquilibriumTime = 0;
|
||||
const G4double fEquilibriumDuration = 0;
|
||||
G4int fRectionType = 0;
|
||||
MolType fReactant1 = nullptr;
|
||||
MolType fReactant2 = nullptr;
|
||||
MolType fReactantB1 = nullptr;
|
||||
MolType fReactantB2 = nullptr;
|
||||
G4double fGlobalTime = 0;
|
||||
G4int fVerbose = 1;
|
||||
};
|
||||
|
||||
#endif //
|
||||
@@ -53,7 +53,10 @@
|
||||
#include "G4UImessenger.hh"
|
||||
#include "G4VStateDependent.hh"
|
||||
|
||||
#include "G4MoleculeCounterManager.hh"
|
||||
|
||||
class G4Track;
|
||||
class G4Run;
|
||||
class G4DNAWaterExcitationStructure;
|
||||
class G4DNAWaterIonisationStructure;
|
||||
class G4Molecule;
|
||||
@@ -150,9 +153,6 @@ public:
|
||||
* in standalone.
|
||||
*/
|
||||
void UseAsStandalone(G4bool flag);
|
||||
G4bool IsCounterResetWhenRunEnds() const;
|
||||
|
||||
void ResetCounterWhenRunEnds(G4bool resetCounterWhenRunEnds);
|
||||
|
||||
void ForceMasterReinitialization();
|
||||
void TagThreadForReinitialization();
|
||||
@@ -199,8 +199,17 @@ public:
|
||||
|
||||
void PushMolecule(std::unique_ptr<G4Molecule> pMolecule,
|
||||
G4double time,
|
||||
const G4ThreeVector& position,
|
||||
G4int parentID);
|
||||
const G4ThreeVector &position,
|
||||
G4int parentID,
|
||||
const G4Track *parentTrack = nullptr);
|
||||
|
||||
//============================================================================
|
||||
// Methods called by RunManagers to notify of Runs & Events
|
||||
//============================================================================
|
||||
void BeginOfEventAction(const G4Event*);
|
||||
void BeginOfRunAction(const G4Run*);
|
||||
void EndOfEventAction(const G4Event*);
|
||||
void EndOfRunAction(const G4Run*);
|
||||
|
||||
protected:
|
||||
void HandleStandaloneInitialization();
|
||||
@@ -251,5 +260,4 @@ private:
|
||||
G4bool fGeometryClosed{false};
|
||||
|
||||
G4int fVerbose{0};
|
||||
G4bool fResetCounterWhenRunEnds{true};
|
||||
};
|
||||
|
||||
@@ -53,6 +53,7 @@ class G4DNAMesh : public G4VDNAMesh
|
||||
Voxel& GetVoxel(const Index& index); // GetorCreateVoxel
|
||||
size_t size() { return fVoxelVector.size(); };
|
||||
Index ConvertIndex(const Index& index, const G4int&) const;
|
||||
Index GetRandomIndex(const Index&, const G4double& resolution) const;
|
||||
std::vector<Index> FindNeighboringVoxels(const Index& index) const;
|
||||
void Reset();
|
||||
Data& GetVoxelMapList(const Index& index);
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Created 25.03.2025 V.Ivanchenko
|
||||
// on base of codes of S.Incerti & M.Karamitros
|
||||
//
|
||||
// Double differential cross section data structure
|
||||
//
|
||||
|
||||
#ifndef G4DNASamplingTable_HH
|
||||
#define G4DNASamplingTable_HH 1
|
||||
|
||||
#include "globals.hh"
|
||||
#include <vector>
|
||||
|
||||
class G4DNASamplingTable
|
||||
{
|
||||
public:
|
||||
explicit G4DNASamplingTable(std::size_t npoint);
|
||||
~G4DNASamplingTable();
|
||||
|
||||
void LoadData(const G4String& filename, G4double factorE, G4double scaleFactor,
|
||||
G4bool verbose);
|
||||
|
||||
G4double GetValue(G4double ekinPrimary, G4double ekinSecondary, G4int shell) const;
|
||||
|
||||
G4double SampleCumulative(G4double ekinPrimary, G4int shell) const;
|
||||
|
||||
G4DNASamplingTable(const G4DNASamplingTable & copy) = delete;
|
||||
G4DNASamplingTable& operator=(const G4DNASamplingTable& right) = delete;
|
||||
|
||||
private:
|
||||
|
||||
G4int GetIndex(const std::vector<G4double>&, G4double x) const;
|
||||
|
||||
G4double VecInterpolation(const std::vector<G4double>* ener,
|
||||
const std::vector<G4double>* val, G4double energy) const;
|
||||
|
||||
G4double Interpolate(G4double e1, G4double e2, G4double e,
|
||||
G4double xs1, G4double xs2) const;
|
||||
|
||||
G4int fNpoints{0};
|
||||
std::vector<G4double> fPrimaryEnergy;
|
||||
std::vector<std::vector<G4double>* > fSecEnergy;
|
||||
std::vector<std::vector<G4double>* > fPDF[5];
|
||||
|
||||
};
|
||||
#endif
|
||||
@@ -30,9 +30,10 @@
|
||||
#include "G4ios.hh"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include "G4MoleculeCounter.hh"
|
||||
#include "G4VMoleculeCounterInternalBase.hh"
|
||||
#include "G4VScavengerMaterial.hh"
|
||||
#include "G4MoleculeTable.hh"
|
||||
#include "G4ChemEquilibrium.hh"
|
||||
|
||||
class G4Material;
|
||||
class G4MolecularConfiguration;
|
||||
@@ -42,7 +43,7 @@ class G4DNAScavengerMaterial : public G4VScavengerMaterial
|
||||
{
|
||||
public:
|
||||
using NbMoleculeInTime =
|
||||
std::map<G4double, int64_t, G4::MoleculeCounter::TimePrecision>;
|
||||
std::map<G4double, int64_t, G4::MoleculeCounter::FixedTimeComparer>;
|
||||
using MolType = const G4MolecularConfiguration*;
|
||||
using MaterialMap = std::map<MolType, int64_t>;
|
||||
using ReactantList = std::vector<MolType>;
|
||||
@@ -80,9 +81,7 @@ class G4DNAScavengerMaterial : public G4VScavengerMaterial
|
||||
{
|
||||
return it->second > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
void SetCounterAgainstTime() { fCounterAgainstTime = true; }
|
||||
@@ -103,9 +102,13 @@ class G4DNAScavengerMaterial : public G4VScavengerMaterial
|
||||
int64_t GetNMoleculesAtTime(MolType molecule, G4double time);
|
||||
G4bool SearchTimeMap(MolType molecule);
|
||||
int64_t SearchUpperBoundTime(G4double time, G4bool sameTypeOfMolecule);
|
||||
void ResetEquilibrium();
|
||||
G4bool SetEquilibrium(const G4DNAMolecularReactionData* pReaction,
|
||||
G4double time);
|
||||
G4bool IsEquilibrium(const G4int& reactionType) const;
|
||||
|
||||
private:
|
||||
G4VChemistryWorld* fpChemistryInfo;
|
||||
private:
|
||||
G4VChemistryWorld* fpChemistryInfo = nullptr;
|
||||
G4bool fIsInitialized;
|
||||
MaterialMap fScavengerTable;
|
||||
CounterMapType fCounterMap;
|
||||
@@ -125,5 +128,6 @@ class G4DNAScavengerMaterial : public G4VScavengerMaterial
|
||||
std::unique_ptr<Search> fpLastSearch;
|
||||
void WaterEquilibrium();
|
||||
|
||||
std::map<G4int,std::unique_ptr<G4ChemEquilibrium>> fEquilibriumProcesses;
|
||||
};
|
||||
#endif // G4DNASCAVENGERMATERIAL_HH
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// Author: Christian Velten (2025)
|
||||
|
||||
#ifndef G4MoleculeReactionCounter_hh
|
||||
#define G4MoleculeReactionCounter_hh 1
|
||||
|
||||
#include "G4DNAMolecularReactionTable.hh"
|
||||
#include "G4VUserMoleculeReactionCounter.hh"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
struct G4MoleculeReactionCounterIndex : public G4VMoleculeReactionCounter::G4VMoleculeReactionCounterIndex
|
||||
{
|
||||
const G4DNAMolecularReactionData* ReactionData;
|
||||
|
||||
G4MoleculeReactionCounterIndex() : ReactionData(nullptr) {}
|
||||
explicit G4MoleculeReactionCounterIndex(const G4DNAMolecularReactionData* reaction) : ReactionData(reaction) {}
|
||||
~G4MoleculeReactionCounterIndex() override = default;
|
||||
|
||||
G4bool operator<(G4VMoleculeReactionCounterIndex const& other) const override
|
||||
{
|
||||
return std::less{}(ReactionData, static_cast<const G4MoleculeReactionCounterIndex&>(other).ReactionData);
|
||||
}
|
||||
G4bool operator==(G4VMoleculeReactionCounterIndex const& other) const override
|
||||
{
|
||||
return std::equal_to{}(ReactionData, static_cast<const G4MoleculeReactionCounterIndex&>(other).ReactionData);
|
||||
}
|
||||
G4String FormattedReactionString(const G4DNAMolecularReactionData* reactionData) const;
|
||||
|
||||
G4String GetInfo() const override
|
||||
{
|
||||
G4String null = "This reaction data is null";
|
||||
if (ReactionData == nullptr)
|
||||
return null;
|
||||
else
|
||||
return FormattedReactionString(ReactionData);
|
||||
}
|
||||
const G4DNAMolecularReactionData* GetReactionData() const override { return ReactionData; }
|
||||
};
|
||||
|
||||
class G4MoleculeReactionCounter : public G4VUserMoleculeReactionCounter<G4MoleculeReactionCounterIndex>
|
||||
{
|
||||
//----------------------------------------------------------------------------
|
||||
public:
|
||||
G4MoleculeReactionCounter();
|
||||
G4MoleculeReactionCounter(G4String);
|
||||
~G4MoleculeReactionCounter() override = default;
|
||||
|
||||
void InitializeUser() override;
|
||||
|
||||
public:
|
||||
std::unique_ptr<G4VMoleculeReactionCounterIndex> BuildSimpleIndex(const G4DNAMolecularReactionData*) const override;
|
||||
};
|
||||
|
||||
#endif // G4MoleculeReactionCounter_hh
|
||||
@@ -97,64 +97,6 @@ protected:
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
class G4Analysis: public G4VPhysChemIO
|
||||
{
|
||||
public:
|
||||
G4Analysis(G4VAnalysisManager*);
|
||||
~G4Analysis() override;
|
||||
|
||||
void InitializeMaster() override{}
|
||||
void InitializeThread() override{}
|
||||
void InitializeFile() override;
|
||||
|
||||
void NewRun() override{}
|
||||
void NewEvent() override{}
|
||||
|
||||
/**
|
||||
* Method used by DNA physics model to create a water molecule.
|
||||
* The ElectronicModification is a flag telling wheter the molecule
|
||||
* is ionized or excited, the electronic level is calculated by the
|
||||
* model and the IncomingTrack is the track responsible for the creation
|
||||
* of this molecule, for instance an electron.
|
||||
*/
|
||||
void CreateWaterMolecule(G4int electronicModif,
|
||||
G4int /*electronicLevel*/,
|
||||
G4double energy,
|
||||
const G4Track* /*theIncomingTrack*/) override;
|
||||
|
||||
/**
|
||||
* Same idea as the previous method but for solvated electron.
|
||||
* This method should be used by the physics model of the ElectronSolvatation
|
||||
* process.
|
||||
*/
|
||||
void CreateSolvatedElectron(const G4Track* /*theIncomingTrack*/,
|
||||
G4ThreeVector* finalPosition = nullptr) override;
|
||||
|
||||
//============================================================================
|
||||
// FILE OPERATIONS
|
||||
//============================================================================
|
||||
|
||||
/**
|
||||
* Tells the chemMan to write into a file
|
||||
* the position and electronic state of the water molecule
|
||||
* and the position thermalized or not of the solvated electron
|
||||
*/
|
||||
void WriteInto(const G4String&, std::ios_base::openmode mode =
|
||||
std::ios_base::out) override;
|
||||
void AddEmptyLineInOutputFile() override{}
|
||||
|
||||
/**
|
||||
* Close the file specified with WriteInto
|
||||
*/
|
||||
void CloseFile() override;
|
||||
|
||||
protected:
|
||||
G4VAnalysisManager* fpAnalysisManager;
|
||||
int fNtupleID;
|
||||
G4bool fFileInitialized;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // G4PHYSCHEMIO_HH_
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include "globals.hh"
|
||||
class G4DNABoundingBox;
|
||||
class G4Material;
|
||||
class G4MolecularConfiguration;
|
||||
@@ -72,9 +73,14 @@ class G4VChemistryWorld
|
||||
{
|
||||
return fpChemistryBoundary.get();
|
||||
}
|
||||
|
||||
std::map<MolType,G4double> GetChemicalComponent() const
|
||||
{
|
||||
return fpChemicalComponent;
|
||||
}
|
||||
protected:
|
||||
std::unique_ptr<G4DNABoundingBox> fpChemistryBoundary;
|
||||
std::map<MolType,double> fpChemicalComponent;
|
||||
std::map<MolType,G4double> fpChemicalComponent;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,437 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Author: Christian Velten (2025)
|
||||
|
||||
#ifndef G4VUSERMOLECULEREACTIONCOUNTER_HH
|
||||
#define G4VUSERMOLECULEREACTIONCOUNTER_HH 1
|
||||
|
||||
#include "G4DNAChemistryManager.hh"
|
||||
#include "G4MoleculeCounterTemplates.hh"
|
||||
#include "G4Scheduler.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4VMoleculeReactionCounter.hh"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<class TIndex>
|
||||
class G4VUserMoleculeReactionCounter : public G4VMoleculeReactionCounter
|
||||
{
|
||||
static_assert(std::is_base_of<G4VMoleculeReactionCounter::G4VMoleculeReactionCounterIndex, TIndex>::value,
|
||||
"TIndex must be derived from G4VMoleculeReactionCounter::G4VMoleculeReactionCounterIndex! "
|
||||
"No forward declaration is allowed.");
|
||||
|
||||
protected:
|
||||
struct Search;
|
||||
|
||||
public:
|
||||
G4VUserMoleculeReactionCounter();
|
||||
G4VUserMoleculeReactionCounter(const G4String&,
|
||||
MoleculeReactionCounterType = MoleculeReactionCounterType::Basic);
|
||||
~G4VUserMoleculeReactionCounter() override = default;
|
||||
|
||||
public:
|
||||
void Initialize() final;
|
||||
void InitializeUser() override = 0;
|
||||
void ResetCounter() override;
|
||||
void Dump() const override;
|
||||
void DumpCounterMapIndices() const override;
|
||||
|
||||
void AbsorbCounter(const G4VMoleculeCounterInternalBase*) override;
|
||||
|
||||
std::unique_ptr<G4VMoleculeReactionCounterIndex> BuildSimpleIndex(const G4DNAMolecularReactionData*) const override = 0;
|
||||
|
||||
void RecordReaction(std::unique_ptr<G4VMoleculeReactionCounterIndex>, G4double, G4int = 1) override;
|
||||
|
||||
std::set<const G4DNAMolecularReactionData*> GetRecordedReactions() const override;
|
||||
std::set<G4double> GetRecordedTimes() const override;
|
||||
|
||||
protected:
|
||||
std::map<TIndex, InnerCounterMapType> fCounterMap{};
|
||||
|
||||
public:
|
||||
const std::map<TIndex, InnerCounterMapType>& GetCounterMap() const { return fCounterMap; }
|
||||
std::vector<TIndex> GetMapIndices() const;
|
||||
|
||||
virtual G4int GetNbReactionsAtTime(const TIndex&, G4double) const;
|
||||
virtual G4int GetNbReactionsAtTime(Search&, const TIndex&, G4double) const;
|
||||
virtual std::vector<G4int> GetNbReactionsAtTimes(const TIndex&,
|
||||
const std::vector<G4double>&) const;
|
||||
|
||||
//-SEARCH-----------------------------------------------------------------------
|
||||
protected:
|
||||
struct Search
|
||||
{
|
||||
Search() : fLowerBoundSet(false) {}
|
||||
typename std::map<TIndex, InnerCounterMapType>::const_iterator fLastIndexSearched;
|
||||
InnerCounterMapType::const_iterator fLowerBoundTime;
|
||||
G4bool fLowerBoundSet;
|
||||
};
|
||||
G4bool SearchIndexUpdated(Search&, const TIndex&) const;
|
||||
G4int SearchUpperBoundTime(Search&, G4double, G4bool) const;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// #include "G4VUserMoleculeReactionCounter.icc"
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
G4VUserMoleculeReactionCounter<T>::G4VUserMoleculeReactionCounter() : G4VMoleculeReactionCounter()
|
||||
{}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
G4VUserMoleculeReactionCounter<T>::G4VUserMoleculeReactionCounter(const G4String& name,
|
||||
MoleculeReactionCounterType type)
|
||||
: G4VMoleculeReactionCounter(name, type)
|
||||
{}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename TIndex>
|
||||
void G4VUserMoleculeReactionCounter<TIndex>::Initialize()
|
||||
{
|
||||
InitializeUser();
|
||||
fIsInitialized = true;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename TIndex>
|
||||
G4int G4VUserMoleculeReactionCounter<TIndex>::GetNbReactionsAtTime(const TIndex& index, G4double time) const
|
||||
{
|
||||
Search search = {};
|
||||
return GetNbReactionsAtTime(search, index, time);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename TIndex>
|
||||
G4int G4VUserMoleculeReactionCounter<TIndex>::GetNbReactionsAtTime(Search& search,
|
||||
const TIndex& index,
|
||||
G4double time) const
|
||||
{
|
||||
G4bool sameIndex = !SearchIndexUpdated(search, index);
|
||||
return SearchUpperBoundTime(search, time, sameIndex);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename TIndex>
|
||||
std::vector<G4int> G4VUserMoleculeReactionCounter<TIndex>::GetNbReactionsAtTimes(
|
||||
const TIndex& index, const std::vector<G4double>& times) const
|
||||
{
|
||||
Search search = {};
|
||||
std::vector<G4int> counts = {};
|
||||
for (auto time : times)
|
||||
counts.push_back(GetNbReactionsAtTime(search, index, time));
|
||||
return counts;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename TIndex>
|
||||
void G4VUserMoleculeReactionCounter<TIndex>::RecordReaction(
|
||||
std::unique_ptr<G4VMoleculeReactionCounter::G4VMoleculeReactionCounterIndex> pIndex,
|
||||
G4double time, G4int number)
|
||||
{
|
||||
const TIndex* mapIndex = dynamic_cast<TIndex*>(pIndex.get());
|
||||
|
||||
if (IsTimeAboveUpperBound(time)) {
|
||||
if (fVerbose > 3) {
|
||||
G4cout << "G4VUserMoleculeReactionCounter<"
|
||||
<< G4::MoleculeCounter::GetTemplateTypeName<TIndex>() << ">(" << GetName()
|
||||
<< ")::RecordReaction : " << mapIndex->GetReactionData()->GetReactionID()
|
||||
<< " at time : " << G4BestUnit(time, "Time") << G4endl;
|
||||
G4cout << ":: [IsTimeAboveUpperBound] Skipping since IsTimeAboveUpperBound == true" << G4endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else if (IsTimeBelowLowerBound(time)) {
|
||||
if (fVerbose > 3) {
|
||||
G4cout << "G4VUserMoleculeReactionCounter<"
|
||||
<< G4::MoleculeCounter::GetTemplateTypeName<TIndex>() << ">(" << GetName()
|
||||
<< ")::RecordReaction : " << mapIndex->GetReactionData()->GetReactionID()
|
||||
<< " at time : " << G4BestUnit(time, "Time") << G4endl;
|
||||
G4cout << ":: [IsTimeBelowLowerBound] Skipping since IsTimeBelowLowerBound == true" << G4endl;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fVerbose > 2) {
|
||||
G4cout << "G4VUserMoleculeReactionCounter<"
|
||||
<< G4::MoleculeCounter::GetTemplateTypeName<TIndex>() << ">(" << GetName()
|
||||
<< ")::RecordReaction : " << mapIndex->GetReactionData()->GetReactionID()
|
||||
<< " at time : " << G4BestUnit(time, "Time") << G4endl;
|
||||
}
|
||||
|
||||
auto [it, indexIsNew] = fCounterMap.emplace(*mapIndex, InnerCounterMapType{fTimeComparer});
|
||||
|
||||
if (indexIsNew || it->second.empty()) {
|
||||
it->second.emplace(time, number);
|
||||
// it->second[time] = number;
|
||||
}
|
||||
else {
|
||||
if (G4MoleculeCounterManager::Instance()->GetResetCountersBeforeEvent())
|
||||
// can only do consistency check if the counters are cleared before each event
|
||||
{
|
||||
auto end = it->second.rbegin();
|
||||
|
||||
if ((end->first <= time || std::fabs(end->first - time) <= fTimeComparer.GetPrecisionAtTime(time)))
|
||||
// Case 1 = new time comes after last recorded data
|
||||
// Case 2 = new time is about the same as the last recorded one
|
||||
{
|
||||
// it->second[time] = end->second + number;
|
||||
auto [it_time, _] = it->second.emplace(time, end->second);
|
||||
it_time->second += number;
|
||||
}
|
||||
else {
|
||||
G4ExceptionDescription errMsg;
|
||||
errMsg << "Time of reaction " << mapIndex->GetReactionData()->GetReactionID() << " is "
|
||||
<< G4BestUnit(time, "Time") << "while the global time is "
|
||||
<< G4BestUnit(G4Scheduler::Instance()->GetGlobalTime(), "Time")
|
||||
<< "(last counter time: " << G4BestUnit(end->first, "Time") << ")" << G4endl;
|
||||
G4Exception(G4String("G4VUserMoleculeReactionCounter<"
|
||||
+ G4::MoleculeCounter::GetTemplateTypeName<TIndex>()
|
||||
+ ">::RecordReaction"),
|
||||
"TIME_DONT_MATCH", FatalException, errMsg);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// since counters are not cleared after chemical run (i.e., after event)
|
||||
// there will already be numbers in the map, so...
|
||||
// (1) find the closest time
|
||||
// (2) emplace entry using closest value as init + number
|
||||
// (3) add number to all "future" entries as well
|
||||
auto it_closest = G4::MoleculeCounter::FindClosestEntryForKey(it->second, time);
|
||||
auto [it_new, _] = it->second.emplace(time, it_closest->second);
|
||||
do {
|
||||
it_new->second += number;
|
||||
} while (++it_new != it->second.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename TIndex>
|
||||
std::vector<TIndex> G4VUserMoleculeReactionCounter<TIndex>::GetMapIndices() const
|
||||
{
|
||||
if (fVerbose > 2) {
|
||||
G4cout << "Entering in G4VUserMoleculeReactionCounter::GetMapIndices" << G4endl;
|
||||
}
|
||||
return G4::MoleculeCounter::GetMapIndices(fCounterMap);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
std::set<const G4DNAMolecularReactionData*> G4VUserMoleculeReactionCounter<T>::GetRecordedReactions() const
|
||||
{
|
||||
if (fVerbose > 2) {
|
||||
G4cout << "Entering in G4VUserMoleculeReactionCounter::GetRecordedReactions" << G4endl;
|
||||
}
|
||||
std::set<const G4DNAMolecularReactionData*> output{};
|
||||
for (const auto& it : fCounterMap) {
|
||||
output.insert(it.first.GetReactionData());
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
std::set<G4double> G4VUserMoleculeReactionCounter<T>::GetRecordedTimes() const
|
||||
{
|
||||
return G4::MoleculeCounter::GetRecordedTimes<T>(fCounterMap);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
void G4VUserMoleculeReactionCounter<T>::Dump() const
|
||||
{
|
||||
DumpCounterMapIndices();
|
||||
G4::MoleculeCounter::DumpCounterMapContents<T>(fCounterMap);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void G4VUserMoleculeReactionCounter<T>::DumpCounterMapIndices() const
|
||||
{
|
||||
G4::MoleculeCounter::DumpCounterMapIndices<T>(fCounterMap);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
void G4VUserMoleculeReactionCounter<T>::ResetCounter()
|
||||
{
|
||||
if (fVerbose > 1) {
|
||||
G4cout << "G4VUserMoleculeReactionCounter<" << G4::MoleculeCounter::GetTemplateTypeName<T>()
|
||||
<< ">(" << GetName() << ")::ResetCounter" << G4endl;
|
||||
}
|
||||
fCounterMap.clear();
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename TIndex>
|
||||
G4bool G4VUserMoleculeReactionCounter<TIndex>::SearchIndexUpdated(Search& search, const TIndex& index) const
|
||||
{
|
||||
if (search.fLowerBoundSet && !(search.fLastIndexSearched->first < index)
|
||||
&& !(index < search.fLastIndexSearched->first))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
auto mol_it = fCounterMap.find(index);
|
||||
search.fLastIndexSearched = mol_it;
|
||||
|
||||
if (mol_it != fCounterMap.end()) {
|
||||
search.fLowerBoundTime = search.fLastIndexSearched->second.end();
|
||||
search.fLowerBoundSet = true;
|
||||
}
|
||||
else {
|
||||
search.fLowerBoundSet = false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename T>
|
||||
G4int G4VUserMoleculeReactionCounter<T>::SearchUpperBoundTime(Search& search, G4double time, G4bool sameIndex) const
|
||||
{
|
||||
auto mol_it = search.fLastIndexSearched;
|
||||
if (mol_it == fCounterMap.end()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
InnerCounterMapType const& timeMap = mol_it->second;
|
||||
if (timeMap.empty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (sameIndex) {
|
||||
if (search.fLowerBoundSet && search.fLowerBoundTime != timeMap.end()) {
|
||||
if (search.fLowerBoundTime->first < time) {
|
||||
auto upperToLast = search.fLowerBoundTime;
|
||||
upperToLast++;
|
||||
|
||||
if (upperToLast == timeMap.end()) {
|
||||
return search.fLowerBoundTime->second;
|
||||
}
|
||||
|
||||
if (upperToLast->first > time) {
|
||||
return search.fLowerBoundTime->second;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto up_time_it = timeMap.upper_bound(time);
|
||||
|
||||
if (up_time_it == timeMap.end()) {
|
||||
auto last_time = timeMap.rbegin();
|
||||
return last_time->second;
|
||||
}
|
||||
if (up_time_it == timeMap.begin()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
up_time_it--;
|
||||
|
||||
search.fLowerBoundTime = up_time_it;
|
||||
search.fLowerBoundSet = true;
|
||||
|
||||
return search.fLowerBoundTime->second;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
template<typename TIndex>
|
||||
void G4VUserMoleculeReactionCounter<TIndex>::AbsorbCounter(
|
||||
const G4VMoleculeCounterInternalBase* pCounterBase)
|
||||
{
|
||||
if (pCounterBase == nullptr) {
|
||||
G4ExceptionDescription errMsg;
|
||||
errMsg << "Could not cast the pointer to type G4VUserMoleculeReactionCounter<"
|
||||
<< G4::MoleculeCounter::GetTemplateTypeName<TIndex>() << ">!\n"
|
||||
<< "Because the pointer is nullptr!" << G4endl;
|
||||
G4Exception(G4String("G4VUserMoleculeReactionCounter<"
|
||||
+ G4::MoleculeCounter::GetTemplateTypeName<TIndex>() + ">::AbsorbCounter"),
|
||||
"BAD_REFERENCE", FatalException, errMsg);
|
||||
}
|
||||
|
||||
auto pCounter = dynamic_cast<G4VUserMoleculeReactionCounter<TIndex> const*>(pCounterBase);
|
||||
|
||||
if (pCounter == nullptr) {
|
||||
G4ExceptionDescription errMsg;
|
||||
errMsg << "Could not cast the pointer to type G4VUserMoleculeReactionCounter<"
|
||||
<< G4::MoleculeCounter::GetTemplateTypeName<TIndex>() << ">!\n"
|
||||
<< "Because the objects aren't of the same type!" << G4endl;
|
||||
G4Exception(G4String("G4VUserMoleculeReactionCounter<"
|
||||
+ G4::MoleculeCounter::GetTemplateTypeName<TIndex>() + ">::AbsorbCounter"),
|
||||
"BAD_REFERENCE", FatalException, errMsg);
|
||||
}
|
||||
|
||||
if (pCounter->GetType() != GetType()) {
|
||||
G4ExceptionDescription errMsg;
|
||||
errMsg << "You are trying to absorb a counter with different type!" << G4endl;
|
||||
G4Exception(G4String("G4VUserMoleculeReactionCounter<"
|
||||
+ G4::MoleculeCounter::GetTemplateTypeName<TIndex>() + ">::AbsorbCounter"),
|
||||
"TYPE_DIFF", JustWarning, errMsg);
|
||||
}
|
||||
|
||||
for (auto const& worker_it : pCounter->GetCounterMap()) {
|
||||
auto [master_it, indexIsNew] =
|
||||
fCounterMap.emplace(worker_it.first, InnerCounterMapType{fTimeComparer});
|
||||
|
||||
G4int currentNumber = 0, previousNumber = 0;
|
||||
for (auto const& [time, number] : worker_it.second) {
|
||||
currentNumber = number - previousNumber;
|
||||
previousNumber = number;
|
||||
|
||||
if (master_it->second.empty()) {
|
||||
master_it->second.emplace(time, currentNumber);
|
||||
}
|
||||
else { // at least one element exists, so we can try to find the closest key
|
||||
auto it_closest = G4::MoleculeCounter::FindClosestEntryForKey(master_it->second, time);
|
||||
auto [it, _] = master_it->second.emplace(time, it_closest->second);
|
||||
do {
|
||||
it->second += currentNumber;
|
||||
} while (++it != master_it->second.end());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user