Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GlaubAADataSetHandler.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 // * *
21 // * Parts of this code which have been developed by QinetiQ Ltd *
22 // * under contract to the European Space Agency (ESA) are the *
23 // * intellectual property of ESA. Rights to use, copy, modify and *
24 // * redistribute this software for general public use are granted *
25 // * in compliance with any licensing, distribution and development *
26 // * policy adopted by the Geant4 Collaboration. This code has been *
27 // * written by QinetiQ Ltd for the European Space Agency, under ESA *
28 // * contract 19770/06/NL/JD (Technology Research Programme). *
29 // * *
30 // * By using, copying, modifying or distributing the software (or *
31 // * any work based on the software) you agree to acknowledge its *
32 // * use in resulting scientific publications, and indicate your *
33 // * acceptance of all terms of the Geant4 Software license. *
34 // ********************************************************************
35 //
36 /// \file hadronic/Hadr02/src/G4GlaubAADataSetHandler.cc
37 /// \brief Implementation of the G4GlaubAADataSetHandler class
38 //
39 // $Id: G4GlaubAADataSetHandler.cc 77519 2013-11-25 10:54:57Z gcosmo $
40 //
41 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 //
43 // MODULE: G4GlaubAADataSetHandler.cc
44 //
45 // Version: 0.A
46 // Date: 02/04/08
47 // Author: P R Truscott
48 // Organisation: QinetiQ Ltd, UK
49 // Customer: ESA/ESTEC, NOORDWIJK
50 // Contract: 19770/06/NL/JD
51 //
52 // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 ///////////////////////////////////////////////////////////////////////////////
54 //
55 #ifdef G4_USE_DPMJET
56 
57 
59 #include "G4FullGlaubAADataSet.hh"
61 #include "G4Isotope.hh"
62 #include "G4Element.hh"
63 #include "G4StableIsotopes.hh"
64 #include "G4PhysicalConstants.hh"
65 #include "G4SystemOfUnits.hh"
66 
67 #include "G4HadronicException.hh"
68 
69 #include "G4DPMJET2_5Interface.hh"
70 
71 #include <fstream>
72 #include <sstream>
73 #include <iomanip>
74 #include <iostream>
75 
76 G4GlaubAADataSetHandler* G4GlaubAADataSetHandler::instance = 0;
77 
78 ////////////////////////////////////////////////////////////////////////////////
79 //
81 {
82 //
83 //
84 // theIndex is a std::map of the Glauber data loaded. It uses a unique
85 // identifier based on the projectile and target A & Z to point to each Glauber
86 // data set object.
87 //
88  theIndex.clear();
89 //
90 //
91 // By default, there is no limit on the number of datasets to load.
92 //
93  maxGlauberDataSets =-1;
94  cntGlauberDataSets = 0;
95 //
96 //
97 // The glauber data sets are assumed to be in Geant4 data directory for
98 // DPMJET II.5, defined by an environment variable.
99 //
100  if ( !getenv("G4DPMJET2_5DATA") )
101  {
102  G4cout <<"ENVIRONMENT VARIABLE G4DPMJET2_5DATA NOT SET " <<G4endl;
103  throw G4HadronicException(__FILE__, __LINE__,
104  "Please setenv G4DPMJET2_5DATA to point to the dpmjet2.5 data files.");
105  }
106  glauberDataSetDir = getenv("G4DPMJET2_5DATA");
107 //
108 //
109 // Initialise the local copy of the Glauber data.
110 //
111  theCurrentGlauberDataSet = 0;
112  ppnCurrent = 0.0;
113  usingLocalGlauberDataSet = false;
114 
115  maxArray = 200;
116 //
117 //
118 // No verbose output by default.
119 //
120  SetVerboseLevel(0);
121 }
122 ////////////////////////////////////////////////////////////////////////////////
123 //
125 {
127 }
128 ////////////////////////////////////////////////////////////////////////////////
129 //
131 {
132 //
133 //
134 // THERE CAN BE ONLY ONE!! .... I mean, one G4GlaubAADataSetHandler.
135 //
136  if (instance == 0) instance = new G4GlaubAADataSetHandler();
137  return instance;
138 }
139 ////////////////////////////////////////////////////////////////////////////////
140 //
141 G4int
142 G4GlaubAADataSetHandler::GetIndexID (const G4int AP, const G4int AT) const
143 {
144  return AP*1000 + AT;
145 }
146 ////////////////////////////////////////////////////////////////////////////////
147 //
148 G4String
149 G4GlaubAADataSetHandler::GetProjectileStringID (const G4int AP) const
150 {
151  std::ostringstream os;
152  os <<"ap" <<AP;
153  return os.str();
154 }
155 ////////////////////////////////////////////////////////////////////////////////
156 //
157 G4String G4GlaubAADataSetHandler::GetTargetStringID (const G4int AT) const
158 {
159  std::ostringstream os;
160  os <<"at" <<AT;
161  return os.str();
162 }
163 
164 ////////////////////////////////////////////////////////////////////////////////
165 //
166 G4String G4GlaubAADataSetHandler::GetStringID (const G4int AP, const G4int AT)
167  const
168 {
169  G4String ID = GetProjectileStringID(AP) + "_" + GetTargetStringID(AT);
170  return ID;
171 }
172 ////////////////////////////////////////////////////////////////////////////////
173 //
174 // LoadGlauberDataRtnPtr
175 //
176 // Function LoadGlauberData to load data for a specific projectile AP and target
177 // AT. Note that, unlike in the previous implementation, there is no overwrite
178 // option since there is only one source of glaubAA data.
179 //
180 // Returns a pointer the the glauber data set object, if exists otherwise
181 // returns NULL.
182 //
183 G4VGlauberDataSet *G4GlaubAADataSetHandler::LoadGlauberDataReturnPtr
184  (const G4int AP, const G4int AT)
185 {
186  G4ParamType1GlaubAADataSet *glauberData = 0;
187 //
188 //
189 // Check whether an file with an appropriate name exists in the directory,
190 // which will probably contain the Glauber data.
191 //
192  G4String glauberID = GetStringID(AP,AT);
193  G4String filename = glauberDataSetDir + "/" + glauberID + ".glaubaadat";
194  std::ifstream glauberFile(filename);
195  if (glauberFile) {
196 //
197 //
198 // File exists, so read data into an appropriate object type. Do a double-
199 // check and make sure we want to retain Glauber data relating to this target.
200 // Note that this GDS handler only deals with parameterised sets (type 1). Also
201 // note that peek returns an ASCII charater code, and therefore since values of
202 // '0' to '9' and 'A' to 'Z' are acceptable, these must be decoded.
203 //
204  G4int i = -1;
205  G4int asci = glauberFile.peek();
206  if (asci >= 48 && asci <= 57) i = asci - 48;
207  else if (asci >= 65 && asci <= 90) i = asci - 55;
208  if (i!=1) {
209  G4cerr <<"ERROR IN G4GlaubAADataSetHandler::LoadGlauberDataReturnPtr"
210  <<G4endl;
211  G4cerr <<"GLAUBER FILE " <<filename <<G4endl;
212  G4cerr <<"IDENTIFIED AS GLAUBER FILE TYPE " <<i <<G4endl;
213  G4cerr <<"THIS IS NOT SUPPORTED" <<G4endl;
214  G4cerr <<G4endl;
215  }
216  else {
217  glauberData = new G4ParamType1GlaubAADataSet();
218  glauberFile >>(*glauberData);
219 //
220 //
221 // Here we check the A of the projectile and target...
222 //
223  G4int AP1 = glauberData->GetAP();
224  G4int AT1 = glauberData->GetAT();
225  G4bool found = AP1==AP && AT1==AT;
226  if (found) {
227 //
228 //
229 // Keep the object and record in the index, or if there is insufficient
230 // space, record it only locally and set the usingLocalGlauberDataSet
231 // flag. In the latter case, the object is deleted after the call to
232 // G4DPMJET2_5Model.
233 //
234  theCurrentGlauberDataSet = glauberData;
235  if (CheckIfSpace()) {
236  G4int n = GetIndexID(AP,AT);
237  theIndex.insert (G4GlaubAADataSetIndex::value_type(n,glauberData));
238  cntGlauberDataSets++;
239  usingLocalGlauberDataSet = false;
240  if (verboseLevel >=2) {
241  G4cout <<"****************************************"
242  <<"****************************************"
243  <<G4endl;
244  G4cout <<"In G4GlaubAADataSetHandler::LoadGlauberDataReturnPtr"
245  <<G4endl;
246  G4cout <<"LOADED GLAUBER DATA SET FOR PROJECTILE A = " <<AP
247  <<" & TARGET A = " <<AT <<G4endl;
248  G4cout <<"AS RECORD NUMBER = " <<theIndex.size() <<G4endl;
249  G4cout <<"****************************************"
250  <<"****************************************"
251  <<G4endl;
252  }
253  }
254  else {
255  usingLocalGlauberDataSet = true;
256  if (verboseLevel >=2) {
257  G4cout <<"****************************************"
258  <<"****************************************"
259  <<G4endl;
260  G4cout <<"In G4GlaubAADataSetHandler::LoadGlauberDataReturnPtr"
261  <<G4endl;
262  G4cout <<"LOADED GLAUBER DATA SET FOR PROJECTILE A = " <<AP
263  <<" & TARGET A = " <<AT <<" TEMPORARILY" <<G4endl;
264  G4cout <<"****************************************"
265  <<"****************************************"
266  <<G4endl;
267  }
268  }
269  }
270  else {
271  G4cerr <<"WARNING IN G4GlaubAADataSetHandler::LoadGlauberData"
272  <<G4endl;
273  G4cerr <<"GLAUBER FILE " <<filename <<" LOOKED LIKE IT SHOULD CONTAIN"
274  <<G4endl;
275  G4cerr <<"DATA FOR AP = " <<AP <<" AND AT = " <<AT <<G4endl;
276  G4cerr <<"BUT CONTAINED AP = " <<AP1 <<" AND AT = " <<AT1 <<G4endl;
277  G4cerr <<G4endl;
278  delete glauberData;
279  glauberData = 0;
280  }
281  }
282  glauberFile.close();
283  }
284 
285  return glauberData;
286 }
287 ////////////////////////////////////////////////////////////////////////////////
288 //
289 // UnloadAllGlauberData
290 //
291 // Member function to delete all objects containg Glauber data. This is very
292 // easy since all of the objects are pointed to in the map "theIndex".
293 //
294 // The value returned is the number of data sets removed.
295 //
297 {
298  G4int n = 0;
299 
300  for (G4GlaubAADataSetIndex::iterator it=theIndex.begin(); it!=theIndex.end();
301  it++)
302  {
303  G4ParamType1GlaubAADataSet *glauberData = it->second;
304  cntGlauberDataSets--;
305  delete glauberData;
306  n++;
307  }
308  theIndex.clear();
309 
310  return n;
311 }
312 ////////////////////////////////////////////////////////////////////////////////
313 //
315  const G4int AT) const
316 {
317  G4int glauberID = GetIndexID (AP,AT);
318  G4GlaubAADataSetIndex::const_iterator it = theIndex.find(glauberID);
319  if (it == theIndex.end()) {
320  G4String glauberStrID = GetStringID(AP,AT);
321  G4String filename = glauberDataSetDir + "/" + glauberStrID +
322  ".glaubaadat";
323  std::ifstream glauberFile;
324  glauberFile.open(filename);
325  if (glauberFile) {
326  glauberFile.close();
327  return true;
328  }
329  else {
330  return false;
331  }
332  }
333 
334  return true;
335 }
336 ////////////////////////////////////////////////////////////////////////////////
337 //
338 // CheckIfSpace
339 //
340 // This member function reads the contents of the file GluaberIndex.dat,
341 // and then proceeds to read all Glauber functions. This can deal with both
342 // full Glauber data sets and parameterised data sets.
343 //
344 G4bool G4GlaubAADataSetHandler::CheckIfSpace () const
345 {
346  if ( maxGlauberDataSets >= 0 &&
347  ( (G4int) theIndex.size() ) >= maxGlauberDataSets) {
348  G4cout <<"WARNING: G4GlaubAADataSetHandler::CheckIfSpace:"
349  <<G4endl;
350  G4cout <<"MAXIMUM NUMBER OF GLAUBER DATASETS REACHED : "
351  <<maxGlauberDataSets <<G4endl;;
352  return false;
353  }
354 
355  return true;
356 }
357 ////////////////////////////////////////////////////////////////////////////////
358 //
359 // SetMaxGlauberDataSets
360 //
361 // This member function controls how many data sets are loaded, in order to
362 // avoid overloading the memory with data.
363 //
365 {
366  if (n > -1 && cntGlauberDataSets > n) {
367  G4cerr <<"ERROR IN G4GlaubAADataSetHandler::SetMaxGlauberDataSets"
368  <<G4endl;
369  G4cerr <<"MAXIMUM NUMBER OF GLAUBER DATA SETS WOULD BE EXCEEDED IF YOU"
370  <<G4endl;
371  G4cerr <<"SET THIS VALUE. ATTEMPTED TO SET TO " <<n
372  <<"WHEN VALUE ALREADY" <<cntGlauberDataSets
373  <<G4endl;
374  G4cerr <<G4endl;
375  }
376  else {
377  maxGlauberDataSets = n;
378  }
379 }
380 ////////////////////////////////////////////////////////////////////////////////
381 //
382 // SetCurrentGlauberDataSet
383 //
384 // Called from G4DPMJET2_5Model to identifies a pointer to the appropriate
385 // Glauber data set, based in the AP and AT provided. If the apprproate dataset
386 // is not already loaded, an attempt will be made to find it and load if there
387 // is space.
388 //
389 // true is returned if a data set has been found and loaded;
390 // false if returned otherwise.
391 //
393  const G4int AT, const G4double ppn)
394 {
395  G4int glauberID = GetIndexID (AP,AT);
396  G4GlaubAADataSetIndex::iterator it = theIndex.find(glauberID);
397  if (it == theIndex.end()) {
398 //
399 //
400 // Have we exceeded any limits for the maximum number of data sets loaded?
401 // If not, try to locate the data and load it.
402 //
403  theCurrentGlauberDataSet =
404  (G4ParamType1GlaubAADataSet*) LoadGlauberDataReturnPtr(AP,AT);
405  if (theCurrentGlauberDataSet != 0) {
406  ppnCurrent = ppn;
407 
408  dtumat_.rprojj[0] = theCurrentGlauberDataSet->rproj;
409  dtumat_.rtagg[0] = theCurrentGlauberDataSet->rtarg;
410  dtumat_.bstepp[0] = theCurrentGlauberDataSet->bstep;
411  dtumat_.bmaxx[0] = theCurrentGlauberDataSet->bmax;
412  return true;
413  }
414  else {
415  return false;
416  }
417  }
418  else {
419 //
420 //
421 // The data are already loaded, so point to this.
422 //
423  theCurrentGlauberDataSet = it->second;
424  ppnCurrent = ppn;
425 
426  dtumat_.rprojj[0] = theCurrentGlauberDataSet->rproj;
427  dtumat_.rtagg[0] = theCurrentGlauberDataSet->rtarg;
428  dtumat_.bstepp[0] = theCurrentGlauberDataSet->bstep;
429  dtumat_.bmaxx[0] = theCurrentGlauberDataSet->bmax;
430  return true;
431  }
432 }
433 ////////////////////////////////////////////////////////////////////////////////
434 //
436 {
437  return theCurrentGlauberDataSet;
438 }
439 ////////////////////////////////////////////////////////////////////////////////
440 //
442 {
443  if (usingLocalGlauberDataSet) delete theCurrentGlauberDataSet;
444  theCurrentGlauberDataSet = 0;
445  ppnCurrent = 0.0;
446  usingLocalGlauberDataSet = false;
447 }
448 ////////////////////////////////////////////////////////////////////////////////
449 //
451  const G4double ppn1)
452 {
453  G4double ppn = 0.0;
454  if (ppn1*GeV > 1.0*eV) ppn = ppn1;
455  else if (ppnCurrent*GeV > 1.0*eV) ppn = ppnCurrent;
456  else return 0.0;
457 
458  return
459  ((G4ParamType1GlaubAADataSet*) theCurrentGlauberDataSet)->GetValueN(v,ppn);
460 }
461 ////////////////////////////////////////////////////////////////////////////////
462 //
464  const G4double ppn1)
465 {
466  G4double ppn = 0.0;
467  if (ppn1*GeV > 1.0*eV) ppn = ppn1;
468  else if (ppnCurrent*GeV > 1.0*eV) ppn = ppnCurrent;
469  else return 0.0;
470 
471  return
472  ((G4ParamType1GlaubAADataSet*) theCurrentGlauberDataSet)->GetValueM(v,ppn);
473 }
474 ////////////////////////////////////////////////////////////////////////////////
475 //
476 #endif
G4bool IsGlauberDataSetAvailable(const G4int AP, const G4int AT) const
void SetMaxGlauberDataSets(const G4int n)
Definition of the G4ParamType1GlaubAADataSet class.
G4GlaubAADataSet * GetCurrentGlauberDataSet() const
Definition of the G4FullGlaubAADataSet class.
virtual ~G4GlaubAADataSetHandler()
int G4int
Definition: G4Types.hh:78
struct ccdpm25dtumat dtumat_
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
G4double GetValueN(const G4double v, const G4double ppn1=0.0)
G4double GetValueM(const G4double v, const G4double ppn1=0.0)
const G4int n
void SetVerboseLevel(const G4int i)
G4bool SetCurrentGlauberDataSet(const G4int AP, const G4int AT, const G4double ppn=0.0)
Definition of the G4DPMJET2_5Interface class.
#define G4endl
Definition: G4ios.hh:61
Definition of the G4GlaubAADataSetHandler class.
static G4GlaubAADataSetHandler * getInstance()
double G4double
Definition: G4Types.hh:76
G4GLOB_DLL std::ostream G4cerr