Project
Loading...
Searching...
No Matches
TPCVDriftTglCalibration.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
14#include "Framework/Logger.h"
15#include "MathUtils/fit.h"
17#include "CCDB/CcdbApi.h"
19#include <Math/SMatrix.h>
20#include <TH2F.h>
21
22namespace o2
23{
24namespace tpc
25{
26
29
32
33//_____________________________________________
35{
36 // Here we initialize the vector of our output objects
37 mVDPerSlot.clear();
38 mCCDBInfoPerSlot.clear();
39 return;
40}
41
42//_____________________________________________
44{
45 // Extract results for the single slot
46 const auto* cont = slot.getContainer();
47 const auto* h = cont->histo.get();
48 auto nx = h->getNBinsX(), ny = h->getNBinsY();
49 std::array<double, 3> parg;
51 double sS = 0, sX = 0, sY = 0, sXX = 0, sXY = 0;
52 int npval = 0;
53 for (auto ix = nx; ix--;) {
54 const auto sliceY = h->getSliceY(ix);
55 auto chi2 = o2::math_utils::fitGaus(ny, sliceY.data(), h->getYMin(), h->getYMax(), parg, &mat);
56 if (chi2 < -2) { // failed
57 continue;
58 }
59 double err2 = mat(1, 1);
60 if (err2 <= 0.f) {
61 continue;
62 }
63 double err2i = 1. / err2, xb = h->getBinXCenter(ix), xbw = xb * err2i, ybw = parg[1] * err2i;
64 sS += err2i;
65 sX += xbw;
66 sXX += xb * xbw;
67 sY += ybw;
68 sXY += xb * ybw;
69 npval++;
70 }
71 if (!mSaveHistosFile.empty()) {
72 TFile savf(mSaveHistosFile.c_str(), "update");
73 auto th2f = h->createTH2F(fmt::format("vdtgl{}_{}", slot.getTFStart(), slot.getTFEnd()));
74 th2f->Write();
75 LOGP(info, "Saved histo for slot {}-{} to {}", slot.getTFStart(), slot.getTFEnd(), mSaveHistosFile);
76 }
77 double det = sS * sXX - sX * sX;
78 if (!det || npval < 2) {
79 LOGP(alarm, "VDrift fit failed for slot {}<=TF<={} with {} entries: det={} npoints={}", slot.getTFStart(), slot.getTFEnd(), cont->entries, det, npval);
80 } else {
81 det = 1. / det;
82 double offs = (sXX * sY - sX * sXY) * det, slope = (sS * sXY - sX * sY) * det;
83 double offsErr = sXX * det, slopErr = sS * det;
84 offsErr = offsErr > 0. ? std::sqrt(offsErr) : 0.;
85 slopErr = slopErr > 0. ? std::sqrt(slopErr) : 0.;
86 float corrFact = 1. / (1. - slope);
87 float corrFactErr = corrFact * corrFact * slopErr;
88 auto& vd = mVDPerSlot.emplace_back(o2::tpc::VDriftCorrFact{slot.getStartTimeMS(),
89 slot.getEndTimeMS(),
90 std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count(),
91 corrFact,
92 corrFactErr,
93 float(cont->driftVFullMean),
94 cont->tOffsetRef, 0.f});
95 // at this stage the correction object is defined wrt average corrected drift used for the slot processing, we want to redefine it to run-constant reference vdrift
96 vd.normalize(cont->driftVRef);
97
98 auto clName = o2::utils::MemFileHelper::getClassName(mVDPerSlot.back());
99 auto flName = o2::ccdb::CcdbApi::generateFileName(clName);
100 std::map<std::string, std::string> md;
101 mCCDBInfoPerSlot.emplace_back("TPC/Calib/VDriftTgl", clName, flName, md,
102 vd.firstTime - 10 * o2::ccdb::CcdbObjectInfo::SECOND, vd.lastTime + o2::ccdb::CcdbObjectInfo::MONTH);
103 LOGP(info, "Finalize slot {}({})<=TF<={}({}) with {} entries | dTgl vs Tgl_ITS offset: {:.4f}+-{:.4f} Slope: {:.4f}+-{:.4f} -> Corr factor = {:.4f}+-{:.4f} wrt <VD>={:.4f} -> {:.4f} wrt {:.4f}",
104 slot.getTFStart(), slot.getStartTimeMS(), slot.getTFEnd(), slot.getEndTimeMS(), cont->entries, offs, offsErr, slope, slopErr, corrFact, corrFactErr, cont->driftVFullMean, vd.corrFact, vd.refVDrift);
105 }
106}
107
108//_____________________________________________
110{
111 auto& cont = getSlots();
112 auto& slot = front ? cont.emplace_front(tstart, tend) : cont.emplace_back(tstart, tend);
113 slot.setContainer(std::make_unique<TPCVDTglContainer>(mNBinsTgl, mMaxTgl, mNBinsDTgl, mMaxDTgl));
114 return slot;
115}
116
117} // namespace tpc
118} // end namespace o2
Utils and constants for calibration and related workflows.
Definition of the parameter class for the detector gas.
uint16_t slope
Definition RawData.h:1
Class for time synchronization of RawReader instances.
TFType getTFEnd() const
Definition TimeSlot.h:47
long getStartTimeMS() const
Definition TimeSlot.h:50
long getEndTimeMS() const
Definition TimeSlot.h:51
const Container * getContainer() const
Definition TimeSlot.h:53
TFType getTFStart() const
Definition TimeSlot.h:46
static std::string generateFileName(const std::string &inp)
Definition CcdbApi.cxx:798
static constexpr long MONTH
static constexpr long SECOND
Slot & emplaceNewSlot(bool front, TFType tstart, TFType tend) final
Double_t fitGaus(const size_t nBins, const T *arr, const T xMin, const T xMax, std::vector< T > &param)
Definition fit.h:231
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
static std::string getClassName(const T &obj)
get the class name of the object