G4ScoringCylinder with inner radius

Hello,
I would like to create a mesh detector from the command-based scoring in the form of a thin cylindrical wall. For this purpose I used these commands:

/score/create/cylinderMesh CylinderMesh1
/score/mesh/cylinderSize 42. 70. mm
/score/mesh/cylinderRMin 41.999 mm
/score/mesh/nBin 1 14 4

But I found this message in the output:

/score/create/cylinderMesh CylinderMesh1
/score/mesh/cylinderSize 42. 70. mm
/score/mesh/cylinderRMin 41.999 mm

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : DigiHitsUtilsScoreVScoringMesh000
      issued by : G4VScoringMesh::SetSize()
   Mesh size has already been set and it cannot be changed.
  This method is ignored.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

/score/mesh/nBin 1 14 4

And from the results and from the list of detectors it can be seen, that the cylinder detector was made as a full cylinder:

G4ScoringCylinder : CylinderMesh1 --- Shape: Cylindrical mesh
 Size (Rmin, Rmax, Dz): (0, 4.2, 7) [cm]
 Angle (start, span): (0, 360) [deg]
# of segments: (14, 4, 1)

In the part of G4VScoringMesh, from where the warning is, I found this:

void G4VScoringMesh::SetSize(G4double size[3])
{
  if(!sizeIsSet)
  {
    sizeIsSet = true;
    for(int i = 0; i < 3; i++)
    {
      fSize[i] = size[i];
    }
  }
  else
  {
    G4String message = "   Mesh size has already been set and it cannot be changed.\n";
    message += "  This method is ignored.";
    G4Exception("G4VScoringMesh::SetSize()",
                "DigiHitsUtilsScoreVScoringMesh000", JustWarning, message);
  }
}

So it seems, that once some numbers are added to the description of dimensions of the mesh detector, no other details cannot be added.
Could you please advice me, how to correct this?

Thank you,
Marek

try to set the minR first, and then issue the cylinderSize command.

the Size command reads the minR entry: geant4/G4ScoringMessenger.cc at 271d2ffb2bd0a2aa26c4d15bc5e99e50f49cd232 · Geant4/geant4 · GitHub

I already tried that, but I got the same error:

/score/mesh/cylinderRMin 41.999 mm
/score/mesh/cylinderSize 42. 70. mm

-------- WWWW ------- G4Exception-START -------- WWWW -------
*** G4Exception : DigiHitsUtilsScoreVScoringMesh000
      issued by : G4VScoringMesh::SetSize()
   Mesh size has already been set and it cannot be changed.
  This method is ignored.
*** This is just a warning message. ***
-------- WWWW -------- G4Exception-END --------- WWWW -------

/score/mesh/nBin 1 14 4

And than because of missing value in the dimensions of cylinder, I got this error:

-------- EEEE ------- G4Exception-START -------- EEEE -------
*** G4Exception : GeomSolids0002
      issued by : G4Tubs::G4Tubs()
Negative Z half-length (0) in solid: CylinderMesh1_mesh0
*** Fatal Exception *** core dump ***
 **** Track information is not available at this moment
 **** Step information is not available at this moment

-------- EEEE -------- G4Exception-END --------- EEEE -------

Hi @Marek Have you been able to solve this error?

Yes, I had to change the source code of Geant4.
In /source/digits_hits/utils/src/G4ScoringMessenger.cc I changed:

  mCylinderSizeCmd = new G4UIcommand("/score/mesh/cylinderSize", this);
  mCylinderSizeCmd->SetGuidance("Define size of the scoring mesh.");
  mCylinderSizeCmd->SetGuidance("R   Dz  unit");
  param = new G4UIparameter("R", 'd', false);
  param->SetParameterRange("R>0");
  mCylinderSizeCmd->SetParameter(param);
  param = new G4UIparameter("Dz", 'd', false);
  param->SetParameterRange("Dz>0");
  mCylinderSizeCmd->SetParameter(param);
  param = new G4UIparameter("unit", 's', true);
  param->SetDefaultUnit("mm");
  mCylinderSizeCmd->SetParameter(param);

to this:

  mCylinderSizeCmd = new G4UIcommand("/score/mesh/cylinderSize", this);
  mCylinderSizeCmd->SetGuidance("Define size of the scoring mesh.");
  mCylinderSizeCmd->SetGuidance("Rmin R   Dz  unit");
  param = new G4UIparameter("Rmin", 'd', false);
  param->SetParameterRange("Rmin>=0");
  mCylinderSizeCmd->SetParameter(param);
  param = new G4UIparameter("R", 'd', false);
  param->SetParameterRange("R>0");
  mCylinderSizeCmd->SetParameter(param);
  param = new G4UIparameter("Dz", 'd', false);
  param->SetParameterRange("Dz>0");
  mCylinderSizeCmd->SetParameter(param);
  param = new G4UIparameter("unit", 's', true);
  param->SetDefaultUnit("mm");
  mCylinderSizeCmd->SetParameter(param);

and this part:

            if(command == mCylinderSizeCmd)
            {
              G4double vsize[3];
              vsize[0]     = (mesh->GetSize()).x();
              vsize[1]     = StoD(token[0]);
              vsize[2]     = StoD(token[1]);
              G4double unt = mCylinderSizeCmd->ValueOf(token[2]);
              vsize[1] *= unt;
              vsize[2] *= unt;
              mesh->SetSize(vsize);
            }

with this:

            if(command == mCylinderSizeCmd)
            {
              G4double vsize[3];
              vsize[0]     = StoD(token[0]);
              vsize[1]     = StoD(token[1]);
              vsize[2]     = StoD(token[2]);
              G4double unt = mCylinderSizeCmd->ValueOf(token[3]);
              vsize[0] *= unt;
              vsize[1] *= unt;
              vsize[2] *= unt;
              mesh->SetSize(vsize);
            }

So now you have to always put 4 values to /score/mesh/cylinderSize - Rmin, Rmax, Dz and unit.

1 Like

Many thanks @Marek :smiley: