Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ToolsAnalysisManager.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, 18/06/2013 ([email protected])
28
30#include "G4H1ToolsManager.hh"
31#include "G4H2ToolsManager.hh"
32#include "G4H3ToolsManager.hh"
33#include "G4P1ToolsManager.hh"
34#include "G4P2ToolsManager.hh"
35#include "G4PlotManager.hh"
36#include "G4MPIToolsManager.hh"
38
40
41//_____________________________________________________________________________
43{
44 return fgToolsInstance;
45}
46
47//_____________________________________________________________________________
49{
50 return ( fgToolsInstance != 0 );
51}
52
53//_____________________________________________________________________________
55 : G4VAnalysisManager(type, isMaster),
56 fH1Manager(nullptr),
57 fH2Manager(nullptr),
58 fH3Manager(nullptr),
59 fP1Manager(nullptr),
60 fP2Manager(nullptr)
61{
62 // Set instance pointer
63 fgToolsInstance = this;
64
65 // Create managers
71 // The managers will be deleted by the base class
72
73 // Set managers to base class which takes then their ownership
79
80 // Plot manager
81 SetPlotManager(std::make_shared<G4PlotManager>(fState));
82}
83
84//_____________________________________________________________________________
86{
87 fgToolsInstance = nullptr;
88}
89
90//
91// protected methods
92//
93
94//_____________________________________________________________________________
96{
97
98 // Only master thread performs plotting
99 if ( G4Threading::IsWorkerThread() ) return true;
100
101 auto finalResult = true;
102
103 // Open output file
104 fPlotManager->OpenFile(fVFileManager->GetPlotFileName());
105
106 // H1
107 auto result
108 = fPlotManager->PlotAndWrite<tools::histo::h1d>(fH1Manager->GetH1Vector(),
110 finalResult = finalResult && result;
111
112 // H2
113 result
114 = fPlotManager->PlotAndWrite<tools::histo::h2d>(fH2Manager->GetH2Vector(),
116 finalResult = finalResult && result;
117
118 // H3
119 // not yet available in tools
120
121 // P1
122 result
123 = fPlotManager->PlotAndWrite<tools::histo::p1d>(fP1Manager->GetP1Vector(),
125 finalResult = finalResult && result;
126
127 // P2
128 // not yet available in tools
129
130 // Close output file
131 result = fPlotManager->CloseFile();
132 finalResult = finalResult && result;
133
134 return finalResult;
135}
136
137//_____________________________________________________________________________
139{
140
141 // if ( G4Threading::IsWorkerThread() ) return true;
142
143 if ( ! hmpi ) return false;
144
145 G4bool finalResult = true;
146
147 // Create MPI manager
148 G4MPIToolsManager mpiToolsManager(fState, hmpi);
149
150 // H1
151 G4bool result
152 = mpiToolsManager.Merge<tools::histo::h1d>(fH1Manager->GetH1Vector(),
154 finalResult = finalResult && result;
155
156 // H2
157 result
158 = mpiToolsManager.Merge<tools::histo::h2d>(fH2Manager->GetH2Vector(),
160 finalResult = finalResult && result;
161
162 // H3
163 result
164 = mpiToolsManager.Merge<tools::histo::h3d>(fH3Manager->GetH3Vector(),
166 finalResult = finalResult && result;
167
168 // P1
169 result
170 = mpiToolsManager.Merge<tools::histo::p1d>(fP1Manager->GetP1Vector(),
172 finalResult = finalResult && result;
173
174 // P2
175 result
176 = mpiToolsManager.Merge<tools::histo::p2d>(fP2Manager->GetP2Vector(),
178 finalResult = finalResult && result;
179
180 return finalResult;
181}
182
183//_____________________________________________________________________________
185{
186// Reset histograms and profiles
187
188 auto finalResult = true;
189
190 auto result = fH1Manager->Reset();
191 finalResult = finalResult && result;
192
193 result = fH2Manager->Reset();
194 finalResult = finalResult && result;
195
196 result = fH3Manager->Reset();
197 finalResult = finalResult && result;
198
199 result = fP1Manager->Reset();
200 finalResult = finalResult && result;
201
202 result = fP2Manager->Reset();
203 finalResult = finalResult && result;
204
205 return finalResult;
206}
bool G4bool
Definition: G4Types.hh:86
const std::vector< G4HnInformation * > & GetHnVector() const
const std::vector< tools::histo::h1d * > & GetH1Vector() const
const std::vector< tools::histo::h2d * > & GetH2Vector() const
const std::vector< G4HnInformation * > & GetHnVector() const
const std::vector< G4HnInformation * > & GetHnVector() const
const std::vector< tools::histo::h3d * > & GetH3Vector() const
G4bool Merge(const std::vector< T * > &htVector, const std::vector< G4HnInformation * > &hnVector)
const std::vector< G4HnInformation * > & GetHnVector() const
const std::vector< tools::histo::p1d * > & GetP1Vector() const
const std::vector< G4HnInformation * > & GetHnVector() const
const std::vector< tools::histo::p2d * > & GetP2Vector() const
G4bool Reset()
static G4ThreadLocal G4ToolsAnalysisManager * fgToolsInstance
virtual G4bool PlotImpl() final
static G4ToolsAnalysisManager * Instance()
virtual G4bool MergeImpl(tools::histo::hmpi *hmpi) final
G4ToolsAnalysisManager(const G4String &type, G4bool isMaster=true)
std::shared_ptr< G4PlotManager > fPlotManager
void SetH1Manager(G4VH1Manager *h1Manager)
void SetH2Manager(G4VH2Manager *h2Manager)
void SetPlotManager(std::shared_ptr< G4PlotManager > plotManager)
G4AnalysisManagerState fState
void SetP2Manager(G4VP2Manager *p2Manager)
void SetP1Manager(G4VP1Manager *p1Manager)
void SetH3Manager(G4VH3Manager *h3Manager)
std::shared_ptr< G4VFileManager > fVFileManager
G4bool IsWorkerThread()
Definition: G4Threading.cc:123
#define G4ThreadLocal
Definition: tls.hh:77