Skip to content

Commit d6b73ce

Browse files
Merge pull request #150 from mach3-software/feature/kskwarczsnki/sigmaCI
feat: Sigma Var CI
2 parents 9e36dd8 + fdb4972 commit d6b73ce

12 files changed

Lines changed: 984 additions & 6 deletions

CIValidations/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ foreach(app
1010
NuOscillatorInterfaceValidations
1111
pValueValidations
1212
SigmaVarValidations
13+
SigmaVarFDValidation
1314
LLHValidation
1415
PredictiveValidations
1516
)

CIValidations/FitterValidations.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void FitVal(const std::string& Algo, bool MoreTests)
4949
MaCh3Fitter->DragRace();
5050
MaCh3Fitter->RunLLHScan();
5151
MaCh3Fitter->Run2DLLHScan();
52+
MaCh3Fitter->RunSigmaVarFD();
5253
MaCh3Fitter->GetStepScaleBasedOnLLHScan();
5354
}
5455
MaCh3Fitter->RunMCMC();

CIValidations/MaCh3CLI

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ run_covariance_validations() {
5656
./CIValidations/MaCh3ModeValidations
5757
./CIValidations/pValueValidations
5858
./CIValidations/SigmaVarValidations
59+
./CIValidations/SigmaVarFDValidation
5960
if [ "$HAVE_UNITTEST_SUPPORT" -eq 0 ]; then
6061
./CIValidations/UnitTests/manager_tests
6162
./CIValidations/UnitTests/histogram_tests
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// MaCh3 spline includes
2+
#include "Utils/Comparison.h"
3+
#include "TKey.h"
4+
5+
/// Current tests include
6+
int main(int argc, char *argv[])
7+
{
8+
SetMaCh3LoggerFormat();
9+
10+
if (argc != 1) {
11+
MACH3LOG_CRITICAL("You specified arguments, but none are needed. (Program name: ", argv[0]);
12+
throw MaCh3Exception(__FILE__ , __LINE__ );
13+
}
14+
MACH3LOG_INFO("Testing Sigma Var");
15+
std::string TutorialPath = std::getenv("MaCh3Tutorial_ROOT");
16+
17+
std::string command = TutorialPath + "/bin/SigmaVarTutorial " +
18+
TutorialPath + "/TutorialConfigs/FitterConfig.yaml";
19+
int ret = system(command.c_str());
20+
if (ret != 0) {
21+
MACH3LOG_WARN("Error: system call failed with code {}", ret);
22+
}
23+
24+
auto file = std::unique_ptr<TFile>(TFile::Open("SigmaVar_Test.root", "UPDATE"));
25+
std::vector<std::string> Names = {"Norm_Param_0", "Norm_Param_1", "Norm_Param_2", "BinnedSplineParam1", "BinnedSplineParam2", "BinnedSplineParam3", "BinnedSplineParam4", "BinnedSplineParam5", "EResLep", "EResTot"};
26+
std::ofstream outFile("SigmaVar.txt");
27+
for (size_t i = 0; i < Names.size(); ++i) {
28+
std::string dirPath = "SigmaVar/" + Names[i] + "/Tutorial/";
29+
TDirectory* dir = file->GetDirectory(dirPath.c_str());
30+
31+
if (!dir) {
32+
std::cerr << "Missing directory: " << dirPath << std::endl;
33+
return 1;
34+
}
35+
36+
TList* keys = dir->GetListOfKeys();
37+
if (!keys) {
38+
std::cerr << "No keys found in: " << dirPath << std::endl;
39+
continue;
40+
}
41+
42+
for (int i = 0; i < keys->GetSize(); ++i) {
43+
TKey* key = dynamic_cast<TKey*>(keys->At(i));
44+
if (!key) continue;
45+
46+
TObject* obj = key->ReadObj();
47+
TH1* hist = dynamic_cast<TH1*>(obj);
48+
if (!hist) continue;
49+
50+
for (int j = 1; j <= hist->GetNbinsX(); ++j) {
51+
double binContent = hist->GetBinContent(j);
52+
outFile << "Dial " << Names[i]
53+
<< " hist = " << hist->GetTitle()
54+
<< " bin = " << j
55+
<< " content = " << std::fixed << std::setprecision(6)
56+
<< std::fabs(binContent) << std::endl;
57+
}
58+
}
59+
}
60+
outFile.close();
61+
62+
bool TheSame = CompareTwoFiles(TutorialPath + "/CIValidations/TestOutputs/SigmaVarOut.txt", "SigmaVar.txt");
63+
if(!TheSame) {
64+
MACH3LOG_CRITICAL("Something is wrong with SigmaVar");
65+
throw MaCh3Exception(__FILE__ , __LINE__ );
66+
} else {
67+
MACH3LOG_INFO("Everything is correct");
68+
}
69+
70+
file->Close();
71+
return 0;
72+
}

CIValidations/TestOutputs/SigmaVarOut.txt

Lines changed: 850 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ MaCh3 is predominantly C++ software although some functionality are available th
2626
6. [Useful Settings](#useful-settings)
2727
7. [How to Plot?](#how-to-plot)
2828
1. [How to run LLH scan](#how-to-run-llh-scan)
29-
2. [Plotting with Python](#plotting-with-python)
29+
2. [How to run Sigma Variation](#how-to-run-sigma-variation)
30+
3. [Plotting with Python](#plotting-with-python)
3031

3132
## How to Start?
3233
To compile simply
@@ -337,14 +338,17 @@ Read more [here](https://mach3-software.github.io/MaCh3/Structs_8h.html#a960da89
337338

338339
## How to Plot?
339340

340-
There are a number of apps included to make plots from the results of your fits, llh scans etc. You can find more details on them and how they work in the main MaCh3 wiki [here](https://github.com/mach3-software/MaCh3/wiki). There you will also find some instructions on how you can write yor own plotting scripts.
341+
There are a number of apps included to make plots from the results of your fits, llh scans etc. You can find more details on them and how they work in the main MaCh3 wiki [here](https://github.com/mach3-software/MaCh3/wiki). There you will also find some instructions on how you can write your own plotting scripts.
341342

342343
The plotting library is configured using yaml files. You can see some examples of such config files in the plotting directory, and a detailed explanation of them is given in [the wiki](https://github.com/mach3-software/MaCh3/wiki).
343344

344345
Some examples on how to make some "standard" plots are given below.
345346

346347
### How to run LLH scan
347-
You can run MCMC in very similar way as MCMC
348+
LLH scan is a procedure where one changes value of single parameter, reweight MC and calculates likelihood.
349+
If running with Asimov setting at prior value LLH should be 0. Rate at which LLH is increasing with increase of value indiceate how sensitive your MC is to give parameter.
350+
351+
You can run LLH scan in very similar way as MCMC
348352
```bash
349353
./bin/LLHScanTutorial TutorialConfigs/FitterConfig.yaml
350354
```
@@ -361,6 +365,13 @@ It is possible to compare several files simply by:
361365
PlotLLH LLH_Test.root LLH_Test_2.root
362366
```
363367

368+
### How to run Sigma Variation
369+
Sigma Var is conceptually similar to LLH scan however here instead of looking how LLH changes one investigate actual sample spectra.
370+
371+
```bash
372+
./bin/SigmaVarTutorial TutorialConfigs/FitterConfig.yaml
373+
```
374+
364375
### Plotting with Python
365376

366377
If you have installed the python interface for MaCh3 as described

Tutorial/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ foreach(app
44
MCMCTutorial
55
LLHScanTutorial
66
PredictiveTutorial
7+
SigmaVarTutorial
78
KinemDistributionTutorial
89
)
910
add_executable(${app} ${app}.cpp)

Tutorial/KinemDistributionTutorial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(int argc, char **argv) {
2626
auto xsec = MaCh3CovarianceFactory<ParameterHandlerGeneric>(FitManager.get(), "Xsec");
2727

2828
// Initialise samplePDF
29-
auto SampleConfig = FitManager->raw()["General"]["TutorialSamples"].as<std::vector<std::string>>();
29+
auto SampleConfig = Get<std::vector<std::string>>(FitManager->raw()["General"]["TutorialSamples"], __FILE__ , __LINE__);
3030
auto mySamples = MaCh3SampleHandlerFactory<SampleHandlerTutorial>(SampleConfig, xsec.get());
3131

3232
// Output file is named after output filename in config plus plot variable(s)

Tutorial/LLHScanTutorial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ int main(int argc, char *argv[]){
1111
auto xsec = MaCh3CovarianceFactory<ParameterHandlerGeneric>(FitManager.get(), "Xsec");
1212

1313
// Initialise samplePDF
14-
auto SampleConfig = FitManager->raw()["General"]["TutorialSamples"].as<std::vector<std::string>>();
14+
auto SampleConfig = Get<std::vector<std::string>>(FitManager->raw()["General"]["TutorialSamples"], __FILE__ , __LINE__);
1515
auto mySamples = MaCh3SampleHandlerFactory<SampleHandlerTutorial>(SampleConfig, xsec.get());
1616

1717
// Create MCMC Class

Tutorial/MCMCTutorial.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int main(int argc, char *argv[]) {
1010
auto xsec = MaCh3CovarianceFactory<ParameterHandlerGeneric>(FitManager.get(), "Xsec");
1111

1212
// Initialise samplePDF
13-
auto SampleConfig = FitManager->raw()["General"]["TutorialSamples"].as<std::vector<std::string>>();
13+
auto SampleConfig = Get<std::vector<std::string>>(FitManager->raw()["General"]["TutorialSamples"], __FILE__ , __LINE__);
1414
auto mySamples = MaCh3SampleHandlerFactory<SampleHandlerTutorial>(SampleConfig, xsec.get());
1515

1616
// Create MCMC Class

0 commit comments

Comments
 (0)