Project
Loading...
Searching...
No Matches
PressureTemperatureHelper.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
15
17#include "TPCBase/CDBTypes.h"
19#include "DataFormatsTPC/DCS.h"
23
24using namespace o2::tpc;
25using namespace o2::framework;
26
28{
29 pc.inputs().get<dcs::Pressure*>("pressure");
30 pc.inputs().get<dcs::Temperature*>("temperature");
31}
32
34{
35 if (matcher == ConcreteDataMatcher(o2::header::gDataOriginTPC, "PRESSURECCDB", 0)) {
36 LOGP(info, "Updating pressure");
37 const auto& pressure = ((dcs::Pressure*)obj);
38 mPressure.second = pressure->robustPressure.time;
39 mPressure.first = pressure->robustPressure.robustPressure;
40 return true;
41 }
42
43 if (matcher == ConcreteDataMatcher(o2::header::gDataOriginTPC, "TEMPERATURECCDB", 0)) {
44 LOGP(info, "Updating temperature");
45 auto temp = *(dcs::Temperature*)obj;
46 temp.fitTemperature(o2::tpc::Side::A, mFitIntervalMS, false);
47 temp.fitTemperature(o2::tpc::Side::C, mFitIntervalMS, false);
48
49 mTemperatureA.first.clear();
50 mTemperatureC.first.clear();
51 mTemperatureA.second.clear();
52 mTemperatureC.second.clear();
53
54 for (const auto& dp : temp.statsA.data) {
55 mTemperatureA.first.emplace_back(toKelvin(dp.value.mean));
56 mTemperatureA.second.emplace_back(dp.time);
57 }
58
59 for (const auto& dp : temp.statsC.data) {
60 mTemperatureC.first.emplace_back(toKelvin(dp.value.mean));
61 mTemperatureC.second.emplace_back(dp.time);
62 }
63
64 // check if temperature data is available
65 if (mTemperatureA.first.empty() && mTemperatureC.first.empty()) {
66 float temperature = toKelvin(temp.getMeanTempRaw());
67 mTemperatureA.first.emplace_back(temperature);
68 mTemperatureA.second.emplace_back(0);
69 mTemperatureC.first.emplace_back(temperature);
70 mTemperatureC.second.emplace_back(0);
71 LOGP(warning, "No temperature data available from fit. Using average temperature {} K", temperature);
72 }
73
74 return true;
75 }
76 return false;
77}
78
79void PressureTemperatureHelper::requestCCDBInputs(std::vector<InputSpec>& inputs)
80{
81 addInput(inputs, {"pressure", o2::header::gDataOriginTPC, "PRESSURECCDB", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalPressure), {}, 1)});
82 addInput(inputs, {"temperature", o2::header::gDataOriginTPC, "TEMPERATURECCDB", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalTemperature), {}, 1)});
83}
84
85void PressureTemperatureHelper::addInput(std::vector<InputSpec>& inputs, InputSpec&& isp)
86{
87 if (std::find(inputs.begin(), inputs.end(), isp) == inputs.end()) {
88 inputs.emplace_back(isp);
89 }
90}
91
97
98void PressureTemperatureHelper::addOutput(std::vector<OutputSpec>& outputs, OutputSpec&& osp)
99{
100 if (std::find(outputs.begin(), outputs.end(), osp) == outputs.end()) {
101 outputs.emplace_back(osp);
102 }
103}
104
105float PressureTemperatureHelper::interpolate(const std::vector<ULong64_t>& timestamps, const std::vector<float>& values, ULong64_t timestamp) const
106{
107 if (auto idxClosest = o2::math_utils::findClosestIndices(timestamps, timestamp)) {
108 auto [idxLeft, idxRight] = *idxClosest;
109 if (idxRight > idxLeft) {
110 const auto x0 = timestamps[idxLeft];
111 const auto x1 = timestamps[idxRight];
112 const float y0 = values[idxLeft];
113 const float y1 = values[idxRight];
114 const float y = (y0 * (x1 - timestamp) + y1 * (timestamp - x0)) / (x1 - x0);
115 return y;
116 } else {
117 return values[idxLeft];
118 }
119 }
120 return 0; // this should never happen
121}
122
124{
125 const float pressure = getPressure(timestamp);
126 const auto temp = getTemperature(timestamp);
127 LOGP(info, "Sending pressure {}, temperature A {} and temperature C {} for timestamp {}", pressure, temp.first, temp.second, timestamp);
130}
131
132float PressureTemperatureHelper::getTP(int64_t ts) const
133{
134 const float pressure = getPressure(ts);
135 const auto temp = getMeanTemperature(ts);
136 if (pressure <= 0) {
137 LOGP(error, "Pressure {} is zero or negative, cannot compute T/P ratio for timestamp {}", pressure, ts);
138 return 0;
139 }
140 const float tp = temp / pressure;
141 return tp;
142}
143
144float PressureTemperatureHelper::getMeanTemperature(const ULong64_t timestamp) const
145{
146 const auto temp = getTemperature(timestamp);
147
148 float sumT = 0;
149 int w = 0;
150 constexpr float minTemp = toKelvin(15);
151 constexpr float maxTemp = toKelvin(25);
152 if (auto t = temp.first; t > minTemp && t < maxTemp) {
153 sumT += t;
154 ++w;
155 }
156 if (auto t = temp.second; t > minTemp && t < maxTemp) {
157 sumT += t;
158 ++w;
159 }
160
161 if (w == 0) {
162 constexpr float defaultTemp = toKelvin(19.6440f);
163 LOGP(info, "Returning default temperature of {}K", defaultTemp);
164 return defaultTemp;
165 }
166
167 const float meanT = sumT / w;
168 return meanT;
169}
170
171std::pair<ULong64_t, ULong64_t> PressureTemperatureHelper::getMinMaxTime() const
172{
173 ULong64_t minTime = std::numeric_limits<ULong64_t>::max();
174 ULong64_t maxTime = 0;
175
176 if (!mPressure.first.empty()) {
177 minTime = std::min(minTime, mPressure.second.front());
178 maxTime = std::max(maxTime, mPressure.second.back());
179 }
180 if (!mTemperatureA.first.empty()) {
181 minTime = std::min(minTime, mTemperatureA.second.front());
182 maxTime = std::max(maxTime, mTemperatureA.second.back());
183 }
184 if (!mTemperatureC.first.empty()) {
185 minTime = std::min(minTime, mTemperatureC.second.front());
186 maxTime = std::max(maxTime, mTemperatureC.second.back());
187 }
188
189 return {minTime, maxTime};
190}
CDB Type definitions for TPC.
DCS data point data formats.
Helper class to extract pressure and temperature.
void snapshot(const Output &spec, T const &object)
decltype(auto) get(R binding, int part=0) const
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
InputRecord & inputs()
The inputs associated with this processing context.
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs)
float getPressure(const ULong64_t timestamp) const
get pressure for given time stamp in ms
void extractCCDBInputs(o2::framework::ProcessingContext &pc) const
trigger checking for CCDB objects
std::pair< ULong64_t, ULong64_t > getMinMaxTime() const
get minimum and maximum time stamps of the pressure and temperature data
static constexpr o2::header::DataDescription getDataDescriptionTemperature()
dataformats::Pair< float, float > getTemperature(const ULong64_t timestamp) const
get temperature for given time stamp in ms
static void addOutput(std::vector< o2::framework::OutputSpec > &outputs, o2::framework::OutputSpec &&osp)
std::pair< std::vector< float >, std::vector< ULong64_t > > mTemperatureA
temperature values A-side
void sendPTForTS(o2::framework::ProcessingContext &pc, const ULong64_t timestamp) const
send temperature and pressure for given time stamp
int mFitIntervalMS
fit interval for the temperature
float getMeanTemperature(const ULong64_t timestamp) const
get mean temperature over A and C side
std::pair< std::vector< float >, std::vector< ULong64_t > > mPressure
pressure values for both measurements
static constexpr o2::header::DataDescription getDataDescriptionPressure()
static void addInput(std::vector< o2::framework::InputSpec > &inputs, o2::framework::InputSpec &&isp)
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
check for new CCDB objects
static constexpr float toKelvin(float celsius)
std::pair< std::vector< float >, std::vector< ULong64_t > > mTemperatureC
temperature values C-side
static void setOutputs(std::vector< o2::framework::OutputSpec > &outputs)
define outputs in case pressure and temperature will be send
float interpolate(const std::vector< ULong64_t > &timestamps, const std::vector< float > &values, ULong64_t timestamp) const
interpolate input values for given timestamp
GLuint GLfloat GLfloat GLfloat GLfloat y1
Definition glcorearb.h:5034
GLuint GLfloat GLfloat GLfloat x1
Definition glcorearb.h:5034
GLint y
Definition glcorearb.h:270
GLenum GLsizei GLsizei GLint * values
Definition glcorearb.h:1576
GLuint GLfloat x0
Definition glcorearb.h:5034
GLubyte GLubyte GLubyte GLubyte w
Definition glcorearb.h:852
GLuint GLfloat GLfloat y0
Definition glcorearb.h:5034
constexpr o2::header::DataOrigin gDataOriginTPC
Definition DataHeader.h:576
Defining PrimaryVertex explicitly as messageable.
Definition TFIDInfo.h:20
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::optional< std::pair< size_t, size_t > > findClosestIndices(const std::vector< DataTimeType > &timestamps, DataTime timestamp)
Definition fit.h:796
Global TPC definitions and constants.
Definition SimTraits.h:167
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
Definition CDBTypes.h:96
@ A
Definition Defs.h:35
@ C
Definition Defs.h:36
@ CalPressure
DCS pressure measurements.
@ CalTemperature
DCS temperature measurements.