Public Member Functions | Private Attributes | List of all members
LBNERunAction Class Reference

#include <LBNERunAction.hh>

Inheritance diagram for LBNERunAction:

Public Member Functions

 LBNERunAction ()
 
 ~LBNERunAction ()
 
void BeginOfRunAction (const G4Run *)
 
void EndOfRunAction (const G4Run *)
 
void CheckOKToRun ()
 
void CheckMemoryUsage (double VMLimit) const
 
void SetDebugLevel (bool t)
 
bool GetDebugLevel () const
 
void SetDoComputeEDepInGraphite (bool t) const
 
bool GetDoComputeEDepInGraphite () const
 
void storeEDepInGraphite (double edep) const
 
void SetDoComputeEDepInArgonGas (bool t) const
 
bool GetDoComputeEDepInArgonGas () const
 
void storeEDepInArgonGas (double edepH1, double edepH2) const
 
void SetDoComputeEDepInHorns (bool t) const
 
bool GetDoComputeEDepInHorns () const
 
LBNFDeDxMapGetG4MARSDeDxMap () const
 

Private Attributes

int fVerboseLevel
 
LBNERunActionMessengerrunMessenger
 
bool fDoComputeEDepInGraphite
 
bool fDoComputeEDepInArgonGas
 
double fMeanEDepInGraphite
 
double fRMSEDepInGraphite
 
double fMeanEDepInArgonGasHorn1
 
double fRMSEDepInArgonGasHorn1
 
double fMeanEDepInArgonGasHorn2
 
double fRMSEDepInArgonGasHorn2
 
bool fDoComputeEDepInHorns
 
LBNFDeDxMapfG4MARSDeDxMap
 

Detailed Description

Definition at line 16 of file LBNERunAction.hh.

Constructor & Destructor Documentation

LBNERunAction::LBNERunAction ( )

Definition at line 28 of file LBNERunAction.cc.

28  :
29 fVerboseLevel(1),
40 {
41 
42  if(fVerboseLevel > 0)
43  {
44  std::cout << "LBNERunAction Constructor Called." << std::endl;
45  }
46 
47 
49 }
double fRMSEDepInArgonGasHorn1
bool fDoComputeEDepInArgonGas
double fRMSEDepInGraphite
bool fDoComputeEDepInHorns
LBNFDeDxMap * fG4MARSDeDxMap
LBNERunActionMessenger * runMessenger
bool fDoComputeEDepInGraphite
double fMeanEDepInArgonGasHorn2
double fRMSEDepInArgonGasHorn2
double fMeanEDepInArgonGasHorn1
double fMeanEDepInGraphite
QTextStream & endl(QTextStream &s)
LBNERunAction::~LBNERunAction ( )

Definition at line 52 of file LBNERunAction.cc.

53 {
54  if(fVerboseLevel > 0)
55  {
56  std::cout << "LBNERunAction Destructor Called." << std::endl;
57  }
58 
59  delete runMessenger;
60 }
LBNERunActionMessenger * runMessenger
QTextStream & endl(QTextStream &s)

Member Function Documentation

void LBNERunAction::BeginOfRunAction ( const G4Run *  aRun)

Definition at line 63 of file LBNERunAction.cc.

64 {
65  if(fVerboseLevel > 0)
66  {
67  std::cout << "LBNERunAction::BeginOfRunAction() Called." << std::endl;
68  }
69 
70 
71  LBNERunManager* theRunManager = dynamic_cast<LBNERunManager*>(G4RunManager::GetRunManager());
72 
73  G4String spaces = " ";
74  //std::cout << std::endl;
75  std::cout << "LBNERunAction::BeginOfRunAction() - Initializing Run "
76  << aRun->GetRunID() << "..." << std::endl;
77 
78  //std::cout << spaces << "Preparing \"" << fLBNEData -> GetSimulation() << "\" Simulation." << std::endl;
79 
80  //
81  //Random number generator
82  //
83  G4String randomFile="rndm/beginOfRun_";
84  char runN[4];
85  snprintf(runN, 4, "%03d",aRun->GetRunID());
86  randomFile.append(runN);
87  randomFile.append(".rndm");
88  CLHEP::HepRandom::saveEngineStatus(randomFile);
89  std::cout << spaces << "Intializing Random Number generator named "
90  << CLHEP::HepRandom::getTheEngine()->name() << " ... " << std::endl
91  << spaces << " Seed = " << CLHEP::HepRandom::getTheSeed() << std::endl
92  << spaces << " Saving Random engine status in "<< randomFile << std::endl;
93  //
94 
96  fRMSEDepInGraphite = 0.;
101  //
102  //Open input ntuples set Number of Events to loop over
103  //
104 // LBNEPrimaryGeneratorAction* primaryGeneratorAction = dynamic_cast<LBNEPrimaryGeneratorAction*>(pRunManager->userPrimaryGeneratorAction);
105 // const LBNEPrimaryGeneratorAction* primaryGeneratorAction =
106 // dynamic_cast<const LBNEPrimaryGeneratorAction*>(pRunManager->GetUserPrimaryGeneratorAction());
107 
108  LBNEPrimaryGeneratorAction* primaryGeneratorAction =
109  (theRunManager->GetLBNEPrimaryGeneratorAction());
110 
111 
112  if(!primaryGeneratorAction)
113  {
114  std::cout << spaces << "PROBLEM: INVALID LBNEPrimaryGeneratorAction POINTER" << std::endl;
115 // fLBNEData -> SetOKToRun(false);
116  return;
117  }
118 
119 // if(fLBNEData->GetSimulation() == "Standard Neutrino Beam" ||
120 // fLBNEData->GetSimulation() == "Target Tracking" ||
121 // fLBNEData->GetSimulation() == "Horn 1 Tracking" ||
122 // fLBNEData->GetSimulation() == "Horn 2 Tracking" )
123  {
124 
125  if (theRunManager->GetUseFlukaInput() || theRunManager->GetUseMarsInput())
126  {
127  G4bool ntpOpen = primaryGeneratorAction->OpenNtuple(theRunManager->GetNptInputFileName());
128 //
129  if(!ntpOpen)
130  {
131  std::ostringstream mStrStr;
132  mStrStr << "PROBLEM: FAILED TO OPEN INPUT NTUPLE. Fatal " << std::endl;
133  G4String mStr(mStrStr.str());
134  G4Exception("LBNERunAction::BeginOfRunAction", " ", RunMustBeAborted, mStr.c_str());
135 
136  return;
137  }
138 //
139  std::cout << spaces << "Successfully opened input ntuple \""
140  << theRunManager->GetNptInputFileName() << "\"" << std::endl;
141 //
142  theRunManager->SetNumberOfEventsLBNE(primaryGeneratorAction->GetNoOfPrimaries());
143  // Note there are public accessors in geant4 v4.9.6 inside the G4RunManager... but not in v4.9.3...
144 //
145  }
146  else
147  {
148  primaryGeneratorAction->SetProtonBeam();
149 
150  }
151 
152  }
153  //
154 
155  //
156  //If still ok to run open output file
157  //
158 
160  if(theRunManager -> GetCreateOutput())
161  if(!(analysis->CreateOutput())) {
162  std::ostringstream mStrStr;
163  mStrStr << "PROBLEM: FAILED TO OPEN OUTPUT NTUPLE. Fatal " << std::endl;
164  G4String mStr(mStrStr.str());
165  G4Exception("LBNERunAction::BeginOfRunAction", " ", RunMustBeAborted, mStr.c_str());
166  }
167 
168  if(theRunManager -> GetCreateDk2NuOutput()) {
169  if(!(analysis->CreateDk2NuOutput())) {
170  std::ostringstream mStrStr;
171  mStrStr << "PROBLEM: FAILED TO OPEN Dk2Nu OUTPUT NTUPLE. Fatal " << std::endl;
172  G4String mStr(mStrStr.str());
173  G4Exception("LBNERunAction::BeginOfRunAction", " ", RunMustBeAborted, mStr.c_str());
174  }
175  analysis->fillDkMeta();
176  }
177 
178  std::cout << std::endl;
179  const bool doLBNEQuickPiToNu = false; // default should be false!. It will slow down execution otherise.
180  if (doLBNEQuickPiToNu) {
182 
183  std::ostringstream fNameStr;
184  fNameStr << theRunManager->GetOutputNtpFileName() << "_";
185  fNameStr.setf(std::ios::right); fNameStr.fill('0'); fNameStr.width(3);
186  fNameStr << theRunManager->GetCurrentRun()->GetRunID();
187  std::string fName(fNameStr.str());
188  std::cerr << " QuickPitoNu file name " << fName << std::endl;
190  } // if usefull
191 
192  if (fDoComputeEDepInHorns) {
193  std::string aNameHH("HornAConceptDesignJan2017");
194  fG4MARSDeDxMap = new LBNFDeDxMap(aNameHH);
195  }
196 
197  std::cout << "LBNERunAction::BeginOfRunAction() - ...completed run initialization. " << std::endl;
198  std::cout << std::endl;
199 
200 
201 }
double fRMSEDepInArgonGasHorn1
void fillDkMeta()
double fRMSEDepInGraphite
bool fDoComputeEDepInHorns
constexpr auto const & right(const_AssnsIter< L, R, D, Dir > const &a, const_AssnsIter< L, R, D, Dir > const &b)
Definition: AssnsIter.h:104
LBNFDeDxMap * fG4MARSDeDxMap
LBNEPrimaryGeneratorAction * GetLBNEPrimaryGeneratorAction()
std::string string
Definition: nybbler.cc:12
void SetNumberOfEventsLBNE(int n)
bool GetUseMarsInput() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:45
static LBNEAnalysis * getInstance()
double fMeanEDepInArgonGasHorn2
G4bool OpenNtuple(G4String ntupleName)
double fRMSEDepInArgonGasHorn2
static LBNEQuickPiToNuVect * Instance()
double fMeanEDepInArgonGasHorn1
double fMeanEDepInGraphite
G4String GetOutputNtpFileName() const
void open(const std::string &prefix)
G4bool CreateDk2NuOutput()
bool GetUseFlukaInput() const
G4bool CreateOutput()
G4String GetNptInputFileName() const
QTextStream & endl(QTextStream &s)
void LBNERunAction::CheckMemoryUsage ( double  VMLimit) const

Definition at line 367 of file LBNERunAction.cc.

367  { // in kb (I think..)
368 
369 // http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c
370  using std::ios_base;
371  using std::ifstream;
372  using std::string;
373 
374  double vm_usage = 0.0;
375 // double resident_set = 0.0;
376 
377  // 'file' stat seems to give the most reliable results
378  //
379  ifstream stat_stream("/proc/self/stat",ios_base::in);
380 
381  // dummy vars for leading entries in stat that we don't care about
382  //
383  string pid, comm, state, ppid, pgrp, session, tty_nr;
384  string tpgid, flags, minflt, cminflt, majflt, cmajflt;
385  string utime, stime, cutime, cstime, priority, nice;
386  string O, itrealvalue, starttime;
387 
388  // the two fields we want
389  //
390  unsigned long vsize;
391  long rss;
392 
393  stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
394  >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
395  >> utime >> stime >> cutime >> cstime >> priority >> nice
396  >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest
397 
398  stat_stream.close();
399 
400 // long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
401 // Don't care about resident memory..
402 //
403  vm_usage = vsize / 1024.0;
404 // std::cerr << " Current memory usage " << vm_usage << std::endl;
405  if (vm_usage > VMlimit) {
406  std::cerr << " Current memory usage " << vm_usage << " Too much above limit " << VMlimit << std::endl;
407  sleep(10);
408  exit(2);
409  }
410 
411 }
std::string string
Definition: nybbler.cc:12
QTextStream & endl(QTextStream &s)
void LBNERunAction::CheckOKToRun ( )

Definition at line 335 of file LBNERunAction.cc.

336 {
337  //check the simulation
338  // Obsolte..
339  /*
340  G4bool knownSim = false;
341  const vstring_t simvec = fLBNEData -> GetListOfSimulations();
342  const G4String simulation = fLBNEData -> GetSimulation();
343 
344  for(vstring_t::const_iterator sit = simvec.begin(); sit != simvec.end(); ++sit)
345  {
346  if (simulation == *sit) { knownSim = true; break;}
347  }
348 
349  if(knownSim) { fLBNEData -> SetOKToRun(true);}
350  else
351  {
352  std::cout << "LBNERunAction::CheckOKToRun() - PROBLEM: Simulation "
353  << "\"" << simulation << "\"" << " unknown. Currently "
354  << "implemented simulations are " << std::endl;
355 
356  for(vstring_t::const_iterator sit = simvec.begin(); sit != simvec.end(); ++sit)
357  {
358  std::cout << " " << *sit << std::endl;
359  }
360  std::cout << std::endl;
361 
362  fLBNEData -> SetOKToRun(false);
363  }
364  */
365  //
366 }
void LBNERunAction::EndOfRunAction ( const G4Run *  aRun)

Definition at line 204 of file LBNERunAction.cc.

205 {
206 // const bool doLBNEQuickPiToNu = true; // default should be false!. Historical..
208 
209  LBNERunManager* theRunManager = dynamic_cast<LBNERunManager*>(G4RunManager::GetRunManager());
210  if(theRunManager->GetVerboseLevel() > 0)
211  {
212  std::cout << "LBNERunAction::EndOfRunAction() Called." << std::endl;
213  }
214 
215  const LBNESteppingAction *pStep = dynamic_cast<const LBNESteppingAction*>(theRunManager->GetUserSteppingAction());
216  std::cout << " End of Run. Number of tracks killed because stuck "
217  << pStep->GetNumTracksKilledAsStuck() << std::endl;
218 
219 
220 
221  G4String spaces = " ";
222  std::cout << std::endl;
223  std::cout << "LBNERunAction::EndOfRunAction() - Terminating Run "
224  << aRun->GetRunID() << "..." << std::endl;
225 
226  //
227  //Random number generator
228  //
229  G4String randomFile="rndm/endOfRun_";
230  char runN[4];
231  snprintf(runN, 4, "%03d",aRun->GetRunID());
232  randomFile.append(runN);
233  randomFile.append(".rndm");
234  CLHEP::HepRandom::saveEngineStatus(randomFile);
235  std::cout << spaces << "Closing Random Number generator... " << std::endl
236  << spaces << " Seed = " << CLHEP::HepRandom::getTheSeed() << std::endl
237  << spaces << " Random engine status saved in "<< randomFile << std::endl;
238 
239  //
240  //Close Input and Output Ntuple
241  //
242 
243  std::cout << spaces << "Closing Input File... " << std::endl;
244  LBNEPrimaryGeneratorAction* primaryGeneratorAction = (theRunManager->GetLBNEPrimaryGeneratorAction());
245 
246  if(primaryGeneratorAction)
247  {
248  primaryGeneratorAction->CloseNtuple();
249  }
250 
251  if(theRunManager -> GetCreateOutput())
252  {
253  std::cout << spaces << "Closing Output File... " << std::endl;
255  analysis->CloseOutput();
256  }
257  if(theRunManager -> GetCreateDk2NuOutput())
258  {
259  std::cout << spaces << "Closing Dk2Nu Output File... " << std::endl;
261  analysis->CloseDk2NuOutput();
262  }
263  //
265  int numEvts = aRun->GetNumberOfEvent();
266  fMeanEDepInGraphite /= numEvts;
267  double aa = fRMSEDepInGraphite;
268  fRMSEDepInGraphite = (std::sqrt(aa - fMeanEDepInGraphite*fMeanEDepInGraphite*numEvts)/(numEvts - 1));
269  std::cout << "LBNERunAction::EndOfRunAction .. Average energy deposition in target [GeV] "
270  << fMeanEDepInGraphite/CLHEP::GeV << " +- " << fRMSEDepInGraphite/CLHEP::GeV << std::endl;
271  }
273  int numEvts = aRun->GetNumberOfEvent();
274  fMeanEDepInArgonGasHorn1 /= numEvts;
275  double aa = fRMSEDepInArgonGasHorn1;
276  fRMSEDepInArgonGasHorn1 = (std::sqrt(aa - fMeanEDepInArgonGasHorn1*fMeanEDepInArgonGasHorn1*numEvts)/(numEvts - 1));
277  std::cout << "LBNERunAction::EndOfRunAction .. Average energy deposition in Argon Gas Horn1 [MeV] "
278  << fMeanEDepInArgonGasHorn1/CLHEP::MeV << " +- " << fRMSEDepInArgonGasHorn1/CLHEP::MeV << std::endl;
279  fMeanEDepInArgonGasHorn2 /= numEvts;
281  fRMSEDepInArgonGasHorn2 = (std::sqrt(aa - fMeanEDepInArgonGasHorn2*fMeanEDepInArgonGasHorn2*numEvts)/(numEvts - 1));
282  std::cout << "LBNERunAction::EndOfRunAction .. Average energy deposition in Argon Gas Horn2 [MeV] "
283  << fMeanEDepInArgonGasHorn2/CLHEP::MeV << " +- " << fRMSEDepInArgonGasHorn2/CLHEP::MeV << std::endl;
284  }
285 
286  if (fDoComputeEDepInHorns) {
287  std::string aDir("./");
288  const char* aDirGG = getenv("_CONDOR_SCRATCH_DIR");
289  if (aDirGG != 0) aDir = std::string(aDirGG);
290  fG4MARSDeDxMap->dumpASCII(aDir, aRun->GetNumberOfEvent());
291  std::cerr << " Before deleting fG4MARSDeDxMap " << std::endl;
292 // delete(fG4MARSDeDxMap);
293 // std::cerr << " After deleting fG4MARSDeDxMap " << std::endl;
294  }
295 
296  std::cout << "LBNERunAction::EndOfRunAction() - ...completed run termination. " << std::endl;
297  std::cout << std::endl;
298 
299 /*
300 
301  G4cout << G4endl;
302  G4cout << G4endl;
303  G4cout << "********************************************************************" << G4endl;
304  G4cout << "********************************************************************" << G4endl;
305  G4cout << "LBNERunAction::EndOfRunAction..." << G4endl;
306  G4cout << "********************************************************************" << G4endl;
307 
308  G4String randomFile="rndm/endOfRun_";
309  char runN[4];
310  sprintf(runN,"%04d",aRun->GetRunID());
311  randomFile.append(runN);
312  randomFile.append(".rndm");
313  CLHEP::HepRandom::saveEngineStatus(randomFile);
314  G4cout << " Random engine status at the end of the run saved in "<<randomFile<<G4endl;
315  LBNEAnalysis* analysis = LBNEAnalysis::getInstance();
316  analysis->finish();
317 
318  G4cout << "********************************************************************" << G4endl;
319  G4cout << "LBNERunAction::EndOfRunAction - Completed." << G4endl;
320  G4cout << "********************************************************************" << G4endl;
321  G4cout << "********************************************************************" << G4endl;
322  G4cout << G4endl;
323  G4cout << G4endl;
324 */
325 }
double fRMSEDepInArgonGasHorn1
bool fDoComputeEDepInArgonGas
double fRMSEDepInGraphite
bool fDoComputeEDepInHorns
LBNFDeDxMap * fG4MARSDeDxMap
LBNEPrimaryGeneratorAction * GetLBNEPrimaryGeneratorAction()
std::string string
Definition: nybbler.cc:12
void dumpASCII(const std::string &aDirectory, int nEvt)
Definition: LBNFDeDxMap.cc:344
void CloseDk2NuOutput()
static LBNEAnalysis * getInstance()
bool fDoComputeEDepInGraphite
double fMeanEDepInArgonGasHorn2
std::string getenv(std::string const &name)
Definition: getenv.cc:15
double fRMSEDepInArgonGasHorn2
static LBNEQuickPiToNuVect * Instance()
double fMeanEDepInArgonGasHorn1
double fMeanEDepInGraphite
int GetNumTracksKilledAsStuck() const
int GetVerboseLevel() const
QTextStream & endl(QTextStream &s)
void CloseOutput()
bool LBNERunAction::GetDebugLevel ( ) const
inline

Definition at line 46 of file LBNERunAction.hh.

46 { return fVerboseLevel; }
bool LBNERunAction::GetDoComputeEDepInArgonGas ( ) const
inline

Definition at line 54 of file LBNERunAction.hh.

bool fDoComputeEDepInArgonGas
bool LBNERunAction::GetDoComputeEDepInGraphite ( ) const
inline

Definition at line 48 of file LBNERunAction.hh.

bool fDoComputeEDepInGraphite
bool LBNERunAction::GetDoComputeEDepInHorns ( ) const
inline

Definition at line 62 of file LBNERunAction.hh.

62 { return fDoComputeEDepInHorns;}
bool fDoComputeEDepInHorns
LBNFDeDxMap* LBNERunAction::GetG4MARSDeDxMap ( ) const
inline

Definition at line 63 of file LBNERunAction.hh.

63 {return fG4MARSDeDxMap;}
LBNFDeDxMap * fG4MARSDeDxMap
void LBNERunAction::SetDebugLevel ( bool  t)
inline

Definition at line 45 of file LBNERunAction.hh.

45 { fVerboseLevel = t; }
void LBNERunAction::SetDoComputeEDepInArgonGas ( bool  t) const
inline

Definition at line 53 of file LBNERunAction.hh.

bool fDoComputeEDepInArgonGas
void LBNERunAction::SetDoComputeEDepInGraphite ( bool  t) const
inline

Definition at line 47 of file LBNERunAction.hh.

bool fDoComputeEDepInGraphite
void LBNERunAction::SetDoComputeEDepInHorns ( bool  t) const
inline

Definition at line 61 of file LBNERunAction.hh.

bool fDoComputeEDepInHorns
void LBNERunAction::storeEDepInArgonGas ( double  edepH1,
double  edepH2 
) const
inline

Definition at line 55 of file LBNERunAction.hh.

55  { /* not really... */
56  fMeanEDepInArgonGasHorn1 += edepH1;
57  fRMSEDepInArgonGasHorn1 += edepH1*edepH1;
58  fMeanEDepInArgonGasHorn2 += edepH2;
59  fRMSEDepInArgonGasHorn2 += edepH2*edepH2;
60  }
double fRMSEDepInArgonGasHorn1
double fMeanEDepInArgonGasHorn2
double fRMSEDepInArgonGasHorn2
double fMeanEDepInArgonGasHorn1
void LBNERunAction::storeEDepInGraphite ( double  edep) const
inline

Definition at line 49 of file LBNERunAction.hh.

49  { /* not really... */
50  fMeanEDepInGraphite += edep;
51  fRMSEDepInGraphite += edep*edep;
52  }
double fRMSEDepInGraphite
double fMeanEDepInGraphite

Member Data Documentation

bool LBNERunAction::fDoComputeEDepInArgonGas
mutableprivate

Definition at line 34 of file LBNERunAction.hh.

bool LBNERunAction::fDoComputeEDepInGraphite
mutableprivate

Definition at line 33 of file LBNERunAction.hh.

bool LBNERunAction::fDoComputeEDepInHorns
mutableprivate

Definition at line 41 of file LBNERunAction.hh.

LBNFDeDxMap* LBNERunAction::fG4MARSDeDxMap
mutableprivate

Definition at line 42 of file LBNERunAction.hh.

double LBNERunAction::fMeanEDepInArgonGasHorn1
mutableprivate

Definition at line 37 of file LBNERunAction.hh.

double LBNERunAction::fMeanEDepInArgonGasHorn2
mutableprivate

Definition at line 39 of file LBNERunAction.hh.

double LBNERunAction::fMeanEDepInGraphite
mutableprivate

Definition at line 35 of file LBNERunAction.hh.

double LBNERunAction::fRMSEDepInArgonGasHorn1
mutableprivate

Definition at line 38 of file LBNERunAction.hh.

double LBNERunAction::fRMSEDepInArgonGasHorn2
mutableprivate

Definition at line 40 of file LBNERunAction.hh.

double LBNERunAction::fRMSEDepInGraphite
mutableprivate

Definition at line 36 of file LBNERunAction.hh.

int LBNERunAction::fVerboseLevel
private

Definition at line 30 of file LBNERunAction.hh.

LBNERunActionMessenger* LBNERunAction::runMessenger
private

Definition at line 31 of file LBNERunAction.hh.


The documentation for this class was generated from the following files: