#!/usr/bin/env python # coding: utf-8 # # Introduction # # QA plots for the generic distortions reconstruction performance # In[1]: # imports to write dynamic markdown contents import os from IPython.display import display, Markdown, Latex from IPython.display import HTML # In[2]: # turn off/on code for the result HTML page display(Markdown('*For the result HTML page:* ')) HTML('''
''') # In[3]: import os.path # readme file of the macros, available if run under JenkinsCI # https://github.com/sPHENIX-Collaboration/utilities/blob/master/jenkins/built-test/test-tracking-qa.sh macro_markdown = 'Fun4All-macros-README.md' if os.path.isfile(macro_markdown) : with open(macro_markdown, 'r') as file: display(Markdown(file.read())) # ## `pyROOT` env check # In[4]: import ROOT OFFLINE_MAIN = os.getenv("OFFLINE_MAIN") if OFFLINE_MAIN is not None: display(Markdown(f"via sPHENIX software distribution at `{OFFLINE_MAIN}`")) # ## Plotting source code # In[5]: import subprocess try: git_url = \ subprocess.run(['git','remote','get-url','origin'], stdout=subprocess.PIPE)\ .stdout.decode('utf-8').strip()\ .replace('git@github.com:','https://github.com/') display(Markdown(f"View the source code repository at {git_url}")) except: # catch *all* exceptions # well do nothing pass ## JenkinsCI information (if available) # In[6]: display(Markdown('Some further details about the QA run, if executed under the Jenkins CI:')) checkrun_repo_commit = os.getenv("checkrun_repo_commit") if checkrun_repo_commit is not None: display(Markdown(f"* The commit being checked is {checkrun_repo_commit}")) ghprbPullLink = os.getenv("ghprbPullLink") if ghprbPullLink is not None: display(Markdown(f"* Link to the pull request: {ghprbPullLink}")) BUILD_URL = os.getenv("BUILD_URL") if BUILD_URL is not None: display(Markdown(f"* Link to the build: {BUILD_URL}")) git_url_macros = os.getenv("git_url_macros") sha_macros = os.getenv("sha_macros") if git_url_macros is not None: display(Markdown(f"* Git repo for macros: {git_url_macros} , which merges `{sha_macros}` and the QA tracking branch")) RUN_ARTIFACTS_DISPLAY_URL = os.getenv("RUN_ARTIFACTS_DISPLAY_URL") if RUN_ARTIFACTS_DISPLAY_URL is not None: display(Markdown(f"* Download the QA ROOT files: {RUN_ARTIFACTS_DISPLAY_URL}")) JENKINS_URL = os.getenv("JENKINS_URL") if JENKINS_URL is not None: display(Markdown(f"Automatically generated by [sPHENIX Jenkins continuous integration]({JENKINS_URL}) [![sPHENIX](https://raw.githubusercontent.com/sPHENIX-Collaboration/utilities/master/jenkins/material/sphenix-logo-white-bg-72p.png)](https://www.sphenix.bnl.gov/web/)             [![jenkins.io](https://raw.githubusercontent.com/sPHENIX-Collaboration/utilities/master/jenkins/material/jenkins_logo_title-72p.png)](https://jenkins.io/)")) # # # Initialization # In[7]: get_ipython().run_cell_magic('cpp', '-d', '\n#include "QA_Draw_Utility.C"\n\n#include \n\n#include \n#include \n#include \n#include \n#include \n#include \n') # In[8]: get_ipython().run_cell_magic('cpp', '', '\nSetsPhenixStyle();\nTVirtualFitter::SetDefaultFitter("Minuit2");\n') # In[9]: get_ipython().run_line_magic('jsroot', 'on') # ## Inputs and file checks # In[10]: qa_file_name_new = os.getenv("qa_file_name_new") if qa_file_name_new is None: qa_file_name_new = "G4sPHENIX_test-tracking_Event500_Sum5_qa.root" display(Markdown(f"`qa_file_name_new` env not set. use the default `qa_file_name_new={qa_file_name_new}`")) qa_file_name_ref = os.getenv("qa_file_name_ref") if qa_file_name_ref is None: qa_file_name_ref = qa_file_name_new display(Markdown(f"`qa_file_name_ref` env not set. use the default same as new file `qa_file_name_ref={qa_file_name_ref}`")) elif qa_file_name_ref == 'None': qa_file_name_ref = qa_file_name_new display(Markdown(f"`qa_file_name_ref` env not set. use the default same as new file `qa_file_name_ref={qa_file_name_ref}`")) # In[11]: # qa_file_new = ROOT.TFile.Open(qa_file_name_new); # assert qa_file_new.IsOpen() # qa_file_new.ls() display(Markdown(f"Opening QA file at `{qa_file_name_new}`")) ROOT.gInterpreter.ProcessLine(f"TFile *qa_file_new = new TFile(\"{qa_file_name_new}\");") ROOT.gInterpreter.ProcessLine(f"const char * qa_file_name_new = \"{qa_file_name_new}\";") if qa_file_name_ref is not None: # qa_file_ref = ROOT.TFile.Open(qa_file_name_ref); # assert qa_file_ref.IsOpen() display(Markdown(f"Opening QA reference file at `{qa_file_name_ref}`")) ROOT.gInterpreter.ProcessLine(f"TFile *qa_file_ref = new TFile(\"{qa_file_name_ref}\");") ROOT.gInterpreter.ProcessLine(f"const char * qa_file_name_ref = \"{qa_file_name_ref}\";") else: ROOT.gInterpreter.ProcessLine(f"TFile *qa_file_ref = nullptr;") ROOT.gInterpreter.ProcessLine(f"const char * qa_file_name_ref = nullptr;") # In[12]: get_ipython().run_cell_magic('cpp', '', '\nif (qa_file_new == nullptr) \n{\n cout <<"Error, can not open QA root file"<IsOpen()) \n{\n cout <<"Error, can not open QA root file"<IsOpen()) \n{\n cout <<"Error, can not open ref QA root file"<Divide(2, 1);\n \n auto h_deltarphi_layer_ref = (TH2F *)qa_file_ref->GetObjectChecked(prefix + "deltarphi_layer", "TH2");\n if( !h_deltarphi_layer_ref )\n { \n std::cout << "h_deltarphi_layer_ref not found. doing nothing." << std::endl;\n return;\n }\n h_deltarphi_layer_ref->SetDirectory(nullptr);\n\n auto h_deltarphi_layer_new = (TH2F *)qa_file_new->GetObjectChecked(prefix + "deltarphi_layer", "TH2");\n if( !h_deltarphi_layer_new )\n { \n std::cout << "h_deltarphi_layer_new not found. doing nothing." << std::endl;\n return;\n }\n \n {\n auto newScale = FitResolution_hist(h_deltarphi_layer_new, false, 1);\n newScale->GetXaxis()->SetTitle("layer");\n newScale->GetYaxis()->SetTitle("#LT#Delta r#phi#GT (#mum)");\n newScale->Scale(1e4);\n newScale->SetMinimum(-100);\n newScale->SetMaximum(100);\n\n auto refScale = FitResolution_hist(h_deltarphi_layer_ref, false, 1);\n refScale->Scale(1e4);\n\n cv_deltarphi_layer->cd(1);\n DrawReference(newScale, refScale);\n \n // Draw line at zero\n auto line = HorizontalLine( gPad, 0 );\n line->Draw();\n }\n \n {\n auto newRMS = FitResolution_hist(h_deltarphi_layer_new, false, 2);\n newRMS->GetXaxis()->SetTitle("layer");\n newRMS->GetYaxis()->SetTitle("RMS(#Delta r#phi) (#mum)");\n newRMS->Scale(1e4);\n newRMS->SetMinimum(0);\n newRMS->SetMaximum(1200);\n \n auto refRMS = FitResolution_hist(h_deltarphi_layer_ref, false, 2);\n refRMS->Scale(1e4);\n \n cv_deltarphi_layer->cd(2);\n DrawReference(newRMS, refRMS);\n }\n \n \n cv_deltarphi_layer->Draw();\n \n') # # Delta z residuals (track - cluster) vs layer number # In[14]: get_ipython().run_cell_magic('cpp', '', ' const char *hist_name_prefix = "QAG4SimulationDistortions";\n TString prefix = TString("h_") + hist_name_prefix + TString("_");\n \n TCanvas *cv_deltaz_layer = new TCanvas(TString("QA_Draw_z_residuals") + TString("_") + hist_name_prefix,\n TString("QA_Draw_z_residuals") + TString("_") + hist_name_prefix,\n 1200,500);\n cv_deltaz_layer->Divide(2, 1);\n \n auto h_deltaz_layer_ref = (TH2F *)qa_file_ref->GetObjectChecked(prefix + "deltaz_layer", "TH2");\n if( !h_deltaz_layer_ref )\n { \n std::cout << "h_deltaz_layer_ref not found. doing nothing." << std::endl;\n return;\n }\n h_deltaz_layer_ref->SetDirectory(nullptr);\n\n auto h_deltaz_layer_new = (TH2F *)qa_file_new->GetObjectChecked(prefix + "deltaz_layer", "TH2");\n if( !h_deltaz_layer_new )\n { \n std::cout << "h_deltaz_layer_new not found. doing nothing." << std::endl;\n return;\n }\n h_deltaz_layer_new->SetDirectory(nullptr);\n \n {\n auto newScale = FitResolution_hist(h_deltaz_layer_new, false, 1);\n newScale->GetXaxis()->SetTitle("layer");\n newScale->GetYaxis()->SetTitle("#LT#Delta z#GT (#mum)");\n newScale->Scale(1e4);\n newScale->SetMinimum(-100);\n newScale->SetMaximum(100);\n\n auto refScale = FitResolution_hist(h_deltaz_layer_ref, false, 1);\n refScale->Scale(1e4);\n\n cv_deltaz_layer->cd(1);\n DrawReference(newScale, refScale);\n \n // Draw line at zero\n auto line = HorizontalLine( gPad, 0 );\n line->Draw();\n }\n \n {\n auto newRMS = FitResolution_hist(h_deltaz_layer_new, false, 2);\n newRMS->GetXaxis()->SetTitle("layer");\n newRMS->GetYaxis()->SetTitle("RMS(#Delta z) (#mum)");\n newRMS->Scale(1e4);\n newRMS->SetMinimum(0);\n newRMS->SetMaximum(2000);\n \n auto refRMS = FitResolution_hist(h_deltaz_layer_ref, false, 2);\n refRMS->Scale(1e4);\n \n cv_deltaz_layer->cd(2);\n DrawReference(newRMS, refRMS);\n }\n \n cv_deltaz_layer->Draw();\n \n') # In[15]: get_ipython().run_cell_magic('cpp', '', '\nKSTestSummary::getInstance()->make_summary_txt("QA-Distortions.txt");\n') # In[16]: get_ipython().run_cell_magic('cpp', '', '\nKSTestSummary::getInstance()->make_summary_TCanvas() -> Draw();\n') # In[ ]: