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