ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4MaterialPropertiesTable.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4MaterialPropertiesTable.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 //
30 // G4MaterialPropertiesTable Implementation
32 //
33 // File: G4MaterialPropertiesTable.cc
34 // Version: 1.0
35 // Created: 1996-02-08
36 // Author: Juliet Armstrong
37 // Updated: 2005-05-12 add SetGROUPVEL(), courtesy of
38 // Horton-Smith (bug report #741), by P. Gumplinger
39 // 2002-11-05 add named material constants by P. Gumplinger
40 // 1999-11-05 Migration from G4RWTPtrHashDictionary to STL
41 // by John Allison
42 // 1997-03-26 by Peter Gumplinger
43 // > cosmetics (only)
44 // mail: gum@triumf.ca
45 //
47 
48 #include "globals.hh"
50 #include "G4PhysicalConstants.hh"
51 #include "G4Log.hh"
52 
53 #include <algorithm>
54 
56 // Constructors
58 
60 {
61  // elements of these 2 vectors must be in same order as
62  // the corresponding enums in G4MaterialPropertiesIndex.hh
63  G4MaterialPropertyName.push_back(G4String("RINDEX"));
64  G4MaterialPropertyName.push_back(G4String("REFLECTIVITY"));
65  G4MaterialPropertyName.push_back(G4String("REALRINDEX"));
66  G4MaterialPropertyName.push_back(G4String("IMAGINARYRINDEX"));
67  G4MaterialPropertyName.push_back(G4String("EFFICIENCY"));
68  G4MaterialPropertyName.push_back(G4String("TRANSMITTANCE"));
69  G4MaterialPropertyName.push_back(G4String("SPECULARLOBECONSTANT"));
70  G4MaterialPropertyName.push_back(G4String("SPECULARSPIKECONSTANT"));
71  G4MaterialPropertyName.push_back(G4String("BACKSCATTERCONSTANT"));
72  G4MaterialPropertyName.push_back(G4String("GROUPVEL"));
73  G4MaterialPropertyName.push_back(G4String("MIEHG"));
74  G4MaterialPropertyName.push_back(G4String("RAYLEIGH"));
75  G4MaterialPropertyName.push_back(G4String("WLSCOMPONENT"));
76  G4MaterialPropertyName.push_back(G4String("WLSABSLENGTH"));
77  G4MaterialPropertyName.push_back(G4String("ABSLENGTH"));
78  G4MaterialPropertyName.push_back(G4String("FASTCOMPONENT"));
79  G4MaterialPropertyName.push_back(G4String("SLOWCOMPONENT"));
80  G4MaterialPropertyName.push_back(G4String("PROTONSCINTILLATIONYIELD"));
81  G4MaterialPropertyName.push_back(G4String("DEUTERONSCINTILLATIONYIELD"));
82  G4MaterialPropertyName.push_back(G4String("TRITONSCINTILLATIONYIELD"));
83  G4MaterialPropertyName.push_back(G4String("ALPHASCINTILLATIONYIELD"));
84  G4MaterialPropertyName.push_back(G4String("IONSCINTILLATIONYIELD"));
85  G4MaterialPropertyName.push_back(G4String("ELECTRONSCINTILLATIONYIELD"));
86 
87  G4MaterialConstPropertyName.push_back(G4String("SURFACEROUGHNESS"));
88  G4MaterialConstPropertyName.push_back(G4String("ISOTHERMAL_COMPRESSIBILITY"));
89  G4MaterialConstPropertyName.push_back(G4String("RS_SCALE_FACTOR"));
90  G4MaterialConstPropertyName.push_back(G4String("WLSMEANNUMBERPHOTONS"));
91  G4MaterialConstPropertyName.push_back(G4String("WLSTIMECONSTANT"));
92  G4MaterialConstPropertyName.push_back(G4String("MIEHG_FORWARD"));
93  G4MaterialConstPropertyName.push_back(G4String("MIEHG_BACKWARD"));
94  G4MaterialConstPropertyName.push_back(G4String("MIEHG_FORWARD_RATIO"));
95  G4MaterialConstPropertyName.push_back(G4String("SCINTILLATIONYIELD"));
96  G4MaterialConstPropertyName.push_back(G4String("RESOLUTIONSCALE"));
97  G4MaterialConstPropertyName.push_back(G4String("FASTTIMECONSTANT"));
98  G4MaterialConstPropertyName.push_back(G4String("FASTSCINTILLATIONRISETIME"));
99  G4MaterialConstPropertyName.push_back(G4String("SLOWTIMECONSTANT"));
100  G4MaterialConstPropertyName.push_back(G4String("SLOWSCINTILLATIONRISETIME"));
101  G4MaterialConstPropertyName.push_back(G4String("YIELDRATIO"));
102  G4MaterialConstPropertyName.push_back(G4String("FERMIPOT"));
103  G4MaterialConstPropertyName.push_back(G4String("DIFFUSION"));
104  G4MaterialConstPropertyName.push_back(G4String("SPINFLIP"));
105  G4MaterialConstPropertyName.push_back(G4String("LOSS"));
106  G4MaterialConstPropertyName.push_back(G4String("LOSSCS"));
107  G4MaterialConstPropertyName.push_back(G4String("ABSCS"));
108  G4MaterialConstPropertyName.push_back(G4String("SCATCS"));
109  G4MaterialConstPropertyName.push_back(G4String("MR_NBTHETA"));
110  G4MaterialConstPropertyName.push_back(G4String("MR_NBE"));
111  G4MaterialConstPropertyName.push_back(G4String("MR_RRMS"));
112  G4MaterialConstPropertyName.push_back(G4String("MR_CORRLEN"));
113  G4MaterialConstPropertyName.push_back(G4String("MR_THETAMIN"));
114  G4MaterialConstPropertyName.push_back(G4String("MR_THETAMAX"));
115  G4MaterialConstPropertyName.push_back(G4String("MR_EMIN"));
116  G4MaterialConstPropertyName.push_back(G4String("MR_EMAX"));
117  G4MaterialConstPropertyName.push_back(G4String("MR_ANGNOTHETA"));
118  G4MaterialConstPropertyName.push_back(G4String("MR_ANGNOPHI"));
119  G4MaterialConstPropertyName.push_back(G4String("MR_ANGCUT"));
120 }
121 
123 // Destructor
125 
127 {
128  MPTiterator i;
129  for (i = MPT.begin(); i != MPT.end(); ++i)
130  {
131  delete (*i).second;
132  }
133  MPT.clear();
134  MPTC.clear();
135 
136  MPiterator it;
137  for (it = MP.begin(); it != MP.end(); ++it)
138  {
139  delete (*it).second;
140  }
141  MP.clear();
142  MCP.clear();
143 
144  G4MaterialPropertyName.clear();
146 }
147 
149 // Methods
151 
153  G4bool warning) const
154 {
155  // Returns the constant material property index corresponding to a key
156 
157  size_t index = std::distance(G4MaterialConstPropertyName.begin(),
158  std::find(G4MaterialConstPropertyName.begin(),
159  G4MaterialConstPropertyName.end(), key));
160  if(index < G4MaterialConstPropertyName.size()) return index;
161  if (warning) {
163  ed << "Constant Material Property Index for key " << key << " not found.";
164  G4Exception("G4MaterialPropertiesTable::GetConstPropertyIndex()","mat206",
165  JustWarning, ed);
166  }
167  return -1;
168 }
169 
171  G4bool warning) const
172 {
173  // Returns the material property index corresponding to a key
174  size_t index = std::distance(G4MaterialPropertyName.begin(),
175  std::find(G4MaterialPropertyName.begin(),
176  G4MaterialPropertyName.end(), key));
177  if(index < G4MaterialPropertyName.size()) return index;
178  if (warning) {
180  ed << "Material Property Index for key " << key << " not found.";
181  G4Exception("G4MaterialPropertiesTable::GetPropertyIndex()","mat207",
182  JustWarning, ed);
183  }
184  return -1;
185 }
186 
188 {
189  // Returns the constant material property corresponding to an index
190  // fatal exception if property not found
191 
192  MCPiterator j;
193  j = MCP.find(index);
194  if ( j != MCP.end() ) return j->second;
196  ed << "Constant Material Property Index " << index << " not found.";
197  G4Exception("G4MaterialPropertiesTable::GetConstProperty()","mat202",
198  FatalException, ed);
199  return 0.;
200 }
201 
203 {
204  // Returns the constant material property corresponding to a key
205  // fatal exception if property not found
206 
207  const G4int index = GetConstPropertyIndex(G4String(key));
208  return GetConstProperty(index);
209 }
210 
212 {
213  // Returns true if a const property 'key' exists
214  const G4int index = GetConstPropertyIndex(G4String(key));
215 
216  MCPiterator j;
217  j = MCP.find(index);
218  if ( j != MCP.end() ) return true;
219  return false;
220 }
221 
224 {
225  // Returns a Material Property Vector corresponding to a key
226  const G4int index = GetPropertyIndex(G4String(key), warning);
227  return GetProperty(index);
228 }
229 
232 {
233  // Returns a Material Property Vector corresponding to an index
234  MPiterator i;
235  i = MP.find(index);
236  if ( i != MP.end() ) return i->second;
237  if (warning) {
239  ed << "Material Property for index " << index << " not found.";
240  G4Exception("G4MaterialPropertiesTable::GetPropertyIndex()","mat208",
241  JustWarning, ed);
242  }
243  return nullptr;
244 }
245 
247  const char *key,
248  G4double *PhotonEnergies,
249  G4double *PropertyValues,
250  G4int NumEntries)
251 {
252  // Provides a way of adding a property to the Material Properties
253  // Table given a pair of numbers and a key
254  G4String k(key);
255  // if the key doesn't exist, add it
256  if (std::find(G4MaterialPropertyName.begin(),
257  G4MaterialPropertyName.end(), k) ==
258  G4MaterialPropertyName.end()) {
259  G4MaterialPropertyName.push_back(k);
260  }
261  G4int index = GetPropertyIndex(k);
262 
263  G4MaterialPropertyVector *mpv = new G4MaterialPropertyVector(PhotonEnergies,
264  PropertyValues, NumEntries);
265  MP[index] = mpv;
266 
267  // if key is RINDEX, we calculate GROUPVEL -
268  // contribution from Tao Lin (IHEP, the JUNO experiment)
269  if (k=="RINDEX") {
271  }
272 
273  return mpv;
274 }
275 
277 AddProperty(const char *key, G4MaterialPropertyVector *mpv)
278 {
279  // Provides a way of adding a property to the Material Properties
280  // Table given an G4MaterialPropertyVector Reference and a key
281  G4String k(key);
282  // if the key doesn't exist, add it
283  if (std::find(G4MaterialPropertyName.begin(),
284  G4MaterialPropertyName.end(), k) ==
285  G4MaterialPropertyName.end()) {
286  G4MaterialPropertyName.push_back(k);
287  }
288  G4int index = GetPropertyIndex(k);
289  MP[ index ] = mpv;
290 
291  // if key is RINDEX, we calculate GROUPVEL -
292  // contribution from Tao Lin (IHEP, the JUNO experiment)
293  if (k=="RINDEX") {
295  }
296 }
297 
299  G4double aPhotonEnergy,
300  G4double aPropertyValue)
301 {
302  // Allows to add an entry pair directly to the Material Property Vector
303  // given a key
304  G4String k(key);
305  if (std::find(G4MaterialPropertyName.begin(),
306  G4MaterialPropertyName.end(), k) ==
307  G4MaterialPropertyName.end()) {
308  G4MaterialPropertyName.push_back(k);
309  }
310  G4int index = GetPropertyIndex(k);
311 
312  G4MaterialPropertyVector *targetVector=MP[index];
313  if (targetVector != nullptr)
314  {
315  targetVector->InsertValues(aPhotonEnergy, aPropertyValue);
316  }
317  else
318  {
319  G4Exception("G4MaterialPropertiesTable::AddEntry()", "mat203",
320  FatalException, "Material Property Vector not found.");
321  }
322 }
323 
325 {
326  // material properties
327  MPiterator i;
328  for (i = MP.begin(); i != MP.end(); ++i)
329  {
330  G4cout << (*i).first << ": "<< G4MaterialPropertyName[(*i).first] <<G4endl;
331  if ( (*i).second != 0 )
332  {
333  (*i).second->DumpValues();
334  }
335  else
336  {
337  G4Exception("G4MaterialPropertiesTable::DumpTable()", "mat204",
338  JustWarning, "NULL Material Property Vector Pointer.");
339  }
340  }
341  // material constant properties
342  MCPiterator j;
343  for (j = MCP.begin(); j != MCP.end(); ++j)
344  {
345  G4cout << j->first <<": "<< G4MaterialConstPropertyName[j->first] <<G4endl;
346  if ( j->second != 0 )
347  {
348  G4cout << j->second << G4endl;
349  }
350  else
351  {
352  G4Exception("G4MaterialPropertiesTable::DumpTable()", "mat202",
353  JustWarning, "No Material Constant Property.");
354  }
355  }
356 }
357 
358 #ifdef G4MULTITHREADED
359 #include "G4AutoLock.hh"
360 namespace {
361  G4Mutex materialPropertyTableMutex = G4MUTEX_INITIALIZER;
362 }
363 #endif
364 
366 {
367 #ifdef G4MULTITHREADED
368  G4AutoLock mptm(&materialPropertyTableMutex);
369 #endif
370  // reconsider (i.e, remove) above mutex as this method is likely called only
371  // when RINDEX is added during the detector construction phase (i.e., adding
372  // meterials properties into geometry) on the master thread (Oct. 2017, SYJ)
373 
374  // check if "GROUPVEL" already exists
375  MPiterator itr;
376  itr = MP.find(kGROUPVEL);
377  if(itr != MP.end()) return itr->second;
378 
379  // fetch RINDEX data, give up if unavailable
380  //
381  G4MaterialPropertyVector *rindex = this->GetProperty(kRINDEX);
382  if (rindex==0) { return 0; }
383 
384  // RINDEX exists but has no entries, give up
385  //
386  if ( rindex->GetVectorLength() == 0 ) { return 0; }
387 
388  // add GROUPVEL vector
389  //
391 
392  // fill GROUPVEL vector using RINDEX values
393  // rindex built-in "iterator" was advanced to first entry above
394  //
395  G4double E0 = rindex->Energy(0);
396  G4double n0 = (*rindex)[0];
397 
398  if (E0 <= 0.)
399  {
400  G4Exception("G4MaterialPropertiesTable::CalculateGROUPVEL()", "mat205",
401  FatalException, "Optical Photon Energy <= 0");
402  }
403 
404  if ( rindex->GetVectorLength() >= 2 )
405  {
406  // good, we have at least two entries in RINDEX
407  // get next energy/value pair
408 
409  G4double E1 = rindex->Energy(1);
410  G4double n1 = (*rindex)[1];
411 
412  if (E1 <= 0.)
413  {
414  G4Exception("G4MaterialPropertiesTable::CalculateGROUPVEL()", "mat205",
415  FatalException, "Optical Photon Energy <= 0");
416  }
417 
418  G4double vg;
419 
420  // add entry at first photon energy
421  //
422  vg = c_light/(n0+(n1-n0)/G4Log(E1/E0));
423 
424  // allow only for 'normal dispersion' -> dn/d(logE) > 0
425  //
426  if((vg<0) || (vg>c_light/n0)) { vg = c_light/n0; }
427 
428  groupvel->InsertValues( E0, vg );
429 
430  // add entries at midpoints between remaining photon energies
431  //
432 
433  for (size_t i = 2; i < rindex->GetVectorLength(); i++)
434  {
435  vg = c_light/( 0.5*(n0+n1)+(n1-n0)/G4Log(E1/E0));
436 
437  // allow only for 'normal dispersion' -> dn/d(logE) > 0
438  //
439  if((vg<0) || (vg>c_light/(0.5*(n0+n1)))) { vg = c_light/(0.5*(n0+n1)); }
440  groupvel->InsertValues( 0.5*(E0+E1), vg );
441 
442  // get next energy/value pair, or exit loop
443  //
444  E0 = E1;
445  n0 = n1;
446  E1 = rindex->Energy(i);
447  n1 = (*rindex)[i];
448 
449  if (E1 <= 0.)
450  {
451  G4Exception("G4MaterialPropertiesTable::CalculateGROUPVEL()", "mat205",
452  FatalException, "Optical Photon Energy <= 0");
453  }
454  }
455 
456  // add entry at last photon energy
457  //
458  vg = c_light/(n1+(n1-n0)/G4Log(E1/E0));
459 
460  // allow only for 'normal dispersion' -> dn/d(logE) > 0
461  //
462  if((vg<0) || (vg>c_light/n1)) { vg = c_light/n1; }
463  groupvel->InsertValues( E1, vg );
464  }
465  else // only one entry in RINDEX -- weird!
466  {
467  groupvel->InsertValues( E0, c_light/n0 );
468  }
469 
470  this->AddProperty( "GROUPVEL", groupvel );
471 
472  return groupvel;
473 }
474 
476 {
477  G4String message("SetGROUPVEL will be obsolete from the next release ");
478  message += "Use G4MaterialPropertiesTable::CalculateGROUPVEL() instead";
479 
480  G4Exception("G4MaterialPropertiesTable::SetGROUPVEL()", "Obsolete",
481  JustWarning, message);
482  return CalculateGROUPVEL();
483 }
484 
485 std::map< G4String, G4MaterialPropertyVector*, std::less<G4String> >*
487 {
488  // warning message
489  G4String message("GetPropertiesMap will be obsolete from the next release ");
490  message += "Use G4MaterialPropertiesTable::GetPropertyMap() instead";
491  G4Exception("G4MaterialPropertiesTable::GetPropertiesMap()", "Obsolete",
492  JustWarning, message);
493 
494  for (MPiterator miter = MP.begin(); miter != MP.end(); miter++)
495  {
496  if(miter->second) {
497  MPT [ G4MaterialPropertyName[miter->first] ] = miter->second;
498  }
499  else {
500  G4Exception("G4MaterialPropertiesTable::GetPropertiesMap()","NullPointer",
501  JustWarning, "Null Pointer for Material Property");
502  continue;
503  }
504  }
505  return &MPT;
506 }
507 
508 std::map< G4String, G4double, std::less<G4String> >* G4MaterialPropertiesTable::GetPropertiesCMap()
509 {
510  // warning message
511  G4String message("GetPropertiesCMap will be obsolete from the next release ");
512  message += "Use G4MaterialPropertiesTable::GetConstPropertyMap() instead";
513  G4Exception("G4MaterialPropertiesTable::GetPropertiesCMap()", "Obsolete",
514  JustWarning, message);
515 
516  for (MCPiterator miter = MCP.begin(); miter != MCP.end(); miter++) {
517  MPTC[ G4MaterialConstPropertyName[miter->first] ] = miter->second;
518  }
519  return &MPTC;
520 }
521 
523 {
524  return G4MaterialPropertyName;;
525 }
526 
528 {
530 }