# RooFit in root 6.28.04

**URL:** <https://root-forum.cern.ch/t/roofit-in-root-6-28-04/55267>\
**Category:** Roofit and RooStats\
**Tags:** roofit\
**Created:** [June 12, 2023, 3:40pm UTC](https://root-forum.cern.ch/t/roofit-in-root-6-28-04/55267 "2023-06-12T15:40:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [June 12, 2023, 3:40pm UTC](https://root-forum.cern.ch/t/roofit-in-root-6-28-04/55267/1 "2023-06-12T15:40:33Z")

</div>

Hi experts on RooFit,  
I have recently upgraded my root to version 6.28.04 in the hope to get rid of some problems in RooFit. However, the opposite seems to be the problem. Two strange things now happen with my code that used to run (acceptably) smoothly on root 6.24.06. First of all, a canvas appears that has never been there before (it shows some of my data and tries to fit to it, but I have not even a clue why it appears). Secondly, when plotting the components of a `RooAddPdf` object they appear very weird (see picture). Yet the whole fit together looks normal.  
On a side note I would like to mentioned that I had problems installing root 6.28.04 and had to run cmake build with `-Druntime_cxxmodules=OFF`. I do not know if that could influence the result.  
Thanks,  
Emil  
[ExampleOfProblem.pdf](https://root-forum.cern.ch/uploads/short-url/yvzzlpB8xGipyh8aO93SzZkzfjb.pdf) (21.6 KB)

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [June 12, 2023, 10:49pm UTC](https://root-forum.cern.ch/t/roofit-in-root-6-28-04/55267/2 "2023-06-12T22:49:32Z")

</div>

Hello @Emil_R,

thanks for posting about this!

I don’t know how this could happen with the Canvas, maybe it’s not related to RooFit.

For the plot: it looks like a problem that is only related to RooFit plotting, not the model itself. Do you have the same problem when you try ROOT 6.26.10? And can you provide me with the files to reproduce the problem (at least the model definition)? Otherwise I’m afraid it’s hard to understand what is going on here.

Thanks!  
Jonas

---

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [June 13, 2023, 7:09am UTC](https://root-forum.cern.ch/t/roofit-in-root-6-28-04/55267/3 "2023-06-13T07:09:03Z")

</div>

Hi @jonas ,  
thank you for your answer! I have tried the same with the current home-brew distributed version (6.26.06) as I did not have 6.26.10 installed. The result is quite bad (the picture is attached). I will give you examples of my code, as the code itself is quite long.  
First I define the shifts I later use:

```auto
RooRealVar shiftSigStar("shiftSigStar","Shift of SigStar",StartShiftSigStar,MinShift,MaxShift);
    RooFormulaVar MassShiftedSigStar("MassShiftSigStar","Mass - shiftSigStar",RooArgSet(mass,shiftSigStar));

```

Then a scaling number for the components:

```auto
RooRealVar Var1520("InvMass1520","InvMass1520",Number1520,0,MaxNumber);

```

I convert my histograms to a RooDataHist (ListHist is a vector of TH1\*):

```auto
RooDataHist *Sim1405 = new RooDataHist("Sim1405","Simulation of 1405",mass,ListHist[1]);

```

I make Pdfs from them:

```auto
RooHistPdf Curve1405("Curve1405","Kurve 1405",MassShifted1405,mass,*Sim1405,0);

```

I plot the data I want to fit to on a RooPlot frame:

```auto
RooDataHist values("values","values",mass, Import(*RealHist));
values.plotOn(Massframe);

```

Then I define my whole Pdf:

```auto
Curves = new RooAddPdf("Curves", "Kurven",
                               RooArgList(Curve1405, Curve1520, CurveLam, CurveSigStar, CurveSig0,
                                          CurveLam0Pi0, *CurveBKG),
                               RooArgList(Var1405, Var1520, VarLam, VarSigStar, VarSig0, VarLamPi, VarBack));

```

Then I fit to the data (The values in Range make sense, I checked that):

```auto
Curves->fitTo(values,Range(LowRange, HighestVal(RealHist)));

```

Afterwards I set the shift to a multiple of the BinWidth of the Histos, as otherwise it would look very bad and the shift should be discrete:

```auto
shift1405.setVal(Clean(shift1405.getVal(),BW));

```

Lastly I plot the fit and the components like:

```auto
Curves->plotOn(Massframe, Range(0., 2000));
Curves->plotOn(Massframe,Name("Lam1520"),Components(Curve1520),LineStyle(kDashed),LineColor(kRed));

```

I hope this helps debugging the code. Please let me know, if you need any more information!  
Thanks,  
Emil

On a side note: In root 6.24 it worked, but I do not have it installed anymore and sadly did not save the plot. However, there it looked fine.

[ExampleProblem626.pdf](https://root-forum.cern.ch/uploads/short-url/nxnJDiwcfZuhv72WadSCKz4Bxsg.pdf) (33.3 KB)

---

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [June 13, 2023, 9:16am UTC](https://root-forum.cern.ch/t/roofit-in-root-6-28-04/55267/4 "2023-06-13T09:16:50Z")

</div>

Maybe it has something to do with Draw Options? I just realized that the RooCurve inherits from TGraph and has therefor Draw Options. So maybe the default Draw Options have changed with the root versions?  
Thanks,  
Emil

---

<div class="post-metadata">

**Author:** ![Emil\_R](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/emil_r/32/31255_2.png) [@Emil\_R](https://root-forum.cern.ch/u/Emil_R)\
**Post date:** [June 15, 2023, 7:05am UTC](https://root-forum.cern.ch/t/roofit-in-root-6-28-04/55267/5 "2023-06-15T07:05:11Z")

</div>

@Jonas sorry to ask again, but have there been any news on this?  
Thanks,  
Emil

---

<div class="post-metadata">

**Author:** ![jonas](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jonas/32/24756_2.png) [@jonas](https://root-forum.cern.ch/u/jonas)\
**Post date:** [June 15, 2023, 2:12pm UTC](https://root-forum.cern.ch/t/roofit-in-root-6-28-04/55267/6 "2023-06-15T14:12:49Z")

</div>

I’m aware of the general problem, but I didn’t expect it to look _that_ bad!

In this line:

```c++
Curves->fitTo(values,Range(LowRange, HighestVal(RealHist)));

```

What is the result of `HighestVal(RealHist)`? Is it the upper limit of the mass variable in RooFit, or higher? If it’s larger, then it would explain why the plotting goes that bad. I think if the fit range would be larger than the variable range, it messes up the sampling algorithm for making the plot and that’s why you get what you get. Maybe not including this `Range()` option in `fitTo()` does help? Or at least if you include it, make sure that the range is not larger than the range of x. If this doesn’t make things look better, I can try to think of other workarounds.

I also have created a GitHub issue to remind myself also to fix the underlying issue for the next ROOT release: [[RF] Plotting shifted RooHistPdfs doesn't go well · Issue #13030 · root-project/root · GitHub](https://github.com/root-project/root/issues/13030)

However, what I can’t see is that any of this worked in ROOT 6.24.06. Maybe my reproducer linked on GitHub is still different from your workflow in some important way?

PS: I see that we have already discussed about this some months ago, sorry that I forgot about the problem in the meantime. With the GitHub issue I opened now, I should not forget it again.

> [@How to implement a horizontal shift for RooHistPdf](https://root-forum.cern.ch/t/how-to-implement-a-horizontal-shift-for-roohistpdf/16787/6):
>
> Hi @RENATO_QUAGLIANI, thanks for your post! Indeed it would be better to use a RooFormulaVar, because the RooLinearVar is not battle-tested so much. I just thought that it’s not possible to use non-fundamental variables in the specific case of the RooHistPdf. But I remember now that this is not true! There is a [RooHistPdf constructor](https://root.cern.ch/doc/master/classRooHistPdf.html#a99fbb46807505e28d99e161298a42de1) that allows you to specify PDF variables and RooDataHist variables separately, so you should use that one. The code would look somewhat like this: // Helper func…

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [June 29, 2023, 2:12pm UTC](https://root-forum.cern.ch/t/roofit-in-root-6-28-04/55267/7 "2023-06-29T14:12:58Z")

</div>

Closed on June 29, 2023, 2:12pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
