ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ToolsAnalysisManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ToolsAnalysisManager.cc
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 (ivana@ipno.in2p3.fr)
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"
37 
39 
40 //_____________________________________________________________________________
42 {
43  return fgToolsInstance;
44 }
45 
46 //_____________________________________________________________________________
48 {
49  return ( fgToolsInstance != 0 );
50 }
51 
52 //_____________________________________________________________________________
54  : G4VAnalysisManager(type, isMaster),
55  fH1Manager(nullptr),
56  fH2Manager(nullptr),
57  fH3Manager(nullptr),
58  fP1Manager(nullptr),
59  fP2Manager(nullptr)
60 {
61  // Set instance pointer
62  fgToolsInstance = this;
63 
64  // Create managers
70  // The managers will be deleted by the base class
71 
72  // Set managers to base class which takes then their ownership
78 
79  // Plot manager
80  SetPlotManager(std::make_shared<G4PlotManager>(fState));
81 }
82 
83 //_____________________________________________________________________________
85 {
86  fgToolsInstance = nullptr;
87 }
88 
89 //
90 // protected methods
91 //
92 
93 //_____________________________________________________________________________
95 {
96 
97  // Only master thread performs plotting
98  if ( G4Threading::IsWorkerThread() ) return true;
99 
100  auto finalResult = true;
101 
102  // Open output file
103  fPlotManager->OpenFile(fVFileManager->GetPlotFileName());
104 
105  // H1
106  auto result
109  finalResult = finalResult && result;
110 
111  // H2
112  result
113  = fPlotManager->PlotAndWrite<tools::histo::h2d>(fH2Manager->GetH2Vector(),
115  finalResult = finalResult && result;
116 
117  // H3
118  // not yet available in tools
119 
120  // P1
121  result
122  = fPlotManager->PlotAndWrite<tools::histo::p1d>(fP1Manager->GetP1Vector(),
124  finalResult = finalResult && result;
125 
126  // P2
127  // not yet available in tools
128 
129  // Close output file
130  result = fPlotManager->CloseFile();
131  finalResult = finalResult && result;
132 
133  return finalResult;
134 }
135 
136 //_____________________________________________________________________________
137 G4bool G4ToolsAnalysisManager::MergeImpl(tools::histo::hmpi* hmpi)
138 {
139 
140  // if ( G4Threading::IsWorkerThread() ) return true;
141 
142  if ( ! hmpi ) return false;
143 
144  G4bool finalResult = true;
145 
146  // Create MPI manager
147  G4MPIToolsManager mpiToolsManager(fState, hmpi);
148 
149  // H1
150  G4bool result
151  = mpiToolsManager.Merge<tools::histo::h1d>(fH1Manager->GetH1Vector(),
153  finalResult = finalResult && result;
154 
155  // H2
156  result
157  = mpiToolsManager.Merge<tools::histo::h2d>(fH2Manager->GetH2Vector(),
159  finalResult = finalResult && result;
160 
161  // H3
162  result
163  = mpiToolsManager.Merge<tools::histo::h3d>(fH3Manager->GetH3Vector(),
165  finalResult = finalResult && result;
166 
167  // P1
168  result
169  = mpiToolsManager.Merge<tools::histo::p1d>(fP1Manager->GetP1Vector(),
171  finalResult = finalResult && result;
172 
173  // P2
174  result
175  = mpiToolsManager.Merge<tools::histo::p2d>(fP2Manager->GetP2Vector(),
177  finalResult = finalResult && result;
178 
179  return finalResult;
180 }
181 
182 //_____________________________________________________________________________
184 {
185 // Reset histograms and profiles
186 
187  auto finalResult = true;
188 
189  auto result = fH1Manager->Reset();
190  finalResult = finalResult && result;
191 
192  result = fH2Manager->Reset();
193  finalResult = finalResult && result;
194 
195  result = fH3Manager->Reset();
196  finalResult = finalResult && result;
197 
198  result = fP1Manager->Reset();
199  finalResult = finalResult && result;
200 
201  result = fP2Manager->Reset();
202  finalResult = finalResult && result;
203 
204  return finalResult;
205 }
206 
207