Functions | Variables
gEvGen.cxx File Reference
#include <cstdlib>
#include <cassert>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <TFile.h>
#include <TTree.h>
#include <TSystem.h>
#include <TVector3.h>
#include <TH1.h>
#include <TF1.h>
#include "Framework/Conventions/XmlParserStatus.h"
#include "Framework/Conventions/GBuild.h"
#include "Framework/Conventions/Controls.h"
#include "Framework/EventGen/EventRecord.h"
#include "Framework/EventGen/GFluxI.h"
#include "Framework/EventGen/GEVGDriver.h"
#include "Framework/EventGen/GMCJDriver.h"
#include "Framework/EventGen/GMCJMonitor.h"
#include "Framework/Interaction/Interaction.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/Ntuple/NtpWriter.h"
#include "Framework/Ntuple/NtpMCFormat.h"
#include "Framework/Numerical/RandomGen.h"
#include "Framework/Numerical/Spline.h"
#include "Framework/ParticleData/PDGCodes.h"
#include "Framework/ParticleData/PDGUtils.h"
#include "Framework/Utils/AppInit.h"
#include "Framework/Utils/RunOpt.h"
#include "Framework/Utils/XSecSplineList.h"
#include "Framework/Utils/StringUtils.h"
#include "Framework/Utils/PrintUtils.h"
#include "Framework/Utils/SystemUtils.h"
#include "Framework/Utils/CmdLnArgParser.h"

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void Initialize (void)
 
void PrintSyntax (void)
 
void GenerateEventsAtFixedInitState (void)
 
int main (int argc, char **argv)
 

Variables

int kDefOptNevents = 0
 
NtpMCFormat_t kDefOptNtpFormat = kNFGHEP
 
Long_t kDefOptRunNu = 0
 
int gOptNevents
 
double gOptNuEnergy
 
double gOptNuEnergyRange
 
int gOptNuPdgCode
 
map< int, double > gOptTgtMix
 
Long_t gOptRunNu
 
string gOptFlux
 
bool gOptWeighted
 
bool gOptUsingFluxOrTgtMix = false
 
long int gOptRanSeed
 
string gOptInpXSecFile
 
string gOptOutFileName
 
string gOptStatFileName
 

Function Documentation

void GenerateEventsAtFixedInitState ( void  )

Definition at line 267 of file gEvGen.cxx.

268 {
269  int neutrino = gOptNuPdgCode;
270  int target = gOptTgtMix.begin()->first;
271  double Ev = gOptNuEnergy;
272  TLorentzVector nu_p4(0.,0.,Ev,Ev); // px,py,pz,E (GeV)
273 
274  // Create init state
275  InitialState init_state(target, neutrino);
276 
277  // Create/config event generation driver
278  GEVGDriver evg_driver;
279  evg_driver.SetEventGeneratorList(RunOpt::Instance()->EventGeneratorList());
280  evg_driver.SetUnphysEventMask(*RunOpt::Instance()->UnphysEventMask());
281  evg_driver.Configure(init_state);
282 
283  // Initialize an Ntuple Writer
285 
286  // If an output file name has been specified... use it
287  if (!gOptOutFileName.empty()){
288  ntpw.CustomizeFilename(gOptOutFileName);
289  }
290  ntpw.Initialize();
291 
292 
293  // Create an MC Job Monitor
294  GMCJMonitor mcjmonitor(gOptRunNu);
295  mcjmonitor.SetRefreshRate(RunOpt::Instance()->MCJobStatusRefreshRate());
296 
297  // If a status file name has been given... use it
298  if (!gOptStatFileName.empty()){
299  mcjmonitor.CustomizeFilename(gOptStatFileName);
300  }
301 
302 
303  LOG("gevgen", pNOTICE)
304  << "\n ** Will generate " << gOptNevents << " events for \n"
305  << init_state << " at Ev = " << Ev << " GeV";
306 
307  // Generate events / print the GHEP record / add it to the ntuple
308  int ievent = 0;
309  while (ievent < gOptNevents) {
310  LOG("gevgen", pNOTICE)
311  << " *** Generating event............ " << ievent;
312 
313  // generate a single event
314  EventRecord * event = evg_driver.GenerateEvent(nu_p4);
315 
316  if(!event) {
317  LOG("gevgen", pNOTICE)
318  << "Last attempt failed. Re-trying....";
319  continue;
320  }
321 
322  LOG("gevgen", pNOTICE)
323  << "Generated Event GHEP Record: " << *event;
324 
325  // add event at the output ntuple, refresh the mc job monitor & clean up
326  ntpw.AddEventRecord(ievent, event);
327  mcjmonitor.Update(ievent,event);
328  ievent++;
329  delete event;
330  }
331 
332  // Save the generated MC events
333  ntpw.Save();
334 }
long int gOptRanSeed
Definition: gEvGen.cxx:213
Long_t gOptRunNu
Definition: gEvGen.cxx:209
NtpMCFormat_t kDefOptNtpFormat
Definition: gEvGen.cxx:200
int gOptNuPdgCode
Definition: gEvGen.cxx:207
int gOptNevents
Definition: gEvGen.cxx:204
string gOptStatFileName
Definition: gEvGen.cxx:216
Simple class to create & update MC job status files and env. vars. This is used to be able to keep tr...
Definition: GMCJMonitor.h:31
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
double gOptNuEnergy
Definition: gEvGen.cxx:205
void SetEventGeneratorList(string listname)
Definition: GEVGDriver.cxx:348
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
Definition: GEVGDriver.h:54
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
A utility class to facilitate creating the GENIE MC Ntuple from the output GENIE GHEP event records...
Definition: NtpWriter.h:39
map< int, double > gOptTgtMix
Definition: gEvGen.cxx:208
string gOptOutFileName
Definition: gEvGen.cxx:215
void Configure(int nu_pdgc, int Z, int A)
Definition: GEVGDriver.cxx:137
A vector of EventGeneratorI objects.
#define pNOTICE
Definition: Messenger.h:61
void SetUnphysEventMask(const TBits &mask)
Definition: GEVGDriver.cxx:219
Event finding and building.
Initial State information.
Definition: InitialState.h:48
EventRecord * GenerateEvent(const TLorentzVector &nu4p)
Definition: GEVGDriver.cxx:228
void GetCommandLineArgs ( int  argc,
char **  argv 
)

Definition at line 556 of file gEvGen.cxx.

557 {
558  LOG("gevgen", pINFO) << "Parsing command line arguments";
559 
560  // Common run options. Set defaults and read.
561  RunOpt::Instance()->EnableBareXSecPreCalc(true);
562  RunOpt::Instance()->ReadFromCommandLine(argc,argv);
563 
564  // Parse run options for this app
565 
566  CmdLnArgParser parser(argc,argv);
567 
568  // help?
569  bool help = parser.OptionExists('h');
570  if(help) {
571  PrintSyntax();
572  exit(0);
573  }
574 
575  // number of events
576  if( parser.OptionExists('n') ) {
577  LOG("gevgen", pINFO) << "Reading number of events to generate";
578  gOptNevents = parser.ArgAsInt('n');
579  } else {
580  LOG("gevgen", pINFO)
581  << "Unspecified number of events to generate - Using default";
583  }
584 
585  // run number
586  if( parser.OptionExists('r') ) {
587  LOG("gevgen", pINFO) << "Reading MC run number";
588  gOptRunNu = parser.ArgAsLong('r');
589  } else {
590  LOG("gevgen", pINFO) << "Unspecified run number - Using default";
592  }
593 
594  // Output file name
595  if( parser.OptionExists('o') ) {
596  LOG("gevgen", pINFO) << "Reading output file name";
597  gOptOutFileName = parser.ArgAsString('o');
598 
600  // strip the output file format and replace with .status
601  if (gOptOutFileName.find_last_of(".") != string::npos)
603  gOptStatFileName.substr(0, gOptOutFileName.find_last_of("."));
604  gOptStatFileName .append(".status");
605  }
606 
607  // flux functional form
608  bool using_flux = false;
609  if( parser.OptionExists('f') ) {
610  LOG("gevgen", pINFO) << "Reading flux function";
611  gOptFlux = parser.ArgAsString('f');
612  using_flux = true;
613  }
614 
615  if(parser.OptionExists('s')) {
616  LOG("gevgen", pWARN)
617  << "-s option no longer available. Please read the revised code documentation";
618  gAbortingInErr = true;
619  exit(1);
620  }
621 
622 
623  // generate weighted events option (only relevant if using a flux)
624  gOptWeighted = parser.OptionExists('w');
625 
626  // neutrino energy
627  if( parser.OptionExists('e') ) {
628  LOG("gevgen", pINFO) << "Reading neutrino energy";
629  string nue = parser.ArgAsString('e');
630 
631  // is it just a value or a range (comma separated set of values)
632  if(nue.find(",") != string::npos) {
633  // split the comma separated list
634  vector<string> nurange = utils::str::Split(nue, ",");
635  assert(nurange.size() == 2);
636  double emin = atof(nurange[0].c_str());
637  double emax = atof(nurange[1].c_str());
638  assert(emax>emin && emin>=0);
639  gOptNuEnergy = emin;
640  gOptNuEnergyRange = emax-emin;
641  if(!using_flux) {
642  LOG("gevgen", pWARN)
643  << "No flux was specified but an energy range was input!";
644  LOG("gevgen", pWARN)
645  << "Events will be generated at fixed E = " << gOptNuEnergy << " GeV";
646  gOptNuEnergyRange = -1;
647  }
648  } else {
649  gOptNuEnergy = atof(nue.c_str());
650  gOptNuEnergyRange = -1;
651  }
652  } else {
653  LOG("gevgen", pFATAL) << "Unspecified neutrino energy - Exiting";
654  PrintSyntax();
655  exit(1);
656  }
657 
658  // neutrino PDG code
659  if( parser.OptionExists('p') ) {
660  LOG("gevgen", pINFO) << "Reading neutrino PDG code";
661  gOptNuPdgCode = parser.ArgAsInt('p');
662  } else {
663  LOG("gevgen", pFATAL) << "Unspecified neutrino PDG code - Exiting";
664  PrintSyntax();
665  exit(1);
666  }
667 
668  // target mix (their PDG codes with their corresponding weights)
669  bool using_tgtmix = false;
670  if( parser.OptionExists('t') ) {
671  LOG("gevgen", pINFO) << "Reading target mix";
672  string stgtmix = parser.ArgAsString('t');
673  gOptTgtMix.clear();
674  vector<string> tgtmix = utils::str::Split(stgtmix,",");
675  if(tgtmix.size()==1) {
676  int pdg = atoi(tgtmix[0].c_str());
677  double wgt = 1.0;
678  gOptTgtMix.insert(map<int, double>::value_type(pdg, wgt));
679  } else {
680  using_tgtmix = true;
681  vector<string>::const_iterator tgtmix_iter = tgtmix.begin();
682  for( ; tgtmix_iter != tgtmix.end(); ++tgtmix_iter) {
683  string tgt_with_wgt = *tgtmix_iter;
684  string::size_type open_bracket = tgt_with_wgt.find("[");
685  string::size_type close_bracket = tgt_with_wgt.find("]");
686  string::size_type ibeg = 0;
687  string::size_type iend = open_bracket;
688  string::size_type jbeg = open_bracket+1;
689  string::size_type jend = close_bracket-1;
690  int pdg = atoi(tgt_with_wgt.substr(ibeg,iend).c_str());
691  double wgt = atof(tgt_with_wgt.substr(jbeg,jend).c_str());
692  LOG("Main", pNOTICE)
693  << "Adding to target mix: pdg = " << pdg << ", wgt = " << wgt;
694  gOptTgtMix.insert(map<int, double>::value_type(pdg, wgt));
695  }//tgtmix_iter
696  }//>1
697 
698  } else {
699  LOG("gevgen", pFATAL) << "Unspecified target PDG code - Exiting";
700  PrintSyntax();
701  exit(1);
702  }
703 
704  gOptUsingFluxOrTgtMix = using_flux || using_tgtmix;
705 
706  // random number seed
707  if( parser.OptionExists("seed") ) {
708  LOG("gevgen", pINFO) << "Reading random number seed";
709  gOptRanSeed = parser.ArgAsLong("seed");
710  } else {
711  LOG("gevgen", pINFO) << "Unspecified random number seed - Using default";
712  gOptRanSeed = -1;
713  }
714 
715  // input cross-section file
716  if( parser.OptionExists("cross-sections") ) {
717  LOG("gevgen", pINFO) << "Reading cross-section file";
718  gOptInpXSecFile = parser.ArgAsString("cross-sections");
719  } else {
720  LOG("gevgen", pINFO) << "Unspecified cross-section file";
721  gOptInpXSecFile = "";
722  }
723 
724  //
725  // print-out the command line options
726  //
727  LOG("gevgen", pNOTICE)
728  << "\n"
729  << utils::print::PrintFramedMesg("gevgen job configuration");
730  LOG("gevgen", pNOTICE)
731  << "MC Run Number: " << gOptRunNu;
732  if(gOptRanSeed != -1) {
733  LOG("gevgen", pNOTICE)
734  << "Random number seed: " << gOptRanSeed;
735  } else {
736  LOG("gevgen", pNOTICE)
737  << "Random number seed was not set, using default";
738  }
739  LOG("gevgen", pNOTICE)
740  << "Number of events requested: " << gOptNevents;
741  if(gOptInpXSecFile.size() > 0) {
742  LOG("gevgen", pNOTICE)
743  << "Using cross-section splines read from: " << gOptInpXSecFile;
744  } else {
745  LOG("gevgen", pNOTICE)
746  << "No input cross-section spline file";
747  }
748  LOG("gevgen", pNOTICE)
749  << "Flux: " << gOptFlux;
750  LOG("gevgen", pNOTICE)
751  << "Generate weighted events? " << gOptWeighted;
752  if(gOptNuEnergyRange>0) {
753  LOG("gevgen", pNOTICE)
754  << "Neutrino energy: ["
755  << gOptNuEnergy << ", " << gOptNuEnergy+gOptNuEnergyRange << "]";
756  } else {
757  LOG("gevgen", pNOTICE)
758  << "Neutrino energy: " << gOptNuEnergy;
759  }
760  LOG("gevgen", pNOTICE)
761  << "Neutrino code (PDG): " << gOptNuPdgCode;
762  LOG("gevgen", pNOTICE)
763  << "Target code (PDG) & weight fraction (in case of multiple targets): ";
765  for(iter = gOptTgtMix.begin(); iter != gOptTgtMix.end(); ++iter) {
766  int tgtpdgc = iter->first;
767  double wgt = iter->second;
768  LOG("gevgen", pNOTICE)
769  << " >> " << tgtpdgc << " (weight fraction = " << wgt << ")";
770  }
771  LOG("gevgen", pNOTICE) << "\n";
772 
773  LOG("gevgen", pNOTICE) << *RunOpt::Instance();
774 
775 }
long int gOptRanSeed
Definition: gEvGen.cxx:213
Long_t kDefOptRunNu
Definition: gEvGen.cxx:201
Long_t gOptRunNu
Definition: gEvGen.cxx:209
#define pFATAL
Definition: Messenger.h:56
int gOptNuPdgCode
Definition: gEvGen.cxx:207
int gOptNevents
Definition: gEvGen.cxx:204
intermediate_table::const_iterator const_iterator
string gOptStatFileName
Definition: gEvGen.cxx:216
double gOptNuEnergyRange
Definition: gEvGen.cxx:206
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
double gOptNuEnergy
Definition: gEvGen.cxx:205
bool gOptWeighted
Definition: gEvGen.cxx:211
#define pINFO
Definition: Messenger.h:62
string gOptInpXSecFile
Definition: gEvGen.cxx:214
#define pWARN
Definition: Messenger.h:60
string gOptFlux
Definition: gEvGen.cxx:210
int kDefOptNevents
Definition: gEvGen.cxx:199
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
map< int, double > gOptTgtMix
Definition: gEvGen.cxx:208
bool gOptUsingFluxOrTgtMix
Definition: gEvGen.cxx:212
string gOptOutFileName
Definition: gEvGen.cxx:215
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
void PrintSyntax(void)
Definition: gEvGen.cxx:777
bool gAbortingInErr
Definition: Messenger.cxx:34
void Initialize ( void  )

Definition at line 247 of file gEvGen.cxx.

248 {
249 
250  if ( ! RunOpt::Instance()->Tune() ) {
251  LOG("gevgen", pFATAL) << " No TuneId in RunOption";
252  exit(-1);
253  }
254  RunOpt::Instance()->BuildTune();
255 
256  // Initialization of random number generators, cross-section table,
257  // messenger thresholds, cache file
258  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
259  utils::app_init::CacheFile(RunOpt::Instance()->CacheFile());
262 
263  // Set GHEP print level
264  GHepRecord::SetPrintLevel(RunOpt::Instance()->EventRecordPrintLevel());
265 }
void RandGen(long int seed)
Definition: AppInit.cxx:30
void XSecTable(string inpfile, bool require_table)
Definition: AppInit.cxx:38
long int gOptRanSeed
Definition: gEvGen.cxx:213
#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
string gOptInpXSecFile
Definition: gEvGen.cxx:214
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
void CacheFile(string inpfile)
Definition: AppInit.cxx:117
int main ( int  argc,
char **  argv 
)

Definition at line 219 of file gEvGen.cxx.

220 {
221  GetCommandLineArgs(argc,argv);
222  Initialize();
223 
224  // throw on NaNs and Infs...
225 #if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT)
226  feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
227 #endif
228  //
229  // Generate neutrino events
230  //
231 
233 #ifdef __CAN_GENERATE_EVENTS_USING_A_FLUX_OR_TGTMIX__
234  GenerateEventsUsingFluxOrTgtMix();
235 #else
236  LOG("gevgen", pERROR)
237  << "\n To be able to generate neutrino events from a flux and/or a target mix"
238  << "\n you need to add the following config options at your GENIE installation:"
239  << "\n --enable-flux-drivers --enable-geom-drivers \n" ;
240 #endif
241  } else {
243  }
244  return 0;
245 }
#define pERROR
Definition: Messenger.h:59
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool gOptUsingFluxOrTgtMix
Definition: gEvGen.cxx:212
void GetCommandLineArgs(int argc, char **argv)
Definition: gEvGen.cxx:556
void GenerateEventsAtFixedInitState(void)
Definition: gEvGen.cxx:267
void Initialize(void)
Definition: gEvGen.cxx:247
void PrintSyntax ( void  )

Definition at line 777 of file gEvGen.cxx.

778 {
779  LOG("gevgen", pNOTICE)
780  << "\n\n" << "Syntax:" << "\n"
781  << "\n gevgen [-h]"
782  << "\n [-r run#]"
783  << "\n -n nev"
784  << "\n -e energy (or energy range) "
785  << "\n -p neutrino_pdg"
786  << "\n -t target_pdg "
787  << "\n [-f flux_description]"
788  << "\n [-o outfile_name]"
789  << "\n [-w]"
790  << "\n [--seed random_number_seed]"
791  << "\n [--cross-sections xml_file]"
792  << "\n [--event-generator-list list_name]"
793  << "\n [--message-thresholds xml_file]"
794  << "\n [--unphysical-event-mask mask]"
795  << "\n [--event-record-print-level level]"
796  << "\n [--mc-job-status-refresh-rate rate]"
797  << "\n [--cache-file root_file]"
798  << "\n [--xml-path config_xml_dir]"
799  << "\n [--tune G18_02a_00_000] (or your preferred tune identifier)"
800  << "\n";
801 }
#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 gOptFlux

Definition at line 210 of file gEvGen.cxx.

string gOptInpXSecFile

Definition at line 214 of file gEvGen.cxx.

int gOptNevents

Definition at line 204 of file gEvGen.cxx.

double gOptNuEnergy

Definition at line 205 of file gEvGen.cxx.

double gOptNuEnergyRange

Definition at line 206 of file gEvGen.cxx.

int gOptNuPdgCode

Definition at line 207 of file gEvGen.cxx.

string gOptOutFileName

Definition at line 215 of file gEvGen.cxx.

long int gOptRanSeed

Definition at line 213 of file gEvGen.cxx.

Long_t gOptRunNu

Definition at line 209 of file gEvGen.cxx.

string gOptStatFileName

Definition at line 216 of file gEvGen.cxx.

map<int,double> gOptTgtMix

Definition at line 208 of file gEvGen.cxx.

bool gOptUsingFluxOrTgtMix = false

Definition at line 212 of file gEvGen.cxx.

bool gOptWeighted

Definition at line 211 of file gEvGen.cxx.

int kDefOptNevents = 0

Definition at line 199 of file gEvGen.cxx.

NtpMCFormat_t kDefOptNtpFormat = kNFGHEP

Definition at line 200 of file gEvGen.cxx.

Long_t kDefOptRunNu = 0

Definition at line 201 of file gEvGen.cxx.