GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
gEvGenHadronNucleus.cxx File Reference
#include <cassert>
#include <cstdlib>
#include "TSystem.h"
#include "TFile.h"
#include "TTree.h"
#include "TH1D.h"
#include "TF1.h"
#include "Framework/Conventions/GBuild.h"
#include "Framework/Algorithm/AlgFactory.h"
#include "Framework/Conventions/Controls.h"
#include "Framework/EventGen/EventRecord.h"
#include "Framework/EventGen/GMCJMonitor.h"
#include "Framework/EventGen/EventRecordVisitorI.h"
#include "Framework/GHEP/GHepParticle.h"
#include "Framework/GHEP/GHepRecord.h"
#include "Framework/GHEP/GHepStatus.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/PDGLibrary.h"
#include "Framework/Utils/AppInit.h"
#include "Framework/Utils/StringUtils.h"
#include "Framework/Utils/PrintUtils.h"
#include "Framework/Utils/XSecSplineList.h"
#include "Framework/Utils/RunOpt.h"
#include "Framework/Utils/CmdLnArgParser.h"
#include "Physics/HadronTransport/INukeHadroFates.h"
#include "Physics/HadronTransport/INukeUtils.h"
Include dependency graph for gEvGenHadronNucleus.cxx:

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
const EventRecordVisitorIGetIntranuke (void)
 
double GenProbeKineticEnergy (void)
 
EventRecordInitializeEvent (void)
 
void BuildSpectrum (void)
 
void PrintSyntax (void)
 
int main (int argc, char **argv)
 

Variables

int kDefOptNevents = 10000
 
Long_t kDefOptRunNu = 0
 
string kDefOptEvFilePrefix = "gntp.inuke"
 
string kDefOptMode = "hA"
 
string gOptMode
 
Long_t gOptRunNu
 
int gOptNevents
 
int gOptProbePdgCode
 
int gOptTgtPdgCode
 
double gOptProbeKE
 
double gOptProbeKEmin
 
double gOptProbeKEmax
 
string gOptFlux
 
string gOptEvFilePrefix
 
bool gOptUsingFlux =false
 
long int gOptRanSeed
 
TH1D * gSpectrum = 0
 

Function Documentation

void BuildSpectrum ( void  )

Definition at line 323 of file gEvGenHadronNucleus.cxx.

References genie::Spline::Evaluate(), genie::gAbortingInErr, gOptFlux, gOptProbeKEmax, gOptProbeKEmin, gOptUsingFlux, gSpectrum, genie::RandomGen::Instance(), genie::controls::kRjMaxIterations, LOG, pFATAL, pNOTICE, and genie::RandomGen::RndGen().

Referenced by main().

324 {
325 // Create kinetic energy spectrum from input function
326 //
327 
328  if(!gOptUsingFlux) return;
329 
330  if(gSpectrum) {
331  delete gSpectrum;
332  gSpectrum = 0;
333  }
334 
335  LOG("gevgen_hadron", pNOTICE)
336  << "Generating a flux histogram ... ";
337 
338  int flux_bins = 300;
339  int flux_entries = 1000000;
340  double ke_min = gOptProbeKEmin;
341  double ke_max = gOptProbeKEmax;
342  double dke = ke_max - ke_min;
343  assert(dke>0 && ke_min>=0.);
344 
345  // kinetic energy spectrum
346  gSpectrum = new TH1D(
347  "spectrum","hadron kinetic energy spectrum", flux_bins, ke_min, ke_max);
348 
349  // check whether the input flux is a file or a functional form
350  bool input_is_file = ! gSystem->AccessPathName(gOptFlux.c_str());
351  if(input_is_file) {
352  Spline * input_flux = new Spline(gOptFlux.c_str());
353 
354  // generate the flux hisogram from the input flux file
355  int n = 100;
356  double ke_step = (ke_max-ke_min)/(n-1);
357  double ymax = -1, ry = -1, gy = -1, ke = -1;
358  for(int i=0; i<n; i++) {
359  ke = ke_min + i*ke_step;
360  ymax = TMath::Max(ymax, input_flux->Evaluate(ke));
361  }
362  ymax *= 1.3;
363 
364  RandomGen * r = RandomGen::Instance();
365 
366  for(int ientry=0; ientry<flux_entries; ientry++) {
367  bool accept = false;
368  unsigned int iter=0;
369  while(!accept) {
370  iter++;
371  if(iter > kRjMaxIterations) {
372  LOG("gevgen_hadron", pFATAL)
373  << "Couldn't generate a flux histogram";
374  gAbortingInErr = true;
375  exit(1);
376  }
377  ke = ke_min + dke * r->RndGen().Rndm();
378  gy = ymax * r->RndGen().Rndm();
379  ry = input_flux->Evaluate(ke);
380  accept = gy < ry;
381  if(accept) gSpectrum->Fill(ke);
382  }
383  }
384  delete input_flux;
385 
386  } else {
387  // generate the flux histogram from the input functional form
388  TF1 * input_func = new TF1("input_func", gOptFlux.c_str(), ke_min, ke_max);
389  gSpectrum->FillRandom("input_func", flux_entries);
390  delete input_func;
391  }
392  TFile f("./input-hadron-flux.root","recreate");
393  gSpectrum->Write();
394  f.Close();
395 }
double gOptProbeKEmax
A numeric analysis tool class for interpolating 1-D functions.
Definition: Spline.h:58
#define pFATAL
Definition: Messenger.h:56
TH1D * gSpectrum
double Evaluate(double x) const
Definition: Spline.cxx:363
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
bool gOptUsingFlux
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
string gOptFlux
Definition: gEvGen.cxx:234
TRandom3 & RndGen(void) const
rnd number generator for generic usage
Definition: RandomGen.h:80
double gOptProbeKEmin
#define pNOTICE
Definition: Messenger.h:61
static const unsigned int kRjMaxIterations
Definition: Controls.h:26
bool gAbortingInErr
Definition: Messenger.cxx:34
double GenProbeKineticEnergy ( void  )

Definition at line 317 of file gEvGenHadronNucleus.cxx.

References gOptProbeKE, gOptUsingFlux, and gSpectrum.

Referenced by InitializeEvent().

318 {
319  if(gOptUsingFlux) return gSpectrum->GetRandom(); // spectrum
320  else return gOptProbeKE; // mono-energetic
321 }
TH1D * gSpectrum
bool gOptUsingFlux
double gOptProbeKE
void GetCommandLineArgs ( int  argc,
char **  argv 
)
const EventRecordVisitorI * GetIntranuke ( void  )

Definition at line 235 of file gEvGenHadronNucleus.cxx.

References genie::gAbortingInErr, genie::AlgFactory::GetAlgorithm(), gOptMode, genie::AlgFactory::Instance(), LOG, and pFATAL.

Referenced by main().

236 {
237 // get the requested INTRANUKE module
238 
239  string sname = "";
240  string sconf = "";
241 
242  if ( gOptMode.compare("hA") == 0 ) {
243  sname = "genie::HAIntranuke";
244  sconf = "Default";
245  } else if ( gOptMode.compare("hN") == 0 ) {
246  sname = "genie::HNIntranuke";
247  sconf = "Default";
248  } else if ( gOptMode.compare("hA2019") == 0 ) {
249  sname = "genie::HAIntranuke2019";
250  sconf = "Default";
251  } else if ( gOptMode.compare("hN2019") == 0 ) {
252  sname = "genie::HNIntranuke2019";
253  sconf = "Default";
254  } else if ( gOptMode.compare("hA2018") == 0 ) {
255  sname = "genie::HAIntranuke2018";
256  sconf = "Default";
257  } else if ( gOptMode.compare("hN2018") == 0 ) {
258  sname = "genie::HNIntranuke2018";
259  sconf = "Default";
260 #ifdef __GENIE_INCL_ENABLED__
261  } else if ( gOptMode.compare("HINCL") == 0 ) {
262  sname = "genie::HINCLCascadeIntranuke";
263  sconf = "Default";
264 #endif
265 #ifdef __GENIE_GEANT4_INTERFACE_ENABLED__
266  } else if ( gOptMode.compare("HG4BertCasc") == 0 ) {
267  sname = "genie::HG4BertCascIntranuke";
268  sconf = "Default";
269 #endif
270  } else {
271  LOG("gevgen_hadron", pFATAL) << "Invalid Intranuke mode - Exiting";
272  gAbortingInErr = true;
273  exit(1);
274  }
275 
276  AlgFactory * algf = AlgFactory::Instance();
277  const EventRecordVisitorI * intranuke =
278  dynamic_cast<const EventRecordVisitorI *> (algf->GetAlgorithm(sname,sconf));
279  assert(intranuke);
280 
281  return intranuke;
282 }
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
#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
const Algorithm * GetAlgorithm(const AlgId &algid)
Definition: AlgFactory.cxx:75
string gOptMode
The GENIE Algorithm Factory.
Definition: AlgFactory.h:39
bool gAbortingInErr
Definition: Messenger.cxx:34
EventRecord * InitializeEvent ( void  )

Definition at line 284 of file gEvGenHadronNucleus.cxx.

References genie::GHepRecord::AddParticle(), genie::GHepRecord::AttachSummary(), GenProbeKineticEnergy(), gOptProbePdgCode, gOptTgtPdgCode, genie::PDGLibrary::Instance(), genie::kIStInitialState, and genie::utils::res::Mass().

Referenced by main().

285 {
286 // Initialize event record. Inserting the probe and target particles.
287 
288  EventRecord * evrec = new EventRecord();
289  Interaction * interaction = new Interaction;
290  evrec->AttachSummary(interaction);
291 
292  // dummy vertex position
293  TLorentzVector x4null(0.,0.,0.,0.);
294 
295  // incident hadron & target nucleon masses
296  PDGLibrary * pdglib = PDGLibrary::Instance();
297  double mh = pdglib -> Find (gOptProbePdgCode) -> Mass();
298  double M = pdglib -> Find (gOptTgtPdgCode ) -> Mass();
299 
300  // incident hadron kinetic energy
301  double ke = GenProbeKineticEnergy();
302 
303  // form incident hadron and target 4-momenta
304  double Eh = mh + ke;
305  double pzh = TMath::Sqrt(TMath::Max(0.,Eh*Eh-mh*mh));
306  TLorentzVector p4h (0.,0.,pzh,Eh);
307  TLorentzVector p4tgt (0.,0.,0., M);
308 
309  // insert probe and target entries
311  evrec->AddParticle(gOptProbePdgCode, ist, -1,-1,-1,-1, p4h, x4null);
312  evrec->AddParticle(gOptTgtPdgCode, ist, -1,-1,-1,-1, p4tgt, x4null);
313 
314  return evrec;
315 }
double GenProbeKineticEnergy(void)
double Mass(Resonance_t res)
resonance mass (GeV)
virtual void AttachSummary(Interaction *interaction)
Definition: GHepRecord.cxx:99
Summary information for an interaction.
Definition: Interaction.h:56
int gOptProbePdgCode
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
Definition: EventRecord.h:37
Singleton class to load &amp; serve a TDatabasePDG.
Definition: PDGLibrary.h:35
virtual void AddParticle(const GHepParticle &p)
Definition: GHepRecord.cxx:499
enum genie::EGHepStatus GHepStatus_t
int gOptTgtPdgCode
int main ( int  argc,
char **  argv 
)

Definition at line 159 of file gEvGenHadronNucleus.cxx.

References genie::NtpWriter::AddEventRecord(), BuildSpectrum(), genie::RunOpt::BuildTune(), genie::NtpWriter::CustomizeFilenamePrefix(), GetCommandLineArgs(), GetIntranuke(), gOptEvFilePrefix, gOptNevents, gOptRanSeed, gOptRunNu, gSpectrum, genie::NtpWriter::Initialize(), InitializeEvent(), genie::RunOpt::Instance(), genie::kNFGHEP, LOG, genie::utils::app_init::MesgThresholds(), pFATAL, pNOTICE, genie::EventRecordVisitorI::ProcessEventRecord(), genie::utils::app_init::RandGen(), genie::NtpWriter::Save(), genie::GHepRecord::SetPrintLevel(), and genie::GMCJMonitor::Update().

160 {
161  // Parse command line arguments
162  GetCommandLineArgs(argc,argv);
163 
164  if ( ! RunOpt::Instance()->Tune() ) {
165  LOG("gmkspl", pFATAL) << " No TuneId in RunOption";
166  exit(-1);
167  }
168  RunOpt::Instance()->BuildTune();
169 
170  // Init random number generator generator with user-specified seed number,
171  // set user-specified mesg thresholds, set user-specified GHEP print-level
172  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
174  GHepRecord::SetPrintLevel(RunOpt::Instance()->EventRecordPrintLevel());
175 
176  // Build the incident hadron kinetic energy spectrum, if required
177  BuildSpectrum();
178 
179  LOG("gevgen_hadron",pNOTICE) << "finish setup";
180 
181  // Get the specified INTRANUKE model
182  const EventRecordVisitorI * intranuke = GetIntranuke();
183 
184  // Initialize an Ntuple Writer to save GHEP records into a ROOT tree
186  ntpw.CustomizeFilenamePrefix(gOptEvFilePrefix);
187  ntpw.Initialize();
188 
189  // Create an MC job monitor
190  GMCJMonitor mcjmonitor(gOptRunNu);
191 
192  LOG("gevgen_hadron",pNOTICE) << "ready to generate events";
193 
194  //
195  // Generate events
196  //
197 
198  int ievent = 0;
199  while (ievent < gOptNevents) {
200  LOG("gevgen_hadron", pNOTICE)
201  << " *** Generating event............ " << ievent;
202 
203  // initialize
204  EventRecord * evrec = InitializeEvent();
205 
206  // generate full h+A event
207  intranuke->ProcessEventRecord(evrec);
208 
209  // print generated events
210  LOG("gevgen_hadron", pNOTICE ) << *evrec;
211 
212  // add event at the output ntuple
213  ntpw.AddEventRecord(ievent, evrec);
214 
215  // refresh the mc job monitor
216  mcjmonitor.Update(ievent,evrec);
217 
218  ievent++;
219  delete evrec;
220 
221  } // end loop events
222 
223  // Save the generated MC events
224  ntpw.Save();
225 
226  // Clean-up
227  if(gSpectrum) {
228  delete gSpectrum;
229  gSpectrum = 0;
230  }
231 
232  return 0;
233 }
void RandGen(long int seed)
Definition: AppInit.cxx:30
string gOptEvFilePrefix
Definition: gAtmoEvGen.cxx:310
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
#define pFATAL
Definition: Messenger.h:56
int gOptNevents
Definition: gEvGen.cxx:228
TH1D * gSpectrum
EventRecord * InitializeEvent(void)
void BuildSpectrum(void)
Simple class to create &amp; 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
virtual void ProcessEventRecord(GHepRecord *event_rec) const =0
Long_t gOptRunNu
Definition: gAtmoEvGen.cxx:295
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
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
#define pNOTICE
Definition: Messenger.h:61
void GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
const EventRecordVisitorI * GetIntranuke(void)
long int gOptRanSeed
Definition: gAtmoEvGen.cxx:312
void PrintSyntax ( void  )

Variable Documentation

string gOptEvFilePrefix

Definition at line 152 of file gEvGenHadronNucleus.cxx.

string gOptFlux

Definition at line 151 of file gEvGenHadronNucleus.cxx.

string gOptMode

Definition at line 143 of file gEvGenHadronNucleus.cxx.

Referenced by GetIntranuke().

int gOptNevents

Definition at line 145 of file gEvGenHadronNucleus.cxx.

double gOptProbeKE

Definition at line 148 of file gEvGenHadronNucleus.cxx.

Referenced by GenProbeKineticEnergy().

double gOptProbeKEmax

Definition at line 150 of file gEvGenHadronNucleus.cxx.

Referenced by BuildSpectrum().

double gOptProbeKEmin

Definition at line 149 of file gEvGenHadronNucleus.cxx.

Referenced by BuildSpectrum().

int gOptProbePdgCode
long int gOptRanSeed

Definition at line 154 of file gEvGenHadronNucleus.cxx.

Long_t gOptRunNu

Definition at line 144 of file gEvGenHadronNucleus.cxx.

int gOptTgtPdgCode
bool gOptUsingFlux =false

Definition at line 153 of file gEvGenHadronNucleus.cxx.

Referenced by BuildSpectrum(), and GenProbeKineticEnergy().

TH1D* gSpectrum = 0

Definition at line 156 of file gEvGenHadronNucleus.cxx.

Referenced by BuildSpectrum(), GenProbeKineticEnergy(), and main().

string kDefOptEvFilePrefix = "gntp.inuke"

Definition at line 139 of file gEvGenHadronNucleus.cxx.

string kDefOptMode = "hA"

Definition at line 140 of file gEvGenHadronNucleus.cxx.

int kDefOptNevents = 10000

Definition at line 137 of file gEvGenHadronNucleus.cxx.

Long_t kDefOptRunNu = 0

Definition at line 138 of file gEvGenHadronNucleus.cxx.