Belle II Software  release-05-02-19
TestBoundarySettingAlgorithm.cc
1 #include <calibration/example_caf_lib/TestBoundarySettingAlgorithm.h>
2 
3 #include <memory>
4 
5 #include <TH1F.h>
6 
7 #include <calibration/dbobjects/TestCalibMean.h>
8 
9 using namespace Belle2;
10 using namespace Calibration;
11 
13 {
15  " -------------------------- Test Calibration Algoritm -------------------------\n"
16  " \n"
17  " Testing algorithm which just gets mean of a test histogram collected by \n"
18  " CaTest module and provides a DB object with another histogram with one \n"
19  " entry at calibrated value. \n"
20  " ------------------------------------------------------------------------------\n"
21  );
22 }
23 
25 {
26  // Pulling in data from collector output. It now returns shared_ptr<T> so the underlying pointer
27  // will delete itself automatically at the end of this scope unless you do something
28  auto hist = getObjectPtr<TH1F>("MyHisto");
29  if (!hist) return c_Failure;
30  B2INFO("Number of Entries in MyHisto was " << hist->GetEntries());
31 
32  float mean = hist->GetMean();
33  float meanError = hist->GetMeanError();
34 
35  B2INFO("Mean of MyHisto was " << mean);
36  B2INFO("Mean Error of MyHisto was " << meanError);
37 
38  if (hist->GetEntries() < 100)
39  return c_NotEnoughData;
40 
41  // Example of saving a DBObject.
42  TestCalibMean* correction = new TestCalibMean(mean, meanError);
43  saveCalibration(correction, "TestCalibMean");
44 
45  // Decide if we need to iterate or if this value was fine
46  if (mean - 42. >= 1.) {
47  return c_Iterate;
48  } else {
49  return c_OK;
50  }
51 }
52 
53 
55 {
56  // First run in data as we iterate, but our boundaries weren't set manually already?
57  // Just set the first run to be a boundary and we are done.
58  if (m_boundaries.empty()) {
59  B2INFO("This is the first run encountered, let's say it is a boundary.");
60  return true;
61  } else {
62  return false;
63  }
64 }
Belle2::CalibrationAlgorithm::saveCalibration
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
Definition: CalibrationAlgorithm.cc:290
Belle2::CalibrationAlgorithm::c_Iterate
@ c_Iterate
Needs iteration =1 in Python.
Definition: CalibrationAlgorithm.h:52
Belle2::CalibrationAlgorithm::c_OK
@ c_OK
Finished successfuly =0 in Python.
Definition: CalibrationAlgorithm.h:51
Belle2::CalibrationAlgorithm::setDescription
void setDescription(const std::string &description)
Set algorithm description (in constructor)
Definition: CalibrationAlgorithm.h:331
Belle2::TestBoundarySettingAlgorithm::TestBoundarySettingAlgorithm
TestBoundarySettingAlgorithm()
Constructor set the prefix to TestCalibration.
Definition: TestBoundarySettingAlgorithm.cc:12
Belle2::TestBoundarySettingAlgorithm::calibrate
virtual EResult calibrate() override
Run algo on data.
Definition: TestBoundarySettingAlgorithm.cc:24
Belle2::TestCalibMean
Test DBObject.
Definition: TestCalibMean.h:27
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::CalibrationAlgorithm::c_Failure
@ c_Failure
Failed =3 in Python.
Definition: CalibrationAlgorithm.h:54
Belle2::ExpRun
Struct containing exp number and run number.
Definition: Splitter.h:55
Belle2::CalibrationAlgorithm::EResult
EResult
The result of calibration.
Definition: CalibrationAlgorithm.h:50
Belle2::CalibrationAlgorithm::c_NotEnoughData
@ c_NotEnoughData
Needs more data =2 in Python.
Definition: CalibrationAlgorithm.h:53
Belle2::CalibrationAlgorithm
Base class for calibration algorithms.
Definition: CalibrationAlgorithm.h:47
Belle2::TestBoundarySettingAlgorithm::isBoundaryRequired
virtual bool isBoundaryRequired(const Calibration::ExpRun &) override
Decide if a run should be a payload boundary. Only used in certain Python Algorithm Starategies.
Definition: TestBoundarySettingAlgorithm.cc:54