Project
Loading...
Searching...
No Matches
NoiseCalibrator.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
13
15
16#include "Framework/Logger.h"
17#include "TFile.h"
21#ifdef WITH_OPENMP
22#include <omp.h>
23#endif
24
25namespace o2
26{
27namespace its
28{
29
30bool NoiseCalibrator::processTimeFrameClusters(gsl::span<const o2::itsmft::CompClusterExt> const& clusters,
31 gsl::span<const unsigned char> const& patterns,
32 gsl::span<const o2::itsmft::ROFRecord> const& rofs)
33{
34 static int nTF = 0;
35 LOG(detail) << "Processing TF# " << nTF++ << " of " << clusters.size() << " clusters in" << rofs.size() << " ROFs";
36 // extract hits
37 auto pattIt = patterns.begin();
38 mChipIDs.clear();
39 for (const auto& rof : rofs) {
40 int chipID = -1;
41 std::vector<int>* currChip = nullptr;
42 auto clustersInFrame = rof.getROFData(clusters);
43 for (const auto& c : clustersInFrame) {
44 if (chipID != c.getSensorID()) { // data is sorted over chip IDs
45 chipID = c.getSensorID();
46 currChip = &mChipHits[chipID];
47 if (currChip->empty()) {
48 mChipIDs.push_back(chipID); // acknowledge non-empty chip
49 }
50 }
51 auto pattID = c.getPatternID();
53 auto row = c.getRow();
54 auto col = c.getCol();
55 if (mDict->getSize() == 0) {
57 patt.acquirePattern(pattIt);
58 } else {
59 LOG(fatal) << "Clusters contain pattern IDs, but no dictionary is provided...";
60 }
61 } else if (pattID == o2::itsmft::CompCluster::InvalidPatternID) {
62 patt.acquirePattern(pattIt);
63 } else if (mDict->isGroup(pattID)) {
64 patt.acquirePattern(pattIt);
65 float xCOG = 0., zCOG = 0.;
66 patt.getCOG(xCOG, zCOG); // for grouped patterns the reference pixel is at COG
67 row -= round(xCOG);
68 col -= round(zCOG);
69 } else {
70 patt = mDict->getPattern(pattID);
71 }
72 auto colSpan = patt.getColumnSpan();
73 auto rowSpan = patt.getRowSpan();
74 // Fast 1-pixel calibration
75 if ((rowSpan == 1) && (colSpan == 1)) {
76 currChip->push_back(o2::itsmft::NoiseMap::getKey(row, col));
77 continue;
78 }
79 if (m1pix) {
80 continue;
81 }
82 for (int ir = 0; ir < rowSpan; ir++) {
83 for (int ic = 0; ic < colSpan; ic++) {
84 if (patt.isSet(ir, ic)) {
85 currChip->push_back(o2::itsmft::NoiseMap::getKey(row + ir, col + ic));
86 }
87 }
88 }
89 }
90 }
91 // distribute hits over the map
92#ifdef WITH_OPENMP
93#pragma omp parallel for schedule(dynamic) num_threads(mNThreads)
94#endif
95 for (int chipID : mChipIDs) {
96 mNoiseMap.increaseNoiseCount(chipID, mChipHits[chipID]);
97 mChipHits[chipID].clear();
98 }
99 mNumberOfStrobes += rofs.size();
100 return (mNumberOfStrobes > mMinROFs) ? true : false;
101}
102
103bool NoiseCalibrator::processTimeFrameDigits(gsl::span<const o2::itsmft::Digit> const& digits,
104 gsl::span<const o2::itsmft::ROFRecord> const& rofs)
105{
106 static int nTF = 0;
107 LOG(detail) << "Processing TF# " << nTF++ << " of " << digits.size() << " digits in " << rofs.size() << " ROFs";
108 mChipIDs.clear();
109 for (const auto& rof : rofs) {
110 int chipID = -1;
111 std::vector<int>* currChip = nullptr;
112 auto digitsInFrame = rof.getROFData(digits);
113 for (const auto& dig : digitsInFrame) {
114 if (chipID != dig.getChipIndex()) {
115 chipID = dig.getChipIndex();
116 currChip = &mChipHits[chipID];
117 if (currChip->empty()) {
118 mChipIDs.push_back(chipID); // acknowledge non-empty chip
119 }
120 }
121 currChip->push_back(o2::itsmft::NoiseMap::getKey(dig.getRow(), dig.getColumn()));
122 }
123 }
124 // distribute hits over the map
125#ifdef WITH_OPENMP
126#pragma omp parallel for schedule(dynamic) num_threads(mNThreads)
127#endif
128 for (int chipID : mChipIDs) {
129 mNoiseMap.increaseNoiseCount(chipID, mChipHits[chipID]);
130 mChipHits[chipID].clear();
131 }
132 mNumberOfStrobes += rofs.size();
133 return (mNumberOfStrobes > mMinROFs) ? true : false;
134}
135
137{
138 // add preproprecessed map to total
139#ifdef WITH_OPENMP
140#pragma omp parallel for schedule(dynamic) num_threads(mNThreads)
141#endif
142 for (int ic = 0; ic < NChips; ic++) {
143 const auto& chExt = extMap.getChip(ic);
144 auto& chCurr = mNoiseMap.getChip(ic);
145 for (auto it : chExt) {
146 chCurr[it.first] += it.second;
147 }
148 }
149}
150
152{
153 LOG(info) << "Number of processed strobes is " << mNumberOfStrobes;
154 if (cutIB > 0) {
155 mNoiseMap.applyProbThreshold(mProbabilityThreshold, mNumberOfStrobes, mProbRelErr, 432, 24119); // to OB only
156 LOG(info) << "Applying special cut for ITS IB: " << cutIB;
157 mNoiseMap.applyProbThreshold(cutIB, mNumberOfStrobes, mProbRelErr, 0, 431); // to IB only
158 } else {
159 mNoiseMap.applyProbThreshold(mProbabilityThreshold, mNumberOfStrobes, mProbRelErr);
160 }
161 mNoiseMap.print();
162}
163
165{
166 for (int i = 0; i < NChips; i++) {
167 mNoiseMap.resetChip(i);
168 mChipHits[i].clear();
169 }
170}
171
172} // namespace its
173} // namespace o2
Definition of the ITSMFT compact cluster.
int32_t i
Definition of the ITSMFT ROFrame (trigger) record.
uint32_t col
Definition RawData.h:4
uint32_t c
Definition RawData.h:2
static constexpr int NChips
bool processTimeFrameDigits(gsl::span< const o2::itsmft::Digit > const &digits, gsl::span< const o2::itsmft::ROFRecord > const &rofs)
void addMap(const o2::itsmft::NoiseMap &extMap)
bool processTimeFrameClusters(gsl::span< const o2::itsmft::CompClusterExt > const &clusters, gsl::span< const unsigned char > const &patterns, gsl::span< const o2::itsmft::ROFRecord > const &rofs)
void finalize(float cutIB=-1.)
int getRowSpan() const
Returns the number of rows.
void acquirePattern(iterator &pattIt)
int getColumnSpan() const
Returns the number of columns.
static int getCOG(int rowSpan, int colSpan, const unsigned char patt[MaxPatternBytes], float &xCOG, float &zCOG)
Static: Compute pattern's COG position. Returns the number of fired pixels.
bool isSet(int row, int col) const
static constexpr unsigned short InvalidPatternID
Definition CompCluster.h:46
NoiseMap class for the ITS and MFT.
Definition NoiseMap.h:39
static int getKey(int row, int col)
Definition NoiseMap.h:223
void increaseNoiseCount(int chip, int row, int col)
Definition NoiseMap.h:66
std::map< int, int > & getChip(int chip)
Definition NoiseMap.h:175
void applyProbThreshold(float t, long int n, float relErr=0.2f, int minChipID=0, int maxChipID=24119)
Definition NoiseMap.h:105
void resetChip(int chip)
Definition NoiseMap.h:191
int getSize() const
Returns the number of elements in the dicionary;.
const ClusterPattern & getPattern(int n) const
Returns the pattern of the topology.
bool isGroup(int n) const
Returns true if the element corresponds to a group of rare topologies.
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"
o2::InteractionRecord ir(0, 0)
std::vector< Cluster > clusters
std::vector< Digit > digits
std::vector< int > row