Belle II Software  release-05-02-19
MillepedeTreeConversionAlgorithm.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Kirill Chilikin *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <alignment/calibration/MillepedeTreeConversionAlgorithm.h>
12 
13 #include <genfit/GblData.h>
14 
15 #include <TFile.h>
16 
17 using namespace Belle2;
18 
20  CalibrationAlgorithm("MillepedeCollector"), m_OutputFile("millepede_data.root") {}
21 
23 {
24 }
25 
27 {
28  m_OutputFile = outputFile;
29 }
30 
32 {
33  const int max_entries = 100;
34  int i, j, n;
35  std::vector<gbl::GblData>* dat = NULL;
36  std::vector<gbl::GblData>::iterator it;
37  double aValue, aErr;
38  std::vector<unsigned int>* indLocal;
39  std::vector<int>* labGlobal;
40  std::vector<double>* derLocal, *derGlobal;
41  float value, error, der[max_entries];
42  int nlab, label[max_entries];
43  auto gblData = getObjectPtr<TTree>("GblDataTree");
44  gblData->SetBranchAddress("GblData", &dat);
45  TFile* f_out = new TFile(m_OutputFile.c_str(), "recreate");
46  TTree* t_out = new TTree("mille", "");
47  t_out->Branch("value", &value, "value/F");
48  t_out->Branch("error", &error, "error/F");
49  t_out->Branch("nlab", &nlab, "nlab/I");
50  t_out->Branch("label", label, "label[nlab]/I");
51  t_out->Branch("der", der, "der[nlab]/F");
52  n = gblData->GetEntries();
53  for (i = 0; i < n; i++) {
54  gblData->GetEntry(i);
55  for (it = dat->begin(); it != dat->end(); ++it) {
56  it->getAllData(aValue, aErr, indLocal, derLocal, labGlobal, derGlobal);
57  if (labGlobal->size() == 0)
58  continue;
59  value = aValue;
60  error = aErr;
61  nlab = std::min((int)labGlobal->size(), max_entries);
62  for (j = 0; j < nlab; j++) {
63  label[j] = (*labGlobal)[j];
64  der[j] = (*derGlobal)[j];
65  }
66  t_out->Fill();
67  }
68  }
69  f_out->cd();
70  t_out->Write();
71  delete t_out;
72  delete f_out;
74 }
75 
Belle2::MillepedeTreeConversionAlgorithm::MillepedeTreeConversionAlgorithm
MillepedeTreeConversionAlgorithm()
Constructor.
Definition: MillepedeTreeConversionAlgorithm.cc:19
Belle2::CalibrationAlgorithm::c_OK
@ c_OK
Finished successfuly =0 in Python.
Definition: CalibrationAlgorithm.h:51
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::MillepedeTreeConversionAlgorithm::~MillepedeTreeConversionAlgorithm
~MillepedeTreeConversionAlgorithm()
Destructor.
Definition: MillepedeTreeConversionAlgorithm.cc:22
Belle2::MillepedeTreeConversionAlgorithm::m_OutputFile
std::string m_OutputFile
Output file name.
Definition: MillepedeTreeConversionAlgorithm.h:62
Belle2::CalibrationAlgorithm::EResult
EResult
The result of calibration.
Definition: CalibrationAlgorithm.h:50
Belle2::CalibrationAlgorithm
Base class for calibration algorithms.
Definition: CalibrationAlgorithm.h:47
Belle2::MillepedeTreeConversionAlgorithm::setOutputFile
void setOutputFile(const char *outputFile)
Set output file name.
Definition: MillepedeTreeConversionAlgorithm.cc:26
Belle2::MillepedeTreeConversionAlgorithm::calibrate
CalibrationAlgorithm::EResult calibrate() override
Calibration.
Definition: MillepedeTreeConversionAlgorithm.cc:31