Get histogram from map<double, TH1D*>

Dear experts,

I want to get an histogram from a map<double, TH1D*>, but I have a *** Break *** segmentation violation, I’m using [*], do you know what is wrong?

Regards

[*]
void code(){

TH1D* h1 = (TH1D*)histKey->ReadObj();

TH1D* hrspSel;

map<double, TH1D*> mapKsFit;
mapKsFit[1.2]=h1;

if(mapKsFit.size()!=0) hrspSel= (TH1D*) mapKsFit.rbegin()->second->DrawClone(); // Break statement!!

}

Hi,

it would be useful to know what you do after this line

TH1D* h1 = (TH1D*)histKey->ReadObj();

Are you by chance closing the file?

Cheers,
Danilo

Dear Danilo,

after TH1D* h1 = (TH1D*)histKey->ReadObj();

h1 has an histogram and I’m doing many things like:

hrsp->Rebin(4);
hrsp->SetBinContent(i, 0.5);
hrsp->SetBinError(i, 0.5);

everything worked well except for the mapping procedure.

The map contain a TH1D* as second and I do not see why:
hrspSel= (TH1D*) mapKsFit.rbegin()->second->DrawClone();
do not work.

Regards

Hi,

it looks something is going out of scope.
Could you share a working script (and input ROOT file if necessary) to reproduce the problem?

Danilo

Dear Danilo,

thank you for your help. Actually I was deleting the “parent pointor” so the copy of the parent pointor in the map couldn’t find it …

Regards