Update 'Utils3.py'

Renata Kopecná 2022-02-02 09:29:29 +01:00
parent a537d86b97
commit c7edd75253

@ -14,19 +14,19 @@ A list of trree branches that are saved as integers
## Functions ## Functions
### def expressionList() ### expressionList()
* **Return** * **Return**
* A list of used expressions, used for pasring any input formula * A list of used expressions, used for pasring any input formula
### def isInt() ### isInt()
* **Parameters** * **Parameters**
* variable="" * variable=""
* **Return** * **Return**
* True is the variable is stored as an integer, false otherwise * True is the variable is stored as an integer, false otherwise
### def treeName() ### treeName()
* **Parameters** * **Parameters**
@ -34,7 +34,7 @@ A list of trree branches that are saved as integers
* **Return** * **Return**
* The correct tree name for given sample. * The correct tree name for given sample.
### def getOptionsDictionary(y) ### getOptionsDictionary(y)
* **Parameters** * **Parameters**
* year * year
* Run * Run
@ -55,14 +55,14 @@ A list of trree branches that are saved as integers
* A dicitonary with all possible saved options in * A dicitonary with all possible saved options in
### def checkYearSample() ### checkYearSample()
* **Parameters** * **Parameters**
* optionsDict * optionsDict
* **Return** * **Return**
* Checks whether the selected data sample defined by optionsDict makes sense. If yes, returns True, otherwise False * Checks whether the selected data sample defined by optionsDict makes sense. If yes, returns True, otherwise False
### def checkYearSample() ### checkYearSample()
* **Parameters** * **Parameters**
* year,MC,ReferenceChannel,PHSP,KshortChannel * year,MC,ReferenceChannel,PHSP,KshortChannel
@ -70,7 +70,7 @@ A list of trree branches that are saved as integers
* Checks whether the selected data sample defined by the options makes sense. If yes, returns True, otherwise False * Checks whether the selected data sample defined by the options makes sense. If yes, returns True, otherwise False
### def getTreePath() ### getTreePath()
* **Parameters** * **Parameters**
* optionsDict, verbose * optionsDict, verbose
* **Return** * **Return**
@ -78,46 +78,26 @@ A list of trree branches that are saved as integers
### def addToTChain() ### addToTChain()
Adds TTrees to TChain from file selected by optionsDict
* **Parameters** * **Parameters**
* tree, optionsDict, verbose * tree, optionsDict, verbose
* **Return**
filePath, filePath2 = getTreePath(optionsDict=optionsDict, verbose=verbose) ### addTMathTags()
#Get first file name
if(optionsDict['BDTed'] or optionsDict['sWeighted'] or optionsDict['bWeighted'] or optionsDict['b2Dweighted']):
print ("[INFO]\tOpening", filePath)
tree.Add(filePath)
else:
if (optionsDict['magnet']=="both"):
print ("[INFO]\tOpening", filePath)
tree.Add(filePath)
print ("[INFO]\tOpening", filePath2)
tree.Add(filePath2)
else:
print ("[INFO]\tOpening", filePath)
tree.Add(filePath)
### def addTMathTags()
* **Parameters** * **Parameters**
* varName * varName
* **Return** * **Return**
* * the varName ewith added "TMath::" so ROOT can function
for expr in expressionList():
varName = varName.replace(expr,"TMath::"+expr)
return varName
### def list_of_DTF_vars () ### list_of_DTF_vars ()
* **Return** * **Return**
* A list of variables that can have a DTF suffix * A list of variables that can have a DTF suffix
### def replace_variables_to_DTF() ### replace_variables_to_DTF()
Pretty much appends \"_DTF\" to everything Pretty much appends \"_DTF\" to everything
* **Parameters** * **Parameters**
* variable = "" * variable = ""
@ -125,104 +105,84 @@ Pretty much appends \"_DTF\" to everything
* the updated name of the variable (with \"_DTF\" appended) * the updated name of the variable (with \"_DTF\" appended)
### getListOfUsedVariables(
### def getListOfUsedVariables(
Parses the desired cut on the given variable to be readable by python Parses the desired cut on the given variable to be readable by python
* **Parameters** * **Parameters**
* variable, cut * variable, cut
* **Return** * **Return**
* List of branches that need to be loaded * List of branches that need to be loaded
* *
### def evaluateCut() ### evaluateCut()
* **Parameters** * **Parameters**
* cut,variablesDict * cut,variablesDict
* **Return** * **Return**
* parses and evaluates the cut using eval() * parses and evaluates the cut using eval()
### def makeVariablePythonFriendly() ### makeVariablePythonFriendly()
Removes ROOT tags and lowers all the letters Removes ROOT tags and lowers all the letters
* **Parameters** * **Parameters**
* variable * variable
* **Return** * **Return**
* variable parsed to be readable by python * variable parsed to be readable by python
### def evaluateVariable() ### evaluateVariable()
* **Parameters** * **Parameters**
* variable,variablesDict * variable,variablesDict
* **Return** * **Return**
* * Evaluates the expression using the information from the branches
tmp = variable
for varName,varValue in variablesDict.items():
tmp = tmp.replace(str(varName),str(varValue[0]))
tmp = makeVariablePythonFriendly(tmp)
return numexpr.evaluate(tmp).item()
### def evaluateWeight() #TODO ### evaluateWeight()
* **Parameters** * **Parameters**
* variablesDict,optionsDict * variablesDict,optionsDict
* **Return** * **Return**
* weight for the given optionsDict * weight branch name for the given optionsDict
### datasetTag()
### def datasetTag()
* **Parameters** * **Parameters**
* optionsDict * optionsDict
* **Return** * **Return**
* Tag (name) for the desired dataset * Tag (name) for the desired dataset
### def weightTag() ### weightTag()
* **Parameters** * **Parameters**
* optionsDict * optionsDict
* **Return** * **Return**
* weight tag for the given optionsDict * weight tag for the given optionsDict
* *
### def KshortDecaysInVeloTag() ### KshortDecaysInVeloTag()
* **Parameters** * **Parameters**
* KshortDecaysInVelo=False * KshortDecaysInVelo=False
* **Return** * **Return**
* Empty string if K+pi0, otherwise '\_LL' if KshortDecaysInVelo else '\_DD' * Empty string if K+pi0, otherwise '\_LL' if KshortDecaysInVelo else '\_DD'
### def variableTag() ### variableTag()
* **Parameters** * **Parameters**
* variable="" * variable=""
* **Return** * **Return**
* parsed and cleanedup variable name for saving the file. It is not perfext but works somewhat * parsed and cleanedup variable name for saving the file. It is not perfext but works somewhat
### def histName() ### histName()
* **Parameters** * **Parameters**
* variable, optionsDict * variable, optionsDict
* **Return** * **Return**
* * Name of the histogram to be saved
name = variableTag(variable)
name = name.replace("TMath::","") #remove functions
for expr in (expressionList()): #For whatever reason I have to but the brackets there
name = name.replace(expr.lower(),expr) #Add capitals to functions
name = "Hist_" + str(optionsDict['year']) + "_" + datasetTag(optionsDict)
name = name + KshortDecaysInVeloTag(optionsDict) + weightTag(optionsDict)
return name
### def stopWatch() ### def stopWatch()
Prints the time passed between `value` and now. Prints the time passed between `value` and now.
* **Parameters** * **Parameters**
* value * value
### getTreeWithPairingBranch()
### def 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) 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** * **Parameters**
* treeFile,tree,run,test * treeFile,tree,run,test
* **Return** * **Return**
* The new tree file and the new tree * The new tree file and the new tree
### def checkMCyear() ### checkMCyear()
* **Parameters** * **Parameters**
* year, ReferenceChannel, PHSP * year, ReferenceChannel, PHSP
* **Return** * **Return**
* either the year or year 2016 if the 2015 sample is not available
if ((not KshortChannel) and (not ReferenceChannel) and (not PHSP) and year == 2015): return 2016
else: return year