GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HybridXSecAlgorithm.cxx
Go to the documentation of this file.
1 //_________________________________________________________________________
2 /*
3  Copyright (c) 2003-2024, 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 
36  std::map<std::string, const XSecAlgorithmI*>::const_iterator
37  cend = fXSecAlgMap.cend();
38 
39  std::map<std::string, const XSecAlgorithmI*>::const_iterator
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 //_________________________________________________________________________
77 double HybridXSecAlgorithm::XSec(const Interaction* interaction,
78  KinePhaseSpace_t kps) const
79 {
80  const XSecAlgorithmI* alg_to_use = this->ChooseXSecAlg( *interaction );
81 
82  if ( !alg_to_use ) return 0.;
83  // Ad hoc solution of problem with inappropriate kinematic phase space
84  // reported by Julia so she can continue working.
85  // (The reason of problem: it is intended for LlewelynSmith,
86  // BUT also used by Rosenbluth)
87  // A more thoughtful solutions could be
88  // 1. Specify in the configuration file the phase space appropriate
89  // for each algorithm
90  // 2. Implement in RosenbluthPXSec the analog of method
91  // LwlynSmithQELCCPXSec::FullDifferentialXSec - Igor Kakorin
92  if (alg_to_use == fDefaultXSecAlg) return alg_to_use->XSec( interaction, kps );
93  return alg_to_use->XSec( interaction, kPSQ2fE );
94 }
95 //_________________________________________________________________________
96 double HybridXSecAlgorithm::Integral(const Interaction* interaction) const
97 {
98  const XSecAlgorithmI* alg_to_use = this->ChooseXSecAlg( *interaction );
99 
100  if ( !alg_to_use ) return 0.;
101  else return alg_to_use->Integral( interaction );
102 }
103 //_________________________________________________________________________
104 bool HybridXSecAlgorithm::ValidProcess(const Interaction* interaction) const
105 {
106  if ( interaction->TestBit(kISkipProcessChk) ) return true;
107 
108  const XSecAlgorithmI* alg_to_use = this->ChooseXSecAlg( *interaction );
109  if ( !alg_to_use ) return false;
110  else return alg_to_use->ValidProcess( interaction );
111 }
112 //_________________________________________________________________________
114 {
115  Algorithm::Configure(config);
116  this->LoadConfig();
117 }
118 //____________________________________________________________________________
119 void HybridXSecAlgorithm::Configure(std::string config)
120 {
121  Algorithm::Configure(config);
122  this->LoadConfig();
123 }
124 //_________________________________________________________________________
126 {
127  fDefaultXSecAlg = NULL;
128 
129  // The user can optionally configure a cross section algorithm
130  // to use by default (i.e., whenever one wasn't explicitly specified
131  // for an input interaction). If one was given, then configure it.
132  // Handling of the interaction-specific algorithms is done via
133  // lazy initialization in ChooseXSecAlg().
134  const Registry& temp_reg = this->GetConfig();
135  if ( temp_reg.Exists("DefaultXSecAlg") ) {
136  fDefaultXSecAlg = dynamic_cast< const XSecAlgorithmI* >(
137  this->SubAlg("DefaultXSecAlg") );
138  assert( fDefaultXSecAlg );
139  }
140 }
Cross Section Calculation Interface.
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?
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
const XSecAlgorithmI * ChooseXSecAlg(const Interaction &interaction) const
void Configure(const Registry &config)
virtual bool ValidProcess(const Interaction *i) const =0
Can this cross section algorithm handle the input process?
virtual double XSec(const Interaction *i, KinePhaseSpace_t k=kPSfE) const =0
Compute the cross section for the input interaction.
string RgKey
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
std::map< string, const XSecAlgorithmI * > fXSecAlgMap
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
virtual double Integral(const Interaction *i) const =0
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