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