ROOT
v6-30
Reference Guide
Loading...
Searching...
No Matches
h1analysisTreeReader.C File Reference
Tutorials
»
Tree tutorials
Detailed Description
H1 analysis example expressed in terms of
TTreeReader
#include "
h1analysisTreeReader.h
"
#include "
TStyle.h
"
#include "
TCanvas.h
"
#include "
TPaveStats.h
"
#include "
TLine.h
"
#include "
TMath.h
"
#include "
TFile.h
"
#include "
TROOT.h
"
const
Double_t
dxbin
= (0.17-0.13)/40;
// Bin-width
const
Double_t
sigma
= 0.0012;
//_____________________________________________________________________
Double_t
fdm5
(
Double_t
*xx,
Double_t
*par)
{
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]*
TMath::Power
(
x
-0.13957, par[1])
+ par[2] / 2.5066/par[4]*
TMath::Exp
(-xp3/2/par[4]/par[4]));
return
res;
}
//_____________________________________________________________________
Double_t
fdm2
(
Double_t
*xx,
Double_t
*par)
{
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]*
TMath::Power
(
x
-0.13957, 0.25)
+ par[1] / 2.5066/
sigma
*
TMath::Exp
(-xp3/2/
sigma
/
sigma
));
return
res;
}
//_____________________________________________________________________
Bool_t
h1analysisTreeReader::Process
(
Long64_t
entry){
// entry is the entry number in the current Tree
// Selection function to select D* and D0.
myTreeReader
.
SetLocalEntry
(entry);
fProcessed
++;
//in case one entry list is given in input, the selection has already been done.
if
(!
useList
) {
// Return as soon as a bad entry is detected
if
(
TMath::Abs
(*
fMd0_d
-1.8646) >= 0.04)
return
kFALSE
;
if
(*
fPtds_d
<= 2.5)
return
kFALSE
;
if
(
TMath::Abs
(*
fEtads_d
) >= 1.5)
return
kFALSE
;
(*fIk)--;
//original fIk used f77 convention starting at 1
(*fIpi)--;
if
(
fNhitrp
.At(*
fIk
)*
fNhitrp
.At(*
fIpi
) <= 1)
return
kFALSE
;
if
(
fRend
.
At
(*
fIk
) -
fRstart
.
At
(*
fIk
) <= 22)
return
kFALSE
;
if
(
fRend
.
At
(*
fIpi
)-
fRstart
.
At
(*
fIpi
) <= 22)
return
kFALSE
;
if
(
fNlhk
.
At
(*
fIk
) <= 0.1)
return
kFALSE
;
if
(
fNlhpi
.
At
(*
fIpi
) <= 0.1)
return
kFALSE
;
(*fIpis)--;
if
(
fNlhpi
.
At
(*
fIpis
) <= 0.1)
return
kFALSE
;
if
(*
fNjets
< 1)
return
kFALSE
;
}
// if option fillList, fill the entry list
if
(
fillList
)
elist
->
Enter
(entry);
//fill some histograms
hdmd
->
Fill
(*
fDm_d
);
h2
->
Fill
(*
fDm_d
,*
fRpd0_t
/0.029979*1.8646/ *
fPtd0_d
);
return
kTRUE
;
}
void
h1analysisTreeReader::Begin
(
TTree
*
/*myTree*/
) {
// function called before starting the event loop
// -it performs some cleanup
// -it creates histograms
// -it sets some initialisation for the entry list
Reset
();
//print the option specified in the Process function.
TString
option
=
GetOption
();
Info
(
"Begin"
,
"starting h1analysis with process option: %s"
,
option
.Data());
delete
gDirectory
->GetList()->FindObject(
"elist"
);
// case when one creates/fills the entry list
if
(
option
.Contains(
"fillList"
)) {
fillList
=
kTRUE
;
elist
=
new
TEntryList
(
"elist"
,
"H1 selection from Cut"
);
// Add to the input list for processing in PROOF, if needed
if
(
fInput
) {
fInput
->
Add
(
new
TNamed
(
"fillList"
,
""
));
// We send a clone to avoid double deletes when importing the result
fInput
->
Add
(
elist
);
// This is needed to avoid warnings from output-to-members mapping
elist
=
nullptr
;
}
Info
(
"Begin"
,
"creating an entry-list"
);
}
// case when one uses the entry list generated in a previous call
if
(
option
.Contains(
"useList"
)) {
useList
=
kTRUE
;
if
(
fInput
) {
// In PROOF option "useList" is processed in SlaveBegin and we do not need
// to do anything here
}
else
{
TFile
f
(
"elist.root"
);
elist
= (
TEntryList
*)
f
.Get(
"elist"
);
if
(
elist
)
elist
->
SetDirectory
(
nullptr
);
//otherwise the file destructor will delete elist
}
}
}
void
h1analysisTreeReader::SlaveBegin
(
TTree
*myTree){
// function called before starting the event loop
// -it performs some cleanup
// -it creates histograms
// -it sets some initialisation for the entry list
Init
(myTree);
//print the option specified in the Process function.
TString
option
=
GetOption
();
Info
(
"SlaveBegin"
,
"starting h1analysis with process option: %s (tree: %p)"
,
option
.Data(), myTree);
//create histograms
hdmd
=
new
TH1F
(
"hdmd"
,
"Dm_d"
,40,0.13,0.17);
h2
=
new
TH2F
(
"h2"
,
"ptD0 vs Dm_d"
,30,0.135,0.165,30,-3,6);
fOutput
->
Add
(
hdmd
);
fOutput
->
Add
(
h2
);
// Entry list stuff (re-parse option because on PROOF only SlaveBegin is called)
if
(
option
.Contains(
"fillList"
)) {
fillList
=
kTRUE
;
// Get the list
if
(
fInput
) {
if
((
elist
= (
TEntryList
*)
fInput
->
FindObject
(
"elist"
)))
// Need to clone to avoid problems when destroying the selector
elist
= (
TEntryList
*)
elist
->
Clone
();
if
(
elist
)
fOutput
->
Add
(
elist
);
else
fillList
=
kFALSE
;
}
}
if
(
fillList
)
Info
(
"SlaveBegin"
,
"creating an entry-list"
);
if
(
option
.Contains(
"useList"
))
useList
=
kTRUE
;
}
void
h1analysisTreeReader::Terminate
() {
// function called at the end of the event loop
hdmd
=
dynamic_cast<
TH1F
*
>
(
fOutput
->
FindObject
(
"hdmd"
));
h2
=
dynamic_cast<
TH2F
*
>
(
fOutput
->
FindObject
(
"h2"
));
if
(
hdmd
==
nullptr
||
h2
==
nullptr
) {
Error
(
"Terminate"
,
"hdmd = %p , h2 = %p"
,
hdmd
,
h2
);
return
;
}
//create the canvas for the h1analysis fit
gStyle
->
SetOptFit
();
TCanvas
*
c1
=
new
TCanvas
(
"c1"
,
"h1analysis analysis"
,10,10,800,600);
c1
->SetBottomMargin(0.15);
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 loglfIkelihood option
if
(
gROOT
->GetListOfFunctions()->FindObject(
"f5"
))
delete
gROOT
->GetFunction(
"f5"
);
TF1
*f5 =
new
TF1
(
"f5"
,
fdm5
,0.139,0.17,5);
f5->
SetParameters
(1000000, .25, 2000, .1454, .001);
hdmd
->
Fit
(
"f5"
,
"lr"
);
//create the canvas for tau d0
gStyle
->
SetOptFit
(0);
gStyle
->
SetOptStat
(1100);
TCanvas
*
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.
if
(
gROOT
->GetListOfFunctions()->FindObject(
"f2"
))
delete
gROOT
->GetFunction(
"f2"
);
TF1
*f2 =
new
TF1
(
"f2"
,
fdm2
,0.139,0.17,2);
f2->
SetParameters
(10000, 10);
h2
->
FitSlicesX
(f2,0,-1,1,
"qln"
);
TH1D
*h2_1 = (
TH1D
*)
gDirectory
->Get(
"h2_1"
);
h2_1->
GetXaxis
()->
SetTitle
(
"#tau[ps]"
);
h2_1->
SetMarkerStyle
(21);
h2_1->
Draw
();
c2
->Update();
TLine
*
line
=
new
TLine
(0,0,0,
c2
->GetUymax());
line
->
Draw
();
// Have the number of entries on the first histogram (to cross check when running
// with entry lists)
TPaveStats
*psdmd = (
TPaveStats
*)
hdmd
->
GetListOfFunctions
()->
FindObject
(
"stats"
);
psdmd->
SetOptStat
(1110);
c1
->Modified();
//save the entry list to a Root file if one was produced
if
(
fillList
) {
if
(!
elist
)
elist
=
dynamic_cast<
TEntryList
*
>
(
fOutput
->
FindObject
(
"elist"
));
if
(
elist
) {
Printf
(
"Entry list 'elist' created:"
);
elist
->
Print
();
TFile
efile(
"elist.root"
,
"recreate"
);
elist
->
Write
();
}
else
{
Error
(
"Terminate"
,
"entry list requested but not found in output"
);
}
}
// Notify the amount of processed events
if
(!
fInput
)
Info
(
"Terminate"
,
"processed %lld events"
,
fProcessed
);
}
void
h1analysisTreeReader::SlaveTerminate
(){
}
Bool_t
h1analysisTreeReader::Notify
() {
// called when loading a new file
// get branch pointers
Info
(
"Notify"
,
"processing file: %s"
,
myTreeReader
.
GetTree
()->
GetCurrentFile
()->
GetName
());
if
(
elist
&&
myTreeReader
.
GetTree
()) {
if
(
fillList
) {
elist
->
SetTree
(
myTreeReader
.
GetTree
());
}
else
if
(
useList
) {
myTreeReader
.
GetTree
()->
SetEntryList
(
elist
);
}
}
return
kTRUE
;
}
f
#define f(i)
Definition
RSha256.hxx:104
Bool_t
bool Bool_t
Definition
RtypesCore.h:63
kFALSE
constexpr Bool_t kFALSE
Definition
RtypesCore.h:101
Double_t
double Double_t
Definition
RtypesCore.h:59
Long64_t
long long Long64_t
Definition
RtypesCore.h:80
kTRUE
constexpr Bool_t kTRUE
Definition
RtypesCore.h:100
TCanvas.h
gDirectory
#define gDirectory
Definition
TDirectory.h:384
TFile.h
option
Option_t Option_t option
Definition
TGWin32VirtualXProxy.cxx:44
TLine.h
TMath.h
TPaveStats.h
TROOT.h
gROOT
#define gROOT
Definition
TROOT.h:407
Printf
void Printf(const char *fmt,...)
Formats a string in a circular formatting buffer and prints the string.
Definition
TString.cxx:2481
TStyle.h
gStyle
R__EXTERN TStyle * gStyle
Definition
TStyle.h:433
TAttAxis::SetTitleOffset
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition
TAttAxis.cxx:298
TAttMarker::SetMarkerStyle
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
Definition
TAttMarker.h:40
TCanvas
The Canvas class.
Definition
TCanvas.h:23
TEntryList
A List of entry numbers in a TTree or TChain.
Definition
TEntryList.h:26
TEntryList::SetTree
virtual void SetTree(const TTree *tree)
If a list for a tree with such name and filename exists, sets it as the current sublist If not,...
Definition
TEntryList.cxx:1290
TEntryList::Enter
virtual Bool_t Enter(Long64_t entry, TTree *tree=nullptr)
Add entry #entry to the list.
Definition
TEntryList.cxx:625
TEntryList::SetDirectory
virtual void SetDirectory(TDirectory *dir)
Add reference to directory dir. dir can be 0.
Definition
TEntryList.cxx:1164
TEntryList::Print
void Print(const Option_t *option="") const override
Print this list.
Definition
TEntryList.cxx:1095
TF1
1-Dim function class
Definition
TF1.h:214
TF1::SetParameters
virtual void SetParameters(const Double_t *params)
Definition
TF1.h:650
TFile
A ROOT file is composed of a header, followed by consecutive data records (TKey instances) with a wel...
Definition
TFile.h:53
TH1D
1-D histogram with a double per channel (see TH1 documentation)}
Definition
TH1.h:620
TH1F
1-D histogram with a float per channel (see TH1 documentation)}
Definition
TH1.h:577
TH1::GetXaxis
TAxis * GetXaxis()
Definition
TH1.h:322
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:3901
TH1::Fill
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition
TH1.cxx:3345
TH1::Draw
void Draw(Option_t *option="") override
Draw this histogram with options.
Definition
TH1.cxx:3067
TH1::GetListOfFunctions
TList * GetListOfFunctions() const
Definition
TH1.h:242
TH2F
2-D histogram with a float per channel (see TH1 documentation)}
Definition
TH2.h:258
TH2::Fill
Int_t Fill(Double_t) override
Invalid Fill method.
Definition
TH2.cxx:347
TH2::FitSlicesX
virtual void FitSlicesX(TF1 *f1=nullptr, Int_t firstybin=0, Int_t lastybin=-1, Int_t cut=0, Option_t *option="QNR", TObjArray *arr=nullptr)
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:970
THashList::FindObject
TObject * FindObject(const char *name) const override
Find object using its name.
Definition
THashList.cxx:262
TLine
Use the TLine constructor to create a simple line.
Definition
TLine.h:22
TList::FindObject
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
Definition
TList.cxx:578
TList::Add
void Add(TObject *obj) override
Definition
TList.h:81
TNamed
The TNamed class is the base class for all named ROOT classes.
Definition
TNamed.h:29
TNamed::Clone
TObject * Clone(const char *newname="") const override
Make a clone of an object using the Streamer facility.
Definition
TNamed.cxx:74
TNamed::SetTitle
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
Definition
TNamed.cxx:164
TNamed::GetName
const char * GetName() const override
Returns name of object.
Definition
TNamed.h:47
TObject::Write
virtual Int_t Write(const char *name=nullptr, Int_t option=0, Int_t bufsize=0)
Write this object to the current directory.
Definition
TObject.cxx:880
TObject::Error
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition
TObject.cxx:987
TObject::Draw
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Definition
TObject.cxx:274
TObject::Info
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Definition
TObject.cxx:961
TPaveStats
The histogram statistics painter class.
Definition
TPaveStats.h:18
TPaveStats::SetOptStat
void SetOptStat(Int_t stat=1)
Set the stat option.
Definition
TPaveStats.cxx:306
TSelector::fInput
TList * fInput
List of objects available during processing.
Definition
TSelector.h:41
TSelector::fOutput
TSelectorList * fOutput
! List of objects created during processing
Definition
TSelector.h:42
TSelector::GetOption
const char * GetOption() const override
Definition
TSelector.h:57
TString
Basic string class.
Definition
TString.h:139
TStyle::SetOptStat
void SetOptStat(Int_t stat=1)
The type of information printed in the histogram statistics box can be selected via the parameter mod...
Definition
TStyle.cxx:1636
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:1589
TTreeReaderArray::At
T & At(std::size_t idx)
Definition
TTreeReaderArray.h:205
TTreeReader::GetTree
TTree * GetTree() const
Definition
TTreeReader.h:181
TTreeReader::SetLocalEntry
EEntryStatus SetLocalEntry(Long64_t entry)
Set the next local tree entry.
Definition
TTreeReader.h:209
TTree
A TTree represents a columnar dataset.
Definition
TTree.h:79
TTree::GetCurrentFile
TFile * GetCurrentFile() const
Return pointer to the current file.
Definition
TTree.cxx:5476
TTree::SetEntryList
virtual void SetEntryList(TEntryList *list, Option_t *opt="")
Set an EntryList.
Definition
TTree.cxx:9033
h1analysisTreeReader::myTreeReader
TTreeReader myTreeReader
Definition
h1analysisTreeReader.h:14
h1analysisTreeReader::Process
Bool_t Process(Long64_t entry) override
The Process() function is called for each entry in the tree (or possibly keyed object in the case of ...
h1analysisTreeReader::fIpi
TTreeReaderValue< Int_t > fIpi
Definition
h1analysisTreeReader.h:20
h1analysisTreeReader::fNhitrp
TTreeReaderArray< Int_t > fNhitrp
Definition
h1analysisTreeReader.h:25
h1analysisTreeReader::fRpd0_t
TTreeReaderValue< Float_t > fRpd0_t
Definition
h1analysisTreeReader.h:24
h1analysisTreeReader::fNlhpi
TTreeReaderArray< Float_t > fNlhpi
Definition
h1analysisTreeReader.h:29
h1analysisTreeReader::fMd0_d
TTreeReaderValue< Float_t > fMd0_d
Definition
h1analysisTreeReader.h:23
h1analysisTreeReader::useList
Bool_t useList
Definition
h1analysisTreeReader.h:35
h1analysisTreeReader::elist
TEntryList * elist
Definition
h1analysisTreeReader.h:37
h1analysisTreeReader::fPtd0_d
TTreeReaderValue< Float_t > fPtd0_d
Definition
h1analysisTreeReader.h:22
h1analysisTreeReader::fProcessed
Long64_t fProcessed
Definition
h1analysisTreeReader.h:38
h1analysisTreeReader::SlaveBegin
void SlaveBegin(TTree *) override
h1analysisTreeReader::fillList
Bool_t fillList
Definition
h1analysisTreeReader.h:36
h1analysisTreeReader::fIk
TTreeReaderValue< Int_t > fIk
Definition
h1analysisTreeReader.h:19
h1analysisTreeReader::Notify
Bool_t Notify() override
This method must be overridden to handle object notification (the base implementation is no-op).
h1analysisTreeReader::Reset
void Reset()
Definition
h1analysisTreeReader.h:81
h1analysisTreeReader::Terminate
void Terminate() override
h1analysisTreeReader::fIpis
TTreeReaderValue< Int_t > fIpis
Definition
h1analysisTreeReader.h:21
h1analysisTreeReader::fNjets
TTreeReaderValue< Int_t > fNjets
Definition
h1analysisTreeReader.h:30
h1analysisTreeReader::h2
TH2F * h2
Definition
h1analysisTreeReader.h:33
h1analysisTreeReader::fRend
TTreeReaderArray< Float_t > fRend
Definition
h1analysisTreeReader.h:27
h1analysisTreeReader::fEtads_d
TTreeReaderValue< Float_t > fEtads_d
Definition
h1analysisTreeReader.h:17
h1analysisTreeReader::hdmd
TH1F * hdmd
Definition
h1analysisTreeReader.h:32
h1analysisTreeReader::SlaveTerminate
void SlaveTerminate() override
h1analysisTreeReader::fRstart
TTreeReaderArray< Float_t > fRstart
Definition
h1analysisTreeReader.h:26
h1analysisTreeReader::fDm_d
TTreeReaderValue< Float_t > fDm_d
Definition
h1analysisTreeReader.h:18
h1analysisTreeReader::fNlhk
TTreeReaderArray< Float_t > fNlhk
Definition
h1analysisTreeReader.h:28
h1analysisTreeReader::fPtds_d
TTreeReaderValue< Float_t > fPtds_d
Definition
h1analysisTreeReader.h:16
h1analysisTreeReader::Begin
void Begin(TTree *) override
h1analysisTreeReader::Init
void Init(TTree *myTree) override
Definition
h1analysisTreeReader.h:67
line
TLine * line
Definition
entrylistblock_figure1.C:235
fdm5
Double_t fdm5(Double_t *xx, Double_t *par)
Definition
h1analysisProxy.h:14
sigma
const Double_t sigma
Definition
h1analysisProxy.h:11
dxbin
const Double_t dxbin
Definition
h1analysisProxy.h:10
fdm2
Double_t fdm2(Double_t *xx, Double_t *par)
Definition
h1analysisProxy.h:25
h1analysisTreeReader.h
c1
return c1
Definition
legend1.C:41
x
Double_t x[n]
Definition
legend1.C:17
c2
return c2
Definition
legend2.C:14
TMath::Exp
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Definition
TMath.h:709
TMath::Power
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Definition
TMath.h:721
TMath::Abs
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition
TMathBase.h:123
Author
Anders Eie, 2013
Definition in file
h1analysisTreeReader.C
.
tutorials
tree
h1analysisTreeReader.C
ROOT v6-30 - Reference Guide Generated on Thu Dec 12 2024 06:13:04 (GVA Time) using Doxygen 1.9.8