HybridXSecAlgorithm.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  For the class documentation see the corresponding header file.
8 */
9 //_________________________________________________________________________
10 
13 
14 using namespace genie;
15 
16 //_________________________________________________________________________
18 {
19 }
20 //_________________________________________________________________________
22  : XSecAlgorithmI("genie::HybridXSecAlgorithm", config)
23 {
24 }
25 //_________________________________________________________________________
27 {
28 }
29 //_________________________________________________________________________
31  const Interaction& interaction) const
32 {
33  std::string inter_str = interaction.AsString();
34  RgKey key = "XSecAlg@Interaction=" + inter_str;
35 
37  cend = fXSecAlgMap.cend();
38 
40  citer = fXSecAlgMap.find( key );
41 
42  // If the algorithm doesn't appear in the map, try to load it.
43  if ( citer == cend ) {
44 
45  // If a key exists for the algorithm in the registry, load it
46  // and store it for rapid retrieval later
47  const Registry& temp_reg = this->GetConfig();
48  if ( temp_reg.Exists(key) ) {
49  const XSecAlgorithmI* temp_alg = dynamic_cast< const XSecAlgorithmI* >(
50  this->SubAlg(key) );
51  assert( temp_alg );
52 
53  fXSecAlgMap[ inter_str ] = temp_alg;
54  return temp_alg;
55  }
56 
57  // Otherwise, if the user has specified a default algorithm, then store a
58  // new entry for that one in the map
59  else if ( fDefaultXSecAlg ) {
60  fXSecAlgMap[ inter_str ] = fDefaultXSecAlg;
61  return fDefaultXSecAlg;
62  }
63 
64  // Otherwise, store and return a null pointer. No suitable algorithm could
65  // be found for the requested interaction.
66  else {
67  fXSecAlgMap[ inter_str ] = NULL;
68  return NULL;
69  }
70 
71  }
72 
73  // If an entry was found in the map, then just use that
74  else return citer->second;
75 }
76 //_________________________________________________________________________
78  KinePhaseSpace_t kps) const
79 {
80  const XSecAlgorithmI* alg_to_use = this->ChooseXSecAlg( *interaction );
81 
82  if ( !alg_to_use ) return 0.;
83  else return alg_to_use->XSec( interaction, kps );
84 }
85 //_________________________________________________________________________
87 {
88  const XSecAlgorithmI* alg_to_use = this->ChooseXSecAlg( *interaction );
89 
90  if ( !alg_to_use ) return 0.;
91  else return alg_to_use->Integral( interaction );
92 }
93 //_________________________________________________________________________
95 {
96  if ( interaction->TestBit(kISkipProcessChk) ) return true;
97 
98  const XSecAlgorithmI* alg_to_use = this->ChooseXSecAlg( *interaction );
99  if ( !alg_to_use ) return false;
100  else return alg_to_use->ValidProcess( interaction );
101 }
102 //_________________________________________________________________________
104 {
105  Algorithm::Configure(config);
106  this->LoadConfig();
107 }
108 //____________________________________________________________________________
110 {
111  Algorithm::Configure(config);
112  this->LoadConfig();
113 }
114 //_________________________________________________________________________
116 {
117  fDefaultXSecAlg = NULL;
118 
119  // The user can optionally configure a cross section algorithm
120  // to use by default (i.e., whenever one wasn't explicitly specified
121  // for an input interaction). If one was given, then configure it.
122  // Handling of the interaction-specific algorithms is done via
123  // lazy initialization in ChooseXSecAlg().
124  const Registry& temp_reg = this->GetConfig();
125  if ( temp_reg.Exists("DefaultXSecAlg") ) {
126  fDefaultXSecAlg = dynamic_cast< const XSecAlgorithmI* >(
127  this->SubAlg("DefaultXSecAlg") );
128  assert( fDefaultXSecAlg );
129  }
130 }
Cross Section Calculation Interface.
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:87
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
std::string string
Definition: nybbler.cc:12
virtual double XSec(const Interaction *i, KinePhaseSpace_t k=kPSfE) const =0
Compute the cross section for the input interaction.
intermediate_table::const_iterator const_iterator
double XSec(const Interaction *i, KinePhaseSpace_t k) const
Compute the cross section for the input interaction.
enum genie::EKinePhaseSpace KinePhaseSpace_t
string AsString(void) const
virtual const Registry & GetConfig(void) const
Definition: Algorithm.cxx:246
Summary information for an interaction.
Definition: Interaction.h:56
bool ValidProcess(const Interaction *i) const
Can this cross section algorithm handle the input process?
def key(type, name=None)
Definition: graph.py:13
static Config * config
Definition: config.cpp:1054
virtual double Integral(const Interaction *i) const =0
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
const XSecAlgorithmI * ChooseXSecAlg(const Interaction &interaction) const
void Configure(const Registry &config)
string RgKey
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
std::map< string, const XSecAlgorithmI * > fXSecAlgMap
virtual bool ValidProcess(const Interaction *i) const =0
Can this cross section algorithm handle the input process?
bool Exists(RgKey key) const
item with input key exists?
Definition: Registry.cxx:563
const XSecAlgorithmI * fDefaultXSecAlg
Optional XSecAlgorithmI to use by default.
void LoadConfig(void)
Load algorithm configuration.
double Integral(const Interaction *i) const
const UInt_t kISkipProcessChk
if set, skip process validity checks
Definition: Interaction.h:47
const Algorithm * SubAlg(const RgKey &registry_key) const
Definition: Algorithm.cxx:345