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.

193 lines
7.7 KiB

  1. from ROOT import gROOT, gDirectory, gStyle, TChain, TTree, TAxis, TH1D, TLine, TGaxis
  2. from Utils import expressionList, variableTag
  3. from Globals import *
  4. def getHistHeight(hist1,hist2):
  5. minY = 1e3
  6. maxY = 0.0
  7. for b in xrange(hist1.GetXaxis().GetNbins()): #hist1 and hist2 have same nBins
  8. maxTmp = max(hist1.GetBinContent(b+1),hist2.GetBinContent(b+1))
  9. if (maxY < maxTmp): maxY = maxTmp
  10. minTmp = min(hist1.GetBinContent(b+1),hist2.GetBinContent(b+1))
  11. if (minY > minTmp): minY = minTmp
  12. if (minY < 0.0): minY = 1.1*minY
  13. else: minY = 0.001
  14. return minY, maxY*1.1
  15. def defineXAxisLabels(variable1,variable2):
  16. xTag = variable1.replace("TMath::","")
  17. for expr in expressionList():
  18. xTag = variable1.replace(expr.lower(),expr)
  19. if (variable1==variable2):
  20. return xTag
  21. else:
  22. xTag2 = variable2.replace("TMath::","")
  23. for expr in expressionList():
  24. xTag2 = variable2.replace(expr.lower(),expr)
  25. return xTag + " vs " + xTag2 #TODO
  26. def makePlot(hist1, hist2, histRatio, pad1, pad2, xAxisTitle, Min, Max, lowerPlotHeight = 0.6):
  27. textsize = gStyle.GetTextSize();
  28. # modifiy pad for the ratio plot
  29. pad1.Clear()
  30. pad1.SetBorderSize (0)
  31. pad1.SetBottomMargin(1e-6)
  32. pad1.SetTopMargin(pad1.GetTopMargin() / ( 1.0 - lowerPlotHeight) )
  33. pad1.cd()
  34. #Set XAxis of the ratio plot #TODO
  35. TGaxis().SetExponentOffset(1e+9,1e+9,"y") #offset = pad size * 1e+7
  36. histRatio.GetXaxis().SetNoExponent() #<-- spoils MaxDigits settings, so don't use it on other axis
  37. histRatio.GetXaxis().SetLabelSize(0.0) #don't print labels
  38. histRatio.GetXaxis().SetRangeUser(Min, Max)
  39. histRatio.GetXaxis().SetTickLength(histRatio.GetXaxis().GetTickLength()/(1-lowerPlotHeight))
  40. histRatio.GetXaxis().SetNdivisions(gStyle.GetNdivisions("X"))
  41. #Set YAxis of the ratio plot
  42. histRatio.GetYaxis().SetTitle("ratio red/black")
  43. histRatio.GetYaxis().SetTitleSize(textsize/(1-lowerPlotHeight))
  44. histRatio.GetYaxis().SetLabelSize(textsize/(1-lowerPlotHeight))
  45. histRatio.GetYaxis().SetTickLength(histRatio.GetYaxis().GetTickLength())
  46. histRatio.GetYaxis().SetNdivisions(gStyle.GetNdivisions("Y"))
  47. histRatio.GetYaxis().SetTitleOffset(1.06*(1-lowerPlotHeight))
  48. histRatio.GetYaxis().SetRangeUser(0.001, 3)
  49. histRatio.Draw("E1")
  50. #Add a line at ratio = 1
  51. unityline2 = TLine(Min, 0.8, Max, 1.0)
  52. unityline2.SetLineStyle(2)
  53. unityline2.SetLineColor(4)
  54. unityline2.Draw()
  55. #Clear pad for the comparison plot
  56. pad2.Clear()
  57. pad2.SetBorderSize(0)
  58. pad2.SetTopMargin(1e-6)
  59. pad2.SetBottomMargin(pad2.GetBottomMargin() / lowerPlotHeight )
  60. pad2.cd()
  61. #Set XAxis of the comparison plot
  62. TGaxis().SetExponentOffset(1e+9,1e+9,"x") #offset = pad size * 1e+7
  63. hist1.GetXaxis().SetTitleOffset(1.05)
  64. hist1.GetXaxis().SetTitleSize (textsize/lowerPlotHeight)
  65. hist1.GetXaxis().SetLabelSize (textsize/lowerPlotHeight)
  66. hist1.GetXaxis().SetTickLength (histRatio.GetXaxis().GetTickLength()/(lowerPlotHeight/(1-lowerPlotHeight)))
  67. hist1.GetXaxis().SetNdivisions (gStyle.GetNdivisions("X"))
  68. hist1.GetXaxis().SetTitle(xAxisTitle)
  69. hist1.GetXaxis().SetRangeUser(Min, Max)
  70. #Set YAxis of the comparison plot
  71. minY, maxY = getHistHeight(hist1,hist2)
  72. hist1.GetYaxis().SetRangeUser(minY,maxY)
  73. hist1.GetYaxis().SetTitle("weighted events")
  74. hist1.GetYaxis().SetLabelSize (textsize/lowerPlotHeight)
  75. hist1.GetYaxis().SetTitleSize (textsize/lowerPlotHeight)
  76. hist1.GetYaxis().SetTickLength(histRatio.GetYaxis().GetTickLength())
  77. hist1.GetYaxis().SetNdivisions (gStyle.GetNdivisions("Y"))
  78. hist1.GetYaxis().SetTitleOffset(1.06*lowerPlotHeight)
  79. hist1.Draw("E1")
  80. hist2.SetLineColor(2)
  81. hist2.SetMarkerColor(2)
  82. hist2.Draw("E1SAME")
  83. return
  84. def defineLegendTags(optionsDict1, optionsDict2):
  85. tag1 = "" #initialize empty strings for tags
  86. tag2 = ""
  87. for key in optionsDict1:
  88. if (optionsDict1[key] != optionsDict2[key]):
  89. if (key == 'year' or key == 'magnet'):
  90. tag1 = tag1 + " " + str(optionsDict1[key])
  91. tag2 = tag2 + " " + str(optionsDict2[key])
  92. elif (key == 'Run'):
  93. tag1 = tag1 + " Run" + optionsDict1[key]
  94. tag2 = tag2 + " Tun" + optionsDict2[key]
  95. else:
  96. if(optionsDict1[key]): tag1 = tag1 + " " + key
  97. if(optionsDict2[key]): tag2 = tag2 + " " + key
  98. return tag1, tag2
  99. def getPlotFileName(variable1, optionsDict1, cut1, variable2, optionsDict2, cut2):
  100. #First define dataset tag
  101. if ( optionsDict1["year"] != optionsDict2["year"] or optionsDict1["magnet"] != optionsDict1["magnet"]):
  102. plotName = str(optionsDict1["year"]) + str(optionsDict1["magnet"])+ "_" + str(optionsDict2["year"]) + str(optionsDict2["magnet"])
  103. else:
  104. plotName = str(optionsDict1["year"]) + str(optionsDict1["magnet"])
  105. #Define name tag
  106. if (variable1==variable2):
  107. plotName = plotName + "_" + variableTag(variable1)
  108. else:
  109. plotName = plotName + "_" + variableTag(variable2) + "_" + variableTag(variable1)
  110. #Define sample tag
  111. if (optionsDict1["MC"]): plotName1 = "MC"
  112. else: plotName1 = "data"
  113. if (optionsDict1["Preselected"]):
  114. plotName1 = plotName1 + "_Presel"
  115. if (optionsDict1["BDTed"]):
  116. plotName1 = plotName1 + "_BDTed"
  117. else: plotName1 = plotName1 + "_Strip"
  118. if (KshortChannel()):
  119. if (optionsDict1["KshortDecaysInVelo"]): plotName1 = plotName1 + "_LL"
  120. else: plotName1 = plotName1 + "_DD"
  121. if (optionsDict2["MC"]): plotName2 = "MC"
  122. else: plotName2 = "data"
  123. if (optionsDict2["Preselected"]):
  124. plotName2 = plotName2 + "_Presel"
  125. if (optionsDict2["BDTed"]):
  126. plotName2 = plotName2 + "_BDTed"
  127. else: plotName2 = plotName2 + "_Strip"
  128. if (KshortChannel()):
  129. if (optionsDict2["KshortDecaysInVelo"]): plotName2 = plotName2 + "_LL"
  130. else: plotName2 = plotName2 + "_DD"
  131. #Define MC/data tags
  132. if (optionsDict1["MC"]):
  133. for keyMC in ['TM','ReferenceChannel', 'PHSP','bWeighted', 'b2Dweighted']: #TODO possibly add branch name
  134. if(optionsDict1[keyMC]): plotName1 = plotName1 + "_" + keyMC
  135. else:
  136. if(optionsDict1["sWeighted"]): plotName1 = plotName1 + "_sWeighted"
  137. if (optionsDict2["MC"]):
  138. for keyMC in ['TM','ReferenceChannel', 'PHSP','bWeighted', 'b2Dweighted']:
  139. if(optionsDict2[keyMC]): plotName2 = plotName2 + "_" + keyMC
  140. else:
  141. if(optionsDict2["sWeighted"]): plotName2 = plotName2 + "_sWeighted"
  142. # if (optionsDict1["UseLowQ2Range"]) plotName1 = plotName1 + "_LowQ2"
  143. # else: plotName1 = plotName1 + "_HighQ2"
  144. # if (optionsDict2["UseLowQ2Range"]) plotName2 = plotName2 + "_LowQ2"
  145. # else: plotName2 = plotName2 + "_HighQ2"
  146. #Strinp the extra cut on TM
  147. if (optionsDict1["TM"] and ("TMedBKGCAT=1" in cut1)): cut1 = cut1.replace("TMedBKGCAT=1","",-1)
  148. if (optionsDict2["TM"] and ("TMedBKGCAT=1" in cut2)): cut2 = cut2.replace("TMedBKGCAT=1","",-1)
  149. plotName1 = (plotName1 + "_"+variableTag(cut1)) if (cut1 != "") else plotName1
  150. plotName2 = (plotName2 + "_"+variableTag(cut2)) if (cut2 != "") else plotName2
  151. plotName = plotName + "_" + plotName1 + "_" + plotName2
  152. plotName = plotName.replace(" ","")
  153. if (KshortChannel()):
  154. return "/auto/data/dgerick/B2Kstmumu/compare_plots/" + plotName + ".eps"
  155. else:
  156. return "/home/lhcb/kopecna/B2KstarMuMu/data/compare_plots/" + plotName + ".eps"