Functions | Variables
gMakeSplines.cxx File Reference
#include <cassert>
#include <cstdlib>
#include <string>
#include <vector>
#include <TSystem.h>
#include "Framework/Conventions/GBuild.h"
#include "Framework/EventGen/GEVGDriver.h"
#include "Framework/Interaction/Interaction.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/Numerical/RandomGen.h"
#include "Framework/ParticleData/PDGCodeList.h"
#include "Framework/Utils/RunOpt.h"
#include "Framework/Utils/AppInit.h"
#include "Framework/Utils/StringUtils.h"
#include "Framework/Utils/PrintUtils.h"
#include "Framework/Utils/XSecSplineList.h"
#include "Framework/Utils/CmdLnArgParser.h"

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void PrintSyntax (void)
 
PDGCodeListGetNeutrinoCodes (void)
 
PDGCodeListGetTargetCodes (void)
 
int main (int argc, char **argv)
 

Variables

string gOptNuPdgCodeList = ""
 
string gOptTgtPdgCodeList = ""
 
string gOptGeomFilename = ""
 
int gOptNKnots = -1
 
double gOptMaxE = -1.
 
bool gOptNoCopy = false
 
long int gOptRanSeed = -1
 
string gOptInpXSecFile = ""
 
string gOptOutXSecFile = ""
 

Function Documentation

void GetCommandLineArgs ( int  argc,
char **  argv 
)

Definition at line 211 of file gMakeSplines.cxx.

212 {
213  LOG("gmkspl", pINFO) << "Parsing command line arguments";
214 
215  // Common run options. Set defaults and read.
216  RunOpt::Instance()->EnableBareXSecPreCalc(true);
217  RunOpt::Instance()->ReadFromCommandLine(argc,argv);
218 
219  // Parse run options for this app
220 
221  CmdLnArgParser parser(argc,argv);
222 
223  // output XML file name
224  if( parser.OptionExists('o') ||
225  parser.OptionExists("output-cross-sections") )
226  {
227  LOG("gmkspl", pINFO) << "Reading output filename";
228  if( parser.OptionExists('o') ) {
229  gOptOutXSecFile = parser.ArgAsString('o');
230  }
231  else {
232  gOptOutXSecFile = parser.ArgAsString("output-cross-sections");
233  }
234  } else {
235  LOG("gmkspl", pINFO) << "Unspecified filename - Using default";
236  gOptOutXSecFile = "xsec_splines.xml";
237  }
238 
239  // number of knots
240  if( parser.OptionExists('n') ) {
241  LOG("gmkspl", pINFO) << "Reading number of knots/spline";
242  gOptNKnots = parser.ArgAsInt('n');
243  } else {
244  LOG("gmkspl", pINFO)
245  << "Unspecified number of knots - Using default";
246  gOptNKnots = -1;
247  }
248 
249  // max spline energy (if < max of validity range)
250  if( parser.OptionExists('e') ) {
251  LOG("gmkspl", pINFO) << "Reading maximum spline energy";
252  gOptMaxE = parser.ArgAsDouble('e');
253  } else {
254  LOG("gmkspl", pINFO)
255  << "Unspecified maximum spline energy - Using default";
256  gOptMaxE = -1;
257  }
258 
259  // write out input splines?
260  if( parser.OptionExists("no-copy") ) {
261  LOG("gmkspl", pINFO) << "Not copying input splines to output";
262  gOptNoCopy = true;
263  }
264 
265  // comma-separated neutrino PDG code list
266  if( parser.OptionExists('p') ) {
267  LOG("gmkspl", pINFO) << "Reading neutrino PDG codes";
268  gOptNuPdgCodeList = parser.ArgAsString('p');
269  } else {
270  LOG("gmkspl", pFATAL)
271  << "Unspecified neutrino PDG code list - Exiting";
272  PrintSyntax();
273  exit(1);
274  }
275 
276  // comma-separated target PDG code list or input geometry file
277  bool tgt_cmd = true;
278  if( parser.OptionExists('t') ) {
279  LOG("gmkspl", pINFO) << "Reading target nuclei PDG codes";
280  gOptTgtPdgCodeList = parser.ArgAsString('t');
281  } else {
282  LOG("gmkspl", pINFO) << "No code list specified from the command line";
283  tgt_cmd = false;
284  }
285 
286  bool tgt_geom = true;
287  if( parser.OptionExists('f') ) {
288  LOG("gmkspl", pINFO) << "Reading ROOT geometry filename";
289  gOptGeomFilename = parser.ArgAsString('f');
290  } else {
291  LOG("gmkspl", pINFO) << "No geometry file was specified";
292  tgt_cmd = false;
293  }
294 
295  bool both = tgt_geom && tgt_cmd;
296  bool none = !tgt_geom && !tgt_cmd;
297  if(none) {
298  LOG("gmkspl", pFATAL)
299  << "No geom file or cmd line target list was specified - Exiting";
300  PrintSyntax();
301  exit(1);
302  }
303  if(both) {
304  LOG("gmkspl", pFATAL)
305  << "You specified both a geom file and a cmd line target list "
306  << "- Exiting confused";
307  PrintSyntax();
308  exit(1);
309  }
310 
311  // random number seed
312  if( parser.OptionExists("seed") ) {
313  LOG("gmkspl", pINFO) << "Reading random number seed";
314  gOptRanSeed = parser.ArgAsLong("seed");
315  } else {
316  LOG("gmkspl", pINFO) << "Unspecified random number seed - Using default";
317  gOptRanSeed = -1;
318  }
319 
320  // input cross-section file
321  if( parser.OptionExists("input-cross-sections") ) {
322  LOG("gmkspl", pINFO) << "Reading cross-section file";
323  gOptInpXSecFile = parser.ArgAsString("input-cross-sections");
324  } else {
325  LOG("gmkspl", pINFO) << "Unspecified input cross-section file";
326  gOptInpXSecFile = "";
327  }
328 
329  //
330  // print the command-line options
331  //
332  LOG("gmkspl", pNOTICE)
333  << "\n"
334  << utils::print::PrintFramedMesg("gmkspl job configuration")
335  << "\n Neutrino PDG codes : " << gOptNuPdgCodeList
336  << "\n Target PDG codes : " << gOptTgtPdgCodeList
337  << "\n Input ROOT geometry : " << gOptGeomFilename
338  << "\n Output cross-section file : " << gOptOutXSecFile
339  << "\n Input cross-section file : " << gOptInpXSecFile
340  << "\n Random number seed : " << gOptRanSeed
341  << "\n";
342 
343  LOG("gmkspl", pNOTICE) << *RunOpt::Instance();
344 }
int gOptNKnots
string gOptNuPdgCodeList
long int gOptRanSeed
string gOptInpXSecFile
#define pFATAL
Definition: Messenger.h:56
string gOptOutXSecFile
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string gOptTgtPdgCodeList
#define pINFO
Definition: Messenger.h:62
void PrintSyntax(void)
double gOptMaxE
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f='*')
Definition: PrintUtils.cxx:164
Command line argument parser.
#define pNOTICE
Definition: Messenger.h:61
bool gOptNoCopy
string gOptGeomFilename
PDGCodeList * GetNeutrinoCodes ( void  )

Definition at line 360 of file gMakeSplines.cxx.

361 {
362  // split the comma separated list
363  vector<string> nuvec = utils::str::Split(gOptNuPdgCodeList, ",");
364 
365  // fill in the PDG code list
366  PDGCodeList * list = new PDGCodeList;
368  for(iter = nuvec.begin(); iter != nuvec.end(); ++iter) {
369  list->push_back( atoi(iter->c_str()) );
370  }
371  return list;
372 }
string gOptNuPdgCodeList
intermediate_table::const_iterator const_iterator
A list of PDG codes.
Definition: PDGCodeList.h:32
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:58
PDGCodeList * GetTargetCodes ( void  )

Definition at line 374 of file gMakeSplines.cxx.

375 {
376  bool from_geom_file = ( gOptGeomFilename.size() > 0 );
377  bool from_cmd_line = ( gOptTgtPdgCodeList.size() > 0 );
378 
379  if (from_cmd_line) {
380  // split the comma separated list
381  vector<string> tgtvec = utils::str::Split(gOptTgtPdgCodeList, ",");
382 
383  // fill in the PDG code list
384  PDGCodeList * list = new PDGCodeList;
386  for(iter = tgtvec.begin(); iter != tgtvec.end(); ++iter) {
387  list->push_back( atoi(iter->c_str()) );
388  }
389  return list;
390  }
391 
392  if (from_geom_file) {
393 #ifdef __GENIE_GEOM_DRIVERS_ENABLED__
394  // create/configure a geometry driver
395  LOG("gmkspl", pINFO) << "Creating/configuring a ROOT geom. driver";
397 
398  PDGCodeList * list = new PDGCodeList(geom->ListOfTargetNuclei());
399 
400  delete geom;
401  return list;
402 #else
403  LOG("gmkspl", pFATAL)
404  << "To read-in a ROOT geometry you need to enable the geometry drivers!";
405  gAbortingInErr = true;
406  exit(1);
407  return 0;
408 #endif
409 
410  }
411  return 0;
412 }
#define pFATAL
Definition: Messenger.h:56
intermediate_table::const_iterator const_iterator
virtual const PDGCodeList & ListOfTargetNuclei(void)
implement the GeomAnalyzerI interface
A list of PDG codes.
Definition: PDGCodeList.h:32
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string gOptTgtPdgCodeList
A ROOT/GEANT4 geometry driver.
#define pINFO
Definition: Messenger.h:62
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
bool gAbortingInErr
Definition: Messenger.cxx:34
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:58
string gOptGeomFilename
int main ( int  argc,
char **  argv 
)

Definition at line 142 of file gMakeSplines.cxx.

143 {
144  // Parse command line arguments
145  GetCommandLineArgs(argc,argv);
146 
147  if ( ! RunOpt::Instance()->Tune() ) {
148  LOG("gmkspl", pFATAL) << " No TuneId in RunOption";
149  exit(-1);
150  }
151  RunOpt::Instance()->BuildTune();
152 
153  // throw on NaNs and Infs...
154 #if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT)
155  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
156 #endif
157 
158  // Init
159  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
162 
163  // Get list of neutrinos and nuclear targets
164 
165  PDGCodeList * neutrinos = GetNeutrinoCodes();
166  PDGCodeList * targets = GetTargetCodes();
167 
168  if(!neutrinos || neutrinos->size() == 0 ) {
169  LOG("gmkspl", pFATAL) << "Empty neutrino PDG code list";
170  PrintSyntax();
171  exit(2);
172  }
173  if(!targets || targets->size() == 0 ) {
174  LOG("gmkspl", pFATAL) << "Empty target PDG code list";
175  PrintSyntax();
176  exit(3);
177  }
178 
179  LOG("gmkspl", pINFO) << "Neutrinos: " << *neutrinos;
180  LOG("gmkspl", pINFO) << "Targets: " << *targets;
181 
182  // Loop over all possible input init states and ask the GEVGDriver
183  // to build splines for all the interactions that its loaded list
184  // of event generators can generate.
185 
188  for(nuiter = neutrinos->begin(); nuiter != neutrinos->end(); ++nuiter) {
189  for(tgtiter = targets->begin(); tgtiter != targets->end(); ++tgtiter) {
190  int nupdgc = *nuiter;
191  int tgtpdgc = *tgtiter;
192  InitialState init_state(tgtpdgc, nupdgc);
193  GEVGDriver driver;
194  driver.SetEventGeneratorList(RunOpt::Instance()->EventGeneratorList());
195  driver.Configure(init_state);
197  }
198  }
199 
200  // Save the splines at the requested XML file
201  XSecSplineList * xspl = XSecSplineList::Instance();
202  bool save_init = !gOptNoCopy;
203  xspl->SaveAsXml(gOptOutXSecFile, save_init);
204 
205  delete neutrinos;
206  delete targets;
207 
208  return 0;
209 }
void RandGen(long int seed)
Definition: AppInit.cxx:30
PDGCodeList * GetTargetCodes(void)
void XSecTable(string inpfile, bool require_table)
Definition: AppInit.cxx:38
int gOptNKnots
PDGCodeList * GetNeutrinoCodes(void)
long int gOptRanSeed
string gOptInpXSecFile
#define pFATAL
Definition: Messenger.h:56
intermediate_table::const_iterator const_iterator
A list of PDG codes.
Definition: PDGCodeList.h:32
string gOptOutXSecFile
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
void SetEventGeneratorList(string listname)
Definition: GEVGDriver.cxx:348
size_t size
Definition: lodepng.cpp:55
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
Definition: GEVGDriver.h:54
#define pINFO
Definition: Messenger.h:62
void SaveAsXml(const string &filename, bool save_init=true) const
void PrintSyntax(void)
void Configure(int nu_pdgc, int Z, int A)
Definition: GEVGDriver.cxx:137
double gOptMaxE
A vector of EventGeneratorI objects.
void CreateSplines(int nknots=-1, double emax=-1, bool inLogE=true)
Definition: GEVGDriver.cxx:577
void GetCommandLineArgs(int argc, char **argv)
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
bool gOptNoCopy
List of cross section vs energy splines.
Initial State information.
Definition: InitialState.h:48
void PrintSyntax ( void  )

Definition at line 346 of file gMakeSplines.cxx.

347 {
348  LOG("gmkspl", pNOTICE)
349  << "\n\n" << "Syntax:" << "\n"
350  << " gmkspl -p nupdg <-t tgtpdg, -f geomfile> "
351  << " <-o | --output-cross-section> xsec_xml_file_name"
352  << " [-n nknots] [-e max_energy] "
353  << " [--seed seed_number]"
354  << " [--input-cross-section xml_file]"
355  << " [--event-generator-list list_name]"
356  << " [--xml-path config_xml_dir]"
357  << " [--message-thresholds xml_file]\n\n";
358 }
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define pNOTICE
Definition: Messenger.h:61

Variable Documentation

string gOptGeomFilename = ""

Definition at line 133 of file gMakeSplines.cxx.

string gOptInpXSecFile = ""

Definition at line 138 of file gMakeSplines.cxx.

double gOptMaxE = -1.

Definition at line 135 of file gMakeSplines.cxx.

int gOptNKnots = -1

Definition at line 134 of file gMakeSplines.cxx.

bool gOptNoCopy = false

Definition at line 136 of file gMakeSplines.cxx.

string gOptNuPdgCodeList = ""

Definition at line 131 of file gMakeSplines.cxx.

string gOptOutXSecFile = ""

Definition at line 139 of file gMakeSplines.cxx.

long int gOptRanSeed = -1

Definition at line 137 of file gMakeSplines.cxx.

string gOptTgtPdgCodeList = ""

Definition at line 132 of file gMakeSplines.cxx.