XSecLinearCombinations.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  Original code contributed by J. Schwehr, D. Cherdack, R. Gran
7  Substantial code refactorizations by the core GENIE group.
8 */
9 //_________________________________________________________________________
10 
14 
15 using namespace genie;
16 
17 //_________________________________________________________________________
19  XSecAlgorithmI("genie::XSecLinearCombinations")
20 {
21 
22 }
23 //_________________________________________________________________________
25  XSecAlgorithmI("genie::XSecLinearCombinations", config)
26 {
27 
28 }
29 //_________________________________________________________________________
31 {
32 
33 }
34 
35 //_________________________________________________________________________
36 
38  const Interaction * interaction, KinePhaseSpace_t kps) const
39 {
40  double xsec = 0 ;
41  // Store xsec prediction for each entry :
42  for( unsigned int i = 0 ; i < fXSections.size() ; ++ i ) {
43  if( fXSections[i] -> ValidKinematics( interaction ) ) {
44  xsec += ( fXSections[i] -> XSec( interaction, kps ) ) * fLinearCoefficients[i] ;
45  }
46  }
47 
48  return xsec;
49 }
50 
51 //_________________________________________________________________________
52 
54 {
55 
56  double xsec = 0 ;
57  // Store xsec prediction for each entry :
58  for( unsigned int i = 0 ; i < fXSections.size() ; ++ i ) {
59  xsec += ( fXSections[i] -> Integral( interaction ) ) * fLinearCoefficients[i] ;
60  }
61 
62  return xsec;
63 }
64 
65 //_________________________________________________________________________
66 
68 {
69  bool is_valid = true ;
70 
71  // CHECK THAT THE XSEC USED CONSIDER A VALID PROCESS
72  for( unsigned int i = 0 ; i < fXSections.size() ; ++ i ) {
73  if( ! fXSections[i] -> ValidProcess( interaction ) ) {
74  is_valid = false ;
75  break ;
76  }
77  }
78 
79  return is_valid ;
80 }
81 
82 //_________________________________________________________________________
83 
85 {
86  Algorithm::Configure(config);
87  this->LoadConfig();
88 }
89 
90 //____________________________________________________________________________
91 
93 {
94  Algorithm::Configure(config);
95  this->LoadConfig();
96 }
97 
98 //_________________________________________________________________________
99 
101 {
102  bool good_config = true ;
103  GetParamVect( "LinearCoefficients", fLinearCoefficients ) ;
104 
105  bool Normalise = false ;
106  GetParam( "Normalise", Normalise ) ;
107 
108  if( Normalise ) {
109  double sum = 0 ;
110  for( unsigned int i = 0 ; i < fLinearCoefficients.size() ; ++i ) {
111  sum += fLinearCoefficients[i] ;
112  }
113 
114  if( sum == 0 ) {
115  good_config = false ;
116  LOG("XSecLinearCombinations", pERROR) << "Sum of linear coefficients is zero. Cannot normalize " ;
117  }
118 
119  for( unsigned int j = 0 ; j < fLinearCoefficients.size() ; ++j ) {
120  fLinearCoefficients[j] /= sum ;
121  }
122  }
123 
124  std::vector<RgKey> XSectionsKeys ;
125  GetParamVectKeys( "CrossSection", XSectionsKeys ) ;
126 
127  if( XSectionsKeys.size() != fLinearCoefficients.size() ) {
128  good_config = false ;
129  LOG("XSecLinearCombinations", pERROR) << "Entries don't match" ;
130  LOG("XSecLinearCombinations", pERROR) << "Cross Sections size: " << XSectionsKeys.size() ;
131  LOG("XSecLinearCombinations", pERROR) << "Linear Coefficients size: " << fLinearCoefficients.size() ;
132  }
133 
134  for( unsigned int i = 0 ; i < XSectionsKeys.size() ; ++i ) {
135  fXSections.push_back( dynamic_cast<const XSecAlgorithmI *> ( this->SubAlg( XSectionsKeys[i] ) ) );
136  if ( ! fXSections[i] ) {
137  good_config = false ;
138  LOG("XSecLinearCombinations", pERROR) << "The SubAlg is not a XSecAlgorithmI";
139  }
140  }
141 
142  if( ! good_config ) {
143  LOG("XSecLinearCombinations", pERROR) << "XSecLinearCombilation Configuration has failed.";
144  exit(78) ;
145  }
146 
147 }
Cross Section Calculation Interface.
double XSec(const Interaction *i, KinePhaseSpace_t k) const
Compute the cross section for the input interaction.
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
#define pERROR
Definition: Messenger.h:59
int GetParamVect(const std::string &comm_name, std::vector< T > &v, bool is_top_call=true) const
Handle to load vectors of parameters.
enum genie::EKinePhaseSpace KinePhaseSpace_t
double Integral(const Interaction *i) const
bool ValidProcess(const Interaction *i) const
Can this cross section algorithm handle the input process?
std::vector< double > fLinearCoefficients
void Configure(const Registry &config)
Summary information for an interaction.
Definition: Interaction.h:56
virtual bool ValidKinematics(const Interaction *i) const
Is the input kinematical point a physically allowed one?
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
constexpr bool is_valid(IDNumber_t< L > const id) noexcept
Definition: IDNumber.h:113
static Config * config
Definition: config.cpp:1054
virtual void Configure(const Registry &config)
Definition: Algorithm.cxx:62
std::vector< const XSecAlgorithmI * > fXSections
A registry. Provides the container for algorithm configuration parameters.
Definition: Registry.h:65
int GetParamVectKeys(const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
Definition: Algorithm.cxx:528
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
const Algorithm * SubAlg(const RgKey &registry_key) const
Definition: Algorithm.cxx:345