egammaMVACalib Class Reference

#include <egammaMVACalib.h>

Inheritance diagram for egammaMVACalib:
asg::AsgMessaging

List of all members.

Classes

class  NotifyDispatcher
struct  ReaderID
struct  VarFormula
struct  XmlVariableInfo

Public Types

enum  egammaType { egPHOTON, egELECTRON, NEGAMMATYPES }
enum  ParticleType {
  UNCONVERTED = 0, CONVERTED = 1, SiSi = 2, ELECTRON = 3,
  NPARTICLETYPES = 4, INVALIDPARTICLE = -1
}
enum  CalibrationType { correctEcluster, correctEaccordion, fullCalibration, NCalibrationTypes }
enum  ShiftType {
  NOSHIFT = 0, PEAKTOTRUE, MEANTOTRUE, MEDIANTOTRUE,
  MEAN10TOTRUE, MEAN20TOTRUE, MEDIAN10TOTRUE, MEDIAN20TOTRUE,
  NSHIFTCORRECTIONS
}
typedef std::map< TString,
TString > 
AdditionalInfoMap
typedef std::map< std::pair
< egammaMVACalib::ReaderID,
egammaMVACalib::ShiftType >
, TF1 * > 
ShiftMap

Public Member Functions

 egammaMVACalib (int particle, bool useNewBDTs=true, TString folder="", const TString &method="BDTG", int calibrationType=correctEaccordion, bool debug=false, const TString &etaBinVar="", const TString &energyBinVar="", const TString &particleTypeVar="", TString filePattern="", bool ignoreSpectators=true)
virtual ~egammaMVACalib ()
void setPeakCorrection (ShiftType shift_type)
void setPeakCorrection (TString shift_type)
void useClusterIf0 (bool useCluster=true)
void setDefinition (const TString &variable, const TString &expression)
void InitTree (TTree *tree, bool doNotify=true)
virtual void LoadVariables (int index)
float getMVAOutput (int index=0)
float getMVAEnergy (int index=0, ShiftType shift_type=NSHIFTCORRECTIONS)
float getMVAEnergyPhoton (float ph_rawcl_Es0, float ph_rawcl_Es1, float ph_rawcl_Es2, float ph_rawcl_Es3, float ph_cl_eta, float ph_cl_E, float ph_cl_etaCalo, float ph_cl_phiCalo, float ph_ptconv, float ph_pt1conv, float ph_pt2conv, int ph_convtrk1nPixHits, int ph_convtrk1nSCTHits, int ph_convtrk2nPixHits, int ph_convtrk2nSCTHits, float ph_Rconv)
float getMVAEnergyElectron (float el_rawcl_Es0, float el_rawcl_Es1, float el_rawcl_Es2, float el_rawcl_Es3, float el_cl_eta, float el_cl_E, float el_cl_etaCalo, float el_cl_phiCalo)
float * getAddress (const TString &input_name)
void setExternal (const TString &input_name)
void printValueInput ()
TTree * getMVAResponseTree (TTree *tree, int Nentries=-1, TString branchName="", TString copyBranches="input", int first_event=0, bool flatten=false, int update=10000)
float getShift (float Et, ReaderID key, ShiftType shift_type) const
const TTreeFormula * getFormula (const TString &variable)
TObjArray * getListOfBranches ()
void activateBranches ()
int getNdata ()
TH2Poly * getTH2Poly () const
void writeROOTfile (const TString &directory, int particle=(int) INVALIDPARTICLE)
TMVA::Reader * getReader (egammaMVACalib::ReaderID key)
egammaMVACalib::ReaderID getReaderID ()
MVAUtils::BDTgetBDT (egammaMVACalib::ReaderID key)

Static Public Member Functions

static void addBranchesFromFormula (TObjArray *branches, TTreeFormula *formula)
static TString getString (TObject *)
static TObjArray * getVariables (const TString &xmlFileName)
static TMVA::Reader * getDummyReader (const TString &xmlFileName)
static TString * getVariables (TMVA::Reader *reader)
static void addReaderInfoToArrays (TMVA::Reader *reader, TObjArray *trees, TObjArray *variables, int index)
static std::vector< double > get_radius (double eta)
static double get_shower_depth (double eta, double raw_cl_0, double raw_cl_1, double raw_cl_2, double raw_cl_3)

Protected Member Functions

TString getCalibTypeString ()
void getReaders (const TString &folder)
void getBDTs (const std::string &folder)
void setupReader (TMVA::Reader *reader, const TString &xml_filename)
void setupBDT (const TString &fileName)
void setupFormulasForReaderID ()
void predefineFormula (const TString &name, const TString &expression, const TString &varInfo, const TString &valueType="F")
bool parseFileName (const TString &fileName, egammaMVACalib::ReaderID &key)
bool parseFileName (const TString &fileName, egammaMVACalib::ParticleType &pType)
TString getBinName (const TString &binField)
int getBin (float etaMin, float etaMax, float energyMin, float energyMax)
void printReadersInfo () const
TTreeFormula * defineFormula (const TString &varName, const TString &expression, TTree *tree)
int getParticleType () const
int getBin () const
void printFormulae () const
void checkFormula (TTreeFormula *formula)
void defineInitialEnergyFormula ()
TTree * getOutputTree (TString copyBranches, bool deactivateFirst=true)
bool checkBin (int bin, float etaMin, float etaMax, float etMin, float etMax)
void defineShiftFormula (ReaderID key)
const TString & getShiftName (ShiftType shift) const
void defineClusterEnergyFormula ()
void checkShowerDepth (TTree *tree)
int getNreaders () const
TTree * createInternalTree (egammaType, TTree *tree)

Static Protected Member Functions

static std::vector
< XmlVariableInfo
parseXml (const TString &xmlFilename)
static std::vector
< XmlVariableInfo
parseVariables (TXMLEngine *xml, void *node, const TString &nodeName)
static egammaMVACalib::ParticleType getParticleType (const TString &s)
static AdditionalInfoMap getUserInfo (const TString &xmlfilename)

Protected Attributes

egammaMVACalib::egammaType m_egammaType
bool m_useNewBDTs
 electron or photon
TString fMethodName
 use egamma::BDT or TMVA::Reader
egammaMVACalib::CalibrationType m_calibrationType
 BDTG.
TString m_etaVar
 correct Eaccordion, Ecluster...
TString m_energyVar
TString m_particleTypeVar
bool m_ignoreSpectators
bool m_hasEnergyBins
int m_binMultiplicity
bool m_clusterEif0
float * m_particleType
 Use clusterE if MVA response is 0.
float * m_eta
float * m_energy
float * m_initialEnergy
TH2Poly * m_hPoly
TTree * m_tree
TTree * m_input_tree
bool m_useInternalTree
TPRegexp * m_fileNamePattern
float m_mvaOutput
float m_dummyFloat
ShiftType m_shiftType
std::map
< egammaMVACalib::ReaderID,
egammaMVACalib::AdditionalInfoMap > 
m_additional_infos
ShiftMap m_shiftMap
std::map
< egammaMVACalib::ReaderID,
TMVA::Reader * > 
m_readers
std::map
< egammaMVACalib::ReaderID,
MVAUtils::BDT * > 
m_BDTs
std::map< TString,
egammaMVACalib::VarFormula
m_formulae
TTreeFormula * m_clusterFormula
float m_ph_rawcl_Es0
float m_ph_rawcl_Es1
float m_ph_rawcl_Es2
float m_ph_rawcl_Es3
float m_ph_cl_eta
float m_ph_cl_E
float m_ph_ptconv
float m_ph_pt1conv
float m_ph_pt2conv
float m_ph_cl_etaCalo
float m_ph_cl_phiCalo
int m_ph_convtrk1nPixHits
int m_ph_convtrk1nSCTHits
int m_ph_convtrk2nPixHits
int m_ph_convtrk2nSCTHits
float m_ph_rawcl_calibHitsShowerDepth
float m_ph_Rconv
float m_el_rawcl_Es0
float m_el_rawcl_Es1
float m_el_rawcl_Es2
float m_el_rawcl_Es3
float m_el_cl_E_TileGap3
float m_el_cl_eta
float m_el_cl_E
float m_el_cl_etaCalo
float m_el_cl_phiCalo
float m_el_cl_phi
float m_el_rawcl_calibHitsShowerDepth

Detailed Description

MVA calibration for electrons and photons authors: Bruno Lenzi, Ruggero Turra : 2012 - 2013

Computes the energy of electrons or photons from a set of input variables like the energy deposits in each layer of the calorimeter, the position of the EM shower, conversion information for converted photons, etc. using a set of corrections stored in xml files (TMVA outputs) or ROOT files (storing custom Boosted Regression Trees, extracted from TMVA)

There are two ways to get the MVA response:

There is one MVA for each bin (particle, eta, Et accordion) defined by ReaderID and stored in a TH2Poly (eta, Et)

The README file in this package contains information about the installation and usage see also https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/EgammaMVACalibration


Constructor & Destructor Documentation

egammaMVACalib::egammaMVACalib ( int  particle,
bool  useNewBDTs = true,
TString  folder = "",
const TString &  method = "BDTG",
int  calibrationType = correctEaccordion,
bool  debug = false,
const TString &  etaBinVar = "",
const TString &  energyBinVar = "",
const TString &  particleTypeVar = "",
TString  filePattern = "",
bool  ignoreSpectators = true 
)

Constructor

Parameters:
particle : photon or electron,
See also:
egammaType
Parameters:
newBDTs : use new BDTs or TMVA ones
folder : where to find the xml or ROOT files
method : optimisation method (BDTG by default)
calibrationType :
See also:
CalibrationType
Parameters:
etaBinVar : variable used to define the eta binning
energyBinVar : variable used to define the energy binning
particleTypeVar : variable used to define the particle type (unconv, SiSi, etc)
fileName : the expected pattern of the xml files
ignoreSpectators : do not create formulae for the spectators
egammaMVACalib::~egammaMVACalib (  )  [virtual]

Destructor


Member Function Documentation

void egammaMVACalib::activateBranches (  ) 

Activate the branches used in the calculation of the MVA response

void egammaMVACalib::addBranchesFromFormula ( TObjArray *  branches,
TTreeFormula *  formula 
) [static]

Called when a TChain changes TTree (overridden from TObject) Add the branches used by the given formula to the given array

void egammaMVACalib::addReaderInfoToArrays ( TMVA::Reader *  reader,
TObjArray *  trees,
TObjArray *  variables,
int  index 
) [static]

Add the information of a TMVA::Reader with "BDTG" method to TObjArrays

bool egammaMVACalib::checkBin ( int  bin,
float  etaMin,
float  etaMax,
float  etMin,
float  etMax 
) [protected]

Check if the given bin is consistent with the previous definitions

void egammaMVACalib::checkFormula ( TTreeFormula *  formula  )  [protected]

Update and check the formula if a new tree was loaded

void egammaMVACalib::checkShowerDepth ( TTree *  tree  )  [protected]

Check if shower depth variable is present or if it needs to be calculated

TTree * egammaMVACalib::createInternalTree ( egammaType  egamma_type,
TTree *  tree 
) [protected]

Create an internal TTree when InitTree(0) is called

void egammaMVACalib::defineClusterEnergyFormula (  )  [protected]

Define the formula to get the cluster energy

TTreeFormula * egammaMVACalib::defineFormula ( const TString &  varName,
const TString &  expression,
TTree *  tree 
) [protected]

Define a formula according to the given name and expression, delete the previous one

void egammaMVACalib::defineInitialEnergyFormula (  )  [protected]

Define the formula that gives the initial energy estimate depending on the calibrationType: Ecluster, Eaccordion or nothing (Efull)

void egammaMVACalib::defineShiftFormula ( ReaderID  key  )  [protected]

Define the formulae for the given key

float * egammaMVACalib::getAddress ( const TString &  input_name  ) 

return the address of a particular input

MVAUtils::BDT* egammaMVACalib::getBDT ( egammaMVACalib::ReaderID  key  )  [inline]

Return the BDT that corresponds to the given key (or null pointer)

void egammaMVACalib::getBDTs ( const std::string &  folder  )  [protected]

Instantiate and setup one MVAUtils::BDT for each bin

int egammaMVACalib::getBin (  )  const [protected]

Return the eta / Et bin for the current entry using the etaBinVar(iable)/energy...

int egammaMVACalib::getBin ( float  etaMin,
float  etaMax,
float  energyMin,
float  energyMax 
) [protected]

Return the bin that corresponds to the interval of eta/Et covered by a weights file. Add the bin if not previously defined

TString egammaMVACalib::getBinName ( const TString &  binField  )  [protected]

Return the variable / field associated to the given string (or an empty string). Used by parseFileName to define the field associated to each part of fileName.

TString egammaMVACalib::getCalibTypeString (  )  [protected]

Return a string representing the calibration type (Eaccordion, Ecluster, ...)

TMVA::Reader * egammaMVACalib::getDummyReader ( const TString &  xmlFileName  )  [static]

Instantiate a dummy TMVA::Reader

const TTreeFormula* egammaMVACalib::getFormula ( const TString &  variable  )  [inline]

Return the TTreeFormula associated to the given variable (or a null pointer)

TObjArray * egammaMVACalib::getListOfBranches (  ) 

Return a list of the TBranches used in the calculation of the MVA response

float egammaMVACalib::getMVAEnergy ( int  index = 0,
ShiftType  shift_type = NSHIFTCORRECTIONS 
)

Get the MVA energy estimation (= MVA output * initialEnergy) for the given index Return 0 if the TMVA::Reader or the intialEnergy formula cannot be found It is the user responsibility to call TTree::GetEntry before this command If shift_type is not specified it uses the one set with setPeakCorrection function.

float egammaMVACalib::getMVAOutput ( int  index = 0  ) 

Get the MVA output for the given index (or 0 if the corresponding TMVA::Reader is not found) It is the user responsibility to call TTree::GetEntry before this command

Get the MVA output (or 0 if the correponding TMVA::Reader is not found)

TTree * egammaMVACalib::getMVAResponseTree ( TTree *  tree,
int  Nentries = -1,
TString  branchName = "",
TString  copyBranches = "input",
int  first_event = 0,
bool  flatten = false,
int  update = 10000 
)

Return a tree with the MVA response for each event If the input tree uses vector branches, the MVA response is stored as a vector, except if flatten is false

Parameters:
tree the input tree
Nentries entries to process
branchName Name of the output branch (method name by default)
copyBranches Branches to copy to MVA tree, comma-separated (input branches by default)
update Display the progress after N events
int egammaMVACalib::getNdata (  ) 

Get the number of particles in the current event. Used by egammaMVACalibMulti. TTree::GetEntry has to be called beforehand

TTree * egammaMVACalib::getOutputTree ( TString  copyBranches,
bool  deactivateFirst = true 
) [protected]

Used by getMVAResponseTree: clone input tree, activating the branches defined by <copyBranches> and deactivating all of them first if <deactivateFirst>=true

egammaMVACalib::ParticleType egammaMVACalib::getParticleType ( const TString &  s  )  [static, protected]

Return the ParticleType corresponding to the given string, used by parseFileName

TMVA::Reader* egammaMVACalib::getReader ( egammaMVACalib::ReaderID  key  )  [inline]

Return the reader that corresponds to the given key (or null pointer)

egammaMVACalib::ReaderID egammaMVACalib::getReaderID (  ) 

Return the key that corresponds to the current entry (LoadVariables or getMVAEnergy has to be called beforehand)

void egammaMVACalib::getReaders ( const TString &  folder  )  [protected]

Instantiate one reader for each xml file and set them up, calling setupReader for each. Also initialize the additional information from the xmls

Loop over the files in the folder and instantiate one TMVA::Reader for each file Files that do not match the required pattern are removed

float egammaMVACalib::getShift ( float  Et,
ReaderID  key,
ShiftType  shift_type 
) const

Return the shift corresponding to the ReaderID and type

const TString & egammaMVACalib::getShiftName ( ShiftType  shift  )  const [protected]

Return the string that corresponds to the shift

TString egammaMVACalib::getString ( TObject *  obj  )  [static]

Return TString from TObjString

TH2Poly * egammaMVACalib::getTH2Poly (  )  const

Return a clone of the TH2Poly object used for defining the binning

egammaMVACalib::AdditionalInfoMap egammaMVACalib::getUserInfo ( const TString &  xmlfilename  )  [static, protected]

Return the user infomation added in the xml files in the <UserInfo> section as a dictionary

TString * egammaMVACalib::getVariables ( TMVA::Reader *  reader  )  [static]

Get the list of variables separated by comma

TObjArray * egammaMVACalib::getVariables ( const TString &  xmlFileName  )  [static]

Return the list of variables used by a TMVA xml file

void egammaMVACalib::InitTree ( TTree *  tree,
bool  doNotify = true 
)

Define all the TTreeFormula instances needed for calculating the MVA response If doNotify is true and a chain is passed, call Notify each time the tree changes

void egammaMVACalib::LoadVariables ( int  index  )  [virtual]

Evaluate each formula defined by the readers and store the output in the corresponding float variable (

See also:
VarFormula) It is the user responsibility to call TTree::GetEntry before this command

Set the variables for the reader, copying the results from the formulae

bool egammaMVACalib::parseFileName ( const TString &  fileName,
egammaMVACalib::ParticleType &  pType 
) [protected]

Called by getBDTs to define the particle associated to the given file. Return true if the file matches the expected pattern

bool egammaMVACalib::parseFileName ( const TString &  fileName,
egammaMVACalib::ReaderID key 
) [protected]

Called by getReaders to define the eta/energy range associated to the given file. Return true if the file matches the expected pattern and the definition of the fields and ranges was successful

std::vector< egammaMVACalib::XmlVariableInfo > egammaMVACalib::parseVariables ( TXMLEngine *  xml,
void *  node,
const TString &  nodeName 
) [static, protected]

Called by parseXml to extract information about the variables and spectators

std::vector< egammaMVACalib::XmlVariableInfo > egammaMVACalib::parseXml ( const TString &  xmlFilename  )  [static, protected]

Parse a xml file. Return a vector where each element is a XmlVariableInfo containing information about the variables and spectators. The full filename must be passed.

void egammaMVACalib::predefineFormula ( const TString &  name,
const TString &  expression,
const TString &  varInfo,
const TString &  valueType = "F" 
) [protected]

Pre-define a formula: store its name, type and definition in m_formulae but do not instantiate TTreeFormula (done in InitTree)

void egammaMVACalib::printFormulae (  )  const [protected]

Print the definition of each formula

void egammaMVACalib::printReadersInfo (  )  const [protected]

Print information about the readers: the total number, eta and energy ranges

void egammaMVACalib::printValueInput (  ) 

Print the values of the previous evaluation for debugging

void egammaMVACalib::setDefinition ( const TString &  variable,
const TString &  expression 
)

Define an expression to replace the given variable

void egammaMVACalib::setExternal ( const TString &  input_name  ) 

do not compute the variable from the TTree. The user should change it for every event using getAddress to reference the internal variable

void egammaMVACalib::setPeakCorrection ( TString  shift_type  ) 

Set the peak correction by a capital string

void egammaMVACalib::setupBDT ( const TString &  fileName  )  [protected]

Instantiate and setup BDT from ROOT file

void egammaMVACalib::setupFormulasForReaderID (  )  [protected]

Setup the functions and pointers used to define the key for each reader

void egammaMVACalib::setupReader ( TMVA::Reader *  reader,
const TString &  xml_filename 
) [protected]

Call parseXml, define formulae add variables associated to the reader. The full filename must be passed

void egammaMVACalib::useClusterIf0 ( bool  useCluster = true  )  [inline]

Use cluster energy if MVA response is 0

void egammaMVACalib::writeROOTfile ( const TString &  directory,
int  particle = (int) INVALIDPARTICLE 
)

Write a ROOT file (MVACalib_<particle>.root) to be used with the new BDT model


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 1 Dec 2017 for RootCore Packages by  doxygen 1.6.1