GENIEGenerator
Loading...
Searching...
No Matches
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-2025, 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"
109//#include "Framework/Utils/SystemUtils.h"
113
114#ifdef __GENIE_GEOM_DRIVERS_ENABLED__
116#endif
117
118using std::string;
119using std::vector;
120
121using namespace genie;
122
123#ifdef __GENIE_GEOM_DRIVERS_ENABLED__
124using namespace genie::geometry;
125#endif
126
127// Prototypes:
128void GetCommandLineArgs (int argc, char ** argv);
129void PrintSyntax (void);
132
133// User-specified options:
137int gOptNKnots = -1;
138double gOptMaxE = -1.;
139bool gOptNoCopy = false;
140long int gOptRanSeed = -1; // random number seed
141string gOptInpXSecFile = ""; // input cross-section file
142string gOptOutXSecFile = ""; // output cross-section file
143
144//____________________________________________________________________________
145int 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//____________________________________________________________________________
214void 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//____________________________________________________________________________
349void 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//____________________________________________________________________________
#define pNOTICE
Definition Messenger.h:61
#define pINFO
Definition Messenger.h:62
#define pFATAL
Definition Messenger.h:56
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Definition Messenger.h:96
int main()
Command line argument parser.
string ArgAsString(char opt)
double ArgAsDouble(char opt)
bool OptionExists(char opt)
was option set?
A vector of EventGeneratorI objects.
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
Definition GEVGDriver.h:54
void Configure(int nu_pdgc, int Z, int A)
void CreateSplines(int nknots=-1, double emax=-1, bool inLogE=true)
void SetEventGeneratorList(string listname)
Initial State information.
A list of PDG codes.
Definition PDGCodeList.h:32
void push_back(int pdg_code)
void ReadFromCommandLine(int argc, char **argv)
Definition RunOpt.cxx:99
static std::string RunOptSyntaxString(bool include_generator_specific)
Definition RunOpt.cxx:157
void BuildTune()
build tune and inform XSecSplineList
Definition RunOpt.cxx:92
void EnableBareXSecPreCalc(bool flag)
Definition RunOpt.h:62
static RunOpt * Instance(void)
Definition RunOpt.cxx:54
List of cross section vs energy splines.
void SaveAsXml(const string &filename, bool save_init=true) const
static XSecSplineList * Instance()
A ROOT/GEANT4 geometry driver.
long int gOptRanSeed
string gOptInpXSecFile
string geom
int gOptNKnots
PDGCodeList * GetTargetCodes(void)
double gOptMaxE
string gOptTgtPdgCodeList
string gOptOutXSecFile
PDGCodeList * GetNeutrinoCodes(void)
void GetCommandLineArgs(int argc, char **argv)
void PrintSyntax(void)
string gOptNuPdgCodeList
bool gOptNoCopy
string gOptGeomFilename
GENIE geometry drivers.
void XSecTable(string inpfile, bool require_table)
Definition AppInit.cxx:38
void RandGen(long int seed)
Definition AppInit.cxx:30
void MesgThresholds(string inpfile)
Definition AppInit.cxx:99
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f=' *')
vector< string > Split(string input, string delim)
THE MAIN GENIE PROJECT NAMESPACE
Definition AlgCmp.h:25
bool gAbortingInErr
Definition Messenger.cxx:34