ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4CompositeEMDataSet.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4CompositeEMDataSet.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 //
28 // Author: Maria Grazia Pia (Maria.Grazia.Pia@cern.ch)
29 //
30 // History:
31 // -----------
32 // 1 Aug 2001 MGP Created
33 //
34 // 15 Jul 2009 Nicolas A. Karakatsanis
35 //
36 // - LoadNonLogData method was created to load only the non-logarithmic data from G4EMLOW
37 // dataset. It is essentially performing the data loading operations as in the past.
38 //
39 // - LoadData method was revised in order to calculate the logarithmic values of the data
40 // It retrieves the data values from the G4EMLOW data files but, then, calculates the
41 // respective log values and loads them to seperate data structures.
42 //
43 // - SetLogEnergiesData method was cretaed to set logarithmic values to G4 data vectors.
44 // The EM data sets, initialized this way, contain both non-log and log values.
45 // These initialized data sets can enhance the computing performance of data interpolation
46 // operations
47 //
48 // -------------------------------------------------------------------
49 
50 #include "G4CompositeEMDataSet.hh"
51 #include "G4EMDataSet.hh"
52 #include "G4VDataSetAlgorithm.hh"
53 #include <fstream>
54 #include <sstream>
55 
57  G4double argUnitEnergies,
58  G4double argUnitData,
59  G4int argMinZ,
60  G4int argMaxZ)
61  :
62  algorithm(argAlgorithm),
63  unitEnergies(argUnitEnergies),
64  unitData(argUnitData),
65  minZ(argMinZ),
66  maxZ(argMaxZ)
67 {
68  if (algorithm == 0)
69  G4Exception("G4CompositeEMDataSet::G4CompositeEMDataSet",
70  "em1003",FatalException,"interpolation == 0");
71 
72 }
73 
74 
75 
77 {
79  if (algorithm) delete algorithm;
80 }
81 
82 
83 G4double G4CompositeEMDataSet::FindValue(G4double argEnergy, G4int argComponentId) const
84 {
85  const G4VEMDataSet* component(GetComponent(argComponentId));
86 
87  if (component) return component->FindValue(argEnergy);
88 
89  std::ostringstream message;
90  message << "G4CompositeEMDataSet::FindValue - component " << argComponentId << " not found";
91 
92  G4Exception("G4CompositeEMDataSet::FindValue",
93  "em1004",FatalException,message.str().c_str());
94 
95  return 0.;
96 }
97 
99 {
100  const size_t n(NumberOfComponents());
101 
102  G4cout << "The data set has " << n << " components" << G4endl;
103  G4cout << G4endl;
104 
105  size_t i(0);
106 
107  while (i<n)
108  {
109  G4cout << "--- Component " << i << " ---" << G4endl;
110  GetComponent(i)->PrintData();
111  i++;
112  }
113 }
114 
115 void G4CompositeEMDataSet::SetEnergiesData(G4DataVector* argEnergies, G4DataVector* argData, G4int argComponentId)
116 {
117  G4VEMDataSet * component(components[argComponentId]);
118 
119  if (component)
120  {
121  component->SetEnergiesData(argEnergies, argData, 0);
122  return;
123  }
124 
125  std::ostringstream message;
126  message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
127 
128  G4Exception("G4CompositeEMDataSet::SetEnergiesData",
129  "em1004",FatalException,message.str().c_str());
130 }
131 
133  G4DataVector* argData,
134  G4DataVector* argLogEnergies,
135  G4DataVector* argLogData,
136  G4int argComponentId)
137 {
138  G4VEMDataSet * component(components[argComponentId]);
139 
140  if (component)
141  {
142  component->SetLogEnergiesData(argEnergies, argData, argLogEnergies, argLogData, 0);
143  return;
144  }
145 
146  std::ostringstream message;
147  message << "G4CompositeEMDataSet::SetEnergiesData - component " << argComponentId << " not found";
148 
149  G4Exception("G4CompositeEMDataSet::SetLogEnergiesData",
150  "em1004",FatalException,message.str().c_str());
151 }
152 
153 
155 {
157 
158  for (G4int z(minZ); z<maxZ; z++)
159  {
161  if (!component->LoadData(argFileName))
162  {
163  delete component;
164  return false;
165  }
166  AddComponent(component);
167  }
168  return true;
169 }
170 
171 
173 {
175 
176  for (G4int z(minZ); z<maxZ; z++)
177  {
179  if (!component->LoadNonLogData(argFileName))
180  {
181  delete component;
182  return false;
183  }
184  AddComponent(component);
185  }
186  return true;
187 }
188 
189 
191 {
192  for (G4int z=minZ; z<maxZ; z++)
193  {
194  const G4VEMDataSet* component(GetComponent(z-minZ));
195 
196  if (!component)
197  {
198  std::ostringstream message;
199  message << "G4CompositeEMDataSet::SaveData - component " << (z-minZ) << " not found";
200  G4Exception("G4CompositeEMDataSet::SaveData",
201  "em1004",FatalException,message.str().c_str());
202  return false;
203  }
204 
205  if (!component->SaveData(argFileName))
206  return false;
207  }
208 
209  return true;
210 }
211 
213 {
214  while (!components.empty())
215  {
216  if (components.back())
217  delete components.back();
218  components.pop_back();
219  }
220 }
221 
222 
224 {
225  G4double value = 0.;
226  if (componentId >= 0 && componentId < (G4int)components.size())
227  {
228  const G4VEMDataSet* dataSet = GetComponent(componentId);
229  value = dataSet->RandomSelect();
230  }
231  return value;
232 }