GENIEGenerator
Loading...
Searching...
No Matches
XSecLinearCombinations.cxx
Go to the documentation of this file.
1//_________________________________________________________________________
2/*
3 Copyright (c) 2003-2025, 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
15using namespace genie;
16
17//_________________________________________________________________________
19 XSecAlgorithmI("genie::XSecLinearCombinations")
20{
21
22}
23//_________________________________________________________________________
25 XSecAlgorithmI("genie::XSecLinearCombinations", config)
26{
27
28}
29//_________________________________________________________________________
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
53double XSecLinearCombinations::Integral( const Interaction * interaction ) const
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
67bool XSecLinearCombinations::ValidProcess( const Interaction * interaction) const
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{
87 this->LoadConfig();
88}
89
90//____________________________________________________________________________
91
93{
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}
#define pERROR
Definition Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
int GetParamVectKeys(const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
int GetParamVect(const std::string &comm_name, std::vector< T > &v, bool is_top_call=true) const
Handle to load vectors of parameters.
virtual void Configure(const Registry &config)
Definition Algorithm.cxx:62
const Algorithm * SubAlg(const RgKey &registry_key) const
Summary information for an interaction.
Definition Interaction.h:56
A registry. Provides the container for algorithm configuration parameters.
Definition Registry.h:65
virtual bool ValidKinematics(const Interaction *i) const
Is the input kinematical point a physically allowed one?
std::vector< const XSecAlgorithmI * > fXSections
std::vector< double > fLinearCoefficients
bool ValidProcess(const Interaction *i) const
Can this cross section algorithm handle the input process?
void Configure(const Registry &config)
double Integral(const Interaction *i) const
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
enum genie::EKinePhaseSpace KinePhaseSpace_t