Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4MoleculeCounterTimeComparer.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// Author: Christian Velten (2025)
27
29
30#include "G4Exception.hh"
31
35
41
44{
45 switch (other.fType) {
47 SetVariablePrecision(other.fVariablePrecision);
48 break;
50 default:
51 SetFixedPrecision(other.fPrecision);
52 break;
53 }
54 return *this;
55}
56
58{
60 fPrecision = precision;
61}
62
64 const std::vector<G4double>& globalTimeHighEdges, const std::vector<G4double>& resolutions)
65{
67 fVariablePrecision.clear();
68 for (auto key = globalTimeHighEdges.cbegin(), val = resolutions.cbegin();
69 key != globalTimeHighEdges.cend() && val != resolutions.cend(); ++key, ++val)
70 {
71 fVariablePrecision.emplace(*key, *val);
72 }
73
74 if (fVariablePrecision.empty()) {
75 G4Exception("G4MoleculeCounterTimeComparer::SetVariablePrecision()",
76 "G4MoleculeCounterTimeComparer", FatalException, "Precision map cannot be empty!");
77 }
78}
79
81 const std::map<G4double, G4double>& resolutionMap)
82{
84 fVariablePrecision = resolutionMap;
85
86 if (fVariablePrecision.empty()) {
87 G4Exception("G4MoleculeCounterTimeComparer::SetVariablePrecision()",
88 "G4MoleculeCounterTimeComparer", FatalException, "Precision map cannot be empty!");
89 }
90}
91
93{
95 return fPrecision;
96 else
97 return fVariablePrecision.upper_bound(time)->second;
98}
99
101{
103 if (std::fabs(a - b) < fPrecision) {
104 return false;
105 }
106 }
108 const auto it_a = fVariablePrecision.upper_bound(a);
109 const auto it_b = fVariablePrecision.upper_bound(b);
110 auto precision = fVariablePrecision.crbegin()->second;
111 if (it_a != fVariablePrecision.cend() && it_b != fVariablePrecision.cend())
112 precision = std::min(it_a->second, it_b->second);
113 if (std::fabs(a - b) < precision) {
114 return false;
115 }
116 }
117 else {
118 G4Exception("G4MoleculeCounterTimeComparer::operator()", "G4MoleculeCounterTimeComparer",
119 FatalException, "Unknown comparison type");
120 }
121 return a < b;
122}
123
124// ---------------------------------------------------------------------
125
128{
130 obj.SetFixedPrecision(precision);
131 return obj;
132}
133
136{
138 obj.SetVariablePrecision(map);
139 return obj;
140}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
G4MoleculeCounterTimeComparer & operator=(const G4MoleculeCounterTimeComparer &)
bool operator()(const G4double &, const G4double &) const
static G4MoleculeCounterTimeComparer CreateWithVariablePrecision(const std::map< G4double, G4double > &)
static G4MoleculeCounterTimeComparer CreateWithFixedPrecision(G4double)
void SetVariablePrecision(const std::vector< G4double > &, const std::vector< G4double > &)