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