Protected Member Functions | Protected Attributes | List of all members
genie::KineGeneratorWithCache Class Referenceabstract

Abstract class. Provides a data caching mechanism for for concrete implementations of the EventRecordVisitorI interface, generating kinematics and wishing to cache maximum differential xsecs. More...

#include <KineGeneratorWithCache.h>

Inheritance diagram for genie::KineGeneratorWithCache:
genie::EventRecordVisitorI genie::Algorithm genie::COHKinematicsGenerator genie::DFRKinematicsGenerator genie::DISKinematicsGenerator genie::DMDISKinematicsGenerator genie::DMEKinematicsGenerator genie::DMELEventGenerator genie::DMELKinematicsGenerator genie::GLRESKinematicsGenerator genie::HEDISKinematicsGenerator genie::IBDKinematicsGenerator genie::NuEKinematicsGenerator genie::QELEventGenerator genie::QELEventGeneratorSM genie::QELEventGeneratorSuSA genie::QELKinematicsGenerator genie::RESKinematicsGenerator genie::SKKinematicsGenerator

Protected Member Functions

 KineGeneratorWithCache ()
 
 KineGeneratorWithCache (string name)
 
 KineGeneratorWithCache (string name, string config)
 
 ~KineGeneratorWithCache ()
 
virtual double ComputeMaxXSec (const Interaction *in) const =0
 
virtual double MaxXSec (GHepRecord *evrec) const
 
virtual double FindMaxXSec (const Interaction *in) const
 
virtual void CacheMaxXSec (const Interaction *in, double xsec) const
 
virtual double Energy (const Interaction *in) const
 
virtual CacheBranchFxAccessCacheBranch (const Interaction *in) const
 
virtual void AssertXSecLimits (const Interaction *in, double xsec, double xsec_max) const
 
- 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. More...
 
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. More...
 
int GetParamVectKeys (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 More...
 
int AddLowRegistry (Registry *rp, bool owns=true)
 add registry with lowest priority, also update ownership More...
 
int MergeTopRegistry (const Registry &r)
 
int AddTopRegisties (const vector< Registry * > &rs, bool owns=false)
 Add registries with top priority, also udated Ownerships. More...
 

Protected Attributes

const XSecAlgorithmIfXSecModel
 
double fSafetyFactor
 maxxsec -> maxxsec * safety_factor More...
 
double fMaxXSecDiffTolerance
 max{100*(xsec-maxxsec)/.5*(xsec+maxxsec)} if xsec>maxxsec More...
 
double fEMin
 min E for which maxxsec is cached - forcing explicit calc. More...
 
bool fGenerateUniformly
 uniform over allowed phase space + event weight? More...
 
- Protected Attributes inherited from genie::Algorithm
bool fAllowReconfig
 
bool fOwnsSubstruc
 true if it owns its substructure (sub-algs,...) More...
 
AlgId fID
 algorithm name and configuration set More...
 
vector< Registry * > fConfVect
 
vector< boolfOwnerships
 ownership for every registry in fConfVect More...
 
AlgStatus_t fStatus
 algorithm execution status More...
 
AlgMapfOwnedSubAlgMp
 local pool for owned sub-algs (taken out of the factory pool) More...
 

Additional Inherited Members

- Public Member Functions inherited from genie::EventRecordVisitorI
virtual ~EventRecordVisitorI ()
 
virtual void ProcessEventRecord (GHepRecord *event_rec) const =0
 
- Public Member Functions inherited from genie::Algorithm
virtual ~Algorithm ()
 
virtual void Configure (const Registry &config)
 
virtual void Configure (string config)
 
virtual void FindConfig (void)
 
virtual const RegistryGetConfig (void) const
 
RegistryGetOwnedConfig (void)
 
virtual const AlgIdId (void) const
 Get algorithm ID. More...
 
virtual AlgStatus_t GetStatus (void) const
 Get algorithm status. More...
 
virtual bool AllowReconfig (void) const
 
virtual AlgCmp_t Compare (const Algorithm *alg) const
 Compare with input algorithm. More...
 
virtual void SetId (const AlgId &id)
 Set algorithm ID. More...
 
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. More...
 
- 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)
 

Detailed Description

Abstract class. Provides a data caching mechanism for for concrete implementations of the EventRecordVisitorI interface, generating kinematics and wishing to cache maximum differential xsecs.

This class provides some common implementation for handling (retrieving, creating, searching, adding to) the cache. The various super-classes should implement the ComputeMaxXSec(...) method for computing the maximum xsec in case it has not already being pushed into the cache at a previous iteration.

Author
Costas Andreopoulos <constantinos.andreopoulos cern.ch> University of Liverpool & STFC Rutherford Appleton Laboratory

December 15, 2004

Copyright (c) 2003-2020, The GENIE Collaboration For the full text of the license visit http://copyright.genie-mc.org

Definition at line 42 of file KineGeneratorWithCache.h.

Constructor & Destructor Documentation

KineGeneratorWithCache::KineGeneratorWithCache ( )
protected

Definition at line 34 of file KineGeneratorWithCache.cxx.

34  :
36 {
37 
38 }
KineGeneratorWithCache::KineGeneratorWithCache ( string  name)
protected

Definition at line 40 of file KineGeneratorWithCache.cxx.

40  :
42 {
43 
44 }
static QCString name
Definition: declinfo.cpp:673
KineGeneratorWithCache::KineGeneratorWithCache ( string  name,
string  config 
)
protected

Definition at line 46 of file KineGeneratorWithCache.cxx.

46  :
48 {
49 
50 }
static QCString name
Definition: declinfo.cpp:673
static Config * config
Definition: config.cpp:1054
KineGeneratorWithCache::~KineGeneratorWithCache ( )
protected

Definition at line 52 of file KineGeneratorWithCache.cxx.

53 {
54 
55 }

Member Function Documentation

CacheBranchFx * KineGeneratorWithCache::AccessCacheBranch ( const Interaction in) const
protectedvirtual

Definition at line 214 of file KineGeneratorWithCache.cxx.

216 {
217 // Returns the cache branch for this algorithm and this interaction. If no
218 // branch is found then one is created.
219 
220  Cache * cache = Cache::Instance();
221 
222  // build the cache branch key as: namespace::algorithm/config/interaction
223  string algkey = this->Id().Key();
224  string intkey = interaction->AsString();
225  string key = cache->CacheBranchKey(algkey, intkey);
226 
227  CacheBranchFx * cache_branch =
228  dynamic_cast<CacheBranchFx *> (cache->FindCacheBranch(key));
229  if(!cache_branch) {
230  //-- create the cache branch at the first pass
231  LOG("Kinematics", pINFO) << "No Max d^nXSec/d{K}^n cache branch found";
232  LOG("Kinematics", pINFO) << "Creating cache branch - key = " << key;
233 
234  cache_branch = new CacheBranchFx("max[d^nXSec/d^n{K}] over phase space");
235  cache->AddCacheBranch(key, cache_branch);
236  }
237  assert(cache_branch);
238 
239  return cache_branch;
240 }
void AddCacheBranch(string key, CacheBranchI *branch)
Definition: Cache.cxx:88
#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
string CacheBranchKey(string k0, string k1="", string k2="") const
Definition: Cache.cxx:93
#define pINFO
Definition: Messenger.h:62
CacheBranchI * FindCacheBranch(string key)
finding/adding cache branches
Definition: Cache.cxx:80
GENIE Cache Memory.
Definition: Cache.h:38
virtual const AlgId & Id(void) const
Get algorithm ID.
Definition: Algorithm.h:97
static Cache * Instance(void)
Definition: Cache.cxx:67
A simple cache branch storing the cached data in a TNtuple.
Definition: CacheBranchFx.h:37
string Key(void) const
Definition: AlgId.h:46
void KineGeneratorWithCache::AssertXSecLimits ( const Interaction in,
double  xsec,
double  xsec_max 
) const
protectedvirtual

Definition at line 242 of file KineGeneratorWithCache.cxx.

244 {
245  // check the computed cross section for the current kinematics against the
246  // maximum cross section used in the rejection MC method for the current
247  // interaction at the current energy.
248  if(xsec>xsec_max) {
249  double f = 200*(xsec-xsec_max)/(xsec_max+xsec);
250  if(f>fMaxXSecDiffTolerance) {
251  LOG("Kinematics", pFATAL)
252  << "xsec: (curr) = " << xsec
253  << " > (max) = " << xsec_max << "\n for " << *interaction;
254  LOG("Kinematics", pFATAL)
255  << "*** Exceeding estimated maximum differential cross section";
256  std::terminate();
257  } else {
258  LOG("Kinematics", pWARN)
259  << "xsec: (curr) = " << xsec
260  << " > (max) = " << xsec_max << "\n for " << *interaction;
261  LOG("Kinematics", pWARN)
262  << "*** The fractional deviation of " << f << " % was allowed";
263  }
264  }
265 
266  // this should never happen - print an error mesg just in case...
267  if(xsec<0) {
268  LOG("Kinematics", pERROR)
269  << "Negative cross section for current kinematics!! \n" << *interaction;
270  }
271 }
#define pERROR
Definition: Messenger.h:59
#define pFATAL
Definition: Messenger.h:56
double fMaxXSecDiffTolerance
max{100*(xsec-maxxsec)/.5*(xsec+maxxsec)} if xsec>maxxsec
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pWARN
Definition: Messenger.h:60
void KineGeneratorWithCache::CacheMaxXSec ( const Interaction in,
double  xsec 
) const
protectedvirtual

Definition at line 182 of file KineGeneratorWithCache.cxx.

184 {
185  LOG("Kinematics", pINFO)
186  << "Adding the computed max{dxsec/dK} value to cache";
188 
189  double E = this->Energy(interaction);
190  if(max_xsec>0) cb->AddValues(E,max_xsec);
191 
192  if(! cb->Spl() ) {
193  if( cb->Map().size() > 40 ) cb->CreateSpline();
194  }
195 
196  if( cb->Spl() ) {
197  if( E < cb->Spl()->XMin() || E > cb->Spl()->XMax() ) {
198  cb->CreateSpline();
199  }
200  }
201 }
void AddValues(double x, double y)
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Spline * Spl(void) const
Definition: CacheBranchFx.h:47
#define pINFO
Definition: Messenger.h:62
double XMax(void) const
Definition: Spline.h:77
const map< double, double > & Map(void) const
Definition: CacheBranchFx.h:46
virtual double Energy(const Interaction *in) const
virtual CacheBranchFx * AccessCacheBranch(const Interaction *in) const
A simple cache branch storing the cached data in a TNtuple.
Definition: CacheBranchFx.h:37
virtual double genie::KineGeneratorWithCache::ComputeMaxXSec ( const Interaction in) const
protectedpure virtual
double KineGeneratorWithCache::Energy ( const Interaction in) const
protectedvirtual

Reimplemented in genie::COHKinematicsGenerator, genie::SKKinematicsGenerator, genie::GLRESKinematicsGenerator, genie::DMEKinematicsGenerator, and genie::NuEKinematicsGenerator.

Definition at line 203 of file KineGeneratorWithCache.cxx.

204 {
205 // Returns the neutrino energy at the struck nucleon rest frame. Kinematic
206 // generators should override this method if they need to cache the max-xsec
207 // values for another energy value (eg kinematic generators for IMD or COH)
208 
209  const InitialState & init_state = interaction->InitState();
210  double E = init_state.ProbeE(kRfHitNucRest);
211  return E;
212 }
E
Definition: 018_def.c:13
double ProbeE(RefFrame_t rf) const
Initial State information.
Definition: InitialState.h:48
double KineGeneratorWithCache::FindMaxXSec ( const Interaction in) const
protectedvirtual

Definition at line 97 of file KineGeneratorWithCache.cxx.

99 {
100 // Find a cached max xsec for the specified xsec algorithm & interaction and
101 // close to the specified energy
102 
103  // get neutrino energy
104  double E = this->Energy(interaction);
105  LOG("Kinematics", pINFO) << "E = " << E;
106 
107  if(E < fEMin) {
108  LOG("Kinematics", pINFO)
109  << "Below minimum energy - Forcing explicit calculation";
110  return -1.;
111  }
112 
113  // access the the cache branch
115 
116  // if there are enough points stored in the cache buffer to build a
117  // spline, then intepolate
118  if( cb->Spl() ) {
119  if( E >= cb->Spl()->XMin() && E <= cb->Spl()->XMax()) {
120  double spl_max_xsec = cb->Spl()->Evaluate(E);
121  LOG("Kinematics", pINFO)
122  << "\nInterpolated: max xsec (E=" << E << ") = " << spl_max_xsec;
123  return spl_max_xsec;
124  }
125  LOG("Kinematics", pINFO)
126  << "Outside spline boundaries - Forcing explicit calculation";
127  return -1.;
128  }
129 
130  // if there are not enough points at the cache buffer to have a spline,
131  // look whether there is another point that is sufficiently close
132  double dE = TMath::Min(0.25, 0.05*E);
133  const map<double,double> & fmap = cb->Map();
134  map<double,double>::const_iterator iter = fmap.lower_bound(E);
135  if(iter != fmap.end()) {
136  if(TMath::Abs(E - iter->first) < dE) return iter->second;
137  }
138 
139  return -1;
140 
141 /*
142  // build the search rule
143  double dE = TMath::Min(0.25, 0.05*E);
144  ostringstream search;
145  search << "(x-" << E << " < " << dE << ") && (x>=" << E << ")";
146 
147  // query for all the entries at a window around the current energy
148  TSQLResult * result = cb->Ntuple()->Query("x:y", search.str().c_str());
149  int nrows = result->GetRowCount();
150  LOG("Kinematics", pDEBUG)
151  << "Found " << nrows << " rows with " << search.str();
152  if(nrows <= 0) {
153  delete result;
154  return -1;
155  }
156 
157  // and now select the entry with the closest energy
158  double max_xsec = -1.0;
159  double Ep = 0;
160  double dEmin = 999;
161  TSQLRow * row = 0;
162  while( (row = result->Next()) ) {
163  double cE = atof( row->GetField(0) );
164  double cxsec = atof( row->GetField(1) );
165  double dE = TMath::Abs(E-cE);
166  if(dE < dEmin) {
167  max_xsec = cxsec;
168  Ep = cE;
169  dEmin = TMath::Min(dE,dEmin);
170  }
171  delete row;
172  }
173  delete result;
174 
175  LOG("Kinematics", pINFO)
176  << "\nRetrieved: max xsec = " << max_xsec << " cached at E = " << Ep;
177 
178  return max_xsec;
179 */
180 }
intermediate_table::const_iterator const_iterator
double Evaluate(double x) const
Definition: Spline.cxx:361
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
Spline * Spl(void) const
Definition: CacheBranchFx.h:47
#define pINFO
Definition: Messenger.h:62
double XMax(void) const
Definition: Spline.h:77
const map< double, double > & Map(void) const
Definition: CacheBranchFx.h:46
E
Definition: 018_def.c:13
double fEMin
min E for which maxxsec is cached - forcing explicit calc.
virtual double Energy(const Interaction *in) const
virtual CacheBranchFx * AccessCacheBranch(const Interaction *in) const
A simple cache branch storing the cached data in a TNtuple.
Definition: CacheBranchFx.h:37
double XMin(void) const
Definition: Spline.h:76
double KineGeneratorWithCache::MaxXSec ( GHepRecord evrec) const
protectedvirtual

Definition at line 57 of file KineGeneratorWithCache.cxx.

58 {
59  LOG("Kinematics", pINFO)
60  << "Getting max. differential xsec for the rejection method";
61 
62  double xsec_max = -1;
63  Interaction * interaction = event_rec->Summary();
64 
65  LOG("Kinematics", pINFO)
66  << "Attempting to find a cached max{dxsec/dK} value";
67  xsec_max = this->FindMaxXSec(interaction);
68  if(xsec_max>0) return xsec_max;
69 
70  LOG("Kinematics", pINFO)
71  << "Attempting to compute the max{dxsec/dK} value";
72  xsec_max = this->ComputeMaxXSec(interaction);
73  if(xsec_max>0) {
74  LOG("Kinematics", pINFO) << "max{dxsec/dK} = " << xsec_max;
75  this->CacheMaxXSec(interaction, xsec_max);
76  return xsec_max;
77  }
78 
79  LOG("Kinematics", pNOTICE)
80  << "Can not generate event kinematics {K} (max_xsec({K};E)<=0)";
81  // xsec for selected kinematics = 0
82  event_rec->SetDiffXSec(0,kPSNull);
83  // switch on error flag
84  event_rec->EventFlags()->SetBitNumber(kKineGenErr, true);
85  // reset 'trust' bits
86  interaction->ResetBit(kISkipProcessChk);
87  interaction->ResetBit(kISkipKinematicChk);
88  // throw exception
90  exception.SetReason("kinematics generation: max_xsec({K};E)<=0");
91  exception.SwitchOnFastForward();
92  throw exception;
93 
94  return 0;
95 }
Summary information for an interaction.
Definition: Interaction.h:56
An exception thrown by EventRecordVisitorI when the normal processing sequence has to be disrupted (f...
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
virtual double ComputeMaxXSec(const Interaction *in) const =0
#define pINFO
Definition: Messenger.h:62
const UInt_t kISkipKinematicChk
if set, skip kinematic validity checks
Definition: Interaction.h:48
virtual void CacheMaxXSec(const Interaction *in, double xsec) const
#define pNOTICE
Definition: Messenger.h:61
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
virtual double FindMaxXSec(const Interaction *in) const
const UInt_t kISkipProcessChk
if set, skip process validity checks
Definition: Interaction.h:47

Member Data Documentation

double genie::KineGeneratorWithCache::fEMin
protected

min E for which maxxsec is cached - forcing explicit calc.

Definition at line 64 of file KineGeneratorWithCache.h.

bool genie::KineGeneratorWithCache::fGenerateUniformly
protected

uniform over allowed phase space + event weight?

Definition at line 65 of file KineGeneratorWithCache.h.

double genie::KineGeneratorWithCache::fMaxXSecDiffTolerance
protected

max{100*(xsec-maxxsec)/.5*(xsec+maxxsec)} if xsec>maxxsec

Definition at line 63 of file KineGeneratorWithCache.h.

double genie::KineGeneratorWithCache::fSafetyFactor
protected

maxxsec -> maxxsec * safety_factor

Definition at line 62 of file KineGeneratorWithCache.h.

const XSecAlgorithmI* genie::KineGeneratorWithCache::fXSecModel
mutableprotected

Definition at line 60 of file KineGeneratorWithCache.h.


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