17 #include "libxml/parser.h" 18 #include "libxml/xmlmemory.h" 19 #include "libxml/xmlreader.h" 22 #include <TLorentzVector.h> 26 #include "Framework/Conventions/GBuild.h" 63 for( ; mm_iter !=
fSplineMap.end(); ++mm_iter) {
65 map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
67 for( ; m_iter != spl_map_curr_tune.end(); ++m_iter) {
72 spl_map_curr_tune.clear();
99 SLOG(
"XSecSplLst",
pERROR) <<
"Spline requested while CurrentTune not set" ;
104 <<
"Checking for spline: " << key <<
" in tune: " <<
fCurrentTune;
110 <<
"No splines for tune " << fCurrentTune <<
" were found!";
113 const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
114 bool exists = (spl_map_curr_tune.count(key) == 1);
131 SLOG(
"XSecSplLst",
pFATAL) <<
"Spline requested while CurrentTune not set" ;
136 <<
"Getting spline: " << key <<
" in tune: " <<
fCurrentTune;
142 <<
"No splines for tune " << fCurrentTune <<
" were found!";
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()) {
150 <<
"Couldn't find spline: " << key <<
" in tune: " <<
fCurrentTune;
153 return m_iter->second;
173 <<
"Creating cross section spline using the algorithm: " << *alg;
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 );
196 <<
"Energy threshold for current interaction = " << Ethr <<
" GeV";
198 int nkb = (Ethr>e_min) ? 5 : 0;
199 int nka = nknots-nkb;
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;
207 double E0 = TMath::Max(Ethr,e_min);
210 dEa = (TMath::Log10(e_max) - TMath::Log10(E0)) /(nka-1);
212 dEa = (e_max-E0) /(nka-1);
214 for(
int i=0; i<nka; i++) {
216 E[i+nkb] = TMath::Power(10., TMath::Log10(E0) + i * dEa);
218 E[i+nkb] = E0 + i * dEa;
227 for (
int i = 0; i < nknots; i++) {
228 TLorentzVector p4(0,0,E[i],E[i]);
230 double pz = TMath::Max(0.,E[i]*E[i] - pr_mass*pr_mass);
231 pz = TMath::Sqrt(pz);
235 xsec[i] = alg->
Integral(interaction);
237 <<
"xsec(E = " << E[i] <<
") = " 238 << (1E+38/
units::cm2)*xsec[i] <<
" x 1E-38 cm^2";
239 if ( std::isnan(xsec[i]) ) {
242 <<
"xsec(E = " << E[i] <<
") = " 243 << (1E+38/
units::cm2)*xsec[i] <<
" x 1E-38 cm^2" 244 <<
" : converting NaN to 0.0";
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 ) {
256 <<
"Last point oddity: " << key <<
" has " 257 <<
" xsec[nknots-1] " << xsec[nknots-1] <<
" < " 258 <<
" xsec[nknots-2] " << xsec[nknots-2];
270 map<string, Spline *> spl_map_curr_tune;
271 fSplineMap.insert( map<
string, map<string, Spline *> >::value_type(
275 map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
276 spl_map_curr_tune.insert( map<string, Spline *>::value_type(key, spline) );
285 <<
"No splines for tune " <<
fCurrentTune <<
" were found!";
288 const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
289 return (
int) spl_map_curr_tune.size();
324 <<
"Saving XSecSplineList as XML in file: " <<
filename;
326 ofstream outxml(filename.c_str());
327 if(!outxml.is_open()) {
331 outxml <<
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
333 outxml <<
"<!-- generated by genie::XSecSplineList::SaveSplineList() -->";
334 outxml << endl <<
endl;
337 outxml <<
"<genie_xsec_spline_list " 338 <<
"version=\"3.00\" uselog=\"" << uselog <<
"\">";
339 outxml << endl <<
endl;
344 for( ; mm_iter !=
fSplineMap.end(); ++mm_iter) {
346 string tune_name = mm_iter->first;
347 outxml <<
" <genie_tune name=\"" << tune_name <<
"\">";
348 outxml << endl <<
endl;
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;
360 bool from_init_set =
false;
364 const set<string> & init_set_curr_tune = it->second;
365 from_init_set = (init_set_curr_tune.count(key) == 1);
367 if(from_init_set && !save_init)
continue;
371 spline->
SaveAsXml(outxml,
"E",
"xsec", key);
374 outxml <<
" </genie_tune>" <<
endl;
377 outxml <<
"</genie_xsec_spline_list>" <<
endl;
389 <<
"Loading splines from: " <<
filename;
391 <<
"Option to keep pre-existing splines is switched " 392 << ( (keep) ?
"ON" :
"OFF" );
396 const int kNodeTypeStartElement = 1;
397 const int kNodeTypeEndElement = 15;
398 const int kKnotX = 0;
399 const int kKnotY = 1;
401 xmlTextReaderPtr reader;
403 int ret = 0, val_type = -1, iknot = 0, nknots = 0;
404 double *
E = 0, * xsec = 0;
405 string spline_name =
"";
408 reader = xmlNewTextReaderFilename(filename.c_str());
409 if (reader != NULL) {
410 ret = xmlTextReaderRead(reader);
412 xmlChar *
name = xmlTextReaderName (reader);
413 xmlChar *
value = xmlTextReaderValue (reader);
414 int type = xmlTextReaderNodeType (reader);
415 int depth = xmlTextReaderDepth (reader);
417 if(depth==0 && type==kNodeTypeStartElement) {
419 if(xmlStrcmp(name, (
const xmlChar *)
"genie_xsec_spline_list")) {
421 <<
"\nXML doc. has invalid root element! [filename: " << filename <<
"]";
425 xmlChar * xvrs = xmlTextReaderGetAttribute(reader,(
const xmlChar*)
"version");
426 xmlChar * xinlog = xmlTextReaderGetAttribute(reader,(
const xmlChar*)
"uselog");
431 <<
"Input x-section spline XML file format version: " << svrs;
433 if (atoi(sinlog.c_str()) == 1) this->
SetLogE(
true);
440 if( (!xmlStrcmp(name, (
const xmlChar *)
"genie_tune")) && type==kNodeTypeStartElement) {
441 xmlChar * xtune = xmlTextReaderGetAttribute(reader,(
const xmlChar*)
"name");
443 SLOG(
"XSecSplLst",
pNOTICE) <<
"Loading x-section splines for GENIE tune: " << temp_tune;
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");
454 SLOG(
"XSecSplLst",
pNOTICE) <<
"Loading spline: " << spline_name;
456 nknots = atoi( snkn.c_str() );
458 E =
new double[nknots];
459 xsec =
new double[nknots];
465 if( (!xmlStrcmp(name, (
const xmlChar *)
"E")) && type==kNodeTypeStartElement) { val_type = kKnotX; }
466 if( (!xmlStrcmp(name, (
const xmlChar *)
"xsec")) && type==kNodeTypeStartElement) { val_type = kKnotY; }
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);
472 if( (!xmlStrcmp(name, (
const xmlChar *)
"knot")) && type==kNodeTypeEndElement) {
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];
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) );
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) );
503 ret = xmlTextReaderRead(reader);
505 xmlFreeTextReader(reader);
508 <<
"\nXML file could not be parsed! [filename: " << filename <<
"]";
513 <<
"\nXML file could not be found! [filename: " << filename <<
"]";
524 <<
"Null XSecAlgorithmI - Returning empty spline key";
530 <<
"Null Interaction - Returning empty spline key";
534 string alg_name = alg->
Id().
Name();
535 string param_set = alg->
Id().
Config();
536 string intkey = interaction->
AsString();
538 string key = alg_name +
"/" + param_set +
"/" + intkey;
549 <<
"No splines for tune " <<
fCurrentTune <<
" were found!";
552 const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
553 vector<string> * keyv =
new vector<string>(spl_map_curr_tune.size());
556 for( ; m_iter != spl_map_curr_tune.end(); ++m_iter) {
557 string key = m_iter->first;
565 stream <<
"\n ******************* XSecSplineList *************************";
566 stream <<
"\n [-] Options:";
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;
577 string curr_tune = mm_iter->first;
578 stream <<
"\n [-] Available x-section splines for tune: " << curr_tune ;
581 const map<string, Spline *> & spl_map_curr_tune = mm_iter->second;
583 for( ; m_iter != spl_map_curr_tune.end(); ++m_iter) {
584 string key = m_iter->first;
585 stream <<
"\n |-----o " <<
key;
void DummyMethodAndSilentCompiler()
Cross Section Calculation Interface.
const KPhaseSpace & PhaseSpace(void) const
string BuildSplineKey(const XSecAlgorithmI *alg, const Interaction *i) const
void SetProbeP4(const TLorentzVector &P4)
THE MAIN GENIE PROJECT NAMESPACE
void CreateSpline(const XSecAlgorithmI *alg, const Interaction *i, int nknots=-1, double e_min=-1, double e_max=-1)
const vector< string > * GetSplineKeys(void) const
double Threshold(void) const
Energy threshold.
bool SplineExists(const XSecAlgorithmI *alg, const Interaction *i) const
string BoolAsYNString(bool b)
A numeric analysis tool class for interpolating 1-D functions.
void SetMinE(double Ev)
set default minimum energy for xsec splines
TParticlePDG * Probe(void) const
map< string, set< string > > fLoadedSplineSet
tune -> { set of initialy loaded splines }
static XSecSplineList * Instance()
string AsString(void) const
bool exists(std::string path)
Summary information for an interaction.
void Print(ostream &stream) const
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
static constexpr double cm2
void SetNKnots(int nk)
set default number of knots for building the spline
virtual double Integral(const Interaction *i) const =0
virtual ~XSecSplineList()
map< string, map< string, Spline * > > fSplineMap
tune -> { xsec_alg/xsec_config/interaction -> Spline }
string fCurrentTune
The `active' tune, out the many that can co-exist.
void SaveAsXml(const string &filename, bool save_init=true) const
string TrimSpaces(string input)
void SaveAsXml(string filename, string xtag, string ytag, string name="") const
virtual const AlgId & Id(void) const
Get algorithm ID.
static XSecSplineList * fInstance
ostream & operator<<(ostream &stream, const AlgConfigPool &config_pool)
void SetLogE(bool on)
set opt to build splines as f(E) or as f(logE)
InitialState * InitStatePtr(void) const
void SetMaxE(double Ev)
set default maximum energy for xsec splines
enum genie::EXmlParseStatus XmlParserStatus_t
#define SLOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a short string (using the FUNCTION and...
const Spline * GetSpline(const XSecAlgorithmI *alg, const Interaction *i) const
List of cross section vs energy splines.
XmlParserStatus_t LoadFromXml(const string &filename, bool keep=false)
QTextStream & endl(QTextStream &s)
string Config(void) const