Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • cvazquez/Urania
  • nsahoo/Urania
  • tnanut/Urania
  • gmeier/Urania
  • lhcb/Urania
5 results
Show changes
Commits on Source (46)
Showing
with 3702 additions and 2021 deletions
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
check-copyright:
image: gitlab-registry.cern.ch/ci-tools/ci-worker:cc7
script:
- curl -o lb-check-copyright "https://gitlab.cern.ch/lhcb-core/LbDevTools/raw/master/LbDevTools/SourceTools.py?inline=false"
- python lb-check-copyright origin/master
check-formatting:
image: gitlab-registry.cern.ch/lhcb-docker/style-checker
script:
- if [ ! -e .clang-format ] ; then
- curl -o .clang-format "https://gitlab.cern.ch/lhcb-core/LbDevTools/raw/master/LbDevTools/data/default.clang-format?inline=false"
- echo '.clang-format' >> .gitignore
- git add .gitignore
- fi
- curl -o lb-format "https://gitlab.cern.ch/lhcb-core/LbDevTools/raw/master/LbDevTools/SourceTools.py?inline=false"
- python lb-format --format-patch apply-formatting.patch origin/master
artifacts:
paths:
- apply-formatting.patch
when: on_failure
expire_in: 1 week
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.5)
#---------------------------------------------------------------
# Load macros and functions for Gaudi-based projects
find_package(GaudiProject)
......
# This file defines "owners" for the code in the Urania project.
#
# See the GitLab documentation for the syntax and motivation:
#
# https://docs.gitlab.com/ee/user/project/code_owners.html
#
# PIDCalib
/PIDCalib/PIDPerfScripts @dhill @smalde
/PIDCalib/PIDPerfTools @dhill @smalde
# B2DXFitters
/PhysFit/B2DXFitters @adudziak @jobutter @kheinick
# Meerkat
/PhysTools/Meerkat @poluekt
# TrackCalib
/TrackCalib @rekopecn @farchill
# System configuration
/UraniaSys @cvazquez # Current Urania maintainer
/ReleaseNotes @cvazquez # Current Urania maintainer
# How to work with Urania
For development purposes of any of the packages hosted under Urania, please follow these [instructions](https://lhcb-core-doc.web.cern.ch/lhcb-core-doc/Development.html#satellite-projects).
<b>IMPORTANT:</b> do not accept MRs before allowing them to run in the nightlies. Please label your MR as ```all-slots``` (or with the label corresponding to the slot you want the MR to be ran on).
<b>IMPORTANT:</b> if you plan to add a new package, please send an e-mail first to [<b>lhcb-urania-developers@cern.ch</b>](mailto:lhcb-urania-developers@cern.ch) to let the maintainer know.
In any case, there are two important rules you must remember:
1. <b>Never clone the whole project for development purposes.</b> Please follow the instructions above.
2. <b>Always checkout the packages from the master branch.</b> If not, when asking for a Merge Request (MR), incompatibilities will appear and thus the MR will be closed.
Apart from project maintainers, also certain package maintainers are allowed to accept and revert MR. These people are listed in the [CODEOWNERS](https://gitlab.cern.ch/lhcb/Urania/blob/master/CODEOWNERS) file.
If you are a package developer and you think you should be granted these permissions as well, please send an email to the mailing list above.
This diff is collapsed.
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
################################################################################
# Package: PIDPerfScripts
################################################################################
......
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import print_function
from __future__ import absolute_import
import re
import math
from PIDPerfScripts.Exceptions import *
from TupleDataset import *
from .TupleDataset import *
def BannedVariables(var=None):
h={
'V2ProbNNK': '{particle}_V2ProbNNK',
'V2ProbNNpi': '{particle}_V2ProbNNpi',
'V2ProbNNp': '{particle}_V2ProbNNp',
'V2ProbNNmu': '{particle}_V2ProbNNmu',
'V2ProbNNe': '{particle}_V2ProbNNe',
'V2ProbNNghost': '{particle}_V2ProbNNghost',
'V3ProbNNK': '{particle}_V3ProbNNK',
'V3ProbNNpi': '{particle}_V3ProbNNpi',
'V3ProbNNp': '{particle}_V3ProbNNp',
'V3ProbNNmu': '{particle}_V3ProbNNmu',
'V3ProbNNe': '{particle}_V3ProbNNe',
'V3ProbNNghost': '{particle}_V3ProbNNghost'
}
h = {
'V2ProbNNK': '{particle}_V2ProbNNK',
'V2ProbNNpi': '{particle}_V2ProbNNpi',
'V2ProbNNp': '{particle}_V2ProbNNp',
'V2ProbNNmu': '{particle}_V2ProbNNmu',
'V2ProbNNe': '{particle}_V2ProbNNe',
'V2ProbNNghost': '{particle}_V2ProbNNghost',
'V3ProbNNK': '{particle}_V3ProbNNK',
'V3ProbNNpi': '{particle}_V3ProbNNpi',
'V3ProbNNp': '{particle}_V3ProbNNp',
'V3ProbNNmu': '{particle}_V3ProbNNmu',
'V3ProbNNe': '{particle}_V3ProbNNe',
'V3ProbNNghost': '{particle}_V3ProbNNghost'
}
if var == None:
return h
else:
return h[var]
return h[var]
#Load the DataSetVariables from the list defined in TupleDataset
def DataSetVariables(var=None):
h = vars_dataset
if var == None:
return h
else:
return h[var]
h = vars_dataset
if var == None:
return h
else:
return h[var]
def GetVarNames():
varArr = [varName for varName, varNameInDataset in DataSetVariables().iteritems()]
varArr = [
varName for varName, varNameInDataset in DataSetVariables().items()
]
varArr.sort()
return varArr
def GetRICHPIDRealPartTypes():
return ("K", "Pi", "P", "e")
def GetRICHPIDPartTypes():
return GetRICHPIDRealPartTypes()+GetProtonPIDPartTypes()+GetDDPIDPartTypes() + ("K_DsPhi","K_DSt3Pi","K_Phi","K_Omega","Pi_KS","Pi_DSt3Pi","e_B_Jpsi")
return GetRICHPIDRealPartTypes() + GetProtonPIDPartTypes(
) + GetDDPIDPartTypes() + ("K_DsPhi", "K_DSt3Pi", "K_Phi", "K_Omega",
"Pi_KS", "Pi_DSt3Pi", "e_B_Jpsi")
def GetMuonPIDRealPartTypes():
return ("Mu",)
return ("Mu", )
def GetProtonPIDPartTypes():
return ("P_LcfB", "P_IncLc", "P_TotLc") + ("P_Sigmac0","P_Sigmacpp","P_B_Jpsi")
return ("P_LcfB", "P_IncLc", "P_TotLc") + ("P_Sigmac0", "P_Sigmacpp",
"P_B_Jpsi")
def GetProtonPIDRealPartTypes():
return ("P",)
return ("P", )
def GetDDPIDPartTypes():
return ("Pi_DD", "K_DD", "P_DD")
def GetMuonPIDPartTypes():
return GetMuonPIDRealPartTypes()+tuple(['{0}_MuonUnBiased'.format(p) for p in GetRICHPIDRealPartTypes()]) + ("Mu_B_Jpsi","Mu_nopt")
return GetMuonPIDRealPartTypes() + tuple(
['{0}_MuonUnBiased'.format(p)
for p in GetRICHPIDRealPartTypes()]) + ("Mu_B_Jpsi", "Mu_nopt")
def GetRealPartTypes():
return GetRICHPIDRealPartTypes()+GetMuonPIDRealPartTypes()
return GetRICHPIDRealPartTypes() + GetMuonPIDRealPartTypes()
def GetPartTypes():
return GetRICHPIDPartTypes()+GetMuonPIDPartTypes()
return GetRICHPIDPartTypes() + GetMuonPIDPartTypes()
def GetRealPartType(PartName):
CheckPartType(PartName)
......@@ -77,6 +109,7 @@ def GetRealPartType(PartName):
else:
return 'Mu'
# N.B. The following method will need to be changed once the
# Lambda_c proton samples are included
def GetMotherName(PartName):
......@@ -84,11 +117,11 @@ def GetMotherName(PartName):
if PartName == 'K' or PartName == 'Pi':
return 'DSt'
elif PartName == 'K_DSt3Pi' or PartName == 'Pi_DSt3Pi':
return 'DSt3Pi'
return 'DSt3Pi'
elif PartName == 'K_DsPhi':
return 'DsPhi'
elif PartName == 'K_Phi':
return 'Phi'
elif PartName == 'K_Phi':
return 'Phi'
elif PartName == 'K_Omega':
return 'Omega'
elif PartName == 'K_DD':
......@@ -121,12 +154,13 @@ def GetMotherName(PartName):
return 'TotLc'
elif PartName == 'P_IncLc':
return 'IncLc'
#Jpsi muon sample with no pT cut
#Jpsi muon sample with no pT cut
elif PartName == 'Mu_nopt':
return 'Jpsi_nopt'
return 'Jpsi_nopt'
else:
return 'Jpsi'
# N.B. The following method will need to be changed once the
# Lambda_c proton samples are included - its going to come from the mother but not for electrons and muons as the are both from jpsis
def GetWorkspaceName(PartName):
......@@ -147,7 +181,8 @@ def GetWorkspaceName(PartName):
elif MType == 'Jpsi':
return 'JpsiCalib'
else:
print 'No workspace found,this is working group production'
print('No workspace found,this is working group production')
def IsMuonUnBiased(PartName):
CheckPartType(PartName)
......@@ -156,29 +191,30 @@ def IsMuonUnBiased(PartName):
else:
return False
def GetRecoVer(StripVer):
CheckStripVer(StripVer)
if StripVer=='13b':
if StripVer == '13b':
return 10
elif StripVer=='15':
elif StripVer == '15':
return 11
elif StripVer=='17':
elif StripVer == '17':
return 12
elif StripVer=='22':
elif StripVer == '22':
return '15a'
elif StripVer=='23Val':
elif StripVer == '23Val':
return '15a'
elif StripVer=='23':
elif StripVer == '23':
return '15a'
elif StripVer=='5TeV':
elif StripVer == '5TeV':
return '15a'
elif StripVer=='21_MCTuneV4':
elif StripVer == '21_MCTuneV4':
return '14V4'
elif StripVer=='21r1_MCTuneV4':
elif StripVer == '21r1_MCTuneV4':
return '14V4'
elif StripVer=='23_MCTuneV1':
return '15aV1'
elif StripVer=='26':
elif StripVer == '23_MCTuneV1':
return '15aV1'
elif StripVer == '26':
return '16'
else:
return 14
......@@ -186,18 +222,19 @@ def GetRecoVer(StripVer):
def GetKnownFunctions():
ret = dir(math)
ret += ["abs","fabs"]
ret += ["abs", "fabs"]
return ret
def CheckCutVarsInTree(cuts,tree):
def CheckCutVarsInTree(cuts, tree):
if cuts in [None, ""]:
return True
math_chars = re.compile("\\s*([-=|&\\(\\)\\+\\*/<>\\[\\]!\\s]+)\\s*")
split_cuts = re.split(math_chars,cuts)
split_cuts = re.split(math_chars, cuts)
#print "CheckCutVarsInTree():", split_cuts
for var in split_cuts:
found = False
if re.match(math_chars,var):
if re.match(math_chars, var):
#print var,"is mathematical"
continue
elif var in GetKnownFunctions():
......@@ -212,26 +249,28 @@ def CheckCutVarsInTree(cuts,tree):
pass
#print var,"is not mathematical or a function"
tree_vars = tree.GetListOfLeaves()
for i in xrange(len(tree_vars)):
for i in range(len(tree_vars)):
if tree_vars[i].GetName() == var:
#print var,"==",tree_vars[i].GetName()
found = True
break
if not found:
raise ValueError("Variable '%s' in cut string '%s' not found in TTree %s!"%(var,cuts,tree.GetName()))
raise ValueError(
"Variable '%s' in cut string '%s' not found in TTree %s!" %
(var, cuts, tree.GetName()))
return False
#print "Everything is bon!"
return True
def CheckCuts(cuts,strip):
def CheckCuts(cuts, strip):
simple_cuts = cuts
for i in "()[]&!|><=:+-*/":
simple_cuts = simple_cuts.replace(i," ")
simple_cuts = simple_cuts.replace(i, " ")
simple_cuts = [x for x in simple_cuts.split(" ") if x!=""]
valid_varibles = [x for x,y in DataSetVariables().iteritems()]
banned_varibles = [x for x,y in BannedVariables().iteritems()]
simple_cuts = [x for x in simple_cuts.split(" ") if x != ""]
valid_varibles = [x for x, y in DataSetVariables().items()]
banned_varibles = [x for x, y in BannedVariables().items()]
valid_varibles.sort()
......@@ -240,111 +279,145 @@ def CheckCuts(cuts,strip):
float(var)
except ValueError:
if var not in valid_varibles:
print "'%s' is not a valid variable"%var
print "Known variables are:"
print valid_varibles
print("'%s' is not a valid variable" % var)
print("Known variables are:")
print(valid_varibles)
return False
if strip=='23_MCTuneV1' or strip=='26':
if strip == '23_MCTuneV1' or strip == '26':
if var in banned_varibles:
print ""
print "**********************************************************"
print "'%s' is banned for RUN2"%var
print "Please use either MC15TuneV1 (V1ProbNN) or MC12TuneV4 (V4ProbNN)"
print "For futher information, please check "
print "https://twiki.cern.ch/twiki/bin/view/LHCb/PIDCalibPackage#PIDCalib_sample_for_2015_and_201"
print "*********************************************************"
print ""
print ""
print("")
print(
"**********************************************************"
)
print("'%s' is banned for RUN2" % var)
print(
"Please use either MC15TuneV1 (V1ProbNN) or MC12TuneV4 (V4ProbNN)"
)
print("For futher information, please check ")
print(
"https://twiki.cern.ch/twiki/bin/view/LHCb/PIDCalibPackage#PIDCalib_sample_for_2015_and_201"
)
print(
"*********************************************************"
)
print("")
print("")
return False
return True
def FlatternPlots(Plots):
ret = []
if isinstance(Plots,list):
for plot in Plots:
ret.extend(FlatternPlots(plot))
if isinstance(Plots, list):
for plot in Plots:
ret.extend(FlatternPlots(plot))
else:
return [Plots]
return ret
def CheckRealPartType(PartName):
ValidPartNames=GetRealPartTypes()
ValidPartNames = GetRealPartTypes()
if PartName not in ValidPartNames:
msg=("Invalid particle type '{0}'. "
"Allowed types are {1}").format(
PartName, str(ValidPartNames))
msg = ("Invalid particle type '{0}'. "
"Allowed types are {1}").format(PartName, str(ValidPartNames))
raise TypeError(msg)
def CheckPartType(PartName):
ValidPartNames=GetPartTypes()
ValidPartNames = GetPartTypes()
if PartName not in ValidPartNames:
msg=("Invalid particle type '{0}'. "
"Allowed types are {1}").format(
PartName, str(ValidPartNames))
msg = ("Invalid particle type '{0}'. "
"Allowed types are {1}").format(PartName, str(ValidPartNames))
raise TypeError(msg)
def CheckMagPol(MagPol):
ValidMagPols=("MagUp", "MagDown")
ValidMagPols = ("MagUp", "MagDown")
if MagPol not in ValidMagPols:
msg=("Invalid magnet polarity '{0}'. "
"Allowed polarities are {1}").format(MagPol, str(ValidMagPols))
msg = ("Invalid magnet polarity '{0}'. "
"Allowed polarities are {1}").format(MagPol, str(ValidMagPols))
raise TypeError(msg)
def CheckStripVer(StripVer):
ValidStripVers=("13b", "15", "17", "20", "20r1", "20_MCTuneV2","23_MCTuneV1","26",
"20r1_MCTuneV2","20_MCTunev3", "21r1","21","22", "23Val","23","5TeV","21_MCTuneV4","21r1_MCTuneV4","Turbo15","Turbo16","Turbo17","Turbo18","pATurbo15","ApTurbo15","pATurbo16","ApTurbo16","Electron15","Electron16","Electron17","Electron18")
if StripVer=='23':
msg=("""
Attention: Stripping 23 is now replaced by Stripping 23_MCTuneV1. Please specify 23_MCTuneV1 as sample version.""")
raise TypeError(msg)
if StripVer=='23_MCTuneV1' or StripVer=='26' or StripVer=='Turbo15' or StripVer=='Turbo16' or StripVer=='Turbo17' or StripVer=='Turbo18' or StripVer=='pATurbo15' or StripVer=='ApTurbo15' or StripVer=='pATurbo16' or StripVer=='ApTurbo16' or StripVer=='Electron15' or StripVer=='Electron16' or StripVer=='Electron17' or StripVer=='Electron18':
print "***************************************************************************************************************************"
print "INFO : ProbNN versions MC12TuneV2 and MC12TuneV3 should not be used for Run 2 data - advise to use MC12TuneV4 or MC15TuneV1"
print "***************************************************************************************************************************"
ValidStripVers = ("13b", "15", "17", "20", "20r1", "20_MCTuneV2",
"23_MCTuneV1", "26", "20r1_MCTuneV2", "20_MCTunev3",
"21r1", "21", "22", "23Val", "23", "5TeV", "21_MCTuneV4",
"21r1_MCTuneV4", "Turbo15", "Turbo16", "Turbo17",
"Turbo18", "pATurbo15", "ApTurbo15", "pATurbo16",
"ApTurbo16", "Electron15", "Electron16", "Electron17",
"Electron18")
if StripVer == '23':
msg = ("""
Attention: Stripping 23 is now replaced by Stripping 23_MCTuneV1. Please specify 23_MCTuneV1 as sample version."""
)
raise TypeError(msg)
if StripVer == '23_MCTuneV1' or StripVer == '26' or StripVer == 'Turbo15' or StripVer == 'Turbo16' or StripVer == 'Turbo17' or StripVer == 'Turbo18' or StripVer == 'pATurbo15' or StripVer == 'ApTurbo15' or StripVer == 'pATurbo16' or StripVer == 'ApTurbo16' or StripVer == 'Electron15' or StripVer == 'Electron16' or StripVer == 'Electron17' or StripVer == 'Electron18':
print(
"***************************************************************************************************************************"
)
print(
"INFO : ProbNN versions MC12TuneV2 and MC12TuneV3 should not be used for Run 2 data - advise to use MC12TuneV4 or MC15TuneV1"
)
print(
"***************************************************************************************************************************"
)
if StripVer not in ValidStripVers:
msg=("Invalid stripping version '{0}'. "
"Allowed versions are {1}").format(StripVer, str(ValidStripVers))
msg = ("Invalid stripping version '{0}'. "
"Allowed versions are {1}").format(StripVer,
str(ValidStripVers))
raise TypeError(msg)
def CheckStripVerPartNameMagPol(StripVer,PartName,MagPol):
Valid_pA_Ap_PartNames = ["K","P","Pi","Mu"]
def CheckStripVerPartNameMagPol(StripVer, PartName, MagPol):
Valid_pA_Ap_PartNames = ["K", "P", "Pi", "Mu"]
Valid_Electron_PartNames = ["e_B_Jpsi"]
if 'pA' in StripVer or 'Ap' in StripVer:
if 'Up' in MagPol:
msg=("MagUp data does not exist in the pA/Ap dataset. Please select MagDown and run again.")
raise TypeError(msg)
if PartName not in Valid_pA_Ap_PartNames:
msg=("Invalid choice of sample for pA/Ap data. Please use one of the following: K, Pi, Mu, P")
if 'Up' in MagPol:
msg = (
"MagUp data does not exist in the pA/Ap dataset. Please select MagDown and run again."
)
raise TypeError(msg)
if PartName not in Valid_pA_Ap_PartNames:
msg = (
"Invalid choice of sample for pA/Ap data. Please use one of the following: K, Pi, Mu, P"
)
raise TypeError(msg)
if 'Electron' in StripVer:
if PartName not in Valid_Electron_PartNames:
msg=("Invalid choice of sample for 2015-2018 electron data. Please use the following: e_B_Jpsi")
raise TypeError(msg)
if PartName not in Valid_Electron_PartNames:
msg = (
"Invalid choice of sample for 2015-2018 electron data. Please use the following: e_B_Jpsi"
)
raise TypeError(msg)
#Check if the user has selected Turbo15 and Turbo16 along with e_B_Jpsi. Warn them to use Electron15 or Electron16 instead.
if 'Turbo15' in StripVer or 'Turbo16' in StripVer or 'Turbo17' in StripVer or 'Turbo18' in StripVer:
if PartName in Valid_Electron_PartNames:
msg=("The electron samples in Turbo15/16/17/18 should NOT be used! Please switch to using Electron15/16/17/18")
raise TypeError(msg)
if PartName in Valid_Electron_PartNames:
msg = (
"The electron samples in Turbo15/16/17/18 should NOT be used! Please switch to using Electron15/16/17/18"
)
raise TypeError(msg)
def CheckVarName(VarName):
ValidVarNames=GetVarNames()
ValidVarNames = GetVarNames()
if VarName not in ValidVarNames:
msg=("Invalid binning variable '{0}'. "
"Allowed variables are {1}").format(VarName, str(ValidVarNames))
msg = ("Invalid binning variable '{0}'. "
"Allowed variables are {1}").format(VarName, str(ValidVarNames))
raise TypeError(msg)
def CheckIsTurbo(StripVer):
ValidTurboNames=("Turbo15","Turbo16","Turbo17","Turbo18","pATurbo15","ApTurbo15","pATurbo16","ApTurbo16")
if StripVer not in ValidTurboNames:
ValidTurboNames = ("Turbo15", "Turbo16", "Turbo17", "Turbo18", "pATurbo15",
"ApTurbo15", "pATurbo16", "ApTurbo16")
if StripVer not in ValidTurboNames:
return False
return True
#def GetTurboPath(StripVer,MagPol):
# CheckStripVer(StripVer)
# CheckMagPol(MagPol)
# CheckMagPol(MagPol)
# if StripVer=='Turbo15':
# if MagPol=='MagDown':
# return "/LHCb/Collision15/Beam6500GeV-VeloClosed-MagDown/Real Data/Reco15a/Turbo02/PIDCalibTuples2r1/95100000/PIDCALIB.ROOT"
......
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import print_function
#Added BKK functionality for retrieving Run 2 WGP nTuples
from DIRAC.Core.Base import Script
Script.initialize()
from DIRAC.Resources.Storage.StorageElement import StorageElement
from DIRAC.Resources.Storage.StorageElement import StorageElement
import DIRAC
from LHCbDIRAC.BookkeepingSystem.Client.BookkeepingClient import BookkeepingClient
from LHCbDIRAC.BookkeepingSystem.Client.BookkeepingClient import BookkeepingClient
from DIRAC.DataManagementSystem.Client.DataManager import DataManager
#Read in the magnet polarity and the data version, along with the user path for writing the output to file
......@@ -14,111 +25,114 @@ MagPolarity = sys.argv[2]
PartName = sys.argv[3]
path = sys.argv[4]
rm = DataManager()
bkClient = BookkeepingClient()
bkDict = {}
bkDict = {}
#args = Script.getPositionalArgs()
#print args
bkDict[ 'ConfigName' ] = 'LHCb'
bkDict[ 'EventTypeId' ] = '95100000'
bkDict['ConfigName'] = 'LHCb'
bkDict['EventTypeId'] = '95100000'
bkDict['FileType'] = 'PIDCALIB.ROOT'
bkDict['DataTakingConditions'] = 'Beam6500GeV-VeloClosed-'+MagPolarity
bkDict['DataTakingConditions'] = 'Beam6500GeV-VeloClosed-' + MagPolarity
#Proton-Proton collision data
if StripVer=="Turbo15" or StripVer=="Turbo16" or StripVer=="Turbo17" or StripVer=="Turbo18":
year = StripVer.replace('Turbo','')
bkDict[ 'ConfigVersion' ] = 'Collision'+year
elif StripVer=="pATurbo15" or StripVer=="pATurbo16":
year = StripVer.replace('pATurbo','')
bkDict[ 'ConfigVersion' ] = 'Protonion'+year
elif StripVer=="ApTurbo15" or StripVer=="ApTurbo16":
year = StripVer.replace('ApTurbo','')
bkDict[ 'ConfigVersion' ] = 'Ionproton'+year
if StripVer == "Turbo15" or StripVer == "Turbo16" or StripVer == "Turbo17" or StripVer == "Turbo18":
year = StripVer.replace('Turbo', '')
bkDict['ConfigVersion'] = 'Collision' + year
elif StripVer == "pATurbo15" or StripVer == "pATurbo16":
year = StripVer.replace('pATurbo', '')
bkDict['ConfigVersion'] = 'Protonion' + year
elif StripVer == "ApTurbo15" or StripVer == "ApTurbo16":
year = StripVer.replace('ApTurbo', '')
bkDict['ConfigVersion'] = 'Ionproton' + year
reco = ''
turbo = ''
version = ''
merge = ''
if StripVer=="Turbo15" or StripVer=="Turbo16" or StripVer=="Turbo17" or StripVer=="Turbo18":
if StripVer == "Turbo15" or StripVer == "Turbo16" or StripVer == "Turbo17" or StripVer == "Turbo18":
############
### 2015 ###
############
if year == '15':
reco = '15a'
turbo = '02'
version = '5r1'
merge = '05'
reco = '15a'
turbo = '02'
version = '5r1'
merge = '05'
############
### 2016 ###
############
elif year == '16':
reco = '16'
turbo = '02a'
version = '9r3'
#Jpsinopt files reproduced in dedicated production
if(PartName=="Mu_nopt"):
version = '9r3p1'
merge = '05'
reco = '16'
turbo = '02a'
version = '9r3'
#Jpsinopt files reproduced in dedicated production
if (PartName == "Mu_nopt"):
version = '9r3p1'
merge = '05'
############
### 2017 ###
############
elif year == '17':
reco = '17'
turbo = '04'
version = '9r1'
#Jpsinopt files reproduced in dedicated production
if(PartName=="Mu_nopt"):
version = '9r2p1'
merge = '05'
reco = '17'
turbo = '04'
version = '9r1'
#Jpsinopt files reproduced in dedicated production
if (PartName == "Mu_nopt"):
version = '9r2p1'
merge = '05'
############
### 2018 ###
############
elif year == '18':
reco = '18'
turbo = '05'
version = '9r2'
#Jpsinopt files reproduced in dedicated production
if(PartName=="Mu_nopt"):
version = '9r2p1'
merge = '05'
elif StripVer=="pATurbo15" or StripVer=="pATurbo16" or StripVer=="ApTurbo15" or StripVer=="ApTurbo16":
reco = '18'
turbo = '05'
version = '9r2'
#Jpsinopt files reproduced in dedicated production
if (PartName == "Mu_nopt"):
version = '9r2p1'
merge = '05'
elif StripVer == "pATurbo15" or StripVer == "pATurbo16" or StripVer == "ApTurbo15" or StripVer == "ApTurbo16":
############
### 2015 ###
############
if year == '15':
reco = '15pLead'
turbo = '03pLead'
version = '5r0'
merge = '01'
reco = '15pLead'
turbo = '03pLead'
version = '5r0'
merge = '01'
############
### 2016 ###
############
elif year == '16':
reco = '16pLead'
turbo = '03pLead'
version = '5r1'
merge = '05'
reco = '16pLead'
turbo = '03pLead'
version = '5r1'
merge = '05'
bkDict[
'ProcessingPass'] = '/Real Data/Reco' + reco + '/Turbo' + turbo + '/PIDCalibTuples' + version + '/PIDMerge' + merge
bkDict[ 'ProcessingPass' ] = '/Real Data/Reco'+reco+'/Turbo'+turbo+'/PIDCalibTuples'+version+'/PIDMerge'+merge
file = bkClient.getFilesWithGivenDataSets(bkDict)
#file = bkClient.getVisibleFilesWithMetadata(bkDict)
#print file
files = file['Value']
print "There are " + str(len(files)) + " WGP nTuples in this dataset"
files = file['Value']
print("There are " + str(len(files)) + " WGP nTuples in this dataset")
#print files
#print "============================================="
newFileList = []
for fileName in files:
newFileList += [fileName.replace ( '/lhcb/LHCb/', "root://eoslhcb.cern.ch//eos/lhcb/grid/prod/lhcb/LHCb/" )]
#print " ".join(newFileList)
newFileList += [
fileName.replace(
'/lhcb/LHCb/',
"root://eoslhcb.cern.ch//eos/lhcb/grid/prod/lhcb/LHCb/")
]
#print " ".join(newFileList)
#Write the file list to a json file for reading back in
import pickle
with open(path+"/files.txt", 'wb') as fp:
with open(path + "/files.txt", 'wb') as fp:
pickle.dump(newFileList, fp)
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import print_function
import os
#class _OCDSvars(object):
class _OCDSvars:
_fileList = None
_envVar = 0 #0 means unchecked, None means non-existent
_fileList = None
_envVar = 0 #0 means unchecked, None means non-existent
def _warningMessage ():
print ""
print 30*'*' + " ! ! ! WARNING ! ! ! " + 29*'*'
print "! You are using NON DEFAULT SAMPLES as the OVERRIDECALIBDATASTORE was set"
print "! Please make sure you understand why this warning appears."
print 80*'*'
print ""
raw_input ( "Press ENTER if you wish to continue..." )
def _warningMessage():
print("")
print(30 * '*' + " ! ! ! WARNING ! ! ! " + 29 * '*')
print(
"! You are using NON DEFAULT SAMPLES as the OVERRIDECALIBDATASTORE was set"
)
print("! Please make sure you understand why this warning appears.")
print(80 * '*')
print("")
input("Press ENTER if you wish to continue...")
def _defineFileList ():
# _warningMessage()
_OCDSvars._fileList = []
f = file ( _getEnvVar () )
if not f:
raise Exception( "Error: File " + f + " not found." )
def _defineFileList():
# _warningMessage()
_OCDSvars._fileList = []
f = file(_getEnvVar())
if not f:
raise Exception("Error: File " + f + " not found.")
for entry in f:
_OCDSvars._fileList += [
entry.replace ( '\n', '' ).replace ('\r', '')
]
for entry in f:
_OCDSvars._fileList += [entry.replace('\n', '').replace('\r', '')]
def _getFileList ():
if _OCDSvars._fileList == None:
_defineFileList()
return _OCDSvars._fileList
def _getFileList():
if _OCDSvars._fileList == None:
_defineFileList()
return _OCDSvars._fileList
def _getEnvVar ():
if _OCDSvars._envVar == 0:
_OCDSvars._envVar = os.getenv ( "OVERRIDECALIBDATASTORE" )
return _OCDSvars._envVar
def _getEnvVar():
if _OCDSvars._envVar == 0:
_OCDSvars._envVar = os.getenv("OVERRIDECALIBDATASTORE")
return _OCDSvars._envVar
def _isEnvVarDefined ():
return _getEnvVar() != None and _getEnvVar() != ""
def GetDictFiles ( runMin, runMax, maxFiles , verbose ):
if not _isEnvVarDefined() : return []
def _isEnvVarDefined():
return _getEnvVar() != None and _getEnvVar() != ""
if maxFiles == None or maxFiles < 0:
maxFiles = 100000
maxIndex = len(_getFileList())
if maxIndex == None or int(maxIndex) > int(maxFiles):
maxIndex = maxFiles
def GetDictFiles(runMin, runMax, maxFiles, verbose):
if not _isEnvVarDefined(): return []
return _getFileList()[:int(maxIndex)]
if maxFiles == None or maxFiles < 0:
maxFiles = 100000
def GetDictIndex ( runMin, runMax, maxFiles , verbose ):
if not _isEnvVarDefined() : return None
maxIndex = len(_getFileList())
if maxIndex == None or int(maxIndex) > int(maxFiles):
maxIndex = maxFiles
if maxFiles == None or maxFiles < 0:
maxFiles = 100000
return _getFileList()[:int(maxIndex)]
maxIndex = len(_getFileList())
if maxIndex == None or maxIndex > maxFiles:
maxIndex = maxFiles
print "Min Index: 0; Max Index: " + str (maxIndex -1)
def GetDictIndex(runMin, runMax, maxFiles, verbose):
if not _isEnvVarDefined(): return None
ret = {
'minIndex' : 0,
'maxIndex' : maxIndex-1
}
return ret
if maxFiles == None or maxFiles < 0:
maxFiles = 100000
maxIndex = len(_getFileList())
if maxIndex == None or maxIndex > maxFiles:
maxIndex = maxFiles
def GetFileName ( index ):
if not _isEnvVarDefined(): return None
print "Required index: " + str ( index )
return _getFileList() [ index ]
print("Min Index: 0; Max Index: " + str(maxIndex - 1))
ret = {'minIndex': 0, 'maxIndex': maxIndex - 1}
return ret
if __name__ == '__main__':
print "GetDictIndex ( 0, 100, 10, True )"
print GetDictIndex ( 0, 100, 10, True )
print "-----------"
print "GetFileName ( 1 )"
print GetFileName ( 1 )
def GetFileName(index):
if not _isEnvVarDefined(): return None
print("Required index: " + str(index))
return _getFileList()[index]
if __name__ == '__main__':
print("GetDictIndex ( 0, 100, 10, True )")
print(GetDictIndex(0, 100, 10, True))
print("-----------")
print("GetFileName ( 1 )")
print(GetFileName(1))
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import print_function
from __future__ import division
from past.utils import old_div
import ROOT
from ROOT import RooFit
from ROOT import vector
......@@ -9,16 +23,21 @@ import sys
from PIDPerfScripts.Definitions import *
from PIDPerfScripts.Binning import GetBinScheme
def MakePerfPlotsList(PartName, DataSet, DLLCutList, BinningScheme,
Plots=None, verbose=True):
def MakePerfPlotsList(PartName,
DataSet,
DLLCutList,
BinningScheme,
Plots=None,
verbose=True):
#======================================================================
# Declare instances of PerfCalculator tool : (class)(instance of class)
#======================================================================
ROOT.gSystem.Load('libRooStats.so')
# ROOT.gSystem.Load('libCintex.so')
# cintex=ROOT.Cintex
# cintex.Enable()
# ROOT.gSystem.Load('libCintex.so')
# cintex=ROOT.Cintex
# cintex.Enable()
ROOT.gSystem.Load('libPIDPerfToolsLib.so')
ROOT.gSystem.Load('libPIDPerfToolsDict.so')
Calc = ROOT.PerfCalculator(ROOT.GenericDataSet)(DataSet)
......@@ -26,7 +45,7 @@ def MakePerfPlotsList(PartName, DataSet, DLLCutList, BinningScheme,
#======================================================================
# Define array of lists, one for each DLL cut
#======================================================================
subPlots = [ [] for j in range(len(DLLCutList)) ]
subPlots = [[] for j in range(len(DLLCutList))]
#======================================================================
# Loop over DLL cuts, and append TH1F to appropriate subPlot-list
......@@ -35,17 +54,12 @@ def MakePerfPlotsList(PartName, DataSet, DLLCutList, BinningScheme,
dataset_index = len(Plots[0]) if Plots else 0
for index, cut in enumerate(DLLCutList):
parsed_cut = cut.strip().replace("/", "_div_")
histname = "%s_%s_%d" %(PartName, parsed_cut, dataset_index)
Dummy = Calc.Perf_Hist(histname,
cut,
BinningScheme,
False,
5,
verbose)
histname = "%s_%s_%d" % (PartName, parsed_cut, dataset_index)
Dummy = Calc.Perf_Hist(histname, cut, BinningScheme, False, 5, verbose)
subPlots[index].append(Dummy)
#Dummy.Delete()
if verbose:
print 'subPlots: ', subPlots
print('subPlots: ', subPlots)
del Calc
#======================================================================
......@@ -53,23 +67,26 @@ def MakePerfPlotsList(PartName, DataSet, DLLCutList, BinningScheme,
# Plots = [ [0,1,...]_DLLK>A, [0,1,...]_DLLK>B, ... ]
#======================================================================
# Need to resolve the following line....
NewPlots = map(add, Plots, subPlots) if Plots else subPlots
NewPlots = list(map(add, Plots, subPlots)) if Plots else subPlots
if verbose:
print 'NewPlots: ', dataset_index, NewPlots
print('NewPlots: ', dataset_index, NewPlots)
del Plots
return NewPlots
def MakePerfPlotsListPyth(PartName, DataSet, DLLCutList, BinningScheme,
Plots=None, verbose=True):
def MakePerfPlotsListPyth(PartName,
DataSet,
DLLCutList,
BinningScheme,
Plots=None,
verbose=True):
#print "in perfplots list pyth"
ROOT.TH1.SetDefaultSumw2(True)
dataset_index = len(Plots[0]) if Plots else 0
PlotsByCut = []
#print " abit further"
print BinningScheme.at(0)
print(BinningScheme.at(0))
if BinningScheme.size() > 0:
BinSchema1 = BinningScheme.at(0)
......@@ -81,64 +98,59 @@ def MakePerfPlotsListPyth(PartName, DataSet, DLLCutList, BinningScheme,
#print "understood bin scheme"
for index, cut in enumerate(DLLCutList):
parsed_cut = cut.strip().replace("/", "_div_")
histname = "%s_%s_%d" %(PartName, parsed_cut, dataset_index)
histname = "%s_%s_%d" % (PartName, parsed_cut, dataset_index)
# print "understood the Cut list"
# print "understood the Cut list"
YVarArgVar = ROOT.RooCmdArg.none()
ZVarArgVar = ROOT.RooCmdArg.none()
if BinningScheme.size() > 1:
YVarArgVar = RooFit.YVar( DataSet.Get_Param(BinSchema2.GetName()), RooFit.Binning(BinSchema2) )
YVarArgVar = RooFit.YVar(
DataSet.Get_Param(BinSchema2.GetName()),
RooFit.Binning(BinSchema2))
if BinningScheme.size() > 2:
ZVarArgVar = RooFit.ZVar( DataSet.Get_Param(BinSchema3.GetName()), RooFit.Binning(BinSchema3) )
ZVarArgVar = RooFit.ZVar(
DataSet.Get_Param(BinSchema3.GetName()),
RooFit.Binning(BinSchema3))
TotalHist = ROOT.RooAbsData.createHistogram(DataSet,
"TotalHist_"+histname,
TotalHist = ROOT.RooAbsData.createHistogram(
DataSet, "TotalHist_" + histname,
DataSet.Get_Param(BinSchema1.GetName()),
RooFit.Binning(BinSchema1),
YVarArgVar,
ZVarArgVar
)
RooFit.Binning(BinSchema1), YVarArgVar, ZVarArgVar)
PassedHist = ROOT.RooAbsData.createHistogram(DataSet,
"PassedHist_"+histname,
PassedHist = ROOT.RooAbsData.createHistogram(
DataSet, "PassedHist_" + histname,
DataSet.Get_Param(BinSchema1.GetName()),
RooFit.Binning(BinSchema1),
RooFit.Cut( DataSet.ReplaceVarNamesInCuts(cut) ),
YVarArgVar,
ZVarArgVar
)
RooFit.Cut(DataSet.ReplaceVarNamesInCuts(cut)), YVarArgVar,
ZVarArgVar)
if BinningScheme.size() > 2:
RatioHist = ROOT.TH3F(
histname, histname,
BinSchema1.numBins(), BinSchema1.array(),
BinSchema2.numBins(), BinSchema2.array(),
BinSchema3.numBins(), BinSchema3.array()
)
BinSchemas = [BinSchema1,BinSchema2,BinSchema3]
AxisTitles = [RatioHist.SetXTitle,RatioHist.SetYTitle,RatioHist.SetZTitle]
RatioHist = ROOT.TH3F(histname, histname, BinSchema1.numBins(),
BinSchema1.array(), BinSchema2.numBins(),
BinSchema2.array(), BinSchema3.numBins(),
BinSchema3.array())
BinSchemas = [BinSchema1, BinSchema2, BinSchema3]
AxisTitles = [
RatioHist.SetXTitle, RatioHist.SetYTitle, RatioHist.SetZTitle
]
elif BinningScheme.size() > 1:
RatioHist = ROOT.TH2F(
histname, histname,
BinSchema1.numBins(), BinSchema1.array(),
BinSchema2.numBins(), BinSchema2.array()
)
BinSchemas = [BinSchema1,BinSchema2]
AxisTitles = [RatioHist.SetXTitle,RatioHist.SetYTitle]
RatioHist = ROOT.TH2F(histname, histname, BinSchema1.numBins(),
BinSchema1.array(), BinSchema2.numBins(),
BinSchema2.array())
BinSchemas = [BinSchema1, BinSchema2]
AxisTitles = [RatioHist.SetXTitle, RatioHist.SetYTitle]
elif BinningScheme.size() > 0:
RatioHist = ROOT.TH1F(
histname, histname,
BinSchema1.numBins(), BinSchema1.array()
)
RatioHist = ROOT.TH1F(histname, histname, BinSchema1.numBins(),
BinSchema1.array())
BinSchemas = [BinSchema1]
AxisTitles = [RatioHist.SetXTitle]
for scheme, setTitle in zip( BinSchemas, AxisTitles ):
for scheme, setTitle in zip(BinSchemas, AxisTitles):
title = DataSet.Get_Param(scheme.GetName()).GetTitle()
unit = DataSet.Get_Param(scheme.GetName()).getUnit().strip()
if unit != "":
title += " [%s]" % ( unit )
title += " [%s]" % (unit)
# print "-----"
# print setTitle
# DataSet.Get_Param(scheme.GetName()).Print()
......@@ -147,31 +159,32 @@ def MakePerfPlotsListPyth(PartName, DataSet, DLLCutList, BinningScheme,
# print scheme.GetName()
setTitle(title)
# print "-----"
#RatioHist = PassedHist.Clone(histname)
RatioHist.Divide(PassedHist,TotalHist,1.0,1.0,"B")
RatioHist.Divide(PassedHist, TotalHist, 1.0, 1.0, "B")
#print "done some dividing"
if BinningScheme.size() > 2:
pidTable = ROOT.PIDTable(RatioHist, BinSchema1, BinSchema2, BinSchema3)
pidTable = ROOT.PIDTable(RatioHist, BinSchema1, BinSchema2,
BinSchema3)
elif BinningScheme.size() > 1:
pidTable = ROOT.PIDTable(RatioHist, BinSchema1, BinSchema2)
elif BinningScheme.size() > 0:
pidTable = ROOT.PIDTable(RatioHist, BinSchema1)
#print "pidTable made"
#print "pidTable made"
#pidTable.PrintTable(sys.stdout, False)
#sys.stdout.flush()
#print "but not printed the table"
PlotsByCut.append([[RatioHist,TotalHist,PassedHist]])
PlotsByCut.append([[RatioHist, TotalHist, PassedHist]])
NewPlots = map(add, Plots, PlotsByCut) if Plots else PlotsByCut
NewPlots = list(map(add, Plots, PlotsByCut)) if Plots else PlotsByCut
if verbose:
print 'PlotsByCut: ', PlotsByCut
print('PlotsByCut: ', PlotsByCut)
return NewPlots
def MakePIDResultList(DataSet, DLLCutList, PIDResults, verbose=True):
print PIDResults
print(PIDResults)
#======================================================================
# Declare instances of PerfCalculator tool : (class)(instance of class)
#======================================================================
......@@ -188,10 +201,11 @@ def MakePIDResultList(DataSet, DLLCutList, PIDResults, verbose=True):
#======================================================================
# Calculate Efficiency
#======================================================================
Dummy = Calc.Perf(DLLCutList,False) #, verbose)
Dummy = Calc.Perf(DLLCutList, False) #, verbose)
PIDResults.append(Dummy)
print PIDResults
print(PIDResults)
def WeightedAveragePIDResults(PIDResults, verbose=False):
#======================================================================
......@@ -199,17 +213,18 @@ def WeightedAveragePIDResults(PIDResults, verbose=False):
# perform weighted average for each index, returning a list of
# [[Eff_0, Err_0], [Eff_1, Err_1], ... , [Eff_n, Err_n]]
#======================================================================
nresults=PIDResults[0].size()
nresults = PIDResults[0].size()
CombPIDResult = []
if nresults==0:
msg=("Failed to perform weighted average of PID results. "
"No results in PIDResult::Container.")
if nresults == 0:
msg = ("Failed to perform weighted average of PID results. "
"No results in PIDResult::Container.")
warnings.warn(msg)
return CombPIDResult
for result in PIDResults:
if result.size()!=nresults:
raise ValueError('PIDResult::Container objects are of differing size')
if result.size() != nresults:
raise ValueError(
'PIDResult::Container objects are of differing size')
for ieff in range(0, nresults):
#print eff
......@@ -217,50 +232,54 @@ def WeightedAveragePIDResults(PIDResults, verbose=False):
Eff_Denom = 0.0
##Err_InSq = 0.0
for iresult, result in enumerate(PIDResults):
eff=result[ieff].Eff
err=result[ieff].Err_Lo
if err==0.:
msg=("Got PIDResult::Container result (index {0:d}, result {1:d}) "
"with zero error. This result will be excluded from the "
"weighted average").format(ieff, iresult)
eff = result[ieff].Eff
err = result[ieff].Err_Lo
if err == 0.:
msg = (
"Got PIDResult::Container result (index {0:d}, result {1:d}) "
"with zero error. This result will be excluded from the "
"weighted average").format(ieff, iresult)
warnings.warn(msg)
continue
Eff_Num += (1.0*eff)/(err*err)
Eff_Denom += 1.0/(err*err)
Eff_Num += old_div((1.0 * eff), (err * err))
Eff_Denom += 1.0 / (err * err)
##Err_InSq += 1.0/(err*err)
if Eff_Denom==0.0:
msg=("Got PIDResult::Container element (index {0:d}) "
"with zero error. This index will be excluded from the list of "
"averaged PID results").format(ieff)
if Eff_Denom == 0.0:
msg = (
"Got PIDResult::Container element (index {0:d}) "
"with zero error. This index will be excluded from the list of "
"averaged PID results").format(ieff)
warnings.warn(msg)
continue
CombPIDResult.append([Eff_Num/Eff_Denom,sqrt(1.0/Eff_Denom)])
CombPIDResult.append(
[old_div(Eff_Num, Eff_Denom),
sqrt(1.0 / Eff_Denom)])
if verbose:
msg=("PIDResult::Container index {idx:d}"
", weighted efficiency=({eff:.3f}+/-{err:.3f})%").format(
idx=ieff, eff=eff*100.0, err=err*100.0)
print msg
msg = ("PIDResult::Container index {idx:d}"
", weighted efficiency=({eff:.3f}+/-{err:.3f})%").format(
idx=ieff, eff=eff * 100.0, err=err * 100.0)
print(msg)
##sqrt(1/Err_InSq)])
#print CombPIDResult
return CombPIDResult
def SimpleAveragePIDResults(CombPIDResults_a, CombPIDResults_b):
#======================================================================
# Perform the simple average of CombPIDResults_a[i] with
# CombPIDResults_b[i] and return another list of type
# [[Eff_0, Err_0], [Eff_1, Err_1], ... , [Eff_n, Err_n]]
#======================================================================
if len(CombPIDResults_a)!=len(CombPIDResults_b):
print '**** Efficiency lists of differing size ****'
if len(CombPIDResults_a) != len(CombPIDResults_b):
print('**** Efficiency lists of differing size ****')
sys.exit(1)
CombPIDResult = []
for i in range(0, len(CombPIDResults_a)):
Eff = (CombPIDResults_a[i][0] + CombPIDResults_b[i][0])/2
Err_Sq = pow(CombPIDResults_a[i][1]/2,2) + pow(CombPIDResults_b[i][1]/2,2)
Eff = old_div((CombPIDResults_a[i][0] + CombPIDResults_b[i][0]), 2)
Err_Sq = pow(old_div(CombPIDResults_a[i][1], 2), 2) + pow(
old_div(CombPIDResults_b[i][1], 2), 2)
CombPIDResult.append([Eff, sqrt(Err_Sq)])
return CombPIDResult
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import print_function
from __future__ import division
from past.utils import old_div
import ROOT
from array import array
def MakeAveragePlot(Plots,oldStyleAverage=False):
def MakeAveragePlot(Plots, oldStyleAverage=False):
#======================================================================
# Loop over plots in subPlots and append average plot
# oldStyleAverage enables a bad way of calculating the average which
......@@ -12,36 +27,44 @@ def MakeAveragePlot(Plots,oldStyleAverage=False):
SumTotalsPlot = None
SumPassedPlot = None
if len(Plots)>0 and isinstance(Plots[0],list):
if len(Plots) > 0 and isinstance(Plots[0], list):
if oldStyleAverage:
print ""
print "Warning: using old style of average calculation. Efficiencies determined this way are incorrect if the efficiency is near zero."
print ""
for (average,total,passed) in Plots:
print("")
print(
"Warning: using old style of average calculation. Efficiencies determined this way are incorrect if the efficiency is near zero."
)
print("")
for (average, total, passed) in Plots:
average.SetBit(ROOT.TH1.kIsAverage)
if CombPlot is None:
CombPlot = average.Clone(average.GetName().replace('_0', '_All'))
SumTotalsPlot = total.Clone(total.GetName().replace('_0', '_All'))
SumPassedPlot = passed.Clone(passed.GetName().replace('_0', '_All'))
CombPlot = average.Clone(average.GetName().replace(
'_0', '_All'))
SumTotalsPlot = total.Clone(total.GetName().replace(
'_0', '_All'))
SumPassedPlot = passed.Clone(passed.GetName().replace(
'_0', '_All'))
else:
CombPlot.Add(average)
SumTotalsPlot.Add(total)
SumPassedPlot.Add(passed)
Plots.append([CombPlot,SumTotalsPlot,SumPassedPlot])
Plots.append([CombPlot, SumTotalsPlot, SumPassedPlot])
else:
print " Using new style average "
for (average,total,passed) in Plots:
print(" Using new style average ")
for (average, total, passed) in Plots:
#plot.SetBit(ROOT.TH1.kIsAverage)
if CombPlot is None:
#print plot.GetName()
CombPlot = average.Clone(average.GetName().replace('_0', '_All'))
SumTotalsPlot = total.Clone(total.GetName().replace('_0', '_All'))
SumPassedPlot = passed.Clone(passed.GetName().replace('_0', '_All'))
CombPlot = average.Clone(average.GetName().replace(
'_0', '_All'))
SumTotalsPlot = total.Clone(total.GetName().replace(
'_0', '_All'))
SumPassedPlot = passed.Clone(passed.GetName().replace(
'_0', '_All'))
else:
SumTotalsPlot.Add(total)
SumPassedPlot.Add(passed)
CombPlot.Divide(SumPassedPlot,SumTotalsPlot,1.0,1.0,"B")
Plots.append([CombPlot,SumTotalsPlot,SumPassedPlot])
CombPlot.Divide(SumPassedPlot, SumTotalsPlot, 1.0, 1.0, "B")
Plots.append([CombPlot, SumTotalsPlot, SumPassedPlot])
else:
for plot in Plots:
plot.SetBit(ROOT.TH1.kIsAverage)
......@@ -53,6 +76,7 @@ def MakeAveragePlot(Plots,oldStyleAverage=False):
Plots.append(CombPlot)
#print Plots
def MakeSumPlot(Plots):
#======================================================================
# Loop over plots in subPlots and append sum plot
......@@ -67,12 +91,14 @@ def MakeSumPlot(Plots):
Plots.append(CombPlot)
#print Plots
def MakeAveragePlotList(Plots,oldStyleAverage=False):
def MakeAveragePlotList(Plots, oldStyleAverage=False):
#======================================================================
# Loop over all subPlots and run MakeAveragePlot()
#======================================================================
for i in range(0, len(Plots)):
MakeAveragePlot(Plots[i],oldStyleAverage)
MakeAveragePlot(Plots[i], oldStyleAverage)
def MakeSumPlotList(Plots):
#======================================================================
......@@ -82,20 +108,19 @@ def MakeSumPlotList(Plots):
MakeSumPlot(Plots[i])
def CalculateBinning(plot,nBins):
def CalculateBinning(plot, nBins):
#tlines = []
points = []
totalIntegral = plot.Integral()
plotBins = plot.GetNbinsX()
for i in xrange(nBins-1):
for i in range(nBins - 1):
j = 1
integral = 0.
xPos = None
for j in xrange(1,plotBins+2):
for j in range(1, plotBins + 2):
integral += plot.GetBinContent(j)
#print i,j,integral,(i,1.),totalIntegral,nBins
if integral > (i+1.)*totalIntegral/nBins:
if integral > old_div((i + 1.) * totalIntegral, nBins):
xPos = plot.GetBinCenter(j)
break
j += 1
......@@ -116,11 +141,10 @@ def makeTGraph(PIDResults, MisIDResults, name, title=None):
## y = [list(t) for t in zip(*PionResults)][0]
## y_err = [list(t) for t in zip(*PionResults)][1]
graph = ROOT.TGraphErrors(len(x), array('f',x), array('f',y),
array('f',x_err), array('f',y_err))
graph = ROOT.TGraphErrors(
len(x), array('f', x), array('f', y), array('f', x_err),
array('f', y_err))
graph.SetName(name)
if title is not None:
graph.SetTitle(title)
return graph
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import print_function
from PIDPerfScripts.Definitions import *
from PIDPerfScripts import OverrideCalibDataStore
......@@ -6,6 +17,7 @@ import pickle
import os
import numpy as np
def GetPklFileSuffix(PartName):
#print "Getting pkl file suffix "
#print PartName
......@@ -13,81 +25,99 @@ def GetPklFileSuffix(PartName):
#print "passed checkplktype "
if PartName in ("K", "Pi"):
return "dst_k_and_pi"
if PartName in ("P",):
if PartName in ("P", ):
return "lam0_p"
if PartName in ("Mu",):
if PartName in ("Mu", ):
return "jpsi_mu"
if PartName in ("e",):
if PartName in ("e", ):
return "jpsi_e"
if PartName in ("K_MuonUnBiased", "Pi_MuonUnBiased"):
return "dst_k_and_pi_muonUnBiased"
if PartName in ("P_MuonUnBiased",):
if PartName in ("P_MuonUnBiased", ):
return "lam0_p_muonUnBiased"
if PartName in ("e_MuonUnBiased",):
if PartName in ("e_MuonUnBiased", ):
return "jpsi_e_muonUnBiased"
if PartName in ("P_LcfB",):
if PartName in ("P_LcfB", ):
return "LcfB_P"
if PartName in ("P_TotLc",):
if PartName in ("P_TotLc", ):
return "TotLc_P"
if PartName in ("P_IncLc",):
if PartName in ("P_IncLc", ):
return "IncLc_P"
def GetRunDictionary(StripVer, PartName="K" , verbose = True ):#, IsMuonUnBiased=False):
pklfileSuffix=GetPklFileSuffix(PartName)
def GetRunDictionary(StripVer, PartName="K",
verbose=True): #, IsMuonUnBiased=False):
pklfileSuffix = GetPklFileSuffix(PartName)
#MUONPreFix = ''
## if PartName in ("Mu", "K_MuonUnBiased", "Pi_MuonUnBiased", "P_MuonUnBiased"):
## MUONPreFix = '/MUON'
#======================================================================
# Dictionary of Dictionaires for StripVersion -> {UpRuns, DownRuns}
#======================================================================
stv = StripVer
if StripVer == '21_MCTuneV4':
stv = '21'
if StripVer == '21r1_MCTuneV4':
stv = '21r1'
stv = '21'
if StripVer == '21r1_MCTuneV4':
stv = '21r1'
if StripVer == '23_MCTuneV1':
stv = '23'
UpRunLims = pickle.load( open( os.path.expandvars(
'$PIDPERFSCRIPTSROOT/pklfiles/Stripping{strp}/up_runLimits_{suf}.pkl'.format(
strp=stv, suf=pklfileSuffix)), 'rb' ) )
DownRunLims = pickle.load( open( os.path.expandvars(
'$PIDPERFSCRIPTSROOT/pklfiles/Stripping{strp}/down_runLimits_{suf}.pkl'.format(
strp=stv, suf=pklfileSuffix)), 'rb' ) )
StripDict = {'StripVer' : StripVer,
'RecoVer' : GetRecoVer(StripVer),
'UpRuns' : UpRunLims.astype(int),
'DownRuns' : DownRunLims.astype(int)
}
stv = '23'
UpRunLims = pickle.load(
open(
os.path.expandvars(
'$PIDPERFSCRIPTSROOT/pklfiles/Stripping{strp}/up_runLimits_{suf}.pkl'
.format(strp=stv, suf=pklfileSuffix)), 'rb'))
DownRunLims = pickle.load(
open(
os.path.expandvars(
'$PIDPERFSCRIPTSROOT/pklfiles/Stripping{strp}/down_runLimits_{suf}.pkl'
.format(strp=stv, suf=pklfileSuffix)), 'rb'))
StripDict = {
'StripVer': StripVer,
'RecoVer': GetRecoVer(StripVer),
'UpRuns': UpRunLims.astype(int),
'DownRuns': DownRunLims.astype(int)
}
NumberOfRunColumns = 7
# Warning: in newer versions of python izip_longest is called zip_longest
UpRunsStr = itertools.izip_longest(*[iter([l.__repr__() for l in StripDict['UpRuns'].tolist()])] * NumberOfRunColumns, fillvalue="")
UpRunsStr = [", ".join([s for s in arr if s != ""])+"," for arr in UpRunsStr]
DownRunsStr = itertools.izip_longest(*[iter([l.__repr__() for l in StripDict['DownRuns'].tolist()])] * NumberOfRunColumns, fillvalue="")
DownRunsStr = [", ".join([s for s in arr if s != ""])+"," for arr in DownRunsStr]
if verbose :
print 'StripVer : ', StripDict['StripVer']
print 'RecoVer : ', StripDict['RecoVer']
print 'UpRuns : ['
for s in UpRunsStr: print " "+s
print "]"
print 'DownRuns : ['
for s in DownRunsStr: print " "+s
print "]"
UpRunsStr = itertools.zip_longest(
*[iter([l.__repr__()
for l in StripDict['UpRuns'].tolist()])] * NumberOfRunColumns,
fillvalue="")
UpRunsStr = [
", ".join([s for s in arr if s != ""]) + "," for arr in UpRunsStr
]
DownRunsStr = itertools.zip_longest(
*[iter([l.__repr__() for l in StripDict['DownRuns'].tolist()])] *
NumberOfRunColumns,
fillvalue="")
DownRunsStr = [
", ".join([s for s in arr if s != ""]) + "," for arr in DownRunsStr
]
if verbose:
print('StripVer : ', StripDict['StripVer'])
print('RecoVer : ', StripDict['RecoVer'])
print('UpRuns : [')
for s in UpRunsStr:
print(" " + s)
print("]")
print('DownRuns : [')
for s in DownRunsStr:
print(" " + s)
print("]")
return StripDict
def __FindFileIndex(run, runFirst, runLast):
#======================================================================
# Is run within the limits of a file?
......@@ -105,12 +135,12 @@ def __FindFileIndex(run, runFirst, runLast):
# - If no match is made, a 'ValueError: min() arg is an empty sequence'
# is returned.
#======================================================================
IsrunGreaterThanFirst = runFirst<=run
IsrunLessThanLast = runLast>=run
IsrunInHere = np.logical_and(IsrunGreaterThanFirst,IsrunLessThanLast)
IsrunGreaterThanFirst = runFirst <= run
IsrunLessThanLast = runLast >= run
IsrunInHere = np.logical_and(IsrunGreaterThanFirst, IsrunLessThanLast)
if np.any(IsrunInHere):
FileIndex = np.min(np.nonzero(IsrunInHere==True)[0])
FileIndex = np.min(np.nonzero(IsrunInHere == True)[0])
elif np.any(IsrunLessThanLast):
FileIndex = np.min(np.nonzero(IsrunLessThanLast == True)[0])
else:
......@@ -119,24 +149,29 @@ def __FindFileIndex(run, runFirst, runLast):
return FileIndex
def GetMinMaxFileDictionary(DataDict, MagPolarity, runMin=None, runMax=None, maxFiles=-1 , verbose = True ):
overridden = OverrideCalibDataStore.GetDictIndex (runMin, runMax, maxFiles, verbose)
def GetMinMaxFileDictionary(DataDict,
MagPolarity,
runMin=None,
runMax=None,
maxFiles=-1,
verbose=True):
overridden = OverrideCalibDataStore.GetDictIndex(runMin, runMax, maxFiles,
verbose)
if overridden: return overridden
#======================================================================
# Determine file index ranges corresponding to RunMin and RunMax
#======================================================================
CheckMagPol(MagPolarity)
runFirst = 0
runLast = 0
if MagPolarity=='MagUp':
runLast = 0
if MagPolarity == 'MagUp':
ndim = DataDict['UpRuns'].shape[0]
runFirst = DataDict['UpRuns'][0:ndim,0]
runLast = DataDict['UpRuns'][0:ndim,1]
runFirst = DataDict['UpRuns'][0:ndim, 0]
runLast = DataDict['UpRuns'][0:ndim, 1]
else:
ndim = DataDict['DownRuns'].shape[0]
runFirst = DataDict['DownRuns'][0:ndim,0]
runLast = DataDict['DownRuns'][0:ndim,1]
runFirst = DataDict['DownRuns'][0:ndim, 0]
runLast = DataDict['DownRuns'][0:ndim, 1]
if runMin is None:
#print 'runMin is None', runMin
......@@ -146,24 +181,27 @@ def GetMinMaxFileDictionary(DataDict, MagPolarity, runMin=None, runMax=None, max
minIndex = __FindFileIndex(int(runMin), runFirst, runLast)
if runMax is None:
#print 'runMax is None', runMax
maxIndex = len(runFirst)-1
maxIndex = len(runFirst) - 1
else:
#print 'runMax is not None', runMax
maxIndex = __FindFileIndex(int(runMax), runFirst, runLast)
#print 'runFirst: {runFirst}, runLast: {runLast}'.format(runFirst=runFirst, runLast=runLast)
if verbose :
print 'RunMin: {run}, Min file index: {index}'.format(run=runMin, index=minIndex)
print 'RunMax: {run}, Max file index: {index}'.format(run=runMax, index=maxIndex)
if verbose:
print('RunMin: {run}, Min file index: {index}'.format(
run=runMin, index=minIndex))
print('RunMax: {run}, Max file index: {index}'.format(
run=runMax, index=maxIndex))
if maxFiles != -1 and maxFiles != None:
if int(maxFiles)-1 < (maxIndex-minIndex):
maxIndex = minIndex + int(maxFiles)-1
if verbose :
print 'MaxFiles: {run}, Min file index: {index}'.format(run=maxFiles, index=minIndex)
print 'MaxFiles: {run}, Max file index: {index}'.format(run=maxFiles, index=maxIndex)
ret = {'minIndex' : minIndex,
'maxIndex' : maxIndex}
if int(maxFiles) - 1 < (maxIndex - minIndex):
maxIndex = minIndex + int(maxFiles) - 1
if verbose:
print('MaxFiles: {run}, Min file index: {index}'.format(
run=maxFiles, index=minIndex))
print('MaxFiles: {run}, Max file index: {index}'.format(
run=maxFiles, index=maxIndex))
ret = {'minIndex': minIndex, 'maxIndex': maxIndex}
return ret
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import print_function
def start():
print ' '
print '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*'
print ' __ __ __ ______ __ ____ ____ ____ ______ __ _ __ '
print ' / / / / / / / ____/ / /_ / __ \ / _/ / __ \ / ____/ ____ _ / / (_) / /_ '
print ' / / / /_/ / / / / __ \ / /_/ / / / / / / / / / / __ `/ / / / / / __ \ '
print ' / /___ / __ / / /___ / /_/ / / ____/ _/ / / /_/ / / /___ / /_/ / / / / / / /_/ / '
print ' /_____/ /_/ /_/ \____/ /_.___/ /_/ /___/ /_____/ \____/ \__,_/ /_/ /_/ /_.___/ '
print ' '
print '=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*'
print(' ')
print(
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*'
)
print(
' __ __ __ ______ __ ____ ____ ____ ______ __ _ __ '
)
print(
' / / / / / / / ____/ / /_ / __ \ / _/ / __ \ / ____/ ____ _ / / (_) / /_ '
)
print(
' / / / /_/ / / / / __ \ / /_/ / / / / / / / / / / __ `/ / / / / / __ \ '
)
print(
' / /___ / __ / / /___ / /_/ / / ____/ _/ / / /_/ / / /___ / /_/ / / / / / / /_/ / '
)
print(
' /_____/ /_/ /_/ \____/ /_.___/ /_/ /___/ /_____/ \____/ \__,_/ /_/ /_/ /_.___/ '
)
print(
' '
)
print(
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*'
)
###############################################################################
# (c) Copyright 2021 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
# #
# In applying this licence, CERN does not waive the privileges and immunities #
# granted to it by virtue of its status as an Intergovernmental Organization #
# or submit itself to any jurisdiction. #
###############################################################################
"""
"""
from __future__ import print_function
import os
print "importing from ", os.path.abspath(__path__[0])
print("importing from ", os.path.abspath(__path__[0]))
from ROOT import *
#gSystem.Load("libCint")