Example of analysis class for the H1 data using code generated by MakeProxy.
This file uses 4 large data sets from the H1 collaboration at DESY Hamburg. One can access these data sets (277 MBytes) from the standard Root web site at: ftp:///root.cern.ch/root/h1analysis
The Physics plots below generated by this example cannot be produced when using smaller data sets.
There are several ways to analyze data stored in a Root Tree
- Using TTree::Draw: This is very convenient and efficient for small tasks. A TTree::Draw call produces one histogram at the time. The histogram is automatically generated. The selection expression may be specified in the command line.
- Using the TTreeViewer: This is a graphical interface to TTree::Draw with the same functionality.
- Using the code generated by TTree::MakeClass: In this case, the user creates an instance of the analysis class. They have the control over the event loop and he can generate an unlimited number of histograms.
- Using the code generated by TTree::MakeSelector. Like for the code generated by TTree::MakeClass, the user can do complex analysis. However, they cannot control the event loop. The event loop is controlled by TTree::Process called by the user. This solution is illustrated by the current code. The advantage of this method is that it can be run in a parallel environment using PROOF (the Parallel Root Facility).
A chain of 4 files (originally converted from PAW ntuples) is used to illustrate the various ways to loop on Root data sets. Each data set contains a Root Tree named "h42"
h1analysProxy.C can be used either via TTree::Draw:
h42->Draw("h1analysisProxy.C");
or it can be used directly with TTree::MakeProxy, for example to generate a shared library. TTree::MakeProxy will generate a TSelector skeleton that include h1analysProxy.C:
h42->MakeProxy("h1sel","h1analysisProxy.C");
This produces one file: h1sel.h which does a #include "h1analysProxy.C" The h1sel class is derived from the Root class TSelector and can then be used as:
h42->Process("h1sel.h+");
The following members functions are called by the TTree::Process functions.
- h1analysProxy_Begin(): Called everytime a loop on the tree starts. a convenient place to create your histograms.
- h1analysProxy_Notify(): This function is called at the first entry of a new Tree in a chain.
- h1analysProxy_Process(): called to analyze each entry.
- h1analysProxy_Terminate(): called at the end of a loop on a TTree. a convenient place to draw/fit your histograms.
To use this file, try the following session
Case A: Create a TChain with the 4 H1 data files
The chain can be created by executed the short macro h1chain.C below:
Case B: Loop on all events
Case C: Same as B, but in addition fill the event list with selected entries.
The event list is saved to a file "elist.root" by the Terminate function. To see the list of selected events, you can do elist->Print("all"). The selection function has selected 7525 events out of the 283813 events in the chain of files. (2.65 per cent)
Case D: Process only entries in the event list
The event list is read from the file in elist.root generated by step C
The commands executed with the 3 different methods B,C and D produce two canvases shown below: begin_html the Dstar plot end_html begin_html the Tau D0 plot end_html
void h1analysisProxy_Begin(
TTree *tree)
{
printf(
"Starting (begin) h1analysis with process option: %s\n",option.
Data());
if (fChain) fChain->SetEntryList(0);
delete gDirectory->GetList()->FindObject(
"elist");
elist =
new TEntryList(
"elist",
"H1 selection from Cut");
if (fInput) {
fInput->Add(
new TNamed(
"fillList",
""));
fInput->Add(elist);
}
} else elist = 0;
if (fInput) {
} else {
Warning(
"Begin",
"option 'useList' not supported in PROOF - ignoring");
Warning(
"Begin",
"the entry list must be set on the chain *before* calling Process");
}
}
}
void h1analysisProxy_SlaveBegin(
TTree *tree)
{
printf(
"Starting (slave) h1analysis with process option: %s\n",option.
Data());
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);
if (fInput) {
}
if (elist)
fOutput->Add(elist);
else
} else elist = 0;
else {
Warning(
"Begin",
"option 'useList' not supported in PROOF - ignoring");
Warning(
"Begin",
"the entry list must be set on the chain *before* calling Process");
}
}
}
return 0;
}
{
if (!useList) {
float f2 = md0_d-1.8646;
if (
gDebug>0) fprintf(stderr,
"entry #%lld f1=%f f2=%f test=%d\n",
fChain->GetReadEntry(),
f1,
f2,test);
if (ptds_d <= 2.5)
return kFALSE;
int cik = ik-1;
int cipi = ipi-1;
f1 = nhitrp[cik];
f2 = nhitrp[cipi];
test = nhitrp[cik]*nhitrp[cipi] <= 1;
if (
gDebug>0) fprintf(stderr,
"entry #%lld f1=%f f2=%f test=%d\n",
fChain->GetReadEntry(),
f1,
f2,test);
if (nhitrp[cik]*nhitrp[cipi] <= 1)
return kFALSE;
if (rend[cik] -rstart[cik] <= 22)
return kFALSE;
if (rend[cipi]-rstart[cipi] <= 22)
return kFALSE;
if (nlhk[cik] <= 0.1)
return kFALSE;
if (nlhpi[cipi] <= 0.1)
return kFALSE;
if (nlhpi[ipis-1] <= 0.1)
return kFALSE;
}
if (fillList) elist->
Enter(entry);
hdmd->Fill(dm_d);
h2->
Fill(dm_d,rpd0_t/0.029979*1.8646/ptd0_d);
}
void h1analysisProxy_SlaveTerminate()
{
printf(
"Terminate (slave) h1analysis\n");
}
void h1analysisProxy_Terminate()
{
printf(
"Terminate (final) h1analysis\n");
hdmd =
dynamic_cast<TH1F*
>(fOutput->FindObject(
"hdmd"));
h2 =
dynamic_cast<TH2F*
>(fOutput->FindObject(
"h2"));
if (hdmd == 0 || h2 == 0) {
Error(
"Terminate",
"hdmd = %p , h2 = %p", hdmd, h2);
return;
}
hdmd->GetXaxis()->SetTitle("m_{K#pi#pi} - m_{K#pi}[GeV/c^{2}]");
hdmd->GetXaxis()->SetTitleOffset(1.4);
hdmd->Fit("f5","lr");
if (fillList) {
elist =
dynamic_cast<TEntryList*
>(fOutput->FindObject(
"elist"));
if (elist) {
TFile efile(
"elist.root",
"recreate");
} else {
Error(
"Terminate",
"entry list requested but not found in output");
}
}
}
- Author
- Philippe Canal from original h1analysis.C by Rene Brun
Definition in file h1analysisProxy.C.