Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4TH3ToolsManager.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
27// Author: Ivana Hrivnacova, 10/08/2022 (ivana@ipno.in2p3.fr)
28
29#include "G4THnToolsManager.hh"
30
31#include "tools/histo/h3d"
32
33using namespace G4Analysis;
34
35#include <fstream>
36
37// Specialization for H3 type
38
39
40//_____________________________________________________________________________
41template <>
43 const G4String& title,
44 const std::array<G4HnDimension, kDim3>& bins,
45 const std::array<G4HnDimensionInformation, kDim3>& hnInfo)
46{
47 // Apply hn information to bins
48 auto newXBins(bins[kX]);
49 Update(newXBins, hnInfo[kX]);
50 auto newYBins(bins[kY]);
51 Update(newYBins, hnInfo[kY]);
52 auto newZBins(bins[kZ]);
53 Update(newZBins, hnInfo[kZ]);
54
55 if ((hnInfo[kX].fBinScheme == G4BinScheme::kLinear) &&
56 (hnInfo[kY].fBinScheme == G4BinScheme::kLinear) &&
57 (hnInfo[kZ].fBinScheme == G4BinScheme::kLinear)) {
58 return new tools::histo::h3d(title,
59 newXBins.fNBins, newXBins.fMinValue, newXBins.fMaxValue,
60 newYBins.fNBins, newYBins.fMinValue, newYBins.fMaxValue,
61 newZBins.fNBins, newZBins.fMinValue, newZBins.fMaxValue);
62 }
63
64 return new tools::histo::h3d(title,
65 newXBins.fEdges, newYBins.fEdges, newZBins.fEdges);
66}
67
68//_____________________________________________________________________________
69template <>
71 tools::histo::h3d* ht,
72 const std::array<G4HnDimension, kDim3>& bins,
73 const std::array<G4HnDimensionInformation, kDim3>& hnInfo)
74{
75 // Apply hn information to bins
76 auto newXBins(bins[kX]);
77 Update(newXBins, hnInfo[kX]);
78 auto newYBins(bins[kY]);
79 Update(newYBins, hnInfo[kY]);
80 auto newZBins(bins[kZ]);
81 Update(newZBins, hnInfo[kZ]);
82
83 if ((hnInfo[kX].fBinScheme == G4BinScheme::kLinear) &&
84 (hnInfo[kY].fBinScheme == G4BinScheme::kLinear) &&
85 (hnInfo[kZ].fBinScheme == G4BinScheme::kLinear)) {
86 ht->configure(
87 newXBins.fNBins, newXBins.fMinValue, newXBins.fMaxValue,
88 newYBins.fNBins, newYBins.fMinValue, newYBins.fMaxValue,
89 newZBins.fNBins, newZBins.fMinValue, newZBins.fMaxValue);
90 return;
91 }
92
93 ht->configure(newXBins.fEdges, newYBins.fEdges, newZBins.fEdges);
94}
95
96//_____________________________________________________________________________
97template <>
99 tools::histo::h3d* ht, const G4HnInformation& hnInformation,
100 std::array<G4double, kDim3>& value, G4double weight)
101{
102 auto xInfo = hnInformation.GetHnDimensionInformation(kX);
103 auto yInfo = hnInformation.GetHnDimensionInformation(kY);
104 auto zInfo = hnInformation.GetHnDimensionInformation(kZ);
105
106 // Apply hn information to value
107 Update(value[kX], xInfo);
108 Update(value[kY], yInfo);
109 Update(value[kZ], zInfo);
110
111 // Fill updated value
112 ht->fill(value[kX], value[kY], value[kZ], weight);
113
114 return true;
115}
116
117//_____________________________________________________________________________
118template <>
120 std::ofstream& output)
121{
122// Write selected objects on ASCII file
123// According to the implementation by Michel Maire, originally in
124// extended examples.
125
126 // Do nothing if no histograms are selected
127 if ( ! GetHnManager()->IsAscii() ) return true;
128
129 // Write h3 histograms
130 auto id = GetHnManager()->GetFirstId();
131 for (const auto& [h3, info] : *GetTHnVector()) {
132
133 if ( (h3 == nullptr) || (! info->GetAscii()) ) {
134 // skip writing
135 // if h3 was deleted or writing ascii is not selected
136 id++;
137 continue;
138 }
139
140 Message(kVL3, "write on ascii", "h3d", info->GetName());
141
142 output << "\n 3D histogram " << id++ << ": " << h3->title()
143 << "\n \n \t \t \t X \t\t Y \t\t Z \t\t Bin Height" << G4endl;
144
145 for (G4int j=0; j< G4int(h3->axis_x().bins()); ++j) {
146 for (G4int k=0; k< G4int(h3->axis_y().bins()); ++k) {
147 for (G4int l=0; l< G4int(h3->axis_y().bins()); ++l) {
148 output << " " << j << "\t" << k << "\t" << l << "\t"
149 << h3->axis_x().bin_center(j) << "\t"
150 << h3->axis_y().bin_center(k) << "\t"
151 << h3->axis_y().bin_center(l) << "\t"
152 << h3->bin_height(j, k, l) << G4endl;
153 }
154 }
155 }
156 }
157
158 return output.good();
159}
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4HnDimensionInformation * GetHnDimensionInformation(G4int dimension)
virtual G4bool WriteOnAscii(std::ofstream &output) override
void Update(G4double &value, const G4HnDimensionInformation &hnInfo)
constexpr G4int kVL3
constexpr G4int kX
constexpr G4int kZ
constexpr G4int kY