Skip to content

Commit 4d64371

Browse files
committed
Merge branch 'dev' into onnx_gpu_timer
2 parents f235071 + d9d6894 commit 4d64371

File tree

23 files changed

+524
-105
lines changed

23 files changed

+524
-105
lines changed

DataFormats/Reconstruction/include/ReconstructionDataFormats/TrackFwd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ class TrackParCovFwd : public TrackParFwd
161161
void propagateToZquadratic(double zEnd, double zField);
162162
void propagateToZhelix(double zEnd, double zField);
163163
void propagateToZ(double zEnd, double zField); // Parameters: helix; errors: quadratic
164+
void propagateToDCAhelix(double zField, const std::array<double, 3>& p, std::array<double, 3>& dca);
164165

165166
// Add Multiple Coulomb Scattering effects
166167
void addMCSEffect(double x2X0);

DataFormats/Reconstruction/include/ReconstructionDataFormats/Vertex.h

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818

1919
#include "CommonDataFormat/TimeStamp.h"
2020
#ifndef GPUCA_GPUCODE_DEVICE
21-
#include <iosfwd>
22-
#include <string>
2321
#include <type_traits>
2422
#include <array>
23+
#ifndef GPUCA_NO_FMT
24+
#include <sstream>
25+
#include <string>
26+
#include <fmt/format.h>
27+
#endif
2528
#endif
2629

2730
namespace o2
@@ -135,6 +138,11 @@ class Vertex : public VertexBase
135138
{
136139
}
137140

141+
#if !defined(GPUCA_NO_FMT) && !defined(GPUCA_GPUCODE_DEVICE)
142+
void print() const;
143+
std::string asString() const;
144+
#endif
145+
138146
GPUd() ushort getNContributors() const { return mNContributors; }
139147
GPUd() void setNContributors(ushort v) { mNContributors = v; }
140148
GPUd() void addContributor() { mNContributors++; }
@@ -162,6 +170,49 @@ class Vertex : public VertexBase
162170

163171
#if !defined(GPUCA_GPUCODE_DEVICE) && !defined(GPUCA_NO_FMT)
164172
std::ostream& operator<<(std::ostream& os, const o2::dataformats::VertexBase& v);
173+
174+
namespace detail
175+
{
176+
template <typename T>
177+
concept Streamable = requires(std::ostream& os, const T& a) {
178+
{ os << a } -> std::same_as<std::ostream&>;
179+
};
180+
181+
template <typename T>
182+
concept HasFormattableTimeStamp = requires(const T& t) {
183+
{ fmt::format("{}", t.getTimeStamp()) } -> std::convertible_to<std::string>;
184+
};
185+
} // namespace detail
186+
187+
template <typename Stamp>
188+
inline std::string Vertex<Stamp>::asString() const
189+
{
190+
const std::string stamp = [&]() -> std::string {
191+
if constexpr (detail::Streamable<Stamp>) {
192+
std::ostringstream oss;
193+
oss << mTimeStamp;
194+
return oss.str();
195+
} else if constexpr (detail::HasFormattableTimeStamp<Stamp>) {
196+
return fmt::format("{}", mTimeStamp.getTimeStamp());
197+
} else {
198+
return "X";
199+
}
200+
}();
201+
return fmt::format("{} NContrib:{} Chi2:{:.2f} Flags:{:b} Stamp:{}", VertexBase::asString(), mNContributors, mChi2, mBits, stamp);
202+
}
203+
204+
template <typename Stamp>
205+
inline std::ostream& operator<<(std::ostream& os, const o2::dataformats::Vertex<Stamp>& v)
206+
{
207+
os << v.asString();
208+
return os;
209+
}
210+
211+
template <typename Stamp>
212+
inline void Vertex<Stamp>::print() const
213+
{
214+
std::cout << *this << '\n';
215+
}
165216
#endif
166217

167218
} // namespace dataformats

DataFormats/Reconstruction/src/TrackFwd.cxx

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
#include "ReconstructionDataFormats/TrackFwd.h"
1313
#include "Math/MatrixFunctions.h"
14+
#include <GPUCommonLogger.h>
1415

1516
namespace o2
1617
{
@@ -503,5 +504,73 @@ bool TrackParCovFwd::getCovXYZPxPyPzGlo(std::array<float, 21>& cv) const
503504
return true;
504505
}
505506

507+
//________________________________________________________________
508+
509+
void TrackParCovFwd::propagateToDCAhelix(double zField, const std::array<double, 3>& p, std::array<double, 3>& dca)
510+
{
511+
// Computing DCA of fwd track w.r.t vertex in helix track model, using Newton-Raphson minimization
512+
513+
auto x0 = mParameters(0);
514+
auto y0 = mParameters(1);
515+
auto z0 = mZ;
516+
auto phi0 = mParameters(2);
517+
auto tanl = mParameters(3);
518+
auto qOverPt = mParameters(4);
519+
auto k = TMath::Abs(o2::constants::math::B2C * zField);
520+
auto qpt = 1.0 / qOverPt;
521+
auto qR = qpt / std::fabs(k);
522+
auto invtanl = 1.0 / tanl;
523+
auto Hz = std::copysign(1, zField);
524+
525+
auto xPV = p[0];
526+
auto yPV = p[1];
527+
auto zPV = p[2];
528+
529+
auto qRtanl = qR * tanl;
530+
auto invqRtanl = 1.0 / qRtanl;
531+
auto [sinp, cosp] = o2::math_utils::sincosd(phi0);
532+
533+
auto z = zPV;
534+
double tol = 1e-4;
535+
int max_iter = 10;
536+
int iter = 0;
537+
538+
while (iter++ < max_iter) {
539+
double theta = (z0 - z) * invqRtanl;
540+
double phi_theta = phi0 + Hz * theta;
541+
double sin_phi_theta = sin(phi_theta);
542+
double cos_phi_theta = cos(phi_theta);
543+
544+
double DX = x0 - Hz * qR * (sin_phi_theta - sinp) - xPV;
545+
double DY = y0 + Hz * qR * (cos_phi_theta - cosp) - yPV;
546+
double DZ = z - zPV;
547+
548+
double dD2_dZ =
549+
2 * DX * cos_phi_theta * invtanl +
550+
2 * DY * sin_phi_theta * invtanl +
551+
2 * DZ;
552+
553+
double d2D2_dZ2 =
554+
2 * invtanl * invtanl +
555+
2 * invtanl * (DX * Hz * sin_phi_theta - DY * Hz * cos_phi_theta) * invqRtanl +
556+
2;
557+
558+
double z_new = z - dD2_dZ / d2D2_dZ2;
559+
560+
if (std::abs(z_new - z) < tol) {
561+
z = z_new;
562+
this->propagateToZhelix(z, zField);
563+
dca[0] = this->getX() - xPV;
564+
dca[1] = this->getY() - yPV;
565+
dca[2] = this->getZ() - zPV;
566+
LOG(debug) << "Converged after " << iter << " iterations for vertex X=" << p[0] << ", Y=" << p[1] << ", Z = " << p[2];
567+
return;
568+
}
569+
z = z_new;
570+
}
571+
LOG(debug) << "Failed to converge after " << iter << " iterations for vertex X=" << p[0] << ", Y=" << p[1] << ", Z = " << p[2];
572+
return;
573+
}
574+
506575
} // namespace track
507576
} // namespace o2

DataFormats/Reconstruction/src/Vertex.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
// or submit itself to any jurisdiction.
1111

1212
#include "ReconstructionDataFormats/Vertex.h"
13-
#include <iostream>
1413
#ifndef GPUCA_NO_FMT
15-
#include <fmt/printf.h>
14+
#include <iostream>
15+
#include <fmt/format.h>
1616
#endif
1717

1818
namespace o2

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct CorrMapParam : public o2::conf::ConfigurableParamHelper<CorrMapParam> {
2929
float lumiMean = 0.; // override TPC corr.map mean lumi (if > 0), disable corrections if < 0
3030
float lumiMeanRef = 0.; // override TPC corr.mapRef mean lumi (if > 0)"
3131
float lumiInstFactor = 1.; // scaling to apply to instantaneous lumi from CTP (but not to IDC scaler)
32+
float CTP2IDCFallBackThreshold = 30.; // if needed, interpret map->getLumi() as map->getIDC(), provided map->getLumi() is below this threshold
3233
int ctpLumiSource = 0; // CTP lumi source: 0 = LumiInfo.getLumi(), 1 = LumiInfo.getLumiAlt()
3334

3435
O2ParamDef(CorrMapParam, "TPCCorrMap");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class CorrectionMapsLoader : public o2::gpu::CorrectionMapsHelper
6363
void init(o2::framework::InitContext& ic);
6464
void copySettings(const CorrectionMapsLoader& src);
6565
void updateInverse(); /// recalculate inverse correction
66+
float getMapMeanRate(const o2::gpu::TPCFastTransform* mp, bool lumiOverridden) const;
6667

6768
static void requestCCDBInputs(std::vector<o2::framework::InputSpec>& inputs, std::vector<o2::framework::ConfigParamSpec>& options, const CorrectionMapsLoaderGloOpts& gloOpts);
6869
static void addGlobalOptions(std::vector<o2::framework::ConfigParamSpec>& options);

Detectors/TPC/calibration/src/CorrectdEdxDistortions.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ void o2::tpc::CorrectdEdxDistortions::setLumi(float lumi)
7070
LOGP(warn, "Nullptr detected in accessing the correction maps");
7171
return;
7272
}
73-
const float lumiAvg = mCorrAvg->getLumi();
74-
const float lumiDer = mCorrDer->getLumi();
73+
const float lumiAvg = mCorrAvg->getIDC();
74+
const float lumiDer = mCorrDer->getIDC();
7575
mScaleDer = (lumi - lumiAvg) / lumiDer;
7676
LOGP(info, "Setting mScaleDer: {} for inst lumi: {} avg lumi: {} deriv. lumi: {}", mScaleDer, lumi, lumiAvg, lumiDer);
7777
}

Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,20 +176,52 @@ bool CorrectionMapsLoader::accountCCDBInputs(const ConcreteDataMatcher& matcher,
176176
if (matcher == ConcreteDataMatcher("TPC", "CorrMap", 0)) {
177177
setCorrMap((o2::gpu::TPCFastTransform*)obj);
178178
mCorrMap->rectifyAfterReadingFromFile();
179-
if (getMeanLumiOverride() == 0 && mCorrMap->getLumi() > 0.) {
180-
setMeanLumi(mCorrMap->getLumi(), false);
179+
mCorrMap->setCTP2IDCFallBackThreshold(o2::tpc::CorrMapParam::Instance().CTP2IDCFallBackThreshold);
180+
if (getMeanLumiOverride() != 0) {
181+
if (getLumiScaleType() == 1) {
182+
mCorrMap->setLumi(getMeanLumiOverride());
183+
LOGP(info, "CorrMap mean lumi rate is overridden to {}", mCorrMap->getLumi());
184+
} else if (getLumiScaleType() == 2) {
185+
mCorrMap->setIDC(getMeanLumiOverride());
186+
LOGP(info, "CorrMap mean IDC rate is overridden to {}", mCorrMap->getIDC());
187+
}
188+
}
189+
float mapMeanRate = 0;
190+
if (getLumiScaleType() == 1) {
191+
mapMeanRate = mCorrMap->getLumi();
192+
} else if (getLumiScaleType() == 2) {
193+
mapMeanRate = mCorrMap->getIDC();
194+
}
195+
if (getMeanLumiOverride() == 0 && mapMeanRate > 0.) {
196+
setMeanLumi(mapMeanRate, false);
181197
}
182-
LOGP(debug, "MeanLumiOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiOverride(), mCorrMap->getLumi(), getMeanLumi());
198+
LOGP(debug, "MeanLumiOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiOverride(), mapMeanRate, getMeanLumi());
183199
setUpdatedMap();
184200
return true;
185201
}
186202
if (matcher == ConcreteDataMatcher("TPC", "CorrMapRef", 0)) {
187203
setCorrMapRef((o2::gpu::TPCFastTransform*)obj);
188204
mCorrMapRef->rectifyAfterReadingFromFile();
205+
mCorrMapRef->setCTP2IDCFallBackThreshold(o2::tpc::CorrMapParam::Instance().CTP2IDCFallBackThreshold);
206+
if (getMeanLumiRefOverride() != 0) {
207+
if (getLumiScaleType() == 1) {
208+
mCorrMapRef->setLumi(getMeanLumiRefOverride());
209+
LOGP(info, "CorrMapRef mean lumi rate is overridden to {}", mCorrMapRef->getLumi());
210+
} else if (getLumiScaleType() == 2) {
211+
mCorrMapRef->setIDC(getMeanLumiRefOverride());
212+
LOGP(info, "CorrMapRef mean IDC rate is overridden to {}", mCorrMapRef->getIDC());
213+
}
214+
}
215+
float mapRefMeanRate = 0;
216+
if (getLumiScaleType() == 1) {
217+
mapRefMeanRate = mCorrMapRef->getLumi();
218+
} else if (getLumiScaleType() == 2) {
219+
mapRefMeanRate = mCorrMapRef->getIDC();
220+
}
189221
if (getMeanLumiRefOverride() == 0) {
190-
setMeanLumiRef(mCorrMapRef->getLumi());
222+
setMeanLumiRef(mapRefMeanRate);
191223
}
192-
LOGP(debug, "MeanLumiRefOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiRefOverride(), mCorrMapRef->getLumi(), getMeanLumiRef());
224+
LOGP(debug, "MeanLumiRefOverride={} MeanLumiMap={} -> meanLumi = {}", getMeanLumiRefOverride(), mapRefMeanRate, getMeanLumiRef());
193225
setUpdatedMapRef();
194226
return true;
195227
}
@@ -217,7 +249,7 @@ bool CorrectionMapsLoader::accountCCDBInputs(const ConcreteDataMatcher& matcher,
217249
int scaleType = getLumiScaleType();
218250
const std::array<std::string, 3> lumiS{"OFF", "CTP", "TPC scaler"};
219251
if (scaleType >= lumiS.size()) {
220-
LOGP(fatal, "Wrong lumi-scale-type provided!");
252+
LOGP(fatal, "Wrong corrmap-lumi-mode provided!");
221253
}
222254

223255
LOGP(info, "TPC correction map params updated: SP corrections: {} (corr.map scaling type={}, override values: lumiMean={} lumiRefMean={} lumiScaleMode={}), CTP Lumi: source={} lumiInstOverride={} , LumiInst scale={} ",

Detectors/TRD/workflow/include/TRDWorkflow/GainCalibSpec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class GainCalibDevice : public o2::framework::Task
4545
{
4646
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
4747
auto slotL = ic.options().get<uint32_t>("sec-per-slot");
48-
auto delay = ic.options().get<uint32_t>("max-delay");
48+
auto delay = ic.options().get<float>("max-delay");
4949
mCalibrator = std::make_unique<o2::trd::CalibratorGain>();
5050
mCalibrator->setSlotLengthInSeconds(slotL);
5151
mCalibrator->setMaxSlotsDelay(delay);
@@ -155,7 +155,7 @@ DataProcessorSpec getTRDGainCalibSpec()
155155
AlgorithmSpec{adaptFromTask<o2::calibration::GainCalibDevice>(ccdbRequest)},
156156
Options{
157157
{"sec-per-slot", VariantType::UInt32, 900u, {"number of seconds per calibration time slot"}},
158-
{"max-delay", VariantType::UInt32, 2u, {"number of slots in past to consider"}},
158+
{"max-delay", VariantType::Float, 0.05f, {"number of slots in past to consider"}},
159159
{"enable-root-output", VariantType::Bool, false, {"output tprofiles and fits to root file"}},
160160
}};
161161
}

Detectors/TRD/workflow/include/TRDWorkflow/T0FitSpec.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class T0FitDevice : public o2::framework::Task
4646
{
4747
o2::base::GRPGeomHelper::instance().setRequest(mCCDBRequest);
4848
auto slotL = ic.options().get<uint32_t>("sec-per-slot");
49-
auto delay = ic.options().get<uint32_t>("max-delay");
49+
auto delay = ic.options().get<float>("max-delay");
5050

5151
mFitInstance = std::make_unique<o2::trd::T0Fit>();
5252
mFitInstance->setSlotLengthInSeconds(slotL);
@@ -159,7 +159,7 @@ DataProcessorSpec getTRDT0FitSpec()
159159
AlgorithmSpec{adaptFromTask<device>(ccdbRequest)},
160160
Options{
161161
{"sec-per-slot", VariantType::UInt32, 900u, {"number of seconds per calibration time slot"}},
162-
{"max-delay", VariantType::UInt32, 2u, {"number of slots in past to consider"}},
162+
{"max-delay", VariantType::Float, 0.05f, {"number of slots in past to consider"}},
163163
{"enable-root-output", VariantType::Bool, false, {"output t0 values to root file"}},
164164
}};
165165
}

0 commit comments

Comments
 (0)