Getting detector information inside the program when defined in the mac file

Dear G4 team,

I have a program in which I define some detectors such as:

/score/create/boxMesh scoring
/score/mesh/boxSize 200. 200. 75. cm
/score/mesh/nBin 40 40 15

/score/quantity/cellFlux score_e1
/score/filter/particle elecfilter1 e-
/score/filter/particleWithKineticEnergy range1 1. 100. keV e- 

/score/quantity/cellFlux score_e2
/score/filter/particle elecfilter2 e-
/score/filter/particleWithKineticEnergy range2 100. 400. keV e-

I would like inside the program to get this information in particular, to get the mesh sizes and number of bins, and to get the scores energies and particle filters

Until now, I am trying to go through the detector as follows:

   G4SDManager* SDMan = G4SDManager::GetSDMpointer();
    for(int i=0; i < SDMan->GetHCtable()->entries(); i++)
    {
        G4cout << i << " "
               << SDMan->GetHCtable()->GetSDname(i) << " "
               << SDMan->GetHCtable()->GetHCname(i) << " "
               << SDMan->FindSensitiveDetector(SDMan->GetHCtable()->GetSDname(i))->GetCollectionName(i) << " "
               << SDMan->FindSensitiveDetector(SDMan->GetHCtable()->GetSDname(i))->GetFilter()<< " "
               <<G4endl;
    }

indeed, SDMan->GetHCtable()->GetSDname(i) returns “scoring” and SDMan->GetHCtable()->GetHCname(i) returns “score_e1” and “score_e2” but I am not able to get the energies and particles filter.

My questions are then:

  1. How can I access the mesh characteristics? What is the class ?
  2. How can I get the filters characteristics for each of the scores?

Thank you

So GetFilter() returns a pointer to a G4VSDFilter, which doesn’t have any interface to the details, just a GetName() function. It looks like you’ve defined both a “particle” filter (G4SDParticleFilter) and a “particle with kinetic energy” filter (G4SDParticleWithEnergyFilter). You might try doing a dynamic_cast to those types and see if the show() function does anything useful for you.

Thank you mkelsey. Indeed, the show() method provides the information but is just writing it in the terminal. I cannot get the information in some variables since, as you mentioned, there is no interface. Do you think there is another way to store the information in some variables?

[quote=“froz1233, post:3, topic:9758”]
I cannot get the information in some variables since, as you mentioned, there is no interface.[/quote]

That’s what it looked like to me – that the detailed configuration is in data members, but there are no accessors to get back that configuration. And show() is not useful here because it writes directly to G4cout internally, rather than acting like operator<<() (with the latter, you could write to a stringstream, and then parse it by hand).

Yeah, but I think it would kind of ugly. You could write your own Messenger with UI commands in place of the existing /score/filter/... commands. What you’d do is capture the argument values into your own data buffer, then construct in a long string the original /score/filter/... command with all the arguments, and invoke that using a UImanager->ApplyCommand() call.

You’d probably have to “override” the /score/quantity commands as well, so that you could capture the name of the SD as well, and associate the subsequent filters to that name.

We don’t use the built-in scorers in our experiment. Instead we have SDs and set selection criteria in them directly, so our own UI commands do pass values that we can access in the code in the moment, rather than having to try “recovering” them.