Skip to content

Commit

Permalink
add pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Zehvogel committed Jul 3, 2024
1 parent 7b151a5 commit dfe4e65
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 66 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: pre-commit

on: [push, pull_request]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: cvmfs-contrib/[email protected]
- uses: aidasoft/run-lcg-view@v4
with:
release-platform: LCG_101/x86_64-centos7-clang12-opt
run: |
export PYTHONPATH=$(python -m site --user-site):$PYTHONPATH
export PATH=/root/.local/bin:$PATH
pip install --upgrade --user pip
pip install pre-commit --user
# Use virtualenv from the LCG release
pip uninstall --yes virtualenv
pre-commit run --show-diff-on-failure \
--color=always \
--all-files
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.4.0
hooks:
- id: mixed-line-ending
- id: trailing-whitespace
- id: end-of-file-fixer
36 changes: 18 additions & 18 deletions TrackingPerformance/Plotting/SuperimposedCanvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def combine_canvases(input_files, output_file, marker_styles_func, legend_text,
# Define different legend position for theta and momentum plots
if marker_styles_func == momentum_styles:
output_legend = ROOT.TLegend(0.55, 0.55, 1.30, 0.92)
#output_legend = ROOT.TLegend(0.65, 0.55, 1.30, 0.92) #x1,y1,x2,y2 normalised coordinates in the current pad
#output_legend = ROOT.TLegend(0.65, 0.55, 1.30, 0.92) #x1,y1,x2,y2 normalised coordinates in the current pad
elif marker_styles_func == theta_styles:
output_legend = ROOT.TLegend(0.5, 0.60, 1.15, 0.92) #x1,y1,x2,y2 normalised coordinates in the current pad
output_legend.SetTextFont(62)
Expand All @@ -72,7 +72,7 @@ def combine_canvases(input_files, output_file, marker_styles_func, legend_text,
for input_file_idx, input_file in enumerate(input_files):
input_root_file = ROOT.TFile(input_file)
input_canvas = input_root_file.Get(canvas_name)

if input_canvas and input_canvas.InheritsFrom("TCanvas"):
primitives = input_canvas.GetListOfPrimitives()
for i in range(primitives.GetSize()):
Expand Down Expand Up @@ -110,15 +110,15 @@ def combine_canvases(input_files, output_file, marker_styles_func, legend_text,
if prim.InheritsFrom("TLegend"):
input_legend = prim
break

if input_legend:
for marker_idx in range(len(marker_styles)):
for marker_idx in range(len(marker_styles)):
new_entry = input_legend.GetListOfPrimitives().At(marker_idx).Clone()
new_entry.SetTextFont(43)
new_entry.SetFillStyle(0)
new_entry.SetMarkerStyle(marker_styles[marker_idx])
new_entry.SetMarkerColor(marker_colors[marker_idx])
new_entry.SetMarkerSize(1.5)
new_entry.SetMarkerSize(1.5)
legend_label = f"{new_entry.GetLabel()}{legend_text[input_file_idx]}\n"
output_legend.AddEntry(new_entry, legend_label, "P")
#for marker_idx in range(1, len(marker_styles) + 1 ): # Skip legend Title
Expand All @@ -134,13 +134,13 @@ def combine_canvases(input_files, output_file, marker_styles_func, legend_text,


output_canvas = ROOT.TCanvas(canvas_name, "Superposed Canvas", 800, 800)

# Set log scales for X and Y axes
if log_x:
output_canvas.SetLogx()
if log_y:
output_canvas.SetLogy()

# Get the current pad
pad = output_canvas.GetPad(0)
# Set the position of the right and top axes
Expand All @@ -151,17 +151,17 @@ def combine_canvases(input_files, output_file, marker_styles_func, legend_text,
output_canvas.SetLeftMargin(0.185)
output_canvas.SetTopMargin(0.06)
output_canvas.SetBottomMargin(0.15)

# Draw the superposed TMultiGraph to the output canvas
superposed_multigraph.Draw("APE" if output_canvas.GetListOfPrimitives().GetSize() == 0 else "APEsame")

# Set the X-axis title
if marker_styles_func == momentum_styles:
superposed_multigraph.GetXaxis().SetTitle("momentum [GeV]")
elif marker_styles_func == theta_styles:
superposed_multigraph.GetXaxis().SetTitle("#theta [deg]")
superposed_multigraph.GetXaxis().SetTitleSize(0.06)

# Set the Y-axis title based on the input canvas name
y_axis_title = set_y_axis_title(canvas_name)
superposed_multigraph.GetYaxis().SetTitle(y_axis_title)
Expand All @@ -174,19 +174,19 @@ def combine_canvases(input_files, output_file, marker_styles_func, legend_text,
elif marker_styles_func == momentum_styles:
y_axis_range = set_y_axis_range_momentum(canvas_name)
superposed_multigraph.GetYaxis().SetRangeUser(y_axis_range[0],y_axis_range[1])

# Set bigger axis scale numbers
superposed_multigraph.GetXaxis().SetLabelSize(0.05)
superposed_multigraph.GetYaxis().SetLabelSize(0.05)

# Increase the marker size
marker_size = 1.5
for graph in superposed_multigraph.GetListOfGraphs():
graph.SetMarkerSize(marker_size)

# Draw the legend on the output canvas
output_legend.Draw()

# Add text on the top left above the graph
text_left_x = 0.19
text_left_y = 0.95
Expand All @@ -195,7 +195,7 @@ def combine_canvases(input_files, output_file, marker_styles_func, legend_text,
latex_left.SetTextFont(42)
latex_left.SetTextSize(0.04)
latex_left.DrawLatexNDC(text_left_x, text_left_y, "FCC-ee CLD")

# Save the output canvas to the root file
output_root_file.cd()
output_canvas.Write()
Expand All @@ -210,7 +210,7 @@ def combine_canvases(input_files, output_file, marker_styles_func, legend_text,
output_pdf_canvas.Print(output_pdf_file + "]")
output_root_file.Close()

if __name__ == "__main__":
if __name__ == "__main__":

def set_styles_and_colors_momentum(input_file_idx):
marker_styles_full = [ROOT.kFullTriangleUp, ROOT.kFullSquare, ROOT.kFullDiamond, ROOT.kFullCross, ROOT.kFullCircle]
Expand All @@ -231,7 +231,7 @@ def set_styles_and_colors_momentum(input_file_idx):
0: (marker_styles_full, colors1),
1: (marker_styles_open, colors1),
}

return style_map.get(input_file_idx, (marker_styles_full, colors1))
momentum_styles = set_styles_and_colors_momentum

Expand All @@ -254,7 +254,7 @@ def set_styles_and_colors_theta(input_file_idx):
#2: (marker_styles_full, colors1),
#3: (marker_styles_full, colors2),
}

return style_map.get(input_file_idx, (marker_styles_full, colors1))
theta_styles = set_styles_and_colors_theta
#_________________________________________________________________
Expand Down
46 changes: 23 additions & 23 deletions TrackingPerformance/Plotting/SuperimposedCanvas_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def add_entries_from_canvas(input_canvas, styles, colors, output_legend, additio
if prim.InheritsFrom("TLegend"):
legend = prim
break

if legend:
for idx, entry in enumerate(legend.GetListOfPrimitives()):
# Skip the first element if necessary
Expand All @@ -125,7 +125,7 @@ def extract_file_identifier(file_name, canvas_style):
else:
raise ValueError(f"Unable to extract file identifier from {file_name}")
elif canvas_style == 'momentum':
# Processing 'momentum' style
# Processing 'momentum' style
if '10.root' in file_name:
return '10'
elif '30.root' in file_name:
Expand All @@ -147,7 +147,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
output_pdf_canvas = ROOT.TCanvas("combined_canvas_ratio", "Combined Canvas Ratio", 600, 600)
output_pdf_file = output_file_path[:-5] + ".pdf"
output_pdf_canvas.Print(output_pdf_file + "[")

graphs_from_a = {cn: [] for cn in canvas_names}
graphs_from_b = {cn: [] for cn in canvas_names}
ratio_graphs = {cn: [] for cn in canvas_names}
Expand All @@ -163,19 +163,19 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
file_path_b = os.path.join(folder_b, file_name)
# Calling process_canvas for each file
file_identifier_a = extract_file_identifier(file_path_a, canvas_style)
graphs_a = process_canvas(folder_a + file_name, canvas_name, 'a', file_identifier_a, canvas_style)
graphs_a = process_canvas(folder_a + file_name, canvas_name, 'a', file_identifier_a, canvas_style)

file_identifier_b = extract_file_identifier(file_path_b, canvas_style)
graphs_b = process_canvas(folder_b + file_name, canvas_name, 'b', file_identifier_b, canvas_style)
graphs_b = process_canvas(folder_b + file_name, canvas_name, 'b', file_identifier_b, canvas_style)

# Create a new canvas for comparison and ratio plots
output_root_file.cd()
comparison_canvas = ROOT.TCanvas(f"{canvas_name}_{file_name[:-5]}", f"Comparison: {canvas_name}", 600, 600)
comparison_canvas.Divide(1, 2) # Divide the canvas for original and ratio plots
# Top pad

# Top pad
pad1 = ROOT.TPad("pad1", "pad1", 0, 0.3, 1, 1.0)
pad1.SetBottomMargin(0.0001)
pad1.SetBottomMargin(0.0001)
pad1.SetLeftMargin(0.2)
pad1.SetRightMargin(0.02)
pad1.SetTopMargin(0.07)
Expand All @@ -195,7 +195,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
y_axis_title = set_y_axis_title(canvas_name)
graph.GetYaxis().SetTitle(y_axis_title)
graph.GetXaxis().SetLabelSize(0)
graph.GetYaxis().SetTitleSize(0.08)
graph.GetYaxis().SetTitleSize(0.08)
graph.GetYaxis().SetLabelSize(0.07)
graph.SetTitle("")
pad1.cd()
Expand All @@ -214,7 +214,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
pad1.cd()
graph.Draw("P SAME") # Draw on top of existing graphs without axes
graphs_from_b[canvas_name].append(graph)

pad1.Update()

# Log scale for momentum X axis
Expand All @@ -223,7 +223,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_

pad1.Update()

# Bottom pad
# Bottom pad
comparison_canvas.cd() # Go back to the canvas to add the second pad

pad2 = ROOT.TPad("pad2", "pad2", 0, 0.0, 1, 0.3)
Expand All @@ -234,7 +234,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
if canvas_style == "momentum": pad2.SetLogx()
pad2.Draw()
pad2.cd()

# Calculating and drawing ratio
if graphs_a and graphs_b:
n_points = graphs_a[0].GetN()
Expand All @@ -254,7 +254,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
global_min_ratio = ratio
if ratio > global_max_ratio:
global_max_ratio = ratio

y_ratio.SetPoint(i, xa, ratio)
y_ratio.SetPointError(i, 0, error)
file_identifier = extract_file_identifier(folder_b + file_name, canvas_style)
Expand All @@ -266,13 +266,13 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
y_axis_limits[canvas_name]['min'] = min(y_axis_limits[canvas_name]['min'], ratio)
y_axis_limits[canvas_name]['max'] = max(y_axis_limits[canvas_name]['max'], ratio)

y_ratio.GetXaxis().SetTitleSize(0.18)
y_ratio.GetXaxis().SetTitleSize(0.18)
y_ratio.GetXaxis().SetLabelSize(0.15)
y_ratio.GetXaxis().SetTickSize(0.11)
y_ratio.GetYaxis().SetLabelSize(0.08)
y_ratio.SetTitle(";#theta [deg];") if canvas_style == "theta" else y_ratio.SetTitle(";momentum [GeV];")
y_ratio.Draw("AP")
ratio_graphs[canvas_name].append(y_ratio)
ratio_graphs[canvas_name].append(y_ratio)
pad2.SetTicky(1) # Set right axis
pad2.Update()

Expand All @@ -281,7 +281,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
x_max = y_ratio.GetXaxis().GetXmax()
# Create a TLine at Y = 1 spanning the width of the x-axis range
line = ROOT.TLine(x_min, 1, x_max, 1)
line.SetLineColor(ROOT.kBlack)
line.SetLineColor(ROOT.kBlack)
line.SetLineStyle(2) # Set line style to dotted
# Draw the line on the same pad as your ratio plot
line.Draw("same")
Expand Down Expand Up @@ -320,7 +320,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
pad1.cd() # Switch to the pad where you want the legend to appear
output_legend.Draw()
pad1.Update()

# Add text on the top left above the graph
pad1.cd()
text_left_x = 0.21
Expand All @@ -347,10 +347,10 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_

# Top pads
top_pad = combined_canvas.cd(1)
top_pad.SetPad(0.0, 0.3, 1.0, 1.0)
top_pad.SetPad(0.0, 0.3, 1.0, 1.0)
top_pad.SetRightMargin(0.02)
top_pad.SetTopMargin(0.07)
top_pad.SetBottomMargin(0.0001)
top_pad.SetTopMargin(0.07)
top_pad.SetBottomMargin(0.0001)
top_pad.SetLeftMargin(0.2)

# Set right and top axes
Expand Down Expand Up @@ -389,7 +389,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_

bottom_pad = combined_canvas.cd(2)
bottom_pad.SetPad(0, 0.0, 1, 0.3)
bottom_pad.SetTopMargin(0.0)
bottom_pad.SetTopMargin(0.0)
bottom_pad.SetBottomMargin(0.5) # Increase bottom margin for axis labels
bottom_pad.SetLeftMargin(0.2)
bottom_pad.SetRightMargin(0.02)
Expand All @@ -401,7 +401,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
draw_option = "APE" if first_graph else "PE same"
y_min = y_axis_limits[canvas_name]['min']
y_max = y_axis_limits[canvas_name]['max']
buffer = (y_max - y_min) * 0.1
buffer = (y_max - y_min) * 0.1
y_min_adjusted = y_min - buffer
y_max_adjusted = y_max + buffer
y_ratio.GetYaxis().SetRangeUser(y_min_adjusted, y_max_adjusted)
Expand All @@ -411,7 +411,7 @@ def process_and_compare_graphs(output_file_path, canvas_names, folder_a, folder_
x_max = y_ratio.GetXaxis().GetXmax()
# Create a TLine at Y = 1 spanning the width of the x-axis range
line = ROOT.TLine(x_min, 1, x_max, 1)
line.SetLineColor(ROOT.kBlack)
line.SetLineColor(ROOT.kBlack)
line.SetLineStyle(2) # Set line style to dotted
# Draw the line on the same pad as your ratio plot
line.Draw("same")
Expand Down
10 changes: 5 additions & 5 deletions TrackingPerformance/Plotting/analysis_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#MomentumList = ["1", "10", "100"]
DetectorModel = ["CLD_o2_v05"] # FCCee_o1_v04 CLD_o2_v05 CLD_o3_v01
Nevts = "10000"
Nevts_per_job = "1000"
Nevts_per_job = "1000"

# Output and input directories
#inputDir = f"/eos/experiment/fcc/users/g/gasadows/TrackingPerformance/{DetectorModel[0]}/REC/mu/VXD_3mic"
Expand Down Expand Up @@ -56,10 +56,10 @@ def analysers(df):
.Define("GunParticle_index", "MCParticles.generatorStatus == 1")
.Define("GunParticle", "MCParticles[GunParticle_index][0]")

.Define("trackStates_IP", "SiTracks_Refitted_1[SiTracks_Refitted_1.location == 1]")
.Define("trackStates_IP", "SiTracks_Refitted_1[SiTracks_Refitted_1.location == 1]")
.Define("MC2TrackIndex", "MCTruthTrackIndex(MCTrackAssociations0, MCTrackAssociations1, MCParticles)")
.Define("GunParticleTrackIndex", "MC2TrackIndex[GunParticle_index][0]")
.Define("GunParticleTSIP", "trackStates_IP[GunParticleTrackIndex]")
.Define("GunParticleTSIP", "trackStates_IP[GunParticleTrackIndex]")

.Define("MatchedGunParticle_1", "MCParticles[MC2TrackIndex != -1]")
.Define("MatchedGunParticle", "FCCAnalyses::MCParticle::sel_genStatus(1) (MatchedGunParticle_1)")
Expand All @@ -75,7 +75,7 @@ def analysers(df):
.Define("reco_omega", "GunParticleTSIP.omega")
.Define("reco_tanLambda", "GunParticleTSIP.tanLambda")
.Define("reco_pvec", "auto p = GunParticleTSIPHelix.getMomentum(); return ROOT::Math::XYZVector(p[0], p[1], p[2]);")
.Define("reco_p", "reco_pvec.R()")
.Define("reco_p", "reco_pvec.R()")
.Define("reco_phi", "reco_pvec.Phi()")
.Define("reco_theta", "reco_pvec.Theta()")

Expand All @@ -89,7 +89,7 @@ def analysers(df):
.Define("true_omega", "GunParticleMCHelix.getOmega()")
.Define("true_tanLambda", "GunParticleMCHelix.getTanLambda()")
.Define("true_pvec", "ROOT::Math::XYZVector(GunParticleMCMom[0], GunParticleMCMom[1], GunParticleMCMom[2])")
.Define("true_p", "true_pvec.R()")
.Define("true_p", "true_pvec.R()")
.Define("true_phi", "true_pvec.Phi()")
.Define("true_theta", "true_pvec.Theta()")

Expand Down
4 changes: 2 additions & 2 deletions TrackingPerformance/Plotting/mergeRecOutputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ def merge_files(theta, momentum, part, dect, eos_dir, Nevts_, Nevt_per_job):
def main():

print(f"Number of processors available: {os.cpu_count()}")

# Parameters as per your script
thetaList_ = ["89"]
momentumList_ = ["1", "10", "100"]
particleList_ = ["mu"]
DetectorModelList_ = ["CLD_o2_v05"]

Nevts_ = "10"
Nevts_ = "10"
Nevt_per_job = "5"

eos_dir = f"/eos/user/g/gasadows/Output/TrackingPerformance/{DetectorModelList_[0]}/REC/"
Expand Down
Loading

0 comments on commit dfe4e65

Please sign in to comment.