GENIEGenerator
Loading...
Searching...
No Matches
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"
Include dependency graph for gMakeSplines.cxx:

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

◆ GetCommandLineArgs()

void GetCommandLineArgs ( int argc,
char ** argv )

Definition at line 214 of file gMakeSplines.cxx.

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}
#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
Command line argument parser.
void ReadFromCommandLine(int argc, char **argv)
Definition RunOpt.cxx:99
void EnableBareXSecPreCalc(bool flag)
Definition RunOpt.h:62
static RunOpt * Instance(void)
Definition RunOpt.cxx:54
long int gOptRanSeed
string gOptInpXSecFile
int gOptNKnots
double gOptMaxE
string gOptTgtPdgCodeList
string gOptOutXSecFile
void PrintSyntax(void)
string gOptNuPdgCodeList
bool gOptNoCopy
string gOptGeomFilename
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f=' *')

References genie::CmdLnArgParser::ArgAsDouble(), genie::CmdLnArgParser::ArgAsInt(), genie::CmdLnArgParser::ArgAsLong(), genie::CmdLnArgParser::ArgAsString(), genie::RunOpt::EnableBareXSecPreCalc(), gOptGeomFilename, gOptInpXSecFile, gOptMaxE, gOptNKnots, gOptNoCopy, gOptNuPdgCodeList, gOptOutXSecFile, gOptRanSeed, gOptTgtPdgCodeList, genie::RunOpt::Instance(), LOG, genie::CmdLnArgParser::OptionExists(), pFATAL, pINFO, pNOTICE, genie::utils::print::PrintFramedMesg(), PrintSyntax(), and genie::RunOpt::ReadFromCommandLine().

Referenced by main().

◆ GetNeutrinoCodes()

PDGCodeList * GetNeutrinoCodes ( void )

Definition at line 366 of file gMakeSplines.cxx.

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}
A list of PDG codes.
Definition PDGCodeList.h:32
void push_back(int pdg_code)
vector< string > Split(string input, string delim)

References gOptNuPdgCodeList, genie::PDGCodeList::push_back(), and genie::utils::str::Split().

Referenced by main().

◆ GetTargetCodes()

PDGCodeList * GetTargetCodes ( void )

Definition at line 380 of file gMakeSplines.cxx.

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";
402 ROOTGeomAnalyzer * geom = new ROOTGeomAnalyzer(gOptGeomFilename);
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}
string geom
bool gAbortingInErr
Definition Messenger.cxx:34

References genie::gAbortingInErr, geom, gOptGeomFilename, gOptTgtPdgCodeList, LOG, pFATAL, pINFO, genie::PDGCodeList::push_back(), and genie::utils::str::Split().

Referenced by main().

◆ main()

int main ( int argc,
char ** argv )

Definition at line 145 of file gMakeSplines.cxx.

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}
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.
void BuildTune()
build tune and inform XSecSplineList
Definition RunOpt.cxx:92
List of cross section vs energy splines.
void SaveAsXml(const string &filename, bool save_init=true) const
static XSecSplineList * Instance()
PDGCodeList * GetTargetCodes(void)
PDGCodeList * GetNeutrinoCodes(void)
void GetCommandLineArgs(int argc, char **argv)
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

References genie::RunOpt::BuildTune(), genie::GEVGDriver::Configure(), genie::GEVGDriver::CreateSplines(), GetCommandLineArgs(), GetNeutrinoCodes(), GetTargetCodes(), gOptInpXSecFile, gOptMaxE, gOptNKnots, gOptNoCopy, gOptOutXSecFile, gOptRanSeed, genie::RunOpt::Instance(), genie::XSecSplineList::Instance(), LOG, genie::utils::app_init::MesgThresholds(), pFATAL, pINFO, PrintSyntax(), genie::utils::app_init::RandGen(), genie::XSecSplineList::SaveAsXml(), genie::GEVGDriver::SetEventGeneratorList(), and genie::utils::app_init::XSecTable().

◆ PrintSyntax()

void PrintSyntax ( void )

Definition at line 349 of file gMakeSplines.cxx.

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}
static std::string RunOptSyntaxString(bool include_generator_specific)
Definition RunOpt.cxx:157

References LOG, pNOTICE, and genie::RunOpt::RunOptSyntaxString().

Referenced by GetCommandLineArgs(), and main().

Variable Documentation

◆ gOptGeomFilename

string gOptGeomFilename = ""

Definition at line 136 of file gMakeSplines.cxx.

Referenced by GetCommandLineArgs(), GetTargetCodes(), and main().

◆ gOptInpXSecFile

string gOptInpXSecFile = ""

Definition at line 141 of file gMakeSplines.cxx.

◆ gOptMaxE

double gOptMaxE = -1.

Definition at line 138 of file gMakeSplines.cxx.

Referenced by GetCommandLineArgs(), and main().

◆ gOptNKnots

int gOptNKnots = -1

Definition at line 137 of file gMakeSplines.cxx.

Referenced by GetCommandLineArgs(), and main().

◆ gOptNoCopy

bool gOptNoCopy = false

Definition at line 139 of file gMakeSplines.cxx.

Referenced by GetCommandLineArgs(), and main().

◆ gOptNuPdgCodeList

string gOptNuPdgCodeList = ""

Definition at line 134 of file gMakeSplines.cxx.

Referenced by GetCommandLineArgs(), and GetNeutrinoCodes().

◆ gOptOutXSecFile

string gOptOutXSecFile = ""

Definition at line 142 of file gMakeSplines.cxx.

Referenced by GetCommandLineArgs(), and main().

◆ gOptRanSeed

long int gOptRanSeed = -1

Definition at line 140 of file gMakeSplines.cxx.

◆ gOptTgtPdgCodeList

string gOptTgtPdgCodeList = ""

Definition at line 135 of file gMakeSplines.cxx.

Referenced by GetCommandLineArgs(), and GetTargetCodes().