|
| 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 | +} |
0 commit comments