Problems with merging multiple histos using THStack

Hey guys!I’m working on some histos in Root framework.
I’ve encountered the problem using THStack to join more histograms(13 of them) together into one final histogram.However,I always get one histogram in the final pdf file and I wonder why is that?(I suppose it’s the last one run.cpp file loops through).However they are not all joined,it seems that somehow other histos get replaced by the last one.I’m not really sure though,so please try to help out here guys.I think Analyzer.h and run.cpp are pretty much fine,there is probably something I’m doing wrong in Analyzer.C
I’m sending the code,
so if you can help me in any way,I’d really appriciate that!

run.cpp (1.1 KB)
Analyzer.C (7.6 KB)
Analyzer.h (121.0 KB)

Hi,

After fixing a few errors in your code, here is what it gives:


Is it what you’re looking for?

Cheers, Bertrand.

Yes actually!What a relief,could u tell me what those errors were about?
Ad tnx for ur reply and help

First you create two histograms with the same name:

   h1= new TH1F("h1","Histogram usporedbe",300,70,370);
   [...]
   h2= new TH1F("h1","Histogram usporedbe",300,70,370);

Then you should set different parameters than the default ones for random filling with the gauss function. For example:

   auto f1 = new TF1("f1", "gaus", 70.0, 370.0);
   f1->SetParameters(10.0, 220.0, 25.0);

   auto h1= new TH1F("h1","Histogram usporedbe",300,70,370);
   h1->FillRandom("f1",20000);
   [...]

But if you look at the output when running your code, you can see ROOT complaining about those errors :wink:

Cheers, Bertrand.

Actually,I just got information that all the histos look the same this way,while i should be getting THStack with different results.Dunno what to do here :confused:

Sorry, but I’m not sure to understand what you mean… If you fill all the TH1 with a Gaussian with the same parameters, then yes, they will obviously look similar…

OK, but how do you fill your histograms?

Using ZZMass,weight.That part is in loop function in Analyzer.C file,with all those if functions,line 45-70 i suppose

The ZZMass variable is not defined in your code…

Well its probably defined in some other files in my AnalyzerSkeleton,im getting fine pdf-s.Just need the code for THStack filling

The way it is none now should just work (since it works with the random filling…)

So i should just put none instead of gauss?

Gauss was simply and example using randomly filled histograms. You must fill your histograms with the real data

So if my data was weight or ZZMass,how would i fill them in THStack,using the code u showed me before?
Sorry if im annoying,just another alot of pressure,pls try to understand

You fill your TH1s with your data (you should know how to get your data and how to fill your histograms), and then you add them in the THStack, as it is already in your code.

Well isnt it just the code i sent in the first place,its not working somehow,only prints one hist

Well, there is not much more I can do, unless you provide a piece of code showing the problem (I solved the one you sent…)

In your Analyzer::Loop, you always fill just a single histogram (the one that corresponds to the given “Folder”), so all others are empty (and for each “Folder”, you recreate all histograms in your “run.cpp”).

Not sure if I follow,is that line 45 u are talking about?Any idea about fixing this problem?

Oh, sorry, I overlooked at the code… Will check and come back to you later…