43 TPCScalerSpec(std::shared_ptr<o2::base::GRPGeomRequest> req,
const o2::tpc::CorrectionMapsGloOpts& sclOpts,
bool enableIDCs,
bool enableMShape) : mCCDBRequest(req), mEnableIDCs(enableIDCs), mEnableMShape(enableMShape), mGlobOpts(sclOpts)
54 mIonDriftTimeMS = ic.options().get<
float>(
"ion-drift-time");
55 mMaxTimeWeightsMS = ic.options().get<
float>(
"max-time-for-weights");
56 mMShapeScalingFac = ic.options().get<
float>(
"m-shape-scaling-factor");
57 mEnableWeights = !(ic.options().get<
bool>(
"disableWeights"));
58 const bool enableStreamer = ic.options().get<
bool>(
"enableStreamer");
59 const int mshapeThreads = ic.options().get<
int>(
"n-threads");
60 mKnotsYMshape = ic.options().get<
int>(
"n-knots-y");
61 mKnotsZMshape = ic.options().get<
int>(
"n-knots-z");
66 mStreamer = std::make_unique<o2::utils::TreeStreamRedirector>(
"M_Shape.root",
"recreate");
68 mTPCCorrMapsLoader.
init(ic, mEnableIDCs);
86 if (mEnableIDCs && pc.inputs().isValid(
"tpcscaler")) {
87 pc.inputs().get<TTree*>(
"tpcscaler");
90 if (mEnableWeights && mEnableIDCs) {
91 if (pc.inputs().isValid(
"tpcscalerw")) {
95 if (mEnableMShape && pc.inputs().isValid(
"mshape")) {
96 pc.inputs().get<TTree*>(
"mshape");
104 static int runWarningMS = -1;
105 if ((mMShapeTPCScaler.
getRun() != -1) && currRun != mMShapeTPCScaler.
getRun() && runWarningMS != currRun) {
107 runWarningMS = currRun;
111 if (!boundaryPotential.mPotential.empty()) {
112 LOGP(info,
"Calculating M-shape correction from input boundary potential");
115 for (
int iz = 0; iz < mMShapeTPCScaler.
getMShapes().mZ; ++iz) {
116 for (
int iphi = 0; iphi < mMShapeTPCScaler.
getMShapes().mPhi; ++iphi) {
117 const float pot = mMShapeScalingFac * boundaryPotential.mPotential[iz];
126 std::function<
void(
int,
double,
double,
double,
double&,
double&,
double&)> getCorrections = [&sc = sc](
const int roc,
double x,
double y,
double z,
double& dx,
double& dy,
double& dz) {
143 (*mStreamer) <<
"treeMShape"
144 <<
"firstTFOrbit=" << firstTFOrbit
145 <<
"timestamp=" << timestamp
146 <<
"boundaryPotential=" << boundaryPotential
147 <<
"mMShapeScalingFac=" << mMShapeScalingFac
152 float tpcScaler = -1.f;
154 static int runWarningIDC = -1;
157 runWarningIDC = currRun;
161 float meanScaler = (scalerA + scalerC) / 2;
162 tpcScaler = meanScaler;
164 (*mStreamer) <<
"treeIDC"
165 <<
"scalerA=" << scalerA
166 <<
"scalerC=" << scalerC
167 <<
"firstTFOrbit=" << firstTFOrbit
168 <<
"timestamp=" << timestamp
178 LOGP(info,
"Publishing CTP Lumi: {} for timestamp: {}, firstTFOrbit: {}", lumiCTP, timestamp, firstTFOrbit);
189 std::vector<std::pair<const o2::gpu::TPCFastSpaceChargeCorrection*, TPCFastSpaceChargeCorrectionHelper::SectorScales>> additionalCorrections;
191 auto uniformScale = [](
double s) {
202 auto* corrMap = mTPCCorrMapsLoader.
getCorrMap();
207 const float lumiScale = mTPCCorrMapsLoader.
getLumiScale();
211 const std::vector<std::pair<const o2::gpu::TPCFastSpaceChargeCorrection*, double>> step0{{&(corrMapRef->getCorrection()), -1.f}};
216 const std::vector<std::pair<const o2::gpu::TPCFastSpaceChargeCorrection*, double>> step1{{&(corrMapRef->getCorrection()), 1.}};
220 additionalCorrections.emplace_back(&(corrMapRef->getCorrection()), uniformScale(lumiScale));
225 LOGP(info,
"Adding M-shape correction to the final map with scaling factor {}", mMShapeScalingFac);
231 LOGP(info,
"Checking for sector edge fluctuation");
233 const auto activeSectors = mTPCCorrMapsLoader.
getSectorEdgeFlucInfo().getSectorsAtTime(currRun,
static_cast<long>(timestamp));
234 if (!activeSectors.empty()) {
235 LOGP(info,
"Adding edge-sector correction for {} active sector(s)", activeSectors.size());
237 for (
const auto& [sector, scale] : activeSectors) {
238 sectorScales[sector] =
static_cast<double>(scale);
244 if (!additionalCorrections.empty()) {
263 LOGP(info,
"Updating TPC scaler");
265 if (mIonDriftTimeMS > 0) {
266 LOGP(info,
"Setting ion drift time to: {}", mIonDriftTimeMS);
269 if (mScalerWeights.
isValid()) {
270 LOGP(info,
"Setting TPC scaler weights");
273 if (mIonDriftTimeMS == -1) {
274 overWriteIntegrationTime();
279 LOGP(info,
"Updating TPC scaler weights");
284 if (mIonDriftTimeMS == -1) {
285 overWriteIntegrationTime();
289 LOGP(info,
"Updating M-shape TPC scaler");
291 if (mMShapeTPCScaler.
getRun() == -1) {
292 LOGP(info,
"Loaded default M-Shape correction object from CCDB");
301 std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest;
302 const bool mEnableIDCs{
true};
303 const bool mEnableMShape{
false};
305 bool mEnableWeights{
false};
306 TPCScalerWeights mScalerWeights{};
307 float mIonDriftTimeMS{-1};
308 float mMaxTimeWeightsMS{500};
310 float mMShapeScalingFac{0};
311 TPCMShapeCorrection mMShapeTPCScaler;
312 int mKnotsYMshape{4};
313 int mKnotsZMshape{4};
314 std::unique_ptr<o2::utils::TreeStreamRedirector> mStreamer;
318 void overWriteIntegrationTime()
321 if (integrationTime <= 0) {
324 if (integrationTime > mMaxTimeWeightsMS) {
325 integrationTime = mMaxTimeWeightsMS;
327 LOGP(info,
"Setting maximum integration time for weights to: {}", integrationTime);
328 mTPCScaler.setIonDriftTimeMS(integrationTime);
334 std::vector<InputSpec> inputs;
336 LOGP(info,
"Publishing IDC scalers for space-charge distortion fluctuation correction");
341 LOGP(info,
"Publishing M-shape correction map");
344 auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(
true,
352 std::vector<OutputSpec> outputs;
364 AlgorithmSpec{adaptFromTask<TPCScalerSpec>(ccdbRequest, sclOpts, enableIDCs, enableMShape)},
366 {
"ion-drift-time", VariantType::Float, -1.f, {
"Overwrite ion drift time if a value >0 is provided"}},
367 {
"max-time-for-weights", VariantType::Float, 500.f, {
"Maximum possible integration time in ms when weights are used"}},
368 {
"m-shape-scaling-factor", VariantType::Float, 1.f, {
"Scale M-shape scaler with this value"}},
369 {
"disableWeights", VariantType::Bool,
false, {
"Disable weights for TPC scalers"}},
370 {
"enableStreamer", VariantType::Bool,
false, {
"Enable streaming of M-shape scalers"}},
371 {
"n-threads", VariantType::Int, 4, {
"Number of threads used for the M-shape correction"}},
372 {
"n-knots-y", VariantType::Int, 4, {
"Number of knots in y-direction used for the M-shape correction"}},
373 {
"n-knots-z", VariantType::Int, 4, {
"Number of knots in z-direction used for the M-shape correction"}}}};
Simple interface to the CDB manager.
Helper class to access load maps from CCDB.
Helper for geometry and GRP related CCDB requests.
This class contains the algorithms for calculation the distortions and corrections.
class to create TPC fast space charge correction
Helper class to extract VDrift from different sources.
auto getOrbitResetTimeMS() const
void checkUpdates(o2::framework::ProcessingContext &pc)
bool finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj)
static GRPGeomHelper & instance()
void setRequest(std::shared_ptr< GRPGeomRequest > req)
o2::pmr::FairMQMemoryResource * getMemoryResource(const Output &spec)
CacheId adoptContainer(const Output &, ContainerT &, CacheStrategy, o2::header::SerializationMethod)
DataAllocator & outputs()
The data allocator is used to allocate memory for the output data.
ServiceRegistryRef services()
The services registry associated with this processing context.
float getLumiScale() const
const o2::gpu::TPCFastTransform * getCorrMapSecEdgeFluc() const
void setLumiScaleType(tpc::LumiScaleType v)
void setLumiScaleMode(tpc::LumiScaleMode v)
const o2::gpu::TPCFastTransform * getCorrMapMShape() const
const o2::gpu::TPCFastTransform * getCorrMap() const
void setCheckCTPIDCConsistency(bool v)
void setCorrMapMShape(std::unique_ptr< o2::gpu::TPCFastTransform > &&m)
bool isCorrMapMShapeDummy() const
return returns if the correction map for the M-shape correction is a dummy spline object
const o2::gpu::TPCFastTransform * getCorrMapRef() const
float getInstLumiCTP() const
tpc::LumiScaleMode getLumiScaleMode() const
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
void extractCCDBInputs(o2::framework::ProcessingContext &pc, float tpcScaler=-1.f)
void init(o2::framework::InitContext &ic, bool idcsAvailable)
bool applySecEdgeFlucCorrection() const
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, const o2::tpc::CorrectionMapsGloOpts &gloOpts)
const auto & getSectorEdgeFlucInfo() const
void enableSecEdgeFlucCorrection(const bool enable=true)
static void setNThreads(const int nThreads)
set the number of threads used for some of the calculations
void getCorrections(const DataT x, const DataT y, const DataT z, const Side side, DataT &corrX, DataT &corrY, DataT &corrZ) const
NumericalFields< DataT > getElectricFieldsInterpolator(const Side side) const
void calcEField(const Side side)
void setPotential(int iz, int ir, int iphi, Side side, float val)
setting the potential directly for given vertex
void calcGlobalCorrections(const Fields &formulaStruct, const int type=3)
void poissonSolver(const Side side, const DataT stoppingConvergence=1e-6, const int symmetry=0)
std::array< double, TPCFastTransformGeo::getNumberOfSectors()> SectorScales
std::unique_ptr< TPCFastSpaceChargeCorrection > createFromGlobalCorrection(std::function< void(int roc, double gx, double gy, double gz, double &dgx, double &dgy, double &dgz)> correctionGlobal, const int nKnotsY=10, const int nKnotsZ=20)
creates TPCFastSpaceChargeCorrection object from a continious space charge correction in global coord...
void setNthreads(int n)
_______________ Settings ________________________
static TPCFastSpaceChargeCorrectionHelper * instance()
Singleton.
void addCorrections(o2::gpu::TPCFastSpaceChargeCorrection &mainCorrection, double scale, const std::vector< std::pair< const o2::gpu::TPCFastSpaceChargeCorrection *, double > > &additionalCorrections)
BoundaryPotentialIFC getBoundaryPotential(const double timestamp) const
const auto & getMShapes() const
void setFromTree(TTree &tpcMShapeTree)
set this object from input tree
void endOfStream(EndOfStreamContext &eos) final
void buildMap(ProcessingContext &pc, int64_t timestamp)
TPCScalerSpec(std::shared_ptr< o2::base::GRPGeomRequest > req, const o2::tpc::CorrectionMapsGloOpts &sclOpts, bool enableIDCs, bool enableMShape)
void finaliseCCDB(o2::framework::ConcreteDataMatcher &matcher, void *obj) final
void run(ProcessingContext &pc) final
void init(framework::InitContext &ic) final
float getMeanScaler(double timestamp, o2::tpc::Side side) const
void setIonDriftTimeMS(float ionDriftTimeMS)
void useWeights(bool useWeights)
enable usage of weights
void setFromTree(TTree &tpcScalerTree)
set this object from input tree
void setScalerWeights(const TPCScalerWeights &weights)
setting the weights for the scalers
static void requestCCDBInputs(std::vector< o2::framework::InputSpec > &inputs, bool laser=true, bool itstpcTgl=true)
void extractCCDBInputs(o2::framework::ProcessingContext &pc, bool laser=true, bool itstpcTgl=true)
const VDriftCorrFact & getVDriftObject() const
bool accountCCDBInputs(const o2::framework::ConcreteDataMatcher &matcher, void *obj)
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLdouble GLdouble GLdouble z
constexpr o2::header::DataOrigin gDataOriginCTP
constexpr o2::header::DataOrigin gDataOriginTPC
constexpr double LHCOrbitMUS
Defining ITS Vertex explicitly as messageable.
std::vector< ConfigParamSpec > ccdbParamSpec(std::string const &path, int runDependent, std::vector< CCDBMetadata > metadata={}, int qrate=0)
std::vector< ConfigParamSpec > Options
std::vector< T, fair::mq::pmr::polymorphic_allocator< T > > vector
@ DerivativeMap
map(lumi) = mean_map + lumiScale * (derivativeMap) where derivativeMap = (mean_map_A - mean_map_B)
@ Linear
map(lumi) = (mean_map - referenceMap) * lumiScale + referenceMap
@ NoCorrection
no corrections at all
@ StaticMapOnly
use only static map instead of main map
@ DerivativeMapMC
same DerivativeMap, but for MC
const std::unordered_map< CDBType, const std::string > CDBTypeMap
Storage name in CCDB for each calibration and parameter type.
@ TPCScaler
use TPC scaler for scaling
o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableIDCs, bool enableMShape, const o2::tpc::CorrectionMapsGloOpts &sclOpts)
@ CalScaler
Scaler from IDCs or combined estimator.
@ CalScalerWeights
Weights for scalers.
@ CalMShape
calibration object for M-shape distortions
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
bool enableSecEdgeFlucCorrection
enable correction of sector edge fluctuations
LumiScaleType lumiType
what estimator to used for corrections scaling: 0: no scaling, 1: CTP, 2: IDC
bool checkCTPIDCconsistency
check the selected CTP or IDC scaling source being consistent with mean scaler of the map
bool requestCTPLumi
request CTP Lumi regardless of what is used for corrections scaling
LumiScaleMode lumiMode
what corrections method to use: 0: classical scaling, 1: Using of the derivative map,...
float mFirstTimeStampMS
first timestamp