Set double for number of primary particles

Hello, I should simulate 6.2E10 primary particles, but running the simulation it says

GWT1 > Using Root
G4WT0 > Using Root
digit length exceeds
62500000000: integer expected.
***** Illegal parameter (0) </run/beamOn 62500000000> *****

***** Batch is interrupted!! *****

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : UIMAN0123
      issued by : G4UImanager::ApplyCommand
Command aborted (400)
Error code : 400
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

Then, it looks like that
/run/beamOn number

number should be an integer value, i.e. the maximum value is 2147483647 …is there a way to change to double?

No. The count of number of events is an integer (G4int). You can simulate an arbitrary number of event by way of multiple runs (i.e., multiple /run/beamOn commands). In your code, you would need to either include the run number (G4Run::GetRunID()) in your output filename, or ensure that the output is kept open and accumulated across runs.

You may also want to have your code set a unique random seed at the start of (or before) each run.

Thank you @mkelsey how to can I do that?
I deleted the line
analysisManager->CloseFile();

but it didn’t work

You would do it with multiple /run/beamOn lines in a single macro. That way you’re doing multiple runs in a single job:

/run/beamOn 2000000000
/run/beamOn 2000000000
/run/beamOn 2000000000

etc. If you want to do separate jobs (for instance, submitting to multiple nodes on a compute farm), then you should make sure that your macro or code specifies a unique filename for each job.

Yes, I did that, but it re-writes the Root file at each run (so I lose data from previous runs and I’ve only data from the last one)…
Instead I should update it…

This is the runaction

B1RunAction.cc (13.2 KB)

I tried deleting the line

analysisManager->CloseFile();

to not close it but it didn’t work

I see that I can creat multiple root file in this way,

/analysis/setFileName myrun1

but I prefere to have only one and update it …isn’t it possible?

If you’re getting a new file each time, then you should look in your code and see if you are telling the analysis manager to create a new file. You might also read the documentation, look at help within Geant4 (interactively), or look at the header file (G4VAnalysisManager.hh) to see if there is functionality to keep the file open.

No…i create a file each time because I wrote

/analysis/setFileName myrun1
/run/beamOn 100
/analysis/setFileName myrun2
/run/beamOn 100
/analysis/setFileName myrun3
/run/beamOn 100

following this @ivana’s message B1 write out from multiple events - #2 by psaxioti

if I don’t write /analysis/setFileName myrun1, /analysis/setFileName myrun2, /analysis/setFileName myrun3 the simulation overwrite the root file each time…

:frowning: That’s unfortunate. It would be nice to be able to open the file at the start of the job (not each run), and accumulate across multiple runs within the job.

If you’re using the ROOT output, at least you can use TChain in your analysis code, and process all your files in one shot.

Yes, I think I will merge the Root files…

Btw…the supervisor asked me to simulate 6,25*10^10 …but I don’t know if it really possible (I mean the needed time of simulating so much events)…

Hello,

You can open/close analysis file only for a given run ID :

In BeginOfRunAction():

  if ( run->GetRunID() == 0 ) {
    analysisManager->OpenFile(fileName);
    G4cout << "Using " << analysisManager->GetType() << G4endl;
  }

and then in EndOfRunAction():

  if ( run->GetRunID() == 2 ) {
    analysisManager->Write();
    analysisManager->CloseFile();
  }

Then the histograms/ntuples will be collected over three runs and saved in a single file open in the first run (with ID = 0).

Best regards,

HEllo @ivana writing

if ( run->GetRunID() == 0 ) {
  analysisManager->OpenFile();
  }

I get the error

C:\B1\src\B1RunAction.cc(246,9): error C2065: 'run': identificatore non dichiarato [C:\B1\B1-build\exampleB1.vcxproj]

where and how did you define “run”?

THis is the run action
B1RunAction.cc (13.2 KB)

“run” is the argument of the BeginOfRunAction() function:

void RunAction::BeginOfRunAction(const G4Run* run)
{
  // Get analysis manager
  auto analysisManager = G4AnalysisManager::Instance();

  // Open an output file
  if ( run->GetRunID() == 0 ) {
    analysisManager->OpenFile(fileName);
    G4cout << "Using " << analysisManager->GetType() << G4endl;
  }
}
1 Like

Ok, in my Runaction I had only

void B1RunAction::BeginOfRunAction(const G4Run*)

now I replaced it by

void B1RunAction::BeginOfRunAction(const G4Run* run) and it worked! thank you!

Sorry @ivana one more question please.

I wrote
if ( run->GetRunID() == 31 ) {

because I splitted the 6.25*10^10 events into 32 bunches… to have a general simulation, I would write something like

if ( run->GetRunID() == fnumbunch ) {

where fnumbunch = numbunch and numbunch is defined in the main file example B1.cc

I’m able to send values from exampleB1.cc to detectorconstruction or steppingaction by the lines

runManager->SetUserInitialization(new B1DetectorConstruction(CircularTargetFlag, MeniscusTargetFlag, HourglassTargetFlag, LinearHourglassTargetFlag, DummyTargetFlag, SecondTargetFlag, RegeneratorFlag, VacuumChambFlag, PlastScintFlag, WorldMat, TargMat1, TargMat2, SecTarPos, pRMin, pRMax, pDz, pSPhi,pDPhi,pMenRmax1, pMenRmax2, zMenOrb1, zMenOrb2, AngRot1, AngRot2, pHourRmax, zHourOrb1, zHourOrb2, pxSemiAxis, pySemiAxis, pzSemiAxis, pzBottomCut, pzTopCut, zLinHourEllips1, zLinHourEllips2, pDzDummy, zFirDummyPos, zSecDummyPos, AngMagX, pRMaxMag, pDzMag, zMagPos, pRMaxTung, pDzTung, zTungstenPos, world_sizeX, world_sizeY, world_sizeZ, pRMaxCE, pRMaxCI, pDzCE, pDzCI, Scint_sizeX, Scint_sizeY, Scint_sizeZ,xScintPos,zScintPos,betaScint));

runManager->SetUserInitialization(new B1ActionInitialization(PrimaryPositronElectronExitFlag, SecondaryPhotonsExitFlag, SecondaryMuonsExitFlag, SecondaryPosEleExitFlag, PrimaryPositronElectronEnteringFlag, RegeneratedPositronFlag, KillNoGammaFlag, ParticlePlastScintFlag, TargExt));

but I don’t know how to send values to the RunAction…

You can pass the value either via ActionInitialization class, which is created in main(), or a better solution would be to define a command, that can be then used from anywhere in your code or from a macro. For this, you can take a look either in B2 example and its DetectorMessenger class or in B5 example, eg. in PrimaryGeneration class, where the commands are defined with use of G4GenericMessenger.

Thank you @ivana, I will check!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.