Belle II Software  release-08-00-10
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  B2INFO("eclWaveformTemplateCalibrationC4Algorithm " << Form("PhotonParameters_CellID%d_CellID%d", first, last));
60  B2INFO("eclWaveformTemplateCalibrationC4Algorithm " << Form("HadronDiodeParameters_CellID%d_CellID%d", first, last));
61 
62  DBObjPtr<ECLDigitWaveformParameters> tempexistingPhotonWaveformParameters(Form("PhotonParameters_CellID%d_CellID%d", first,
63  last));
64  DBObjPtr<ECLDigitWaveformParameters> tempexistingHadronDiodeWaveformParameters(Form("HadronDiodeParameters_CellID%d_CellID%d",
65  first, last));
66 
67  auto runs = getRunList();
68  // Take the first run
69  ExpRun chosenRun = runs.front();
70  B2INFO("merging using the ExpRun (" << chosenRun.second << "," << chosenRun.first << ")");
71  // After here your DBObjPtrs are correct
72  updateDBObjPtrs(1, chosenRun.second, chosenRun.first);
73 
74  for (int j = first; j <= last; j++) {
75  B2INFO("Check Norm Parms CellID " << j);
76  B2INFO("P " << j << " " << tempexistingPhotonWaveformParameters->getPhotonParameters(j)[0]);
77  B2INFO("H " << j << " " << tempexistingHadronDiodeWaveformParameters->getHadronParameters(j)[0]);
78  B2INFO("D " << j << " " << tempexistingHadronDiodeWaveformParameters->getDiodeParameters(j)[0]);
79 
80  cellIDs.push_back(j);
81  photonNorms.push_back(tempexistingPhotonWaveformParameters->getPhotonParameters(j)[0]);
82  hadronNorms.push_back(tempexistingPhotonWaveformParameters->getHadronParameters(j)[0]);
83  diodeNorms.push_back(tempexistingPhotonWaveformParameters->getDiodeParameters(j)[0]);
84 
85  float tempPhotonWaveformParameters[11];
86  float tempHadronWaveformParameters[11];
87  float tempDiodeWaveformParameters[11];
88 
89  for (int k = 0; k < 11; k++) {
90  tempPhotonWaveformParameters[k] = tempexistingPhotonWaveformParameters->getPhotonParameters(j)[k];
91  tempHadronWaveformParameters[k] = tempexistingHadronDiodeWaveformParameters->getHadronParameters(j)[k];
92  tempDiodeWaveformParameters[k] = tempexistingHadronDiodeWaveformParameters->getDiodeParameters(j)[k];
93  }
94  PhotonHadronDiodeParameters->setTemplateParameters(j, tempPhotonWaveformParameters, tempHadronWaveformParameters,
95  tempDiodeWaveformParameters);
96  }
97  }
98 
99  auto gphotonNorms = new TGraph(cellIDs.size(), cellIDs.data(), photonNorms.data());
100  gphotonNorms->SetName("gphotonNorms");
101  auto ghadronNorms = new TGraph(cellIDs.size(), cellIDs.data(), hadronNorms.data());
102  ghadronNorms->SetName("ghadronNorms");
103  auto gdiodeNorms = new TGraph(cellIDs.size(), cellIDs.data(), diodeNorms.data());
104  gdiodeNorms->SetName("gdiodeNorms");
105 
106  TString fName = m_outputName;
107  TFile* histfile = new TFile(fName, "recreate");
108  histfile->cd();
109  gphotonNorms->Write();
110  ghadronNorms->Write();
111  gdiodeNorms->Write();
112  histfile->Close();
113  delete histfile;
114 
115 
116  B2INFO("eclWaveformTemplateCalibrationC4Algorithm: Successful, now writing DB PAyload");
117  saveCalibration(PhotonHadronDiodeParameters, "ECLDigitWaveformParameters");
118 
119  return c_OK;
120 }
121 
Base class for calibration algorithms.
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
void updateDBObjPtrs(const unsigned int event, const int run, const int experiment)
Updates any DBObjPtrs by calling update(event) for DBStore.
void setDescription(const std::string &description)
Set algorithm description (in constructor)
EResult
The result of calibration.
@ c_OK
Finished successfuly =0 in Python.
const std::vector< Calibration::ExpRun > & getRunList() const
Get the list of runs for which calibration is called.
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.
Struct containing exp number and run number.
Definition: Splitter.h:51