8 #include <ecl/calibration/eclEdgeAlgorithm.h>
9 #include <ecl/dbobjects/ECLCrystalCalib.h>
14 #include "TDirectory.h"
20 using namespace Calibration;
27 "Generate payloads ECLCrystalThetaEdge and ECLCrystalPhiEdge found by eclEdgeCollector"
38 auto eclCrystalX = getObjectPtr<TH1F>(
"eclCrystalX");
39 auto eclCrystalY = getObjectPtr<TH1F>(
"eclCrystalY");
40 auto eclCrystalZ = getObjectPtr<TH1F>(
"eclCrystalZ");
41 auto eclCrystalR = getObjectPtr<TH1F>(
"eclCrystalR");
42 auto eclCrystalTheta = getObjectPtr<TH1F>(
"eclCrystalTheta");
43 auto eclCrystalPhi = getObjectPtr<TH1F>(
"eclCrystalPhi");
44 auto eclCrystalDirTheta = getObjectPtr<TH1F>(
"eclCrystalDirTheta");
45 auto eclCrystalDirPhi = getObjectPtr<TH1F>(
"eclCrystalDirPhi");
46 auto eclCrystalEdgeTheta = getObjectPtr<TH1F>(
"eclCrystalEdgeTheta");
47 auto eclCrystalEdgePhi = getObjectPtr<TH1F>(
"eclCrystalEdgePhi");
48 auto eclEdgeCounter = getObjectPtr<TH1F>(
"eclEdgeCounter");
51 TFile* histfile =
new TFile(
"eclEdgeAlgorithm.root",
"recreate");
56 eclCrystalTheta->Write();
57 eclCrystalPhi->Write();
58 eclCrystalDirTheta->Write();
59 eclCrystalDirPhi->Write();
60 eclCrystalEdgeTheta->Write();
61 eclCrystalEdgePhi->Write();
62 eclEdgeCounter->Write();
68 const int nCalls = (int)(eclEdgeCounter->GetBinContent(1) + 0.0001);
71 int firstCrysID[69] = {};
72 for (
int thetaID = 1; thetaID < 69; thetaID++) {
77 TH1F* eclCrystalWidthTheta =
new TH1F(
"eclCrystalWidthTheta",
"Width of each crystal in theta;cellID;crystal width (rad)", 8736, 1,
79 TH1F* eclCrystalWidthPhi =
new TH1F(
"eclCrystalWidthPhi",
"Width of each crystal in phi;cellID;crystal width (rad)", 8736, 1, 8737);
83 std::vector<float> tempThetaEdge;
84 std::vector<float> tempUnc(8736, 0.);
85 for (
int cellID = 1; cellID <= 8736; cellID++) {
86 tempThetaEdge.push_back(eclCrystalEdgeTheta->GetBinContent(cellID) / nCalls);
91 B2RESULT(
"eclEdgeAlgorithm: successfully stored payload ECLCrystalThetaEdge");
95 std::vector<float> tempPhiEdge;
96 for (
int cellID = 1; cellID <= 8736; cellID++) {
97 tempPhiEdge.push_back(eclCrystalEdgePhi->GetBinContent(cellID) / nCalls);
102 B2RESULT(
"eclEdgeAlgorithm: successfully stored payload ECLCrystalPhiEdge");
107 std::vector<float> tempPhiWidth;
109 for (
int thetaID = 0; thetaID < 69; thetaID++) {
112 int nextID = crysID + 1;
114 double width = tempPhiEdge[nextID] - tempPhiEdge[crysID];
115 if (width < 0) {width += 2.*TMath::Pi();}
116 tempPhiWidth.push_back(width);
122 B2RESULT(
"eclEdgeAlgorithm: successfully stored payload ECLCrystalPhiWidth");
125 for (
int cellID = 1; cellID <= 8736; cellID++) {
126 eclCrystalWidthPhi->SetBinContent(cellID, tempPhiWidth[cellID - 1]);
127 eclCrystalWidthPhi->SetBinError(cellID, 0.);
130 eclCrystalWidthPhi->Write();
135 std::vector<float> tempThetaWidth;
136 for (
int thetaID = 0; thetaID < 68; thetaID++) {
137 for (
int ic = firstCrysID[thetaID]; ic < firstCrysID[thetaID] +
m_crystalsPerRing[thetaID]; ic++) {
138 double minThetaWidth = 999.;
139 double maxThetaWidth = -999.;
140 for (
int icnext = firstCrysID[thetaID + 1]; icnext < firstCrysID[thetaID + 1] +
m_crystalsPerRing[thetaID + 1]; icnext++) {
143 double offset = tempPhiEdge[ic] - tempPhiEdge[icnext];
144 if (offset < -TMath::Pi()) {offset += 2.*TMath::Pi();}
145 if (offset > TMath::Pi()) {offset -= 2.*TMath::Pi();}
146 if (offset >= 0. and offset < tempPhiWidth[icnext]) {
147 double width = tempThetaEdge[icnext] - tempThetaEdge[ic];
148 if (width < minThetaWidth) {minThetaWidth = width;}
149 if (width > maxThetaWidth) {maxThetaWidth = width;}
153 offset = tempPhiEdge[icnext] - tempPhiEdge[ic];
154 if (offset < -TMath::Pi()) {offset += 2.*TMath::Pi();}
155 if (offset > TMath::Pi()) {offset -= 2.*TMath::Pi();}
156 if (offset >= 0. and offset < tempPhiWidth[ic]) {
157 double width = tempThetaEdge[icnext] - tempThetaEdge[ic];
158 if (width < minThetaWidth) {minThetaWidth = width;}
159 if (width > maxThetaWidth) {maxThetaWidth = width;}
163 tempThetaWidth.push_back(0.5 * (maxThetaWidth + minThetaWidth));
168 const double upperThetaEdge = 2.7416;
169 const int thetaID68 = 68;
170 for (
int ic = firstCrysID[thetaID68]; ic < firstCrysID[thetaID68] +
m_crystalsPerRing[thetaID68]; ic++) {
171 tempThetaWidth.push_back(upperThetaEdge - tempThetaEdge[ic]);
178 B2RESULT(
"eclEdgeAlgorithm: successfully stored payload ECLCrystalThetaWidth");
181 for (
int cellID = 1; cellID <= 8736; cellID++) {
182 eclCrystalWidthTheta->SetBinContent(cellID, tempThetaWidth[cellID - 1]);
183 eclCrystalWidthTheta->SetBinError(cellID, 0.);
186 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 successfuly =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.
const short m_crystalsPerRing[69]
crystals per thetaID
virtual EResult calibrate() override
..Run algorithm
Abstract base class for different kinds of events.