Skip to content

Commit 8ce25b7

Browse files
committed
Methods for layer-dependend mat.LUT rescaling
See the macro O2/Detectors/Base/test/rescaleLUT.C as an example, which writes a rescaled LUT to the <original_name>_rescaled.root file. The rescaling parameters are provided as a set of RescRange structs: radial range + scaling coefficient. It uses a method o2::base::MatLayerCylSet::scaleLayersByR(rmin,rmax, factor, bool scaleX2X0=true, bool scaleRho=true). All LUT layers overlapping with rmin:rmax range will be rescaled. Alternatively, one can use directly the method o2::base::MatLayerCylSet::scaleLayersByID(lrIDmin,lrIDmax, factor, bool scaleX2X0=true, bool scaleRho=true) to scale a set of layers [lrIDmin:lrIDmax].
1 parent 10dd8dc commit 8ce25b7

File tree

6 files changed

+136
-1
lines changed

6 files changed

+136
-1
lines changed

Detectors/Base/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ endif()
8787

8888
install(FILES test/buildMatBudLUT.C
8989
test/extractLUTLayers.C
90+
test/rescaleLUT.C
9091
DESTINATION share/macro/)
9192

9293
o2_add_test_root_macro(test/buildMatBudLUT.C
@@ -96,3 +97,7 @@ o2_add_test_root_macro(test/buildMatBudLUT.C
9697
o2_add_test_root_macro(test/extractLUTLayers.C
9798
PUBLIC_LINK_LIBRARIES O2::DetectorsBase
9899
LABELS detectorsbase)
100+
101+
o2_add_test_root_macro(test/rescaleLUT.C
102+
PUBLIC_LINK_LIBRARIES O2::DetectorsBase
103+
LABELS detectorsbase)

Detectors/Base/include/DetectorsBase/MatLayerCyl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ class MatLayerCyl : public o2::gpu::FlatObject
9393
GPUd() const MatCell& getCell(int iphiSlice, int iz) const { return mCells[getCellID(iphiSlice, iz)]; }
9494

9595
#ifndef GPUCA_ALIGPUCODE // this part is unvisible on GPU version
96-
GPUd() MatCell& getCellPhiBin(int iphi, int iz)
96+
MatCell& getCellPhiBin(int iphi, int iz)
9797
{
9898
return mCells[getCellIDPhiBin(iphi, iz)];
9999
}
100+
101+
void scale(float factor, bool _x2x0 = true, bool _rho = true);
100102
#endif
101103

102104
// ---------------------- Z slice manipulation

Detectors/Base/include/DetectorsBase/MatLayerCylSet.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class MatLayerCylSet : public o2::gpu::FlatObject
9898
// get material budget traversed on the line between point0 and point1
9999
return getMatBudget(point0.X(), point0.Y(), point0.Z(), point1.X(), point1.Y(), point1.Z());
100100
}
101+
102+
void scaleLayersByID(int lrFrom, int lrTo, float factor, bool _x2x0 = true, bool _rho = true);
103+
void scaleLayersByR(float rFrom, float rTo, float factor, bool _x2x0 = true, bool _rho = true);
104+
101105
#endif // !GPUCA_ALIGPUCODE
102106
GPUd() MatBudget getMatBudget(float x0, float y0, float z0, float x1, float y1, float z1) const;
103107

Detectors/Base/src/MatLayerCyl.cxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,24 @@ void MatLayerCyl::flatten(char* newPtr)
319319
mConstructionMask = Constructed;
320320
}
321321

322+
//________________________________________________________________________________
323+
void MatLayerCyl::scale(float factor, bool _x2x0, bool _rho)
324+
{
325+
LOGP(info, "Scaling layer {:.3f}<r<{:.3f} by {:.3f}", getRMin(), getRMax(), factor);
326+
for (int i = 0; i < mNPhiSlices * mNZBins; i++) {
327+
if (_x2x0) {
328+
mCells[i].meanX2X0 *= factor;
329+
}
330+
if (_rho) {
331+
mCells[i].meanRho *= factor;
332+
}
333+
}
334+
}
335+
322336
#endif // ! GPUCA_ALIGPUCODE
323337

324338
#ifndef GPUCA_GPUCODE
339+
325340
//________________________________________________________________________________
326341
void MatLayerCyl::fixPointers(char* oldPtr, char* newPtr)
327342
{

Detectors/Base/src/MatLayerCylSet.cxx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,33 @@ void MatLayerCylSet::print(bool data) const
256256
float(getFlatBufferSize()) / 1024 / 1024);
257257
}
258258

259+
//________________________________________________________________________________
260+
void MatLayerCylSet::scaleLayersByID(int lrFrom, int lrTo, float factor, bool _x2x0, bool _rho)
261+
{
262+
lrFrom = std::max(0, std::min(lrFrom, get()->mNLayers - 1));
263+
lrTo = std::max(0, std::min(lrTo, get()->mNLayers - 1));
264+
int dir = lrFrom >= lrTo ? -1 : 1;
265+
lrTo += dir;
266+
for (int i = lrFrom; i != lrTo; i += dir) {
267+
get()->mLayers[i].scale(factor, _x2x0, _rho);
268+
}
269+
}
270+
271+
//________________________________________________________________________________
272+
void MatLayerCylSet::scaleLayersByR(float rFrom, float rTo, float factor, bool _x2x0, bool _rho)
273+
{
274+
if (rFrom > rTo) {
275+
std::swap(rFrom, rTo);
276+
}
277+
Ray ray(std::max(getRMin(), rFrom), 0., 0., std::min(getRMax(), rTo), 0., 0.);
278+
short lmin, lmax;
279+
if (!getLayersRange(ray, lmin, lmax)) {
280+
LOGP(warn, "No layers found for {} < r < {}", rFrom, rTo);
281+
return;
282+
}
283+
scaleLayersByID(lmin, lmax, factor, _x2x0, _rho);
284+
}
285+
259286
#endif //!GPUCA_ALIGPUCODE
260287

261288
#ifndef GPUCA_GPUCODE

Detectors/Base/test/rescaleLUT.C

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
#if !defined(__CLING__) || defined(__ROOTCLING__)
13+
#include "DetectorsBase/MatLayerCylSet.h"
14+
#include "Framework/Logger.h"
15+
#include "CCDB/BasicCCDBManager.h"
16+
#include <regex>
17+
#endif
18+
19+
// Macro to extract layers covering selected radial range into the separate LUT file.
20+
21+
void rescaleLUT(o2::base::MatLayerCylSet* src, const std::string& outName)
22+
{
23+
struct RescRange {
24+
float rMin, rMax, factor;
25+
};
26+
std::vector<RescRange> task = {
27+
// put here radial ranges in increasing order with corresponding factors to rescale
28+
{0.1f, 6.f, 1.05}, // e.g. rescale layers covering 0.1<r<6 by factor 1.05
29+
{30.f, 40.f, 1.15}, // e.g. rescale layers covering 30.f<r<40.f by factor 1.15
30+
};
31+
32+
// check if there are no overlaps in ranges, to avoid double rescaling
33+
for (size_t il = 1; il < task.size(); il++) {
34+
short lmax, lmin;
35+
float rmin = task[il - 1].rMax, rmax = task[il].rMin;
36+
if (rmin > rmax) {
37+
LOGP(error, "rMax={:.2f} of range {} is larger then rMin={:.2f} of range {}, must be in increasing order", rmin, il - 1, rmax, il);
38+
return;
39+
}
40+
o2::base::Ray ray(std::max(src->getRMin(), rmin), 0., 0., std::min(src->getRMax(), rmax), 0., 0.);
41+
if (!src->getLayersRange(ray, lmin, lmax)) {
42+
LOGP(error, "No layers found for {:.2f} < r < {:.2f}", rmin, rmax);
43+
return;
44+
}
45+
if (lmin == lmax) {
46+
LOGP(error, "rMax={:.2f} of range {} and rMin={:.2f} of range {}, correspond to the same slice {} with {:.2f}<r<{:.2f}",
47+
rmin, il - 1, rmax, il, lmin, src->getLayer(lmin).getRMin(), src->getLayer(lmin).getRMax());
48+
return;
49+
}
50+
}
51+
52+
for (size_t il = 0; il < task.size(); il++) {
53+
src->scaleLayersByR(task[il].rMin, task[il].rMax, task[il].factor);
54+
}
55+
if (outName.size()) {
56+
src->writeToFile(outName);
57+
}
58+
}
59+
60+
void rescaleLUT(const std::string& fname)
61+
{
62+
auto src = o2::base::MatLayerCylSet::loadFromFile(fname);
63+
if (!src) {
64+
LOGP(error, "failed to open source LUT from {}", fname);
65+
return;
66+
}
67+
auto fnameOut = std::regex_replace(fname, std::regex(R"(.root)"), "_rescaled.root");
68+
rescaleLUT(src, fnameOut);
69+
}
70+
71+
void rescaleLUT(long timestamp = -1)
72+
{
73+
auto& mg = o2::ccdb::BasicCCDBManager::instance();
74+
mg.setTimestamp(timestamp);
75+
auto src = o2::base::MatLayerCylSet::rectifyPtrFromFile(mg.get<o2::base::MatLayerCylSet>("GLO/Param/MatLUT"));
76+
if (!src) {
77+
LOGP(error, "failed to open load LUT from CCDB for timestamp {}", timestamp);
78+
return;
79+
}
80+
auto fnameOut = fmt::format("matbudLUT_ts{}_rescaled.root", timestamp);
81+
rescaleLUT(src, fnameOut);
82+
}

0 commit comments

Comments
 (0)