Belle II Software development
eclComputePulseTemplates_Step0.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 headers. */
10#include <ecl/dataobjects/ECLElementNumbers.h>
11
12/* ROOT headers. */
13#include <TFile.h>
14#include <TString.h>
15#include <TTree.h>
16
17/* C++ headers. */
18#include <cassert>
19#include <cstdlib>
20#include <iostream>
21#include <fstream>
22
23using namespace std;
24using namespace Belle2;
25
26/*
27Note photon shape calibrations are needed to compute hadron and diode templates.
28Photon calibrations should be placed in file named params_gamma_shape.dat in same directory as this script.
29Format of params_gamma_shape.dat:
30
31cellID PhotonScale 0 p0 p1 p2 p3 p4 p5 p6 p7 p8 p9
32
33where p0-p9 are 10 ShaperDSP shaper parameters for basf2 C++ implementation of ShaperDSP function.
34
35eclComputePulseTemplates_Step0.cc - places photon parameters in ntuple
36eclComputePulseTemplates_Step1.cc - produce photon array input for eclComputePulseTemplates_Step2.py
37eclComputePulseTemplates_Step2.py - produce hadron and diode array input for eclComputePulseTemplates_Step3.py
38eclComputePulseTemplates_Step3.cc - computed hadron and diode shape parameters and organizes into temp ntuple
39eclComputePulseTemplates_Step4.cc - organizes photon, hadron and diode templates into final ntuple to produce dbobject.
40
41To run template calculation:
42
43First "OutputDirectory" variable in eclComputePulseTemplates_Stepx.cc files should be modified to a temp directory before running scripts.
44recompile with "scons ecl"
45
461) execute eclComputePulseTemplates_Step0 0
472) for i=0 i<873 i++
483) execute eclComputePulseTemplates_Step1 i*10 (i+1)*10
494) basf2 eclComputePulseTemplates_Step2.py i*10 (i+1)*10
505) execute eclComputePulseTemplates_Step3 i*10 (i+1)*10
516) execute eclComputePulseTemplates_Step0 1
527) execute eclWriteWaveformParametersLocalDB
53Final step will create local db object.
54*/
55
58 vector<double> PhotonWaveformPars;
59 vector<double> HadronWaveformPars;
60 vector<double> DiodeWaveformPars;
61 double MaxResHadron;
62 double MaxValHadron;
63 double MaxResDiode;
64 double MaxValDiode;
65};
66
67// cppcheck-suppress constParameter ; main() keeps its standard signature
68int main(int argc, char* argv[])
69{
70 //
71 TString OutputDirectory = ".";
72 if (OutputDirectory == "") {
73 std::cout << "Error set output directory" << std::endl;
74 return -1;
75 }
76 //
77 assert(argc == 2);
78 int Flag = atoi(argv[1]);
79 TString InputDirectory = OutputDirectory;
80 //
81 TString ParameterTreeOutputName = OutputDirectory + "PhotonWaveformParameters.root";
82 if (Flag == 1) ParameterTreeOutputName = "DigitWaveformParameters.root";
83 TFile* ParameterTreeOutputFile = new TFile(ParameterTreeOutputName, "RECREATE");
84 //
85 TTree* ParameterTree = new TTree("ParTree", "");
86 double PhotonWaveformPar[11];
87 double HadronWaveformPar[11];
88 double DiodeWaveformPar[11];
89 for (int k = 0; k < 11; k++) {
90 PhotonWaveformPar[k] = 0;
91 HadronWaveformPar[k] = 0;
92 DiodeWaveformPar[k] = 0;
93 }
94 double mHadronRes = 0;
95 double mDiodeRes = 0;
96 double mHadronMax = 0;
97 double mDiodeMax = 0;
98 ParameterTree->Branch("PhotonPar", &PhotonWaveformPar, "PhotonWaveformPar[11]/D");
99 ParameterTree->Branch("HadronPar", &HadronWaveformPar, "HadronWaveformPar[11]/D");
100 ParameterTree->Branch("DiodePar", &DiodeWaveformPar, "DiodeWaveformPar[11]/D");
101 ParameterTree->Branch("mHadronRes", &mHadronRes, "mHadronRes/D");
102 ParameterTree->Branch("mDiodeRes", &mDiodeRes, "mDiodeRes/D");
103 ParameterTree->Branch("mHadronMax", &mHadronMax, "mHadronMax/D");
104 ParameterTree->Branch("mDiodeMax", &mDiodeMax, "mDiodeMax/D");
105 //
106 std::vector<crystalInfo> cellIDcheck(ECLElementNumbers::c_NCrystals);
107 ifstream PhotonFile("/home/belle2/longos/WaveformFitting/ecl/tools/params_gamma_shape.dat");
108 if (PhotonFile.is_open()) {
109 std::vector<double> templine(12);
110 for (int k = 0; k < ECLElementNumbers::c_NCrystals; k++) {
111 for (unsigned int j = 0; j < templine.size(); j++) PhotonFile >> templine[j];
112 cellIDcheck[int(templine[0]) - 1].PhotonWaveformPars.resize(11);
113 cellIDcheck[int(templine[0]) - 1].PhotonWaveformPars[0] = templine[1];
114 for (int j = 0; j < 10; j++) cellIDcheck[int(templine[0]) - 1].PhotonWaveformPars[j + 1] = templine[j + 2];
115 std::cout << int(templine[0]) << " " << templine[1] << endl;
116 }
117 PhotonFile.close();
118 } else {
119 std::cout << "ERROR cannot open photon param file." << endl;
120 return -1;
121 }
122 if (Flag == 0) {
123 for (unsigned int f = 0; f < cellIDcheck.size(); f++) {
124 for (int k = 0; k < 11; k++) PhotonWaveformPar[k] = cellIDcheck[f].PhotonWaveformPars[k];
125 ParameterTree->Fill();
126 }
127 } else if (Flag == 1) {
128 int batch = 10;
129 for (int k = 0; k < 874; k++) {
130 int low = k * batch;
131 int high = (k + 1) * batch;
132 //std::cout<<k<<std::endl;
133 TFile* TempFile = new TFile(InputDirectory + Form("HadronPars_Low%d_High%d.root", low, high), "READ");
134 TTree* TempTree = static_cast<TTree*>(TempFile->Get("HadronWaveformInfo"));
135 double tHadronShapePars_A[11];
136 double tDiodeShapePars_A[11];
137 double tMaxResidualHadron_A;
138 double tMaxResidualDiode_A;
139 double tMaxValDiode_A;
140 double tMaxValHadron_A;
141 TempTree->SetBranchAddress("TempHadronPar11_A", &tHadronShapePars_A);
142 TempTree->SetBranchAddress("TempDiodePar11_A", &tDiodeShapePars_A);
143 TempTree->SetBranchAddress("MaxResHadron_A", &tMaxResidualHadron_A);
144 TempTree->SetBranchAddress("MaxResDiode_A", &tMaxResidualDiode_A);
145 TempTree->SetBranchAddress("MaxValDiode_A", &tMaxValDiode_A);
146 TempTree->SetBranchAddress("MaxValHadron_A", &tMaxValHadron_A);
147 //
148 for (int j = 0; j < batch; j++) {
149 int tCellID = (k * batch) + j;
150 if (tCellID >= ECLElementNumbers::c_NCrystals)continue;
151 TempTree->GetEntry(j);
152 cellIDcheck[tCellID].HadronWaveformPars.resize(11);
153 cellIDcheck[tCellID].DiodeWaveformPars.resize(11);
154 for (int p = 0; p < 11; p++) {
155 if (tHadronShapePars_A[p] > 100 || tHadronShapePars_A[p] < -100) {
156 std::cout << "Warning large parameter for: " << tCellID << " " << tHadronShapePars_A[p] << std::endl;
157 for (int h = 0; h < 11; h++)std::cout << tHadronShapePars_A[h] << " , ";
158 std::cout << std::endl;
159 }
160 cellIDcheck[tCellID].HadronWaveformPars[p] = tHadronShapePars_A[p];
161 }
162 //std::cout<<tCellID<<std::endl;
163 //for(int h=0;h<11;h++ )std::cout<<tHadronShapePars_A[h]<<" , ";
164 //std::cout<<std::endl;
165 cellIDcheck[tCellID].MaxResHadron = tMaxResidualHadron_A;
166 cellIDcheck[tCellID].MaxValHadron = tMaxValHadron_A;
167 for (int p = 0; p < 11; p++) cellIDcheck[tCellID].DiodeWaveformPars[p] = tDiodeShapePars_A[p];
168 cellIDcheck[tCellID].MaxResDiode = tMaxResidualDiode_A;
169 cellIDcheck[tCellID].MaxValDiode = tMaxValDiode_A;
170 }
171 TempFile->Close();
172 }
173 //
174 for (unsigned int f = 0; f < ECLElementNumbers::c_NCrystals; f++) {
175 for (int k = 0; k < 11; k++) {
176 PhotonWaveformPar[k] = cellIDcheck[f].PhotonWaveformPars[k];
177 HadronWaveformPar[k] = cellIDcheck[f].HadronWaveformPars[k];
178 DiodeWaveformPar[k] = cellIDcheck[f].DiodeWaveformPars[k];
179 }
180 mHadronRes = cellIDcheck[f].MaxResHadron;
181 mDiodeRes = cellIDcheck[f].MaxResDiode;
182 mHadronMax = cellIDcheck[f].MaxValHadron;
183 mDiodeMax = cellIDcheck[f].MaxValDiode;
184 ParameterTree->Fill();
185 }
186 }
187 //
188 ParameterTreeOutputFile->cd();
189 ParameterTree->Write();
190 ParameterTreeOutputFile->Write();
191 ParameterTreeOutputFile->Close();
192 //
193 //
194 return 0;
195}
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.
STL namespace.
a struct to hold relevant Crystal information
vector< double > PhotonWaveformPars
photon waveform parameters
vector< double > HadronWaveformPars
hadron waveform parameters
vector< double > DiodeWaveformPars
diode waveform parameters