Belle II Software  release-08-00-10
eclWaveformTemplateCalibrationC3Algorithm.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 /* Own header. */
10 #include <ecl/calibration/eclWaveformTemplateCalibrationC3Algorithm.h>
11 
12 /* ECL headers. */
13 #include <ecl/dataobjects/ECLElementNumbers.h>
14 #include <ecl/dbobjects/ECLDigitWaveformParameters.h>
15 
16 /* ROOT headers. */
17 #include <TFile.h>
18 #include <TGraph.h>
19 #include <TTree.h>
20 #include <TF1.h>
21 
22 #include <stdlib.h>
23 
24 using namespace std;
25 using namespace Belle2;
26 using namespace ECL;
27 
29 eclWaveformTemplateCalibrationC3Algorithm::eclWaveformTemplateCalibrationC3Algorithm():
30  CalibrationAlgorithm("eclWaveformTemplateCalibrationC2Collector")
31 {
33  "Perform the hadron and diode template shape calibration using photon template shapes from stage C2"
34  );
35 }
36 
38 {
39 
40  B2INFO("RUNNING" << Form("eclComputePulseTemplates_Step2.py %d %d", (m_firstCellID), (m_lastCellID)));
41  system(Form("eclComputePulseTemplates_Step2.py %d %d", (m_firstCellID), (m_lastCellID)));
42 
43  B2INFO("RUNNING " << Form("eclComputePulseTemplates_Step3 %d %d", m_firstCellID, m_lastCellID));
44  system(Form("eclComputePulseTemplates_Step3 %d %d", m_firstCellID, m_lastCellID));
45 
46  //save to db
47  ECLDigitWaveformParameters* HadronDiodeParameters = new ECLDigitWaveformParameters();
48 
49  TFile* TempFile = new TFile(Form("HadronPars_Low%d_High%d.root", m_firstCellID, m_lastCellID), "READ");
50  TTree* TempTree = (TTree*) TempFile->Get("HadronWaveformInfo");
51  double tHadronShapePars_A[11];
52  double tDiodeShapePars_A[11];
53  double tMaxResidualHadron_A;
54  double tMaxResidualDiode_A;
55  double tMaxValDiode_A;
56  double tMaxValHadron_A;
57  TempTree->SetBranchAddress("TempHadronPar11_A", &tHadronShapePars_A);
58  TempTree->SetBranchAddress("TempDiodePar11_A", &tDiodeShapePars_A);
59  TempTree->SetBranchAddress("MaxResHadron_A", &tMaxResidualHadron_A);
60  TempTree->SetBranchAddress("MaxResDiode_A", &tMaxResidualDiode_A);
61  TempTree->SetBranchAddress("MaxValDiode_A", &tMaxValDiode_A);
62  TempTree->SetBranchAddress("MaxValHadron_A", &tMaxValHadron_A);
63 
64  int batch = m_lastCellID - m_firstCellID;
65  for (int j = 0; j <= batch; j++) {
66  int tCellID = m_firstCellID + j;
67  if (tCellID > ECLElementNumbers::c_NCrystals)continue;
68  B2INFO("tCellID=" << tCellID << " j=" << j);
69  TempTree->GetEntry(j);
70  float tHadronShapePars_float[11];
71  float tDiodeShapePars_float[11];
72  for (int p = 0; p < 11; p++) {
73 
74  if (tHadronShapePars_A[p] > 100 || tHadronShapePars_A[p] < -100) {
75  B2INFO("Warning large parameter for: " << tCellID << " " << tHadronShapePars_A[p]);
76  for (int h = 0; h < 11; h++) B2INFO(tHadronShapePars_A[h]);
77  }
78 
79  tHadronShapePars_float[p] = (float)tHadronShapePars_A[p];
80  tDiodeShapePars_float[p] = (float)tDiodeShapePars_A[p];
81 
82  }
83 
84  B2INFO("tCellID tHadronShapePars_float[0]" << tCellID << " " << tHadronShapePars_float[0]);
85 
86  HadronDiodeParameters->setTemplateParameters(tCellID, tHadronShapePars_float, tHadronShapePars_float, tDiodeShapePars_float);
87  }
88  TempFile->Close();
89 
90  saveCalibration(HadronDiodeParameters, Form("HadronDiodeParameters_CellID%d_CellID%d", m_firstCellID, m_lastCellID));
91  return c_OK;
92 }
93 
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
EResult
The result of calibration.
@ c_OK
Finished successfuly =0 in Python.
DB object to store photon, hadron and diode shape parameters.
void setTemplateParameters(int cellID, const float photonInput[11], const float hadronInput[11], const float diodeInput[11])
Set photon, hadron and diode template parameters for crystal.
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.