I have a weird problem trying to fill a histogram. When the histogram is defined in BeginofRunAction via
G4double Xmax = 15.; G4double Ymax = 15.; G4int Xbins = 30; G4int Ybins = 30; analysisManager->CreateH2("gen_events","Generated Events", Xbins, -Xmax, +Xmax, Ybins, -Ymax, +Ymax);
all is fine. The histogram is written to the root file. But whenever I use variables from the code to define the histogram bounds, e.g.
G4double Xmax = MuDetector->GetWorld_sizeX()/2.;
G4double Ymax = MuDetector->GetWorld_sizeY()/2.;
G4int Xbins = int(2.*Xmax);
G4int Ybins = int(2.*Ymax);
there is no more histogram in the root file even though G4cout tells me the parameters I am passing to CreateH2 are the same in both cases.
I can also test the histogram contents in EndofRunAction, with
G4cout << " mean_x = " << G4BestUnit(analysisManager->GetH2(0)->mean_x(), “Length”)<<G4endl;
I get some statistics in the first case and a segfault in the second (histogram does not exist)
*** G4Exception : Analysis_W011
issued by : G4THnManager::GetH2
histogram 0 does not exist.
What am I doing wrong???