# Issues in normalization in ranges and projections in 2d Model

**URL:** <https://root-forum.cern.ch/t/issues-in-normalization-in-ranges-and-projections-in-2d-model/62925>\
**Category:** Roofit and RooStats\
**Tags:** graphics, root\
**Created:** [February 12, 2025, 2:16pm UTC](https://root-forum.cern.ch/t/issues-in-normalization-in-ranges-and-projections-in-2d-model/62925 "2025-02-12T14:16:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Elia\_Giulio\_Grandoni](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/elia_giulio_grandoni/32/36714_2.png) [@Elia\_Giulio\_Grandoni](https://root-forum.cern.ch/u/Elia_Giulio_Grandoni)\
**Post date:** [February 12, 2025, 2:16pm UTC](https://root-forum.cern.ch/t/issues-in-normalization-in-ranges-and-projections-in-2d-model/62925/1 "2025-02-12T14:16:47Z")

</div>

Dear experts,

I am trying to do a 2d unbinned fit in subranges. I did follow the tutorial [multirangefit](https://root.cern/doc/v628/rf312__multirangefit_8C.html) to do it and the result seem to be reasonable with the another independent result. For instance here is the relevant part of the code about it:

```auto
/*some variable and pdf definitions*/

// Create the 2d acc and rmd model
RooProdPdf model_acc((string(pdf_acc->GetName()) + "_2d").c_str(), (string(pdf_acc->GetName()) + "_2d").c_str(), RooArgList(*pdf_acc, *pdf_cte));
RooProdPdf model_rmd((string(pdf_rmd->GetName()) + "_2d").c_str(), (string(pdf_rmd->GetName()) + "_2d").c_str(), RooArgList(*pdf_rmd, *pdf_gaus));

// Create the variables for rmd and acc
RooRealVar nRmd("nRmd", "nRmd", 1000, 0, 5000);
RooRealVar nAcc("nAcc", "nAcc", 500, 0, 5000);

// Create the 2d pdf
RooAddPdf model((model_name + "_2d").c_str(), (model_name + "_2d").c_str(), RooArgList(model_rmd, model_acc), RooArgList(nRmd, nAcc));

/*some other stuff*/

time->setRange(time_min, time_max);
time->setRange("fullRange", time_min, time_max);
time->setRange("leftSide", time_min, time_max);
time->setRange("rightSide", time_min, time_max);
minv->setRange(minv_min, minv_max);
minv->setRange("fullRange", minv_min, minv_max);
minv->setRange("leftSide", minv_min, -84);
minv->setRange("rightSide", 121, minv_max);

/*some other stuff*/

// Fit the model to the data
RooFitResult *result = model.fitTo(data, Save(), Range("leftSide,rightSide"), Strategy(2));
model.removeStringAttribute("fitrange");
result->Print("v");

```

Now I want to draw in different “slices” of my obsrevables _minv_ and _time_ the projection of the other variable. For instance, 3 slices of _time_ the projection in each slice in the _minv_ variable of the model. For this I followed [rangeplot](https://root.cern/doc/v628/rf311__rangeplot_8C.html) tutorial. When it comes to the drawing I wrote then:

```auto
RooPlot *plotMinvSlice = minv->frame(
Title(Form("m^{2}_{inv} projection for t_{e#gamma} #in [%.02f, %.02f] ns", t_low, t_high)));
data.plotOn(plotMinvSlice, CutRange(rangeName.c_str()));

model.plotOn(plotMinvSlice,
             Range("fullRange"),
             NormRange("leftSide,rightSide"),
             ProjectionRange(rangeName.c_str()), /*name of the time sub-range*/
             LineColor(kMagenta + 2),
             LineStyle(kDashed));

```

It seems to work fine but the terminal tells me a warning like:

```auto
[#0] WARNING:Plotting -- RooHist::getFitRangeNEvt() WARNING: The number of normalisation events associated to histogram h_data_CutRange[slice1] is not equal to number of events in this histogram.
This is due a cut being applied while plotting the data. Automatic normalisation over a sub-range of a plot variable assumes
that the effect of that cut is uniform across the plot, which may be an incorrect assumption. To obtain a correct normalisation, it needs to be passed explicitly:
       data->plotOn(frame01,CutRange("SB1"));
       const double nData = data->sumEntries("", "SB1"); //or the cut string such as sumEntries("x > 0.");
       model.plotOn(frame01, RooFit::Normalization(nData, RooAbsReal::NumEvent), ProjectionRange("SB1"));

```

If I apply these corrections my drawing does not make sense.  
Is there anything that I am missing here?

Thanks in advance,  
Elia

---

<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:** [February 12, 2025, 2:33pm UTC](https://root-forum.cern.ch/t/issues-in-normalization-in-ranges-and-projections-in-2d-model/62925/2 "2025-02-12T14:33:38Z")

</div>

Hi @Elia_Giulio_Grandoni, thanks for the question!

Can you maybe provide the full code, and optimally also the input data for a full reproducer?

In particular, the `/*some variable and pdf definitions*/` would be good to know, so that we can better understand how you defined the ranges for the multiple variables.

---

<div class="post-metadata">

**Author:** ![Elia\_Giulio\_Grandoni](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/elia_giulio_grandoni/32/36714_2.png) [@Elia\_Giulio\_Grandoni](https://root-forum.cern.ch/u/Elia_Giulio_Grandoni)\
**Post date:** [February 12, 2025, 2:40pm UTC](https://root-forum.cern.ch/t/issues-in-normalization-in-ranges-and-projections-in-2d-model/62925/3 "2025-02-12T14:40:10Z")

</div>

Sure @jonas

I can attach the full code and the workspaces I am using. (there is a function at the top of the main code that must be commented)

[fit2d\_background.C](https://root-forum.cern.ch/uploads/short-url/22SL3B0PIyJpfI4CIcOksC5Ix3T.C) (19.8 KB)  
[ws\_common\_2021.root](https://root-forum.cern.ch/uploads/short-url/1yExfUUsvabCLsGTScfWiQ8z57w.root) (11.1 KB)  
[ws\_common\_2022.root](https://root-forum.cern.ch/uploads/short-url/iyzYcnH3w52RB49uV8CgXFPiqxC.root) (11.1 KB)  
[rec\_2021\_side\_fit.root](https://root-forum.cern.ch/uploads/short-url/fu6Ti2Xmm8rzqfMrTrclm8NwbXN.root) (524.7 KB)  
[rec\_2022\_side\_fit.root](https://root-forum.cern.ch/uploads/short-url/imbw0u4hBHT0jdiAW2lfkCl31h3.root) (631.9 KB)

Cheers

---

<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:** [February 26, 2025, 2:41pm UTC](https://root-forum.cern.ch/t/issues-in-normalization-in-ranges-and-projections-in-2d-model/62925/4 "2025-02-26T14:41:08Z")

</div>

Closed on February 26, 2025, 2:41pm UTC

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