Skip to content

Commit

Permalink
TPC: Adding possibility to correct for V-shape distortions
Browse files Browse the repository at this point in the history
The time dependent distortions that we observe in the DCAs on the A-side
can be similarly corrected as the space-charge distortions. For this a
new model is added which we can linearly scale up or down according to current
V-shape observed in DCA.

Further changes:
- TPC IDC scaler adding helper function to split the scalers, when writing to
file
- fixing timestamp in TPC time series

Adding v-shape correction object to several places

Adding option to recalculate the inverse correction during reconstruction

Pass needed options to tpc-scalers workflow from dpl-workflow.sh

connect TPCScalerSpec to dependent standalone workflows

Adding option to load correction map from local macro

Adding updated v-shape scaler with z-pos

Updating v-shape calibration procedure

temporary fix compiling

Renaming V-shape tp M-shape
  • Loading branch information
matthias-kleiner committed Jan 12, 2024
1 parent d40b3a0 commit 8ed5bbf
Show file tree
Hide file tree
Showing 39 changed files with 766 additions and 78 deletions.
5 changes: 5 additions & 0 deletions Detectors/Align/Workflow/src/barrel-alignment-workflow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "TPCReaderWorkflow/TrackReaderSpec.h"
#include "TPCReaderWorkflow/ClusterReaderSpec.h"
#include "TPCWorkflow/ClusterSharingMapSpec.h"
#include "TPCWorkflow/TPCScalerSpec.h"
#include "TPCCalibration/CorrectionMapsLoader.h"
#include "TOFWorkflowIO/ClusterReaderSpec.h"
#include "TOFWorkflowIO/TOFMatchedReaderSpec.h"
Expand Down Expand Up @@ -147,6 +148,10 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
o2::conf::ConfigurableParam::writeINI("o2_barrel_alignment_configuration.ini");
}

if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get<bool>("disable-root-input")) {
specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection));
}

specs.emplace_back(o2::align::getBarrelAlignmentSpec(srcMP, src, dets, skipDetClusters, enableCosmic, postprocess, useMC, sclOpt));
// RS FIXME: check which clusters are really needed
if (!postprocess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "ITSMFTWorkflow/ClusterReaderSpec.h"
#include "TPCReaderWorkflow/TrackReaderSpec.h"
#include "TPCReaderWorkflow/ClusterReaderSpec.h"
#include "TPCWorkflow/TPCScalerSpec.h"
#include "TPCWorkflow/ClusterSharingMapSpec.h"
#include "TOFWorkflowIO/ClusterReaderSpec.h"
#include "TOFWorkflowIO/TOFMatchedReaderSpec.h"
Expand Down Expand Up @@ -101,6 +102,9 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
}
GID::mask_t srcCl = src;
GID::mask_t dummy;
if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get<bool>("disable-root-input")) {
specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection));
}
specs.emplace_back(o2::globaltracking::getCosmicsMatchingSpec(src, useMC, sclOpt));

o2::globaltracking::InputHelper::addInputSpecs(configcontext, specs, src, src, src, useMC, dummy); // clusters MC is not needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "GlobalTrackingWorkflowHelpers/InputHelper.h"
#include "ITSWorkflow/TrackReaderSpec.h"
#include "TPCReaderWorkflow/TrackReaderSpec.h"
#include "TPCWorkflow/TPCScalerSpec.h"
#include "TOFWorkflowIO/TOFMatchedReaderSpec.h"
#include "TOFWorkflowIO/ClusterReaderSpec.h"
#include "ReconstructionDataFormats/GlobalTrackID.h"
Expand Down Expand Up @@ -96,7 +97,9 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
src = src | GID::getSourcesMask("CTP");
}
WorkflowSpec specs;

if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get<bool>("disable-root-input")) {
specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection));
}
specs.emplace_back(o2::vertexing::getSecondaryVertexingSpec(src, enableCasc, enable3body, enableStrTr, enableCCDBParams, useMC, sclOpt));

// only TOF clusters are needed if TOF is involved, no clusters MC needed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "TSystem.h"
#include "DetectorsBase/DPLWorkflowUtils.h"
#include "TPCCalibration/CorrectionMapsLoader.h"
#include "TPCWorkflow/TPCScalerSpec.h"

using namespace o2::framework;
using DetID = o2::detectors::DetID;
Expand Down Expand Up @@ -167,7 +168,9 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
specs.push_back(s);
}
}

if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get<bool>("disable-root-input")) {
specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection));
}
specs.emplace_back(o2::globaltracking::getTOFMatcherSpec(src, useMC, useFIT, refitTPCTOF, strict, extratolerancetrd, writeMatchable, sclOpt, nLanes)); // doTPCrefit not yet supported (need to load TPC clusters?)

if (!disableRootOut) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// or submit itself to any jurisdiction.

#include "TPCWorkflow/ClusterSharingMapSpec.h"
#include "TPCWorkflow/TPCScalerSpec.h"
#include "GlobalTrackingWorkflow/TPCITSMatchingSpec.h"
#include "GlobalTrackingWorkflow/TrackWriterTPCITSSpec.h"
#include "GlobalTrackingWorkflowHelpers/InputHelper.h"
Expand Down Expand Up @@ -87,6 +88,9 @@ WorkflowSpec defineDataProcessing(o2::framework::ConfigContext const& configcont
}

o2::framework::WorkflowSpec specs;
if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get<bool>("disable-root-input")) {
specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection));
}
specs.emplace_back(o2::globaltracking::getTPCITSMatchingSpec(srcL, useFT0, calib, !GID::includesSource(GID::TPC, src), useMC, sclOpt));

if (!configcontext.options().get<bool>("disable-root-output")) {
Expand Down
1 change: 1 addition & 0 deletions Detectors/GlobalTrackingWorkflow/study/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ o2_add_library(GlobalTrackingStudy
O2::GlobalTrackingWorkflowHelpers
O2::DataFormatsGlobalTracking
O2::DetectorsVertexing
O2::TPCWorkflow
O2::SimulationDataFormat)

o2_add_executable(study-workflow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "GlobalTrackingWorkflowHelpers/InputHelper.h"
#include "DetectorsRaw/HBFUtilsInitializer.h"
#include "TPCCalibration/CorrectionMapsLoader.h"
#include "TPCWorkflow/TPCScalerSpec.h"

using namespace o2::framework;
using GID = o2::dataformats::GlobalTrackID;
Expand Down Expand Up @@ -70,6 +71,9 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
}
o2::globaltracking::InputHelper::addInputSpecs(configcontext, specs, srcCls, srcTrc, srcTrc, useMC);
o2::globaltracking::InputHelper::addInputSpecsPVertex(configcontext, specs, useMC); // P-vertex is always needed
if (sclOpt.needTPCScalersWorkflow() && !configcontext.options().get<bool>("disable-root-input")) {
specs.emplace_back(o2::tpc::getTPCScalerSpec(sclOpt.lumiType == 2, sclOpt.enableMShapeCorrection));
}
specs.emplace_back(o2::trackstudy::getTPCTrackStudySpec(srcTrc, srcCls, useMC, sclOpt));

// configure dpl timer to inject correct firstTForbit: start from the 1st orbit of TF containing 1st sampled orbit
Expand Down
2 changes: 2 additions & 0 deletions Detectors/TPC/base/include/TPCBase/CDBTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ enum class CDBType {
CalTimeSeries, ///< integrated DCAs for longer time interval
CalScaler, ///< Scaler from IDCs or combined estimator
CalScalerWeights, ///< Weights for scalers
CalMShape, ///< calibration object for M-shape distortions
///
CorrMapParam, ///< parameters for CorrectionMapsLoader configuration
///
Expand Down Expand Up @@ -144,6 +145,7 @@ const std::unordered_map<CDBType, const std::string> CDBTypeMap{
{CDBType::CalTimeSeries, "TPC/Calib/TimeSeries"},
{CDBType::CalScaler, "TPC/Calib/Scaler"},
{CDBType::CalScalerWeights, "TPC/Calib/ScalerWeights"},
{CDBType::CalMShape, "TPC/Calib/MShapeScaler"},
// correction maps loader params
{CDBType::CorrMapParam, "TPC/Calib/CorrMapParam"},
// distortion maps
Expand Down
4 changes: 3 additions & 1 deletion Detectors/TPC/calibration/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ o2_add_library(TPCCalibration
src/CalculatedEdx.cxx
src/TPCScaler.cxx
src/CorrMapParam.cxx
src/TPCMShapeScaler.cxx
PUBLIC_LINK_LIBRARIES O2::DataFormatsTPC O2::TPCBase
O2::TPCReconstruction ROOT::Minuit
Microsoft.GSL::GSL
Expand Down Expand Up @@ -107,7 +108,8 @@ o2_target_root_dictionary(TPCCalibration
include/TPCCalibration/TPCFastSpaceChargeCorrectionHelper.h
include/TPCCalibration/CalculatedEdx.h
include/TPCCalibration/TPCScaler.h
include/TPCCalibration/CorrMapParam.h)
include/TPCCalibration/CorrMapParam.h
include/TPCCalibration/TPCMShapeScaler.h)

o2_add_test_root_macro(macro/comparePedestalsAndNoise.C
PUBLIC_LINK_LIBRARIES O2::TPCBase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ namespace tpc
{

struct CorrectionMapsLoaderGloOpts {
int lumiType = 0;
int lumiMode = 0;
int lumiType = 0; ///< 0: no scaling, 1: CTP, 2: IDC
int lumiMode = 0; ///< 0: classical scaling, 1: Using of the derivative map, 2: Using of the derivative map for MC
bool enableMShapeCorrection = false;

bool needTPCScalersWorkflow() const
{
return lumiType == 2 || enableMShapeCorrection;
}
};

class CorrectionMapsLoader : public o2::gpu::CorrectionMapsHelper
Expand All @@ -55,6 +61,7 @@ class CorrectionMapsLoader : public o2::gpu::CorrectionMapsHelper
void updateVDrift(float vdriftCorr, float vdrifRef, float driftTimeOffset = 0);
void init(o2::framework::InitContext& ic);
void copySettings(const CorrectionMapsLoader& src);
void updateInverse(); /// recalculate inverse correction

static void requestCCDBInputs(std::vector<o2::framework::InputSpec>& inputs, std::vector<o2::framework::ConfigParamSpec>& options, const CorrectionMapsLoaderGloOpts& gloOpts);
static void addGlobalOptions(std::vector<o2::framework::ConfigParamSpec>& options);
Expand All @@ -65,8 +72,9 @@ class CorrectionMapsLoader : public o2::gpu::CorrectionMapsHelper
static void addOption(std::vector<o2::framework::ConfigParamSpec>& options, o2::framework::ConfigParamSpec&& osp);
static void addInput(std::vector<o2::framework::InputSpec>& inputs, o2::framework::InputSpec&& isp);

float mInstLumiFactor = 1.0; // multiplicative factor for inst. lumi
int mCTPLumiSource = 0; // 0: main, 1: alternative CTP lumi source
float mInstLumiFactor = 1.0; // multiplicative factor for inst. lumi
int mCTPLumiSource = 0; // 0: main, 1: alternative CTP lumi source
int mNthreadsInv = 1; // number of threads used for calculating the inverse correction
#endif
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ class TPCFastSpaceChargeCorrectionHelper

void testGeometry(const TPCFastTransformGeo& geo) const;

/// initialise inverse transformation
void initInverse(o2::gpu::TPCFastSpaceChargeCorrection& correction, bool prn);

/// initialise inverse transformation from linear combination of several input corrections
void initInverse(std::vector<o2::gpu::TPCFastSpaceChargeCorrection*>& corrections, const std::vector<float> scaling, bool prn);

private:
/// geometry initialization
void initGeometry();
Expand All @@ -107,9 +113,6 @@ class TPCFastSpaceChargeCorrectionHelper
/// initialise max drift length
void initMaxDriftLength(o2::gpu::TPCFastSpaceChargeCorrection& correction, bool prn);

/// initialise inverse transformation
void initInverse(o2::gpu::TPCFastSpaceChargeCorrection& correction, bool prn);

static TPCFastSpaceChargeCorrectionHelper* sInstance; ///< singleton instance
bool mIsInitialized = 0; ///< initialization flag
int mNthreads = 1; ///< n of threads to use
Expand Down
99 changes: 99 additions & 0 deletions Detectors/TPC/calibration/include/TPCCalibration/TPCMShapeScaler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

/// \file TPCMShapeScaler.h
/// \author Matthias Kleiner <[email protected]>

#ifndef ALICEO2_TPC_TPCMSHAPESCALER
#define ALICEO2_TPC_TPCMSHAPESCALER

#include "DataFormatsTPC/Defs.h"
#include <vector>

class TTree;

namespace o2::tpc
{

/*
Class for storing the scalers (obtained from DCAs) which are used to correct for the M-shape distortions
*/

struct TPCMShape {
double getEndTime(float sampling) const { return mStartTimeMS + mScalerA.size() * sampling; }
double mStartTimeMS; ///< start time of the M-shape
std::vector<float> mScalerA; ///< DCA or whatever
std::vector<float> mZPosition; ///< z-position of the delta potential
bool operator<(const TPCMShape& r) const { return mStartTimeMS < r.mStartTimeMS; }
ClassDefNV(TPCMShape, 1);
};

class TPCMShapeScaler
{
public:
/// default constructor
TPCMShapeScaler() = default;

/// \return returns number of stored M-shapes
int getNValues() const { return mMShape.size(); }

/// setting the scalers <time, value>
void setScaler(const std::vector<double>& time, const std::vector<float>& scaler, const std::vector<float>& zpos);

/// \return returns run number for which this object is valid
void setRun(int run) { mRun = run; }

/// dump this object to a file
/// \param file output file
void dumpToFile(const char* file, const char* name);

/// load parameters from input file (which were written using the writeToFile method)
/// \param inpf input file
void loadFromFile(const char* inpf, const char* name);

/// set this object from input tree
void setFromTree(TTree& tpcScalerTree);

/// set sampling time of the stored values
float setSamplingTimeMS(float t) { return mSamplingTimeMS = t; }

/// adding a M-shape
void addMShape(const TPCMShape& vshape) { mMShape.emplace_back(); }

/// \return returns run number for which this object is valid
int getRun() const { return mRun; }

/// \return returns M-shape scaling value for given timestamp
/// \param timestamp timestamp for which the scaler is queried
std::pair<float, float> getScaler(const double timestamp) const;

/// \return returns sampling time of the stored values
float getSamplingTimeMS() const { return mSamplingTimeMS; }

/// \return returns all stored M-shapes
const auto& getMShapes() const { return mMShape; }

private:
int mRun{}; ///< run for which this object is valid
float mSamplingTimeMS = 1; ///< sampling time of the M-shape scalers
std::vector<TPCMShape> mMShape; ///< vector containing the M-shapes

/// if distance to neighbouring data is larger than sampling time return 0 for the scaling
bool checkDeltaTime(double deltaTime) const { return deltaTime < 1.5 * mSamplingTimeMS; }

/// return linear interpolated value
float getVal(float x, float x0, float x1, float y0, float y1) const { return (y0 * (x1 - x) + y1 * (x - x0)) / (x1 - x0); }

ClassDefNV(TPCMShapeScaler, 1);
};

} // namespace o2::tpc
#endif
22 changes: 20 additions & 2 deletions Detectors/TPC/calibration/include/TPCCalibration/TPCScaler.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ class TPCScaler
/// \return returns number of stored TPC scaler values
int getNValues(o2::tpc::Side side) const { return (side == o2::tpc::Side::A ? mScalerA.size() : mScalerC.size()); }

/// set the parameters for the coefficients of the polynomial
/// \param params parameter for the coefficients
/// set TPC scalers
/// \param values scaling values
void setScaler(const std::vector<float>& values, const o2::tpc::Side side) { (side == o2::tpc::Side::A ? (mScalerA = values) : (mScalerC = values)); }

/// \return returns ion drift time in ms
Expand All @@ -73,6 +73,19 @@ class TPCScaler
/// \param file output file
void dumpToFile(const char* file, const char* name);

/// dump this object to a file for a given time range
/// \param file output file
/// \param startTime start time stamp in ms of the dumped object
/// \param endTime end time stamp in ms of the dumped object (if endTimeMS=-1 the end of the stored data is used)
void dumpToFile(const char* file, const char* name, double startTimeMS, double endTimeMS);

/// dump this object to several file each containing the scalers for n minutes
/// \param file output file
/// \param minutesPerObject minutes each output file is covering
/// \param marginMS additional margin to the beginning of each object (should be >= getIonDriftTimeMS())
/// \param marginCCDBMinutes margin for CCDB timestamp
void dumpToFileSlices(const char* file, const char* name, int minutesPerObject, float marginMS = 500, float marginCCDBMinutes = 1);

/// load parameters from input file (which were written using the writeToFile method)
/// \param inpf input file
void loadFromFile(const char* inpf, const char* name);
Expand Down Expand Up @@ -114,6 +127,11 @@ class TPCScaler
/// \return returns duration in ms for which the scalers are defined
float getDurationMS(o2::tpc::Side side) const { return mIntegrationTimeMS * getNValues(side); }

/// clamp scaler values
/// \param minThreshold minimum accepted scaler value
/// \param maxThreshold maximum accepted scaler value
void clampScalers(float minThreshold, float maxThreshold, Side side);

/// setting the weights for the scalers
void setScalerWeights(const TPCScalerWeights& weights) { mScalerWeights = weights; }

Expand Down
Loading

0 comments on commit 8ed5bbf

Please sign in to comment.