Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4AnalysisUtilities.hh
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
27// Author: Ivana Hrivnacova, 04/07/2012 (ivana@ipno.in2p3.fr)
28
29#ifndef G4AnalysisUtilities_h
30#define G4AnalysisUtilities_h 1
31
32#include "G4Exception.hh"
33#include "globals.hh"
34
35#include <vector>
36#include <memory>
37#include <string_view>
38
39// Enumeration for definition of available output types
40
48
49namespace G4Analysis
50{
51
52// Constant expressions
53//
54constexpr G4int kX { 0 };
55constexpr G4int kY { 1 };
56constexpr G4int kZ { 2 };
57constexpr G4int kInvalidId { -1 };
58constexpr G4int kVL0 { 0 };
59constexpr G4int kVL1 { 1 };
60constexpr G4int kVL2 { 2 };
61constexpr G4int kVL3 { 3 };
62constexpr G4int kVL4 { 4 };
63constexpr unsigned int kDim1 { 1 };
64constexpr unsigned int kDim2 { 2 };
65constexpr unsigned int kDim3 { 3 };
66constexpr unsigned int kMaxDim { kDim3 };
67constexpr unsigned int kDefaultBasketSize { 32000 };
68constexpr unsigned int kDefaultBasketEntries {4000 };
69constexpr std::string_view kNamespaceName { "G4Analysis" };
70
71// Warning
72//
73void Warn(const G4String& message,
74 const std::string_view inClass,
75 const std::string_view inFunction);
76
77// Get unit value with added handling of "none"
78G4double GetUnitValue(const G4String& unit);
79
80// Tokenizer with taking into account composed strings within ""
81void Tokenize(const G4String& line, std::vector<G4String>& tokens);
82
83// Get output type from name
84G4AnalysisOutput GetOutput(const G4String& outputName, G4bool warn = true);
85size_t GetOutputId(const G4String& outputName, G4bool warn = true);
87
88// Get short hnType from the tools object
89template <typename HT>
91{
92 // tools::histo::h1d etc.
93 G4String hnTypeLong = HT::s_class();
94
95 // tools::histo::h1d -> h1 etc.
96 std::size_t lastColon = hnTypeLong.rfind(":");
97 if (lastColon != G4String::npos && lastColon + 1 < hnTypeLong.length()) {
98 G4String potentialType = hnTypeLong.substr(lastColon + 1);
99 if (potentialType.length() >= 2 &&
100 (potentialType.substr(0, 1) == "h" || potentialType.substr(0, 1) == "p")) {
101 return potentialType.substr(0, 2);
102 }
103 }
104 G4cerr << "Warning: Could not extract short hnType for " << hnTypeLong << G4endl;
105 return "";
106}
107
108template <typename HT>
110{
111 // tools::histo::h1d etc.
112 G4String hnTypeLong = HT::s_class();
113 std::size_t length = hnTypeLong.length();
114 return (length >= 3 && hnTypeLong.substr(length - 3) == "p1d") ||
115 (length >= 3 && hnTypeLong.substr(length - 3) == "p2d");
116}
117
118// String conversion
119template <typename T>
120inline
121std::string ToString(const T& value)
122{ return std::to_string(value); }
123
124template <>
125inline
126std::string ToString<std::string>(const std::string& value)
127{ return value; }
128
129// File names utilities
130
131// Get file base name (without dot)
132G4String GetBaseName(const G4String& fileName);
133
134// Get file base extension (without dot)
135G4String GetExtension(const G4String& fileName,
136 const G4String& defaultExtension = "");
137
138// Compose and return the histogram or profile specific file name:
139// - add _hn_hnName suffix to the file base name
140// - add file extension if not present
142 const G4String& fileName,
143 const G4String& fileType,
144 const G4String& hnType,
145 const G4String& hnName);
146
147// Update Hn file name:
148// - add _vN suffix to the base namer if cycle > 0
150 const G4String& fileName,
151 const G4String& fileType,
152 G4int cycle = 0);
153
154// Compose and return the ntuple specific file name:
155// - add _nt_ntupleName suffix to the file base name
156// - add _vN suffix if cycle > 0
157// - add _tN suffix if called on thread worker
158// - add file extension if not present
160 const G4String& fileName,
161 const G4String& fileType,
162 const G4String& ntupleName,
163 G4int cycle = 0);
164
165// Compose and return the ntuple specific file name:
166// - add _mFN suffix to the file base name where FN = ntupleFileNumber
167// - add _vN suffix if cycle > 0
168// - add file extension if not present
170 const G4String& fileName,
171 const G4String& fileType,
172 G4int ntupleFileNumber,
173 G4int cycle = 0);
174
175// Update file base name with the thread suffix:
176// - add _vN suffix if cycle > 0
177// - add _tN suffix if called on thread worker
178// - add file extension if not present
180 const G4String& fileName,
181 const G4String& fileType,
182 G4int cycle = 0);
183
184// Generate plot file name for an output file name
185G4String GetPlotFileName(const G4String& fileName);
186
187}
188
189/*
190// make possible to print enumerators in class enum as integer
191template <typename Enumeration>
192auto as_integer(Enumeration const value)
193 -> typename std::underlying_type<Enumeration>::type
194{
195 return static_cast<typename std::underlying_type<Enumeration>::type>(value);
196}
197*/
198
199#endif
200
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4String GetExtension(const G4String &fileName, const G4String &defaultExtension="")
constexpr unsigned int kDefaultBasketSize
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
size_t GetOutputId(const G4String &outputName, G4bool warn=true)
constexpr unsigned int kDim3
constexpr G4int kVL1
std::string ToString(const T &value)
constexpr G4int kVL2
std::string ToString< std::string >(const std::string &value)
G4String GetTnFileName(const G4String &fileName, const G4String &fileType, G4int cycle=0)
G4String GetPlotFileName(const G4String &fileName)
constexpr std::string_view kNamespaceName
G4double GetUnitValue(const G4String &unit)
G4String GetOutputName(G4AnalysisOutput outputType)
constexpr unsigned int kMaxDim
constexpr G4int kVL3
G4AnalysisOutput GetOutput(const G4String &outputName, G4bool warn=true)
G4String GetNtupleFileName(const G4String &fileName, const G4String &fileType, const G4String &ntupleName, G4int cycle=0)
constexpr G4int kVL4
constexpr G4int kVL0
constexpr G4int kInvalidId
constexpr unsigned int kDefaultBasketEntries
constexpr G4int kX
G4String GetHnType()
G4String GetHnFileName(const G4String &fileName, const G4String &fileType, const G4String &hnType, const G4String &hnName)
G4String GetBaseName(const G4String &fileName)
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)
constexpr unsigned int kDim2
constexpr unsigned int kDim1
constexpr G4int kZ
constexpr G4int kY
std::string to_string(G4FermiAtomicMass mass)