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