3 #include <fwk/CentralConfig.h>
4 #include <det/VManager.h>
5 #include <utl/Branch.h>
8 #include <sevt/SEvent.h>
9 #include <sevt/Station.h>
10 #include <sevt/SmallPMT.h>
11 #include <sevt/SmallPMTCalibData.h>
12 #include <sdet/PMTConstants.h>
13 #include <sdet/SDetector.h>
15 #include <utl/ErrorLogger.h>
26 namespace SdEACalibrationFillerKG {
31 auto topB = CentralConfig::GetInstance()->GetTopBranch(
"SdEACalibrationFiller");
33 auto onlineValuesUUBB = topB.GetChild(
"onlineValuesUUB");
34 onlineValuesUUBB.GetChild(
"rawCharge").GetData(fRawChargeUUB);
35 onlineValuesUUBB.GetChild(
"rawPeak").GetData(fRawPeakUUB);
36 onlineValuesUUBB.GetChild(
"hgBaseline").GetData(fHgBaselineUUB);
37 onlineValuesUUBB.GetChild(
"lgBaseline").GetData(fLgBaselineUUB);
38 onlineValuesUUBB.GetChild(
"DARatio").GetData(fDARatioUUB);
40 auto onlineValuesPPAB = topB.GetChild(
"onlineValuesPPA");
41 onlineValuesPPAB.GetChild(
"rawCharge").GetData(fRawChargePPA);
42 onlineValuesPPAB.GetChild(
"rawPeak").GetData(fRawPeakPPA);
44 auto offlineValuesUUBB = topB.GetChild(
"offlineValuesUUB");
45 offlineValuesUUBB.GetChild(
"beta").GetData(fBeta);
46 offlineValuesUUBB.GetChild(
"betaErr").GetData(fBetaErr);
47 offlineValuesUUBB.GetChild(
"betaChi2").GetData(fBetaChi2);
48 offlineValuesUUBB.GetChild(
"betaCorrectionFact").GetData(fBetaCorrectionFact);
55 SdEACalibrationFiller::Run(
Event& event)
60 auto& sEvent =
event.GetSEvent();
62 for (
auto& station : sEvent.StationsRange()) {
64 const auto& dStation = det::Detector::GetInstance().GetSDetector().GetStation(station);
66 const bool isUub = dStation.IsUUB();
67 const bool hasSmallPMT = dStation.HasSmallPMT();
68 const bool hasScintillator = dStation.HasScintillator();
70 if (isUub || hasScintillator) {
71 FillCalibrationInfo(station);
73 FillCalibrationInfoSmallPMT(station);
84 SdEACalibrationFiller::FillCalibrationInfo(
Station& station)
101 const auto& dStation = det::Detector::GetInstance().GetSDetector().GetStation(station);
103 const bool hasScintillator = dStation.HasScintillator();
104 const bool isUub = dStation.IsUUB();
110 if (!pmt.HasCalibData())
113 auto& pmtCalibData = pmt.GetCalibData();
116 const auto type = pmt.GetType();
118 const auto& chargeHistoBinning = dStation.GetMuonChargeHistogramBinning<
short>(type, stationCalibData.GetVersion());
121 double rawCharge = 0;
122 double hgBaseline = 0;
123 double lgBaseline = 0;
129 const unsigned int i = pmt.GetId() - 1;
130 rawPeak = fRawPeakUUB[i];
131 rawCharge = fRawChargeUUB[i];
132 hgBaseline = fHgBaselineUUB[i];
133 lgBaseline = fLgBaselineUUB[i];
134 daRatio = fDARatioUUB[i];
136 }
else if (hasScintillator) {
139 rawPeak = fRawPeakPPA[pmtId-1];
140 rawCharge = fRawChargePPA[pmtId-1];
144 const double vemPeak = pmtCalibData.GetVEMPeak();
145 const double vemCharge = pmtCalibData.GetVEMCharge();
150 rawCharge = vemCharge;
153 pmtCalibData.SetVEMPeak(rawPeak);
154 pmtCalibData.SetVEMCharge(rawCharge);
158 pmtCalibData.SetIsTubeOk(
true);
159 pmtCalibData.SetIsLowGainOk(
true);
164 if (isUub && pmt.HasFADCTrace()) {
170 vector<double> hgPiece;
171 vector<double> lgPiece;
173 hgPiece.reserve(500);
174 lgPiece.reserve(500);
176 for (
int i = 0; i < 500; ++i) {
177 hgPiece.push_back(hgTrace[i]);
178 lgPiece.push_back(lgTrace[i]);
181 sort(hgPiece.begin(), hgPiece.end());
182 sort(lgPiece.begin(), lgPiece.end());
184 if (hgPiece.size() % 2 == 0)
185 hgBaseline = (hgPiece[hgPiece.size() / 2 - 1] + hgPiece[hgPiece.size() / 2]) / 2;
187 hgBaseline = hgPiece[hgPiece.size() / 2];
189 if (lgPiece.size() % 2 == 0)
190 lgBaseline = (lgPiece[lgPiece.size() / 2 - 1] + lgPiece[lgPiece.size() / 2]) / 2;
192 lgBaseline = lgPiece[lgPiece.size() / 2];
194 pmtCalibData.SetBaseline(hgBaseline, 2);
196 pmtCalibData.SetDynodeAnodeRatio(daRatio, 0);
197 pmtCalibData.SetIsTubeOk(
true);
198 pmtCalibData.SetIsLowGainOk(
true);
210 if (!muonChargeHistoSize ||
int(chargeHistoBinning.size()) - 1 != muonChargeHistoSize) {
211 WARNING(
"There should be a muon charge histogram!");
214 const CalibHistogram chargeHisto(chargeHistoBinning, pmtCalibData.GetMuonChargeHisto());
215 const double baseEstimate =
216 pmtCalibData.GetBaseline() * 20 - pmtCalibData.GetMuonChargeHistoOffset();
217 const double base = (fabs(baseEstimate) < 20) ? baseEstimate : 0;
219 if (chargeHisto.GetMaximum() > 500) {
222 unsigned int bin = chargeHisto.GetNBins() - 1;
223 unsigned int nbbin = bin;
227 unsigned int binmin = 0;
228 unsigned int binmax = 0;
237 else if (hasScintillator)
241 v = int(chargeHisto.GetBinAverage(bin));
242 v1 = int(chargeHisto.GetBinAverage(bin + dir));
243 v2 = int(chargeHisto.GetBinAverage(bin + 2*dir));
245 if (v > vmax && v > max)
248 if (binmin &&
double(max) / v > 1.3 && double(max) / v1 > 1.3 && double(max) / v2 > 1.3)
250 if (!binmin && max &&
double(max) / v > 1.3 && double(max) / v1 > 1.3 && double(max) / v2 > 1.3) {
261 estimate = (binmin + binmax) / 2;
265 }
else if (estimate < binmax && estimate > binmin && binmin > 0 && binmax < chargeHisto.GetNBins() && binmin < binmax) {
274 for (
unsigned int i = binmin; i < binmax; ++i) {
275 const double v = chargeHisto.GetBinAverage(i);
276 const double a = chargeHisto.GetBinCenter(i);
278 const double a2 = a *
a;
280 const double a3 = a2 *
a;
290 (y * (x4 * x - x2 * x3) + xy * (x2 * x2 - nb * x4) +
291 x2y * (nb * x3 - x * x2));
293 (y * (x2 * x2 - x * x3) + xy * (nb * x3 - x * x2) +
294 x2y * (x * x - nb * x2));
297 if (res > chargeHisto.GetBinCenter(binmin) && res < chargeHisto.GetBinCenter(binmax))
302 if (isUub && !(res > humpvMin && res < humpvMax))
309 rawCharge = res / 1.045;
318 rawPeak = rawCharge / 1.8;
321 pmtCalibData.SetIsTubeOk(
false);
324 pmtCalibData.SetVEMPeak(rawPeak);
325 pmtCalibData.SetVEMCharge(rawCharge);
332 SdEACalibrationFiller::FillCalibrationInfoSmallPMT(
Station& station)
345 if (spmt.HasCalibData())
349 auto& spmtCalib = spmt.GetCalibData();
350 spmtCalib.SetIsTubeOk(
true);
351 spmtCalib.SetVersion(0);
352 spmtCalib.SetBeta(fBeta);
353 spmtCalib.SetBetaError(fBetaErr);
354 spmtCalib.SetChi2(fBetaChi2);
355 spmtCalib.SetCorrectionFactor(fBetaCorrectionFact);
359 spmtCalib.SetBeta(fBeta, pmt.GetId());
360 spmtCalib.SetBetaError(fBetaErr, pmt.GetId());
361 spmtCalib.SetChi2(fBetaChi2, pmt.GetId());
362 spmtCalib.SetCorrectionFactor(fBetaCorrectionFact, pmt.GetId());
const std::vector< int > & GetMuonChargeHisto() const
histogram of the sum of muon charges (not really used anywhere)
void Init()
Initialise the registry.
class to hold data at Station level
void MakeCalibData()
Make PMT calibration data object.
#define WARNING(message)
Macro for logging warning messages.
sevt::StationCalibData & GetCalibData()
Get calibration data for the station.
ResultFlag
Flag returned by module methods to the RunController.
total (shower and background)