Logo ROOT   6.08/07
Reference Guide
List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
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

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. More...
 
bool Configure ()
 This function has the aim of setting the arguments read from the input file. More...
 
bool Run ()
 Execute all the TChain::Draw() as configured and stores the output histograms. More...
 

Private Types

enum  EReadingWhat { kReadingOutput, kReadingTreeName, kReadingInput, kReadingExpressions }
 

Private Member Functions

std::string GetLine (int &numbLine)
 Skip subsequent empty lines read from fIn and returns the next not empty line. More...
 
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. More...
 
bool HandleInputFileNameConfig (const std::string &line)
 Returns false if not a tree name, otherwise sets the name of the tree. More...
 
bool SetTreeName ()
 Disambiguate tree name from first input file and set up fTreeName if it is empty. More...
 

Private Attributes

std::string fConfigFile
 Name of the configuration file. More...
 
std::map< std::string, std::pair< std::string, std::string > > fHists
 
std::ifstream fIn
 Stream for the input file. More...
 
std::vector< std::string > fInputFiles
 .root input files More...
 
std::string fOutputFile
 Output file in which are stored the histograms. More...
 
std::string fTreeName
 Name of the input tree. More...
 

#include <TSimpleAnalysis.h>

Member Enumeration Documentation

◆ EReadingWhat

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

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.


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