8#include <calibration/example_caf_lib/TestCalibrationAlgorithm.h>
14#include <TClonesArray.h>
18#include <alignment/dataobjects/MilleData.h>
19#include <calibration/dbobjects/TestCalibObject.h>
20#include <calibration/dbobjects/TestCalibMean.h>
23using namespace Calibration;
28 " -------------------------- Test Calibration Algorithm -------------------------\n"
30 " Testing algorithm which just gets mean of a test histogram collected by \n"
31 " CaTest module and provides a DB object with another histogram with one \n"
32 " entry at calibrated value. \n"
33 " ------------------------------------------------------------------------------\n"
39 std::string debugFileName = (this->
getPrefix()) +
"debug.root";
40 B2INFO(
"Storing histograms in " << debugFileName);
43 TDirectory* currentDir = gDirectory;
44 TFile* debugFile =
new TFile(debugFileName.c_str(),
"RECREATE");
46 TH1F* debugHisto =
new TH1F(
"h1",
"h1", 30, -3., 3.);
47 for (
int i = 0; i < 1000; ++i) {
48 debugHisto->Fill(gRandom->Gaus());
71 const std::string previousMeanKey =
"previous_mean";
75 B2INFO(
"An input JSON object was set with the previous calculated mean = " << prevMean);
86 B2INFO(
"Number of Entries in MyTree was " << ttree->GetEntries());
87 B2INFO(
"Number of Entries in MyHisto was " << hist->GetEntries());
89 float mean = hist->GetMean();
90 float meanError = hist->GetMeanError();
92 B2INFO(
"Mean of MyHisto was " << mean);
93 B2INFO(
"Mean Error of MyHisto was " << meanError);
100 B2WARNING(
"We were asked to fail by the m_willFail flag. Failing");
104 for (
auto& fileName : mille->getFiles()) {
105 B2INFO(
"Stored Mille binary file: " << fileName);
108 if (hist->GetEntries() < 100 || ttree->GetEntries() <
getMinEntries() || mille->getFiles().empty())
116 TClonesArray* exampleDBArrayConstants =
new TClonesArray(
"Belle2::TestCalibObject", 2);
118 for (
int i = 0; i < 2; i++) {
124 B2INFO(
"mean: " << mean);
125 B2INFO(
"meanError: " << meanError);
132 if (mean - 42. >= 1.) {
142 float mean = hist->GetMean();
145 B2INFO(
"This is the first run encountered, let's say it is a boundary.");
146 B2INFO(
"Initial mean was " << mean);
152 B2INFO(
"Histogram mean has shifted from " <<
m_previousMean.value()
153 <<
" to " << mean <<
". We are requesting a new payload boundary for ("
154 << currentRun.first <<
"," << currentRun.second <<
")");
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
bool inputJsonKeyExists(const std::string &key) const
Test for a key in the input JSON object.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
std::string getPrefix() const
Get the prefix used for getting calibration data.
EResult
The result of calibration.
@ c_OK
Finished successfully =0 in Python.
@ c_Iterate
Needs iteration =1 in Python.
@ c_NotEnoughData
Needs more data =2 in Python.
@ c_Failure
Failed =3 in Python.
const T getOutputJsonValue(const std::string &key) const
Get a value using a key from the JSON output object, not sure why you would want to do this.
void setOutputJsonValue(const std::string &key, const T &value)
Set a key:value pair for the outputJson object, expected to used internally during calibrate()
CalibrationAlgorithm(const std::string &collectorModuleName)
Constructor - sets the prefix for collected objects (won't be accesses until execute(....
bool getForceFail()
getter for m_willFail
int m_debugHisto
Set if a debugging histogram should be created in the algorithm output directory.
std::optional< float > m_previousMean
During isBoundaryRequired this is used to define the previous run's mean.
virtual EResult calibrate() override
Run algo on data.
float m_allowedMeanShift
Configurable parameter for deciding when to choose a new payload boundary (if used)
virtual bool isBoundaryRequired(const Calibration::ExpRun ¤tRun) override
Decide if a run should be a payload boundary. Only used in certain Python Algorithm Starategies.
void createDebugHistogram()
Perform debug histogram file creation.
TestCalibrationAlgorithm()
Constructor set the prefix to TestCalibration.
int getMinEntries()
getter for m_minEntries
std::shared_ptr< T > getObjectPtr(const std::string &name, const std::vector< Calibration::ExpRun > &requestedRuns)
Get calibration data object by name and list of runs, the Merge function will be called to generate t...
Abstract base class for different kinds of events.
Struct containing exp number and run number.