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
G4TP2ToolsManager.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/p2d"
32
33using namespace G4Analysis;
34
35#include <fstream>
36
37// Specialization for P2 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 UpdateValues(newZBins, hnInfo[kZ]);
54
55 if ((hnInfo[kX].fBinScheme == G4BinScheme::kLinear) &&
56 (hnInfo[kY].fBinScheme == G4BinScheme::kLinear)) {
57 if ( newZBins.fMinValue == 0. && newZBins.fMaxValue == 0.) {
58 return new tools::histo::p2d(
59 title, newXBins.fNBins, newXBins.fMinValue, newXBins.fMaxValue,
60 newYBins.fNBins, newYBins.fMinValue, newYBins.fMaxValue);
61 }
62 return new tools::histo::p2d(
63 title, newXBins.fNBins, newXBins.fMinValue, newXBins.fMaxValue,
64 newYBins.fNBins, newYBins.fMinValue, newYBins.fMaxValue,
65 newZBins.fMinValue, newZBins.fMaxValue);
66 }
67
68 if ( newZBins.fMinValue == 0. && newZBins.fMaxValue == 0.) {
69 return new tools::histo::p2d(title, newXBins.fEdges, newYBins.fEdges);
70 }
71 return new tools::histo::p2d(title, newXBins.fEdges, newYBins.fEdges,
72 newZBins.fMinValue, newZBins.fMaxValue);
73}
74
75//_____________________________________________________________________________
76template <>
78 tools::histo::p2d* ht,
79 const std::array<G4HnDimension, kDim3>& bins,
80 const std::array<G4HnDimensionInformation, kDim3>& hnInfo)
81{
82 // Apply hn information to bins
83 auto newXBins(bins[kX]);
84 Update(newXBins, hnInfo[kX]);
85 auto newYBins(bins[kY]);
86 Update(newYBins, hnInfo[kY]);
87 auto newZBins(bins[kZ]);
88 UpdateValues(newZBins, hnInfo[kZ]);
89
90 if ((hnInfo[kX].fBinScheme == G4BinScheme::kLinear) &&
91 (hnInfo[kY].fBinScheme == G4BinScheme::kLinear)) {
92 if ( newZBins.fMinValue == 0. && newZBins.fMaxValue == 0.) {
93 ht->configure(
94 newXBins.fNBins, newXBins.fMinValue, newXBins.fMaxValue,
95 newYBins.fNBins, newYBins.fMinValue, newYBins.fMaxValue);
96 return;
97 }
98 ht->configure(
99 newXBins.fNBins, newXBins.fMinValue, newXBins.fMaxValue,
100 newYBins.fNBins, newYBins.fMinValue, newYBins.fMaxValue,
101 newZBins.fMinValue, newZBins.fMaxValue);
102 return;
103 }
104
105 if ( newZBins.fMinValue == 0. && newZBins.fMaxValue == 0.) {
106 ht->configure(newXBins.fEdges, newYBins.fEdges);
107 return;
108 }
109
110 ht->configure(newXBins.fEdges, newYBins.fEdges,
111 newZBins.fMinValue, newZBins.fMaxValue);
112}
113
114//_____________________________________________________________________________
115template <>
117 tools::histo::p2d* ht, const G4HnInformation& hnInformation,
118 std::array<G4double, kDim3>& value, G4double weight)
119{
120 auto xInfo = hnInformation.GetHnDimensionInformation(kX);
121 auto yInfo = hnInformation.GetHnDimensionInformation(kY);
122 auto zInfo = hnInformation.GetHnDimensionInformation(kZ);
123
124 // Apply hn information to value
125 Update(value[kX], xInfo);
126 Update(value[kY], yInfo);
127 Update(value[kZ], zInfo);
128
129 // Fill updated value
130 ht->fill(value[kX], value[kY], value[kZ], weight);
131
132 return true;
133}
134
135//_____________________________________________________________________________
136template <>
138 std::ofstream& output)
139{
140// Write selected objects on ASCII file
141
142 // Do nothing if no histograms are selected
143 if ( ! GetHnManager()->IsAscii() ) return true;
144
145 // Write p2 histograms
146 auto id = GetHnManager()->GetFirstId();
147 for (const auto& [p2, info] : *GetTHnVector()) {
148
149 if ( (p2 == nullptr) || (! info->GetAscii()) ) {
150 // skip writing
151 // if p2 was deleted or writing ascii is not selected
152 id++;
153 continue;
154 }
155
156 Message(kVL3, "write on ascii", "p2d", info->GetName());
157
158 output << "\n 2D profile " << id++ << ": " << p2->title()
159 << "\n \n \t \t X \t\t Y \t\t MeanZ" << G4endl;
160
161 for (G4int j=0; j< G4int(p2->axis_x().bins()); ++j) {
162 for (G4int k=0; k< G4int(p2->axis_y().bins()); ++k) {
163 auto sw = p2->bin_Sw(j, k);
164 auto svw = p2->bin_Svw(j, k);
165 auto mean = ( sw != 0. ) ? (svw / sw) : 0.;
166 output << " " << j << "\t" << k << "\t"
167 << p2->axis_x().bin_center(j) << "\t"
168 << p2->axis_y().bin_center(k) << "\t"
169 << mean << G4endl;
170 }
171 }
172 }
173
174 return output.good();
175}
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)
void UpdateValues(G4HnDimension &bins, const G4HnDimensionInformation &hnInfo)
constexpr G4int kVL3
constexpr G4int kX
constexpr G4int kZ
constexpr G4int kY