4 Utils3.py
Renata Kopecná edited this page 2022-02-02 09:31:17 +01:00

Helper functions originally created for the comparison tool. However, as there are many more smart functions, the file is sourced also by other python scripts. Be sure to always include Utils3.py correctly! If it complains, first check the path of your included Utils3.py.

Table of Contents

Classes

ShowArgumentsParser(argparse.ArgumentParser)

Class used for pretty parser error printouts

Global variables

intVarsList

A list of trree branches that are saved as integers

Functions

expressionList()

  • Return
    • A list of used expressions, used for pasring any input formula

isInt()

  • Parameters
    • variable=""
  • Return
    • True is the variable is stored as an integer, false otherwise

treeName()

  • Parameters
    • MC=False, TM=False, Preselected=False
  • Return
    • The correct tree name for given sample.

getOptionsDictionary(y)

  • Parameters
    • year
    • Run
    • magnet
    • MC
    • TM
    • ReferenceChannel
    • PHSP
    • Preselected
    • BDTed
    • sWeighted
    • bWeighted
    • b2Dweighted
    • weightBranch
    • KshortDecaysInVelo
    • UseLowQ2Range
  • Reurn
    • A dicitonary with all possible saved options in

checkYearSample()

  • Parameters
    • optionsDict
  • Return
    • Checks whether the selected data sample defined by optionsDict makes sense. If yes, returns True, otherwise False

checkYearSample()

  • Parameters
    • year,MC,ReferenceChannel,PHSP,KshortChannel
  • Return
    • Checks whether the selected data sample defined by the options makes sense. If yes, returns True, otherwise False

getTreePath()

  • Parameters
    • optionsDict, verbose
  • Return
    • Returns the path to the tree based on the optionsDict. Calls getPathForPython.

addToTChain()

Adds TTrees to TChain from file selected by optionsDict

  • Parameters
    • tree, optionsDict, verbose

addTMathTags()

  • Parameters
    • varName
  • Return
    • the varName ewith added "TMath::" so ROOT can function

list_of_DTF_vars ()

  • Return
    • A list of variables that can have a DTF suffix

replace_variables_to_DTF()

Pretty much appends "_DTF" to everything

  • Parameters
    • variable = ""
  • Return
    • the updated name of the variable (with "_DTF" appended)

getListOfUsedVariables(

Parses the desired cut on the given variable to be readable by python

  • Parameters
    • variable, cut
  • Return
    • List of branches that need to be loaded

evaluateCut()

  • Parameters
    • cut,variablesDict
  • Return
    • parses and evaluates the cut using eval()

makeVariablePythonFriendly()

Removes ROOT tags and lowers all the letters

  • Parameters
    • variable
  • Return
    • variable parsed to be readable by python

evaluateVariable()

  • Parameters
    • variable,variablesDict
  • Return
    • Evaluates the expression using the information from the branches

evaluateWeight()

  • Parameters
    • variablesDict,optionsDict
  • Return
    • weight branch name for the given optionsDict

datasetTag()

  • Parameters
    • optionsDict
  • Return
    • Tag (name) for the desired dataset

weightTag()

  • Parameters
    • optionsDict
  • Return
    • weight tag for the given optionsDict

KshortDecaysInVeloTag()

  • Parameters
    • KshortDecaysInVelo=False
  • Return
    • Empty string if K+pi0, otherwise '_LL' if KshortDecaysInVelo else '_DD'

variableTag()

  • Parameters
    • variable=""
  • Return
    • parsed and cleanedup variable name for saving the file. It is not perfext but works somewhat

histName()

  • Parameters
    • variable, optionsDict
  • Return
    • Name of the histogram to be saved

def stopWatch()

Prints the time passed between value and now.

  • Parameters
    • value

getTreeWithPairingBranch()

Adds the branch with the corresponding pairing function to the tree. Pairing function is a unique number calculated from the event and run numbers. This is calculated using the [Cantor pairing function](https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function)
  • Parameters
    • treeFile,tree,run,test
  • Return
    • The new tree file and the new tree

checkMCyear()

  • Parameters
    • year, ReferenceChannel, PHSP
  • Return
    • either the year or year 2016 if the 2015 sample is not available