Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TSimpleAnalysis Class Reference

A TSimpleAnalysis object creates histograms from a TChain.

These histograms are stored to an output file. The histogrammed (TTreeFormula) expressions, their cuts, the input and output files are configured through a simple config file that allows comments starting with '#'. Here an example of configuration file:

# This is an example of configuration file
file_output.root #the output file in which histograms are stored
# The next line has the name of the tree of the input data. It is
# optional if there is exactly one tree in the first input file.
ntuple #name of the input tree
# The lines of the next block correspond to .root input files that
# contain the tree
hsimple1.root #first .root input file
hsimple2.root #second .root input file
# The next block is composed by lines that allow to configure the
# histograms. They have the following syntax:
# NAME = EXPRESSION if CUT
# which corresponds to chain->Draw("EXPRESSION >> NAME", "CUT")
# i.e. it will create a histogram called NAME and store it in
# file_output.root.
# "if CUT" is optional
hpx=px if px<-3 #first histogram
hpxpy=px:py #second histogram
# End of the configuration file
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void input
char name[80]
Definition TGX11.cxx:110
Definition file.py:1
Definition first.py:1
Definition tree.py:1
static void output()

It is possible to use the script rootdrawtree that allows to use the class just in command line through the bash shell.

Definition at line 33 of file TSimpleAnalysis.h.

Public Member Functions

 TSimpleAnalysis (const std::string &file)
 
 TSimpleAnalysis (const std::string &output, const std::vector< std::string > &inputFiles, const std::vector< std::string > &expressions, const std::string &treeName)
 Constructor for the case of command line parsing arguments.
 
bool Configure ()
 This function has the aim of setting the arguments read from the input file.
 
bool Run ()
 Execute all the TChain::Draw() as configured and stores the output histograms.
 

Private Types

enum  EReadingWhat { kReadingOutput , kReadingTreeName , kReadingInput , kReadingExpressions }
 The elements of the enumeration refer to the different types of elements that are in the input file. More...
 

Private Member Functions

std::string GetLine (int &numbLine)
 Skip subsequent empty lines read from fIn and returns the next not empty line.
 
std::string HandleExpressionConfig (const std::string &line)
 Handle the expression lines of the input file in order to pass the elements to the members of the object.
 
bool HandleInputFileNameConfig (const std::string &line)
 Returns false if not a tree name, otherwise sets the name of the tree.
 
bool SetTreeName ()
 Disambiguate tree name from first input file and set up fTreeName if it is empty.
 

Private Attributes

std::string fConfigFile
 Name of the configuration file.
 
std::map< std::string, std::pair< std::string, std::string > > fHists
 The map contains in the first part the names of the histograms written in the output file, in the second part the pair of what is shown in the histograms and the cut applied on the variables.
 
std::ifstream fIn
 Stream for the input file.
 
std::vector< std::string > fInputFiles
 .root input files
 
std::string fOutputFile
 Output file in which are stored the histograms.
 
std::string fTreeName
 Name of the input tree.
 

#include <TSimpleAnalysis.h>

Member Enumeration Documentation

◆ EReadingWhat

The elements of the enumeration refer to the different types of elements that are in the input file.

Enumerator
kReadingOutput 

Reading the name of the output file.

kReadingTreeName 

Reading the name of the tree.

kReadingInput 

Reading the name of the .root input files.

kReadingExpressions 

Reading the expressions.

Definition at line 48 of file TSimpleAnalysis.h.

Constructor & Destructor Documentation

◆ TSimpleAnalysis() [1/2]

TSimpleAnalysis::TSimpleAnalysis ( const std::string &  file)
inline

Definition at line 62 of file TSimpleAnalysis.h.

◆ TSimpleAnalysis() [2/2]

TSimpleAnalysis::TSimpleAnalysis ( const std::string &  output,
const std::vector< std::string > &  inputFiles,
const std::vector< std::string > &  expressions,
const std::string &  treeName = "" 
)

Constructor for the case of command line parsing arguments.

It sets the members of the object.

Parameters
[in]output- name of the output file
[in]inputFiles- name of the input .root files
[in]expressions- what is shown in the histograms
[in]treeName- name of the tree
Exceptions
std::runtime_errorin case of ill-formed expressions

Definition at line 154 of file TSimpleAnalysis.cxx.

Member Function Documentation

◆ Configure()

bool TSimpleAnalysis::Configure ( )

This function has the aim of setting the arguments read from the input file.

Definition at line 414 of file TSimpleAnalysis.cxx.

◆ GetLine()

std::string TSimpleAnalysis::GetLine ( int numbLine)
private

Skip subsequent empty lines read from fIn and returns the next not empty line.

param[in] numbLine - number of the input file line

Definition at line 398 of file TSimpleAnalysis.cxx.

◆ HandleExpressionConfig()

std::string TSimpleAnalysis::HandleExpressionConfig ( const std::string &  line)
private

Handle the expression lines of the input file in order to pass the elements to the members of the object.

param[in] line - TTreeFormula expression, either read form the configuration file or passed as expression to the constructor

Definition at line 98 of file TSimpleAnalysis.cxx.

◆ HandleInputFileNameConfig()

bool TSimpleAnalysis::HandleInputFileNameConfig ( const std::string &  line)
private

Returns false if not a tree name, otherwise sets the name of the tree.

param[in] line - line read from the input file

Definition at line 384 of file TSimpleAnalysis.cxx.

◆ Run()

bool TSimpleAnalysis::Run ( )

Execute all the TChain::Draw() as configured and stores the output histograms.

Returns true if the analysis succeeds.

Definition at line 264 of file TSimpleAnalysis.cxx.

◆ SetTreeName()

bool TSimpleAnalysis::SetTreeName ( )
private

Disambiguate tree name from first input file and set up fTreeName if it is empty.

Definition at line 234 of file TSimpleAnalysis.cxx.

Member Data Documentation

◆ fConfigFile

std::string TSimpleAnalysis::fConfigFile
private

Name of the configuration file.

Definition at line 36 of file TSimpleAnalysis.h.

◆ fHists

std::map<std::string, std::pair<std::string, std::string> > TSimpleAnalysis::fHists
private

The map contains in the first part the names of the histograms written in the output file, in the second part the pair of what is shown in the histograms and the cut applied on the variables.

Definition at line 44 of file TSimpleAnalysis.h.

◆ fIn

std::ifstream TSimpleAnalysis::fIn
private

Stream for the input file.

Definition at line 40 of file TSimpleAnalysis.h.

◆ fInputFiles

std::vector<std::string> TSimpleAnalysis::fInputFiles
private

.root input files

Definition at line 37 of file TSimpleAnalysis.h.

◆ fOutputFile

std::string TSimpleAnalysis::fOutputFile
private

Output file in which are stored the histograms.

Definition at line 38 of file TSimpleAnalysis.h.

◆ fTreeName

std::string TSimpleAnalysis::fTreeName
private

Name of the input tree.

Definition at line 39 of file TSimpleAnalysis.h.

Libraries for TSimpleAnalysis:

The documentation for this class was generated from the following files: