XSecScaleMap.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.Tena and M.Roda
7  Substantial code refactorizations by the core GENIE group.
8 */
9 //_________________________________________________________________________
10 
16 
17 using namespace genie;
18 
19 //_________________________________________________________________________
21  XSecScaleI("genie::XSecScaleMap")
22 {
23 
24 }
25 //_________________________________________________________________________
27  XSecScaleI("genie::XSecScaleMap",config)
28 {
29 
30 }
31 //_________________________________________________________________________
33 {
34 
35 }
36 //_________________________________________________________________________
38  // This function accesses the requested Algoritm given the Pdg code and
39  // it retrieves the appropiate scaling.
40  // Get Target pdg
41  int pdg_target = interaction.InitState().Tgt().Pdg() ;
42 
43  const auto it = fXSecScaleMap.find(pdg_target) ;
44  if ( it != fXSecScaleMap.end() ) {
45  return (it -> second)->GetScaling( interaction ) ;
46  }
47  if ( fXSecScaleDefault ) {
48  // return default
49  return fXSecScaleDefault->GetScaling( interaction ) ;
50  }
51  return 1. ;
52 
53 }
54 
55 //_________________________________________________________________________
56 
58 {
59  bool good_config = true ;
60  fXSecScaleDefault = nullptr ;
61  fXSecScaleMap.clear() ;
62 
63  // Store default value
64  static RgKey default_algo_name = "XSecScaleDefaultAlg" ;
65  if( GetConfig().Exists(default_algo_name) ) {
66  fXSecScaleDefault = dynamic_cast<const XSecScaleI *> ( this->SubAlg(default_algo_name) );
67  if( !fXSecScaleDefault ) {
68  good_config = false ;
69  LOG("XSecScaleMap", pERROR) << "The subalgorithm with ID couldn't be casted " ;
70  // << SubAlg(default_algo_name)->Id() << " couldn't be casted " ;
71  }
72 
73  }
74 
75  // Get possible entries to pdg - shift map
76  auto kpdg_list = GetConfig().FindKeys("XSecScaleAlg@Pdg=") ;
77 
78  for( auto kiter = kpdg_list.begin(); kiter != kpdg_list.end(); ++kiter ) {
79  const RgKey & key = *kiter ;
80  vector<string> kv = genie::utils::str::Split(key,"=");
81  assert(kv.size()==2);
82  int pdg_target = stoi( kv[1] );
83  if( ! PDGLibrary::Instance()->Find(pdg_target) ) {
84  good_config = false ;
85  LOG("XSecScaleMap", pERROR) << "The target Pdg code associated is not valid : " << pdg_target ;
86  continue ;
87  }
88 
89  if( ! pdg::IsIon(pdg_target) ) {
90  good_config = false ;
91  LOG("XSecScaleMap", pERROR) << "The target Pdg code does not correspond to a Ion : " << pdg_target ;
92  continue ;
93  }
94 
95  const auto algo = fXSecScaleMap[pdg_target] = dynamic_cast<const XSecScaleI*> ( this->SubAlg( key ) );
96  if( ! algo ) {
97  good_config = false ;
98  LOG("XSecScaleMap", pERROR) << "The subalgorithm " << GetConfig().GetAlg(key).name
99  << " and target pdg " << pdg_target << " do not exist" ;
100  continue ;
101  }
102 
103  }
104 
105  if( ! good_config ) {
106  LOG("XSecScaleMap", pERROR) << "Configuration has failed.";
107  exit(78) ;
108  }
109 
110 }
111 
112 //_________________________________________________________________________
THE MAIN GENIE PROJECT NAMESPACE
Definition: AlgCmp.h:25
#define pERROR
Definition: Messenger.h:59
This class is responsible to compute a scaling factor for the XSec.
Definition: XSecScaleI.h:25
int Pdg(void) const
Definition: Target.h:71
virtual void LoadConfig(void) override
virtual const Registry & GetConfig(void) const
Definition: Algorithm.cxx:246
std::map< int, const XSecScaleI * > fXSecScaleMap
Definition: XSecScaleMap.h:42
Summary information for an interaction.
Definition: Interaction.h:56
RgKeyList FindKeys(RgKey key_part) const
create list with all keys containing &#39;key_part&#39;
Definition: Registry.cxx:840
#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
virtual double GetScaling(const Interaction &) const =0
static Config * config
Definition: config.cpp:1054
virtual double GetScaling(const Interaction &) const override
static PDGLibrary * Instance(void)
Definition: PDGLibrary.cxx:57
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
bool IsIon(int pdgc)
Definition: PDGUtils.cxx:39
string RgKey
const InitialState & InitState(void) const
Definition: Interaction.h:69
const Target & Tgt(void) const
Definition: InitialState.h:66
const XSecScaleI * fXSecScaleDefault
Definition: XSecScaleMap.h:41
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
RgAlg GetAlg(RgKey key) const
Definition: Registry.cxx:488
const Algorithm * SubAlg(const RgKey &registry_key) const
Definition: Algorithm.cxx:345