Belle II Software  release-08-00-04
eclWaveformTemplateCalibrationC4Algorithm.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/eclWaveformTemplateCalibrationC4Algorithm.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 using namespace Calibration;
28 
30 eclWaveformTemplateCalibrationC4Algorithm::eclWaveformTemplateCalibrationC4Algorithm():
31  CalibrationAlgorithm("DummyCollector")
32 {
34  "Collects results from C3 to produce final payload, which contains new waveform templates"
35  );
36 }
37 
39 {
40  B2INFO("eclWaveformTemplateCalibrationC4Algorithm m_firstCellID, m_lastCellID " << m_firstCellID << " " << m_lastCellID);
41 
42  //save to db
43  ECLDigitWaveformParameters* PhotonHadronDiodeParameters = new ECLDigitWaveformParameters();
44 
45  std::vector<float> cellIDs;
46  std::vector<float> photonNorms;
47  std::vector<float> hadronNorms;
48  std::vector<float> diodeNorms;
49 
50  //int experimentNumber = -999;
51 
52  for (int i = 0; i < m_numBatches; i++) {
53 
54  int first = (i * m_batchsize) + 1;
55  int last = ((i + 1) * m_batchsize);
57 
58  B2INFO("eclWaveformTemplateCalibrationC4Algorithm i " << i << " " << first << " " << last);
59 
60  DBObjPtr<ECLDigitWaveformParameters> tempexistingPhotonWaveformParameters(Form("PhotonParameters_CellID%d_CellID%d", first,
61  last));
62  DBObjPtr<ECLDigitWaveformParameters> tempexistingHadronDiodeWaveformParameters(Form("HadronDiodeParameters_CellID%d_CellID%d",
63  first, last));
64 
65  for (int j = first; j <= last; j++) {
66  B2INFO("Check Norm Parms CellID " << j);
67  B2INFO("P " << j << " " << tempexistingPhotonWaveformParameters->getPhotonParameters(j)[0]);
68  B2INFO("H " << j << " " << tempexistingHadronDiodeWaveformParameters->getHadronParameters(j)[0]);
69  B2INFO("D " << j << " " << tempexistingHadronDiodeWaveformParameters->getDiodeParameters(j)[0]);
70 
71  cellIDs.push_back(j);
72  photonNorms.push_back(tempexistingPhotonWaveformParameters->getPhotonParameters(j)[0]);
73  hadronNorms.push_back(tempexistingPhotonWaveformParameters->getHadronParameters(j)[0]);
74  diodeNorms.push_back(tempexistingPhotonWaveformParameters->getDiodeParameters(j)[0]);
75 
76  float tempPhotonWaveformParameters[11];
77  float tempHadronWaveformParameters[11];
78  float tempDiodeWaveformParameters[11];
79 
80  for (int k = 0; k < 11; k++) {
81  tempPhotonWaveformParameters[k] = tempexistingPhotonWaveformParameters->getPhotonParameters(j)[k];
82  tempHadronWaveformParameters[k] = tempexistingHadronDiodeWaveformParameters->getHadronParameters(j)[k];
83  tempDiodeWaveformParameters[k] = tempexistingHadronDiodeWaveformParameters->getDiodeParameters(j)[k];
84  }
85  PhotonHadronDiodeParameters->setTemplateParameters(j, tempPhotonWaveformParameters, tempHadronWaveformParameters,
86  tempDiodeWaveformParameters);
87  }
88  }
89 
90  auto gphotonNorms = new TGraph(cellIDs.size(), cellIDs.data(), photonNorms.data());
91  gphotonNorms->SetName("gphotonNorms");
92  auto ghadronNorms = new TGraph(cellIDs.size(), cellIDs.data(), hadronNorms.data());
93  ghadronNorms->SetName("ghadronNorms");
94  auto gdiodeNorms = new TGraph(cellIDs.size(), cellIDs.data(), diodeNorms.data());
95  gdiodeNorms->SetName("gdiodeNorms");
96 
97  TString fName = m_outputName;
98  TFile* histfile = new TFile(fName, "recreate");
99  histfile->cd();
100  gphotonNorms->Write();
101  ghadronNorms->Write();
102  gdiodeNorms->Write();
103  histfile->Close();
104  delete histfile;
105 
106 
107  B2INFO("eclWaveformTemplateCalibrationC4Algorithm: Successful, now writing DB PAyload");
108  saveCalibration(PhotonHadronDiodeParameters, "ECLDigitWaveformParameters");
109 
110  return c_OK;
111 }
112 
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.
Class for accessing objects in the database.
Definition: DBObjPtr.h:21
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.