LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
chem4.cc File Reference

Chem4 example. More...

#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "ActionInitialization.hh"
#include "G4RunManager.hh"
#include "G4DNAChemistryManager.hh"
#include "G4UImanager.hh"
#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"
#include "CommandLineParser.hh"

Go to the source code of this file.

Functions

CommandLineParser * parser (0)
 
unsigned int noise ()
 
void SetSeed ()
 
void Parse (int &argc, char **argv)
 
int main (int argc, char **argv)
 
bool IsBracket (char c)
 

Variables

long seed = 0
 

Detailed Description

Chem4 example.

Definition in file chem4.cc.

Function Documentation

bool IsBracket ( char  c)

Definition at line 194 of file chem4.cc.

Referenced by SetSeed().

195 {
196  switch(c)
197  {
198  case '[':
199  case ']':
200  return true;
201  default:
202  return false;
203  }
204 }
int main ( int  argc,
char **  argv 
)

Definition at line 76 of file chem4.cc.

References Parse(), parser(), and SetSeed().

77 {
78  // Parse options given in commandLine
79  Parse(argc, argv);
80  Command* commandLine(0);
81  SetSeed();
82 
83  // Construct the run manager according to whether MT is activated or not
84  //
85 #ifdef G4MULTITHREADED
86  G4MTRunManager* runManager= new G4MTRunManager();
87 
88  if((commandLine = parser->GetCommandIfActive("-mt")))
89  {
90  int nThreads = 2;
91  if(commandLine->GetOption() == "NMAX")
92  {
93  nThreads = G4Threading::G4GetNumberOfCores();
94  }
95  else
96  {
97  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
98  }
99 
100  runManager->SetNumberOfThreads(nThreads);
101  }
102 
103  G4cout << "**************************************************************"
104  << "******\n===== Chem4 is started with "
105  << runManager->GetNumberOfThreads() << " of "
106  << G4Threading::G4GetNumberOfCores()
107  << " available threads =====\n\n*************************************"
108  <<"*******************************"
109  << G4endl;
110 #else
111  G4RunManager* runManager = new G4RunManager();
112 #endif
113 
114  // Set mandatory initialization classes
115  runManager->SetUserInitialization(new PhysicsList());
116  runManager->SetUserInitialization(new DetectorConstruction());
117  runManager->SetUserInitialization(new ActionInitialization());
118 
119  // Initialize visualization
120  G4VisManager* visManager = new G4VisExecutive();
121  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
122  // G4VisManager* visManager = new G4VisExecutive("Quiet");
123  visManager->Initialize();
124 
125  // Get the pointer to the User Interface manager
126  G4UImanager* UImanager = G4UImanager::GetUIpointer();
127  G4UIExecutive* ui(0);
128 
129  // interactive mode : define UI session
130  if((commandLine = parser->GetCommandIfActive("-gui")))
131  {
132  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
133 
134  if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
135 
136  if (parser->GetCommandIfActive("-novis") == 0)
137  {
138  // visualization is used by default
139  if ((commandLine = parser->GetCommandIfActive("-vis")))
140  {
141  // select a visualization driver if needed (e.g. HepFile)
142  UImanager->ApplyCommand
143  (G4String("/vis/open ") + commandLine->GetOption());
144  }
145  else
146  {
147  // by default OGL is used
148  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
149  }
150  UImanager->ApplyCommand("/control/execute vis.mac");
151  }
152  }
153  else
154  {
155  // to be use visualization file (= store the visualization into
156  // an external file:
157  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
158  if((commandLine = parser->GetCommandIfActive("-vis")))
159  {
160  UImanager->ApplyCommand(G4String("/vis/open ")
161  + commandLine->GetOption());
162  UImanager->ApplyCommand("/control/execute vis.mac");
163  }
164  }
165 
166  if((commandLine = parser->GetCommandIfActive("-mac")))
167  {
168  G4String command = "/control/execute ";
169  UImanager->ApplyCommand(command + commandLine->GetOption());
170  }
171  else
172  {
173  UImanager->ApplyCommand("/control/execute beam.in");
174  }
175 
176  if((commandLine = parser->GetCommandIfActive("-gui")))
177  {
178  ui->SessionStart();
179  delete ui;
180  }
181 
182  // Job termination
183  // Free the store: user actions, physics_list and detector_description are
184  // owned and deleted by the run manager, so they should not be deleted
185  // in the main() program !
186  delete visManager;
187  delete runManager;
188  CommandLineParser::DeleteInstance();
189  return 0;
190 }
void Parse(int &argc, char **argv)
Definition: chem4.cc:291
void SetSeed()
Definition: chem4.cc:208
TConfigurablePhysicsList< ModularPhysicsList > PhysicsList
Definition: PhysicsList.h:83
CommandLineParser * parser(0)
unsigned int noise ( )

Definition at line 261 of file chem4.cc.

References file, and util::size().

Referenced by img::DataProviderAlg::addCoherentNoise(), img::DataProviderAlg::addWhiteNoise(), trkf::InteractPlane::clone(), noisefilteralg::WireCellNoiseFilter::DoNoiseFilter(), genf::RKTrackRep::Extrap(), cluster::DBScanAlg::run_dbscan_cluster(), cluster::DBScanAlg::run_FN_cluster(), cluster::DBScanAlg::run_FN_naive_cluster(), genf::GFMaterialEffects::setNoiseBrems(), SetSeed(), and genf::GFMaterialEffects::stepper().

262 {
263 #if defined(WIN32)|| defined(_WIN32)|| defined(__WIN32)&&!defined(__CYGWIN__)
264  // TODO: MS Win
265  return std::time(0);
266 #else
267  unsigned int random_seed, random_seed_a, random_seed_b;
268  std::ifstream file ("/dev/urandom", std::ios::binary);
269  if (file.is_open())
270  {
271  char * memblock;
272  int size = sizeof(int);
273  memblock = new char [size];
274  file.read (memblock, size);
275  file.close();
276  random_seed_a = *reinterpret_cast<int*>(memblock);
277  delete[] memblock;
278  }// end if
279  else
280  {
281  random_seed_a = 0;
282  }
283  random_seed_b = std::time(0);
284  random_seed = random_seed_a xor random_seed_b;
285  return random_seed;
286 #endif
287 }
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:101
TFile * file
void Parse ( int &  argc,
char **  argv 
)

Definition at line 291 of file chem4.cc.

References parser().

Referenced by main().

292 {
294  // Parse options given in commandLine
295  //
296  parser = CommandLineParser::GetParser();
297 
298  parser->AddCommand("-gui", Command::OptionNotCompulsory,
299  "Select geant4 UI or just launch a geant4 terminal"
300  "session",
301  "qt");
302 
303  parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute",
304  "macFile.mac");
305 
306  parser->AddCommand("-seed",
307  Command::WithOption,
308  "Give a seed value in argument to be tested", "seed");
309 
310 #ifdef G4MULTITHREADED
311  parser->AddCommand("-mt",Command::WithOption,
312  "Launch in MT mode (events computed in parallel,"
313  " NOT RECOMMANDED WITH CHEMISTRY)", "2");
314 #endif
315 
316  parser->AddCommand("-chemOFF", Command::WithoutOption,
317  "Deactivate chemistry");
318 
319  parser->AddCommand("-vis", Command::WithOption,
320  "Select a visualization driver", "OGL 600x600-0+0");
321 
322  parser->AddCommand("-novis", Command::WithoutOption,
323  "Deactivate visualization when using GUI");
324 
325  parser->AddCommand("-cluster", Command::WithoutOption,
326  "Launch the code on a cluster, avoid dupplicated seeds");
327 
329  // If -h or --help is given in option : print help and exit
330  //
331  if (parser->Parse(argc, argv) != 0) // help is being printed
332  {
333  // if you are using ROOT, create a TApplication in this condition in order
334  // to print the help from ROOT as well
335  CommandLineParser::DeleteInstance();
336  std::exit(0);
337  }
338 
340  // Kill application if wrong argument in command line
341  //
342  if(parser->CheckIfNotHandledOptionsExists(argc, argv))
343  {
344  // if you are using ROOT, you should initialise your TApplication
345  // before this condition
346  std::exit(0);
347  }
348 }
CommandLineParser * parser(0)
CommandLineParser* parser ( )

Referenced by main(), Parse(), and SetSeed().

void SetSeed ( )

Definition at line 208 of file chem4.cc.

References IsBracket(), noise(), parser(), and seed.

Referenced by main().

209 {
210  Command* commandLine(0);
211 
212  if((commandLine = parser->GetCommandIfActive("-seed")))
213  {
214  seed = atoi(commandLine->GetOption().c_str());
215  }
216 
217  if(seed == 0) // If no seed given in argument, setup the seed
218  {
219  long jobID_int = 0;
220  long noice = 0;
221 
222  //____________________________________
223  // In case on cluster
224  if((commandLine = parser->GetCommandIfActive("-cluster")))
225  {
226  noice = labs((long) noise());
227 
228  const char * env = std::getenv("PBS_JOBID");
229 
230  if(env)
231  {
232  G4String buffer(env);
233  G4String jobID_string = buffer.substr(0, buffer.find("."));
234  jobID_string.erase(std::remove_if(jobID_string.begin(),
235  jobID_string.end(),
236  &IsBracket),
237  jobID_string.end());
238  jobID_int = atoi(jobID_string.c_str());
239  }
240  else
241  {
242  env = std::getenv("SGE_TASK_ID");
243  if(env) jobID_int = atoi(env);
244  }
245  } // end cluster
246 
247  //____________________________________
248  seed = ((long) time(NULL)) + jobID_int + noice;
249  }
250 
251  G4cout << "Seed used : " << seed << G4endl;
252  G4Random::setTheEngine(new CLHEP::MixMaxRng());
253  G4Random::setTheSeed(seed);
254 
255  // Choose the Random engine
256  // CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
257 }
bool IsBracket(char c)
Definition: chem4.cc:194
unsigned int noise()
Definition: chem4.cc:261
long seed
Definition: chem4.cc:67
CommandLineParser * parser(0)

Variable Documentation

long seed = 0

Definition at line 67 of file chem4.cc.

Referenced by evgen::ActiveVolumeVertexSampler::ActiveVolumeVertexSampler(), nnet::NoiseWaveformDump::analyze(), nnet::RawWaveformDump::analyze(), nnet::RawWaveformClnSigDump::analyze(), trkf::SeedAna::analyze(), lar_pandora::LArPandoraHelper::CollectSeeds(), rndm::details::RangeCheckHelper< SEED >::configure(), rndm::details::PerEventPolicy< SEED >::createEventSeed(), art::RandomNumberGenerator::defaultEngineKind(), rndm::NuRandomService::defineEngineID(), artg4tk::EventGenerator::EventGenerator(), rndm::details::PerEventPolicy< SEED >::EventTimestamp_v1(), evgb::EvtTimeShiftI::EvtTimeShiftI(), rndm::SeedMaster< SEED >::freezeSeed(), evgen::GENIEGen::GENIEGen(), rndm::SeedMaster< seed_t >::getCurrentSeed(), rndm::SeedMaster< SEED >::getEventSeed(), rndm::NuRandomService::getGlobalCurrentSeed(), rndm::details::CheckedRangePolicy< SEED >::getSeed(), rndm::SeedMaster< SEED >::getSeed(), cmtool::CMatchManager::IterationProcess(), evgen::larg4SingleGen::larg4SingleGen(), main(), evgen::MARLEYHelper::MARLEYHelper(), rndm::details::RandomPolicy< SEED >::RandomImpl::master_seed(), evgen::NeutronOsc::NeutronOsc(), evgen::NucleonDecay::NucleonDecay(), std::hash< std::tuple< TT... > >::operator()(), rndm::details::RangeCheckHelper< seed_t >::operator()(), rndm::NuRandomService::print(), trkf::CCTrackMaker::produce(), TrackProducerFromPFParticle::produce(), rndm::NuRandomService::readSeedParameter(), rndm::NuRandomService::registerAndSeedEngine(), rndm::SeedMaster< SEED >::reseed(), rndm::SeedMaster< SEED >::reseedEvent(), rndm::NuRandomService::reseedInstance(), SetSeed(), and evgen::SingleGen::SingleGen().