Skip to content

Commit 9b8fb23

Browse files
TPC: Add scaling of VDrift with T/P (#14602)
* TPC: Add scaling of VDrift with T/P - scaling of the VDrift is automatically enabled - the reference T/P is extracted for VDrift objects without stored T/P if firstTime and lastTime of VDrift object is in the range +-20 minutes of available temperature and pressure - scaling with T/P can be disabled by setting 'TPCGasParam.Temperature=0;TPCGasParam.Pressure=0' - reference T/P is extracted automatically for online created VDrift with ITSTgl and laser method - add storing of temperature. pressure and used VDrift in timeseries * VDrift: Keep refVDrift constant by changing corrFact with T/P
1 parent d84a22c commit 9b8fb23

File tree

15 files changed

+287
-45
lines changed

15 files changed

+287
-45
lines changed

DataFormats/Detectors/TPC/include/DataFormatsTPC/LtrCalibData.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ struct LtrCalibData {
4242
std::vector<uint16_t> matchedLtrIDs; ///< matched laser track IDs
4343
std::vector<uint16_t> nTrackTF; ///< number of laser tracks per TF
4444
std::vector<float> dEdx; ///< dE/dx of each track
45+
float tp{0.f}; ///< temperature over pressure ratio
4546

4647
bool isValid() const
4748
{
@@ -138,7 +139,7 @@ struct LtrCalibData {
138139
dEdx.clear();
139140
}
140141

141-
ClassDefNV(LtrCalibData, 4);
142+
ClassDefNV(LtrCalibData, 5);
142143
};
143144

144145
} // namespace o2::tpc

DataFormats/Detectors/TPC/include/DataFormatsTPC/VDriftCorrFact.h

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,27 +26,35 @@ namespace o2::tpc
2626
{
2727

2828
struct VDriftCorrFact {
29-
long firstTime{}; ///< first time stamp of processed TFs
30-
long lastTime{}; ///< last time stamp of processed TFs
31-
long creationTime{}; ///< time of creation
32-
float corrFact{1.0}; ///< drift velocity correction factor (multiplicative)
33-
float corrFactErr{0.0}; ///< stat error of correction factor
34-
float refVDrift{0.}; ///< reference vdrift for which factor was extracted
29+
long firstTime{}; ///< first time stamp of processed TFs
30+
long lastTime{}; ///< last time stamp of processed TFs
31+
long creationTime{}; ///< time of creation
32+
float corrFact{1.0}; ///< drift velocity correction factor (multiplicative)
33+
float corrFactErr{0.0}; ///< stat error of correction factor
34+
float refVDrift{0.}; ///< reference vdrift for which factor was extracted
3535
float refTimeOffset{0.}; ///< additive time offset reference (\mus)
3636
float timeOffsetCorr{0.}; ///< additive time offset correction (\mus)
37+
float refTP{0.}; ///< reference temperature / pressure for which refVDrift was extracted
3738

3839
float getVDrift() const { return refVDrift * corrFact; }
3940
float getVDriftError() const { return refVDrift * corrFactErr; }
4041

4142
float getTimeOffset() const { return refTimeOffset + timeOffsetCorr; }
4243

4344
// renormalize VDrift reference and correction either to provided new reference (if >0) or to correction 1 wrt current reference
44-
void normalize(float newVRef = 0.f)
45+
void normalize(float newVRef = 0.f, float tp = 0.f)
4546
{
47+
float normVDrift = newVRef;
4648
if (newVRef == 0.f) {
47-
newVRef = refVDrift * corrFact;
49+
normVDrift = refVDrift * corrFact;
50+
newVRef = normVDrift;
51+
if ((tp > 0) && (refTP > 0)) {
52+
// linear scaling based on relative change of T/P
53+
normVDrift *= refTP / tp;
54+
refTP = tp; // update reference T/P
55+
}
4856
}
49-
float fact = refVDrift / newVRef;
57+
float fact = refVDrift / normVDrift;
5058
refVDrift = newVRef;
5159
corrFactErr *= fact;
5260
corrFact *= fact;
@@ -66,7 +74,7 @@ struct VDriftCorrFact {
6674
}
6775
}
6876

69-
ClassDefNV(VDriftCorrFact, 2);
77+
ClassDefNV(VDriftCorrFact, 3);
7078
};
7179

7280
} // namespace o2::tpc

Detectors/Calibration/include/DetectorsCalibration/IntegratedClusterCalibrator.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,9 @@ struct TimeSeriesdEdx {
331331
};
332332

333333
struct TimeSeriesITSTPC {
334+
float mVDrift = 0; ///< drift velocity in cm/us
335+
float mPressure = 0; ///< pressure
336+
float mTemperature = 0; ///< temperature
334337
TimeSeries mTSTPC; ///< TPC standalone DCAs
335338
TimeSeries mTSITSTPC; ///< ITS-TPC standalone DCAs
336339
ITSTPC_Matching mITSTPCAll; ///< ITS-TPC matching efficiency for ITS standalone + afterburner
@@ -499,7 +502,7 @@ struct TimeSeriesITSTPC {
499502
nVertexContributors_Quantiles.resize(nTotalQ);
500503
}
501504

502-
ClassDefNV(TimeSeriesITSTPC, 5);
505+
ClassDefNV(TimeSeriesITSTPC, 6);
503506
};
504507

505508
} // end namespace tpc

Detectors/GlobalTracking/src/MatchTPCITS.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void MatchTPCITS::run(const o2::globaltracking::RecoContainer& inp,
101101
break;
102102
}
103103
if (mVDriftCalibOn) { // in the beginning of the output vector we send the full and reference VDrift used for this TF
104-
calib.emplace_back(mTPCVDrift, mTPCDrift.refVDrift, -999.);
104+
calib.emplace_back(mTPCVDrift, mTPCDrift.refVDrift, mTPCDrift.refTP);
105105
calib.emplace_back(mTPCDriftTimeOffset, mTPCDrift.refTimeOffset, -999.);
106106
}
107107

Detectors/TPC/calibration/include/TPCCalibration/CalibLaserTracks.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include <gsl/span>
2626
#include <string_view>
2727

28-
#include "CommonConstants/MathConstants.h"
2928
#include "CommonUtils/TreeStreamRedirector.h"
3029
#include "DataFormatsTPC/TrackTPC.h"
3130
#include "DataFormatsTPC/LaserTrack.h"
@@ -74,10 +73,12 @@ class CalibLaserTracks
7473
~CalibLaserTracks() = default;
7574

7675
/// process all tracks of one TF
77-
void fill(const gsl::span<const TrackTPC> tracks);
76+
/// \param tp ratio of temperature over pressure
77+
void fill(const gsl::span<const TrackTPC> tracks, float tp = 0);
7878

7979
/// process all tracks of one TF
80-
void fill(std::vector<TrackTPC> const& tracks);
80+
/// \param tp ratio of temperature over pressure
81+
void fill(std::vector<TrackTPC> const& tracks, float tp = 0);
8182

8283
/// process single track
8384
void processTrack(const TrackTPC& track);
@@ -163,6 +164,8 @@ class CalibLaserTracks
163164
float mDriftV{0}; ///< drift velocity used during reconstruction
164165
float mTOffsetMUS{0}; ///< time offset in \mus to impose
165166
float mZbinWidth{0}; ///< width of a bin in us
167+
float mAvgTP{0}; ///< ratio of average temperature over pressure
168+
float mAvgDriftV{0}; ///< average drift velocity used for the laser track calibration
166169
uint64_t mTFstart{0}; ///< start time of processed time frames
167170
uint64_t mTFend{0}; ///< end time of processed time frames
168171
LtrCalibData mCalibDataTF{}; ///< calibration data for single TF (debugging)
@@ -184,7 +187,7 @@ class CalibLaserTracks
184187
/// perform fits on the matched z-position pairs to extract the drift velocity correction factor and trigger offset
185188
void fillCalibData(LtrCalibData& calibData, const std::vector<TimePair>& pairsA, const std::vector<TimePair>& pairsC);
186189

187-
ClassDefNV(CalibLaserTracks, 1);
190+
ClassDefNV(CalibLaserTracks, 2);
188191
};
189192

190193
} // namespace o2::tpc

Detectors/TPC/calibration/include/TPCCalibration/PressureTemperatureHelper.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,35 @@ class PressureTemperatureHelper
6363
/// get pressure for given time stamp in ms
6464
float getPressure(const ULong64_t timestamp) const { return interpolate(mPressure.second, mPressure.first, timestamp); }
6565

66+
/// manually set the pressure
67+
void setPressure(const std::pair<std::vector<float>, std::vector<ULong64_t>>& pressure) { mPressure = pressure; }
68+
69+
/// manually set the temperature
70+
void setTemperature(const std::pair<std::vector<float>, std::vector<ULong64_t>>& temperatureA, const std::pair<std::vector<float>, std::vector<ULong64_t>>& temperatureC)
71+
{
72+
mTemperatureA = temperatureA;
73+
mTemperatureC = temperatureC;
74+
}
75+
6676
/// get temperature for given time stamp in ms
6777
dataformats::Pair<float, float> getTemperature(const ULong64_t timestamp) const { return dataformats::Pair<float, float>{interpolate(mTemperatureA.second, mTemperatureA.first, timestamp), interpolate(mTemperatureC.second, mTemperatureC.first, timestamp)}; }
6878

79+
/// get mean temperature over A and C side
80+
float getMeanTemperature(const ULong64_t timestamp) const;
81+
82+
// get ratio of temperature over pressure for given time stamp
83+
float getTP(int64_t ts) const;
84+
6985
static constexpr o2::header::DataDescription getDataDescriptionPressure() { return o2::header::DataDescription{"pressure"}; }
7086
static constexpr o2::header::DataDescription getDataDescriptionTemperature() { return o2::header::DataDescription{"temperature"}; }
7187

88+
/// get minimum and maximum time stamps of the pressure and temperature data
89+
std::pair<ULong64_t, ULong64_t> getMinMaxTime() const;
90+
7291
protected:
7392
static void addInput(std::vector<o2::framework::InputSpec>& inputs, o2::framework::InputSpec&& isp);
7493
static void addOutput(std::vector<o2::framework::OutputSpec>& outputs, o2::framework::OutputSpec&& osp);
94+
static constexpr float toKelvin(float celsius) { return celsius + 273.15f; } // convert Celsius to Kelvin
7595

7696
std::pair<std::vector<float>, std::vector<ULong64_t>> mPressure; ///< pressure values for both measurements
7797
std::pair<std::vector<float>, std::vector<ULong64_t>> mTemperatureA; ///< temperature values A-side

Detectors/TPC/calibration/include/TPCCalibration/TPCVDriftTglCalibration.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct TPCVDTglContainer {
3232
double driftVFullMean = 0.;
3333
static float tOffsetRef;
3434
static float driftVRef;
35+
float tp = 0;
3536

3637
TPCVDTglContainer(int ntgl, float tglMax, int ndtgl, float dtglMax)
3738
{
@@ -42,9 +43,12 @@ struct TPCVDTglContainer {
4243
{
4344
histo = std::make_unique<o2::dataformats::FlatHisto2D_f>(*(src.histo.get()));
4445
entries = src.entries;
46+
tp = src.tp;
47+
driftVFullMean = src.driftVFullMean;
4548
}
4649

47-
void fill(const gsl::span<const o2::dataformats::Triplet<float, float, float>> data)
50+
/// \param tp ratio of temperature over pressure
51+
void fill(const gsl::span<const o2::dataformats::Triplet<float, float, float>> data, float currentTemperaturePressure = 0)
4852
{
4953
if (data.size() < 3) { // first 2 entres always contains the {full and reference VDrift} and {full and reference DriftTimeOffset} used for the TF
5054
return;
@@ -59,12 +63,14 @@ struct TPCVDTglContainer {
5963
}
6064
//
6165
float vfull = data[0].first, vref = data[0].second;
66+
const float temperaturePressure = (data[0].third == 0) ? currentTemperaturePressure : data[0].third;
6267
if (driftVRef == 0.f) {
6368
driftVRef = vref;
6469
} else if (driftVRef != vref) {
6570
LOGP(warn, "data with VDriftRef={} were received while initially was set to {}, keep old one", vref, driftVRef);
6671
}
6772
driftVFullMean = (driftVFullMean * nTFProc + vfull) / (nTFProc + 1);
73+
tp = (tp * nTFProc + temperaturePressure) / (nTFProc + 1);
6874
if (tOffsetRef == 0.f) {
6975
tOffsetRef = data[1].first; // assign 1st full toffset as a reference
7076
}
@@ -73,6 +79,11 @@ struct TPCVDTglContainer {
7379

7480
void merge(const TPCVDTglContainer* other)
7581
{
82+
const int norm = nTFProc + other->nTFProc;
83+
if (norm > 0) {
84+
tp = (tp * nTFProc + other->tp * other->nTFProc) / norm;
85+
driftVFullMean = (driftVFullMean * nTFProc + other->driftVFullMean * other->nTFProc) / norm;
86+
}
7687
entries += other->entries;
7788
histo->add(*(other->histo));
7889
LOGP(debug, "Old entries:{} New entries:{} oldSum: {} newSum: {}", other->entries, entries, other->histo->getSum(), histo->getSum());
@@ -82,7 +93,7 @@ struct TPCVDTglContainer {
8293
{
8394
LOG(info) << "Nentries = " << entries;
8495
}
85-
ClassDefNV(TPCVDTglContainer, 1);
96+
ClassDefNV(TPCVDTglContainer, 2);
8697
};
8798

8899
class TPCVDriftTglCalibration : public o2::calibration::TimeSlotCalibration<TPCVDTglContainer>

Detectors/TPC/calibration/include/TPCCalibration/VDriftHelper.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "GPUCommonRtypes.h"
2020
#include "DataFormatsTPC/VDriftCorrFact.h"
21+
#include "TPCCalibration/PressureTemperatureHelper.h"
2122
#include <array>
2223
#include <vector>
2324
#include <string_view>
@@ -56,23 +57,28 @@ class VDriftHelper
5657
Source getSource() const { return mSource; }
5758
static std::string_view getSourceName(Source s) { return SourceNames[s]; }
5859
std::string_view getSourceName() const { return SourceNames[mSource]; }
60+
const auto& getPTHelper() const { return mPTHelper; }
5961

6062
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher& matcher, void* obj);
6163
void extractCCDBInputs(o2::framework::ProcessingContext& pc, bool laser = true, bool itstpcTgl = true);
6264
static void requestCCDBInputs(std::vector<o2::framework::InputSpec>& inputs, bool laser = true, bool itstpcTgl = true);
6365

6466
protected:
6567
static void addInput(std::vector<o2::framework::InputSpec>& inputs, o2::framework::InputSpec&& isp);
68+
bool extractTPForVDrift(VDriftCorrFact& vdrift, int64_t tsStepMS = 100 * 1000);
6669
VDriftCorrFact mVDLaser{};
6770
VDriftCorrFact mVDTPCITSTgl{};
6871
VDriftCorrFact mVD{};
69-
Source mSource{Source::Param}; // update source
70-
bool mUpdated = false; // signal update, must be reset once new value is fetched
72+
Source mSource{Source::Param}; // update source
73+
bool mUpdated = false; // signal update, must be reset once new value is fetched
74+
bool mIsTPScalingPossible = false; // if T/P scaling is possible always perform the updating
7175
bool mForceParamDrift = false; // enforce vdrift from gasParam
7276
bool mForceParamOffset = false; // enforce offset from DetectorParam
77+
bool mForceTPScaling = false; // enforce T/P scaling from gasParam (scaling disabled by negative T or P)
7378
uint32_t mMayRenormSrc = 0xffffffff; // if starting VDrift correction != 1, we will renorm reference in such a way that initial correction is 1.0, flag per source
79+
PressureTemperatureHelper mPTHelper; // helper to extract pressure and temperature from CCDB
7480

75-
ClassDefNV(VDriftHelper, 1);
81+
ClassDefNV(VDriftHelper, 2);
7682
};
7783
} // namespace o2::tpc
7884
#endif

Detectors/TPC/calibration/src/CalibLaserTracks.cxx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
#include <string_view>
2525

2626
using namespace o2::tpc;
27-
void CalibLaserTracks::fill(std::vector<TrackTPC> const& tracks)
27+
void CalibLaserTracks::fill(std::vector<TrackTPC> const& tracks, float tp)
2828
{
29-
fill(gsl::span(tracks.data(), tracks.size()));
29+
fill(gsl::span(tracks.data(), tracks.size()), tp);
3030
}
3131

3232
//______________________________________________________________________________
33-
void CalibLaserTracks::fill(const gsl::span<const TrackTPC> tracks)
33+
void CalibLaserTracks::fill(const gsl::span<const TrackTPC> tracks, float tp)
3434
{
3535
// ===| clean up TF data |===
3636
mZmatchPairsTFA.clear();
@@ -63,6 +63,9 @@ void CalibLaserTracks::fill(const gsl::span<const TrackTPC> tracks)
6363
mCalibDataTF.firstTime = mTFstart;
6464
mCalibDataTF.lastTime = tfEnd;
6565

66+
mAvgTP = (mAvgTP * mCalibData.processedTFs + tp) / (mCalibData.processedTFs + 1);
67+
mAvgDriftV = (mAvgDriftV * mCalibData.processedTFs + mDriftV) / (mCalibData.processedTFs + 1);
68+
6669
// ===| TF counters |===
6770
++mCalibData.processedTFs;
6871
++mCalibDataTF.processedTFs;
@@ -147,6 +150,8 @@ void CalibLaserTracks::processTrack(const TrackTPC& track)
147150
<< "ltr=" << ltr // matched ideal laser track
148151
<< "trOutLtr=" << parOutAtLtr // track rotated and propagated to ideal track position
149152
<< "TPCTracks=" << writeTrack // original TPC track
153+
<< "mDriftV=" << mDriftV
154+
<< "laserTrackID=" << laserTrackID
150155
<< "\n";
151156
}
152157
}
@@ -277,6 +282,18 @@ void CalibLaserTracks::merge(const CalibLaserTracks* other)
277282
mCalibData.firstTime = std::min(mCalibData.firstTime, other->mCalibData.firstTime);
278283
mCalibData.lastTime = std::max(mCalibData.lastTime, other->mCalibData.lastTime);
279284

285+
if ((mAvgTP > 0) && (other->mAvgTP > 0)) {
286+
mAvgTP = (mAvgTP + other->mAvgTP) / 2.0;
287+
} else if (other->mAvgTP > 0) {
288+
mAvgTP = other->mAvgTP;
289+
}
290+
291+
if ((mAvgDriftV > 0) && (other->mAvgDriftV > 0)) {
292+
mAvgDriftV = (mAvgDriftV + other->mAvgDriftV) / 2.0;
293+
} else if (other->mAvgDriftV > 0) {
294+
mAvgDriftV = other->mAvgDriftV;
295+
}
296+
280297
sort(mZmatchPairsA);
281298
sort(mZmatchPairsC);
282299

@@ -296,6 +313,7 @@ void CalibLaserTracks::endTF()
296313
<< "zPairsA=" << mZmatchPairsTFA
297314
<< "zPairsC=" << mZmatchPairsTFC
298315
<< "calibData=" << mCalibDataTF
316+
<< "mDriftV=" << mDriftV
299317
<< "\n";
300318
}
301319
}
@@ -330,7 +348,7 @@ void CalibLaserTracks::fillCalibData(LtrCalibData& calibData, const std::vector<
330348
auto dvA = fit(pairsA, "A-Side");
331349
auto dvC = fit(pairsC, "C-Side");
332350
calibData.creationTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
333-
calibData.refVDrift = mDriftV;
351+
calibData.refVDrift = mAvgDriftV;
334352
calibData.dvOffsetA = dvA.x1;
335353
calibData.dvCorrectionA = dvA.x2;
336354
calibData.nTracksA = uint16_t(pairsA.size());
@@ -340,6 +358,7 @@ void CalibLaserTracks::fillCalibData(LtrCalibData& calibData, const std::vector<
340358
calibData.nTracksC = uint16_t(pairsC.size());
341359

342360
calibData.refTimeOffset = mTOffsetMUS;
361+
calibData.tp = mAvgTP;
343362
}
344363

345364
//______________________________________________________________________________

0 commit comments

Comments
 (0)