Angular analysis of B+->K*+(K+pi0)mumu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

339 lines
12 KiB

  1. from __future__ import print_function
  2. import numpy as np
  3. from pathlib import Path
  4. from putIntoSlides_Utils import *
  5. HD_FOLDER = "/home/renata/B2KMuMu/sigma0/B2KstarMuMu/code/ewp-Bplus2Kstmumu-AngAna/FCNCfitter/"
  6. FIG_FOLDER = HD_FOLDER + "plots/"
  7. MASS_FIG_FOLDER = FIG_FOLDER + "MassFit/"
  8. MC_FIG_FOLDER = FIG_FOLDER + "MCfit/"
  9. TOYS_FIG_FOLDER = FIG_FOLDER + "Toys/"
  10. MAIN_FIG_FOLDER = FIG_FOLDER + "MainFit/"
  11. BKG_FIG_FOLDER = FIG_FOLDER + "bkgFit/"
  12. GENLVL_FIG_FOLDER = FIG_FOLDER + "GenLvlFit/"
  13. TEX_FILE_FOLDER = "includes/" #Don't use ./ as it efs up the print of includes
  14. #FIG_FOLDER = "./figures"
  15. OUTPUT_TAG = ""
  16. TITLE_TAG = ""
  17. decName = "KplusPi0Resolved"
  18. ANGLES = ["ctk", "ctl", "phi"]
  19. MASS_PLOTS = ["m_log","m", "mkpi"]
  20. ANG_PARAMS = ["Fl", "S3", "S4", "S5", "Afb", "S7", "S8", "S9"]
  21. MASS_PARAMS = ["m_b", "m_sigma_1", "alpha_1", "alpha_2", "n_1", "n_2"]
  22. MASS_BKG = ["m_lambda","f_sig"]
  23. ANGLE_BKG = ["cbkgctk1","cbkgctk2","cbkgctk3","cbkgctk4","cbkgctl1","cbkgctl2"]
  24. SWAVE_PARAMS = ["FS","SS1","SS2","SS3","SS4","SS5"]
  25. ANGLE_FOLDING = [
  26. ["Fl", "S3", "Afb", "S9"],
  27. ["Fl", "S3", "S4"],
  28. ["Fl", "S3", "S5"],
  29. ["Fl", "S3", "S7"],
  30. ["Fl", "S3", "S8"]
  31. ]
  32. ANGLE_FOLDING_S = [ #FS is set extra, so to not complicate it, it is not listed here
  33. ["SS1"],
  34. ["SS1","SS2"],
  35. ["SS1","SS3"],
  36. ["SS1","SS4"],
  37. ["SS4"],
  38. ]
  39. def projections(angle,Run): #Plot all angle projections in 18 bins
  40. listOfEntries = list(map(str,np.arange(0,18,1)))
  41. defaultTitle = angle + " projections, " + RunTag(Run)
  42. outputName = angle + "proj_" + RunTag(Run)
  43. figsPerSlide=6
  44. figsPerRow=3
  45. make_figure_slides(FIG_FOLDER+"/angular/",angle+"eff__LOOP___" + decName + "_" + RunTag(Run), listOfEntries, defaultTitle, figsPerSlide, figsPerRow, ".eps", outputName+".tex")
  46. def massFit(nBins, observable, Run): #Plot mass-only fits
  47. massFitName = "_massfit" + rareJpsiTag(False)
  48. path = observable + massFitName + "Fit" + binTag(nBins) + "_bin__LOOP___"+ RunTag(Run) + ""
  49. figsPerSlide=6
  50. figsPerRow=3
  51. make_figure_slides(MASS_FIG_FOLDER,path,
  52. list(map(str,np.arange(0,nBins,1))),"Signal mass fit",
  53. figsPerSlide, figsPerRow,
  54. ".eps",TEX_FILE_FOLDER+"MassFit_Signal_"+observable+"_"+RunTag(Run)+".tex")
  55. return
  56. def massFitRef(Run):
  57. massFitName = "_massfit" + rareJpsiTag(True)
  58. path = "__LOOP__" + massFitName + "Fit" + binTag(1) + "_bin0_" + RunTag(Run) + ""
  59. figsPerSlide=2
  60. figsPerRow=2
  61. make_figure_slides(MASS_FIG_FOLDER,path,
  62. MASS_PLOTS,"Reference mass fit",
  63. figsPerSlide, figsPerRow,
  64. ".eps",TEX_FILE_FOLDER+"MassFit_Jpsi_"+RunTag(Run)+".tex")
  65. return
  66. def massFitMCRef(Run): #Plot only mass fit of reference MC
  67. MCfitName = "_MC" + rareJpsiTag(True) + "Fit"
  68. path = "__LOOP__" + MCfitName + binTag(1) + "_bin0_SimultaneousFit_" + RunTag(Run) + "_OnlyMass"
  69. figsPerSlide=2
  70. figsPerRow=2
  71. make_figure_slides(MC_FIG_FOLDER + "Jpsi/",path,
  72. MASS_PLOTS,"MC Reference mass fit",
  73. figsPerSlide, figsPerRow,
  74. ".eps",TEX_FILE_FOLDER+"MC_MassFit_Jpsi_"+RunTag(Run)+".tex")
  75. return
  76. def massFitMC(nBins, observable, Run):
  77. MCfitName = "_MC" + rareJpsiTag(False) + "Fit"
  78. path = observable + MCfitName + binTag(nBins) + "_bin__LOOP___SimultaneousFit_" + RunTag(Run)
  79. figsPerSlide=5
  80. figsPerRow=3
  81. make_figure_slides(MC_FIG_FOLDER + "Signal/",path,
  82. list(map(str,np.arange(0,nBins,1))),"MC Signal mass fit",
  83. figsPerSlide, figsPerRow,
  84. ".eps",TEX_FILE_FOLDER+"MC_MassFit_Signal_"+observable+"_"+RunTag(Run)+".tex")
  85. return
  86. def angleFitMC(nBins, bin, Run): #Plot only ANGLES fit of signal MC
  87. MCfitName = "_MC" + rareJpsiTag(False) + "Fit"
  88. path = "__LOOP__" + MCfitName + binTagFull(nBins,bin)+"_SimultaneousFit_" + RunTag(Run) + "_OnlyANGLES_AllPDFs"
  89. figsPerSlide=3
  90. figsPerRow=3
  91. make_figure_slides(MC_FIG_FOLDER + "Signal/",path,
  92. ANGLES,"MC Signal fit, " + binTitle(nBins,bin),
  93. figsPerSlide, figsPerRow,
  94. ".eps",TEX_FILE_FOLDER+"MC_Signal"+binTagFull(nBins,bin)+"_"+RunTag(Run)+"_onlyANGLES.tex")
  95. return
  96. def MainFitRef(Run, Toy, fold, fullBkg):
  97. fitName = rareJpsiTag(True) + "Fit"
  98. path = "__LOOP__" + fitName + toyTag(Toy)+ binTag(1) + "_bin"+str(0)+"_SimultaneousFit" + foldTag(fold) + "_" + RunTag(Run) + plotBkgTag(fullBkg)+"_AllPDFs"
  99. figsPerSlide=6
  100. figsPerRow=3
  101. title = "Main fit, Ref"+ (", toy" if Toy else "")
  102. if (fold != -1): title += ", fld " + str(fold)
  103. make_figure_slides(MAIN_FIG_FOLDER, path,
  104. ANGLES+MASS_PLOTS,title,
  105. figsPerSlide, figsPerRow,
  106. ".eps",TEX_FILE_FOLDER+"MainFit_Ref"+toyTag(Toy)+ foldTag(fold)+ "_"+RunTag(Run)+plotBkgTag(fullBkg)+".tex")
  107. return
  108. def MainFit(Run, nBins, bin, fold, fullBkg):
  109. fitName = rareJpsiTag(False) + "Fit"
  110. path = "__LOOP__" + fitName + binTagFull(nBins,bin) +"_SimultaneousFit" + foldTag(fold) +"_" + RunTag(Run) + plotBkgTag(fullBkg)+ "_AllPDFs"
  111. figsPerSlide=6
  112. figsPerRow=3
  113. title = "Main fit, toy, "+str(bin+1)+"/" + str(nBins) + " bin(s)"
  114. if (fold != -1): title += ", fld " + str(fold)
  115. make_figure_slides(MAIN_FIG_FOLDER, path,
  116. ANGLES+MASS_PLOTS, title,
  117. figsPerSlide, figsPerRow,
  118. ".eps",TEX_FILE_FOLDER+"MainFit"+ binTagFull(nBins,bin) + foldTag(fold)+"_"+RunTag(Run)+plotBkgTag(fullBkg)+".tex")
  119. return
  120. def ToyFitCheckRef():
  121. path = "Init_vs_Fit___LOOP___Ref"
  122. plot_list = ANG_PARAMS + ANGLE_BKG +MASS_PARAMS + MASS_BKG
  123. figsPerSlide=6
  124. figsPerRow=3
  125. make_figure_slides("./figures/FullFitToy/",path,
  126. plot_list,"Toy init vs fit, Reference-like",
  127. figsPerSlide, figsPerRow,
  128. ".eps",TEX_FILE_FOLDER+"ToyInitFit.tex")
  129. return
  130. def MainFitToyCheck(isRef):
  131. refTag = "_Ref" if isRef else ""
  132. path = "FinalToy_Init_vs_Fit___LOOP__" + refTag
  133. plot_list = ANG_PARAMS + ANGLE_BKG +MASS_PARAMS + MASS_BKG
  134. figsPerSlide=6
  135. figsPerRow=3
  136. make_figure_slides(TOYS_FIG_FOLDER,path,
  137. plot_list,"Main fit vs init," + " Reference-like" if isRef else " Signal-like",
  138. figsPerSlide, figsPerRow,
  139. ".eps",TEX_FILE_FOLDER+"MainFitToy"+ refTag+".tex")
  140. return
  141. def localToy(folder, jobID, isRef, bin, nBins, fold, incBkg, onlyBkg, onlySig):
  142. refTag = "Ref" if isRef else "Signal"
  143. path = str(jobID)+"/__LOOP___toyfit__"+str(jobID)
  144. path = path + "_"+rareJpsiTag(isRef)+"Fit" + sigBkgTag(onlySig,onlyBkg)
  145. path = path + binTag(nBins)+"_bin"+str(bin)
  146. path = path +"_Run12_SimultaneousFit"+foldTag(fold)+"_HighBmass"+plotBkgTag(incBkg) + "_AllPDFs"
  147. #Split the path definition this stupid cause easier debuging
  148. plot_list = ANGLES + MASS_PLOTS
  149. if (onlyBkg): plot_list = ["ctk", "ctl", "phi", "m"]
  150. figsPerSlide= 4 if onlyBkg else 6
  151. figsPerRow= 4 if onlyBkg else 3
  152. title = "Toys" + rareJpsiTag(isRef) + sigBkgTag(onlySig,onlyBkg) +binTag(nBins)+"_bin"+str(bin) +foldTag(fold) +plotBkgTag(incBkg)
  153. title = title.replace("_"," ")
  154. fileTag = str(jobID)+rareJpsiTag(isRef)+str(bin)+str(nBins)+foldTag(fold)+plotBkgTag(incBkg)
  155. make_figure_slides(folder,path,
  156. plot_list,title, #TODO: check the title
  157. figsPerSlide, figsPerRow,
  158. ".eps",TEX_FILE_FOLDER+"Toy"+ fileTag+".tex")
  159. return
  160. def MCfit(nBins, bin, Run, fold): #Plot MC fit everything
  161. MCfitName = "_MC" + rareJpsiTag(False) + "Fit"
  162. path = "__LOOP__" + MCfitName + binTagFull(nBins,bin)+"_SimultaneousFit" + foldTag(fold) +"_" + RunTag(Run) + "_AllPDFs"
  163. figsPerSlide=6
  164. figsPerRow=3
  165. title = "MC Signal fit, "+binTitle(nBins,bin)
  166. if (fold != -1): title += ", fld " + str(fold)
  167. make_figure_slides(MC_FIG_FOLDER + "Signal/",path,
  168. ANGLES+MASS_PLOTS, title,
  169. figsPerSlide, figsPerRow,
  170. ".eps",TEX_FILE_FOLDER+"MC_Signal"+binTagFull(nBins,bin)+ foldTag(fold)+"_"+RunTag(Run)+".tex")
  171. return
  172. def BkgFitRef(Run, sideband):
  173. var_list = ["ctk", "ctl", "phi", "mkpi"]
  174. massFitName = "_Bckgnd" + rareJpsiTag(True)
  175. sidebandTag = ""
  176. if (sideband ==-1): sidebandTag = "_LowBmass"
  177. elif (sideband ==0): sidebandTag = "_HighBmass"
  178. sidebandTitle = ""
  179. if (sideband ==-1): sidebandTitle = ", lower sideband"
  180. elif (sideband ==0): sidebandTitle = ", upper sideband"
  181. path = "__LOOP__" + massFitName + "Fit" + binTag(1) + "_bin0_" + RunTag(Run)+ sidebandTag
  182. figsPerSlide=4
  183. figsPerRow=4
  184. make_figure_slides(BKG_FIG_FOLDER,path,
  185. var_list,"BKG mass fit"+sidebandTitle,
  186. figsPerSlide, figsPerRow,
  187. ".eps",TEX_FILE_FOLDER+"BkgFit_Jpsi_"+RunTag(Run)+sidebandTag+".tex")
  188. return
  189. def genLvlMC(nBins, bin, Run, fold):
  190. genLvlName = "_genLvl_MC" + rareJpsiTag(False) + "Fit"
  191. path = "__LOOP__" + genLvlName + binTagFull(nBins,bin)+ "_OnlyANGLES_AllPDFs"
  192. figsPerSlide=6
  193. figsPerRow=3
  194. title = "GenLvl MC fit, "+binTitle(nBins,bin)
  195. make_figure_slides(GENLVL_FIG_FOLDER,path,
  196. ANGLES, title,
  197. figsPerSlide, figsPerRow,
  198. ".eps",TEX_FILE_FOLDER+"GenLvlMC"+binTagFull(nBins,bin)+ foldTag(fold)+"_"+RunTag(Run)+".tex")
  199. return
  200. def compareGenLvlAndMC(toDavid):
  201. plotName = "GenLvl_vs_MC_"
  202. path = plotName + "__LOOP__" + ("_MyVsDavids" if toDavid else "")
  203. figsPerSlide=8
  204. figsPerRow=4
  205. title = "GenLvl vs "
  206. if (toDavid): title += "David's GenLvl"
  207. else: title += "signal MC"
  208. make_figure_slides(MC_FIG_FOLDER,path,
  209. ANG_PARAMS, title,
  210. figsPerSlide, figsPerRow,
  211. ".eps",TEX_FILE_FOLDER+"GenLvl" + ("_Vs_Davids" if toDavid else "_Vs_SigMC")+".tex")
  212. return
  213. def compareFolding():
  214. path = "Folding___LOOP__"
  215. figsPerSlide=8
  216. figsPerRow=4
  217. title = "Folding comparisons"
  218. make_figure_slides(MC_FIG_FOLDER,path,
  219. ANG_PARAMS, title,
  220. figsPerSlide, figsPerRow,
  221. ".eps",TEX_FILE_FOLDER+"Folding_comparison.tex")
  222. return
  223. def KstarMass(Ref,nBins, Run):
  224. MCfitName = "mkpi_MC" + rareJpsiTag(Ref) + "Fit"
  225. path = MCfitName + binTag(nBins) +"_bin__LOOP__" +"_SimultaneousFit_" + RunTag(Run) + ("_AllPDFs" if (Run == 12) else "") + ("_OnlyMass" if (Ref) else "")
  226. figsPerSlide=6
  227. figsPerRow=3
  228. binsList = list(map(str,np.arange(0,nBins,1)))
  229. title = "MC "+("Jpsi" if Ref else "Signal") +" fit, "+str(nBins) + " bin" + (", " if nBins==1 else "s, ") + RunTag(Run)
  230. make_figure_slides(MC_FIG_FOLDER + ("Jpsi/" if Ref else "Signal/"),path,
  231. binsList, title,
  232. figsPerSlide, figsPerRow,
  233. ".eps",TEX_FILE_FOLDER+"MC"+ rareJpsiTag(Ref)+"_Kpi"+binTag(nBins)+ "_"+RunTag(Run)+".tex")
  234. return
  235. #######################
  236. def toyPulls(bin,jobID,sWave=False):
  237. all_vars_list = ANG_PARAMS + ANGLE_BKG + MASS_BKG
  238. if(sWave): all_vars_list = all_vars_list + SWAVE_PARAMS
  239. figName = "/__LOOP___bin" + str(bin) +"_Signal_HighBmass_Pulls"
  240. figsPerSlide=8
  241. figsPerRow=4
  242. outFolder = "outputs/"+str(jobID)+"/"
  243. Path(outFolder).mkdir(parents=True, exist_ok=True)
  244. title = str(jobID) + ", bin " + str(bin)
  245. make_figure_slides(TOYS_FIG_FOLDER + str(jobID),figName,
  246. all_vars_list, title,
  247. figsPerSlide, figsPerRow,
  248. ".eps",outFolder+"bin"+str(bin)+".tex")
  249. #######################
  250. totBins = 5
  251. totFld = 4
  252. # for b in range(0,5):
  253. # toyPulls(b,353)
  254. #BkgFitRef(12,0)
  255. #for x in range(325,370):
  256. # toyPulls(0,x,True)
  257. toys = False
  258. for fld in range(-1,totFld+1):
  259. MainFitRef(12, toys, fld, False)
  260. MainFitRef(12, toys, fld, True)
  261. for fld in range(-1,totFld+1):
  262. #localToy("Toys/Bkg/",7,True,0,1,fld,False,True,False)
  263. #localToy("Toys/Ref/",5,True,0,1,fld,False,False,False)
  264. for bin in range(0,totBins):
  265. localToy("Toys/Sig/",10,False,bin,totBins,fld,False, False, False)
  266. localToy("Toys/Sig/",10,False,bin,totBins,fld,True, False, False)