LArSoft  v06_85_00
Liquid Argon Software toolkit - http://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 198 of file chem4.cc.

Referenced by SetSeed().

199 {
200  switch(c)
201  {
202  case '[':
203  case ']':
204  return true;
205  default:
206  return false;
207  }
208 }
int main ( int  argc,
char **  argv 
)

Definition at line 77 of file chem4.cc.

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

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

Definition at line 265 of file chem4.cc.

References file.

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

266 {
267 #if defined(WIN32)|| defined(_WIN32)|| defined(__WIN32)&&!defined(__CYGWIN__)
268  // TODO: MS Win
269  return std::time(0);
270 #else
271  unsigned int random_seed, random_seed_a, random_seed_b;
272  std::ifstream file ("/dev/urandom", std::ios::binary);
273  if (file.is_open())
274  {
275  char * memblock;
276  int size = sizeof(int);
277  memblock = new char [size];
278  file.read (memblock, size);
279  file.close();
280  random_seed_a = *reinterpret_cast<int*>(memblock);
281  delete[] memblock;
282  }// end if
283  else
284  {
285  random_seed_a = 0;
286  }
287  random_seed_b = std::time(0);
288  random_seed = random_seed_a xor random_seed_b;
289  return random_seed;
290 #endif
291 }
TFile * file
void Parse ( int &  argc,
char **  argv 
)

Definition at line 295 of file chem4.cc.

References parser().

Referenced by main().

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

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

void SetSeed ( )

Definition at line 212 of file chem4.cc.

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

Referenced by main().

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

Variable Documentation