forked from AliceO2Group/O2Physics
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctpRateFetcher.cxx
More file actions
130 lines (121 loc) · 4.88 KB
/
ctpRateFetcher.cxx
File metadata and controls
130 lines (121 loc) · 4.88 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
// 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 "ctpRateFetcher.h"
#include <CCDB/BasicCCDBManager.h>
#include <CommonConstants/LHCConstants.h>
#include <DataFormatsCTP/Configuration.h>
#include <DataFormatsCTP/Scalers.h>
#include <DataFormatsParameters/GRPLHCIFData.h>
#include <map>
#include <string>
#include <vector>
namespace o2
{
double ctpRateFetcher::fetch(o2::ccdb::BasicCCDBManager* ccdb, uint64_t timeStamp, int runNumber, const std::string& sourceName, bool fCrashOnNull)
{
setupRun(runNumber, ccdb, timeStamp);
if (sourceName.find("ZNC") != std::string::npos) {
if (runNumber < 544448) {
return fetchCTPratesInputs(ccdb, timeStamp, runNumber, 25) / (sourceName.find("hadronic") != std::string::npos ? 28. : 1.);
} else {
return fetchCTPratesClasses(ccdb, timeStamp, runNumber, "C1ZNC-B-NOPF-CRU", 6) / (sourceName.find("hadronic") != std::string::npos ? 28. : 1.);
}
} else if (sourceName == "T0CE") {
return fetchCTPratesClasses(ccdb, timeStamp, runNumber, "CMTVXTCE-B-NOPF");
} else if (sourceName == "T0SC") {
return fetchCTPratesClasses(ccdb, timeStamp, runNumber, "CMTVXTSC-B-NOPF");
} else if (sourceName == "T0VTX") {
if (runNumber < 534202) {
return fetchCTPratesClasses(ccdb, timeStamp, runNumber, "minbias_TVX_L0", 3); // 2022
} else {
double_t ret = fetchCTPratesClasses(ccdb, timeStamp, runNumber, "CMTVX-B-NOPF");
if (ret < 0.) {
LOG(info) << "Trying different class";
ret = fetchCTPratesClasses(ccdb, timeStamp, runNumber, "CMTVX-NONE");
if ((ret < 0) && fCrashOnNull) {
LOG(fatal) << "None of the classes used for lumi found";
}
}
return ret;
}
}
LOG(error) << "CTP rate for " << sourceName << " not available";
return -1.;
}
double ctpRateFetcher::fetchCTPratesClasses(o2::ccdb::BasicCCDBManager* /*ccdb*/, uint64_t timeStamp, int /*runNumber*/, 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 -1.;
}
auto rate{mScalers->getRateGivenT(timeStamp * 1.e-3, classIndex, inputType, 1)};
return pileUpCorrection(rate.second);
}
double ctpRateFetcher::fetchCTPratesInputs(o2::ccdb::BasicCCDBManager* /*ccdb*/, uint64_t timeStamp, int /*runNumber*/, int input)
{
std::vector<ctp::CTPScalerRecordO2> recs = mScalers->getScalerRecordO2();
if (recs[0].scalersInps.size() == 48) {
return pileUpCorrection(mScalers->getRateGivenT(timeStamp * 1.e-3, input, 7, 1).second);
} else {
LOG(error) << "Inputs not available";
return -1.;
}
}
double ctpRateFetcher::pileUpCorrection(double triggerRate)
{
if (mLHCIFdata == nullptr) {
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)
{
if (runNumber == mRunNumber) {
return;
}
mRunNumber = runNumber;
LOG(debug) << "Setting up CTP scalers for run " << mRunNumber;
if (mManualCleanup) {
delete mConfig;
delete mScalers;
delete mLHCIFdata;
}
std::map<std::string, std::string> metadata;
mLHCIFdata = ccdb->getSpecific<parameters::GRPLHCIFData>("GLO/Config/GRPLHCIF", timeStamp, metadata);
if (mLHCIFdata == nullptr) {
LOG(fatal) << "GRPLHCIFData not in database, timestamp:" << timeStamp;
}
metadata["runNumber"] = std::to_string(mRunNumber);
mConfig = ccdb->getSpecific<ctp::CTPConfiguration>("CTP/Config/Config", timeStamp, metadata);
if (mConfig == nullptr) {
LOG(fatal) << "CTPRunConfig not in database, timestamp:" << timeStamp;
}
mScalers = ccdb->getSpecific<ctp::CTPRunScalers>("CTP/Calib/Scalers", timeStamp, metadata);
if (mScalers == nullptr) {
LOG(fatal) << "CTPRunScalers not in database, timestamp:" << timeStamp;
}
mScalers->convertRawToO2();
}
} // namespace o2