I am trying to produce a two dimensional histogram.
It is booked as shown below.
#################
void qghbb::book() {
theFile = new TFile(“ndim.root”,“RECREATE”);
theFile->cd();
h2 = new TH2F(“h2”, “MD vs OpA”, 100, -1., 1., 100, 0., 1000.);
}
#################
And then it is filled by, h2->Fill(de1, de2);
There is no compiler error.
But it crashed exactly at this line during runtime.
The root file “ndim.root” is not created either.
Can anybody give me some hint to solve this problem?
The source code is embeded in a large program.
And it is difficult to make a simple macro file.
It would be nice if one can point out an obvious or possible mistake
in the code quoted.
The example file is quite useful though.
The line,
TFile theFile = (TFile)gROOT->FindObject(“ndim.root”);
seems to be the only place of suspect.
When I used this line instead of “TFile* theFile;” in my program,
there was an error message shown below.
###############################################
/afs/cern.ch/user/s/sro/sw/ORCA_8_7_1/src/Workspace/qgbbh.cpp:175: invalid in-class initialization of static data member of non-integral type `TFile*’
How can I implement this line in my C++ source code?
Thanks for the preparation of the sample program.
But it still has problem.
My program is the following.
########################
class qghbb : public EventAnalyser {
private:
void upDate(G3EventProxy* ev) {
if (ev != 0) analysis(ev);
}
void book(); //!< book the histograms
void hend(); //!< save the histograms to file
TFile* theFile;
TH2F *h2;
};
void qghbb::book() {
theFile = new TFile(“ndim.root”,“RECREATE”, “Demo ROOT file with histograms”);
// theFile->cd();
h2 = new TH2F(“h2”, “The Higgs Momentum Distribution as a
Function of the Opening Angle”, 100, -1., 1., 100, 0., 1000.);
}
void qghbb::hend() {
// theFile->cd();
theFile->Write();
theFile->Close();
}
void qghbb::analysis(G3EventProxy* ev) {
h2->Fill(de1, de2);
}
###############
The de1 was 0.64 and the de2 was 68.80.
But it crashed at the last line.
Is there anything wrong?
S.
That’s really difficult for me to help you more without a running example. I do not see anything wrong in the few lines you sent. May be somebody else in the forum will see the problem just looking at them … Personally I don’t…
Cheers, Olivier
it seems that, unless de1 and de2 are global variables, then it should not know what values they have. But since they are not pointer, there should be no problem…
Have you tried compiling the code with de1 and de2 replaced with actual numeric values (like 0.68 and 62.39) ? Does it still crash?
Have you tried doing some stuff with the .root file? Like a file->Print() for example?
Remember to close the file when you no longer need it… It’s standard C procedure and perhaps ROOT’s C++ is intelligent enough to deal with it, but you should create good habits.
This is a good point.
It once occurred to me to use numerical values for the de1 and de2.
But I didn’t try because the values should be changing each time
in the loop.
When I used the numerical values, it still crashed on the same line.
I haven’t tried doing any stuff with the .root file except filling a root tree
for one dimensional histograms only.
The root tree is successfully filled and resulted proper one dimensional histograms.