-
Notifications
You must be signed in to change notification settings - Fork 10
ROOT Statistical Interference + Introdcing GitHub Actions for fitting results validation #53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+2,195
−70
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| name: Validate CMS Open Data ttbar analysis | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| run-cms-open-data-ttbar-analysis: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Set up ROOT environment | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y dpkg-dev cmake g++ gcc binutils libx11-dev libncurses5-dev libssl-dev libxpm-dev \ | ||
| libxft-dev libxml2-dev libz-dev libxext-dev python3-dev git libtbb-dev libgif-dev xrootd-client python3 | ||
| pip install numpy plotting distributed tqdm uproot | ||
| wget https://root.cern/download/root_v6.32.04.Linux-ubuntu22.04-x86_64-gcc11.4.tar.gz | ||
| tar -xzvf root_v6.32.04.Linux-ubuntu22.04-x86_64-gcc11.4.tar.gz | ||
| source root/bin/thisroot.sh | ||
| echo "ROOT is set up" | ||
| - name: Run Analysis | ||
| run: | | ||
| source root/bin/thisroot.sh | ||
| cd analyses/cms-open-data-ttbar/ | ||
| ./validate | tee output.txt | ||
| - name: Compare histograms validation output with expected | ||
| id: histograms | ||
| run: | | ||
| cd analyses/cms-open-data-ttbar/ | ||
| if grep -q "Test failed: Histograms validation output does not match expected result." output.txt; then | ||
| echo "Histograms validation failed." | ||
| echo "RESULT_HISTOGRAMS=fail" >> $GITHUB_ENV | ||
| exit 1 | ||
| else | ||
| echo "Histograms validation passed." | ||
| echo "RESULT_HISTOGRAMS=pass" >> $GITHUB_ENV | ||
| fi | ||
| - name: Run validation sequences for fitResults | ||
| id: fitresults | ||
| run: | | ||
| cd analyses/cms-open-data-ttbar/ | ||
| if grep -q "Test failed: fitResults validation output does not match expected result." output.txt; then | ||
| echo "fitResults validation failed." | ||
| echo "RESULT_FITRESULTS=fail" >> $GITHUB_ENV | ||
| exit 1 | ||
| else | ||
| echo "fitResults validation passed." | ||
| echo "RESULT_FITRESULTS=pass" >> $GITHUB_ENV | ||
| fi | ||
2 changes: 2 additions & 0 deletions
2
.github/workflows/validation/histograms_1_file_validation_reference.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Validating 'histograms.root' against reference 'reference/histos_1_file_per_process.json'... | ||
| All good! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Validating 'histograms.root' against reference 'reference/histos_1_file_per_process.json'... | ||
| All good! |
Binary file added
BIN
+19.8 KB
analyses/cms-open-data-ttbar/reference/fitResults/fitResults_10_file.root
Binary file not shown.
Binary file added
BIN
+19.7 KB
analyses/cms-open-data-ttbar/reference/fitResults/fitResults_1_file.root
Binary file not shown.
Binary file added
BIN
+19.8 KB
analyses/cms-open-data-ttbar/reference/fitResults/fitResults_5_file.root
Binary file not shown.
88 changes: 88 additions & 0 deletions
88
analyses/cms-open-data-ttbar/reference/fitResults/validate_fit_result.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| import argparse | ||
|
|
||
| import ROOT | ||
|
|
||
| # Create an argument parser | ||
| parser = argparse.ArgumentParser(description="Run the fitting part of the analysis.") | ||
|
|
||
| # Add argument for the first parameter (n-max-files-per-sample) | ||
| parser.add_argument('--n-files-per-sample', type=int, required=True, help="Maximum number of files per sample.") | ||
|
|
||
|
|
||
| def get_fit_result(file_path, fit_result_name): | ||
| """Open the ROOT file and retrieve the RooFitResult object.""" | ||
| file = ROOT.TFile(file_path) | ||
| fit_result = file.Get(fit_result_name) | ||
| if not fit_result: | ||
| raise ValueError( | ||
| f"Fit result '{fit_result_name}' not found in {file_path}" | ||
| ) | ||
| return fit_result | ||
|
|
||
|
|
||
| def compare_fit_results(result1, result2): | ||
| """Compare the parameter values of two RooFitResults.""" | ||
| params1 = result1.floatParsFinal() | ||
| params2 = result2.floatParsFinal() | ||
|
|
||
| # Check for the same number of parameters | ||
| if params1.getSize() != params2.getSize(): | ||
| print( | ||
| f"Number of parameters differ: {params1.getSize()} != {params2.getSize()}" | ||
| ) | ||
| return | ||
|
|
||
| print("Comparing parameters...") | ||
|
|
||
| ERROR = False | ||
|
|
||
| # Loop over parameters in the first result and compare with the second | ||
| for i in range(params1.getSize()): | ||
| par1 = params1[i] | ||
| par2 = params2.find( | ||
| par1.GetName() | ||
| ) # Find corresponding parameter by name in result2 | ||
|
|
||
| if not par2: | ||
| print( | ||
| f"Parameter '{par1.GetName()}' not found in the second fit result." | ||
| ) | ||
| ERROR = True | ||
| continue | ||
|
|
||
| # Compare values and print differences | ||
| if abs(par1.getVal() - par2.getVal()) < 1e-6: | ||
| print(f"Parameter '{par1.GetName()}' matches: {par1.getVal()}") | ||
| else: | ||
| print( | ||
| f"Parameter '{par1.GetName()}' differs: {par1.getVal()} != {par2.getVal()}" | ||
| ) | ||
| ERROR = True | ||
|
|
||
| # Optionally compare errors too | ||
| if abs(par1.getError() - par2.getError()) > 1e-6: | ||
| print( | ||
| f"Parameter '{par1.GetName()}' error differs: {par1.getError()} != {par2.getError()}" | ||
| ) | ||
| ERROR = True | ||
|
|
||
| if ERROR: | ||
| print("ERROR: Comparison failed.") | ||
|
|
||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| number_of_files = args.n_files_per_sample | ||
|
|
||
| # Replace these with the paths to your .root files and fit result names | ||
| file1 = "./fitResults.root" | ||
| file2 = f"./reference/fitResults/fitResults_{number_of_files}_file.root" | ||
| fit_result_name_1 = "fitResult" # Fit result in first file | ||
| fit_result_name_2 = "fitResult" # Fit result in second file | ||
|
|
||
| # Load the fit results from the two files | ||
| fit_result_1 = get_fit_result(file1, fit_result_name_1) | ||
| fit_result_2 = get_fit_result(file2, fit_result_name_2) | ||
|
|
||
| # Compare the fit results | ||
| compare_fit_results(fit_result_1, fit_result_2) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.