ConfigIsotopeMapUtils.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*
3  Copyright (c) 2003-2019, The GENIE Collaboration
4  For the full text of the license visit http://copyright.genie-mc.org
5  or see $GENIE/LICENSE
6 
7  Author: Brian Coopersmith, University of Rochester
8 
9  For documentation see the corresponding header file.
10 
11 */
12 //____________________________________________________________________________
13 
15 
20 
21 using namespace std;
22 
23 namespace genie {
24 namespace utils {
25 namespace config {
26 
27 //____________________________________________________________________________
28 // Given a map of nucleus PDGs to values and ranges of nucleus As to values,
29 // return the value for the supplied target. Individual nucleus maps take
30 // precedence over the range maps.
31 //____________________________________________________________________________
33  const Target& target, const map<int, double>& nuc_to_val,
34  const map<pair<int, int>, double>& nucA_range_to_val,
35  double* val) {
36  const int pdgc = pdg::IonPdgCode(target.A(), target.Z());
37  map<int, double>::const_iterator nuc_it = nuc_to_val.find(pdgc);
38  if(nuc_it != nuc_to_val.end()) {
39  *val = nuc_it->second;
40  return true;
41  }
42  map<pair<int, int>, double>::const_iterator range_it =
43  nucA_range_to_val.begin();
44  for(; range_it != nucA_range_to_val.end(); ++range_it) {
45  if (target.A() >= range_it->first.first &&
46  target.A() <= range_it->first.second) {
47  *val = range_it->second;
48  return true;
49  }
50  }
51  return false;
52 }
53 //____________________________________________________________________________
54 // Read in from the config file all listed NucA range parameters for a given
55 // key. Valid for As up to 419. Stores them in the map from
56 // pair(lowA, highA) to value.
57 //____________________________________________________________________________
58 void LoadAllNucARangesForKey(const char* key_name, const char* log_tool_name,
60  map<pair<int, int>, double>* nuc_rangeA_to_val) {
61  for (int lowA = 1; lowA < 3 * 140; lowA++) {
62  for (int highA = lowA; highA < 3 * 140; highA++) {
63  double val;
64  if (GetDoubleKeyRangeNucA(key_name, lowA, highA, config, &val)) {
65  LOG(log_tool_name, pINFO) << "For "<< lowA - 1 <<" < A < " <<
66  highA + 1 << " -> using " << key_name << " = " << val;
67  (*nuc_rangeA_to_val)[pair<int, int>(lowA, highA)] = val;
68  }
69  }
70  }
71 }
72 //____________________________________________________________________________
73 // Read in from the config file all listed NucZ range parameters for a given
74 // key. Valid for Zs up to 139 and As up to 3*Z. Stores them in the map from
75 // PDG code to value.
76 //____________________________________________________________________________
77 void LoadAllIsotopesForKey(const char* key_name, const char* log_tool_name,
78  Registry* config, map<int, double>* nuc_to_val) {
79  for (int Z = 1; Z < 140; Z++) {
80  for (int A = Z; A < 3 * Z; A++) {
81  const int pdgc = pdg::IonPdgCode(A, Z);
82  double val;
83  if(GetDoubleKeyPDG(key_name, pdgc, config, &val)) {
84  LOG(log_tool_name, pINFO) << "Nucleus: " << pdgc <<
85  " -> using " << key_name << " = " << val;
86  (*nuc_to_val)[pdgc] = val;
87  }
88  }
89  }
90 }
91 //____________________________________________________________________________
92 // Check if the key <valName>@Pdg=<pdgc> exists in config. If so, load that
93 // into val, and return true. Otherwise return false.
94 //____________________________________________________________________________
95 bool GetDoubleKeyPDG(const char* valName, const int pdgc,
96  Registry* config, double* val)
97 {
98  ostringstream s;
99  s<<valName<<"@Pdg="<<pdgc;
100  RgKey key = s.str();
101  if(!config->Exists(key)) {
102  return false;
103  }
104  *val = config->GetDoubleDef(key,0);
105  return true;
106 }
107 //____________________________________________________________________________
108 // Check if the key <valName>@LowA=<lowA>;HighA=<highA> exists in config. If
109 // so load that into val and return true. Otherwise return false.
110 //____________________________________________________________________________
111 bool GetDoubleKeyRangeNucA(const char* valName, const int lowA,
112  const int highA, Registry* config, double* val)
113 {
114  ostringstream s;
115  s<<valName<<"@LowA="<<lowA<<";HighA="<<highA;
116  RgKey key = s.str();
117  if(!config->Exists(key)) {
118  return false;
119  }
120  *val = config->GetDoubleDef(key,0);
121  return true;
122 }
123 
124 } // namespace config
125 } // namespace utils
126 } // namespace genie
RgDbl GetDoubleDef(RgKey key, RgDbl def_opt, bool set_def=true)
Definition: Registry.cxx:550
const XML_Char * target
Definition: expat.h:268
THE MAIN GENIE PROJECT NAMESPACE
Definition: GeneratorBase.h:8
int A(void) const
Definition: Target.h:71
Definition: config.py:1
Float_t Z
Definition: plot.C:38
void LoadAllIsotopesForKey(const char *key_name, const char *log_tool_name, Registry *config, map< int, double > *nuc_to_val)
const XML_Char * s
Definition: expat.h:262
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:97
A Neutrino Interaction Target. Is a transparent encapsulation of quite different physical systems suc...
Definition: Target.h:41
int Z(void) const
Definition: Target.h:69
#define pINFO
Definition: Messenger.h:63
static const double A
Definition: Units.h:82
bool GetValueFromNuclearMaps(const Target &target, const map< int, double > &nuc_to_val, const map< pair< int, int >, double > &nucA_range_to_val, double *val)
string RgKey
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:66
bool GetDoubleKeyRangeNucA(const char *valName, const int lowA, const int highA, Registry *config, double *val)
int IonPdgCode(int A, int Z)
Definition: PDGUtils.cxx:69
bool Exists(RgKey key) const
item with input key exists?
Definition: Registry.cxx:578
bool GetDoubleKeyPDG(const char *valName, const int pdgc, Registry *config, double *val)
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
void LoadAllNucARangesForKey(const char *key_name, const char *log_tool_name, Registry *config, map< pair< int, int >, double > *nuc_rangeA_to_val)