Belle II Software  release-08-01-10
ECLLocalRunCalibUnit.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 
9 // ECL
10 #include <ecl/modules/eclLocalRunCalibration/ECLLocalRunCalibUnit.h>
11 #include <ecl/dbobjects/ECLCrystalLocalRunCalib.h>
12 #include <ecl/dbobjects/ECLLocalRunCalibRef.h>
13 
14 using namespace Belle2;
15 // Constructor.
17  const int& ncellids,
18  const float& min_value,
19  const float& max_value,
20  const int* const ndevs):
21  m_isNegAmpl(false), m_unitData(ncellids,
23  min_value,
24  max_value,
25  ndevs))
26 {
27 }
28 // Destructor.
30 {
31 }
32 // This function will be called, if the
33 // negative amplitude values are observed
34 // in the current run.
36 {
37  m_isNegAmpl = true;
38 }
39 // Checking presence of negative
40 // amplitudes.
42 {
43  return m_isNegAmpl;
44 }
45 // Add value to
46 // accamulate mean value,
47 // standard deviation and
48 // number of accepted events.
49 void ECLLocalRunCalibUnit::add(const int& index, const float& value)
50 {
51  m_unitData[index].add(value);
52 }
53 // Calculate accumulated values.
55 {
56  for (auto& cellAcc : m_unitData) {
57  cellAcc.calc();
58  }
59 }
60 // Getter of accumulated values.
61 template <typename T>
63  std::vector<T>* vec,
64  T(ECLLocalRunCalibAcc::*getter)() const)
65 {
66  for (const auto& obj : m_unitData) {
67  vec->push_back((obj.*getter)());
68  }
69 }
70 // Make current run as reference.
71 void ECLLocalRunCalibUnit::markAsRefference(const bool& isLocal,
72  const std::string& dbName,
73  const int& run,
74  const IntervalOfValidity& iov)
75 {
76  int exp = iov.getExperimentLow();
77  ECLDBTool refPayload(isLocal, dbName.c_str(),
78  "ECLCalibRef");
79  refPayload.connect();
80  ECLLocalRunCalibRef refobj(exp, run);
81  refPayload.write(&refobj, iov);
82 }
83 // Change previous validity interval.
85  const IntervalOfValidity& iov)
86 {
87  int exp = iov.getExperimentLow();
88  int run_high = iov.getRunLow() - 1;
89  EventMetaData ev(1, run_high, exp);
90  IntervalOfValidity* prevIoV;
91  payload.read(&prevIoV, ev);
92  int run_low = prevIoV->getRunLow();
93  IntervalOfValidity ciov(exp, run_low,
94  exp, run_high);
95  payload.changeIoV(ev, ciov);
96  delete prevIoV;
97 }
98 // Save results.
100  bool isLocal,
101  const std::string& dbName,
102  const std::string& payloadName,
103  const IntervalOfValidity& iov,
104  const int& run,
105  const bool& changePrev,
106  const bool& addref)
107 {
108  int exp = iov.getExperimentLow();
110  if (m_unitData.size() > 0) {
111  int nevents = 0;
112  for (const auto& cellAcc : m_unitData) {
113  nevents = cellAcc.getNOfEvents();
114  if (nevents != 0) {
115  break;
116  }
117  }
118  std::vector<int> counts;
119  counts.reserve(m_unitData.size());
120  callAccGetter<int>(&counts,
122  std::vector<float> means;
123  means.reserve(m_unitData.size());
124  callAccGetter<float>(&means,
126  std::vector<float> stddevs;
127  stddevs.reserve(m_unitData.size());
128  callAccGetter<float>(&stddevs,
130  data.setNumberOfEvents(nevents);
131  data.setNumbersOfAcceptedEvents(counts);
132  data.setCalibVector(means, stddevs);
133  data.setExpRun(exp, run);
134  ECLDBTool payload(isLocal, dbName.c_str(),
135  payloadName.c_str());
136  payload.connect();
137  if (changePrev) {
138  changePreviousIoV(payload, iov);
139  }
140  payload.write(&data, iov);
141  if (addref) {
142  markAsRefference(isLocal, dbName,
143  run, iov);
144  }
145  }
146 }
ECLCrystalLocalRunCalib is designed to store results of the ECL local run calibration to database.
The ECLDBTool class is designed to read / write object from / to database.
Definition: ECLDBTool.h:23
void write(TObject *const obj, const IntervalOfValidity &iov) const
Write object and validity interval to a database.
Definition: ECLDBTool.cc:38
void connect() const
Connect to a database.
Definition: ECLDBTool.cc:28
ECLLocalRunCalibAcc is the class designed to accumulate mean values, standard deviation and number of...
int getCount() const
Get number of accepted events.
float getMean() const
Get mean value.
float getStdDev() const
Get standard deviation.
ECLLocalRunCalibRef is designed to store reference marks to database for ECL local run calibration.
void calc()
Calculate accumulated values.
std::vector< ECLLocalRunCalibAcc > m_unitData
Mean value and standard deviation accumulators for each cell id.
void callAccGetter(std::vector< T > *vec, T(ECLLocalRunCalibAcc::*getter)() const)
Getter of accumulated values.
ECLLocalRunCalibUnit(const int &ncellids, const float &min_value, const float &max_value, const int *const ndevs)
Constructor.
void markAsRefference(const bool &isLocal, const std::string &dbName, const int &run, const IntervalOfValidity &iov)
Mark current run as reference.
void enableNegAmpl()
This function will be called only in the case, if negative amplitudes are observed in the current run...
void changePreviousIoV(const ECLDBTool &payload, const IntervalOfValidity &iov)
Change previous validity interval.
bool m_isNegAmpl
m_isNegAmpl is true if there are negative amplitudes in the current run and false otherwise.
void writeToDB(bool isLocal, const std::string &dbName, const std::string &payloadName, const IntervalOfValidity &iov, const int &run, const bool &changePrev, const bool &addref)
Write calibration results into a database.
bool isNegAmpl() const
Check presence of negative amplitudes in the current run.
void add(const int &cellid, const float &value)
Add value to accumulate mean value, standard deviation and number of accepted events.
Store event, run, and experiment numbers.
Definition: EventMetaData.h:33
A class that describes the interval of experiments/runs for which an object in the database is valid.
int getRunLow() const
Getter for lowest run number.
Abstract base class for different kinds of events.