Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions roofit/roofitcore/src/RooPlot.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -898,22 +898,28 @@ bool RooPlot::drawAfter(const char *after, const char *target)
/// methods to change the drawing style attributes of a contained
/// object directly.

TObject *RooPlot::findObject(const char *name, const TClass* tClass) const
TObject *RooPlot::findObject(const char *name, const TClass *tClass) const
{
TObject *ret = nullptr;
TObject *ret = nullptr;

for(auto const& item : _items) {
TObject &obj = *item.first;
if ((!name || name[0] == '\0' || !TString(name).CompareTo(obj.GetName()))
&& (!tClass || (obj.IsA()==tClass))) {
ret = &obj ;
}
}
for (auto const &item : _items) {
TObject &obj = *item.first;
if ((!name || name[0] == '\0' || !TString(name).CompareTo(obj.GetName())) && (!tClass || (obj.IsA() == tClass))) {
ret = &obj;
}
}

if (ret == nullptr) {
coutE(InputArguments) << "RooPlot::findObject(" << GetName() << ") cannot find object " << (name?name:"<last>") << std::endl ;
}
return ret ;
if (ret == nullptr) {
std::stringstream error;
error << "RooPlot::findObject(" << GetName() << ") cannot find object " << (name ? name : "<last>") << "\n"
<< "Available objects are:\n";
for (auto const &item : _items) {
TObject &obj = *item.first;
error << " - " << obj.IsA()->GetName() << " \"" << obj.GetName() << "\"\n";
}
coutE(InputArguments) << error.str();
}
return ret;
}


Expand Down
2 changes: 1 addition & 1 deletion roofit/roofitcore/src/RooSimultaneous.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -777,7 +777,7 @@ RooPlot* RooSimultaneous::plotOn(RooPlot *frame, RooLinkedList& cmdList) const
projDataTmp(projData->reduce(RooFit::SelectVars(projDataVars), RooFit::Cut(cutString.c_str())));

// Override normalization and projection dataset
RooCmdArg tmp1 = RooFit::Normalization(scaleFactor*wTable->getFrac(idxCatClone->getCurrentLabel()),stype) ;
RooCmdArg tmp1 = RooFit::Normalization(scaleFactor*wTable->get(idxCatClone->getCurrentLabel()),RooAbsReal::NumEvent) ;
RooCmdArg tmp2 = RooFit::ProjWData(*projDataSet,*projDataTmp) ;

// WVE -- do not adjust normalization for asymmetry plots
Expand Down
25 changes: 12 additions & 13 deletions roofit/roofitcore/test/stressRooFit_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -2974,22 +2974,21 @@ class TestBasic501 : public RooUnitTest {
RooPlot *frame1 = x.frame(Bins(30), Title("Physics sample"));

// Plot all data tagged as physics sample
combData.plotOn(frame1, Cut("sample==sample::physics"));
std::unique_ptr<RooAbsData> slicedData1{combData.reduce(Cut("sample==sample::physics"))};
slicedData1->SetName("combData_Cut[sample==sample::physics]"); // to be consistent with reference file
slicedData1->plotOn(frame1);

// Plot "physics" slice of simultaneous pdf.
// NBL You _must_ project the sample index category with data using ProjWData
// as a RooSimultaneous makes no prediction on the shape in the index category
// and can thus not be integrated
simPdf.plotOn(frame1, Slice(sample, "physics"), ProjWData(sample, combData));
simPdf.plotOn(frame1, Slice(sample, "physics"), Components("px"), ProjWData(sample, combData),
LineStyle(kDashed));

// The same plot for the control sample slice
simPdf.getPdf("physics")->plotOn(frame1);
simPdf.getPdf("physics")->plotOn(frame1, Components("px"), LineStyle(kDashed));

// The same plot for the control sample slice.
RooPlot *frame2 = x.frame(Bins(30), Title("Control sample"));
combData.plotOn(frame2, Cut("sample==sample::control"));
simPdf.plotOn(frame2, Slice(sample, "control"), ProjWData(sample, combData));
simPdf.plotOn(frame2, Slice(sample, "control"), Components("px_ctl"), ProjWData(sample, combData),
LineStyle(kDashed));
std::unique_ptr<RooAbsData> slicedData2{combData.reduce(Cut("sample==sample::control"))};
slicedData2->SetName("combData_Cut[sample==sample::control]"); // to be consistent with reference file
slicedData2->plotOn(frame2);
simPdf.getPdf("control")->plotOn(frame2);
simPdf.getPdf("control")->plotOn(frame2, Components("px_ctl"), LineStyle(kDashed));

regPlot(frame1, "rf501_plot1");
regPlot(frame2, "rf501_plot2");
Expand Down
27 changes: 13 additions & 14 deletions tutorials/roofit/roofit/rf501_simultaneouspdf.C
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,28 @@ void rf501_simultaneouspdf()
RooPlot *frame1 = x.frame(Title("Physics sample"));

// Plot all data tagged as physics sample
combData.plotOn(frame1, Cut("sample==sample::physics"));
std::unique_ptr<RooAbsData> slicedData1{combData.reduce(Cut("sample==sample::physics"))};
slicedData1->plotOn(frame1);

// Plot "physics" slice of simultaneous pdf.
simPdf.getPdf("physics")->plotOn(frame1);
simPdf.getPdf("physics")->plotOn(frame1, Components("px"), LineStyle(kDashed));

// The same plot for the control sample slice. We do this with a different
// approach, using the data slice for the projection. This approach is more
// general, because you can plot sums of slices by using logical or in the
// Cut() command.
// NBL You _must_ project the sample index category with data using ProjWData
// as a RooSimultaneous makes no prediction on the shape in the index category
// and can thus not be integrated.
// In other words: Since the PDF doesn't know the number of events in the different
// category states, it doesn't know how much of each component it has to project out.
// This information is read from the data.
simPdf.plotOn(frame1, Slice(sample, "physics"), ProjWData(sample, combData));
simPdf.plotOn(frame1, Slice(sample, "physics"), Components("px"), ProjWData(sample, combData), LineStyle(kDashed));

// The same plot for the control sample slice. We do this with a different
// approach this time, for illustration purposes. Here, we are slicing the
// dataset and then use the data slice for the projection, because then the
// RooFit::Slice() becomes unnecessary. This approach is more general,
// because you can plot sums of slices by using logical or in the Cut()
// command.
RooPlot *frame2 = x.frame(Bins(30), Title("Control sample"));
std::unique_ptr<RooAbsData> slicedData{combData.reduce(Cut("sample==sample::control"))};
slicedData->plotOn(frame2);
simPdf.plotOn(frame2, ProjWData(sample, *slicedData));
simPdf.plotOn(frame2, Components("px_ctl"), ProjWData(sample, *slicedData), LineStyle(kDashed));
std::unique_ptr<RooAbsData> slicedData2{combData.reduce(Cut("sample==sample::control"))};
slicedData2->plotOn(frame2);
simPdf.plotOn(frame2, ProjWData(sample, *slicedData2));
simPdf.plotOn(frame2, Components("px_ctl"), ProjWData(sample, *slicedData2), LineStyle(kDashed));

// The same plot for all the phase space. Here, we can just use the original
// combined dataset.
Expand Down
34 changes: 17 additions & 17 deletions tutorials/roofit/roofit/rf501_simultaneouspdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
## \date February 2018
## \authors Clemens Lange, Wouter Verkerke (C++ version)

import ROOT

Check failure on line 14 in tutorials/roofit/roofit/rf501_simultaneouspdf.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

tutorials/roofit/roofit/rf501_simultaneouspdf.py:14:1: I001 Import block is un-sorted or un-formatted


# Create model for physics sample
Expand Down Expand Up @@ -96,28 +96,28 @@
frame1 = x.frame(Title="Physics sample")

# Plot all data tagged as physics sample
combData.plotOn(frame1, Cut="sample==sample::physics")
slicedData1 = combData.reduce(Cut="sample==sample::physics")
slicedData1.plotOn(frame1)

# Plot "physics" slice of simultaneous pdf.
# NB: You *must* project the sample index category with data using ProjWData as
# a RooSimultaneous makes no prediction on the shape in the index category and
# can thus not be integrated. In other words: Since the PDF doesn't know the
# number of events in the different category states, it doesn't know how much
# of each component it has to project out. This info is read from the data.
simPdf.plotOn(frame1, Slice=(sample, "physics"), ProjWData=(sample, combData))
simPdf.plotOn(frame1, Slice=(sample, "physics"), Components="px", ProjWData=(sample, combData), LineStyle="--")
simPdf.getPdf("physics").plotOn(frame1)
simPdf.getPdf("physics").plotOn(frame1, Components="px", LineStyle="--")

# The same plot for the control sample slice. We do this with a different
# approach this time, for illustration purposes. Here, we are slicing the
# dataset and then use the data slice for the projection, because then the
# RooFit::Slice() becomes unnecessary. This approach is more general,
# because you can plot sums of slices by using logical or in the Cut()
# command.
# approach, using the data slice for the projection. This approach is more
# general, because you can plot sums of slices by using logical or in the
# Cut() command.
# NBL You _must_ project the sample index category with data using ProjWData
# as a RooSimultaneous makes no prediction on the shape in the index category
# and can thus not be integrated.
# In other words: Since the PDF doesn't know the number of events in the different
# category states, it doesn't know how much of each component it has to project out.
# This information is read from the data.
frame2 = x.frame(Title="Control sample")
slicedData = combData.reduce(Cut="sample==sample::control")
slicedData.plotOn(frame2)
simPdf.plotOn(frame2, ProjWData=(sample, slicedData))
simPdf.plotOn(frame2, Components="px_ctl", ProjWData=(sample, slicedData), LineStyle="--")
slicedData2 = combData.reduce(Cut="sample==sample::control")
slicedData2.plotOn(frame2)
simPdf.plotOn(frame2, ProjWData=(sample, slicedData2))
simPdf.plotOn(frame2, Components="px_ctl", ProjWData=(sample, slicedData2), LineStyle="--")

# The same plot for all the phase space. Here, we can just use the original
# combined dataset.
Expand Down
Loading