GENIEGenerator
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions | Variables
gNNBarOscEvGen.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/NNBarOscillation/NNBarOscMode.h"
#include "Physics/NNBarOscillation/NNBarOscUtils.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"
Include dependency graph for gNNBarOscEvGen.cxx:

Go to the source code of this file.

Functions

void GetCommandLineArgs (int argc, char **argv)
 
void PrintSyntax (void)
 
int SelectAnnihilationMode (int pdg_code)
 
int SelectInitState (void)
 
const EventRecordVisitorINeutronOscGenerator (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
 
NNBarOscMode_t gOptDecayMode = kNONull
 
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 
)
int main ( int  argc,
char **  argv 
)

Definition at line 183 of file gNNBarOscEvGen.cxx.

References genie::NtpWriter::AddEventRecord(), genie::NtpWriter::CustomizeFilenamePrefix(), GetCommandLineArgs(), gOptEvFilePrefix, gOptNev, gOptRanSeed, gOptRunNu, genie::NtpWriter::Initialize(), genie::RunOpt::Instance(), kDefOptNtpFormat, LOG, genie::utils::app_init::MesgThresholds(), NeutronOscGenerator(), genie::Interaction::NOsc(), pINFO, pNOTICE, genie::EventRecordVisitorI::ProcessEventRecord(), genie::utils::app_init::RandGen(), genie::NtpWriter::Save(), SelectAnnihilationMode(), SelectInitState(), genie::GHepRecord::SetPrintLevel(), genie::GMCJMonitor::SetRefreshRate(), and genie::GMCJMonitor::Update().

184 {
185  // Parse command line arguments
186  GetCommandLineArgs(argc,argv);
187 
188  // Init messenger and random number seed
189  utils::app_init::MesgThresholds(RunOpt::Instance()->MesgThresholdFiles());
191 
192  // Initialize an Ntuple Writer to save GHEP records into a TTree
194  ntpw.CustomizeFilenamePrefix(gOptEvFilePrefix);
195  ntpw.Initialize();
196 
197  // Create a MC job monitor for a periodically updated status file
198  GMCJMonitor mcjmonitor(gOptRunNu);
199  mcjmonitor.SetRefreshRate(RunOpt::Instance()->MCJobStatusRefreshRate());
200 
201  // Set GHEP print level
202  GHepRecord::SetPrintLevel(RunOpt::Instance()->EventRecordPrintLevel());
203 
204  // Get the nucleon decay generator
205  const EventRecordVisitorI * mcgen = NeutronOscGenerator();
206 
207  // Event loop
208  int ievent = 0;
209  while (1)
210  {
211  if(ievent == gOptNev) break;
212 
213  LOG("gevgen_nnbar_osc", pNOTICE)
214  << " *** Generating event............ " << ievent;
215 
216  EventRecord * event = new EventRecord;
217  int target = SelectInitState();
218  int decay = SelectAnnihilationMode(target);
219  Interaction * interaction = Interaction::NOsc(target,decay);
220  event->AttachSummary(interaction);
221 
222  // Simulate decay
223  mcgen->ProcessEventRecord(event);
224 
225  LOG("gevgen_nnbar_osc", 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_nnbar_osc", pNOTICE) << "Done!";
240 
241  return 0;
242 }
void RandGen(long int seed)
Definition: AppInit.cxx:30
const EventRecordVisitorI * NeutronOscGenerator(void)
string gOptEvFilePrefix
Definition: gAtmoEvGen.cxx:310
Defines the EventRecordVisitorI interface. Concrete implementations of this interface use the &#39;Visito...
int SelectAnnihilationMode(int pdg_code)
Summary information for an interaction.
Definition: Interaction.h:56
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
int gOptNev
Definition: gAtmoEvGen.cxx:305
#define pINFO
Definition: Messenger.h:62
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
NtpMCFormat_t kDefOptNtpFormat
Definition: gAtmoEvGen.cxx:319
void MesgThresholds(string inpfile)
Definition: AppInit.cxx:99
int SelectInitState(void)
#define pNOTICE
Definition: Messenger.h:61
void GetCommandLineArgs(int argc, char **argv)
Definition: gAtmoEvGen.cxx:563
long int gOptRanSeed
Definition: gAtmoEvGen.cxx:312
const EventRecordVisitorI * NeutronOscGenerator ( void  )

Definition at line 323 of file gNNBarOscEvGen.cxx.

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

Referenced by main().

324 {
325  string sname = "genie::EventGenerator";
326  string sconfig = "NNBarOsc";
327  AlgFactory * algf = AlgFactory::Instance();
328  const EventRecordVisitorI * mcgen =
329  dynamic_cast<const EventRecordVisitorI *> (algf->GetAlgorithm(sname,sconfig));
330  if(!mcgen) {
331  LOG("gevgen_nnbar_osc", pFATAL)
332  << "Couldn't instantiate the neutron oscillation generator";
333  gAbortingInErr = true;
334  exit(1);
335  }
336  return mcgen;
337 }
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  )
int SelectAnnihilationMode ( int  pdg_code)

Definition at line 244 of file gNNBarOscEvGen.cxx.

References genie::gAbortingInErr, gOptDecayMode, genie::RandomGen::Instance(), genie::kNORandom, LOG, pERROR, pFATAL, genie::RandomGen::RndNum(), and genie::RandomGen::SetSeed().

Referenced by main().

245 {
246  // if the mode is set to 'random' (the default), pick one at random!
247  if (gOptDecayMode == kNORandom) {
248  int mode;
249 
250  std::string pdg_string = std::to_string(static_cast<long long>(pdg_code));
251  if (pdg_string.size() != 10) {
252  LOG("gevgen_nnbar_osc", pERROR)
253  << "Expecting PDG code to be a 10-digit integer; instead, it's the following: " << pdg_string;
254  gAbortingInErr = true;
255  exit(1);
256  }
257 
258  // count number of protons & neutrons
259  int n_nucleons = std::stoi(pdg_string.substr(6,3)) - 1;
260  int n_protons = std::stoi(pdg_string.substr(3,3));
261 
262  // factor proton / neutron ratio into branching ratios
263  double proton_frac = ((double)n_protons) / ((double)n_nucleons);
264  double neutron_frac = 1 - proton_frac;
265 
266  // set branching ratios, taken from bubble chamber data
267  const int n_modes = 16;
268  double br [n_modes] = { 0.010, 0.080, 0.100, 0.220,
269  0.360, 0.160, 0.070, 0.020,
270  0.015, 0.065, 0.110, 0.280,
271  0.070, 0.240, 0.100, 0.100 };
272 
273  for (int i = 0; i < n_modes; i++) {
274  if (i < 7)
275  br[i] *= proton_frac;
276  else
277  br[i] *= neutron_frac;
278  }
279 
280  // randomly generate a number between 1 and 0
281  RandomGen * rnd = RandomGen::Instance();
282  rnd->SetSeed(0);
283  double p = rnd->RndNum().Rndm();
284 
285  // loop through all modes, figure out which one our random number corresponds to
286  double threshold = 0;
287  for (int i = 0; i < n_modes; i++) {
288  threshold += br[i];
289  if (p < threshold) {
290  // once we've found our mode, return it!
291  mode = i + 1;
292  return mode;
293  }
294  }
295 
296  // error message, in case the random number selection fails
297  LOG("gevgen_nnbar_osc", pFATAL) << "Random selection of final state failed!";
298  gAbortingInErr = true;
299  exit(1);
300  }
301 
302  // if specific annihilation mode specified, just use that
303  else {
304  int mode = (int) gOptDecayMode;
305  return mode;
306  }
307 }
HNLDecayMode_t gOptDecayMode
#define pERROR
Definition: Messenger.h:59
#define pFATAL
Definition: Messenger.h:56
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
TRandom3 & RndNum(void) const
rnd number generator used by MC integrators &amp; other numerical methods
Definition: RandomGen.h:77
bool gAbortingInErr
Definition: Messenger.cxx:34
void SetSeed(long int seed)
Definition: RandomGen.cxx:82
int SelectInitState ( void  )

Definition at line 309 of file gNNBarOscEvGen.cxx.

References genie::gAbortingInErr, gOptTgtMix, LOG, and pERROR.

Referenced by main().

310 {
311  if (gOptTgtMix.size() > 1) {
312  LOG("gevgen_nnbar_osc", pERROR)
313  << "Target mix not currently supported. You must specify a single target nucleus!";
314  gAbortingInErr = true;
315  exit(1);
316  }
317 
318  int pdg_code = gOptTgtMix.begin()->first;
319 
320  return pdg_code;
321 }
#define pERROR
Definition: Messenger.h:59
map< int, double > gOptTgtMix
Definition: gAtmoEvGen.cxx:299
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE...
Definition: Messenger.h:96
bool gAbortingInErr
Definition: Messenger.cxx:34

Variable Documentation

NNBarOscMode_t gOptDecayMode = kNONull

Definition at line 172 of file gNNBarOscEvGen.cxx.

string gOptEvFilePrefix = kDefOptEvFilePrefix

Definition at line 173 of file gNNBarOscEvGen.cxx.

double gOptGeomDUnits = 0

Definition at line 179 of file gNNBarOscEvGen.cxx.

double gOptGeomLUnits = 0

Definition at line 178 of file gNNBarOscEvGen.cxx.

int gOptNev = 10

Definition at line 171 of file gNNBarOscEvGen.cxx.

long int gOptRanSeed = -1

Definition at line 180 of file gNNBarOscEvGen.cxx.

string gOptRootGeom

Definition at line 176 of file gNNBarOscEvGen.cxx.

string gOptRootGeomTopVol = ""

Definition at line 177 of file gNNBarOscEvGen.cxx.

Long_t gOptRunNu = 1000

Definition at line 170 of file gNNBarOscEvGen.cxx.

map<int,double> gOptTgtMix

Definition at line 175 of file gNNBarOscEvGen.cxx.

bool gOptUsingRootGeom = false

Definition at line 174 of file gNNBarOscEvGen.cxx.

string kDefOptEvFilePrefix = "gntp"

Definition at line 167 of file gNNBarOscEvGen.cxx.

string kDefOptGeomDUnits = "g_cm3"

Definition at line 165 of file gNNBarOscEvGen.cxx.

string kDefOptGeomLUnits = "mm"

Definition at line 164 of file gNNBarOscEvGen.cxx.

NtpMCFormat_t kDefOptNtpFormat = kNFGHEP

Definition at line 166 of file gNNBarOscEvGen.cxx.