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
67int main(int argc, char* argv[])
68{
69 //
70 TString OutputDirectory = ".";
71 if (OutputDirectory == "") {
72 std::cout << "Error set output directory" << std::endl;
73 return -1;
74 }
75 //
76 assert(argc == 2);
77 int Flag = atoi(argv[1]);
78 TString InputDirectory = OutputDirectory;
79 //
80 TString ParameterTreeOutputName = OutputDirectory + "PhotonWaveformParameters.root";
81 if (Flag == 1) ParameterTreeOutputName = "DigitWaveformParameters.root";
82 TFile* ParameterTreeOutputFile = new TFile(ParameterTreeOutputName, "RECREATE");
83 //
84 TTree* ParameterTree = new TTree("ParTree", "");
85 double PhotonWaveformPar[11];
86 double HadronWaveformPar[11];
87 double DiodeWaveformPar[11];
88 for (int k = 0; k < 11; k++) {
89 PhotonWaveformPar[k] = 0;
90 HadronWaveformPar[k] = 0;
91 DiodeWaveformPar[k] = 0;
92 }
93 double mHadronRes = 0;
94 double mDiodeRes = 0;
95 double mHadronMax = 0;
96 double mDiodeMax = 0;
97 ParameterTree->Branch("PhotonPar", &PhotonWaveformPar, "PhotonWaveformPar[11]/D");
98 ParameterTree->Branch("HadronPar", &HadronWaveformPar, "HadronWaveformPar[11]/D");
99 ParameterTree->Branch("DiodePar", &DiodeWaveformPar, "DiodeWaveformPar[11]/D");
100 ParameterTree->Branch("mHadronRes", &mHadronRes, "mHadronRes/D");
101 ParameterTree->Branch("mDiodeRes", &mDiodeRes, "mDiodeRes/D");
102 ParameterTree->Branch("mHadronMax", &mHadronMax, "mHadronMax/D");
103 ParameterTree->Branch("mDiodeMax", &mDiodeMax, "mDiodeMax/D");
104 //
105 std::vector<crystalInfo> cellIDcheck(ECLElementNumbers::c_NCrystals);
106 ifstream PhotonFile("/home/belle2/longos/WaveformFitting/ecl/tools/params_gamma_shape.dat");
107 if (PhotonFile.is_open()) {
108 std::vector<double> templine(12);
109 for (int k = 0; k < ECLElementNumbers::c_NCrystals; k++) {
110 for (unsigned int j = 0; j < templine.size(); j++) PhotonFile >> templine[j];
111 cellIDcheck[int(templine[0]) - 1].PhotonWaveformPars.resize(11);
112 cellIDcheck[int(templine[0]) - 1].PhotonWaveformPars[0] = templine[1];
113 for (int j = 0; j < 10; j++) cellIDcheck[int(templine[0]) - 1].PhotonWaveformPars[j + 1] = templine[j + 2];
114 std::cout << int(templine[0]) << " " << templine[1] << endl;
115 }
116 PhotonFile.close();
117 } else {
118 std::cout << "ERROR cannot open photon param file." << endl;
119 return -1;
120 }
121 if (Flag == 0) {
122 for (unsigned int f = 0; f < cellIDcheck.size(); f++) {
123 for (int k = 0; k < 11; k++) PhotonWaveformPar[k] = cellIDcheck[f].PhotonWaveformPars[k];
124 ParameterTree->Fill();
125 }
126 } else if (Flag == 1) {
127 int batch = 10;
128 for (int k = 0; k < 874; k++) {
129 int low = k * batch;
130 int high = (k + 1) * batch;
131 //std::cout<<k<<std::endl;
132 TFile* TempFile = new TFile(InputDirectory + Form("HadronPars_Low%d_High%d.root", low, high), "READ");
133 TTree* TempTree = (TTree*) TempFile->Get("HadronWaveformInfo");
134 double tHadronShapePars_A[11];
135 double tDiodeShapePars_A[11];
136 double tMaxResidualHadron_A;
137 double tMaxResidualDiode_A;
138 double tMaxValDiode_A;
139 double tMaxValHadron_A;
140 TempTree->SetBranchAddress("TempHadronPar11_A", &tHadronShapePars_A);
141 TempTree->SetBranchAddress("TempDiodePar11_A", &tDiodeShapePars_A);
142 TempTree->SetBranchAddress("MaxResHadron_A", &tMaxResidualHadron_A);
143 TempTree->SetBranchAddress("MaxResDiode_A", &tMaxResidualDiode_A);
144 TempTree->SetBranchAddress("MaxValDiode_A", &tMaxValDiode_A);
145 TempTree->SetBranchAddress("MaxValHadron_A", &tMaxValHadron_A);
146 //
147 for (int j = 0; j < batch; j++) {
148 int tCellID = (k * batch) + j;
149 if (tCellID >= ECLElementNumbers::c_NCrystals)continue;
150 TempTree->GetEntry(j);
151 cellIDcheck[tCellID].HadronWaveformPars.resize(11);
152 cellIDcheck[tCellID].DiodeWaveformPars.resize(11);
153 for (int p = 0; p < 11; p++) {
154 if (tHadronShapePars_A[p] > 100 || tHadronShapePars_A[p] < -100) {
155 std::cout << "Warning large parameter for: " << tCellID << " " << tHadronShapePars_A[p] << std::endl;
156 for (int h = 0; h < 11; h++)std::cout << tHadronShapePars_A[h] << " , ";
157 std::cout << std::endl;
158 }
159 cellIDcheck[tCellID].HadronWaveformPars[p] = tHadronShapePars_A[p];
160 }
161 //std::cout<<tCellID<<std::endl;
162 //for(int h=0;h<11;h++ )std::cout<<tHadronShapePars_A[h]<<" , ";
163 //std::cout<<std::endl;
164 cellIDcheck[tCellID].MaxResHadron = tMaxResidualHadron_A;
165 cellIDcheck[tCellID].MaxValHadron = tMaxValHadron_A;
166 for (int p = 0; p < 11; p++) cellIDcheck[tCellID].DiodeWaveformPars[p] = tDiodeShapePars_A[p];
167 cellIDcheck[tCellID].MaxResDiode = tMaxResidualDiode_A;
168 cellIDcheck[tCellID].MaxValDiode = tMaxValDiode_A;
169 }
170 TempFile->Close();
171 }
172 //
173 for (unsigned int f = 0; f < ECLElementNumbers::c_NCrystals; f++) {
174 for (int k = 0; k < 11; k++) {
175 PhotonWaveformPar[k] = cellIDcheck[f].PhotonWaveformPars[k];
176 HadronWaveformPar[k] = cellIDcheck[f].HadronWaveformPars[k];
177 DiodeWaveformPar[k] = cellIDcheck[f].DiodeWaveformPars[k];
178 }
179 mHadronRes = cellIDcheck[f].MaxResHadron;
180 mDiodeRes = cellIDcheck[f].MaxResDiode;
181 mHadronMax = cellIDcheck[f].MaxValHadron;
182 mDiodeMax = cellIDcheck[f].MaxValDiode;
183 ParameterTree->Fill();
184 }
185 }
186 //
187 ParameterTreeOutputFile->cd();
188 ParameterTree->Write();
189 ParameterTreeOutputFile->Write();
190 ParameterTreeOutputFile->Close();
191 //
192 //
193 return 0;
194}
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