I would like to create an array of histograms (of variable length). Then after having created this array I would like to look for elements in it using histo name.
Using STL, I could do :
std::map hmap;
hmap[“h1”] = new TH1F(…);
hmap[“h2”] = new TH1F(…);
and filling histos like that
hmap[“h1”]->Fill(x1);
…
however std::map do not seem to work in interactive root sessions. Could you confirm ?
So an alternative solution could be to use a std::vector and a class method like GetHisto(TString histoname). But in this method I need to loop over vector elements to math names which is quite time consuming…
My question, do you have a quick alternative way to code that ?
[quote=“renaud”]Oups, of course I was meaning std::map( TString, TH1F )
[/quote]
Hopefully you meant
std::map < TString, TH1F* >
I have used std::map < std::string, void* > histMap;
and that seemed to work (I can’t remember why I used void* and then cast it to TH1F*…) in cint.
Charles
p.s. Rene just pointed out in another message that you can use '<'s if you click “Disable HTML in this post”
[quote=“pcanal”]You probably need to generate the dictionary for this stl container before being able to use it properly from the command line.
[/quote]
You don’t need to if you want to use an interpreted script (at least not in Root 4). See attached script. histWithMap.C (5.16 KB)