File indexing completed on 2024-04-06 12:32:47
0001 import os
0002 import numpy as np
0003 import uproot as up
0004 import matplotlib.pyplot as plt
0005 from matplotlib.ticker import NullFormatter
0006
0007 """
0008 This is a sample code for ROC curve plotting (Feel free to change it to Your needs!)
0009 Code is ran from "Validation/MtdValidation/test" directory
0010 Before running the code initialize cmsenv
0011 Run the code by using python3 -> 'python3 ROC_ploter.py'
0012 Change the DQM File and ROC plot output directories accordingly to Your workspace
0013
0014 """
0015
0016
0017 print("All libraries has been read in!")
0018
0019 directory_path = os.getenv('PWD')
0020 ROC_plots_directory = directory_path + '/ROC'
0021
0022 class MTD_Ele_Iso:
0023
0024 def __init__(self,filename_Sig: str, filename_Bkg: str,dz_cut: str,dtSignif_cut: bool):
0025
0026 self.filename_sig = directory_path + filename_Sig
0027 self.filename_bkg = directory_path + filename_Bkg
0028
0029 self.cut_type = dtSignif_cut
0030 self.dz_cut_description = dz_cut
0031
0032 self.Tree_Sig = up.open(self.filename_sig)["DQMData/Run 1/MTD/Run summary/ElectronIso;1"]
0033 self.Tree_Bkg = up.open(self.filename_bkg)["DQMData/Run 1/MTD/Run summary/ElectronIso;1"]
0034
0035 self.Sig_hists = {}
0036 self.Bkg_hists = {}
0037
0038 self.Sig_iso_eff = {}
0039 self.Bkg_iso_eff = {}
0040
0041 def Read_hists(self):
0042
0043 self.Sig_hists['Sig_noMTD_EB'] = self.Tree_Sig['Ele_chIso_sum_Sig_EB;1'].to_numpy()
0044 self.Sig_hists['Sig_noMTD_EE'] = self.Tree_Sig['Ele_chIso_sum_Sig_EE;1'].to_numpy()
0045 self.Bkg_hists['Bkg_noMTD_EB'] = self.Tree_Bkg['Ele_chIso_sum_Bkg_EB;1'].to_numpy()
0046 self.Bkg_hists['Bkg_noMTD_EE'] = self.Tree_Bkg['Ele_chIso_sum_Bkg_EE;1'].to_numpy()
0047
0048 if self.cut_type == True:
0049
0050 self.Sig_hists['Sig_4sigma_EB'] = self.Tree_Sig['Ele_chIso_sum_MTD_4sigma_Sig_EB;1'].to_numpy()
0051 self.Sig_hists['Sig_3sigma_EB'] = self.Tree_Sig['Ele_chIso_sum_MTD_3sigma_Sig_EB;1'].to_numpy()
0052 self.Sig_hists['Sig_2sigma_EB'] = self.Tree_Sig['Ele_chIso_sum_MTD_2sigma_Sig_EB;1'].to_numpy()
0053
0054 self.Sig_hists['Sig_4sigma_EE'] = self.Tree_Sig['Ele_chIso_sum_MTD_4sigma_Sig_EE;1'].to_numpy()
0055 self.Sig_hists['Sig_3sigma_EE'] = self.Tree_Sig['Ele_chIso_sum_MTD_3sigma_Sig_EE;1'].to_numpy()
0056 self.Sig_hists['Sig_2sigma_EE'] = self.Tree_Sig['Ele_chIso_sum_MTD_2sigma_Sig_EE;1'].to_numpy()
0057
0058 self.Bkg_hists['Bkg_4sigma_EB'] = self.Tree_Bkg['Ele_chIso_sum_MTD_4sigma_Bkg_EB;1'].to_numpy()
0059 self.Bkg_hists['Bkg_3sigma_EB'] = self.Tree_Bkg['Ele_chIso_sum_MTD_3sigma_Bkg_EB;1'].to_numpy()
0060 self.Bkg_hists['Bkg_2sigma_EB'] = self.Tree_Bkg['Ele_chIso_sum_MTD_2sigma_Bkg_EB;1'].to_numpy()
0061
0062 self.Bkg_hists['Bkg_4sigma_EE'] = self.Tree_Bkg['Ele_chIso_sum_MTD_4sigma_Bkg_EE;1'].to_numpy()
0063 self.Bkg_hists['Bkg_3sigma_EE'] = self.Tree_Bkg['Ele_chIso_sum_MTD_3sigma_Bkg_EE;1'].to_numpy()
0064 self.Bkg_hists['Bkg_2sigma_EE'] = self.Tree_Bkg['Ele_chIso_sum_MTD_2sigma_Bkg_EE;1'].to_numpy()
0065
0066 else:
0067
0068
0069
0070
0071 self.Sig_hists['Sig_cut1_EB'] = self.Tree_Sig['Ele_chIso_sum_MTD_1_Sig_EB;1'].to_numpy()
0072 self.Sig_hists['Sig_cut2_EB'] = self.Tree_Sig['Ele_chIso_sum_MTD_2_Sig_EB;1'].to_numpy()
0073 self.Sig_hists['Sig_cut3_EB'] = self.Tree_Sig['Ele_chIso_sum_MTD_3_Sig_EB;1'].to_numpy()
0074 self.Sig_hists['Sig_cut5_EB'] = self.Tree_Sig['Ele_chIso_sum_MTD_5_Sig_EB;1'].to_numpy()
0075
0076 self.Sig_hists['Sig_cut1_EE'] = self.Tree_Sig['Ele_chIso_sum_MTD_1_Sig_EE;1'].to_numpy()
0077 self.Sig_hists['Sig_cut2_EE'] = self.Tree_Sig['Ele_chIso_sum_MTD_2_Sig_EE;1'].to_numpy()
0078 self.Sig_hists['Sig_cut3_EE'] = self.Tree_Sig['Ele_chIso_sum_MTD_3_Sig_EE;1'].to_numpy()
0079 self.Sig_hists['Sig_cut5_EE'] = self.Tree_Sig['Ele_chIso_sum_MTD_5_Sig_EE;1'].to_numpy()
0080
0081 self.Bkg_hists['Bkg_cut1_EB'] = self.Tree_Bkg['Ele_chIso_sum_MTD_1_Bkg_EB;1'].to_numpy()
0082 self.Bkg_hists['Bkg_cut2_EB'] = self.Tree_Bkg['Ele_chIso_sum_MTD_2_Bkg_EB;1'].to_numpy()
0083 self.Bkg_hists['Bkg_cut3_EB'] = self.Tree_Bkg['Ele_chIso_sum_MTD_3_Bkg_EB;1'].to_numpy()
0084 self.Bkg_hists['Bkg_cut5_EB'] = self.Tree_Bkg['Ele_chIso_sum_MTD_5_Bkg_EB;1'].to_numpy()
0085
0086 self.Bkg_hists['Bkg_cut1_EE'] = self.Tree_Bkg['Ele_chIso_sum_MTD_1_Bkg_EE;1'].to_numpy()
0087 self.Bkg_hists['Bkg_cut2_EE'] = self.Tree_Bkg['Ele_chIso_sum_MTD_2_Bkg_EE;1'].to_numpy()
0088 self.Bkg_hists['Bkg_cut3_EE'] = self.Tree_Bkg['Ele_chIso_sum_MTD_3_Bkg_EE;1'].to_numpy()
0089 self.Bkg_hists['Bkg_cut5_EE'] = self.Tree_Bkg['Ele_chIso_sum_MTD_5_Bkg_EE;1'].to_numpy()
0090
0091 def Calculate_efficiencies(self):
0092
0093 efficiency_Sig_noMTD_EB , efficiency_Bkg_noMTD_EB , efficiency_Sig_noMTD_EE , efficiency_Bkg_noMTD_EE = [],[],[],[]
0094
0095 if self.cut_type == True:
0096
0097 efficiency_Sig_4sigma_EB , efficiency_Bkg_4sigma_EB , efficiency_Sig_4sigma_EE , efficiency_Bkg_4sigma_EE = [],[],[],[]
0098 efficiency_Sig_3sigma_EB , efficiency_Bkg_3sigma_EB , efficiency_Sig_3sigma_EE , efficiency_Bkg_3sigma_EE = [],[],[],[]
0099 efficiency_Sig_2sigma_EB , efficiency_Bkg_2sigma_EB , efficiency_Sig_2sigma_EE , efficiency_Bkg_2sigma_EE = [],[],[],[]
0100
0101 for i in range( len(self.Sig_hists['Sig_noMTD_EB'][0]) ):
0102
0103 efficiency_Sig_noMTD_EB.append( sum(self.Sig_hists['Sig_noMTD_EB'][0][0:i+1])/sum(self.Sig_hists['Sig_noMTD_EB'][0]) )
0104 efficiency_Sig_4sigma_EB.append( sum(self.Sig_hists['Sig_4sigma_EB'][0][0:i+1])/sum(self.Sig_hists['Sig_4sigma_EB'][0]) )
0105 efficiency_Sig_3sigma_EB.append( sum(self.Sig_hists['Sig_3sigma_EB'][0][0:i+1])/sum(self.Sig_hists['Sig_3sigma_EB'][0]) )
0106 efficiency_Sig_2sigma_EB.append( sum(self.Sig_hists['Sig_2sigma_EB'][0][0:i+1])/sum(self.Sig_hists['Sig_2sigma_EB'][0]) )
0107
0108 efficiency_Bkg_noMTD_EB.append( sum(self.Bkg_hists['Bkg_noMTD_EB'][0][0:i+1])/sum(self.Bkg_hists['Bkg_noMTD_EB'][0]) )
0109 efficiency_Bkg_4sigma_EB.append( sum(self.Bkg_hists['Bkg_4sigma_EB'][0][0:i+1])/sum(self.Bkg_hists['Bkg_4sigma_EB'][0]) )
0110 efficiency_Bkg_3sigma_EB.append( sum(self.Bkg_hists['Bkg_3sigma_EB'][0][0:i+1])/sum(self.Bkg_hists['Bkg_3sigma_EB'][0]) )
0111 efficiency_Bkg_2sigma_EB.append( sum(self.Bkg_hists['Bkg_2sigma_EB'][0][0:i+1])/sum(self.Bkg_hists['Bkg_2sigma_EB'][0]) )
0112
0113
0114 efficiency_Sig_noMTD_EE.append( sum(self.Sig_hists['Sig_noMTD_EE'][0][0:i+1])/sum(self.Sig_hists['Sig_noMTD_EE'][0]) )
0115 efficiency_Sig_4sigma_EE.append( sum(self.Sig_hists['Sig_4sigma_EE'][0][0:i+1])/sum(self.Sig_hists['Sig_4sigma_EE'][0]) )
0116 efficiency_Sig_3sigma_EE.append( sum(self.Sig_hists['Sig_3sigma_EE'][0][0:i+1])/sum(self.Sig_hists['Sig_3sigma_EE'][0]) )
0117 efficiency_Sig_2sigma_EE.append( sum(self.Sig_hists['Sig_2sigma_EE'][0][0:i+1])/sum(self.Sig_hists['Sig_2sigma_EE'][0]) )
0118
0119 efficiency_Bkg_noMTD_EE.append( sum(self.Bkg_hists['Bkg_noMTD_EE'][0][0:i+1])/sum(self.Bkg_hists['Bkg_noMTD_EE'][0]) )
0120 efficiency_Bkg_4sigma_EE.append( sum(self.Bkg_hists['Bkg_4sigma_EE'][0][0:i+1])/sum(self.Bkg_hists['Bkg_4sigma_EE'][0]) )
0121 efficiency_Bkg_3sigma_EE.append( sum(self.Bkg_hists['Bkg_3sigma_EE'][0][0:i+1])/sum(self.Bkg_hists['Bkg_3sigma_EE'][0]) )
0122 efficiency_Bkg_2sigma_EE.append( sum(self.Bkg_hists['Bkg_2sigma_EE'][0][0:i+1])/sum(self.Bkg_hists['Bkg_2sigma_EE'][0]) )
0123
0124
0125 self.Sig_iso_eff['Sig_noMTD_EB'] , self.Bkg_iso_eff['Bkg_noMTD_EB'] = efficiency_Sig_noMTD_EB , efficiency_Bkg_noMTD_EB
0126 self.Sig_iso_eff['Sig_4sigma_EB'] , self.Bkg_iso_eff['Bkg_4sigma_EB'] = efficiency_Sig_4sigma_EB , efficiency_Bkg_4sigma_EB
0127 self.Sig_iso_eff['Sig_3sigma_EB'] , self.Bkg_iso_eff['Bkg_3sigma_EB'] = efficiency_Sig_3sigma_EB , efficiency_Bkg_3sigma_EB
0128 self.Sig_iso_eff['Sig_2sigma_EB'] , self.Bkg_iso_eff['Bkg_2sigma_EB'] = efficiency_Sig_2sigma_EB , efficiency_Bkg_2sigma_EB
0129
0130 self.Sig_iso_eff['Sig_noMTD_EE'] , self.Bkg_iso_eff['Bkg_noMTD_EE'] = efficiency_Sig_noMTD_EE , efficiency_Bkg_noMTD_EE
0131 self.Sig_iso_eff['Sig_4sigma_EE'] , self.Bkg_iso_eff['Bkg_4sigma_EE'] = efficiency_Sig_4sigma_EE , efficiency_Bkg_4sigma_EE
0132 self.Sig_iso_eff['Sig_3sigma_EE'] , self.Bkg_iso_eff['Bkg_3sigma_EE'] = efficiency_Sig_3sigma_EE , efficiency_Bkg_3sigma_EE
0133 self.Sig_iso_eff['Sig_2sigma_EE'] , self.Bkg_iso_eff['Bkg_2sigma_EE'] = efficiency_Sig_2sigma_EE , efficiency_Bkg_2sigma_EE
0134
0135 else:
0136
0137 efficiency_Sig_cut1_EB , efficiency_Bkg_cut1_EB , efficiency_Sig_cut1_EE , efficiency_Bkg_cut1_EE = [],[],[],[]
0138 efficiency_Sig_cut2_EB , efficiency_Bkg_cut2_EB , efficiency_Sig_cut2_EE , efficiency_Bkg_cut2_EE = [],[],[],[]
0139 efficiency_Sig_cut3_EB , efficiency_Bkg_cut3_EB , efficiency_Sig_cut3_EE , efficiency_Bkg_cut3_EE = [],[],[],[]
0140 efficiency_Sig_cut5_EB , efficiency_Bkg_cut5_EB , efficiency_Sig_cut5_EE , efficiency_Bkg_cut5_EE = [],[],[],[]
0141
0142 for i in range( len(self.Sig_hists['Sig_noMTD_EB'][0]) ):
0143
0144 efficiency_Sig_noMTD_EB.append( sum(self.Sig_hists['Sig_noMTD_EB'][0][0:i+1])/sum(self.Sig_hists['Sig_noMTD_EB'][0]) )
0145 efficiency_Sig_cut1_EB.append( sum(self.Sig_hists['Sig_cut1_EB'][0][0:i+1])/sum(self.Sig_hists['Sig_cut1_EB'][0]) )
0146 efficiency_Sig_cut2_EB.append( sum(self.Sig_hists['Sig_cut2_EB'][0][0:i+1])/sum(self.Sig_hists['Sig_cut2_EB'][0]) )
0147 efficiency_Sig_cut3_EB.append( sum(self.Sig_hists['Sig_cut3_EB'][0][0:i+1])/sum(self.Sig_hists['Sig_cut3_EB'][0]) )
0148 efficiency_Sig_cut5_EB.append( sum(self.Sig_hists['Sig_cut5_EB'][0][0:i+1])/sum(self.Sig_hists['Sig_cut5_EB'][0]) )
0149
0150 efficiency_Bkg_noMTD_EB.append( sum(self.Bkg_hists['Bkg_noMTD_EB'][0][0:i+1])/sum(self.Bkg_hists['Bkg_noMTD_EB'][0]) )
0151 efficiency_Bkg_cut1_EB.append( sum(self.Bkg_hists['Bkg_cut1_EB'][0][0:i+1])/sum(self.Bkg_hists['Bkg_cut1_EB'][0]) )
0152 efficiency_Bkg_cut2_EB.append( sum(self.Bkg_hists['Bkg_cut2_EB'][0][0:i+1])/sum(self.Bkg_hists['Bkg_cut2_EB'][0]) )
0153 efficiency_Bkg_cut3_EB.append( sum(self.Bkg_hists['Bkg_cut3_EB'][0][0:i+1])/sum(self.Bkg_hists['Bkg_cut3_EB'][0]) )
0154 efficiency_Bkg_cut5_EB.append( sum(self.Bkg_hists['Bkg_cut5_EB'][0][0:i+1])/sum(self.Bkg_hists['Bkg_cut5_EB'][0]) )
0155
0156
0157 efficiency_Sig_noMTD_EE.append( sum(self.Sig_hists['Sig_noMTD_EE'][0][0:i+1])/sum(self.Sig_hists['Sig_noMTD_EE'][0]) )
0158 efficiency_Sig_cut1_EE.append( sum(self.Sig_hists['Sig_cut1_EE'][0][0:i+1])/sum(self.Sig_hists['Sig_cut1_EE'][0]) )
0159 efficiency_Sig_cut2_EE.append( sum(self.Sig_hists['Sig_cut2_EE'][0][0:i+1])/sum(self.Sig_hists['Sig_cut2_EE'][0]) )
0160 efficiency_Sig_cut3_EE.append( sum(self.Sig_hists['Sig_cut3_EE'][0][0:i+1])/sum(self.Sig_hists['Sig_cut3_EE'][0]) )
0161 efficiency_Sig_cut5_EE.append( sum(self.Sig_hists['Sig_cut5_EE'][0][0:i+1])/sum(self.Sig_hists['Sig_cut5_EE'][0]) )
0162
0163 efficiency_Bkg_noMTD_EE.append( sum(self.Bkg_hists['Bkg_noMTD_EE'][0][0:i+1])/sum(self.Bkg_hists['Bkg_noMTD_EE'][0]) )
0164 efficiency_Bkg_cut1_EE.append( sum(self.Bkg_hists['Bkg_cut1_EE'][0][0:i+1])/sum(self.Bkg_hists['Bkg_cut1_EE'][0]) )
0165 efficiency_Bkg_cut2_EE.append( sum(self.Bkg_hists['Bkg_cut2_EE'][0][0:i+1])/sum(self.Bkg_hists['Bkg_cut2_EE'][0]) )
0166 efficiency_Bkg_cut3_EE.append( sum(self.Bkg_hists['Bkg_cut3_EE'][0][0:i+1])/sum(self.Bkg_hists['Bkg_cut3_EE'][0]) )
0167 efficiency_Bkg_cut5_EE.append( sum(self.Bkg_hists['Bkg_cut5_EE'][0][0:i+1])/sum(self.Bkg_hists['Bkg_cut5_EE'][0]) )
0168
0169
0170 self.Sig_iso_eff['Sig_noMTD_EB'] , self.Bkg_iso_eff['Bkg_noMTD_EB'] = efficiency_Sig_noMTD_EB , efficiency_Bkg_noMTD_EB
0171 self.Sig_iso_eff['Sig_cut1_EB'] , self.Bkg_iso_eff['Bkg_cut1_EB'] = efficiency_Sig_cut1_EB , efficiency_Bkg_cut1_EB
0172 self.Sig_iso_eff['Sig_cut2_EB'] , self.Bkg_iso_eff['Bkg_cut2_EB'] = efficiency_Sig_cut2_EB , efficiency_Bkg_cut2_EB
0173 self.Sig_iso_eff['Sig_cut3_EB'] , self.Bkg_iso_eff['Bkg_cut3_EB'] = efficiency_Sig_cut3_EB , efficiency_Bkg_cut3_EB
0174 self.Sig_iso_eff['Sig_cut5_EB'] , self.Bkg_iso_eff['Bkg_cut5_EB'] = efficiency_Sig_cut5_EB , efficiency_Bkg_cut5_EB
0175
0176 self.Sig_iso_eff['Sig_noMTD_EE'] , self.Bkg_iso_eff['Bkg_noMTD_EE'] = efficiency_Sig_noMTD_EE , efficiency_Bkg_noMTD_EE
0177 self.Sig_iso_eff['Sig_cut1_EE'] , self.Bkg_iso_eff['Bkg_cut1_EE'] = efficiency_Sig_cut1_EE , efficiency_Bkg_cut1_EE
0178 self.Sig_iso_eff['Sig_cut2_EE'] , self.Bkg_iso_eff['Bkg_cut2_EE'] = efficiency_Sig_cut2_EE , efficiency_Bkg_cut2_EE
0179 self.Sig_iso_eff['Sig_cut3_EE'] , self.Bkg_iso_eff['Bkg_cut3_EE'] = efficiency_Sig_cut3_EE , efficiency_Bkg_cut3_EE
0180 self.Sig_iso_eff['Sig_cut5_EE'] , self.Bkg_iso_eff['Bkg_cut5_EE'] = efficiency_Sig_cut5_EE , efficiency_Bkg_cut5_EE
0181
0182 def Plot_ROC_curves(self,xmin,xmax,ymin,ymax,save: bool):
0183
0184 if self.cut_type == True:
0185
0186 plt.plot(self.Sig_iso_eff['Sig_noMTD_EB'],self.Bkg_iso_eff['Bkg_noMTD_EB'], label = 'noMTD')
0187 plt.plot(self.Sig_iso_eff['Sig_4sigma_EB'],self.Bkg_iso_eff['Bkg_4sigma_EB'], label = '4sigma cut')
0188 plt.plot(self.Sig_iso_eff['Sig_3sigma_EB'],self.Bkg_iso_eff['Bkg_3sigma_EB'], label = '3sigma cut')
0189 plt.plot(self.Sig_iso_eff['Sig_2sigma_EB'],self.Bkg_iso_eff['Bkg_2sigma_EB'], label = '2sigma cut')
0190 plt.legend(loc='best')
0191 plt.ylim(ymin,ymax)
0192 plt.xlim(xmin,xmax)
0193 plt.grid()
0194 plt.xlabel("Signal efficiency")
0195 plt.ylabel("Background efficiency")
0196 plt.title(f'ROC curves for BTL, {self.dz_cut_description}')
0197 if(save):
0198 plt.savefig(ROC_plots_directory+f'ROC_curve_BTL_dtsignif_{self.dz_cut_description}')
0199 plt.show()
0200
0201 plt.plot(self.Sig_iso_eff['Sig_noMTD_EE'],self.Bkg_iso_eff['Bkg_noMTD_EE'], label = 'noMTD')
0202 plt.plot(self.Sig_iso_eff['Sig_4sigma_EE'],self.Bkg_iso_eff['Bkg_4sigma_EE'], label = '4sigma cut')
0203 plt.plot(self.Sig_iso_eff['Sig_3sigma_EE'],self.Bkg_iso_eff['Bkg_3sigma_EE'], label = '3sigma cut')
0204 plt.plot(self.Sig_iso_eff['Sig_2sigma_EE'],self.Bkg_iso_eff['Bkg_2sigma_EE'], label = '2sigma cut')
0205 plt.legend(loc='best')
0206 plt.ylim(ymin,ymax)
0207 plt.xlim(xmin,xmax)
0208 plt.grid()
0209 plt.xlabel("Signal efficiency")
0210 plt.ylabel("Background efficiency")
0211 plt.title(f'ROC curves for ETL, {self.dz_cut_description}')
0212 if(save):
0213 plt.savefig(ROC_plots_directory+f'ROC_curve_ETL_dtsignif_{self.dz_cut_description}')
0214 plt.show()
0215
0216 else:
0217
0218
0219 plt.plot(self.Sig_iso_eff['Sig_noMTD_EB'],self.Bkg_iso_eff['Bkg_noMTD_EB'], label = 'noMTD')
0220 plt.plot(self.Sig_iso_eff['Sig_cut1_EB'],self.Bkg_iso_eff['Bkg_cut1_EB'], label = 'cut1 - 300ps')
0221 plt.plot(self.Sig_iso_eff['Sig_cut2_EB'],self.Bkg_iso_eff['Bkg_cut2_EB'], label = 'cut2 - 270ps')
0222 plt.plot(self.Sig_iso_eff['Sig_cut3_EB'],self.Bkg_iso_eff['Bkg_cut3_EB'], label = 'cut3 - 240ps')
0223 plt.plot(self.Sig_iso_eff['Sig_cut5_EB'],self.Bkg_iso_eff['Bkg_cut5_EB'], label = 'cut5 - 180ps')
0224 plt.legend(loc='best')
0225 plt.ylim(ymin,ymax)
0226 plt.xlim(xmin,xmax)
0227 plt.grid()
0228 plt.xlabel("Signal efficiency")
0229 plt.ylabel("Background efficiency")
0230 plt.title(f'ROC curves for BTL, {self.dz_cut_description}')
0231 if(save):
0232 plt.savefig(ROC_plots_directory+f'ROC_curve_BTL_abs_dt_{self.dz_cut_description}')
0233 plt.show()
0234
0235 plt.plot(self.Sig_iso_eff['Sig_noMTD_EE'],self.Bkg_iso_eff['Bkg_noMTD_EE'], label = 'noMTD')
0236 plt.plot(self.Sig_iso_eff['Sig_cut1_EE'],self.Bkg_iso_eff['Bkg_cut1_EE'], label = 'cut1 - 300ps')
0237 plt.plot(self.Sig_iso_eff['Sig_cut2_EE'],self.Bkg_iso_eff['Bkg_cut2_EE'], label = 'cut2 - 270ps')
0238 plt.plot(self.Sig_iso_eff['Sig_cut3_EE'],self.Bkg_iso_eff['Bkg_cut3_EE'], label = 'cut3 - 240ps')
0239 plt.plot(self.Sig_iso_eff['Sig_cut5_EE'],self.Bkg_iso_eff['Bkg_cut5_EE'], label = 'cut5 - 180ps')
0240 plt.legend(loc='best')
0241 plt.ylim(ymin,ymax)
0242 plt.xlim(xmin,xmax)
0243 plt.grid()
0244 plt.xlabel("Signal efficiency")
0245 plt.ylabel("Background efficiency")
0246 plt.title(f'ROC curves for ETL, {self.dz_cut_description}')
0247 if(save):
0248 plt.savefig(ROC_plots_directory+f'ROC_curve_ETL_abs_dt_{self.dz_cut_description}')
0249 plt.show()
0250
0251
0252
0253 def Plot_ROC_curves_vs_dz_noMTD(xmin,xmax,ymin,ymax,save:bool,*objects):
0254
0255 for i in objects:
0256 plt.plot(i.Sig_iso_eff['Sig_noMTD_EB'],i.Bkg_iso_eff['Bkg_noMTD_EB'],label=f'noMTD {i.dz_cut_description}')
0257 plt.legend(loc='best')
0258 plt.ylim(ymin,ymax)
0259 plt.xlim(xmin,xmax)
0260 plt.grid()
0261 plt.xlabel("Signal efficiency")
0262 plt.ylabel("Background efficiency")
0263 plt.title('ROC curves for BTL, no MTD case')
0264 if(save):
0265 plt.savefig(ROC_plots_directory+'ROC_curve_BTL_noMTD_dzCuts')
0266 plt.show()
0267
0268 for i in objects:
0269 plt.plot(i.Sig_iso_eff['Sig_noMTD_EE'],i.Bkg_iso_eff['Bkg_noMTD_EE'],label=f'noMTD {i.dz_cut_description}')
0270 plt.legend(loc='best')
0271 plt.ylim(ymin,ymax)
0272 plt.xlim(xmin,xmax)
0273 plt.grid()
0274 plt.xlabel("Signal efficiency")
0275 plt.ylabel("Background efficiency")
0276 plt.title('ROC curves for ETL, no MTD case')
0277 if(save):
0278 plt.savefig(ROC_plots_directory+'ROC_curve_ETL_noMTD_dzCuts')
0279 plt.show()
0280
0281
0282
0283
0284
0285
0286 def main():
0287
0288
0289 dz010_cut_obj = MTD_Ele_Iso('DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Sig_dz010_v5.root','DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Bkg_dz010_v5.root','dz_1mm',True)
0290 dz020_cut_obj = MTD_Ele_Iso('DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Sig_dz020_v5.root','DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Bkg_dz020_v5.root','dz_2mm',True)
0291 dz030_cut_obj = MTD_Ele_Iso('DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Sig_dz030_v5.root','DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Bkg_dz030_v5.root','dz_3mm',True)
0292 dz040_cut_obj = MTD_Ele_Iso('DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Sig_dz040_v5.root','DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Bkg_dz040_v5.root','dz_4mm',True)
0293 dz050_cut_obj = MTD_Ele_Iso('DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Sig_dz050_v5.root','DQM_V0001_R000000001__Global__CMSSW_X_Y_Z__RECO_Bkg_dz050_v5.root','dz_5mm',True)
0294
0295 dz010_cut_obj.Read_hists()
0296 dz020_cut_obj.Read_hists()
0297 dz030_cut_obj.Read_hists()
0298 dz040_cut_obj.Read_hists()
0299 dz050_cut_obj.Read_hists()
0300
0301 dz010_cut_obj.Calculate_efficiencies()
0302 dz020_cut_obj.Calculate_efficiencies()
0303 dz030_cut_obj.Calculate_efficiencies()
0304 dz040_cut_obj.Calculate_efficiencies()
0305 dz050_cut_obj.Calculate_efficiencies()
0306
0307
0308 dz010_cut_obj.Plot_ROC_curves(0.75,1.0,0.05,0.4,True)
0309 dz020_cut_obj.Plot_ROC_curves(0.75,1.0,0.05,0.4,True)
0310 dz030_cut_obj.Plot_ROC_curves(0.75,1.0,0.05,0.4,True)
0311 dz040_cut_obj.Plot_ROC_curves(0.75,1.0,0.05,0.4,True)
0312 dz050_cut_obj.Plot_ROC_curves(0.75,1.0,0.05,0.4,True)
0313
0314
0315
0316 Plot_ROC_curves_vs_dz_noMTD(0.75,1.0,0.05,0.4,True,dz010_cut_obj,dz020_cut_obj,dz030_cut_obj,dz040_cut_obj,dz050_cut_obj)
0317
0318
0319 if __name__ == "__main__":
0320 main()