Skip to content

Commit 914e929

Browse files
authored
Merge branch 'AliceO2Group:dev' into new-detector4
2 parents 180fecc + fe1d400 commit 914e929

File tree

43 files changed

+897
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+897
-172
lines changed

CCDB/include/CCDB/BasicCCDBManager.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,20 @@ class CCDBManagerInstance
108108

109109
/// retrieve an object of type T from CCDB as stored under path, timestamp and metaData
110110
template <typename T>
111-
T* getSpecific(std::string const& path, long timestamp = -1, MD metaData = MD())
111+
T* getSpecific(std::string const& path, long timestamp = -1, MD metaData = MD(), std::map<std::string, std::string>* headers = nullptr)
112112
{
113113
// TODO: add some error info/handling when failing
114114
mMetaData = metaData;
115-
return getForTimeStamp<T>(path, timestamp);
115+
auto obj = getForTimeStamp<T>(path, timestamp);
116+
if (headers) {
117+
*headers = mHeaders;
118+
}
119+
return obj;
116120
}
117121

118122
/// retrieve an object of type T from CCDB as stored under path and using the timestamp in the middle of the run + metadata. The run number is provided separately to conform to typical analysis use (in which case metadata does not include runNumber)
119123
template <typename T>
120-
T* getSpecificForRun(std::string const& path, int runNumber, MD metaData = MD());
124+
T* getSpecificForRun(std::string const& path, int runNumber, MD const& metaData = MD());
121125

122126
/// detect online processing modes (i.e. CCDB objects may be updated in the lifetime of the manager)
123127
bool isOnline() const { return mDeplMode == o2::framework::DeploymentMode::OnlineAUX || mDeplMode == o2::framework::DeploymentMode::OnlineDDS || mDeplMode == o2::framework::DeploymentMode::OnlineECS; }
@@ -129,6 +133,9 @@ class CCDBManagerInstance
129133
return getForTimeStamp<T>(path, mTimestamp);
130134
}
131135

136+
// gain access to underlaying CCDB layer (to allow for more complex queries without need to reinit another API)
137+
CcdbApi& getCCDBAccessor() { return mCCDBAccessor; }
138+
132139
bool isHostReachable() const { return mCCDBAccessor.isHostReachable(); }
133140

134141
/// clear all entries in the cache
@@ -230,11 +237,12 @@ class CCDBManagerInstance
230237
template <typename T>
231238
T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
232239
{
240+
mHeaders.clear(); // we clear at the beginning; to allow to retrieve the header information in a subsequent call
233241
T* ptr = nullptr;
234242
mQueries++;
235243
auto start = std::chrono::system_clock::now();
236244
if (!isCachingEnabled()) {
237-
ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, nullptr, "",
245+
ptr = mCCDBAccessor.retrieveFromTFileAny<T>(path, mMetaData, timestamp, &mHeaders, "",
238246
mCreatedNotAfter ? std::to_string(mCreatedNotAfter) : "",
239247
mCreatedNotBefore ? std::to_string(mCreatedNotBefore) : "");
240248
if (!ptr) {
@@ -305,7 +313,6 @@ T* CCDBManagerInstance::getForTimeStamp(std::string const& path, long timestamp)
305313
} else {
306314
cached.cacheValidUntil = -1;
307315
}
308-
mHeaders.clear();
309316
mMetaData.clear();
310317
if (!ptr) {
311318
if (mFatalWhenNull) {
@@ -328,7 +335,7 @@ T* CCDBManagerInstance::getForRun(std::string const& path, int runNumber, bool s
328335
}
329336

330337
template <typename T>
331-
T* CCDBManagerInstance::getSpecificForRun(std::string const& path, int runNumber, MD metaData)
338+
T* CCDBManagerInstance::getSpecificForRun(std::string const& path, int runNumber, MD const& metaData)
332339
{
333340
auto [start, stop] = getRunDuration(runNumber, mFatalWhenNull);
334341
if (start < 0 || stop < 0) {

DataFormats/Parameters/include/DataFormatsParameters/AggregatedRunInfo.h

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,35 @@ struct AggregatedRunInfo {
3232
int runNumber = 0; // run number
3333
int64_t sor = 0; // best known timestamp for the start of run
3434
int64_t eor = 0; // best known timestamp for end of run
35-
int64_t orbitsPerTF = 0; // number of orbits per TF
35+
int64_t orbitsPerTF = 0; // number of orbits per TF (takes precedence over that in GRPECS)
3636
int64_t orbitReset = 0; // timestamp of orbit reset before run
3737
int64_t orbitSOR = 0; // orbit when run starts after orbit reset
3838
int64_t orbitEOR = 0; // orbit when run ends after orbit reset
3939

4040
// we may have pointers to actual data source objects GRPECS, ...
4141
const o2::parameters::GRPECSObject* grpECS = nullptr; // pointer to GRPECSobject (fetched during struct building)
4242

43-
// fills and returns AggregatedRunInfo for a given run number.
44-
static AggregatedRunInfo buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber);
4543
static AggregatedRunInfo buildAggregatedRunInfo(int runnumber, long sorMS, long eorMS, long orbitResetMUS, const o2::parameters::GRPECSObject* grpecs, const std::vector<Long64_t>* ctfFirstRunOrbitVec);
44+
45+
// fills and returns AggregatedRunInfo for a given data run number.
46+
static AggregatedRunInfo buildAggregatedRunInfo_DATA(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber);
47+
48+
// Returns the meta-data (MCProdInfo) associated to production lpm_prod_tag (performed by username)
49+
static std::map<std::string, std::string> getMCProdInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber,
50+
std::string const& lpm_prod_tag, std::string const& username = "aliprod");
51+
52+
// function that adjusts with values from MC
53+
void adjust_from_MC(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username = "aliprod");
54+
55+
// Fills and returns AggregatedRunInfo for a given run number.
56+
// If a non-empty lpm_prod_tag is given, it will potentially override values with specifics from a
57+
// MC production identified by that tag and username.
58+
static AggregatedRunInfo buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb,
59+
int runnumber,
60+
std::string const& lpm_prod_tag = "",
61+
std::string const& username = "aliprod");
62+
63+
ClassDefNV(AggregatedRunInfo, 1);
4664
};
4765

4866
} // namespace o2::parameters

DataFormats/Parameters/src/AggregatedRunInfo.cxx

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
using namespace o2::parameters;
2323

24-
o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber)
24+
o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo_DATA(o2::ccdb::CCDBManagerInstance& ccdb, int runnumber)
2525
{
2626
// TODO: could think about caching results per runnumber to
2727
// avoid going to CCDB multiple times ---> but should be done inside the CCDBManagerInstance
@@ -83,3 +83,67 @@ o2::parameters::AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(int
8383
}
8484
return AggregatedRunInfo{runnumber, sorMS, eorMS, nOrbitsPerTF, orbitResetMUS, orbitSOR, orbitEOR, grpecs};
8585
}
86+
87+
namespace
88+
{
89+
90+
// get path where to find MC production info
91+
std::string getFullPath_MC(std::string const& username, std::string const& lpm_prod_tag)
92+
{
93+
// construct the path where to lookup
94+
std::string path = "/Users/" + std::string(1, username[0]) + "/" + username;
95+
std::string fullpath = path + "/" + "MCProdInfo/" + lpm_prod_tag;
96+
return fullpath;
97+
}
98+
99+
} // namespace
100+
101+
std::map<std::string, std::string> AggregatedRunInfo::getMCProdInfo(o2::ccdb::CCDBManagerInstance& ccdb,
102+
int run_number,
103+
std::string const& lpm_prod_tag,
104+
std::string const& username)
105+
{
106+
std::map<std::string, std::string> metaDataFilter;
107+
metaDataFilter["LPMProductionTag"] = lpm_prod_tag;
108+
109+
// fetch the meta information for MC productions
110+
auto header_data = ccdb.getCCDBAccessor().retrieveHeaders(getFullPath_MC(username, lpm_prod_tag), metaDataFilter, run_number);
111+
return header_data;
112+
}
113+
114+
void AggregatedRunInfo::adjust_from_MC(o2::ccdb::CCDBManagerInstance& ccdb,
115+
int run_number,
116+
std::string const& lpm_prod_tag,
117+
std::string const& username)
118+
{
119+
auto header_data = AggregatedRunInfo::getMCProdInfo(ccdb, run_number, lpm_prod_tag, username);
120+
121+
// adjust timeframe length if we find entry for MC production
122+
auto iter = header_data.find("OrbitsPerTF");
123+
if (iter != header_data.end()) {
124+
auto mc_orbitsPerTF = std::stoi(iter->second);
125+
if (mc_orbitsPerTF != orbitsPerTF) {
126+
LOG(info) << "Adjusting OrbitsPerTF from " << orbitsPerTF << " to " << mc_orbitsPerTF << " based on differing MC info";
127+
orbitsPerTF = mc_orbitsPerTF;
128+
}
129+
} else {
130+
LOG(warn) << "No OrbitsPerTF information found for MC production " << lpm_prod_tag << " and run number " << run_number;
131+
}
132+
}
133+
134+
AggregatedRunInfo AggregatedRunInfo::buildAggregatedRunInfo(o2::ccdb::CCDBManagerInstance& ccdb, int run_number, std::string const& lpm_prod_tag, std::string const& username)
135+
{
136+
// (a) lookup the AggregatedRunInfo for the data run
137+
// (b) modify/overwrite the info object with MC specific settings if lpm_prod_tag is given
138+
139+
auto original_info = buildAggregatedRunInfo_DATA(ccdb, run_number);
140+
141+
if (lpm_prod_tag.size() == 0) {
142+
return original_info;
143+
}
144+
145+
// in this case we adjust the info from MC
146+
original_info.adjust_from_MC(ccdb, run_number, lpm_prod_tag, username);
147+
148+
return original_info;
149+
}

DataFormats/Parameters/src/GRPLHCIFData.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ using namespace o2::constants::lhc;
2828
const std::unordered_map<unsigned int, unsigned int> GRPLHCIFData::mZtoA =
2929
{
3030
{1, 1},
31+
{8, 16},
32+
{10, 20},
3133
{82, 208}};
3234

3335
//_______________________________________________

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);

0 commit comments

Comments
 (0)