GENIEGenerator
Loading...
Searching...
No Matches
genie::CascadeReweight Class Reference

In this module, the event weight is set depending on the FSI fate. The weights are set depending on the xml configuration defined by the user. More...

#include <CascadeReweight.h>

Inheritance diagram for genie::CascadeReweight:
[legend]
Collaboration diagram for genie::CascadeReweight:
[legend]

Public Member Functions

 CascadeReweight ()
 CascadeReweight (string config)
 ~CascadeReweight ()
void ProcessEventRecord (GHepRecord *event_rec) const
void Configure (const Registry &config)
void Configure (string param_set)
Public Member Functions inherited from genie::EventRecordVisitorI
virtual ~EventRecordVisitorI ()
Public Member Functions inherited from genie::Algorithm
virtual ~Algorithm ()
virtual void FindConfig (void)
virtual const RegistryGetConfig (void) const
RegistryGetOwnedConfig (void)
virtual const AlgIdId (void) const
 Get algorithm ID.
virtual AlgStatus_t GetStatus (void) const
 Get algorithm status.
virtual bool AllowReconfig (void) const
virtual AlgCmp_t Compare (const Algorithm *alg) const
 Compare with input algorithm.
virtual void SetId (const AlgId &id)
 Set algorithm ID.
virtual void SetId (string name, string config)
const AlgorithmSubAlg (const RgKey &registry_key) const
void AdoptConfig (void)
void AdoptSubstructure (void)
virtual void Print (ostream &stream) const
 Print algorithm info.

Protected Member Functions

double GetEventWeight (const GHepRecord &ev) const
 get weight from fate and configuration
Protected Member Functions inherited from genie::EventRecordVisitorI
 EventRecordVisitorI ()
 EventRecordVisitorI (string name)
 EventRecordVisitorI (string name, string config)
Protected Member Functions inherited from genie::Algorithm
 Algorithm ()
 Algorithm (string name)
 Algorithm (string name, string config)
void Initialize (void)
void DeleteConfig (void)
void DeleteSubstructure (void)
RegistryExtractLocalConfig (const Registry &in) const
RegistryExtractLowerConfig (const Registry &in, const string &alg_key) const
 Split an incoming configuration Registry into a block valid for the sub-algo identified by alg_key.
template<class T>
bool GetParam (const RgKey &name, T &p, bool is_top_call=true) const
template<class T>
bool GetParamDef (const RgKey &name, T &p, const T &def) const
template<class T>
int GetParamVect (const std::string &comm_name, std::vector< T > &v, bool is_top_call=true) const
 Handle to load vectors of parameters.
int GetParamVectKeys (const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
template<class T>
int GetParamMat (const std::string &comm_name, TMatrixT< T > &mat, bool is_top_call=true) const
 Handle to load matrix of parameters.
template<class T>
int GetParamMatSym (const std::string &comm_name, TMatrixTSym< T > &mat, bool is_top_call=true) const
int GetParamMatKeys (const std::string &comm_name, std::vector< RgKey > &k, bool is_top_call=true) const
int AddTopRegistry (Registry *rp, bool owns=true)
 add registry with top priority, also update ownership
int AddLowRegistry (Registry *rp, bool owns=true)
 add registry with lowest priority, also update ownership
int MergeTopRegistry (const Registry &r)
int AddTopRegisties (const vector< Registry * > &rs, bool owns=false)
 Add registries with top priority, also udated Ownerships.

Private Member Functions

void LoadConfig (void)
 read configuration from xml file

Static Private Member Functions

static const std::map< INukeFateHN_t, string > & GetEINukeFateKeysMap (void)

Private Attributes

std::map< INukeFateHN_t, double > fDefaultMap
std::map< INukeFateHN_t, map< int, double > > fFateWeightsMap

Additional Inherited Members

Static Public Member Functions inherited from genie::Algorithm
static string BuildParamVectKey (const std::string &comm_name, unsigned int i)
static string BuildParamVectSizeKey (const std::string &comm_name)
static string BuildParamMatKey (const std::string &comm_name, unsigned int i, unsigned int j)
static string BuildParamMatRowSizeKey (const std::string &comm_name)
static string BuildParamMatColSizeKey (const std::string &comm_name)
Protected Attributes inherited from genie::Algorithm
bool fAllowReconfig
bool fOwnsSubstruc
 true if it owns its substructure (sub-algs,...)
AlgId fID
 algorithm name and configuration set
vector< Registry * > fConfVect
vector< bool > fOwnerships
 ownership for every registry in fConfVect
AlgStatus_t fStatus
 algorithm execution status
AlgMapfOwnedSubAlgMp
 local pool for owned sub-algs (taken out of the factory pool)

Detailed Description

In this module, the event weight is set depending on the FSI fate. The weights are set depending on the xml configuration defined by the user.

Author
Julia Tena-Vidal <j.tena-vidal \at liverpool.ac.uk>
Created:\n July 2021
License:\n Copyright (c) 2003-2025, The GENIE Collaboration
For the full text of the license visit http://copyright.genie-mc.org

Definition at line 26 of file CascadeReweight.h.

Constructor & Destructor Documentation

◆ CascadeReweight() [1/2]

CascadeReweight::CascadeReweight ( )

Definition at line 37 of file CascadeReweight.cxx.

38 : EventRecordVisitorI("genie::CascadeReweight") {}

References genie::EventRecordVisitorI::EventRecordVisitorI().

◆ CascadeReweight() [2/2]

CascadeReweight::CascadeReweight ( string config)

Definition at line 40 of file CascadeReweight.cxx.

41 : EventRecordVisitorI("genie::CascadeReweight", config) {}

References genie::EventRecordVisitorI::EventRecordVisitorI().

◆ ~CascadeReweight()

CascadeReweight::~CascadeReweight ( )

Definition at line 43 of file CascadeReweight.cxx.

43{}

Member Function Documentation

◆ Configure() [1/2]

void CascadeReweight::Configure ( const Registry & config)
virtual

Configure the algorithm with an external registry The registry is merged with the top level registry if it is owned, Otherwise a copy of it is added with the highest priority

Reimplemented from genie::Algorithm.

Definition at line 94 of file CascadeReweight.cxx.

94 {
96 this->LoadConfig();
97}
virtual void Configure(const Registry &config)
Definition Algorithm.cxx:62
void LoadConfig(void)
read configuration from xml file

References genie::Algorithm::Configure(), and LoadConfig().

◆ Configure() [2/2]

void CascadeReweight::Configure ( string config)
virtual

Configure the algorithm from the AlgoConfigPool based on param_set string given in input An algorithm contains a vector of registries coming from different xml configuration files, which are loaded according a very precise prioriy This methods will load a number registries in order of priority: 1) "Tunable" parameter set from CommonParametes. This is loaded with the highest prioriry and it is designed to be used for tuning procedure Usage not expected from the user. 2) For every string defined in "CommonParame" the corresponding parameter set will be loaded from CommonParameter.xml 3) parameter set specified by the config string and defined in the xml file of the algorithm 4) if config is not "Default" also the Default parameter set from the same xml file will be loaded Effectively this avoids the repetion of a parameter when it is not changed in the requested configuration

Reimplemented from genie::Algorithm.

Definition at line 99 of file CascadeReweight.cxx.

99 {
100 Algorithm::Configure(param_set);
101 this->LoadConfig();
102}

References genie::Algorithm::Configure(), and LoadConfig().

◆ GetEINukeFateKeysMap()

const std::map< INukeFateHN_t, string > & genie::CascadeReweight::GetEINukeFateKeysMap ( void )
inlinestaticprivate

Definition at line 46 of file CascadeReweight.h.

46 {
47 static const std::map<INukeFateHN_t,string> map_keys { {kIHNFtNoInteraction,"NoInteraction"},{kIHNFtCEx,"CEx"}, {kIHNFtElas,"Elastic"}, {kIHNFtInelas,"Inelastic"},{kIHNFtAbs,"Abs"}, {kIHNFtCmp,"Cmp"} } ;
48 return map_keys ;
49 }
@ kIHNFtNoInteraction

References genie::kIHNFtAbs, genie::kIHNFtCEx, genie::kIHNFtCmp, genie::kIHNFtElas, genie::kIHNFtInelas, and genie::kIHNFtNoInteraction.

Referenced by LoadConfig().

◆ GetEventWeight()

double CascadeReweight::GetEventWeight ( const GHepRecord & ev) const
protected

get weight from fate and configuration

Definition at line 58 of file CascadeReweight.cxx.

58 {
59
60 GHepParticle *p = 0;
61 TIter event_iter(&event);
62 double total_weight = 1.;
63 while ((p = dynamic_cast<GHepParticle *>(event_iter.Next()))) {
64 // Look only at stable particles in the nucleus:
65 if ( p->Status() != kIStHadronInTheNucleus ) continue ;
66 // Get particle fate
67 auto fate_rescatter = p->RescatterCode();
68 // Only look at particles that had FSI
69 if (fate_rescatter < 0 || fate_rescatter == kIHNFtUndefined)
70 continue;
71 INukeFateHN_t fate = (INukeFateHN_t)fate_rescatter;
72
73 // Read map weight:
74 const auto map_it = fFateWeightsMap.find(fate);
75 // Get weight given a pdg code.
76 if (map_it != fFateWeightsMap.end()) {
77 int pdg_target = p->Pdg();
78 const auto weight_it = (map_it->second).find(pdg_target);
79 if (weight_it != (map_it->second).end()) {
80 total_weight *= weight_it->second;
81 continue;
82 }
83 }
84 // If fate is not in the pdg map, use default values:
85 const auto def_it = fDefaultMap.find(fate);
86 if (def_it != fDefaultMap.end()) {
87 total_weight *= def_it->second;
88 }
89 } // end loop over particles
90
91 return total_weight;
92}
std::map< INukeFateHN_t, double > fDefaultMap
std::map< INukeFateHN_t, map< int, double > > fFateWeightsMap
int Pdg(void) const
int RescatterCode(void) const
GHepStatus_t Status(void) const
@ kIHNFtUndefined
@ kIStHadronInTheNucleus
Definition GHepStatus.h:37
enum genie::EINukeFateHN_t INukeFateHN_t

References fDefaultMap, fFateWeightsMap, genie::kIHNFtUndefined, genie::kIStHadronInTheNucleus, genie::GHepParticle::Pdg(), genie::GHepParticle::RescatterCode(), and genie::GHepParticle::Status().

Referenced by ProcessEventRecord().

◆ LoadConfig()

void CascadeReweight::LoadConfig ( void )
private

read configuration from xml file

Definition at line 104 of file CascadeReweight.cxx.

104 {
105 bool good_config = true;
106
107 // Clean maps
108 fDefaultMap.clear();
109 fFateWeightsMap.clear();
110
111 // Create vector with list of possible keys (follows the order of the fates
112 // enumeration)
113 std::map<INukeFateHN_t, string> EINukeFate_map_keys = GetEINukeFateKeysMap();
114
115 for (map<INukeFateHN_t, string>::iterator it_keys =
116 EINukeFate_map_keys.begin();
117 it_keys != EINukeFate_map_keys.end(); it_keys++) {
118 // Find fate specifications
119 std::string to_find_def =
120 "CascadeReweight-Default-Weight-" + (it_keys->second);
121
122 auto kdef_list = GetConfig().FindKeys(to_find_def.c_str());
123 for (auto kiter = kdef_list.begin(); kiter != kdef_list.end(); ++kiter) {
124 const RgKey &key = *kiter;
125 double weight;
126 GetParam(key, weight);
127 // Add check weight > 0
128 if (weight < 0) {
129 LOG("CascadeReweight", pERROR)
130 << "The weight assigned to " << to_find_def << " is not positive";
131 good_config = false;
132 continue;
133 }
134 fDefaultMap[it_keys->first] = weight;
135 }
136
137 // Find Pdg specifications
138 std::string to_find_pdg =
139 "CascadeReweight-Weight-" + (it_keys->second) + "@Pdg=";
140 auto kpdg_list = GetConfig().FindKeys(to_find_pdg.c_str());
141 std::map<int, double> WeightMap; // define map that stores <pdg, weight>
142 for (auto kiter = kpdg_list.begin(); kiter != kpdg_list.end(); ++kiter) {
143 const RgKey &key = *kiter;
144 vector<string> kv = genie::utils::str::Split(key, "=");
145 assert(kv.size() == 2);
146 int pdg_target = stoi(kv[1]);
147 if (!PDGLibrary::Instance()->Find(pdg_target)) {
148 LOG("CascadeReweight", pERROR)
149 << "The target Pdg code associated to " << to_find_pdg
150 << " is not valid : " << pdg_target;
151 good_config = false;
152 continue;
153 }
154 double weight;
155 GetParam(key, weight);
156 // Add check weight > 0
157 if (weight < 0) {
158 LOG("CascadeReweight", pERROR)
159 << "The weight assigned to " << to_find_pdg << " is not positive";
160 good_config = false;
161 continue;
162 }
163 // Add pdg and weight in map
164 WeightMap.insert(std::pair<int, double>(pdg_target, weight));
165 }
166 // store information in class member
167 fFateWeightsMap[it_keys->first] = std::move(WeightMap);
168 }
169
170 if (!good_config) {
171 LOG("CascadeReweight", pFATAL) << "Configuration has failed.";
172 exit(78);
173 }
174}
#define pERROR
Definition Messenger.h:59
#define pFATAL
Definition Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
string RgKey
virtual const Registry & GetConfig(void) const
bool GetParam(const RgKey &name, T &p, bool is_top_call=true) const
static const std::map< INukeFateHN_t, string > & GetEINukeFateKeysMap(void)
static PDGLibrary * Instance(void)
RgKeyList FindKeys(RgKey key_part) const
create list with all keys containing 'key_part'
Definition Registry.cxx:840
vector< string > Split(string input, string delim)

References fDefaultMap, fFateWeightsMap, genie::Registry::FindKeys(), genie::Algorithm::GetConfig(), GetEINukeFateKeysMap(), genie::Algorithm::GetParam(), genie::PDGLibrary::Instance(), LOG, pERROR, pFATAL, and genie::utils::str::Split().

Referenced by Configure(), and Configure().

◆ ProcessEventRecord()

void CascadeReweight::ProcessEventRecord ( GHepRecord * event_rec) const
virtual

Implements genie::EventRecordVisitorI.

Definition at line 45 of file CascadeReweight.cxx.

45 {
46 if (!evrec) {
47 LOG("CascadeReweight", pERROR) << "** Null input!";
48 return;
49 }
50 // Get Associated weight
51 double weight = GetEventWeight(*evrec);
52 // Set weight
53 evrec->SetWeight(weight);
54
55 return;
56}
double GetEventWeight(const GHepRecord &ev) const
get weight from fate and configuration

References GetEventWeight(), LOG, pERROR, and genie::GHepRecord::SetWeight().

Member Data Documentation

◆ fDefaultMap

std::map< INukeFateHN_t, double > genie::CascadeReweight::fDefaultMap
private

Definition at line 52 of file CascadeReweight.h.

Referenced by GetEventWeight(), and LoadConfig().

◆ fFateWeightsMap

std::map< INukeFateHN_t, map<int,double> > genie::CascadeReweight::fFateWeightsMap
private

Definition at line 53 of file CascadeReweight.h.

Referenced by GetEventWeight(), and LoadConfig().


The documentation for this class was generated from the following files: