I am running a Monte Carlo simulation where I fill in a tree with isotopes names as string variables. All fine, but at the end of the simulation, instead of writing the large tree to the root file, I would like to draw/project the tree onto a TH1 histogram and write just the histogram to the file, so the final size of the root files can be kept small.
But I do not know the range of the string variables (isotopes names), so I cannot really pre-define a histogram. I am trying to do this in my class destructor (executed at the end of the simulation):
Thank you for your reply. Yes, within Root it is fine, I was using this in the past. But now I am trying to do it in my Monte Carlo code (Geant4), where I have access to root header files, the code knows about TTree and TH1F and creates the TTree object, and fills it and can write it to a root file at the end of the run. But the root file is huge, and there are many simulation runs to add the output files from …
So I was trying to use the same technique, which works inside the Root session, to draw the tree into a histogram and write only the histogram to the root file at the end, without the tree object. But Geant4, while it knows about TTree and TH1F classes and objects, has no idea what “htemp” is. So I cannot use this method. Is it possible though to draw or project the tree containing strings to a histogram (outside root)?
Now I get this during the compilation, so not even running yet:
SteppingAction.cc:59:25: error: use of undeclared identifier ‘gPad’. The code knows and can use/fill/draw TTree and TH1F objects though.
I was hoping it would be possible to draw the tree into a TH1F histogram directly using those string variables… Probably not possible? With numbers/data it would be easy, as I could define a histogram with a large range, but for characters/stings…
Thank you. Now it compiled fine, but at the end of the run it crashed right at the line
TH1* htemp = (TH1*)gPad->FindObject("htemp");
which I tested with cout messages after each line. Well, I guess I should give up and live with the large tree objects. Thank you for all your replies and wanting to help with this.
If anything else comes to mind though, please let me know of course.
…
Graphics systems deleted.
Visualization Manager deleting…
G4 kernel has come to Quit state.
1
2
3
*** Break *** segmentation violation
Generating stack trace…
0x000000010b631269 in SteppingAction::~SteppingAction() (in g4root_ESS_isotopes) + 25
0x000000010f1cfc6b in G4SteppingManager::~G4SteppingManager() (in libG4tracking.dylib) (G4SteppingManager.cc:110)
0x000000010f1d9eea in G4TrackingManager::~G4TrackingManager() (in libG4tracking.dylib) (G4TrackingManager.cc:62)
0x000000010f127fb3 in G4EventManager::~G4EventManager() (in libG4event.dylib) (G4EventManager.cc:84)
0x000000010f0b340e in G4RunManagerKernel::~G4RunManagerKernel() (in libG4run.dylib) (G4RunManagerKernel.cc:283)
0x000000010f0b399e in G4RunManagerKernel::~G4RunManagerKernel() (in libG4run.dylib) (G4RunManagerKernel.cc:262)
0x000000010f0a58c7 in G4RunManager::~G4RunManager() (in libG4run.dylib) (G4RunManager.cc:224)
0x000000010f0a5a5e in G4RunManager::~G4RunManager() (in libG4run.dylib) (G4RunManager.cc:184)
0x000000010b61c4c3 in main (in g4root_ESS_isotopes) + 6595
0x00007fff8c3ce5ad in start (in libdyld.dylib) + 1
Cristians-iMac:ESS_isotopes-build cristian$
The crash is in SteppingAction indeed, but where the tree is used to produce the histogram. Without this, the root file is produced fine with the tree written to it. But these lines are in the Geant4 code indeed.