Project
Loading...
Searching...
No Matches
HMPIDDCSProcessor.h
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
12#ifndef HMPIDDCSPROCESSOR_H
13#define HMPIDDCSPROCESSOR_H
14
15// HMPID Base
16#include "HMPIDBase/Geo.h"
17#include "HMPIDBase/Param.h"
18
19// Root classes:
20#include <TF1.h>
21#include <TF2.h>
22#include <TGraph.h>
23#include <TSystem.h>
24
25// miscallenous libraries
26#include <cmath>
27#include <deque>
28#include <gsl/gsl>
29#include <memory>
30#include <string>
31
32// O2 includes:
33#include "CCDB/CcdbApi.h"
34#include "CCDB/CcdbObjectInfo.h"
40#include "Framework/Logger.h"
41
47
48namespace o2::hmpid
49{
50
51using namespace std::literals;
52using TimeStampType = uint64_t;
53
55 bool isDpValid = false;
56 double dpVal = -999;
57};
58
60{
61
62 public:
63 HMPIDDCSProcessor() = default;
64 ~HMPIDDCSProcessor() = default;
65
66 // Process Datapoints:
67 // ====================================================================
68 // process span of DPs:
69 // process DPs, fetch IDs and call processIR or processHMPID
70 void init(const std::vector<DPID>& pids);
71
72 void process(const gsl::span<const DPCOM> dps);
73
74 // called from HMPIDDCSDataProcessorSpec,
75 // loops over all the arrays of DPCOM-vectors, and calls the relevant
76 // fill()-methods above
77 void finalize();
78
79 //===== help-functions
80 //================================================================================
81 void setStartValidity(long t)
82 {
83 mStartValidity = t;
84 if (mVerbose) {
85 LOGP(info, "mStartValidity {}", mStartValidity);
86 }
87 }
88
93
94 // ef : runindenpendent, only used for verifying fits
96 {
97 mEndValidity = t + 3 * o2::ccdb::CcdbObjectInfo::DAY; // ef : add some time for validity
98 if (mVerbose) {
99 LOGP(info, "mEndValidity {}", mStartValidity); // after startValidity
100 }
101 }
102
103 // ef : set end validity when Runstatus == STOP
105 {
106 mEndValidity = t;
107 if (mVerbose) {
108 LOGP(info, "mEndValidity {}", mStartValidity);
109 }
110 }
111
116
117 long getStartValidity() { return mStartValidity; }
118
119 void useVerboseMode() { mVerbose = true; }
120
121 // convert char in aliasString to int
122 int aliasStringToInt(const DPID& dpid, std::size_t startIndex);
123 int subStringToInt(std::string istr, std::size_t si);
124 uint64_t processFlags(const uint64_t flags, const char* pid);
125
126 //===== DCS-CCDB methods and members Used in
127 // HMPIDDCSDataProcessor===============================================================
128
129 CcdbObjectInfo& getccdbRefInfo() { return mccdbRefInfo; }
130 std::vector<TF1> getRefIndexObj() { return arNmean; }
131
132 CcdbObjectInfo& getHmpidChargeInfo() { return mccdbChargeInfo; }
133 std::vector<TF1>& getChargeCutObj() { return arQthre; }
135 {
136 arQthre.clear();
137 arNmean.clear();
138 }
139 // ==========================================================================================================
141 {
142 mPids.clear();
143 }
144
146 {
147 return mRunNumberFromGRP;
148 } // ef : just using the same as for emcal
149
151 {
152 mRunNumberFromGRP = rn;
153 } // ef : just using the same as for emcal
154
155 private:
156 void processTRANS(const DPCOM& dp);
157 void processHMPID(const DPCOM& dp);
158
159 // Fill entries of DPs==================================================
160 void fillChPressure(
161 const DPCOM& dpcom); // fill element[0-6] in chamber-pressure vector
162
163 void fillEnvPressure(const DPCOM& dpcom); // fill environment-pressure vector
164
165 // HV in each chamber_section = 7*3 --> will result in Q_thre
166 void fillHV(const DPCOM& dpcom); // fill element[0-20] in HV vector
167
168 // Temp in (T1) and out (T2), in each chamber_radiator = 7*3 :
169 void fillTempIn(const DPCOM& dpcom); // fill element[0-20] in tempIn vector
170 void fillTempOut(const DPCOM& dpcom); // fill element[0-20] in tempOut vector
171
172 // =====finalize DPs, after run is finished
173 // ==================================================================================
174 // functions return nullptr if there is no entry in the array of DPCOM-vectors at
175 // the given element
176 std::unique_ptr<TF1> finalizeEnvPressure();
177 std::unique_ptr<TF1> finalizeChPressure(int iCh);
178 std::unique_ptr<TF1> finalizeHv(int iCh, int iSec);
179 bool finalizeTempOut(int iCh, int iRad);
180 bool finalizeTempIn(int iCh, int iRad);
181
182 //===== procTrans
183 //===================================================================================================
184 // ef: just return the value insted of using the function call
185 // logging of problems is instead done where they occur
186 /*
187 double defaultEMean(); // just set a refractive index for C6F14 at ephot=6.675
188 // eV @ T=25 C
189 */
190
191 double procTrans();
192
193 // ef: could pass everything here as const-ref, but everything is done at EOR,
194 // so maybe not so
195 bool evalCorrFactor(const double& dRefArgon, const double& dCellArgon, const double& dRefFreon,
196 const double& dCellFreon, const double& dPhotEn, const int& i);
197 TransparencyDpInfo dpVector2Double(const std::vector<DPCOM>& dpVec, const char* dpString, int i);
198 double calculatePhotonEnergy(int i);
199
200 // get methods for time-ranges
201 // ===============================================================================
202 // const auto& getTimeQThresh() const { return mTimeQThresh; }
203 // const auto& getTimeArNmean() const { return mTimeArNmean; }
204
207 TimeStampType getMinTime(const std::vector<DPCOM>& dps)
208 {
209 TimeStampType firstTime = std::numeric_limits<uint64_t>::max();
210 for (const auto& dp : dps) {
211 const auto time = dp.data.get_epoch_time();
212 firstTime = std::min(firstTime, time);
213 }
214 return firstTime;
215 }
216
217 // return timestamp of last fetched datapoint for a given ID (Tin/Tout,
218 // Environment pressure, HV, chamber pressure)
219 TimeStampType getMaxTime(const std::vector<DPCOM>& dps)
220 {
221 TimeStampType lastTime = 0;
222 for (const auto& dp : dps) {
223
224 // check if tme of DP is greater (i.e. later) than previously latest
225 // fetched DP:
226 const auto time = dp.data.get_epoch_time();
227 lastTime = std::max(lastTime, time);
228 }
229 return lastTime;
230 }
231
232 struct TimeRange {
233 uint64_t first = std::numeric_limits<uint64_t>::max();
234 uint64_t last = std::numeric_limits<uint64_t>::min();
235 };
236
237 const UInt_t kDefault = BIT(14);
238 bool isDefault(const TF1* f) const { return f->TestBit(kDefault); }
239 void setDefault(TF1* f, bool v) { f->SetBit(kDefault, v); }
240 // ef: set flag in invalid object, such that it can be read on receiving
241 // side (Ckov reconstruction) as invalid and thus use default value
242
243 std::unordered_map<DPID, bool> mPids;
244
245 int mRunNumberFromGRP = -2; // ef : just using the same as for emcal
246
247 // ======= DCS-CCDB
248 // ==========================================================================================
249
250 long mFirstTime; // time when a CCDB object was stored first
251 long mStartValidity = o2::ccdb::CcdbObjectInfo::INFINITE_TIMESTAMP; // TF index for processing, used to store CCDB object
253 long mStart = 0; // TF index for processing, used to store CCDB object
254 bool mFirstTimeSet = false;
255
256 bool mVerbose = false;
257
258 CcdbObjectInfo mccdbRefInfo;
259 CcdbObjectInfo mccdbChargeInfo;
260
261 // objects to be stored in CCDB:
262 // refractive index:
263 std::vector<TF1> arNmean; // 43 21* Tin and 21*Tout (1 per radiator, 3
264 // radiators per chambers)
265 // + 1 for ePhotMean (mean photon energy)
266 // Charge Threshold:
267 std::vector<TF1> arQthre; // 42 Qthre=f(time) one per sector
268
269 //======= finalize() and fill() private variables
270 //============================================================
271 double xP, yP;
272
273 // env pressure
274 int cntEnvPressure = 0; // cnt Environment-pressure entries
275 std::vector<DPCOM> dpVecEnv; // environment-pressure vector
276
277 // ch pressure
278 int cntChPressure = 0; // cnt chamber-pressure entries in element iCh[0..6]
279 std::vector<DPCOM> dpVecCh[7]; // chamber-pressure vector [0..6]
280 std::unique_ptr<TF1[]> pArrCh = std::unique_ptr<TF1[]>(new TF1[7]);
281
282 // Temperature
283 int cntTin = 0,
284 cntTOut =
285 0; // cnt tempereature entries in element i[0..20]; i = 3*iCh+iSec
286 std::vector<DPCOM> dpVecTempIn[21]; // tempIn vector [0..20]
287 std::vector<DPCOM> dpVecTempOut[21]; // tempOut vector [0..20]
288
289 // HV
290 int cntHV = 0; // cnt HV entries in element i[0..41]; i = iCh*6 + iSec
291 std::vector<DPCOM> dpVecHV[42]; // HV vector [0..41]; 7 chambers * 6 sectors
292 std::unique_ptr<TF1[]> pArrHv = std::unique_ptr<TF1[]>(new TF1[24]);
293
294 // procTrans variables
295 // ======================================================================
296 static constexpr double eMeanDefault = 6.675; // Default mean photon energy if
297 // DP is invalid or not fetched
298
299 double sEnergProb = 0, sProb = 0; // energy probaility, probability
300 double eMean = 0; // initialize eMean (Photon energy mean) to 0
301
302 static constexpr double aCorrFactor[30] = {
303 0.937575212, 0.93805688, 0.938527113, 0.938986068, 0.939433897,
304 0.939870746, 0.940296755, 0.94071206, 0.941116795, 0.941511085,
305 0.941895054, 0.942268821, 0.942632502, 0.942986208, 0.943330047,
306 0.943664126, 0.943988544, 0.944303401, 0.944608794, 0.944904814,
307 0.945191552, 0.945469097, 0.945737533, 0.945996945, 0.946247412,
308 0.946489015, 0.94672183, 0.946945933, 0.947161396, 0.947368291};
309
310 // ef: hardcoded default wavelengths
311 static constexpr double arrWaveLenDefault[30] = {
312 162, 164, 166, 168, 170, 172, 174, 176, 178, 180,
313 182, 184, 186, 188, 190, 192, 194, 196, 198, 200,
314 202, 204, 206, 208, 210, 212, 214, 216, 218, 220};
315
316 static constexpr double nm2eV = 1239.842609; // 1239.842609 from nm to eV
317 double photEn; // photon energy
318
319 // wavelength
320 double lambda;
321 std::vector<DPCOM> waveLenVec[30];
322
323 // phototube current for argon reference
324 double refArgon;
325 std::vector<DPCOM> argonRefVec[30];
326
327 // phototube current for freon reference
328 double refFreon;
329 std::vector<DPCOM> freonRefVec[30];
330
331 // phototube current for argon cell
332 double cellArgon;
333 std::vector<DPCOM> argonCellVec[30];
334
335 // phototube current for freon cell
336 double cellFreon;
337 std::vector<DPCOM> freonCellVec[30];
338
339 static constexpr double aConvFactor = 1.0 - 0.3 / 1.8;
340 double aTransRad; // evaluate 15 mm of thickness C6F14 Trans
341 double aTransSiO2; // evaluate 0.5 mm of thickness SiO2 Trans
342 double aTransGap; // evaluate 80 cm of thickness Gap (low density CH4)
343 // transparency
344 double aCsIQE; // evaluate CsI quantum efficiency
345 double aTotConvolution; // evaluate total convolution of all material optical
346 // properties
347
348 // indexes for getting chamber-numbers etc
349 // =======================================================================================
350
351 // Chamber Pressures
352 static constexpr std::size_t indexChPr = 7;
353
354 // High Voltage
355 static constexpr std::size_t indexChHv = 7;
356 static constexpr std::size_t indexSecHv = 13;
357
358 // Temperatures
359 static constexpr std::size_t indexChTemp = 7;
360 static constexpr std::size_t indexRadTemp = 22;
361
362 // Timestamps and TimeRanges
363 // ======================================================================================
364 // timestamps of last and first entry in vectors of DPCOMs
365 uint64_t hvFirstTime, hvLastTime;
366 uint64_t chPrFirstTime, chPrLastTime;
367 uint64_t envPrFirstTime, envPrLastTime;
368
369 uint64_t timeTinFirst, timeTinLast;
370 uint64_t timeToutFirst, timeToutLast;
371
372 TimeRange mTimeEMean; // Timerange for mean photon energy(procTrans)
373
374 //======= constExpression string-literals to assign DPs to the correct method:
375 //====================================================
376
377 // check if Transparency or other HMPID specifciation
378 static constexpr auto HMPID_ID{"HMP_"sv};
379 static constexpr auto TRANS_ID{"HMP_TRANPLANT_MEASURE_"sv};
380 // HMPID-temp, HV, pressure IDs (HMP_{"HMP_"sv};)
381 static constexpr auto TEMP_OUT_ID{"OUT_TEMP"sv};
382 static constexpr auto TEMP_IN_ID{"_IN_TEMP"sv};
383 static constexpr auto HV_ID{"_HV_VMON"sv};
384 static constexpr auto ENV_PRESS_ID{"ENV_PENV"sv};
385 static constexpr auto CH_PRESS_ID{"AS_PMWPC"sv};
386
387 // HMPID-IR IDs (TRANS_ID{"HMP_TRANPLANT_MEASURE_"sv})
388 static constexpr auto WAVE_LEN_ID{"WAVELENGHT"sv}; // 0-9
389 static constexpr auto REF_ID{"REFERENCE"sv}; // argonReference and freonRef
390 static constexpr auto ARGON_CELL_ID{"ARGONCELL"sv}; // argon Cell reference
391 static constexpr auto FREON_CELL_ID{"C6F14CELL"sv}; // fron Cell Reference
392
393 static constexpr auto ARGON_REF_ID{"ARGONREFERENCE"sv}; // argonReference
394 static constexpr auto FREON_REF_ID{"C6F14REFERENCE"sv}; // freonReference
395
396 ClassDefNV(HMPIDDCSProcessor, 0);
397}; // end class
398} // namespace o2::hmpid
399#endif
Utils and constants for calibration and related workflows.
int16_t time
Definition RawEventData.h:4
int32_t i
static constexpr long DAY
static constexpr long INFINITE_TIMESTAMP
void init(const std::vector< DPID > &pids)
int aliasStringToInt(const DPID &dpid, std::size_t startIndex)
int subStringToInt(std::string istr, std::size_t si)
std::vector< TF1 > & getChargeCutObj()
CcdbObjectInfo & getHmpidChargeInfo()
std::vector< TF1 > getRefIndexObj()
uint64_t processFlags(const uint64_t flags, const char *pid)
const GLdouble * v
Definition glcorearb.h:832
GLdouble f
Definition glcorearb.h:310
GLbitfield flags
Definition glcorearb.h:1570
uint64_t TimeStampType