Functions | Variables
gNeutralHeavyLeptonEvGen.cxx File Reference
#include <cassert>
#include <cstdlib>
#include <string>
#include <vector>
#include <sstream>
#include <TSystem.h>
#include <TGeoVolume.h>
#include <TGeoManager.h>
#include <TGeoShape.h>
#include <TGeoBBox.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/NeutralHeavyLepton/NHLDecayMode.h"
#include "Physics/NeutralHeavyLepton/NHLDecayUtils.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)
 
void InitBoundingBox (void)
 
TLorentzVector GeneratePosition (void)
 
const EventRecordVisitorINHLGenerator (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
 
double gOptEnergyNHL = -1
 
double gOptMassNHL = -1
 
NHLDecayMode_t gOptDecayMode = kNHLDcyNull
 
string gOptEvFilePrefix = kDefOptEvFilePrefix
 
bool gOptUsingRootGeom = false
 
string gOptRootGeom
 
string gOptRootGeomTopVol = ""
 
double gOptGeomLUnits = 0
 
long int gOptRanSeed = -1
 
double fdx = 0
 
double fdy = 0
 
double fdz = 0
 
double fox = 0
 
double foy = 0
 
double foz = 0
 

Function Documentation

TLorentzVector GeneratePosition ( void  )

Definition at line 273 of file gNeutralHeavyLeptonEvGen.cxx.

274 {
275  RandomGen * rnd = RandomGen::Instance();
276  TRandom3 & rnd_geo = rnd->RndGeom();
277 
278  double rndx = 2 * (rnd_geo.Rndm() - 0.5); // [-1,1]
279  double rndy = 2 * (rnd_geo.Rndm() - 0.5); // [-1,1]
280  double rndz = 2 * (rnd_geo.Rndm() - 0.5); // [-1,1]
281 
282  double t_gen = 0;
283  double x_gen = fox + rndx * fdx;
284  double y_gen = foy + rndy * fdy;
285  double z_gen = foz + rndz * fdz;
286 
287  TLorentzVector pos(x_gen, y_gen, z_gen, t_gen);
288  return pos;
289 }
A singleton holding random number generator classes. All random number generation in GENIE should tak...
Definition: RandomGen.h:29
TRandom3 & RndGeom(void) const
rnd number generator used by geometry drivers
Definition: RandomGen.h:68
void GetCommandLineArgs ( int  argc,
char **  argv 
)

Definition at line 306 of file gNeutralHeavyLeptonEvGen.cxx.

307 {
308  LOG("gevgen_nhl", pINFO) << "Parsing command line arguments";
309 
310  // Common run options.
311  RunOpt::Instance()->ReadFromCommandLine(argc,argv);
312 
313  // Parse run options for this app
314 
315  CmdLnArgParser parser(argc,argv);
316 
317  // help?
318  bool help = parser.OptionExists('h');
319  if(help) {
320  PrintSyntax();
321  exit(0);
322  }
323 
324  // run number
325  if( parser.OptionExists('r') ) {
326  LOG("gevgen_nhl", pDEBUG) << "Reading MC run number";
327  gOptRunNu = parser.ArgAsLong('r');
328  } else {
329  LOG("gevgen_nhl", pDEBUG) << "Unspecified run number - Using default";
330  gOptRunNu = 1000;
331  } //-r
332 
333  // number of events
334  if( parser.OptionExists('n') ) {
335  LOG("gevgen_nhl", pDEBUG)
336  << "Reading number of events to generate";
337  gOptNev = parser.ArgAsInt('n');
338  } else {
339  LOG("gevgen_nhl", pFATAL)
340  << "You need to specify the number of events";
341  PrintSyntax();
342  exit(0);
343  } //-n
344 
345  // NHL mass
346  gOptMassNHL = -1;
347  if( parser.OptionExists("mass") ) {
348  LOG("gevgen_nhl", pDEBUG)
349  << "Reading NHL mass";
350  gOptMassNHL = parser.ArgAsDouble("mass");
351  } else {
352  LOG("gevgen_nhl", pFATAL)
353  << "You need to specify the NHL mass";
354  PrintSyntax();
355  exit(0);
356  } //--mass
357  PDGLibrary * pdglib = PDGLibrary::Instance();
358  pdglib->AddNHL(gOptMassNHL);
359 
360  // NHL energy (temporary - will disappear once we add an option to read a flux)
361  gOptEnergyNHL = -1;
362  if( parser.OptionExists('E') ) {
363  LOG("gevgen_nhl", pDEBUG)
364  << "Reading NHL energy";
365  gOptEnergyNHL = parser.ArgAsDouble('E');
366  } else {
367  LOG("gevgen_nhl", pFATAL)
368  << "You need to specify the NHL energy";
369  PrintSyntax();
370  exit(0);
371  } //-E
372  assert(gOptEnergyNHL > gOptMassNHL);
373 
374  // NHL decay mode
375  int mode = -1;
376  if( parser.OptionExists('m') ) {
377  LOG("gevgen_nhl", pDEBUG)
378  << "Reading NHL decay mode";
379  mode = parser.ArgAsInt('m');
380  } else {
381  LOG("gevgen_nhl", pFATAL)
382  << "You need to specify the decay mode";
383  PrintSyntax();
384  exit(0);
385  } //-m
386  gOptDecayMode = (NHLDecayMode_t) mode;
387 
389  if(!allowed) {
390  LOG("gevgen_nhl", pFATAL)
391  << "Specified decay is not allowed kinematically for the given NHL mass";
392  PrintSyntax();
393  exit(0);
394  }
395 
396  //
397  // geometry
398  //
399 
400  string geom = "";
401  string lunits;
402  // string dunits;
403  if( parser.OptionExists('g') ) {
404  LOG("gevgen_nhl", pDEBUG) << "Getting input geometry";
405  geom = parser.ArgAsString('g');
406 
407  // is it a ROOT file that contains a ROOT geometry?
408  bool accessible_geom_file =
409  ! (gSystem->AccessPathName(geom.c_str()));
410  if (accessible_geom_file) {
411  gOptRootGeom = geom;
412  gOptUsingRootGeom = true;
413  }
414  } else {
415  // LOG("gevgen_nhl", pFATAL)
416  // << "No geometry option specified - Exiting";
417  // PrintSyntax();
418  // exit(1);
419  } //-g
420 
421  if(gOptUsingRootGeom) {
422  // using a ROOT geometry - get requested geometry units
423 
424  // legth units:
425  if( parser.OptionExists('L') ) {
426  LOG("gevgen_nhl", pDEBUG)
427  << "Checking for input geometry length units";
428  lunits = parser.ArgAsString('L');
429  } else {
430  LOG("gevgen_nhl", pDEBUG) << "Using default geometry length units";
431  lunits = kDefOptGeomLUnits;
432  } // -L
433  // // density units:
434  // if( parser.OptionExists('D') ) {
435  // LOG("gevgen_nhl", pDEBUG)
436  // << "Checking for input geometry density units";
437  // dunits = parser.ArgAsString('D');
438  // } else {
439  // LOG("gevgen_nhl", pDEBUG) << "Using default geometry density units";
440  // dunits = kDefOptGeomDUnits;
441  // } // -D
443  // gOptGeomDUnits = utils::units::UnitFromString(dunits);
444 
445  // check whether an event generation volume name has been
446  // specified -- default is the 'top volume'
447  if( parser.OptionExists('t') ) {
448  LOG("gevgen_nhl", pDEBUG) << "Checking for input volume name";
449  gOptRootGeomTopVol = parser.ArgAsString('t');
450  } else {
451  LOG("gevgen_nhl", pDEBUG) << "Using the <master volume>";
452  } // -t
453 
454  } // using root geom?
455 
456  // event file prefix
457  if( parser.OptionExists('o') ) {
458  LOG("gevgen_nhl", pDEBUG) << "Reading the event filename prefix";
459  gOptEvFilePrefix = parser.ArgAsString('o');
460  } else {
461  LOG("gevgen_nhl", pDEBUG)
462  << "Will set the default event filename prefix";
464  } //-o
465 
466  // random number seed
467  if( parser.OptionExists("seed") ) {
468  LOG("gevgen_nhl", pINFO) << "Reading random number seed";
469  gOptRanSeed = parser.ArgAsLong("seed");
470  } else {
471  LOG("gevgen_nhl", pINFO) << "Unspecified random number seed - Using default";
472  gOptRanSeed = -1;
473  }
474 
475  //
476  // >>> print the command line options
477  //
478 
479  ostringstream gminfo;
480  if (gOptUsingRootGeom) {
481  gminfo << "Using ROOT geometry - file: " << gOptRootGeom
482  << ", top volume: "
483  << ((gOptRootGeomTopVol.size()==0) ? "<master volume>" : gOptRootGeomTopVol)
484  << ", length units: " << lunits;
485  // << ", density units: " << dunits;
486  }
487 
488  LOG("gevgen_nhl", pNOTICE)
489  << "\n\n"
490  << utils::print::PrintFramedMesg("gevgen_nhl job configuration");
491 
492  LOG("gevgen_nhl", pNOTICE)
493  << "\n @@ Run number : " << gOptRunNu
494  << "\n @@ Random seed : " << gOptRanSeed
495  << "\n @@ NHL mass : " << gOptMassNHL << " GeV"
496  << "\n @@ Decay channel : " << utils::nhl::AsString(gOptDecayMode)
497  << "\n @@ Geometry : " << gminfo.str()
498  << "\n @@ Statistics : " << gOptNev << " events";
499 }
string kDefOptGeomLUnits
string gOptRootGeomTopVol
Long_t gOptRunNu
#define pFATAL
Definition: Messenger.h:56
double gOptMassNHL
double gOptEnergyNHL
double gOptGeomLUnits
void AddNHL(double mass)
Definition: PDGLibrary.cxx:165
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
double UnitFromString(string u)
Definition: UnitUtils.cxx:18
#define pINFO
Definition: Messenger.h:62
string kDefOptEvFilePrefix
string gOptEvFilePrefix
bool gOptUsingRootGeom
void PrintSyntax(void)
Singleton class to load & serve a TDatabasePDG.
Definition: PDGLibrary.h:32
string PrintFramedMesg(string mesg, unsigned int nl=1, const char f='*')
Definition: PrintUtils.cxx:164
const char * AsString(Resonance_t res)
resonance id -> string
Command line argument parser.
#define pNOTICE
Definition: Messenger.h:61
string gOptRootGeom
long int gOptRanSeed
NHLDecayMode_t gOptDecayMode
enum genie::ENHLDecayMode NHLDecayMode_t
bool IsKinematicallyAllowed(NHLDecayMode_t nhldm, double Mnhl)
#define pDEBUG
Definition: Messenger.h:63
void InitBoundingBox ( void  )

Definition at line 232 of file gNeutralHeavyLeptonEvGen.cxx.

233 {
234 // Initialise geometry bounding box, used for generating NHL vertex positions
235 
236  fdx = 0; // half-length - x
237  fdy = 0; // half-length - y
238  fdz = 0; // half-length - z
239  fox = 0; // origin - x
240  foy = 0; // origin - y
241  foz = 0; // origin - z
242 
243  if(!gOptUsingRootGeom) return;
244 
245  bool geom_is_accessible = ! (gSystem->AccessPathName(gOptRootGeom.c_str()));
246  if (!geom_is_accessible) {
247  LOG("gevgen_nhl", pFATAL)
248  << "The specified ROOT geometry doesn't exist! Initialization failed!";
249  exit(1);
250  }
251 
252  TGeoManager * gm = TGeoManager::Import(gOptRootGeom.c_str());
253  TGeoVolume * top_volume = gm->GetTopVolume();
254  TGeoShape * ts = top_volume->GetShape();
255  TGeoBBox * box = (TGeoBBox *)ts;
256  //get box origin and dimensions (in the same units as the geometry)
257  fdx = box->GetDX(); // half-length
258  fdy = box->GetDY(); // half-length
259  fdz = box->GetDZ(); // half-length
260  fox = (box->GetOrigin())[0];
261  foy = (box->GetOrigin())[1];
262  foz = (box->GetOrigin())[2];
263 
264  // Convert from local to SI units
265  fdx *= gOptGeomLUnits;
266  fdy *= gOptGeomLUnits;
267  fdz *= gOptGeomLUnits;
268  fox *= gOptGeomLUnits;
269  foy *= gOptGeomLUnits;
270  foz *= gOptGeomLUnits;
271 }
#define pFATAL
Definition: Messenger.h:56
double gOptGeomLUnits
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
#define Import
bool gOptUsingRootGeom
string gOptRootGeom
int main ( int  argc,
char **  argv 
)

Definition at line 164 of file gNeutralHeavyLeptonEvGen.cxx.

165 {
166  // Parse command line arguments
167  GetCommandLineArgs(argc,argv);
168 
169  // Init messenger and random number seed
170  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
172 
173  // Initialize an Ntuple Writer to save GHEP records into a TTree
175  ntpw.CustomizeFilenamePrefix(gOptEvFilePrefix);
176  ntpw.Initialize();
177 
178  // Create a MC job monitor for a periodically updated status file
179  GMCJMonitor mcjmonitor(gOptRunNu);
180  mcjmonitor.SetRefreshRate(RunOpt::Instance()->MCJobStatusRefreshRate());
181 
182  // Set GHEP print level
183  GHepRecord::SetPrintLevel(RunOpt::Instance()->EventRecordPrintLevel());
184 
185  // Read geometry bounding box - for vertex position generation
186  InitBoundingBox();
187 
188  // Get the nucleon decay generator
189  const EventRecordVisitorI * mcgen = NHLGenerator();
190 
191  // Event loop
192  int ievent = 0;
193  while (1)
194  {
195  if(ievent == gOptNev) break;
196 
197  LOG("gevgen_nhl", pNOTICE)
198  << " *** Generating event............ " << ievent;
199 
200  EventRecord * event = new EventRecord;
201  // int target = SelectInitState();
202  int decay = (int)gOptDecayMode;
203  Interaction * interaction = Interaction::NHL(gOptEnergyNHL, decay);
204  event->AttachSummary(interaction);
205 
206  // Simulate decay
207  mcgen->ProcessEventRecord(event);
208 
209  // Generate a position within the geometry bounding box
210  TLorentzVector x4 = GeneratePosition();
211  event->SetVertex(x4);
212 
213  LOG("gevgen_nhl", pINFO)
214  << "Generated event: " << *event;
215 
216  // Add event at the output ntuple, refresh the mc job monitor & clean-up
217  ntpw.AddEventRecord(ievent, event);
218  mcjmonitor.Update(ievent,event);
219  delete event;
220 
221  ievent++;
222  } // event loop
223 
224  // Save the generated event tree & close the output file
225  ntpw.Save();
226 
227  LOG("gevgen_nhl", pNOTICE) << "Done!";
228 
229  return 0;
230 }
void RandGen(long int seed)
Definition: AppInit.cxx:30
TLorentzVector GeneratePosition(void)
virtual void ProcessEventRecord(GHepRecord *event_rec) const =0
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
Long_t gOptRunNu
NtpMCFormat_t kDefOptNtpFormat
double gOptEnergyNHL
const EventRecordVisitorI * NHLGenerator(void)
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
void GetCommandLineArgs(int argc, char **argv)
void InitBoundingBox(void)
#define pINFO
Definition: Messenger.h:62
string gOptEvFilePrefix
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
long int gOptRanSeed
NHLDecayMode_t gOptDecayMode
Event finding and building.
const EventRecordVisitorI * NHLGenerator ( void  )

Definition at line 291 of file gNeutralHeavyLeptonEvGen.cxx.

292 {
293  string sname = "genie::EventGenerator";
294  string sconfig = "NeutralHeavyLepton";
295  AlgFactory * algf = AlgFactory::Instance();
296  const EventRecordVisitorI * mcgen =
297  dynamic_cast<const EventRecordVisitorI *> (algf->GetAlgorithm(sname,sconfig));
298  if(!mcgen) {
299  LOG("gevgen_nhl", pFATAL) << "Couldn't instantiate the NHL generator";
300  gAbortingInErr = true;
301  exit(1);
302  }
303  return mcgen;
304 }
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 501 of file gNeutralHeavyLeptonEvGen.cxx.

502 {
503  LOG("gevgen_nhl", pFATAL)
504  << "\n **Syntax**"
505  << "\n gevgen_nhl [-h] "
506  << "\n [-r run#]"
507  << "\n -E nhl_energy (temporary)"
508  << "\n --mass nhl_mass"
509  << "\n -m decay_mode"
510  << "\n -f flux ** not installed yet **"
511  << "\n [-g geometry]"
512  << "\n [-t top_volume_name_at_geom]"
513  << "\n [-L length_units_at_geom]"
514  << "\n -n n_of_events "
515  << "\n [-o output_event_file_prefix]"
516  << "\n [--seed random_number_seed]"
517  << "\n [--message-thresholds xml_file]"
518  << "\n [--event-record-print-level level]"
519  << "\n [--mc-job-status-refresh-rate rate]"
520  << "\n"
521  << " Please also read the detailed documentation at http://www.genie-mc.org"
522  << " or look at the source code: $GENIE/src/Apps/gNeutralHeavyLeptonEvGen.cxx"
523  << "\n";
524 }
#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

Variable Documentation

double fdx = 0

Definition at line 156 of file gNeutralHeavyLeptonEvGen.cxx.

double fdy = 0

Definition at line 157 of file gNeutralHeavyLeptonEvGen.cxx.

double fdz = 0

Definition at line 158 of file gNeutralHeavyLeptonEvGen.cxx.

double fox = 0

Definition at line 159 of file gNeutralHeavyLeptonEvGen.cxx.

double foy = 0

Definition at line 160 of file gNeutralHeavyLeptonEvGen.cxx.

double foz = 0

Definition at line 161 of file gNeutralHeavyLeptonEvGen.cxx.

NHLDecayMode_t gOptDecayMode = kNHLDcyNull

Definition at line 147 of file gNeutralHeavyLeptonEvGen.cxx.

double gOptEnergyNHL = -1

Definition at line 145 of file gNeutralHeavyLeptonEvGen.cxx.

string gOptEvFilePrefix = kDefOptEvFilePrefix

Definition at line 148 of file gNeutralHeavyLeptonEvGen.cxx.

double gOptGeomLUnits = 0

Definition at line 152 of file gNeutralHeavyLeptonEvGen.cxx.

double gOptMassNHL = -1

Definition at line 146 of file gNeutralHeavyLeptonEvGen.cxx.

int gOptNev = 10

Definition at line 144 of file gNeutralHeavyLeptonEvGen.cxx.

long int gOptRanSeed = -1

Definition at line 153 of file gNeutralHeavyLeptonEvGen.cxx.

string gOptRootGeom

Definition at line 150 of file gNeutralHeavyLeptonEvGen.cxx.

string gOptRootGeomTopVol = ""

Definition at line 151 of file gNeutralHeavyLeptonEvGen.cxx.

Long_t gOptRunNu = 1000

Definition at line 143 of file gNeutralHeavyLeptonEvGen.cxx.

bool gOptUsingRootGeom = false

Definition at line 149 of file gNeutralHeavyLeptonEvGen.cxx.

string kDefOptEvFilePrefix = "gntp"

Definition at line 140 of file gNeutralHeavyLeptonEvGen.cxx.

string kDefOptGeomDUnits = "g_cm3"

Definition at line 138 of file gNeutralHeavyLeptonEvGen.cxx.

string kDefOptGeomLUnits = "mm"

Definition at line 137 of file gNeutralHeavyLeptonEvGen.cxx.

NtpMCFormat_t kDefOptNtpFormat = kNFGHEP

Definition at line 139 of file gNeutralHeavyLeptonEvGen.cxx.