Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
genie::XSecSplineList Class Reference

List of cross section vs energy splines. More...

#include <XSecSplineList.h>

Classes

struct  Cleaner
 

Public Member Functions

void SaveAsXml (const string &filename, bool save_init=true) const
 
XmlParserStatus_t LoadFromXml (const string &filename, bool keep=false)
 
void Print (ostream &stream) const
 
void SetCurrentTune (const string &tune)
 
string CurrentTune (void) const
 
bool HasSplineFromTune (const string &tune) const
 
bool SplineExists (const XSecAlgorithmI *alg, const Interaction *i) const
 
bool SplineExists (string spline_key) const
 
const SplineGetSpline (const XSecAlgorithmI *alg, const Interaction *i) const
 
const SplineGetSpline (string spline_key) const
 
void CreateSpline (const XSecAlgorithmI *alg, const Interaction *i, int nknots=-1, double e_min=-1, double e_max=-1)
 
int NSplines (void) const
 
bool IsEmpty (void) const
 
string BuildSplineKey (const XSecAlgorithmI *alg, const Interaction *i) const
 
const vector< string > * GetSplineKeys (void) const
 
void SetLogE (bool on)
 set opt to build splines as f(E) or as f(logE) More...
 
void SetNKnots (int nk)
 set default number of knots for building the spline More...
 
void SetMinE (double Ev)
 set default minimum energy for xsec splines More...
 
void SetMaxE (double Ev)
 set default maximum energy for xsec splines More...
 
bool UseLogE (void) const
 
int NKnots (void) const
 
double Emin (void) const
 
double Emax (void) const
 

Static Public Member Functions

static XSecSplineListInstance ()
 

Private Member Functions

 XSecSplineList ()
 
 XSecSplineList (const XSecSplineList &spline_list)
 
virtual ~XSecSplineList ()
 

Private Attributes

bool fUseLogE
 
int fNKnots
 
double fEmin
 
double fEmax
 
string fCurrentTune
 The `active' tune, out the many that can co-exist. More...
 
map< string, map< string, Spline * > > fSplineMap
 tune -> { xsec_alg/xsec_config/interaction -> Spline } More...
 
map< string, set< string > > fLoadedSplineSet
 tune -> { set of initialy loaded splines } More...
 

Static Private Attributes

static XSecSplineListfInstance = 0
 

Friends

struct Cleaner
 
ostream & operator<< (ostream &stream, const XSecSplineList &xsl)
 

Detailed Description

List of cross section vs energy splines.

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

May 12, 2005

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

Definition at line 45 of file XSecSplineList.h.

Constructor & Destructor Documentation

genie::XSecSplineList::XSecSplineList ( )
private

Definition at line 48 of file XSecSplineList.cxx.

49 {
50  fInstance = 0;
51  fCurrentTune = "";
52  fUseLogE = true;
53  fNKnots = 100;
54  fEmin = 0.01; // GeV
55  fEmax = 100.00; // GeV
56 }
string fCurrentTune
The `active&#39; tune, out the many that can co-exist.
static XSecSplineList * fInstance
genie::XSecSplineList::XSecSplineList ( const XSecSplineList spline_list)
private
genie::XSecSplineList::~XSecSplineList ( )
privatevirtual

Definition at line 58 of file XSecSplineList.cxx.

59 {
60 // Clean up.
61 
62  map<string, map<string, Spline *> >::iterator mm_iter = fSplineMap.begin();
63  for( ; mm_iter != fSplineMap.end(); ++mm_iter) {
64  // loop over splines for given tune
65  map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
66  map<string, Spline *>::iterator m_iter = spl_map_curr_tune.begin();
67  for( ; m_iter != spl_map_curr_tune.end(); ++m_iter) {
68  Spline * spline = m_iter->second;
69  delete spline;
70  spline = 0;
71  }
72  spl_map_curr_tune.clear();
73  }
74  fSplineMap.clear();
75  fInstance = 0;
76 }
intermediate_table::iterator iterator
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
static XSecSplineList * fInstance

Member Function Documentation

string genie::XSecSplineList::BuildSplineKey ( const XSecAlgorithmI alg,
const Interaction i 
) const

Definition at line 519 of file XSecSplineList.cxx.

521 {
522  if(!alg) {
523  LOG("XSecSplLst", pWARN)
524  << "Null XSecAlgorithmI - Returning empty spline key";
525  return "";
526  }
527 
528  if(!interaction) {
529  LOG("XSecSplLst", pWARN)
530  << "Null Interaction - Returning empty spline key";
531  return "";
532  }
533 
534  string alg_name = alg->Id().Name();
535  string param_set = alg->Id().Config();
536  string intkey = interaction->AsString();
537 
538  string key = alg_name + "/" + param_set + "/" + intkey;
539 
540  return key;
541 }
#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
#define pWARN
Definition: Messenger.h:60
void genie::XSecSplineList::CreateSpline ( const XSecAlgorithmI alg,
const Interaction i,
int  nknots = -1,
double  e_min = -1,
double  e_max = -1 
)

Definition at line 156 of file XSecSplineList.cxx.

158 {
159 // Build a cross section spline for the input interaction using the input
160 // cross section algorithm and store in the list.
161 // For building this specific entry of the spline list, the user is allowed
162 // to override the list-wide nknots,e_min,e_max
163 
164  // FE_ALL_EXCEPT FE_INEXACT FE_UNDERFLOW
165  // FE_DIVBYZERO FE_INVALID FE_OVERFLO
166  // rwh -- uncomment to catch NaN
167  // feenableexcept(FE_DIVBYZERO|FE_INVALID|FE_OVERFLOW);
168 
169  double xsec[nknots];
170  double E [nknots];
171 
172  SLOG("XSecSplLst", pNOTICE)
173  << "Creating cross section spline using the algorithm: " << *alg;
174 
175  string key = this->BuildSplineKey(alg,interaction);
176 
177  // If any of the nknots,e_min,e_max was not set or its value is not acceptable
178  // use the list values
179  //
180  if (e_min < 0.) e_min = this->Emin();
181  if (e_max < 0.) e_max = this->Emax();
182  if (nknots <= 2) nknots = this->NKnots();
183  assert( e_min < e_max );
184 
185  // Distribute the knots in the energy range (e_min,e_max) :
186  // - Will use 5 knots linearly spaced below the energy thresholds so that the
187  // spline behaves correctly in (e_min,Ethr)
188  // - Place 1 knot exactly on the input interaction threshold
189  // - Place the remaining n-6 knots spaced either linearly or logarithmically
190  // above the input interaction threshold
191  // The above scheme schanges appropriately if Ethr<e_min (i.e. no knots
192  // are computed below threshold)
193  //
194  double Ethr = interaction->PhaseSpace().Threshold();
195  SLOG("XSecSplLst", pNOTICE)
196  << "Energy threshold for current interaction = " << Ethr << " GeV";
197 
198  int nkb = (Ethr>e_min) ? 5 : 0; // number of knots < threshold
199  int nka = nknots-nkb; // number of knots >= threshold
200 
201  // knots < energy threshold
202  double dEb = (Ethr>e_min) ? (Ethr - e_min) / nkb : 0;
203  for(int i=0; i<nkb; i++) {
204  E[i] = e_min + i*dEb;
205  }
206  // knots >= energy threshold
207  double E0 = TMath::Max(Ethr,e_min);
208  double dEa = 0;
209  if(this->UseLogE())
210  dEa = (TMath::Log10(e_max) - TMath::Log10(E0)) /(nka-1);
211  else
212  dEa = (e_max-E0) /(nka-1);
213 
214  for(int i=0; i<nka; i++) {
215  if(this->UseLogE())
216  E[i+nkb] = TMath::Power(10., TMath::Log10(E0) + i * dEa);
217  else
218  E[i+nkb] = E0 + i * dEa;
219  }
220  // force last point to avoid floating point cumulative slew
221  E[nknots-1] = e_max;
222 
223  // Compute cross sections for the input interaction at the selected
224  // set of energies
225  //
226  double pr_mass = interaction->InitStatePtr()->Probe()->Mass();
227  for (int i = 0; i < nknots; i++) {
228  TLorentzVector p4(0,0,E[i],E[i]);
229  if (pr_mass > 0.) {
230  double pz = TMath::Max(0.,E[i]*E[i] - pr_mass*pr_mass);
231  pz = TMath::Sqrt(pz);
232  p4.SetPz(pz);
233  }
234  interaction->InitStatePtr()->SetProbeP4(p4);
235  xsec[i] = alg->Integral(interaction);
236  SLOG("XSecSplLst", pNOTICE)
237  << "xsec(E = " << E[i] << ") = "
238  << (1E+38/units::cm2)*xsec[i] << " x 1E-38 cm^2";
239  if ( std::isnan(xsec[i]) ) {
240  // this sometimes happens near threshold, warn and move on
241  SLOG("XSecSplLst", pWARN)
242  << "xsec(E = " << E[i] << ") = "
243  << (1E+38/units::cm2)*xsec[i] << " x 1E-38 cm^2"
244  << " : converting NaN to 0.0";
245  xsec[i] = 0.0;
246  }
247 
248  }
249 
250  // Warn about odd case of decreasing cross section
251  // but allow for small variation due to integration errors
252  const double eps_xsec = 1.0e-5;
253  const double xsec_scale = (1.0-eps_xsec);
254  if ( xsec[nknots-1] < xsec[nknots-2]*xsec_scale ) {
255  SLOG("XSecSplLst", pWARN)
256  << "Last point oddity: " << key << " has "
257  << " xsec[nknots-1] " << xsec[nknots-1] << " < "
258  << " xsec[nknots-2] " << xsec[nknots-2];
259  }
260 
261  // Build
262  //
263  Spline * spline = new Spline(nknots, E, xsec);
264 
265  // Save
266  //
267  map<string, map<string, Spline *> >::iterator //\/
268  mm_iter = fSplineMap.find(fCurrentTune);
269  if(mm_iter == fSplineMap.end()) {
270  map<string, Spline *> spl_map_curr_tune;
271  fSplineMap.insert( map<string, map<string, Spline *> >::value_type(
272  fCurrentTune, spl_map_curr_tune) );
273  mm_iter = fSplineMap.find(fCurrentTune);
274  }
275  map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
276  spl_map_curr_tune.insert( map<string, Spline *>::value_type(key, spline) );
277 }
string BuildSplineKey(const XSecAlgorithmI *alg, const Interaction *i) const
bool UseLogE(void) const
def key(type, name=None)
Definition: graph.py:13
double Emin(void) const
static constexpr double cm2
Definition: Units.h:69
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
int NKnots(void) const
string fCurrentTune
The `active&#39; tune, out the many that can co-exist.
#define pWARN
Definition: Messenger.h:60
double Emax(void) const
#define pNOTICE
Definition: Messenger.h:61
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
string genie::XSecSplineList::CurrentTune ( void  ) const
inline

Definition at line 63 of file XSecSplineList.h.

63 { return fCurrentTune; }
string fCurrentTune
The `active&#39; tune, out the many that can co-exist.
double genie::XSecSplineList::Emax ( void  ) const
inline

Definition at line 91 of file XSecSplineList.h.

91 { return fEmax; }
double genie::XSecSplineList::Emin ( void  ) const
inline

Definition at line 90 of file XSecSplineList.h.

90 { return fEmin; }
const Spline * genie::XSecSplineList::GetSpline ( const XSecAlgorithmI alg,
const Interaction i 
) const

Definition at line 120 of file XSecSplineList.cxx.

122 {
123  string key = this->BuildSplineKey(alg,interaction);
124  return this->GetSpline(key);
125 }
string BuildSplineKey(const XSecAlgorithmI *alg, const Interaction *i) const
def key(type, name=None)
Definition: graph.py:13
const Spline * GetSpline(const XSecAlgorithmI *alg, const Interaction *i) const
const Spline * genie::XSecSplineList::GetSpline ( string  spline_key) const

Definition at line 127 of file XSecSplineList.cxx.

128 {
129 
130  if ( fCurrentTune.size() == 0 ) {
131  SLOG("XSecSplLst", pFATAL) << "Spline requested while CurrentTune not set" ;
132  exit(0) ;
133  }
134 
135  SLOG("XSecSplLst", pDEBUG)
136  << "Getting spline: " << key << " in tune: " << fCurrentTune;
137 
138  map<string, map<string, Spline *> >::const_iterator //\/
139  mm_iter = fSplineMap.find(fCurrentTune);
140  if(mm_iter == fSplineMap.end()) {
141  SLOG("XSecSplLst", pWARN)
142  << "No splines for tune " << fCurrentTune << " were found!";
143  return 0;
144  }
145  const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
147  m_iter = spl_map_curr_tune.find(key);
148  if(m_iter == spl_map_curr_tune.end()) {
149  SLOG("XSecSplLst", pWARN)
150  << "Couldn't find spline: " << key << " in tune: " << fCurrentTune;
151  return 0;
152  }
153  return m_iter->second;
154 }
#define pFATAL
Definition: Messenger.h:56
intermediate_table::const_iterator const_iterator
def key(type, name=None)
Definition: graph.py:13
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
string fCurrentTune
The `active&#39; tune, out the many that can co-exist.
#define pWARN
Definition: Messenger.h:60
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
#define pDEBUG
Definition: Messenger.h:63
const vector< string > * genie::XSecSplineList::GetSplineKeys ( void  ) const

Definition at line 543 of file XSecSplineList.cxx.

544 {
545  map<string, map<string, Spline *> >::const_iterator //\/
546  mm_iter = fSplineMap.find(fCurrentTune);
547  if(mm_iter == fSplineMap.end()) {
548  SLOG("XSecSplLst", pWARN)
549  << "No splines for tune " << fCurrentTune << " were found!";
550  return 0;
551  }
552  const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
553  vector<string> * keyv = new vector<string>(spl_map_curr_tune.size());
554  unsigned int i=0;
555  map<string, Spline *>::const_iterator m_iter = spl_map_curr_tune.begin();
556  for( ; m_iter != spl_map_curr_tune.end(); ++m_iter) {
557  string key = m_iter->first;
558  (*keyv)[i++]=key;
559  }
560  return keyv;
561 }
intermediate_table::const_iterator const_iterator
def key(type, name=None)
Definition: graph.py:13
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
string fCurrentTune
The `active&#39; tune, out the many that can co-exist.
#define pWARN
Definition: Messenger.h:60
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
bool genie::XSecSplineList::HasSplineFromTune ( const string tune) const
inline

Definition at line 64 of file XSecSplineList.h.

64 { return fSplineMap.count(tune) > 0 ; }
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
XSecSplineList * genie::XSecSplineList::Instance ( void  )
static

Definition at line 78 of file XSecSplineList.cxx.

79 {
80  if(fInstance == 0) {
81  static XSecSplineList::Cleaner cleaner;
82  cleaner.DummyMethodAndSilentCompiler();
84  }
85  return fInstance;
86 }
static XSecSplineList * fInstance
bool genie::XSecSplineList::IsEmpty ( void  ) const

Definition at line 292 of file XSecSplineList.cxx.

293 {
294  int n = this->NSplines();
295  return (n == 0);
296 }
int NSplines(void) const
std::void_t< T > n
XmlParserStatus_t genie::XSecSplineList::LoadFromXml ( const string filename,
bool  keep = false 
)

Load XSecSplineList from ROOT file. If keep = true, then the loaded splines are added to the existing list. If false, then the existing list is reset before loading the splines.

Definition at line 382 of file XSecSplineList.cxx.

383 {
384 //! Load XSecSplineList from ROOT file. If keep = true, then the loaded splines
385 //! are added to the existing list. If false, then the existing list is reset
386 //! before loading the splines.
387 
388  SLOG("XSecSplLst", pNOTICE)
389  << "Loading splines from: " << filename;
390  SLOG("XSecSplLst", pINFO)
391  << "Option to keep pre-existing splines is switched "
392  << ( (keep) ? "ON" : "OFF" );
393 
394  if(!keep) fSplineMap.clear();
395 
396  const int kNodeTypeStartElement = 1;
397  const int kNodeTypeEndElement = 15;
398  const int kKnotX = 0;
399  const int kKnotY = 1;
400 
401  xmlTextReaderPtr reader;
402 
403  int ret = 0, val_type = -1, iknot = 0, nknots = 0;
404  double * E = 0, * xsec = 0;
405  string spline_name = "";
406  string temp_tune ;
407 
408  reader = xmlNewTextReaderFilename(filename.c_str());
409  if (reader != NULL) {
410  ret = xmlTextReaderRead(reader);
411  while (ret == 1) {
412  xmlChar * name = xmlTextReaderName (reader);
413  xmlChar * value = xmlTextReaderValue (reader);
414  int type = xmlTextReaderNodeType (reader);
415  int depth = xmlTextReaderDepth (reader);
416 
417  if(depth==0 && type==kNodeTypeStartElement) {
418  LOG("XSecSplLst", pDEBUG) << "Root element = " << name;
419  if(xmlStrcmp(name, (const xmlChar *) "genie_xsec_spline_list")) {
420  LOG("XSecSplLst", pERROR)
421  << "\nXML doc. has invalid root element! [filename: " << filename << "]";
422  return kXmlInvalidRoot;
423  }
424 
425  xmlChar * xvrs = xmlTextReaderGetAttribute(reader,(const xmlChar*)"version");
426  xmlChar * xinlog = xmlTextReaderGetAttribute(reader,(const xmlChar*)"uselog");
427  string svrs = utils::str::TrimSpaces((const char *)xvrs);
428  string sinlog = utils::str::TrimSpaces((const char *)xinlog);
429 
430  LOG("XSecSplLst", pNOTICE)
431  << "Input x-section spline XML file format version: " << svrs;
432 
433  if (atoi(sinlog.c_str()) == 1) this->SetLogE(true);
434  else this->SetLogE(false);
435 
436  xmlFree(xvrs);
437  xmlFree(xinlog);
438  }
439 
440  if( (!xmlStrcmp(name, (const xmlChar *) "genie_tune")) && type==kNodeTypeStartElement) {
441  xmlChar * xtune = xmlTextReaderGetAttribute(reader,(const xmlChar*)"name");
442  temp_tune = utils::str::TrimSpaces((const char *)xtune);
443  SLOG("XSecSplLst", pNOTICE) << "Loading x-section splines for GENIE tune: " << temp_tune;
444  xmlFree(xtune);
445  }
446 
447  if( (!xmlStrcmp(name, (const xmlChar *) "spline")) && type==kNodeTypeStartElement) {
448  xmlChar * xname = xmlTextReaderGetAttribute(reader,(const xmlChar*)"name");
449  xmlChar * xnkn = xmlTextReaderGetAttribute(reader,(const xmlChar*)"nknots");
450  string sname = utils::str::TrimSpaces((const char *)xname);
451  string snkn = utils::str::TrimSpaces((const char *)xnkn);
452 
453  spline_name = sname;
454  SLOG("XSecSplLst", pNOTICE) << "Loading spline: " << spline_name;
455 
456  nknots = atoi( snkn.c_str() );
457  iknot=0;
458  E = new double[nknots];
459  xsec = new double[nknots];
460 
461  xmlFree(xname);
462  xmlFree(xnkn);
463  }
464 
465  if( (!xmlStrcmp(name, (const xmlChar *) "E")) && type==kNodeTypeStartElement) { val_type = kKnotX; }
466  if( (!xmlStrcmp(name, (const xmlChar *) "xsec")) && type==kNodeTypeStartElement) { val_type = kKnotY; }
467 
468  if( (!xmlStrcmp(name, (const xmlChar *) "#text")) && depth==5) {
469  if (val_type==kKnotX) E [iknot] = atof((const char *)value);
470  else if (val_type==kKnotY) xsec[iknot] = atof((const char *)value);
471  }
472  if( (!xmlStrcmp(name, (const xmlChar *) "knot")) && type==kNodeTypeEndElement) {
473  iknot++;
474  }
475  if( (!xmlStrcmp(name, (const xmlChar *) "spline")) && type==kNodeTypeEndElement) {
476 #ifdef __GENIE_LOW_LEVEL_MESG_ENABLED__
477  LOG("XSecSplLst", pINFO) << "Done with current spline";
478  for(int i=0; i<nknots; i++) {
479  LOG("XSecSplLst", pINFO) << "xsec[E = " << E[i] << "] = " << xsec[i];
480  }
481 #endif
482  // done looping over knots - build the spline
483  Spline * spline = new Spline(nknots, E, xsec);
484  delete [] E;
485  delete [] xsec;
486 
487  // insert the spline to the map
488  map<string, map<string, Spline *> >::iterator //\/
489  mm_iter = fSplineMap.find( temp_tune );
490  if(mm_iter == fSplineMap.end()) {
491  map<string, Spline *> spl_map_curr_tune;
492  fSplineMap.insert( map<string, map<string, Spline *> >::value_type(
493  temp_tune, spl_map_curr_tune) );
494  mm_iter = fSplineMap.find( temp_tune );
495  }
496  map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
497  spl_map_curr_tune.insert(
498  map<string, Spline *>::value_type(spline_name, spline) );
499  fLoadedSplineSet[temp_tune].insert(spline_name);
500  }
501  xmlFree(name);
502  xmlFree(value);
503  ret = xmlTextReaderRead(reader);
504  }
505  xmlFreeTextReader(reader);
506  if (ret != 0) {
507  LOG("XSecSplLst", pERROR)
508  << "\nXML file could not be parsed! [filename: " << filename << "]";
509  return kXmlNotParsed;
510  }
511  } else {
512  LOG("XSecSplLst", pERROR)
513  << "\nXML file could not be found! [filename: " << filename << "]";
514  }
515 
516  return kXmlOK;
517 }
static QCString name
Definition: declinfo.cpp:673
#define pERROR
Definition: Messenger.h:59
map< string, set< string > > fLoadedSplineSet
tune -> { set of initialy loaded splines }
string filename
Definition: train.py:213
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pINFO
Definition: Messenger.h:62
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
string TrimSpaces(string input)
Definition: StringUtils.cxx:18
E
Definition: 018_def.c:13
void SetLogE(bool on)
set opt to build splines as f(E) or as f(logE)
#define pNOTICE
Definition: Messenger.h:61
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
#define pDEBUG
Definition: Messenger.h:63
int genie::XSecSplineList::NKnots ( void  ) const
inline

Definition at line 89 of file XSecSplineList.h.

89 { return fNKnots; }
int genie::XSecSplineList::NSplines ( void  ) const

Definition at line 279 of file XSecSplineList.cxx.

280 {
281  map<string, map<string, Spline *> >::const_iterator //
282  mm_iter = fSplineMap.find(fCurrentTune);
283  if(mm_iter == fSplineMap.end()) {
284  SLOG("XSecSplLst", pWARN)
285  << "No splines for tune " << fCurrentTune << " were found!";
286  return 0;
287  }
288  const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
289  return (int) spl_map_curr_tune.size();
290 }
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
string fCurrentTune
The `active&#39; tune, out the many that can co-exist.
#define pWARN
Definition: Messenger.h:60
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
void genie::XSecSplineList::Print ( ostream &  stream) const

Definition at line 563 of file XSecSplineList.cxx.

564 {
565  stream << "\n ******************* XSecSplineList *************************";
566  stream << "\n [-] Options:";
567  stream << "\n |";
568  stream << "\n |-----o UseLogE..................." << fUseLogE;
569  stream << "\n |-----o Spline Emin..............." << fEmin;
570  stream << "\n |-----o Spline Emax..............." << fEmax;
571  stream << "\n |-----o Spline NKnots............." << fNKnots;
572  stream << "\n |";
573 
574  map<string, map<string, Spline *> >::const_iterator mm_iter;
575  for(mm_iter = fSplineMap.begin(); mm_iter != fSplineMap.end(); ++mm_iter) {
576 
577  string curr_tune = mm_iter->first;
578  stream << "\n [-] Available x-section splines for tune: " << curr_tune ;
579  stream << "\n |";
580 
581  const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
582  map<string, Spline *>::const_iterator m_iter = spl_map_curr_tune.begin();
583  for( ; m_iter != spl_map_curr_tune.end(); ++m_iter) {
584  string key = m_iter->first;
585  stream << "\n |-----o " << key;
586  }
587  stream << "\n";
588  }
589 }
intermediate_table::const_iterator const_iterator
def key(type, name=None)
Definition: graph.py:13
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
void genie::XSecSplineList::SaveAsXml ( const string filename,
bool  save_init = true 
) const

Save XSecSplineList to XML file

Definition at line 319 of file XSecSplineList.cxx.

320 {
321 //! Save XSecSplineList to XML file
322 
323  SLOG("XSecSplLst", pNOTICE)
324  << "Saving XSecSplineList as XML in file: " << filename;
325 
326  ofstream outxml(filename.c_str());
327  if(!outxml.is_open()) {
328  SLOG("XSecSplLst", pERROR) << "Couldn't create file = " << filename;
329  return;
330  }
331  outxml << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
332  outxml << endl << endl;
333  outxml << "<!-- generated by genie::XSecSplineList::SaveSplineList() -->";
334  outxml << endl << endl;
335 
336  int uselog = (fUseLogE ? 1 : 0);
337  outxml << "<genie_xsec_spline_list "
338  << "version=\"3.00\" uselog=\"" << uselog << "\">";
339  outxml << endl << endl;
340 
341  // loop over tunes
342  map<string, map<string, Spline *> >::const_iterator //\/
343  mm_iter = fSplineMap.begin();
344  for( ; mm_iter != fSplineMap.end(); ++mm_iter) {
345 
346  string tune_name = mm_iter->first;
347  outxml << " <genie_tune name=\"" << tune_name << "\">";
348  outxml << endl << endl;
349 
350  // loop over splines for given tune
351  const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
353  m_iter = spl_map_curr_tune.begin();
354  for( ; m_iter != spl_map_curr_tune.end(); ++m_iter) {
355  string key = m_iter->first;
356 
357  // If current spline is from the initial loaded set,
358  // look-up input option to decide whether to write out in
359  // new output file or not
360  bool from_init_set = false;
361  map<string, set<string> >::const_iterator //\/
362  it = fLoadedSplineSet.find(tune_name);
363  if(it != fLoadedSplineSet.end()) {
364  const set<string> & init_set_curr_tune = it->second;
365  from_init_set = (init_set_curr_tune.count(key) == 1);
366  }
367  if(from_init_set && !save_init) continue;
368 
369  // Add current spline to output file
370  Spline * spline = m_iter->second;
371  spline->SaveAsXml(outxml,"E","xsec", key);
372  }//spline loop
373 
374  outxml << " </genie_tune>" << endl;
375  }//tune loop
376 
377  outxml << "</genie_xsec_spline_list>" << endl;
378 
379  outxml.close();
380 }
#define pERROR
Definition: Messenger.h:59
intermediate_table::const_iterator const_iterator
map< string, set< string > > fLoadedSplineSet
tune -> { set of initialy loaded splines }
string filename
Definition: train.py:213
def key(type, name=None)
Definition: graph.py:13
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
#define pNOTICE
Definition: Messenger.h:61
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
QTextStream & endl(QTextStream &s)
void genie::XSecSplineList::SetCurrentTune ( const string tune)
inline

Definition at line 62 of file XSecSplineList.h.

62 { fCurrentTune = tune; }
string fCurrentTune
The `active&#39; tune, out the many that can co-exist.
void genie::XSecSplineList::SetLogE ( bool  on)

set opt to build splines as f(E) or as f(logE)

Definition at line 298 of file XSecSplineList.cxx.

299 {
300  fUseLogE = on;
301 }
void genie::XSecSplineList::SetMaxE ( double  Ev)

set default maximum energy for xsec splines

Definition at line 314 of file XSecSplineList.cxx.

315 {
316  if(Ev>0) fEmax = Ev;
317 }
void genie::XSecSplineList::SetMinE ( double  Ev)

set default minimum energy for xsec splines

Definition at line 309 of file XSecSplineList.cxx.

310 {
311  if(Ev>0) fEmin = Ev;
312 }
void genie::XSecSplineList::SetNKnots ( int  nk)

set default number of knots for building the spline

Definition at line 303 of file XSecSplineList.cxx.

304 {
305  fNKnots = nk;
306  if(fNKnots<10) fNKnots = 10; // minimum acceptable number of knots
307 }
bool genie::XSecSplineList::SplineExists ( const XSecAlgorithmI alg,
const Interaction i 
) const

Definition at line 88 of file XSecSplineList.cxx.

90 {
91  string key = this->BuildSplineKey(alg,interaction);
92  return this->SplineExists(key);
93 }
string BuildSplineKey(const XSecAlgorithmI *alg, const Interaction *i) const
bool SplineExists(const XSecAlgorithmI *alg, const Interaction *i) const
def key(type, name=None)
Definition: graph.py:13
bool genie::XSecSplineList::SplineExists ( string  spline_key) const

Definition at line 95 of file XSecSplineList.cxx.

96 {
97 
98  if ( fCurrentTune.size() == 0 ) {
99  SLOG("XSecSplLst", pERROR) << "Spline requested while CurrentTune not set" ;
100  return false ;
101  }
102 
103  SLOG("XSecSplLst", pDEBUG)
104  << "Checking for spline: " << key << " in tune: " << fCurrentTune;
105 
106  map<string, map<string, Spline *> >::const_iterator //
107  mm_iter = fSplineMap.find(fCurrentTune);
108  if(mm_iter == fSplineMap.end()) {
109  SLOG("XSecSplLst", pWARN)
110  << "No splines for tune " << fCurrentTune << " were found!";
111  return false;
112  }
113  const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
114  bool exists = (spl_map_curr_tune.count(key) == 1);
115  SLOG("XSecSplLst", pDEBUG)
116  << "Spline found?...." << utils::print::BoolAsYNString(exists);
117  return exists;
118 }
#define pERROR
Definition: Messenger.h:59
string BoolAsYNString(bool b)
Definition: PrintUtils.cxx:108
bool exists(std::string path)
def key(type, name=None)
Definition: graph.py:13
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
string fCurrentTune
The `active&#39; tune, out the many that can co-exist.
#define pWARN
Definition: Messenger.h:60
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
Definition: Messenger.h:84
#define pDEBUG
Definition: Messenger.h:63
bool genie::XSecSplineList::UseLogE ( void  ) const
inline

Definition at line 88 of file XSecSplineList.h.

88 { return fUseLogE; }

Friends And Related Function Documentation

friend struct Cleaner
friend

Definition at line 120 of file XSecSplineList.h.

ostream& operator<< ( ostream &  stream,
const XSecSplineList xsl 
)
friend

Definition at line 40 of file XSecSplineList.cxx.

41 {
42  list.Print(stream);
43  return stream;
44 }

Member Data Documentation

string genie::XSecSplineList::fCurrentTune
private

The `active' tune, out the many that can co-exist.

Definition at line 106 of file XSecSplineList.h.

double genie::XSecSplineList::fEmax
private

Definition at line 104 of file XSecSplineList.h.

double genie::XSecSplineList::fEmin
private

Definition at line 103 of file XSecSplineList.h.

XSecSplineList * genie::XSecSplineList::fInstance = 0
staticprivate

Definition at line 99 of file XSecSplineList.h.

map<string, set<string> > genie::XSecSplineList::fLoadedSplineSet
private

tune -> { set of initialy loaded splines }

Definition at line 109 of file XSecSplineList.h.

int genie::XSecSplineList::fNKnots
private

Definition at line 102 of file XSecSplineList.h.

map<string, map<string, Spline *> > genie::XSecSplineList::fSplineMap
private

tune -> { xsec_alg/xsec_config/interaction -> Spline }

Definition at line 108 of file XSecSplineList.h.

bool genie::XSecSplineList::fUseLogE
private

Definition at line 101 of file XSecSplineList.h.


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