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.

48 lines
1.5 KiB

  1. #Reorganizes the arrays in TGraph in a way x is ascending, as ROOT is stupidly behaving when plotting when it is not the case
  2. #Renata Kopecna
  3. from ROOT import TTree, TChain, TFile, TVector3, TObject, TGraphErrors, TGraph
  4. import numpy as np
  5. import os
  6. def redoGraph(Run, graphFile, name):
  7. graph = graphFile.Get("MLP "+name+"Run"+str(Run))
  8. size = graph.GetN()
  9. buffer_X = graph.GetX()
  10. X = np.fromiter(buffer_X,dtype=np.float, count = size)
  11. buffer_Y = graph.GetY()
  12. Y = np.fromiter(buffer_Y,dtype=np.float, count = size)
  13. arr = np.column_stack((X,Y))
  14. arr = np.unique(arr,axis=0)
  15. print(arr)
  16. X = arr[:,0].flatten('C')
  17. Y = arr[:,1].flatten('C')
  18. newGraph = TGraph(X.size,X,Y)
  19. newGraph.SetTitle(name)
  20. newGraph.SetName(name)
  21. return newGraph
  22. def rewriteMVAscan(Run):
  23. path = "/home/lhcb/kopecna/B2KstarMuMu_clean/Data/Tuples/FinalSelection/KplusPi0Resolved_BDTscan_Run"+str(Run)+"_fine.root"
  24. graphFile = TFile.Open(path,"READ")
  25. list_of_names = ["sigYield","bkgYield","bkgYield_fromAllEvts","refYield","significance","significance_fromAllEvts"]
  26. newFile = TFile.Open(path.replace(".root","_new.root"),"RECREATE")
  27. newFile.cd()
  28. for name in list_of_names:
  29. redoGraph(Run,graphFile,name).Write()
  30. newFile.Close()
  31. graphFile.Close()
  32. cmd = "mv " + path + " " + path.replace(".root","_old.root")
  33. os.system(cmd)
  34. cmd = "mv " + path.replace(".root","_new.root") + " " + path
  35. os.system(cmd)
  36. rewriteMVAscan(1)
  37. rewriteMVAscan(2)