Logo ROOT  
Reference Guide
df101_h1Analysis.C File Reference

Detailed Description

View in nbviewer Open in SWAN This tutorial illustrates how to express the H1 analysis with a RDataFrame.

auto Select = [](ROOT::RDataFrame &dataFrame) {
using Farray_t = ROOT::VecOps::RVec<float>;
using Iarray_t = ROOT::VecOps::RVec<int>;
auto ret = dataFrame.Filter("TMath::Abs(md0_d - 1.8646) < 0.04")
.Filter("ptds_d > 2.5")
.Filter("TMath::Abs(etads_d) < 1.5")
.Filter([](int ik, int ipi, Iarray_t& nhitrp) { return nhitrp[ik - 1] * nhitrp[ipi - 1] > 1; },
{"ik", "ipi", "nhitrp"})
.Filter([](int ik, Farray_t& rstart, Farray_t& rend) { return rend[ik - 1] - rstart[ik - 1] > 22; },
{"ik", "rstart", "rend"})
.Filter([](int ipi, Farray_t& rstart, Farray_t& rend) { return rend[ipi - 1] - rstart[ipi - 1] > 22; },
{"ipi", "rstart", "rend"})
.Filter([](int ik, Farray_t& nlhk) { return nlhk[ik - 1] > 0.1; }, {"ik", "nlhk"})
.Filter([](int ipi, Farray_t& nlhpi) { return nlhpi[ipi - 1] > 0.1; }, {"ipi", "nlhpi"})
.Filter([](int ipis, Farray_t& nlhpi) { return nlhpi[ipis - 1] > 0.1; }, {"ipis", "nlhpi"})
.Filter("njets >= 1");
return ret;
};
const Double_t dxbin = (0.17 - 0.13) / 40; // Bin-width
{
Double_t x = xx[0];
if (x <= 0.13957)
return 0;
Double_t xp3 = (x - par[3]) * (x - par[3]);
Double_t res =
dxbin * (par[0] * pow(x - 0.13957, par[1]) + par[2] / 2.5066 / par[4] * exp(-xp3 / 2 / par[4] / par[4]));
return res;
}
{
static const Double_t sigma = 0.0012;
Double_t x = xx[0];
if (x <= 0.13957)
return 0;
Double_t xp3 = (x - 0.1454) * (x - 0.1454);
Double_t res = dxbin * (par[0] * pow(x - 0.13957, 0.25) + par[1] / 2.5066 / sigma * exp(-xp3 / 2 / sigma / sigma));
return res;
}
void FitAndPlotHdmd(TH1 &hdmd)
{
// create the canvas for the h1analysis fit
auto c1 = new TCanvas("c1", "h1analysis analysis", 10, 10, 800, 600);
hdmd.GetXaxis()->SetTitle("m_{K#pi#pi} - m_{K#pi}[GeV/c^{2}]");
hdmd.GetXaxis()->SetTitleOffset(1.4);
// fit histogram hdmd with function f5 using the loglikelihood option
auto f5 = new TF1("f5", fdm5, 0.139, 0.17, 5);
f5->SetParameters(1000000, .25, 2000, .1454, .001);
hdmd.Fit("f5", "lr");
hdmd.DrawClone();
}
void FitAndPlotH2(TH2 &h2)
{
// create the canvas for tau d0
auto c2 = new TCanvas("c2", "tauD0", 100, 100, 800, 600);
c2->SetGrid();
c2->SetBottomMargin(0.15);
// Project slices of 2-d histogram h2 along X , then fit each slice
// with function f2 and make a histogram for each fit parameter
// Note that the generated histograms are added to the list of objects
// in the current directory.
auto f2 = new TF1("f2", fdm2, 0.139, 0.17, 2);
f2->SetParameters(10000, 10);
h2.FitSlicesX(f2, 0, -1, 1, "qln");
// See TH2::FitSlicesX documentation
auto h2_1 = (TH1D *)gDirectory->Get("h2_1");
h2_1->GetXaxis()->SetTitle("#tau [ps]");
h2_1->SetMarkerStyle(21);
h2_1->DrawClone();
c2->Update();
auto line = new TLine(0, 0, 0, c2->GetUymax());
line->Draw();
}
void df101_h1Analysis()
{
TChain chain("h42");
chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarmb.root");
chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarp1a.root");
chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarp1b.root");
chain.Add("root://eospublic.cern.ch//eos/root-eos/h1/dstarp2.root");
ROOT::RDataFrame dataFrame(chain);
auto selected = Select(dataFrame);
auto hdmdARP = selected.Histo1D({"hdmd", "Dm_d", 40, 0.13, 0.17}, "dm_d");
auto selectedAddedBranch = selected.Define("h2_y", "rpd0_t / 0.029979f * 1.8646f / ptd0_d");
auto h2ARP = selectedAddedBranch.Histo2D({"h2", "ptD0 vs Dm_d", 30, 0.135, 0.165, 30, -3, 6}, "dm_d", "h2_y");
FitAndPlotHdmd(*hdmdARP);
FitAndPlotH2(*h2ARP);
}
Date
December 2016
Author
Axel Naumann, Danilo Piparo (CERN)

Definition in file df101_h1Analysis.C.

TLine
Definition: TLine.h:22
TH1D
1-D histogram with a double per channel (see TH1 documentation)}
Definition: TH1.h:615
exp
double exp(double)
TObject::DrawClone
virtual TObject * DrawClone(Option_t *option="") const
Draw a clone of this object in the current selected pad for instance with: gROOT->SetSelectedPad(gPad...
Definition: TObject.cxx:221
x
Double_t x[n]
Definition: legend1.C:17
ROOT::RDataFrame
ROOT's RDataFrame offers a high level interface for analyses of data stored in TTrees,...
Definition: RDataFrame.hxx:42
fdm5
Double_t fdm5(Double_t *xx, Double_t *par)
Definition: h1analysisProxy.h:14
ROOT::VecOps::Filter
RVec< T > Filter(const RVec< T > &v, F &&f)
Create a new collection with the elements passing the filter expressed by the predicate.
Definition: RVec.hxx:938
TStyle::SetOptFit
void SetOptFit(Int_t fit=1)
The type of information about fit parameters printed in the histogram statistics box can be selected ...
Definition: TStyle.cxx:1544
ROOT::EnableImplicitMT
void EnableImplicitMT(UInt_t numthreads=0)
Enable ROOT's implicit multi-threading for all objects and methods that provide an internal paralleli...
Definition: TROOT.cxx:523
gStyle
R__EXTERN TStyle * gStyle
Definition: TStyle.h:412
dxbin
const Double_t dxbin
Definition: h1analysisProxy.h:10
gDirectory
#define gDirectory
Definition: TDirectory.h:236
TH2
Definition: TH2.h:30
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition: TNamed.cxx:164
line
TLine * line
Definition: entrylistblock_figure1.C:235
TH2::FitSlicesX
virtual void FitSlicesX(TF1 *f1=0, Int_t firstybin=0, Int_t lastybin=-1, Int_t cut=0, Option_t *option="QNR", TObjArray *arr=0)
Project slices along X in case of a 2-D histogram, then fit each slice with function f1 and make a hi...
Definition: TH2.cxx:897
sigma
const Double_t sigma
Definition: h1analysisProxy.h:11
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition: TObject.cxx:197
Double_t
double Double_t
Definition: RtypesCore.h:59
TCanvas
Definition: TCanvas.h:23
TH1
Definition: TH1.h:57
c2
return c2
Definition: legend2.C:14
TChain
Definition: TChain.h:33
TH1::Fit
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
Definition: TH1.cxx:3807
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:293
TF1
1-Dim function class
Definition: TF1.h:212
fdm2
Double_t fdm2(Double_t *xx, Double_t *par)
Definition: h1analysisProxy.h:25
TH1::GetXaxis
TAxis * GetXaxis()
Get the behaviour adopted by the object about the statoverflows. See EStatOverflows for more informat...
Definition: TH1.h:317
pow
double pow(double, double)
ROOT::VecOps::RVec< float >
c1
return c1
Definition: legend1.C:41