Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-27 09:12:04

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //  G4VMoleculeCounter.hh
0027 //  Geant4
0028 //
0029 //  Created by Mathieu Karamitros on 02/11/2016.
0030 //  Modified by Christian Velten on 10/27/2024.
0031 //
0032 //
0033 #ifndef G4VMOLECULECOUNTER_HH
0034 #define G4VMOLECULECOUNTER_HH 1
0035 
0036 #include "G4MoleculeCounterTimeComparer.hh"
0037 #include "G4VMoleculeCounterInternalBase.hh"
0038 
0039 #include <map>
0040 #include <memory>
0041 
0042 class G4MolecularConfiguration;
0043 class G4MoleculeDefinition;
0044 class G4Track;
0045 class G4StepPoint;
0046 
0047 //------------------------------------------------------------------------------
0048 
0049 class G4VMoleculeCounter : public G4VMoleculeCounterInternalBase
0050 {
0051     template<typename>
0052     friend class G4VUserMoleculeCounter;
0053 
0054   public:
0055     enum MoleculeCounterType
0056     {
0057       Other,
0058       Basic,
0059       Mesoscopic,
0060     };
0061     struct G4VMoleculeCounterIndex : public G4VMoleculeCounterIndexInterface
0062     {
0063         virtual ~G4VMoleculeCounterIndex() = default;
0064         virtual G4bool operator<(G4VMoleculeCounterIndex const&) const = 0;
0065         virtual G4bool operator==(G4VMoleculeCounterIndex const&) const = 0;
0066         virtual G4String GetInfo() const = 0;
0067         virtual const G4MolecularConfiguration* GetMolecule() const = 0;
0068     };
0069 
0070   private:
0071     G4VMoleculeCounter();
0072     G4VMoleculeCounter(const G4String&, MoleculeCounterType = MoleculeCounterType::Other);
0073     G4VMoleculeCounter(G4VMoleculeCounter const&) = delete;
0074     void operator=(G4VMoleculeCounter const& x) = delete;
0075 
0076   public:
0077     ~G4VMoleculeCounter() override = default;
0078 
0079   public:
0080     virtual std::unique_ptr<G4VMoleculeCounterIndex> BuildIndex(const G4Track*) const = 0;
0081     virtual std::unique_ptr<G4VMoleculeCounterIndex> BuildIndex(const G4Track*,
0082                                                                 const G4StepPoint*) const = 0;
0083     virtual std::unique_ptr<G4VMoleculeCounterIndex> BuildSimpleIndex(const G4MolecularConfiguration*) const = 0;
0084 
0085     virtual void AddMolecule(std::unique_ptr<G4VMoleculeCounterIndex>, G4double, G4int = 1) = 0;
0086     virtual void RemoveMolecule(std::unique_ptr<G4VMoleculeCounterIndex>, G4double, G4int = 1) = 0;
0087 
0088     virtual std::set<const G4MolecularConfiguration*> GetRecordedMolecules() const = 0;
0089     std::set<G4double> GetRecordedTimes() const override = 0;
0090 
0091     virtual void SchedulerFinalizedTracking() = 0;
0092 
0093   protected:
0094     MoleculeCounterType fType{MoleculeCounterType::Other};
0095 
0096     G4bool fSensitiveToStepping{false};
0097     G4bool fNegativeCountsAreFatal{true};
0098 
0099     std::set<const G4MoleculeDefinition*> fIgnoredMolecules{};
0100     std::set<const G4MolecularConfiguration*> fIgnoredReactants{};
0101 
0102   public:
0103     MoleculeCounterType GetType() const;
0104 
0105     G4bool GetSensitiveToStepping() const;
0106     void SetSensitiveToStepping(G4bool = true);
0107 
0108     G4bool GetNegativeCountsAreFatal() const;
0109 
0110     // Ignore certain molecules from counting
0111     void IgnoreMolecule(const G4MoleculeDefinition*);
0112     void IgnoreReactant(const G4MolecularConfiguration*);
0113     void RegisterAll();
0114 
0115     G4bool IsReactantIgnored(const G4MoleculeDefinition*) const;
0116     G4bool IsReactantIgnored(const G4MolecularConfiguration*) const;
0117 
0118   protected:
0119     void SetNegativeCountsAreFatal(G4bool);
0120 };
0121 
0122 //------------------------------------------------------------------------------
0123 
0124 inline G4VMoleculeCounter::MoleculeCounterType G4VMoleculeCounter::GetType() const
0125 {
0126   return fType;
0127 }
0128 
0129 inline G4bool G4VMoleculeCounter::GetSensitiveToStepping() const
0130 {
0131   return fSensitiveToStepping;
0132 }
0133 
0134 inline G4bool G4VMoleculeCounter::GetNegativeCountsAreFatal() const
0135 {
0136   return fNegativeCountsAreFatal;
0137 }
0138 inline void G4VMoleculeCounter::SetNegativeCountsAreFatal(G4bool flag)
0139 {
0140   fNegativeCountsAreFatal = flag;
0141 }
0142 
0143 inline void G4VMoleculeCounter::IgnoreMolecule(const G4MoleculeDefinition* molecule)
0144 {
0145   fIgnoredMolecules.insert(molecule);
0146 }
0147 
0148 inline void G4VMoleculeCounter::IgnoreReactant(const G4MolecularConfiguration* reactant)
0149 {
0150   fIgnoredReactants.insert(reactant);
0151 }
0152 
0153 inline void G4VMoleculeCounter::RegisterAll()
0154 {
0155   fIgnoredMolecules.clear();
0156   fIgnoredReactants.clear();
0157 }
0158 
0159 #endif