1 #include <calibration/example_caf_lib/TestCalibrationAlgorithm.h>
7 #include <TClonesArray.h>
11 #include <alignment/dataobjects/MilleData.h>
12 #include <calibration/dbobjects/TestCalibObject.h>
13 #include <calibration/dbobjects/TestCalibMean.h>
16 using namespace Calibration;
21 " -------------------------- Test Calibration Algoritm -------------------------\n"
23 " Testing algorithm which just gets mean of a test histogram collected by \n"
24 " CaTest module and provides a DB object with another histogram with one \n"
25 " entry at calibrated value. \n"
26 " ------------------------------------------------------------------------------\n"
32 std::string debugFileName = (this->
getPrefix()) +
"debug.root";
33 B2INFO(
"Storing histograms in " << debugFileName);
36 TDirectory* currentDir = gDirectory;
37 TFile* debugFile =
new TFile(debugFileName.c_str(),
"RECREATE");
39 TH1F* debugHisto =
new TH1F(
"h1",
"h1", 30, -3., 3.);
40 for (
int i = 0; i < 1000; ++i) {
41 debugHisto->Fill(gRandom->Gaus());
64 const std::string previousMeanKey =
"previous_mean";
67 const float prevMean = getOutputJsonValue<float>(previousMeanKey);
68 B2INFO(
"An input JSON object was set with the previous calculated mean = " << prevMean);
73 auto ttree = getObjectPtr<TTree>(
"MyTree");
74 auto hist = getObjectPtr<TH1F>(
"MyHisto");
75 auto mille = getObjectPtr<MilleData>(
"test_mille");
79 B2INFO(
"Number of Entries in MyTree was " << ttree->GetEntries());
80 B2INFO(
"Number of Entries in MyHisto was " << hist->GetEntries());
82 float mean = hist->GetMean();
83 float meanError = hist->GetMeanError();
85 B2INFO(
"Mean of MyHisto was " << mean);
86 B2INFO(
"Mean Error of MyHisto was " << meanError);
93 B2WARNING(
"We were asked to fail by the m_willFail flag. Failing");
97 for (
auto& fileName : mille->getFiles()) {
98 B2INFO(
"Stored Mille binary file: " << fileName);
101 if (hist->GetEntries() < 100 || ttree->GetEntries() <
getMinEntries() || mille->getFiles().empty())
109 TClonesArray* exampleDBArrayConstants =
new TClonesArray(
"Belle2::TestCalibObject", 2);
111 for (
int i = 0; i < 2; i++) {
117 B2INFO(
"mean: " << mean);
118 B2INFO(
"meanError: " << meanError);
122 setOutputJsonValue<float>(previousMeanKey, mean);
125 if (mean - 42. >= 1.) {
134 auto hist = getObjectPtr<TH1F>(
"MyHisto");
135 float mean = hist->GetMean();
138 B2INFO(
"This is the first run encountered, let's say it is a boundary.");
139 B2INFO(
"Initial mean was " << mean);
145 B2INFO(
"Histogram mean has shifted from " <<
m_previousMean.value()
146 <<
" to " << mean <<
". We are requesting a new payload boundary for ("
147 << currentRun.first <<
"," << currentRun.second <<
")");