8#include <svd/calibration/SVDHotStripsCalibrationsAlgorithm.h>
11#include <svd/calibration/SVDHotStripsCalibrations.h>
14#include <framework/logging/Logger.h>
32 double stripOccAfterAbsCut[768];
40 auto tree = getObjectPtr<TTree>(
"HTreeOccupancyCalib");
41 auto hNEvents = getObjectPtr<TH1F>(
"HNEvents");
43 TH1F* hocc =
new TH1F(
"",
"", 768, 0, 768);
46 B2WARNING(
"No tree object.");
47 }
else if (!tree->GetEntries()) {
48 B2WARNING(
"No data in the tree.");
51 B2WARNING(
"No histogram object containing the number of events.");
59 tree->SetBranchAddress(
"hist", &hocc);
60 tree->SetBranchAddress(
"layer", &layer);
61 tree->SetBranchAddress(
"ladder", &ladder);
62 tree->SetBranchAddress(
"sensor", &sensor);
63 tree->SetBranchAddress(
"view", &side);
65 std::map<std::tuple<int, int, int, int>, TH1F*> map_hocc;
67 for (
int i = 0; i < tree->GetEntries(); i++) {
70 TH1F*& hOccupancy = map_hocc[std::make_tuple(layer, ladder, sensor, side)];
71 if (hOccupancy ==
nullptr) {
72 hOccupancy = (TH1F*)hocc->Clone(Form(
"hocc_L%dL%dS%d_%d", layer, ladder, sensor, side));
74 hOccupancy->Add(hocc);
80 while (gSystem->GetPathInfo(Form(
"algorithm_SVDHotStripsCalibrations_output_rev_%d.root", cal_rev), info) == 0)
82 std::unique_ptr<TFile> f(
new TFile(Form(
"algorithm_SVDHotStripsCalibrations_output_rev_%d.root", cal_rev),
"RECREATE"));
86 f->WriteTObject(hNEvents.get());
87 nevents = ((TH1F*)hNEvents.get())->GetEntries();
90 for (
const auto& key : map_hocc) {
91 std::tie(layer, ladder, sensor, side) = key.first;
93 if (!side && layer != 3) nstrips = 512;
95 TH1F* hOccupancy = (TH1F*)key.second;
96 if (nevents != 0) hOccupancy->Scale(1. / nevents);
97 else B2ERROR(
"No events to compute the occupancy as strip_count/nevents");
99 f->WriteTObject(hOccupancy);
101 for (
int i = 0; i < nstrips; i++) { vecHS[i] = 0;}
103 for (
int iterStrip = 0; iterStrip < nstrips; iterStrip++) {
104 float occCal = hOccupancy->GetBinContent(iterStrip + 1);
105 B2DEBUG(40,
"Occupancy for: " << layer <<
"." << ladder <<
"." << sensor <<
"." << side <<
", strip:" << iterStrip <<
": " <<
108 if (occCal > occThr) {
109 vecHS[iterStrip] = 1;
110 stripOccAfterAbsCut[iterStrip] = 0;
111 }
else stripOccAfterAbsCut[iterStrip] = occCal;
115 while (
theHSFinder(stripOccAfterAbsCut, vecHS, nstrips)) {}
117 for (
int l = 0; l < nstrips; l++) {
118 isHotStrip = (int) vecHS[l];
120 payload->set(layer, ladder, sensor,
bool(side), l, isHotStrip);
139 int N = nstrips / base;
141 for (
int sector = 0; sector < N; sector++) {
144 double sensorOccAverage = 0;
146 for (
int l = sector * base; l < sector * base + base; l++) {
147 sensorOccAverage += stripOccAfterAbsCut[l];
148 if (stripOccAfterAbsCut[l] > 0) nafter++;
150 sensorOccAverage = sensorOccAverage / nafter;
152 B2DEBUG(1,
"Average occupancy: " << sensorOccAverage);
154 for (
int l = sector * base; l < sector * base + base; l++) {
160 stripOccAfterAbsCut[l] = 0;
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.
float m_relativeOccupancyThreshold
occupancy relative to the average sensor occupancy used to define a strip as hot.
std::string m_id
Parameter given to set the UniqueID of the payload.
bool m_computeAverageOccupancyPerChip
granularity used to estimate average occupancy.
bool theHSFinder(double *stripOccAfterAbsCut, bool *hsflag, int nstrips)
returns true if the strip is hot
float m_absoluteOccupancyThreshold
absolute occupancy thresold to define a strip as hot.
SVDHotStripsCalibrationsAlgorithm(const std::string &str)
Constructor set the prefix to SVDHotStripsCalibrationsCollector.
virtual EResult calibrate() override
Run algo on data.
SVDCalibrationsBase< SVDCalibrationsBitmap > t_payload
typedef of the SVDHotStripsCalibrations payload for all SVD strips
Abstract base class for different kinds of events.