Usage of Accumulables

I am a bit confused about how to use accumulables. It’s not clear to me how to access and modify accumulables, for example, I want to increment a counter every time a particle leaves a specific volume per event in stepping action.

I tried to do something like this:

G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance();
auto test = accumulableManager->GetAccumulable(“PMT1”);
G4cout <GetValue()<<"\n";
but this gives me either -1408678848 or 1701996900


Usage of accumulable is demonstrated in basic examples B1 and B3a.

See also below a working example how to access an accumulable via its name and update its value (I tried this code in B1::RunAction class).

In RunAction() ctor:

 // Create another accumulable with a name (in 
 accumulableManager->CreateAccumulable<G4double>("EdepBis", 0.);

Then in BeginOfRunAction()

  auto edepBis = accumulableManager->GetAccumulable<double>("EdepBis");
            // Note that the return value is of pointer type
  G4cout << "edepBis: " << edepBis->GetValue() << G4endl;
  G4cout << "edepBis++: " << accumulableManager->GetAccumulable<double>("EdepBis")->GetValue() << G4endl;

  auto& edepBisRef = (*accumulableManager->GetAccumulable<double>("EdepBis"));
            // Get accumulable as reference
  G4cout << "edepBisRef: " << edepBisRef.GetValue() << G4endl;
  G4cout << "edepBisRef++: " << accumulableManager->GetAccumulable<double>("EdepBis")->GetValue() << G4endl;

The above code gives then the following output:

### Run 1 starts.
edepBis: 0
edepBis++: 1
edepBisRef: 1
edepBisRef++: 2
--> Event 0 starts.

Best regards,