forked from AliceO2Group/AliceO2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTPRateFetcher.cxx
More file actions
182 lines (177 loc) · 6.9 KB
/
CTPRateFetcher.cxx
File metadata and controls
182 lines (177 loc) · 6.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#include "DataFormatsCTP/CTPRateFetcher.h"
#include <map>
#include <vector>
#include "CommonConstants/LHCConstants.h"
using namespace o2::ctp;
double CTPRateFetcher::fetch(o2::ccdb::BasicCCDBManager* ccdb, uint64_t timeStamp, int runNumber, std::string sourceName)
{
auto triggerRate = fetchNoPuCorr(ccdb, timeStamp, runNumber, sourceName);
if (triggerRate >= 0) {
return pileUpCorrection(triggerRate);
}
return -1;
}
double CTPRateFetcher::fetchNoPuCorr(o2::ccdb::BasicCCDBManager* ccdb, uint64_t timeStamp, int runNumber, std::string sourceName)
{
setupRun(runNumber, ccdb, timeStamp, 1);
if (sourceName.find("ZNC") != std::string::npos) {
if (runNumber < 544448) {
return fetchCTPratesInputsNoPuCorr(timeStamp, 25) / (sourceName.find("hadronic") != std::string::npos ? 28. : 1.);
} else {
return fetchCTPratesClassesNoPuCorr(timeStamp, "C1ZNC-B-NOPF-CRU", 6) / (sourceName.find("hadronic") != std::string::npos ? 28. : 1.);
}
} else if (sourceName == "T0CE") {
return fetchCTPratesClassesNoPuCorr(timeStamp, "CMTVXTCE-B-NOPF");
} else if (sourceName == "T0SC") {
return fetchCTPratesClassesNoPuCorr(timeStamp, "CMTVXTSC-B-NOPF");
} else if (sourceName == "T0VTX") {
if (runNumber < 534202) {
return fetchCTPratesClassesNoPuCorr(timeStamp, "minbias_TVX_L0", 3); // 2022
} else {
double_t ret = fetchCTPratesClassesNoPuCorr(timeStamp, "CMTVX-B-NOPF");
if (ret == -2.) {
LOG(info) << "Trying different class";
ret = fetchCTPratesClassesNoPuCorr(timeStamp, "CMTVX-NONE");
if (ret < 0) {
LOG(fatal) << "None of the classes used for lumi found";
}
}
return ret;
}
}
LOG(error) << "CTP rate for " << sourceName << " not available";
return -1.;
}
void CTPRateFetcher::updateScalers(ctp::CTPRunScalers& scalers)
{
mScalers = scalers;
mScalers.convertRawToO2();
}
//
int CTPRateFetcher::getRates(std::array<double, 3>& rates, o2::ccdb::BasicCCDBManager* ccdb, int runNumber, const std::string sourceName) // rates at start,stop and middle of the run
{
setupRun(runNumber, ccdb, 0, 1);
mOrbit = 1;
mOutsideLimits = 1;
auto orbitlimits = mScalers.getOrbitLimit();
// std::cout << "1st orbit:" << orbitlimits.first << " last:" << orbitlimits.second << " Middle:" << (orbitlimits.first + orbitlimits.second)/2 << std::endl;
double rate0 = fetch(ccdb, orbitlimits.first, mRunNumber, sourceName);
double rateLast = fetch(ccdb, orbitlimits.second, mRunNumber, sourceName);
double rateM = fetch(ccdb, (orbitlimits.first + orbitlimits.second) / 2, mRunNumber, sourceName);
// std::cout << rate0 << " " << rateLast << " " << rateM << std::endl;
rates[0] = rate0;
rates[1] = rateLast;
rates[2] = rateM;
return 0;
}
//
double CTPRateFetcher::fetchCTPratesClasses(uint64_t timeStamp, const std::string& className, int inputType)
{
auto triggerRate = fetchCTPratesClassesNoPuCorr(timeStamp, className, inputType);
if (triggerRate >= 0) {
return pileUpCorrection(triggerRate);
}
return -1;
}
double CTPRateFetcher::fetchCTPratesClassesNoPuCorr(uint64_t timeStamp, const std::string& className, int inputType)
{
std::vector<ctp::CTPClass>& ctpcls = mConfig.getCTPClasses();
std::vector<int> clslist = mConfig.getTriggerClassList();
int classIndex = -1;
for (size_t i = 0; i < clslist.size(); i++) {
if (ctpcls[i].name.find(className) != std::string::npos) {
classIndex = i;
break;
}
}
if (classIndex == -1) {
LOG(warn) << "Trigger class " << className << " not found in CTPConfiguration";
return -2.;
}
if (mOrbit) {
auto rate{mScalers.getRate((uint32_t)timeStamp, classIndex, inputType, mOutsideLimits)};
return rate.second;
} else {
auto rate{mScalers.getRateGivenT(timeStamp * 1.e-3, classIndex, inputType, mOutsideLimits)};
return rate.second;
}
}
double CTPRateFetcher::fetchCTPratesInputs(uint64_t timeStamp, int input)
{
std::vector<ctp::CTPScalerRecordO2>& recs = mScalers.getScalerRecordO2();
if (recs[0].scalersInps.size() == 48) {
if (mOrbit) {
return pileUpCorrection(mScalers.getRate((uint32_t)timeStamp, input, 7, mOutsideLimits).second);
} else {
return pileUpCorrection(mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, mOutsideLimits).second);
}
} else {
LOG(error) << "Inputs not available";
return -1.;
}
}
double CTPRateFetcher::fetchCTPratesInputsNoPuCorr(uint64_t timeStamp, int input)
{
std::vector<ctp::CTPScalerRecordO2>& recs = mScalers.getScalerRecordO2();
if (recs[0].scalersInps.size() == 48) {
if (mOrbit) {
return mScalers.getRate((uint32_t)timeStamp, input, 7, mOutsideLimits).second;
} else {
return mScalers.getRateGivenT(timeStamp * 1.e-3, input, 7, mOutsideLimits).second; // qc flag implemented only for time
}
} else {
LOG(error) << "Inputs not available";
return -1.;
}
}
double CTPRateFetcher::pileUpCorrection(double triggerRate)
{
if (mLHCIFdata.getFillNumber() == 0) {
LOG(fatal) << "No filling" << std::endl;
}
auto bfilling = mLHCIFdata.getBunchFilling();
std::vector<int> bcs = bfilling.getFilledBCs();
double nbc = bcs.size();
double nTriggersPerFilledBC = triggerRate / nbc / constants::lhc::LHCRevFreq;
double mu = -std::log(1 - nTriggersPerFilledBC);
return mu * nbc * constants::lhc::LHCRevFreq;
}
void CTPRateFetcher::setupRun(int runNumber, o2::ccdb::BasicCCDBManager* ccdb, uint64_t timeStamp, bool initScalers)
{
if (runNumber == mRunNumber) {
return;
}
mRunNumber = runNumber;
LOG(info) << "Setting up CTP scalers for run " << mRunNumber;
auto ptrLHCIFdata = ccdb->getSpecific<parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", timeStamp);
if (ptrLHCIFdata == nullptr) {
LOG(fatal) << "GRPLHCIFData not in database, timestamp:" << timeStamp;
}
mLHCIFdata = *ptrLHCIFdata;
std::map<string, string> metadata;
metadata["runNumber"] = std::to_string(mRunNumber);
auto ptrConfig = ccdb->getSpecific<ctp::CTPConfiguration>("CTP/Config/Config", timeStamp, metadata);
if (ptrConfig == nullptr) {
LOG(fatal) << "CTPRunConfig not in database, timestamp:" << timeStamp;
}
mConfig = *ptrConfig;
if (initScalers) {
auto ptrScalers = ccdb->getSpecific<ctp::CTPRunScalers>("CTP/Calib/Scalers", timeStamp, metadata);
if (ptrScalers) {
mScalers = *ptrScalers;
mScalers.convertRawToO2();
} else {
LOG(fatal) << "CTPRunScalers not in database, timestamp:" << timeStamp;
}
}
}