From 60e1a2609628a2e062f2336f7bad4a566146f49c Mon Sep 17 00:00:00 2001
From: xueting <xueting.yang@cern.ch>
Date: Tue, 16 May 2023 23:35:50 +0800
Subject: [PATCH] fix the hash code issue of 2 handlers(hlt2 eff)

---
 handlers/PrCheckerSummaryHandler.py           | 96 ++++++++++++-------
 handlers/PrCheckerSummaryHandler_withoutUT.py | 64 ++++++++-----
 2 files changed, 100 insertions(+), 60 deletions(-)

diff --git a/handlers/PrCheckerSummaryHandler.py b/handlers/PrCheckerSummaryHandler.py
index 58631b6c..e20adb13 100644
--- a/handlers/PrCheckerSummaryHandler.py
+++ b/handlers/PrCheckerSummaryHandler.py
@@ -43,15 +43,15 @@ def effPlotsDict_long():
     }
 
     basedict["Pt"][
-        "path"] = "Track/BestLongTrackChecker_2b1808e5/BestLong/01_long_Pt"
+        "path"] = "/BestLong/01_long_Pt"
     basedict["P"][
-        "path"] = "Track/BestLongTrackChecker_2b1808e5/BestLong/01_long_P"
+        "path"] = "/BestLong/01_long_P"
     basedict["Eta"][
-        "path"] = "Track/BestLongTrackChecker_2b1808e5/BestLong/01_long_Eta"
+        "path"] = "/BestLong/01_long_Eta"
     basedict["nPV"][
-        "path"] = "Track/BestLongTrackChecker_2b1808e5/BestLong/01_long_nPV"
+        "path"] = "/BestLong/01_long_nPV"
     basedict["docaz"][
-        "path"] = "Track/BestLongTrackChecker_2b1808e5/BestLong/01_long_docaz"
+        "path"] = "/BestLong/01_long_docaz"
     basedict["Pt"]["unit"] = "pT [MeV]"
     basedict["P"]["unit"] = "p [MeV]"
     basedict["Eta"]["unit"] = "#eta [-]"
@@ -79,15 +79,15 @@ def effPlotsDict_down():
     }
 
     basedict["Pt"][
-        "path"] = "Track/BestDownstreamTrackChecker_16cf5e80/BestDownstream/01_UT+T_Pt"
+        "path"] = "/BestDownstream/01_UT+T_Pt"
     basedict["P"][
-        "path"] = "Track/BestDownstreamTrackChecker_16cf5e80/BestDownstream/01_UT+T_P"
+        "path"] = "/BestDownstream/01_UT+T_P"
     basedict["Eta"][
-        "path"] = "Track/BestDownstreamTrackChecker_16cf5e80/BestDownstream/01_UT+T_Eta"
+        "path"] = "/BestDownstream/01_UT+T_Eta"
     basedict["nPV"][
-        "path"] = "Track/BestDownstreamTrackChecker_16cf5e80/BestDownstream/01_UT+T_nPV"
+        "path"] = "/BestDownstream/01_UT+T_nPV"
     basedict["docaz"][
-        "path"] = "Track/BestDownstreamTrackChecker_16cf5e80/BestDownstream/01_UT+T_docaz"
+        "path"] = "/BestDownstream/01_UT+T_docaz"
     basedict["Pt"]["unit"] = "pT [MeV]"
     basedict["P"]["unit"] = "p [MeV]"
     basedict["Eta"]["unit"] = "#eta [-]"
@@ -115,15 +115,15 @@ def effPlotsDict_forward():
     }
 
     basedict["Pt"][
-        "path"] = "Track/ForwardTrackChecker_38a3d1fd/Forward/01_long_Pt"
+        "path"] = "/Forward/01_long_Pt"
     basedict["P"][
-        "path"] = "Track/ForwardTrackChecker_38a3d1fd/Forward/01_long_P"
+        "path"] = "/Forward/01_long_P"
     basedict["Eta"][
-        "path"] = "Track/ForwardTrackChecker_38a3d1fd/Forward/01_long_Eta"
+        "path"] = "/Forward/01_long_Eta"
     basedict["nPV"][
-        "path"] = "Track/ForwardTrackChecker_38a3d1fd/Forward/01_long_nPV"
+        "path"] = "/Forward/01_long_nPV"
     basedict["docaz"][
-        "path"] = "Track/ForwardTrackChecker_38a3d1fd/Forward/01_long_docaz"
+        "path"] = "/Forward/01_long_docaz"
     basedict["Pt"]["unit"] = "pT [MeV]"
     basedict["P"]["unit"] = "p [MeV]"
     basedict["Eta"]["unit"] = "#eta [-]"
@@ -151,15 +151,15 @@ def effPlotsDict_velo():
     }
 
     basedict["Pt"][
-        "path"] = "Track/VeloFullTrackChecker_b448179f/VeloFull/01_notElectron_Velo_Pt"
+        "path"] = "/VeloFull/01_notElectron_Velo_Pt"
     basedict["P"][
-        "path"] = "Track/VeloFullTrackChecker_b448179f/VeloFull/01_notElectron_Velo_P"
+        "path"] = "/VeloFull/01_notElectron_Velo_P"
     basedict["Eta"][
-        "path"] = "Track/VeloFullTrackChecker_b448179f/VeloFull/01_notElectron_Velo_Eta"
+        "path"] = "/VeloFull/01_notElectron_Velo_Eta"
     basedict["nPV"][
-        "path"] = "Track/VeloFullTrackChecker_b448179f/VeloFull/01_notElectron_Velo_nPV"
+        "path"] = "/VeloFull/01_notElectron_Velo_nPV"
     basedict["docaz"][
-        "path"] = "Track/VeloFullTrackChecker_b448179f/VeloFull/01_notElectron_Velo_docaz"
+        "path"] = "/VeloFull/01_notElectron_Velo_docaz"
     basedict["Pt"]["unit"] = "pT [MeV]"
     basedict["P"]["unit"] = "p [MeV]"
     basedict["Eta"]["unit"] = "#eta [-]"
@@ -186,14 +186,14 @@ def effPlotsDict_ttrack():
         "docaz": {},
     }
 
-    basedict["Pt"]["path"] = "Track/SeedTrackChecker_6f38a9cb/Seed/01_hasT_Pt"
-    basedict["P"]["path"] = "Track/SeedTrackChecker_6f38a9cb/Seed/01_hasT_P"
+    basedict["Pt"]["path"] = "/Seed/01_hasT_Pt"
+    basedict["P"]["path"] = "/Seed/01_hasT_P"
     basedict["Eta"][
-        "path"] = "Track/SeedTrackChecker_6f38a9cb/Seed/01_hasT_Eta"
+        "path"] = "/Seed/01_hasT_Eta"
     basedict["nPV"][
-        "path"] = "Track/SeedTrackChecker_6f38a9cb/Seed/01_hasT_nPV"
+        "path"] = "/Seed/01_hasT_nPV"
     basedict["docaz"][
-        "path"] = "Track/SeedTrackChecker_6f38a9cb/Seed/01_hasT_docaz"
+        "path"] = "/Seed/01_hasT_docaz"
     basedict["Pt"]["unit"] = "pT [MeV]"
     basedict["P"]["unit"] = "p [MeV]"
     basedict["Eta"]["unit"] = "#eta [-]"
@@ -238,6 +238,30 @@ class PrCheckerSummaryHandler(BaseHandler):
         inputfile = ROOT.TFile.Open(os.path.join(directory, rootfile), 'read')
         outputfile = ROOT.TFile("PrCheckerSummary.root", "recreate")
 
+        path_long = "Track/BestLongTrackChecker_"
+        path_down = "Track/BestDownstreamTrackChecker_"
+        path_forward = "Track/ForwardTrackChecker_"
+        path_velo = "Track/VeloFullTrackChecker_"
+        path_ttrack = "Track/SeedTrackChecker_"
+
+        #Get the hash codes
+        Trackfile = inputfile.GetDirectory("Track")
+        keys = Trackfile.GetListOfKeys()
+        for key in keys:
+            obj = key.ReadObj()
+            path = obj.GetPath()
+            if path_long in path:
+                pattern_long = path.split("_")[-1]
+            if path_down in path:
+                pattern_down = path.split("_")[-1]
+            if path_forward in path:
+                pattern_forward = path.split("_")[-1]
+            if path_velo in path:
+                pattern_velo = path.split("_")[-1]
+            if path_ttrack in path:
+                pattern_ttrack = path.split("_")[-1]
+
+            
         from .utils.LHCbStyle import setLHCbStyle
         from .utils.Legend import place_legend
 
@@ -264,11 +288,13 @@ class PrCheckerSummaryHandler(BaseHandler):
         effPlots_ttrack = getEffPlots_ttrack()
         eff_dict_ttrack = effPlotsDict_ttrack()
 
+        #Put the hash codes inside the path
         for effPlot in effPlots_long:
             outputfile.cd("long")
-            effNom = inputfile.Get(eff_dict_long[effPlot]["path"] +
+            print(effPlot)
+            effNom = inputfile.Get(path_long+pattern_long+eff_dict_long[effPlot]["path"] +
                                    "_reconstructed")
-            effDenom = inputfile.Get(eff_dict_long[effPlot]["path"] +
+            effDenom = inputfile.Get(path_long+pattern_long+eff_dict_long[effPlot]["path"] +
                                      "_reconstructible")
             canvas_eff = ROOT.TCanvas(effPlot, effPlot)
             efficiency = ROOT.TGraphAsymmErrors()
@@ -302,9 +328,9 @@ class PrCheckerSummaryHandler(BaseHandler):
 
         for effPlot in effPlots_down:
             outputfile.cd("down")
-            effNom = inputfile.Get(eff_dict_down[effPlot]["path"] +
+            effNom = inputfile.Get(path_down+pattern_down+eff_dict_down[effPlot]["path"] +
                                    "_reconstructed")
-            effDenom = inputfile.Get(eff_dict_down[effPlot]["path"] +
+            effDenom = inputfile.Get(path_down+pattern_down+eff_dict_down[effPlot]["path"] +
                                      "_reconstructible")
             canvas_eff = ROOT.TCanvas(effPlot, effPlot)
             efficiency = ROOT.TGraphAsymmErrors()
@@ -338,9 +364,9 @@ class PrCheckerSummaryHandler(BaseHandler):
 
         for effPlot in effPlots_forward:
             outputfile.cd("forward")
-            effNom = inputfile.Get(eff_dict_forward[effPlot]["path"] +
+            effNom = inputfile.Get(path_forward+pattern_forward+eff_dict_forward[effPlot]["path"] +
                                    "_reconstructed")
-            effDenom = inputfile.Get(eff_dict_forward[effPlot]["path"] +
+            effDenom = inputfile.Get(path_forward+pattern_forward+eff_dict_forward[effPlot]["path"] +
                                      "_reconstructible")
             canvas_eff = ROOT.TCanvas(effPlot, effPlot)
             efficiency = ROOT.TGraphAsymmErrors()
@@ -374,9 +400,9 @@ class PrCheckerSummaryHandler(BaseHandler):
 
         for effPlot in effPlots_velo:
             outputfile.cd("velo")
-            effNom = inputfile.Get(eff_dict_velo[effPlot]["path"] +
+            effNom = inputfile.Get(path_velo+pattern_velo+eff_dict_velo[effPlot]["path"] +
                                    "_reconstructed")
-            effDenom = inputfile.Get(eff_dict_velo[effPlot]["path"] +
+            effDenom = inputfile.Get(path_velo+pattern_velo+eff_dict_velo[effPlot]["path"] +
                                      "_reconstructible")
             canvas_eff = ROOT.TCanvas(effPlot, effPlot)
             efficiency = ROOT.TGraphAsymmErrors()
@@ -410,9 +436,9 @@ class PrCheckerSummaryHandler(BaseHandler):
 
         for effPlot in effPlots_ttrack:
             outputfile.cd("ttrack")
-            effNom = inputfile.Get(eff_dict_ttrack[effPlot]["path"] +
+            effNom = inputfile.Get(path_ttrack+pattern_ttrack+eff_dict_ttrack[effPlot]["path"] +
                                    "_reconstructed")
-            effDenom = inputfile.Get(eff_dict_ttrack[effPlot]["path"] +
+            effDenom = inputfile.Get(path_ttrack+pattern_ttrack+eff_dict_ttrack[effPlot]["path"] +
                                      "_reconstructible")
             canvas_eff = ROOT.TCanvas(effPlot, effPlot)
             efficiency = ROOT.TGraphAsymmErrors()
diff --git a/handlers/PrCheckerSummaryHandler_withoutUT.py b/handlers/PrCheckerSummaryHandler_withoutUT.py
index 5e534ca2..a68cba5b 100644
--- a/handlers/PrCheckerSummaryHandler_withoutUT.py
+++ b/handlers/PrCheckerSummaryHandler_withoutUT.py
@@ -25,7 +25,6 @@ from .gaussValidation import grepPattern
 from collectRunResults import urlopen
 import logging
 import subprocess
-
 from collections import defaultdict
 
 
@@ -37,13 +36,12 @@ def effPlotsDict_long():
         "nPV": {},
         "docaz": {},
     }
-
-    basedict["Pt"]["path"] = "Track/BestLongTrackChecker/BestLong/01_long_Pt"
-    basedict["P"]["path"] = "Track/BestLongTrackChecker/BestLong/01_long_P"
-    basedict["Eta"]["path"] = "Track/BestLongTrackChecker/BestLong/01_long_Eta"
-    basedict["nPV"]["path"] = "Track/BestLongTrackChecker/BestLong/01_long_nPV"
+    basedict["Pt"]["path"] = "/BestLong/01_long_Pt"
+    basedict["P"]["path"] = "/BestLong/01_long_P"
+    basedict["Eta"]["path"] = "/BestLong/01_long_Eta"
+    basedict["nPV"]["path"] = "/BestLong/01_long_nPV"
     basedict["docaz"][
-        "path"] = "Track/BestLongTrackChecker/BestLong/01_long_docaz"
+        "path"] = "/BestLong/01_long_docaz"
     basedict["Pt"]["unit"] = "pT [MeV]"
     basedict["P"]["unit"] = "p [MeV]"
     basedict["Eta"]["unit"] = "#eta [-]"
@@ -69,17 +67,16 @@ def effPlotsDict_velo():
         "nPV": {},
         "docaz": {},
     }
-
     basedict["Pt"][
-        "path"] = "Track/VeloFullTrackChecker/VeloFull/01_notElectron_Velo_Pt"
+        "path"] = "/VeloFull/01_notElectron_Velo_Pt"
     basedict["P"][
-        "path"] = "Track/VeloFullTrackChecker/VeloFull/01_notElectron_Velo_P"
+        "path"] = "/VeloFull/01_notElectron_Velo_P"
     basedict["Eta"][
-        "path"] = "Track/VeloFullTrackChecker/VeloFull/01_notElectron_Velo_Eta"
+        "path"] = "/VeloFull/01_notElectron_Velo_Eta"
     basedict["nPV"][
-        "path"] = "Track/VeloFullTrackChecker/VeloFull/01_notElectron_Velo_nPV"
+        "path"] = "/VeloFull/01_notElectron_Velo_nPV"
     basedict["docaz"][
-        "path"] = "Track/VeloFullTrackChecker/VeloFull/01_notElectron_Velo_docaz"
+        "path"] = "/VeloFull/01_notElectron_Velo_docaz"
     basedict["Pt"]["unit"] = "pT [MeV]"
     basedict["P"]["unit"] = "p [MeV]"
     basedict["Eta"]["unit"] = "#eta [-]"
@@ -105,12 +102,11 @@ def effPlotsDict_ttrack():
         "nPV": {},
         "docaz": {},
     }
-
-    basedict["Pt"]["path"] = "Track/SeedTrackChecker/Seed/01_hasT_Pt"
-    basedict["P"]["path"] = "Track/SeedTrackChecker/Seed/01_hasT_P"
-    basedict["Eta"]["path"] = "Track/SeedTrackChecker/Seed/01_hasT_Eta"
-    basedict["nPV"]["path"] = "Track/SeedTrackChecker/Seed/01_hasT_nPV"
-    basedict["docaz"]["path"] = "Track/SeedTrackChecker/Seed/01_hasT_docaz"
+    basedict["Pt"]["path"] ="/Seed/01_hasT_Pt"
+    basedict["P"]["path"] ="/Seed/01_hasT_P"
+    basedict["Eta"]["path"] ="/Seed/01_hasT_Eta"
+    basedict["nPV"]["path"] ="/Seed/01_hasT_nPV"
+    basedict["docaz"]["path"] ="/Seed/01_hasT_docaz"
     basedict["Pt"]["unit"] = "pT [MeV]"
     basedict["P"]["unit"] = "p [MeV]"
     basedict["Eta"]["unit"] = "#eta [-]"
@@ -156,6 +152,22 @@ class PrCheckerSummaryHandler_withoutUT(BaseHandler):
         inputfile = ROOT.TFile.Open(os.path.join(directory, rootfile), 'read')
         outputfile = ROOT.TFile("PrCheckerSummary.root", "recreate")
 
+        #Get the hash codes
+        path_long = "Track/BestLongTrackChecker_"
+        path_velo = "Track/VeloFullTrackChecker_"
+        path_ttrack = "Track/SeedTrackChecker_"
+        Trackfile = inputfile.GetDirectory("Track")
+        keys = Trackfile.GetListOfKeys()
+        for key in keys:
+            obj = key.ReadObj()
+            path = obj.GetPath()
+            if path_long in path:
+                pattern_long = path.split("_")[-1]
+            if path_velo in path:
+                pattern_velo = path.split("_")[-1]
+            if path_ttrack in path:
+                pattern_ttrack = path.split("_")[-1]
+
         from .utils.LHCbStyle import setLHCbStyle
         from .utils.Legend import place_legend
 
@@ -176,11 +188,12 @@ class PrCheckerSummaryHandler_withoutUT(BaseHandler):
         effPlots_ttrack = getEffPlots_ttrack()
         eff_dict_ttrack = effPlotsDict_ttrack()
 
+        #Put the hash codes inside the path
         for effPlot in effPlots_long:
             outputfile.cd("long")
-            effNom = inputfile.Get(eff_dict_long[effPlot]["path"] +
+            effNom = inputfile.Get(path_long+pattern_long+eff_dict_long[effPlot]["path"] +
                                    "_reconstructed")
-            effDenom = inputfile.Get(eff_dict_long[effPlot]["path"] +
+            effDenom = inputfile.Get(path_long+pattern_long+eff_dict_long[effPlot]["path"] +
                                      "_reconstructible")
             canvas_eff = ROOT.TCanvas(effPlot, effPlot)
             efficiency = ROOT.TGraphAsymmErrors()
@@ -214,9 +227,10 @@ class PrCheckerSummaryHandler_withoutUT(BaseHandler):
 
         for effPlot in effPlots_velo:
             outputfile.cd("velo")
-            effNom = inputfile.Get(eff_dict_velo[effPlot]["path"] +
+            print(eff_dict_velo[effPlot]["path"])
+            effNom = inputfile.Get(path_velo+pattern_velo+eff_dict_velo[effPlot]["path"] +
                                    "_reconstructed")
-            effDenom = inputfile.Get(eff_dict_velo[effPlot]["path"] +
+            effDenom = inputfile.Get(path_velo+pattern_velo+eff_dict_velo[effPlot]["path"] +
                                      "_reconstructible")
             canvas_eff = ROOT.TCanvas(effPlot, effPlot)
             efficiency = ROOT.TGraphAsymmErrors()
@@ -250,9 +264,9 @@ class PrCheckerSummaryHandler_withoutUT(BaseHandler):
 
         for effPlot in effPlots_ttrack:
             outputfile.cd("ttrack")
-            effNom = inputfile.Get(eff_dict_ttrack[effPlot]["path"] +
+            effNom = inputfile.Get(path_ttrack+pattern_ttrack+eff_dict_ttrack[effPlot]["path"] +
                                    "_reconstructed")
-            effDenom = inputfile.Get(eff_dict_ttrack[effPlot]["path"] +
+            effDenom = inputfile.Get(path_ttrack+pattern_ttrack+eff_dict_ttrack[effPlot]["path"] +
                                      "_reconstructible")
             canvas_eff = ROOT.TCanvas(effPlot, effPlot)
             efficiency = ROOT.TGraphAsymmErrors()
-- 
GitLab