diff --git a/doc/musrSim.pdf b/doc/musrSim.pdf index 94ee1ad..5962a05 100644 Binary files a/doc/musrSim.pdf and b/doc/musrSim.pdf differ diff --git a/doc/musrSim.tex b/doc/musrSim.tex index d58f55e..b1f5da9 100644 --- a/doc/musrSim.tex +++ b/doc/musrSim.tex @@ -126,6 +126,7 @@ in the macro file: By default, the output of the simulation is written out in the subdirectory ``data'' with the name ``musr\_RUNNUMBER.root''. +(Note that the execution of the simulation can be terminated gently by creating a file ``RUNNUMBER.stop'' in the working directory.) \section{Conventions} The default units of the musrSim in both the macro file (RUNNUMBER.mac) and in the Root tree @@ -766,7 +767,10 @@ Three special volumes ``Target, M0, M1 and M2''. the job will be terminated gently if its physical execution time exceeds \emph{timeMax}. Note that the units of \emph{timeMax} are seconds, - and the default value is set to 85000\,s (23\,hours, 37\,minutes). + and the default value is set to 85000\,s (23\,hours, 37\,minutes).\\ + (Note that the simulation can also be terminated gently by creating a file + ``RUNNUMBER.stop'' in the working directory, where RUNNUMBER matches the + run number specified in the name of the macro file.) \end{description} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{Output root tree variables} diff --git a/include/musrParameters.hh b/include/musrParameters.hh index eb33d84..8c0efb2 100644 --- a/include/musrParameters.hh +++ b/include/musrParameters.hh @@ -34,6 +34,7 @@ class musrParameters { static musrParameters* GetInstance(); static G4String mySteeringFileName; // name of the steering file (e.g. the *.mac file) + static G4String myStopFileName; // name of the stop file (e.g. the *.stop file), which will stop the run if it is created static G4bool storeOnlyEventsWithHits; // variable specifying whether to store interesting // or all events into the ROOT tree. (default = true) static G4int storeOnlyEventsWithHitInDetID; // simillar to "storeOnlyEventsWithHits". The event is stored diff --git a/src/musrEventAction.cc b/src/musrEventAction.cc index af4edff..9130b9b 100644 --- a/src/musrEventAction.cc +++ b/src/musrEventAction.cc @@ -30,11 +30,14 @@ #include "G4ios.hh" #include "G4TransportationManager.hh" #include "G4FieldManager.hh" +#include "musrParameters.hh" #include "musrRootOutput.hh" #include "musrErrorMessage.hh" #include "musrSteppingAction.hh" #include "F04GlobalField.hh" -#include "G4RunManager.hh" // needed just in order to save random number generator seed +#include "G4Run.hh" +#include "G4RunManager.hh" +#include //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -75,6 +78,13 @@ void musrEventAction::EndOfEventAction(const G4Event* evt) { // cout << ":." << flush; long thisEventNr = (long) evt->GetEventID(); + // write out the root tree: + musrRootOutput* myRootOutput = musrRootOutput::GetRootInstance(); + G4RunManager* fRunManager = G4RunManager::GetRunManager(); + myRootOutput->SetRunID(fRunManager->GetCurrentRun()->GetRunID()); + myRootOutput->SetEventID(fRunManager->GetCurrentEvent()->GetEventID()); + myRootOutput->FillEvent(); + // get number of stored trajectories G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer(); G4int n_trajectories = 0; @@ -94,6 +104,19 @@ void musrEventAction::EndOfEventAction(const G4Event* evt) { G4RunManager* fRunManager = G4RunManager::GetRunManager(); fRunManager->AbortRun(true); } + + // Stop the run, if the user wished that (by creating a file "RUNNUMBER.stop" + struct stat stFileInfo; + if (stat((musrParameters::myStopFileName).c_str(),&stFileInfo)==0) { + // Stop the execution of the run - the file "RUNNUMBER.stop" was found + remove((musrParameters::myStopFileName).c_str()); + char eMessage[200]; + sprintf(eMessage,"musrEventAction::EndOfEventAction(): Request to stop the run was found (%s) ==> RUN STOPPED",musrParameters::myStopFileName.c_str()); + musrErrorMessage::GetInstance()->musrError(WARNING,eMessage,false); + G4RunManager* fRunManager = G4RunManager::GetRunManager(); + fRunManager->AbortRun(true); + } + if (thisEventNr != 0 and thisEventNr%nHowOftenToPrintEvent == 0) { time_t curr=time(0); //char * ctime(const time_t * tp); diff --git a/src/musrParameters.cc b/src/musrParameters.cc index 40ba6b5..d389da2 100644 --- a/src/musrParameters.cc +++ b/src/musrParameters.cc @@ -30,6 +30,12 @@ musrParameters::musrParameters(G4String steeringFileName) pointerToParameters = this; boolG4RegionRequested = false; mySteeringFileName = steeringFileName; + myStopFileName = mySteeringFileName; + // myStopFileName.replace(myStopFileName.end()-2,myStopFileName.end(),"stop"); + // Int_t lengthOfFileName= + // myStopFileName.replace(3,5,"stop"); + myStopFileName.replace(myStopFileName.length()-3,myStopFileName.length()-1,"stop"); + // Read in the parameters, which have to be known before the detector construction is run // (and therefore the parameters can not be read in in the musrDetectorConstruction.cc class). @@ -98,7 +104,8 @@ musrParameters* musrParameters::GetInstance() { return pointerToParameters; } -G4String musrParameters::mySteeringFileName="Unset"; +G4String musrParameters::mySteeringFileName="Unset"; +G4String musrParameters::myStopFileName="Unsetblablabla034tdk40928jfmfnakfh921djf02UNSET"; G4bool musrParameters::storeOnlyEventsWithHits=true; G4int musrParameters::storeOnlyEventsWithHitInDetID=0; G4double musrParameters::signalSeparationTime=100*nanosecond; diff --git a/src/musrRootOutput.cc b/src/musrRootOutput.cc index 2acaf24..145dbae 100644 --- a/src/musrRootOutput.cc +++ b/src/musrRootOutput.cc @@ -25,6 +25,7 @@ #include "G4RunManager.hh" #include "G4Run.hh" #include "musrErrorMessage.hh" +#include "musrParameters.hh" //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... @@ -310,7 +311,9 @@ void musrRootOutput::FillEvent() { htest5->Fill(atan2(posIniMomy_t,posIniMomx_t)); htest6->Fill(atan2(sqrt(posIniMomx_t*posIniMomx_t+posIniMomy_t*posIniMomy_t),posIniMomz_t)); if (weight_t>0.) { - rootTree->Fill(); + if ( !((musrParameters::storeOnlyEventsWithHits)&&(det_n<=0)) ) { + rootTree->Fill(); + } } } diff --git a/src/musrScintSD.cc b/src/musrScintSD.cc index d1c1349..5cd5697 100644 --- a/src/musrScintSD.cc +++ b/src/musrScintSD.cc @@ -29,8 +29,6 @@ #include "G4ios.hh" #include // needed for the sort() function #include "G4VProcess.hh" // needed for the degugging message of the process name -#include "G4RunManager.hh" -#include "G4Run.hh" #include "musrParameters.hh" #include "musrErrorMessage.hh" #include "musrSteppingAction.hh" @@ -154,10 +152,6 @@ void musrScintSD::EndOfEvent(G4HCofThisEvent*) { // Positron_momentum_already_stored=0; musrRootOutput* myRootOutput = musrRootOutput::GetRootInstance(); - G4RunManager* fRunManager = G4RunManager::GetRunManager(); - myRootOutput->SetRunID(fRunManager->GetCurrentRun()->GetRunID()); - myRootOutput->SetEventID(fRunManager->GetCurrentEvent()->GetEventID()); - G4int NbHits = scintCollection->entries(); if (myStoreOnlyEventsWithHits) { @@ -373,8 +367,6 @@ void musrScintSD::EndOfEvent(G4HCofThisEvent*) { } } //end "if (NbHits>0)" - - myRootOutput->FillEvent(); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......