Skip to content

Commit 6bfc61f

Browse files
noferinishahor02
authored andcommitted
add TOF diagnostic from ccdb in digitisation (empty crates, TRM errors)
1 parent f01f10a commit 6bfc61f

11 files changed

Lines changed: 269 additions & 53 deletions

File tree

DataFormats/Detectors/TOF/include/DataFormatsTOF/Diagnostic.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ class Diagnostic
3333
Diagnostic() = default;
3434
int fill(ULong64_t pattern);
3535
int fill(ULong64_t pattern, int frequency);
36-
int getFrequency(ULong64_t pattern); // Get frequency
37-
int getFrequencyROW() { return getFrequency(0); } // Readout window frequency
38-
int getFrequencyEmptyCrate(int crate) { return getFrequency(getEmptyCrateKey(crate)); } // empty crate frequency
39-
int getFrequencyEmptyTOF() { return getFrequency(1); } // empty crate frequency
36+
int getFrequency(ULong64_t pattern) const; // Get frequency
37+
int getFrequencyROW() const { return getFrequency(0); } // Readout window frequency
38+
int getFrequencyEmptyCrate(int crate) const { return getFrequency(getEmptyCrateKey(crate)); } // empty crate frequency
39+
int getFrequencyEmptyTOF() const { return getFrequency(1); } // empty crate frequency
4040
int fillNoisy(int channel, int frequency = 1) { return fill(getNoisyChannelKey(channel), frequency); }
4141
int fillROW() { return fill(0); }
4242
int fillEmptyCrate(int crate, int frequency = 1) { return fill(getEmptyCrateKey(crate), frequency); }
@@ -49,7 +49,8 @@ class Diagnostic
4949
void fill(const Diagnostic& diag); // for calibration
5050
void fill(const gsl::span<const o2::tof::Diagnostic>){}; // for calibration
5151
void merge(const Diagnostic* prev);
52-
void getNoisyMap(Bool_t* output); // set true in output channel array
52+
void getNoisyMap(Bool_t* output, int noisyThr = 1) const; // set true in output channel array
53+
void getNoisyLevelMap(Char_t* output) const; // set true in output channel array
5354
unsigned long size() const { return mVector.size(); }
5455
ULong64_t getPattern(int i) const
5556
{
@@ -64,6 +65,8 @@ class Diagnostic
6465
int getChannel(ULong64_t pattern) const;
6566
int getNoisyLevel(ULong64_t pattern) const;
6667

68+
const std::map<ULong64_t, uint32_t>& getVector() const { return mVector; }
69+
6770
private:
6871
std::map<ULong64_t, uint32_t> mVector; // diagnostic frequency vector (key/pattern , frequency)
6972

DataFormats/Detectors/TOF/src/Diagnostic.cxx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ int Diagnostic::fill(ULong64_t pattern, int frequency)
4949
return frequency;
5050
}
5151

52-
int Diagnostic::getFrequency(ULong64_t pattern)
52+
int Diagnostic::getFrequency(ULong64_t pattern) const
5353
{
5454
auto pairC = mVector.find(pattern);
5555
if (pairC != mVector.end()) {
@@ -135,7 +135,7 @@ void Diagnostic::merge(const Diagnostic* prev)
135135
}
136136
}
137137

138-
void Diagnostic::getNoisyMap(Bool_t* output)
138+
void Diagnostic::getNoisyLevelMap(Char_t* output) const
139139
{
140140
// set true in output channel array
141141
for (auto pair : mVector) {
@@ -146,6 +146,23 @@ void Diagnostic::getNoisyMap(Bool_t* output)
146146
continue;
147147
}
148148

149-
output[getChannel(key)] = true;
149+
output[getChannel(key)] = getNoisyLevel(key);
150+
}
151+
}
152+
153+
void Diagnostic::getNoisyMap(Bool_t* output, int noisyThr) const
154+
{
155+
// set true in output channel array
156+
for (auto pair : mVector) {
157+
auto key = pair.first;
158+
int slot = getSlot(key);
159+
160+
if (slot != 14) {
161+
continue;
162+
}
163+
164+
if (getNoisyLevel(key) >= noisyThr) {
165+
output[getChannel(key)] = true;
166+
}
150167
}
151168
}

Detectors/TOF/base/include/TOFBase/CalibTOFapi.h

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "CCDB/BasicCCDBManager.h"
2121
#include "DataFormatsTOF/CalibLHCphaseTOF.h"
2222
#include "DataFormatsTOF/CalibTimeSlewingParamTOF.h"
23+
#include "TOFBase/Geo.h"
24+
#include "DataFormatsTOF/Diagnostic.h"
2325

2426
namespace o2
2527
{
@@ -35,9 +37,10 @@ class CalibTOFapi
3537
using CcdbApi = o2::ccdb::CcdbApi;
3638

3739
public:
38-
CalibTOFapi() = default;
40+
void resetDia();
41+
CalibTOFapi();
3942
CalibTOFapi(const std::string url);
40-
CalibTOFapi(long timestamp, o2::dataformats::CalibLHCphaseTOF* phase, o2::dataformats::CalibTimeSlewingParamTOF* slew) : mTimeStamp(timestamp), mLHCphase(phase), mSlewParam(slew) {}
43+
CalibTOFapi(long timestamp, o2::dataformats::CalibLHCphaseTOF* phase, o2::dataformats::CalibTimeSlewingParamTOF* slew) : mTimeStamp(timestamp), mLHCphase(phase), mSlewParam(slew) { CalibTOFapi(); }
4144
~CalibTOFapi() = default;
4245
void setTimeStamp(long t)
4346
{
@@ -50,6 +53,7 @@ class CalibTOFapi
5053
}
5154
void readLHCphase();
5255
void readTimeSlewingParam();
56+
void readDiagnosticFrequencies();
5357
void writeLHCphase(LhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, uint64_t minTimeSTamp, uint64_t maxTimeStamp);
5458
void writeTimeSlewingParam(SlewParam* param, std::map<std::string, std::string> metadataChannelCalib, uint64_t minTimeSTamp, uint64_t maxTimeStamp = 0);
5559
float getTimeCalibration(int ich, float tot);
@@ -61,10 +65,27 @@ class CalibTOFapi
6165
SlewParam& getSlewParamObj() { return *mSlewParam; }
6266
LhcPhase* getLhcPhase() { return mLHCphase; }
6367

68+
int getNoisyThreshold() const { return mNoisyThreshold; }
69+
void setNoisyThreshold(int val) { mNoisyThreshold = val; }
70+
float getEmptyTOFProb() const { return mEmptyTOF; }
71+
const float* getEmptyCratesProb() const { return mEmptyCrateProb; }
72+
const std::vector<std::pair<int, float>>& getNoisyProb() const { return mNoisy; }
73+
const std::vector<std::pair<int, float>>& getTRMerrorProb() const { return mTRMerrorProb; }
74+
const std::vector<int>& getTRMmask() const { return mTRMmask; }
75+
6476
private:
6577
long mTimeStamp; ///< timeStamp for queries
6678
LhcPhase* mLHCphase = nullptr; ///< object for LHC phase
6779
SlewParam* mSlewParam = nullptr; ///< object for timeslewing (containing info also for offset and problematic)
80+
Diagnostic* mDiaFreq = nullptr; ///< object for Diagnostic Frequency
81+
82+
// info from diagnostic
83+
int mNoisyThreshold = 1; ///< threshold to be noisy
84+
float mEmptyTOF = 0; ///< probability to have TOF fully empty
85+
float mEmptyCrateProb[Geo::kNCrate]; ///< probability to have an empty crate in the current readout window
86+
std::vector<std::pair<int, float>> mNoisy; ///< probTRMerror
87+
std::vector<std::pair<int, float>> mTRMerrorProb; ///< probTRMerror
88+
std::vector<int> mTRMmask; ///< mask error for TRM
6889

6990
ClassDefNV(CalibTOFapi, 1);
7091
};

Detectors/TOF/base/include/TOFBase/Strip.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ class Strip
8585
void fillOutputContainer(std::vector<o2::tof::Digit>& digits);
8686

8787
static int mDigitMerged;
88+
std::map<ULong64_t, o2::tof::Digit>& getDigitMap() { return mDigits; }
8889

8990
protected:
9091
Int_t mStripIndex = -1; ///< Strip ID

Detectors/TOF/base/src/CalibTOFapi.cxx

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,24 @@ using namespace o2::tof;
1616

1717
ClassImp(o2::tof::CalibTOFapi);
1818

19-
CalibTOFapi::CalibTOFapi(const std::string url)
19+
void CalibTOFapi::resetDia()
20+
{
21+
memset(mEmptyCrateProb, 0., Geo::kNCrate * 4);
22+
mTRMerrorProb.clear();
23+
mTRMmask.clear();
24+
mNoisy.clear();
25+
}
26+
27+
CalibTOFapi::CalibTOFapi()
2028
{
29+
resetDia();
30+
}
31+
32+
//______________________________________________________________________
2133

34+
CalibTOFapi::CalibTOFapi(const std::string url)
35+
{
36+
CalibTOFapi();
2237
// setting the URL to the CCDB manager
2338

2439
setURL(url);
@@ -49,6 +64,70 @@ void CalibTOFapi::readTimeSlewingParam()
4964

5065
//______________________________________________________________________
5166

67+
void CalibTOFapi::readDiagnosticFrequencies()
68+
{
69+
static const int NCH_PER_CRATE = Geo::NSTRIPXSECTOR * Geo::NPADS;
70+
// getting the Diagnostic Frequency calibration
71+
// needed for simulation
72+
73+
auto& mgr = CcdbManager::instance();
74+
mDiaFreq = mgr.getForTimeStamp<Diagnostic>("TOF/Calib/Diagnostic", mTimeStamp);
75+
76+
resetDia();
77+
78+
if (!mDiaFreq->getFrequencyROW()) {
79+
return;
80+
}
81+
82+
float nrow = (float)mDiaFreq->getFrequencyROW();
83+
mEmptyTOF = mDiaFreq->getFrequencyEmptyTOF() / nrow;
84+
85+
nrow -= mDiaFreq->getFrequencyEmptyTOF();
86+
87+
if (nrow < 1) {
88+
return;
89+
}
90+
91+
// fill empty crates
92+
int ncrate[Geo::kNCrate];
93+
for (int i = 0; i < Geo::kNCrate; i++) {
94+
ncrate[i] = mDiaFreq->getFrequencyEmptyCrate(i) - mDiaFreq->getFrequencyEmptyTOF(); // counts of empty crate for non-empty event
95+
mEmptyCrateProb[i] = ncrate[i] / nrow;
96+
}
97+
98+
const auto vectorDia = mDiaFreq->getVector();
99+
// fill TRM errors and noisy
100+
for (auto pair : vectorDia) {
101+
auto key = pair.first;
102+
int slot = mDiaFreq->getSlot(key);
103+
104+
if (slot < 13 && slot > 2) { // is TRM
105+
int icrate = mDiaFreq->getCrate(key);
106+
int crateslot = icrate * 100 + slot;
107+
mTRMerrorProb.push_back(std::make_pair(crateslot, pair.second / (nrow - ncrate[icrate])));
108+
mTRMmask.push_back(key - mDiaFreq->getTRMKey(icrate, slot)); // remove crate and slot from the key (28 bit errors remaining)
109+
continue;
110+
}
111+
112+
int channel = mDiaFreq->getChannel(key);
113+
if (channel > -1) { // noisy
114+
int crate = channel / NCH_PER_CRATE;
115+
mNoisy.push_back(std::make_pair(channel, pair.second / (nrow - ncrate[crate])));
116+
continue;
117+
}
118+
}
119+
120+
std::sort(mTRMerrorProb.begin(), mTRMerrorProb.end(), [](const auto& a, const auto& b) {
121+
return a.first < b.first;
122+
});
123+
124+
std::sort(mNoisy.begin(), mNoisy.end(), [](const auto& a, const auto& b) {
125+
return a.first < b.first;
126+
});
127+
}
128+
129+
//______________________________________________________________________
130+
52131
void CalibTOFapi::writeLHCphase(LhcPhase* phase, std::map<std::string, std::string> metadataLHCphase, uint64_t minTimeStamp, uint64_t maxTimeStamp)
53132
{
54133

Detectors/TOF/base/src/WindowFiller.cxx

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -456,27 +456,27 @@ void WindowFiller::fillDiagnosticFrequency()
456456
int slot = 0;
457457
if (mReadoutWindowData[j].isEmptyCrate(ic)) {
458458
mDiagnosticFrequency.fillEmptyCrate(ic);
459-
} else {
460-
isTOFempty = false;
461-
}
462-
if (dia) {
463-
int fd = mReadoutWindowData[j].firstDia();
464-
int lastdia = fd + dia;
465-
466-
ULong64_t key;
467-
for (int dd = fd; dd < lastdia; dd++) {
468-
if (mPatterns[dd] >= 28) {
469-
slot = mPatterns[dd] - 28;
470-
key = mDiagnosticFrequency.getTRMKey(ic, slot);
471-
continue;
472-
}
473-
474-
key += (1 << mPatterns[dd]);
475-
476-
if (dd + 1 == lastdia || mPatterns[dd + 1] >= 28) {
477-
mDiagnosticFrequency.fill(key);
459+
if (dia) {
460+
int fd = mReadoutWindowData[j].firstDia();
461+
int lastdia = fd + dia;
462+
463+
ULong64_t key;
464+
for (int dd = fd; dd < lastdia; dd++) {
465+
if (mPatterns[dd] >= 28) {
466+
slot = mPatterns[dd] - 28;
467+
key = mDiagnosticFrequency.getTRMKey(ic, slot);
468+
continue;
469+
}
470+
471+
key += (1 << mPatterns[dd]);
472+
473+
if (dd + 1 == lastdia || mPatterns[dd + 1] >= 28) {
474+
mDiagnosticFrequency.fill(key);
475+
}
478476
}
479477
}
478+
} else {
479+
isTOFempty = false;
480480
}
481481
}
482482
}

0 commit comments

Comments
 (0)