132 #if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT) 139 #include <TVector3.h> 144 #include "Framework/Conventions/GBuild.h" 167 #ifdef __GENIE_FLUX_DRIVERS_ENABLED__ 168 #ifdef __GENIE_GEOM_DRIVERS_ENABLED__ 169 #define __CAN_GENERATE_EVENTS_USING_A_FLUX_OR_TGTMIX__ 179 using std::ostringstream;
181 using namespace genie;
188 #ifdef __CAN_GENERATE_EVENTS_USING_A_FLUX_OR_TGTMIX__ 189 void GenerateEventsUsingFluxOrTgtMix();
191 GFluxI * FluxDriver (
void);
192 GFluxI * MonoEnergeticFluxDriver (
void);
193 GFluxI * TH1FluxDriver (
void);
225 #if defined(HAVE_FENV_H) && defined(HAVE_FEENABLEEXCEPT) 226 feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
233 #ifdef __CAN_GENERATE_EVENTS_USING_A_FLUX_OR_TGTMIX__ 234 GenerateEventsUsingFluxOrTgtMix();
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" ;
251 LOG(
"gevgen",
pFATAL) <<
" No TuneId in RunOption";
270 int target = gOptTgtMix.begin()->first;
272 TLorentzVector nu_p4(0.,0.,Ev,Ev);
304 <<
"\n ** Will generate " <<
gOptNevents <<
" events for \n" 305 << init_state <<
" at Ev = " << Ev <<
" GeV";
311 <<
" *** Generating event............ " << ievent;
318 <<
"Last attempt failed. Re-trying....";
323 <<
"Generated Event GHEP Record: " << *
event;
337 #ifdef __CAN_GENERATE_EVENTS_USING_A_FLUX_OR_TGTMIX__ 339 void GenerateEventsUsingFluxOrTgtMix(
void)
342 GFluxI * flux_driver = FluxDriver();
379 LOG(
"gevgen",
pNOTICE) <<
" *** Generating event............ " << ievent;
416 else flux_driver = TH1FluxDriver();
421 GFluxI * MonoEnergeticFluxDriver(
void)
431 GFluxI * TH1FluxDriver(
void)
438 int flux_entries = 100000;
446 bool input_is_text_file = ! gSystem->AccessPathName(
gOptFlux.c_str());
447 bool input_is_root_file =
gOptFlux.find(
".root") != string::npos &&
449 if(input_is_text_file) {
455 double estep = (emax-emin)/(n-1);
456 double ymax = -1, ry = -1, gy = -1,
e = -1;
457 for(
int i=0; i<
n; i++) {
459 ymax = TMath::Max(ymax, input_flux->
Evaluate(
e));
464 spectrum =
new TH1D(
"spectrum",
"neutrino flux", 300, emin, emax);
465 spectrum->SetDirectory(0);
467 for(
int ientry=0; ientry<flux_entries; ientry++) {
473 LOG(
"gevgen",
pFATAL) <<
"Couldn't generate a flux histogram";
476 e = emin + de * r->
RndGen().Rndm();
477 gy = ymax * r->
RndGen().Rndm();
480 if(accept) spectrum->Fill(
e);
485 else if(input_is_root_file) {
490 assert(fv.size()==2);
491 assert( !gSystem->AccessPathName(fv[0].c_str()) );
493 LOG(
"gevgen",
pNOTICE) <<
"Getting input flux from root file: " << fv[0];
494 TFile * flux_file =
new TFile(fv[0].c_str(),
"read");
496 LOG(
"gevgen",
pNOTICE) <<
"Flux name: " << fv[1];
497 TH1D * hst = (TH1D *)flux_file->Get(fv[1].c_str());
499 LOG(
"gevgen",
pFATAL) <<
"Could not load the flux histogram \"" << fv[1]
500 <<
"\" from the input ROOT file: " << fv[0];
508 spectrum = (TH1D*)hst->Clone();
509 spectrum->SetNameTitle(
"spectrum",
"neutrino_flux");
510 spectrum->SetDirectory(0);
511 for(
int ibin = 1; ibin <= hst->GetNbinsX(); ibin++) {
512 if(hst->GetBinLowEdge(ibin) + hst->GetBinWidth(ibin) > emax ||
513 hst->GetBinLowEdge(ibin) < emin) {
514 spectrum->SetBinContent(ibin, 0);
518 LOG(
"gevgen",
pNOTICE) << spectrum->GetEntries();
523 LOG(
"gevgen",
pNOTICE) << spectrum->GetEntries();
529 TF1 * input_func =
new TF1(
"input_func",
gOptFlux.c_str(), emin, emax);
530 spectrum =
new TH1D(
"spectrum",
"neutrino flux", 300, emin, emax);
531 spectrum->SetDirectory(0);
532 spectrum->FillRandom(
"input_func", flux_entries);
537 TFile
f(
"./input-flux.root",
"recreate");
541 TVector3 bdir (0,0,1);
542 TVector3 bspot(0,0,0);
558 LOG(
"gevgen",
pINFO) <<
"Parsing command line arguments";
577 LOG(
"gevgen",
pINFO) <<
"Reading number of events to generate";
581 <<
"Unspecified number of events to generate - Using default";
587 LOG(
"gevgen",
pINFO) <<
"Reading MC run number";
590 LOG(
"gevgen",
pINFO) <<
"Unspecified run number - Using default";
596 LOG(
"gevgen",
pINFO) <<
"Reading output file name";
608 bool using_flux =
false;
610 LOG(
"gevgen",
pINFO) <<
"Reading flux function";
617 <<
"-s option no longer available. Please read the revised code documentation";
628 LOG(
"gevgen",
pINFO) <<
"Reading neutrino energy";
632 if(nue.find(
",") != string::npos) {
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);
643 <<
"No flux was specified but an energy range was input!";
645 <<
"Events will be generated at fixed E = " <<
gOptNuEnergy <<
" GeV";
653 LOG(
"gevgen",
pFATAL) <<
"Unspecified neutrino energy - Exiting";
660 LOG(
"gevgen",
pINFO) <<
"Reading neutrino PDG code";
663 LOG(
"gevgen",
pFATAL) <<
"Unspecified neutrino PDG code - Exiting";
669 bool using_tgtmix =
false;
671 LOG(
"gevgen",
pINFO) <<
"Reading target mix";
675 if(tgtmix.size()==1) {
676 int pdg = atoi(tgtmix[0].c_str());
678 gOptTgtMix.insert(map<int, double>::value_type(pdg, wgt));
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());
693 <<
"Adding to target mix: pdg = " << pdg <<
", wgt = " << wgt;
694 gOptTgtMix.insert(map<int, double>::value_type(pdg, wgt));
699 LOG(
"gevgen",
pFATAL) <<
"Unspecified target PDG code - Exiting";
708 LOG(
"gevgen",
pINFO) <<
"Reading random number seed";
711 LOG(
"gevgen",
pINFO) <<
"Unspecified random number seed - Using default";
717 LOG(
"gevgen",
pINFO) <<
"Reading cross-section file";
720 LOG(
"gevgen",
pINFO) <<
"Unspecified cross-section file";
737 <<
"Random number seed was not set, using default";
746 <<
"No input cross-section spline file";
754 <<
"Neutrino energy: [" 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;
769 <<
" >> " << tgtpdgc <<
" (weight fraction = " << wgt <<
")";
780 <<
"\n\n" <<
"Syntax:" <<
"\n" 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]" 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)"
void RandGen(long int seed)
static void SetPrintLevel(int print_level)
void XSecTable(string inpfile, bool require_table)
void SetUnphysEventMask(const TBits &mask)
string ArgAsString(char opt)
THE MAIN GENIE PROJECT NAMESPACE
static RandomGen * Instance()
Access instance.
void SetEventGeneratorList(string listname)
void CustomizeFilename(string filename)
void ReadFromCommandLine(int argc, char **argv)
NtpMCFormat_t kDefOptNtpFormat
A numeric analysis tool class for interpolating 1-D functions.
void Update(int iev, const EventRecord *event)
void CustomizeFilename(string filename)
double Evaluate(double x) const
A singleton holding random number generator classes. All random number generation in GENIE should tak...
void SetRefreshRate(int rate)
void UseFluxDriver(GFluxI *flux)
Simple class to create & update MC job status files and env. vars. This is used to be able to keep tr...
A GENIE `MC Job Driver'. Can be used for setting up complicated event generation cases involving deta...
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
void SetEventGeneratorList(string listname)
void ForceSingleProbScale(void)
A generic GENIE flux driver. Generates a 'cylindrical' neutrino beam along the input direction...
A simple GENIE flux driver for monoenergetic neutrinos along the z direction. Can handle a mix of neu...
void Configure(bool calc_prob_scales=true)
void Save(void)
get the even tree
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
void AddEventRecord(int ievent, const EventRecord *ev_rec)
save the event tree
void SetTransverseRadius(double Rt)
Misc GENIE control constants.
void SetNuDirection(const TVector3 &direction)
void BuildTune()
build tune and inform XSecSplineList
EventRecord * GenerateEvent(void)
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
int main(int argc, char **argv)
void Initialize(void)
add event
static RunOpt * Instance(void)
vector< string > Split(string input, string delim)
A utility class to facilitate creating the GENIE MC Ntuple from the output GENIE GHEP event records...
map< int, double > gOptTgtMix
bool gOptUsingFluxOrTgtMix
void GetCommandLineArgs(int argc, char **argv)
TRandom3 & RndGen(void) const
rnd number generator for generic usage
void Configure(int nu_pdgc, int Z, int A)
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f='*')
A vector of EventGeneratorI objects.
void GenerateEventsAtFixedInitState(void)
void SetBeamSpot(const TVector3 &spot)
void MesgThresholds(string inpfile)
void AddEnergySpectrum(int nu_pdgc, TH1D *spectrum)
Command line argument parser.
enum genie::ENtpMCFormat NtpMCFormat_t
Defines the GENIE Geometry Analyzer Interface.
static const unsigned int kRjMaxIterations
void SetUnphysEventMask(const TBits &mask)
Most commonly used PDG codes. A set of utility functions to handle PDG codes is provided in PDGUtils...
void UseGeomAnalyzer(GeomAnalyzerI *geom)
void UseSplines(bool useLogE=true)
The PointGeomAnalyzer class is the simplest implementation of the GeomAnalyserI interface and defines...
bool OptionExists(char opt)
was option set?
void CacheFile(string inpfile)
void EnableBareXSecPreCalc(bool flag)
Event finding and building.
Initial State information.
GENIE Interface for user-defined flux classes.
EventRecord * GenerateEvent(const TLorentzVector &nu4p)