10#include <ecl/calibration/eclEdgeAlgorithm.h>
13#include <ecl/dataobjects/ECLElementNumbers.h>
14#include <ecl/dbobjects/ECLCrystalCalib.h>
27using namespace Calibration;
34 "Generate payloads ECLCrystalThetaEdge and ECLCrystalPhiEdge found by eclEdgeCollector"
45 auto eclCrystalX = getObjectPtr<TH1F>(
"eclCrystalX");
46 auto eclCrystalY = getObjectPtr<TH1F>(
"eclCrystalY");
47 auto eclCrystalZ = getObjectPtr<TH1F>(
"eclCrystalZ");
48 auto eclCrystalR = getObjectPtr<TH1F>(
"eclCrystalR");
49 auto eclCrystalTheta = getObjectPtr<TH1F>(
"eclCrystalTheta");
50 auto eclCrystalPhi = getObjectPtr<TH1F>(
"eclCrystalPhi");
51 auto eclCrystalDirTheta = getObjectPtr<TH1F>(
"eclCrystalDirTheta");
52 auto eclCrystalDirPhi = getObjectPtr<TH1F>(
"eclCrystalDirPhi");
53 auto eclCrystalEdgeTheta = getObjectPtr<TH1F>(
"eclCrystalEdgeTheta");
54 auto eclCrystalEdgePhi = getObjectPtr<TH1F>(
"eclCrystalEdgePhi");
55 auto eclEdgeCounter = getObjectPtr<TH1F>(
"eclEdgeCounter");
58 TFile* histfile =
new TFile(
"eclEdgeAlgorithm.root",
"recreate");
63 eclCrystalTheta->Write();
64 eclCrystalPhi->Write();
65 eclCrystalDirTheta->Write();
66 eclCrystalDirPhi->Write();
67 eclCrystalEdgeTheta->Write();
68 eclCrystalEdgePhi->Write();
69 eclEdgeCounter->Write();
75 const int nCalls = (int)(eclEdgeCounter->GetBinContent(1) + 0.0001);
78 int firstCrysID[69] = {};
79 for (
int thetaID = 1; thetaID < 69; thetaID++) {
84 TH1F* eclCrystalWidthTheta =
new TH1F(
"eclCrystalWidthTheta",
"Width of each crystal in theta;cellID;crystal width (rad)",
87 TH1F* eclCrystalWidthPhi =
new TH1F(
"eclCrystalWidthPhi",
"Width of each crystal in phi;cellID;crystal width (rad)",
92 std::vector<float> tempThetaEdge;
95 tempThetaEdge.push_back(eclCrystalEdgeTheta->GetBinContent(cellID) / nCalls);
100 B2RESULT(
"eclEdgeAlgorithm: successfully stored payload ECLCrystalThetaEdge");
104 std::vector<float> tempPhiEdge;
106 tempPhiEdge.push_back(eclCrystalEdgePhi->GetBinContent(cellID) / nCalls);
111 B2RESULT(
"eclEdgeAlgorithm: successfully stored payload ECLCrystalPhiEdge");
116 std::vector<float> tempPhiWidth;
118 for (
int thetaID = 0; thetaID < 69; thetaID++) {
121 int nextID = crysID + 1;
123 double width = tempPhiEdge[nextID] - tempPhiEdge[crysID];
124 if (width < 0) {width += 2.*TMath::Pi();}
125 tempPhiWidth.push_back(width);
131 B2RESULT(
"eclEdgeAlgorithm: successfully stored payload ECLCrystalPhiWidth");
135 eclCrystalWidthPhi->SetBinContent(cellID, tempPhiWidth[cellID - 1]);
136 eclCrystalWidthPhi->SetBinError(cellID, 0.);
139 eclCrystalWidthPhi->Write();
144 std::vector<float> tempThetaWidth;
145 for (
int thetaID = 0; thetaID < 68; thetaID++) {
146 for (
int ic = firstCrysID[thetaID]; ic < firstCrysID[thetaID] +
m_crystalsPerRing[thetaID]; ic++) {
147 double minThetaWidth = 999.;
148 double maxThetaWidth = -999.;
149 for (
int icnext = firstCrysID[thetaID + 1]; icnext < firstCrysID[thetaID + 1] +
m_crystalsPerRing[thetaID + 1]; icnext++) {
152 double offset = tempPhiEdge[ic] - tempPhiEdge[icnext];
153 if (offset < -TMath::Pi()) {offset += 2.*TMath::Pi();}
154 if (offset > TMath::Pi()) {offset -= 2.*TMath::Pi();}
155 if (offset >= 0. and offset < tempPhiWidth[icnext]) {
156 double width = tempThetaEdge[icnext] - tempThetaEdge[ic];
157 if (width < minThetaWidth) {minThetaWidth = width;}
158 if (width > maxThetaWidth) {maxThetaWidth = width;}
162 offset = tempPhiEdge[icnext] - tempPhiEdge[ic];
163 if (offset < -TMath::Pi()) {offset += 2.*TMath::Pi();}
164 if (offset > TMath::Pi()) {offset -= 2.*TMath::Pi();}
165 if (offset >= 0. and offset < tempPhiWidth[ic]) {
166 double width = tempThetaEdge[icnext] - tempThetaEdge[ic];
167 if (width < minThetaWidth) {minThetaWidth = width;}
168 if (width > maxThetaWidth) {maxThetaWidth = width;}
172 tempThetaWidth.push_back(0.5 * (maxThetaWidth + minThetaWidth));
177 const double upperThetaEdge = 2.7416;
178 const int thetaID68 = 68;
179 for (
int ic = firstCrysID[thetaID68]; ic < firstCrysID[thetaID68] +
m_crystalsPerRing[thetaID68]; ic++) {
180 tempThetaWidth.push_back(upperThetaEdge - tempThetaEdge[ic]);
187 B2RESULT(
"eclEdgeAlgorithm: successfully stored payload ECLCrystalThetaWidth");
191 eclCrystalWidthTheta->SetBinContent(cellID, tempThetaWidth[cellID - 1]);
192 eclCrystalWidthTheta->SetBinError(cellID, 0.);
195 eclCrystalWidthTheta->Write();
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 successfully =0 in Python.
General DB object to store one calibration number per ECL crystal.
void setCalibVector(const std::vector< float > &CalibConst, const std::vector< float > &CalibConstUnc)
Set vector of constants with uncertainties.
eclEdgeAlgorithm()
..Constructor
const short m_crystalsPerRing[69]
crystals per thetaID
virtual EResult calibrate() override
..Run algorithm
const int c_NCrystals
Number of crystals.
Abstract base class for different kinds of events.