Belle II Software  release-05-01-25
SVDHotStripsCalibrationsAlgorithm.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2017 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributors: Laura Zani (2019) *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 #include <svd/calibration/SVDHotStripsCalibrationsAlgorithm.h>
11 
12 
13 #include <svd/calibration/SVDHotStripsCalibrations.h>
14 
15 #include <TH1F.h>
16 #include <framework/logging/Logger.h>
17 #include <iostream>
18 #include <TString.h>
19 
20 using namespace std;
21 using namespace Belle2;
22 
23 SVDHotStripsCalibrationsAlgorithm::SVDHotStripsCalibrationsAlgorithm(const std::string& str) :
24  CalibrationAlgorithm("SVDOccupancyCalibrationsCollector")
25 {
26  setDescription("SVDHotStripsCalibrations calibration algorithm");
27  m_id = str;
28  m_base = -1;
29  m_relOccPrec = 5.;
30 }
31 
33 {
34 
35  int isHotStrip = 0;
36  int vecHS[768];
37  double stripOccAfterAbsCut[768];
38 
39  for (int i = 0; i < 768; i++) { vecHS[i] = 0; stripOccAfterAbsCut[i] = 0;}
40 
41  // float occCal = 1.;
42  float occThr = 0.2; //first absolute cut for strips with occupancy >20%
43 
44  // auto HSBitmap = new Belle2::SVDCalibrationsBitmap();
45  auto payload = new Belle2::SVDHotStripsCalibrations::t_payload(isHotStrip, m_id);
46 
47  auto tree = getObjectPtr<TTree>("HTreeOccupancyCalib");
48 
49  TH1F* hocc = new TH1F("", "", 768, 0, 768);
50 
51  if (!tree) {
52  B2WARNING("No tree object.");
53  } else if (!tree->GetEntries()) {
54  B2WARNING("No data in the tree.");
55  }
56 
57  int layer = 0;
58  int ladder = 0;
59  int sensor = 0;
60  int side = 0;
61 
62  tree->SetBranchAddress("hist", &hocc);
63  tree->SetBranchAddress("layer", &layer);
64  tree->SetBranchAddress("ladder", &ladder);
65  tree->SetBranchAddress("sensor", &sensor);
66  tree->SetBranchAddress("view", &side);
67 
68 
69  for (int i = 0; i < tree->GetEntries(); i++) {
70  tree->GetEntry(i);
71  int nstrips = 768;
72  if (!side && layer != 3) nstrips = 512;
73 
74  for (int iterStrip = 0; iterStrip < nstrips; iterStrip++) {
75  float occCal = hocc->GetBinContent(iterStrip + 1);
76  // B2INFO("Occupancy for" << layer << "." << ladder << "." << sensor << "." << side << ", strip:" << iterStrip << ": " << occCal);
77 
78  if (occCal > occThr) {
79  vecHS[iterStrip] = 1;
80  stripOccAfterAbsCut[iterStrip] = 0;
81  } else stripOccAfterAbsCut[iterStrip] = occCal;
82  }
83 
84  //iterative procedure
85  // B2INFO("Starting iterative procedure for hot strips finding");
86  bool moreHS = true;
87 
88  while (moreHS && theHSFinder(stripOccAfterAbsCut, vecHS, nstrips)) {
89  moreHS = theHSFinder(stripOccAfterAbsCut, vecHS, nstrips);
90  }
91 
92  for (int l = 0; l < nstrips; l++) {
93  isHotStrip = (int) vecHS[l];
94 
95  payload->set(layer, ladder, sensor, bool(side), l, isHotStrip);
96  }
97  }
98 
99  saveCalibration(payload, "SVDHotStripsCalibrations");
100 
101  // probably not needed - would trigger re-doing the collection
102  //if ( ... too large corrections ... ) return c_Iterate;
103  return c_OK;
104 }
105 
106 
107 bool SVDHotStripsCalibrationsAlgorithm::theHSFinder(double* stripOccAfterAbsCut, int* hsflag, int nstrips)
108 {
109  bool found = false;
110 
111  if (m_base == -1)
112  m_base = nstrips;
113 
114  int N = nstrips / m_base;
115 
116  for (int sector = 0; sector < N; sector++) {
117 
118  int nafter = 0;
119  double sensorOccAverage = 0;
120 
121  for (int l = sector * m_base; l < sector * m_base + m_base; l++) {
122  sensorOccAverage = sensorOccAverage + stripOccAfterAbsCut[l];
123  if (stripOccAfterAbsCut[l] > 0) nafter++;
124  }
125  sensorOccAverage = sensorOccAverage / nafter;
126 
127  B2DEBUG(1, "Average occupancy: " << sensorOccAverage);
128 
129  for (int l = sector * m_base; l < sector * m_base + m_base; l++) {
130 
131  // flag additional HS by comparing each strip occupancy with the sensor-based average occupancy
132 
133  if (stripOccAfterAbsCut[l] > sensorOccAverage * m_relOccPrec) {
134  hsflag[l] = 1;
135  found = true;
136  stripOccAfterAbsCut[l] = 0;
137  }
138  // else hsflag[l]=0;
139  }
140  }
141 
142  return found;
143 }
Belle2::CalibrationAlgorithm::saveCalibration
void saveCalibration(TClonesArray *data, const std::string &name)
Store DBArray payload with given name with default IOV.
Definition: CalibrationAlgorithm.cc:290
Belle2::SVDHotStripsCalibrationsAlgorithm::calibrate
virtual EResult calibrate() override
Run algo on data.
Definition: SVDHotStripsCalibrationsAlgorithm.cc:32
Belle2::SVDHotStripsCalibrations::t_payload
SVDCalibrationsBase< SVDCalibrationsBitmap > t_payload
typedef of the SVDHotStripsCalibrations payload for all SVD strips
Definition: SVDHotStripsCalibrations.h:48
Belle2::CalibrationAlgorithm::c_OK
@ c_OK
Finished successfuly =0 in Python.
Definition: CalibrationAlgorithm.h:51
Belle2::CalibrationAlgorithm::setDescription
void setDescription(const std::string &description)
Set algorithm description (in constructor)
Definition: CalibrationAlgorithm.h:331
Belle2::SVDHotStripsCalibrationsAlgorithm::m_relOccPrec
float m_relOccPrec
parameter to tue the finder algorithm
Definition: SVDHotStripsCalibrationsAlgorithm.h:50
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::SVDHotStripsCalibrationsAlgorithm::m_id
std::string m_id
Parameter given to set the UniqueID of the payload.
Definition: SVDHotStripsCalibrationsAlgorithm.h:47
Belle2::CalibrationAlgorithm::EResult
EResult
The result of calibration.
Definition: CalibrationAlgorithm.h:50
Belle2::SVDHotStripsCalibrationsAlgorithm::theHSFinder
bool theHSFinder(double *stripOccAfterAbsCut, int *hsflag, int nstrips)
returns true if the strip is hot
Definition: SVDHotStripsCalibrationsAlgorithm.cc:107
Belle2::CalibrationAlgorithm
Base class for calibration algorithms.
Definition: CalibrationAlgorithm.h:47
Belle2::SVDHotStripsCalibrationsAlgorithm::m_base
int m_base
parameter to tune finder angorithm
Definition: SVDHotStripsCalibrationsAlgorithm.h:49