Functions | Variables
gNucleonDecayEvGen.cxx File Reference
#include <cassert>
#include <cstdlib>
#include <string>
#include <vector>
#include <sstream>
#include <TSystem.h>
#include "Framework/Algorithm/AlgFactory.h"
#include "Framework/EventGen/EventRecord.h"
#include "Framework/EventGen/EventGeneratorI.h"
#include "Framework/EventGen/EventRecordVisitorI.h"
#include "Framework/EventGen/GMCJMonitor.h"
#include "Framework/Messenger/Messenger.h"
#include "Framework/Ntuple/NtpWriter.h"
#include "Physics/NucleonDecay/NucleonDecayMode.h"
#include "Physics/NucleonDecay/NucleonDecayUtils.h"
#include "Framework/Numerical/RandomGen.h"
#include "Framework/ParticleData/PDGCodes.h"
#include "Framework/ParticleData/PDGUtils.h"
#include "Framework/ParticleData/PDGLibrary.h"
#include "Framework/Utils/StringUtils.h"
#include "Framework/Utils/UnitUtils.h"
#include "Framework/Utils/PrintUtils.h"
#include "Framework/Utils/AppInit.h"
#include "Framework/Utils/RunOpt.h"
#include "Framework/Utils/CmdLnArgParser.h"

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void PrintSyntax (void)
 
int SelectInitState (void)
 
const EventRecordVisitorINucleonDecayGenerator (void)
 
int main (int argc, char **argv)
 

Variables

string kDefOptGeomLUnits = "mm"
 
string kDefOptGeomDUnits = "g_cm3"
 
NtpMCFormat_t kDefOptNtpFormat = kNFGHEP
 
string kDefOptEvFilePrefix = "gntp"
 
Long_t gOptRunNu = 1000
 
int gOptNev = 10
 
NucleonDecayMode_t gOptDecayMode = kNDNull
 
int gOptDecayedNucleon = kNDNull
 
string gOptEvFilePrefix = kDefOptEvFilePrefix
 
bool gOptUsingRootGeom = false
 
map< int, double > gOptTgtMix
 
string gOptRootGeom
 
string gOptRootGeomTopVol = ""
 
double gOptGeomLUnits = 0
 
double gOptGeomDUnits = 0
 
long int gOptRanSeed = -1
 

Function Documentation

void GetCommandLineArgs ( int  argc,
char **  argv 
)

Definition at line 313 of file gNucleonDecayEvGen.cxx.

314 {
315  LOG("gevgen_ndcy", pINFO) << "Parsing command line arguments";
316 
317  // Common run options.
318  RunOpt::Instance()->ReadFromCommandLine(argc,argv);
319 
320  // Parse run options for this app
321 
322  CmdLnArgParser parser(argc,argv);
323 
324  // help?
325  bool help = parser.OptionExists('h');
326  if(help) {
327  PrintSyntax();
328  exit(0);
329  }
330 
331  // run number
332  if( parser.OptionExists('r') ) {
333  LOG("gevgen_ndcy", pDEBUG) << "Reading MC run number";
334  gOptRunNu = parser.ArgAsLong('r');
335  } else {
336  LOG("gevgen_ndcy", pDEBUG) << "Unspecified run number - Using default";
337  gOptRunNu = 1000;
338  } //-r
339 
340 
341  // number of events
342  if( parser.OptionExists('n') ) {
343  LOG("gevgen_ndcy", pDEBUG)
344  << "Reading number of events to generate";
345  gOptNev = parser.ArgAsInt('n');
346  } else {
347  LOG("gevgen_ndcy", pFATAL)
348  << "You need to specify the number of events";
349  PrintSyntax();
350  exit(0);
351  } //-n
352 
353  // decay mode
354  int mode = -1;
355  if( parser.OptionExists('m') ) {
356  LOG("gevgen_ndcy", pDEBUG)
357  << "Reading decay mode";
358  mode = parser.ArgAsInt('m');
359  } else {
360  LOG("gevgen_ndcy", pFATAL)
361  << "You need to specify the decay mode";
362  PrintSyntax();
363  exit(0);
364  } //-m
366 
367  // decayed nucleon PDG
368  if( parser.OptionExists('N') ) {
369  LOG("gevgen_ndcy", pINFO) << "Reading decayed nucleon PDG";
370  gOptDecayedNucleon = parser.ArgAsInt('N');
371  } else {
372  LOG("gevgen_ndcy", pINFO) << "Unspecified decayed nucleon PDG - Using default";
373  gOptDecayedNucleon = 0;
374  }
375 
377  if(!valid_mode) {
378  LOG("gevgen_ndcy", pFATAL)
379  << "You need to specify a valid decay mode / decayed nucleon PDG combination";
380  PrintSyntax();
381  exit(0);
382  }
383 
384  //
385  // geometry
386  //
387 
388  string geom = "";
389  string lunits, dunits;
390  if( parser.OptionExists('g') ) {
391  LOG("gevgen_ndcy", pDEBUG) << "Getting input geometry";
392  geom = parser.ArgAsString('g');
393 
394  // is it a ROOT file that contains a ROOT geometry?
395  bool accessible_geom_file =
396  ! (gSystem->AccessPathName(geom.c_str()));
397  if (accessible_geom_file) {
398  gOptRootGeom = geom;
399  gOptUsingRootGeom = true;
400  }
401  } else {
402  LOG("gevgen_ndcy", pFATAL)
403  << "No geometry option specified - Exiting";
404  PrintSyntax();
405  exit(1);
406  } //-g
407 
408  if(gOptUsingRootGeom) {
409  // using a ROOT geometry - get requested geometry units
410 
411  // legth units:
412  if( parser.OptionExists('L') ) {
413  LOG("gevgen_ndcy", pDEBUG)
414  << "Checking for input geometry length units";
415  lunits = parser.ArgAsString('L');
416  } else {
417  LOG("gevgen_ndcy", pDEBUG) << "Using default geometry length units";
418  lunits = kDefOptGeomLUnits;
419  } // -L
420  // density units:
421  if( parser.OptionExists('D') ) {
422  LOG("gevgen_ndcy", pDEBUG)
423  << "Checking for input geometry density units";
424  dunits = parser.ArgAsString('D');
425  } else {
426  LOG("gevgen_ndcy", pDEBUG) << "Using default geometry density units";
427  dunits = kDefOptGeomDUnits;
428  } // -D
431 
432  // check whether an event generation volume name has been
433  // specified -- default is the 'top volume'
434  if( parser.OptionExists('t') ) {
435  LOG("gevgen_ndcy", pDEBUG) << "Checking for input volume name";
436  gOptRootGeomTopVol = parser.ArgAsString('t');
437  } else {
438  LOG("gevgen_ndcy", pDEBUG) << "Using the <master volume>";
439  } // -t
440 
441  } // using root geom?
442 
443  else {
444  // User has specified a target mix.
445  // Decode the list of target pdf codes & their corresponding weight fraction
446  // (specified as 'pdg_code_1[fraction_1],pdg_code_2[fraction_2],...')
447  // See documentation on top section of this file.
448  //
449  gOptTgtMix.clear();
450  vector<string> tgtmix = utils::str::Split(geom,",");
451  if(tgtmix.size()==1) {
452  int pdg = atoi(tgtmix[0].c_str());
453  double wgt = 1.0;
454  gOptTgtMix.insert(map<int, double>::value_type(pdg, wgt));
455  } else {
456  vector<string>::const_iterator tgtmix_iter = tgtmix.begin();
457  for( ; tgtmix_iter != tgtmix.end(); ++tgtmix_iter) {
458  string tgt_with_wgt = *tgtmix_iter;
459  string::size_type open_bracket = tgt_with_wgt.find("[");
460  string::size_type close_bracket = tgt_with_wgt.find("]");
461  if (open_bracket ==string::npos ||
462  close_bracket==string::npos)
463  {
464  LOG("gevgen_ndcy", pFATAL)
465  << "You made an error in specifying the target mix";
466  PrintSyntax();
467  exit(1);
468  }
469  string::size_type ibeg = 0;
470  string::size_type iend = open_bracket;
471  string::size_type jbeg = open_bracket+1;
472  string::size_type jend = close_bracket;
473  int pdg = atoi(tgt_with_wgt.substr(ibeg,iend-ibeg).c_str());
474  double wgt = atof(tgt_with_wgt.substr(jbeg,jend-jbeg).c_str());
475  LOG("gevgen_ndcy", pDEBUG)
476  << "Adding to target mix: pdg = " << pdg << ", wgt = " << wgt;
477  gOptTgtMix.insert(map<int, double>::value_type(pdg, wgt));
478 
479  }// tgtmix_iter
480  } // >1 materials in mix
481  } // using tgt mix?
482 
483  // event file prefix
484  if( parser.OptionExists('o') ) {
485  LOG("gevgen_ndcy", pDEBUG) << "Reading the event filename prefix";
486  gOptEvFilePrefix = parser.ArgAsString('o');
487  } else {
488  LOG("gevgen_ndcy", pDEBUG)
489  << "Will set the default event filename prefix";
491  } //-o
492 
493 
494  // random number seed
495  if( parser.OptionExists("seed") ) {
496  LOG("gevgen_ndcy", pINFO) << "Reading random number seed";
497  gOptRanSeed = parser.ArgAsLong("seed");
498  } else {
499  LOG("gevgen_ndcy", pINFO) << "Unspecified random number seed - Using default";
500  gOptRanSeed = -1;
501  }
502 
503  //
504  // >>> print the command line options
505  //
506 
507  PDGLibrary * pdglib = PDGLibrary::Instance();
508 
509  ostringstream gminfo;
510  if (gOptUsingRootGeom) {
511  gminfo << "Using ROOT geometry - file: " << gOptRootGeom
512  << ", top volume: "
513  << ((gOptRootGeomTopVol.size()==0) ? "<master volume>" : gOptRootGeomTopVol)
514  << ", length units: " << lunits
515  << ", density units: " << dunits;
516  } else {
517  gminfo << "Using target mix - ";
519  for(iter = gOptTgtMix.begin(); iter != gOptTgtMix.end(); ++iter) {
520  int pdg_code = iter->first;
521  double wgt = iter->second;
522  TParticlePDG * p = pdglib->Find(pdg_code);
523  if(p) {
524  string name = p->GetName();
525  gminfo << "(" << name << ") -> " << 100*wgt << "% / ";
526  }//p?
527  }
528  }
529 
530  LOG("gevgen_ndcy", pNOTICE)
531  << "\n\n"
532  << utils::print::PrintFramedMesg("gevgen_ndcy job configuration");
533 
534  LOG("gevgen_ndcy", pNOTICE)
535  << "\n @@ Run number: " << gOptRunNu
536  << "\n @@ Random number seed: " << gOptRanSeed
537  << "\n @@ Decay channel $ " << utils::nucleon_decay::AsString(gOptDecayMode, gOptDecayedNucleon)
538  << "\n @@ Geometry $ " << gminfo.str()
539  << "\n @@ Statistics $ " << gOptNev << " events";
540 
541  //
542  // Temporary warnings...
543  //
544  if(gOptUsingRootGeom) {
545  LOG("gevgen_ndcy", pWARN)
546  << "\n ** ROOT geometries not supported yet in the nucleon decay mode"
547  << "\n ** (they will be in the very near future)"
548  << "\n ** Please specify a `target mix' instead.";
549  gAbortingInErr = true;
550  exit(1);
551  }
552 }
static QCString name
Definition: declinfo.cpp:673
int gOptNev
double gOptGeomDUnits
double gOptGeomLUnits
Long_t gOptRunNu
#define pFATAL
Definition: Messenger.h:56
string kDefOptEvFilePrefix
int gOptDecayedNucleon
intermediate_table::const_iterator const_iterator
string gOptRootGeomTopVol
string gOptRootGeom
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
map< int, double > gOptTgtMix
string gOptEvFilePrefix
double UnitFromString(string u)
Definition: UnitUtils.cxx:18
bool gOptUsingRootGeom
p
Definition: test.py:223
string kDefOptGeomDUnits
void PrintSyntax(void)
#define pINFO
Definition: Messenger.h:62
#define pWARN
Definition: Messenger.h:60
vector< string > Split(string input, string delim)
Definition: StringUtils.cxx:36
Singleton class to load & serve a TDatabasePDG.
Definition: PDGLibrary.h:32
enum genie::ENucleonDecayMode NucleonDecayMode_t
bool IsValidMode(NNBarOscMode_t ndm)
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f='*')
Definition: PrintUtils.cxx:164
const char * AsString(Resonance_t res)
resonance id -> string
TParticlePDG * Find(int pdgc, bool must_exist=true)
Definition: PDGLibrary.cxx:75
Command line argument parser.
#define pNOTICE
Definition: Messenger.h:61
bool gAbortingInErr
Definition: Messenger.cxx:34
long int gOptRanSeed
string kDefOptGeomLUnits
NucleonDecayMode_t gOptDecayMode
#define pDEBUG
Definition: Messenger.h:63
int main ( int  argc,
char **  argv 
)

Definition at line 176 of file gNucleonDecayEvGen.cxx.

177 {
178  // Parse command line arguments
179  GetCommandLineArgs(argc,argv);
180 
181  // Init messenger and random number seed
182  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
184 
185  // Initialize an Ntuple Writer to save GHEP records into a TTree
187  ntpw.CustomizeFilenamePrefix(gOptEvFilePrefix);
188  ntpw.Initialize();
189 
190  // Create a MC job monitor for a periodically updated status file
191  GMCJMonitor mcjmonitor(gOptRunNu);
192  mcjmonitor.SetRefreshRate(RunOpt::Instance()->MCJobStatusRefreshRate());
193 
194  // Set GHEP print level
195  GHepRecord::SetPrintLevel(RunOpt::Instance()->EventRecordPrintLevel());
196 
197  // Get the nucleon decay generator
198  const EventRecordVisitorI * mcgen = NucleonDecayGenerator();
199 
200  // Event loop
201  int ievent = 0;
202  int dpdg = 0;
203  if (gOptDecayedNucleon > 0) {
204  dpdg = gOptDecayedNucleon;
205  } else {
207  }
208 
209  while (1)
210  {
211  if(ievent == gOptNev) break;
212 
213  LOG("gevgen_ndcy", pNOTICE)
214  << " *** Generating event............ " << ievent;
215 
216  EventRecord * event = new EventRecord;
217  int target = SelectInitState();
218  int decay = (int)gOptDecayMode;
219  Interaction * interaction = Interaction::NDecay(target,decay,dpdg);
220  event->AttachSummary(interaction);
221 
222  // Simulate decay
223  mcgen->ProcessEventRecord(event);
224 
225  LOG("gevgen_ndcy", pINFO)
226  << "Generated event: " << *event;
227 
228  // Add event at the output ntuple, refresh the mc job monitor & clean-up
229  ntpw.AddEventRecord(ievent, event);
230  mcjmonitor.Update(ievent,event);
231  delete event;
232 
233  ievent++;
234  } // event loop
235 
236  // Save the generated event tree & close the output file
237  ntpw.Save();
238 
239  LOG("gevgen_ndcy", pNOTICE) << "Done!";
240 
241  return 0;
242 }
const EventRecordVisitorI * NucleonDecayGenerator(void)
void RandGen(long int seed)
Definition: AppInit.cxx:30
int gOptNev
virtual void ProcessEventRecord(GHepRecord *event_rec) const =0
Long_t gOptRunNu
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
int gOptDecayedNucleon
int SelectInitState(void)
void GetCommandLineArgs(int argc, char **argv)
Summary information for an interaction.
Definition: Interaction.h:56
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
string gOptEvFilePrefix
#define pINFO
Definition: Messenger.h:62
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
NtpMCFormat_t kDefOptNtpFormat
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
#define pNOTICE
Definition: Messenger.h:61
long int gOptRanSeed
int DecayedNucleonPdgCode(NucleonDecayMode_t ndm)
Event finding and building.
NucleonDecayMode_t gOptDecayMode
const EventRecordVisitorI * NucleonDecayGenerator ( void  )

Definition at line 298 of file gNucleonDecayEvGen.cxx.

299 {
300  string sname = "genie::EventGenerator";
301  string sconfig = "NucleonDecay";
302  AlgFactory * algf = AlgFactory::Instance();
303  const EventRecordVisitorI * mcgen =
304  dynamic_cast<const EventRecordVisitorI *> (algf->GetAlgorithm(sname,sconfig));
305  if(!mcgen) {
306  LOG("gevgen_ndcy", pFATAL) << "Couldn't instantiate the nucleon decay generator";
307  gAbortingInErr = true;
308  exit(1);
309  }
310  return mcgen;
311 }
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
The GENIE Algorithm Factory.
Definition: AlgFactory.h:39
bool gAbortingInErr
Definition: Messenger.cxx:34
void PrintSyntax ( void  )

Definition at line 554 of file gNucleonDecayEvGen.cxx.

555 {
556  LOG("gevgen_ndcy", pFATAL)
557  << "\n **Syntax**"
558  << "\n gevgen_ndcy [-h] "
559  << "\n [-r run#]"
560  << "\n -m decay_mode"
561  << "\n [-N decayed_nucleon]"
562  << "\n -g geometry"
563  << "\n [-t top_volume_name_at_geom]"
564  << "\n [-L length_units_at_geom]"
565  << "\n [-D density_units_at_geom]"
566  << "\n -n n_of_events "
567  << "\n [-o output_event_file_prefix]"
568  << "\n [--seed random_number_seed]"
569  << "\n [--message-thresholds xml_file]"
570  << "\n [--event-record-print-level level]"
571  << "\n [--mc-job-status-refresh-rate rate]"
572  << "\n"
573  << " Please also read the detailed documentation at http://www.genie-mc.org"
574  << " or look at the source code: $GENIE/src/Apps/gNucleonDecayEvGen.cxx"
575  << "\n";
576 }
#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 SelectInitState ( void  )

Definition at line 244 of file gNucleonDecayEvGen.cxx.

245 {
247  LOG("gevgen_ndcy", pFATAL) << "Not a valid decay mode and/or decayed nucleon...";
248  gAbortingInErr = true;
249  exit(1);
250  }
251 
252  int dpdg = 0;
253  if (gOptDecayedNucleon > 0) {
254  dpdg = gOptDecayedNucleon;
255  } else {
257  }
258 
259  map<int,double> cprob; // cumulative probability
261 
262  double sum_prob = 0;
263  for(iter = gOptTgtMix.begin(); iter != gOptTgtMix.end(); ++iter) {
264  int pdg_code = iter->first;
265  int A = pdg::IonPdgCodeToA(pdg_code);
266  int Z = pdg::IonPdgCodeToZ(pdg_code);
267 
268  double nucleon_decay_fraction = 0.;
269  if (dpdg == kPdgProton ) { nucleon_decay_fraction = (double)Z / (double)A; }
270  else if (dpdg == kPdgNeutron ) { nucleon_decay_fraction = (double)(A-Z) / (double)A; }
271 
272  double wgt = iter->second;
273  double prob = wgt*nucleon_decay_fraction;
274 
275  sum_prob += prob;
276  cprob.insert(map<int, double>::value_type(pdg_code, sum_prob));
277  }
278 
279  assert(sum_prob > 0.);
280 
281  RandomGen * rnd = RandomGen::Instance();
282  double r = sum_prob * rnd->RndEvg().Rndm();
283 
284  for(iter = cprob.begin(); iter != cprob.end(); ++iter) {
285  int pdg_code = iter->first;
286  double prob = iter->second;
287  if(r < prob) {
288  LOG("gevgen_ndcy", pNOTICE) << "Selected initial state = " << pdg_code;
289  return pdg_code;
290  }
291  }
292 
293  LOG("gevgen_ndcy", pFATAL) << "Couldn't select an initial state...";
294  gAbortingInErr = true;
295  exit(1);
296 }
#define pFATAL
Definition: Messenger.h:56
int gOptDecayedNucleon
int IonPdgCodeToA(int pdgc)
Definition: PDGUtils.cxx:60
intermediate_table::const_iterator const_iterator
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
map< int, double > gOptTgtMix
TRandom3 & RndEvg(void) const
rnd number generator used by the event generation drivers
Definition: RandomGen.h:74
#define A
Definition: memgrp.cpp:38
bool IsValidMode(NNBarOscMode_t ndm)
int IonPdgCodeToZ(int pdgc)
Definition: PDGUtils.cxx:52
const int kPdgProton
Definition: PDGCodes.h:81
#define pNOTICE
Definition: Messenger.h:61
bool gAbortingInErr
Definition: Messenger.cxx:34
const int kPdgNeutron
Definition: PDGCodes.h:83
int DecayedNucleonPdgCode(NucleonDecayMode_t ndm)
NucleonDecayMode_t gOptDecayMode

Variable Documentation

int gOptDecayedNucleon = kNDNull

Definition at line 165 of file gNucleonDecayEvGen.cxx.

NucleonDecayMode_t gOptDecayMode = kNDNull

Definition at line 164 of file gNucleonDecayEvGen.cxx.

string gOptEvFilePrefix = kDefOptEvFilePrefix

Definition at line 166 of file gNucleonDecayEvGen.cxx.

double gOptGeomDUnits = 0

Definition at line 172 of file gNucleonDecayEvGen.cxx.

double gOptGeomLUnits = 0

Definition at line 171 of file gNucleonDecayEvGen.cxx.

int gOptNev = 10

Definition at line 163 of file gNucleonDecayEvGen.cxx.

long int gOptRanSeed = -1

Definition at line 173 of file gNucleonDecayEvGen.cxx.

string gOptRootGeom

Definition at line 169 of file gNucleonDecayEvGen.cxx.

string gOptRootGeomTopVol = ""

Definition at line 170 of file gNucleonDecayEvGen.cxx.

Long_t gOptRunNu = 1000

Definition at line 162 of file gNucleonDecayEvGen.cxx.

map<int,double> gOptTgtMix

Definition at line 168 of file gNucleonDecayEvGen.cxx.

bool gOptUsingRootGeom = false

Definition at line 167 of file gNucleonDecayEvGen.cxx.

string kDefOptEvFilePrefix = "gntp"

Definition at line 159 of file gNucleonDecayEvGen.cxx.

string kDefOptGeomDUnits = "g_cm3"

Definition at line 157 of file gNucleonDecayEvGen.cxx.

string kDefOptGeomLUnits = "mm"

Definition at line 156 of file gNucleonDecayEvGen.cxx.

NtpMCFormat_t kDefOptNtpFormat = kNFGHEP

Definition at line 158 of file gNucleonDecayEvGen.cxx.