GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gMakeSplines.cxx
Go to the documentation of this file.
1 //____________________________________________________________________________
2 /*!
3 
4 \program gmkspl
5 
6 \brief GENIE utility program building XML cross section splines that can
7  be loaded into GENIE to speed-up event generation.
8  The list of neutrino PDG codes is passed from the command line.
9  The list of nuclear target PDG codes is either passed from the
10  command line or extracted from the input ROOT/GEANT geometry.
11 
12  Syntax :
13 
14  gmkspl -p nupdg
15  <-t tgtpdg, -f geomfile>
16  <-o | --output-cross-sections> xsec_xml_file_name
17  [-n nknots]
18  [-e max_energy]
19  [--no-copy]
20  [--seed seed_number]
21  [--input-cross-sections xml_file]
22 
23  // command line args handled by RunOpt:
24  [--event-generator-list list_name] // default "Default"
25  [--tune tune_name] // default "G18_02a_00_000"
26  [--xml-path path]
27  [--message-thresholds xml_file]
28 
29 
30  Note :
31  [] marks optional arguments.
32  <> marks a list of arguments out of which only one can be
33  selected at any given time.
34 
35  Options :
36  -p
37  A comma separated list of nu PDG codes.
38  -t
39  A comma separated list of tgt PDG codes.
40  PDG code format: 10LZZZAAAI
41  -f
42  A ROOT file containing a ROOT/GEANT geometry description.
43  -o, --output-cross-sections
44  Name of output XML file containing computed cross-section data.
45  Default: `xsec_splines.xml'.
46  -n
47  Number of knots per spline.
48  Default: 15 knots per decade of energy range with a minimum
49  of 30 knots totally.
50  -e
51  Maximum energy in spline.
52  Default: The max energy in the validity range of the spline
53  generating thread.
54  --no-copy
55  Does not write out the input cross-sections in the output file
56  --seed
57  Random number seed.
58  --input-cross-sections
59  Name (incl. full path) of an XML file with pre-computed
60  free-nucleon cross-section values. If loaded, it can speed-up
61  cross-section calculation for nuclear targets.
62 
63  --event-generator-list
64  List of event generators to load in event generation drivers.
65  [default: "Default"].
66  --tune
67  Specifies a GENIE comprehensive neutrino interaction model tune.
68  [default: "Default"].
69  --xml-path
70  A directory to load XML files from - overrides $GXMLPATH, and $GENIE/config
71  --message-thresholds
72  Allows users to customize the message stream thresholds.
73  The thresholds are specified using an XML file.
74  See $GENIE/config/Messenger.xml for the XML schema.
75 
76  *** See the User Manual for more details and examples. ***
77 
78 \author Costas Andreopoulos <c.andreopoulos \at cern.ch>
79  University of Liverpool
80 
81 \created September 27, 2005
82 
83 \cpright Copyright (c) 2003-2024, The GENIE Collaboration
84  For the full text of the license visit http://copyright.genie-mc.org
85 
86 */
87 //____________________________________________________________________________
88 
89 #include <cassert>
90 #include <cstdlib>
91 #include <string>
92 #include <vector>
93 
94 #if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT)
95 #include <fenv.h> // for `feenableexcept`
96 #endif
97 
98 #include <TSystem.h>
99 
100 #include "Framework/Conventions/GBuild.h"
106 #include "Framework/Utils/RunOpt.h"
107 #include "Framework/Utils/AppInit.h"
109 //#include "Framework/Utils/SystemUtils.h"
113 
114 #ifdef __GENIE_GEOM_DRIVERS_ENABLED__
116 #endif
117 
118 using std::string;
119 using std::vector;
120 
121 using namespace genie;
122 
123 #ifdef __GENIE_GEOM_DRIVERS_ENABLED__
124 using namespace genie::geometry;
125 #endif
126 
127 // Prototypes:
128 void GetCommandLineArgs (int argc, char ** argv);
129 void PrintSyntax (void);
131 PDGCodeList * GetTargetCodes (void);
132 
133 // User-specified options:
134 string gOptNuPdgCodeList = "";
135 string gOptTgtPdgCodeList = "";
136 string gOptGeomFilename = "";
137 int gOptNKnots = -1;
138 double gOptMaxE = -1.;
139 bool gOptNoCopy = false;
140 long int gOptRanSeed = -1; // random number seed
141 string gOptInpXSecFile = ""; // input cross-section file
142 string gOptOutXSecFile = ""; // output cross-section file
143 
144 //____________________________________________________________________________
145 int main(int argc, char ** argv)
146 {
147  // Parse command line arguments
148  GetCommandLineArgs(argc,argv);
149 
150  if ( ! RunOpt::Instance()->Tune() ) {
151  LOG("gmkspl", pFATAL) << " No TuneId in RunOption";
152  exit(-1);
153  }
155 
156  // throw on NaNs and Infs...
157 #if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT)
158  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
159 #endif
160 
161  // Init
162  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
165 
166  // Get list of neutrinos and nuclear targets
167 
168  PDGCodeList * neutrinos = GetNeutrinoCodes();
169  PDGCodeList * targets = GetTargetCodes();
170 
171  if(!neutrinos || neutrinos->size() == 0 ) {
172  LOG("gmkspl", pFATAL) << "Empty neutrino PDG code list";
173  PrintSyntax();
174  exit(2);
175  }
176  if(!targets || targets->size() == 0 ) {
177  LOG("gmkspl", pFATAL) << "Empty target PDG code list";
178  PrintSyntax();
179  exit(3);
180  }
181 
182  LOG("gmkspl", pINFO) << "Neutrinos: " << *neutrinos;
183  LOG("gmkspl", pINFO) << "Targets: " << *targets;
184 
185  // Loop over all possible input init states and ask the GEVGDriver
186  // to build splines for all the interactions that its loaded list
187  // of event generators can generate.
188 
189  PDGCodeList::const_iterator nuiter;
190  PDGCodeList::const_iterator tgtiter;
191  for(nuiter = neutrinos->begin(); nuiter != neutrinos->end(); ++nuiter) {
192  for(tgtiter = targets->begin(); tgtiter != targets->end(); ++tgtiter) {
193  int nupdgc = *nuiter;
194  int tgtpdgc = *tgtiter;
195  InitialState init_state(tgtpdgc, nupdgc);
196  GEVGDriver driver;
198  driver.Configure(init_state);
200  }
201  }
202 
203  // Save the splines at the requested XML file
205  bool save_init = !gOptNoCopy;
206  xspl->SaveAsXml(gOptOutXSecFile, save_init);
207 
208  delete neutrinos;
209  delete targets;
210 
211  return 0;
212 }
213 //____________________________________________________________________________
214 void GetCommandLineArgs(int argc, char ** argv)
215 {
216  LOG("gmkspl", pINFO) << "Parsing command line arguments";
217 
218  // Common run options. Set defaults and read.
221 
222  // Parse run options for this app
223 
224  CmdLnArgParser parser(argc,argv);
225 
226  // output XML file name
227  if( parser.OptionExists('o') ||
228  parser.OptionExists("output-cross-sections") )
229  {
230  LOG("gmkspl", pINFO) << "Reading output filename";
231  if( parser.OptionExists('o') ) {
232  gOptOutXSecFile = parser.ArgAsString('o');
233  }
234  else {
235  gOptOutXSecFile = parser.ArgAsString("output-cross-sections");
236  }
237  } else {
238  LOG("gmkspl", pINFO) << "Unspecified filename - Using default";
239  gOptOutXSecFile = "xsec_splines.xml";
240  }
241 
242  // number of knots
243  if( parser.OptionExists('n') ) {
244  LOG("gmkspl", pINFO) << "Reading number of knots/spline";
245  gOptNKnots = parser.ArgAsInt('n');
246  } else {
247  LOG("gmkspl", pINFO)
248  << "Unspecified number of knots - Using default";
249  gOptNKnots = -1;
250  }
251 
252  // max spline energy (if < max of validity range)
253  if( parser.OptionExists('e') ) {
254  LOG("gmkspl", pINFO) << "Reading maximum spline energy";
255  gOptMaxE = parser.ArgAsDouble('e');
256  } else {
257  LOG("gmkspl", pINFO)
258  << "Unspecified maximum spline energy - Using default";
259  gOptMaxE = -1;
260  }
261 
262  // write out input splines?
263  if( parser.OptionExists("no-copy") ) {
264  LOG("gmkspl", pINFO) << "Not copying input splines to output";
265  gOptNoCopy = true;
266  }
267 
268  // comma-separated neutrino PDG code list
269  if( parser.OptionExists('p') ) {
270  LOG("gmkspl", pINFO) << "Reading neutrino PDG codes";
271  gOptNuPdgCodeList = parser.ArgAsString('p');
272  } else {
273  LOG("gmkspl", pFATAL)
274  << "Unspecified neutrino PDG code list - Exiting";
275  PrintSyntax();
276  exit(1);
277  }
278 
279  // comma-separated target PDG code list or input geometry file
280  bool tgt_cmd = true;
281  if( parser.OptionExists('t') ) {
282  LOG("gmkspl", pINFO) << "Reading target nuclei PDG codes";
283  gOptTgtPdgCodeList = parser.ArgAsString('t');
284  } else {
285  LOG("gmkspl", pINFO) << "No code list specified from the command line";
286  tgt_cmd = false;
287  }
288 
289  bool tgt_geom = true;
290  if( parser.OptionExists('f') ) {
291  LOG("gmkspl", pINFO) << "Reading ROOT geometry filename";
292  gOptGeomFilename = parser.ArgAsString('f');
293  } else {
294  LOG("gmkspl", pINFO) << "No geometry file was specified";
295  tgt_cmd = false;
296  }
297 
298  bool both = tgt_geom && tgt_cmd;
299  bool none = !tgt_geom && !tgt_cmd;
300  if(none) {
301  LOG("gmkspl", pFATAL)
302  << "No geom file or cmd line target list was specified - Exiting";
303  PrintSyntax();
304  exit(1);
305  }
306  if(both) {
307  LOG("gmkspl", pFATAL)
308  << "You specified both a geom file and a cmd line target list "
309  << "- Exiting confused";
310  PrintSyntax();
311  exit(1);
312  }
313 
314  // random number seed
315  if( parser.OptionExists("seed") ) {
316  LOG("gmkspl", pINFO) << "Reading random number seed";
317  gOptRanSeed = parser.ArgAsLong("seed");
318  } else {
319  LOG("gmkspl", pINFO) << "Unspecified random number seed - Using default";
320  gOptRanSeed = -1;
321  }
322 
323  // input cross-section file
324  if( parser.OptionExists("input-cross-sections") ) {
325  LOG("gmkspl", pINFO) << "Reading cross-section file";
326  gOptInpXSecFile = parser.ArgAsString("input-cross-sections");
327  } else {
328  LOG("gmkspl", pINFO) << "Unspecified input cross-section file";
329  gOptInpXSecFile = "";
330  }
331 
332  //
333  // print the command-line options
334  //
335  LOG("gmkspl", pNOTICE)
336  << "\n"
337  << utils::print::PrintFramedMesg("gmkspl job configuration")
338  << "\n Neutrino PDG codes : " << gOptNuPdgCodeList
339  << "\n Target PDG codes : " << gOptTgtPdgCodeList
340  << "\n Input ROOT geometry : " << gOptGeomFilename
341  << "\n Output cross-section file : " << gOptOutXSecFile
342  << "\n Input cross-section file : " << gOptInpXSecFile
343  << "\n Random number seed : " << gOptRanSeed
344  << "\n";
345 
346  LOG("gmkspl", pNOTICE) << *RunOpt::Instance();
347 }
348 //____________________________________________________________________________
349 void PrintSyntax(void)
350 {
351  LOG("gmkspl", pNOTICE)
352  << "\n\n" << "Syntax:" << "\n"
353  << " gmkspl -p nupdg"
354  << "\n <-t tgtpdg, -f geomfile> "
355  << "\n <-o | --output-cross-sections> xsec_xml_file_name"
356  << "\n [-n nknots]"
357  << "\n [-e max_energy]"
358  << "\n [--no-copy]"
359  << "\n [--seed seed_number]"
360  << "\n [--input-cross-sections xml_file]"
362  << "\n";
363 
364 }
365 //____________________________________________________________________________
367 {
368  // split the comma separated list
369  vector<string> nuvec = utils::str::Split(gOptNuPdgCodeList, ",");
370 
371  // fill in the PDG code list
372  PDGCodeList * list = new PDGCodeList;
373  vector<string>::const_iterator iter;
374  for(iter = nuvec.begin(); iter != nuvec.end(); ++iter) {
375  list->push_back( atoi(iter->c_str()) );
376  }
377  return list;
378 }
379 //____________________________________________________________________________
381 {
382  bool from_geom_file = ( gOptGeomFilename.size() > 0 );
383  bool from_cmd_line = ( gOptTgtPdgCodeList.size() > 0 );
384 
385  if (from_cmd_line) {
386  // split the comma separated list
387  vector<string> tgtvec = utils::str::Split(gOptTgtPdgCodeList, ",");
388 
389  // fill in the PDG code list
390  PDGCodeList * list = new PDGCodeList;
391  vector<string>::const_iterator iter;
392  for(iter = tgtvec.begin(); iter != tgtvec.end(); ++iter) {
393  list->push_back( atoi(iter->c_str()) );
394  }
395  return list;
396  }
397 
398  if (from_geom_file) {
399 #ifdef __GENIE_GEOM_DRIVERS_ENABLED__
400  // create/configure a geometry driver
401  LOG("gmkspl", pINFO) << "Creating/configuring a ROOT geom. driver";
403 
404  PDGCodeList * list = new PDGCodeList(geom->ListOfTargetNuclei());
405 
406  delete geom;
407  return list;
408 #else
409  LOG("gmkspl", pFATAL)
410  << "To read-in a ROOT geometry you need to enable the geometry drivers!";
411  gAbortingInErr = true;
412  exit(1);
413  return 0;
414 #endif
415 
416  }
417  return 0;
418 }
419 //____________________________________________________________________________
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)
string gOptNuPdgCodeList
void ReadFromCommandLine(int argc, char **argv)
Definition: RunOpt.cxx:99
#define pFATAL
Definition: Messenger.h:56
static XSecSplineList * Instance()
virtual const PDGCodeList & ListOfTargetNuclei(void)
implement the GeomAnalyzerI interface
int main(int argc, char **argv)
Definition: gAtmoEvGen.cxx:327
A list of PDG codes.
Definition: PDGCodeList.h:32
string gOptOutXSecFile
string gOptInpXSecFile
Definition: gAtmoEvGen.cxx:313
#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
static std::string RunOptSyntaxString(bool include_generator_specific)
Definition: RunOpt.cxx:157
string geom
string gOptTgtPdgCodeList
A ROOT/GEANT4 geometry driver.
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
Definition: GEVGDriver.h:54
#define pINFO
Definition: Messenger.h:62
void BuildTune()
build tune and inform XSecSplineList
Definition: RunOpt.cxx:92
void SaveAsXml(const string &filename, bool save_init=true) const
static RunOpt * Instance(void)
Definition: RunOpt.cxx:54
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
void Configure(int nu_pdgc, int Z, int A)
Definition: GEVGDriver.cxx:137
double gOptMaxE
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f='*')
Definition: PrintUtils.cxx:164
A vector of EventGeneratorI objects.
void CreateSplines(int nknots=-1, double emax=-1, bool inLogE=true)
Definition: GEVGDriver.cxx:577
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
Command line argument parser.
#define pNOTICE
Definition: Messenger.h:61
void GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
bool gOptNoCopy
bool gAbortingInErr
Definition: Messenger.cxx:34
List of cross section vs energy splines.
void PrintSyntax(void)
void EnableBareXSecPreCalc(bool flag)
Definition: RunOpt.h:62
void push_back(int pdg_code)
Definition: PDGCodeList.cxx:58
string gOptGeomFilename
Initial State information.
Definition: InitialState.h:48
long int gOptRanSeed
Definition: gAtmoEvGen.cxx:312