Skip to content

Commit 463e36e

Browse files
TPC: Adding loading of distortions maps from CCDB for MC (#12300)
* TPC: Adding loading of distortions maps from CCDB for MC Distortions from pre-calculated maps can be loaded from CCDB with the option --tpc-simulate-distortions in the o2-sim-digitizer-workflow: o2-sim-digitizer-workflow $ARGS_ALL -b --tpc-lanes 1 --onlyDet TPC --tpc-simulate-distortions * Implement scaling of distortions in MC - Scaling of the distortions can be enabled with `o2-sim-digitizer-workflow --tpc-distortion-type 2`, where the lumi is taken from `TPCCorrMap.lumiInst`. - space charge: adding meta data for scaling - In reconstruction the --corrmap-lumi-mode 2 should be used for MC and luminosity set via TPCCorrMap.lumiInst - Fixing inverse transform for scalMode 1 and 2! - other small changes * renaming CCDB path for MC correction map to be more consistent * Adding lumi source as meta data
1 parent c14c590 commit 463e36e

14 files changed

Lines changed: 249 additions & 111 deletions

File tree

Detectors/TPC/base/include/TPCBase/CDBTypes.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,18 @@ enum class CDBType {
7171
///
7272
CalCorrMap, ///< Cluster correction map (high IR rate distortions)
7373
CalCorrMapRef, ///< Cluster correction reference map (static distortions)
74+
CalCorrMapMC, ///< Cluster correction map (high IR rate distortions) for MC
75+
CalCorrDerivMapMC, ///< Cluster correction reference map (static distortions) for MC
7476
///
7577
CalCorrDerivMap, ///< Cluster correction map (derivative map)
7678
///
7779
CalTimeSeries, ///< integrated DCAs for longer time interval
7880
CalScaler, ///< Scaler from IDCs or combined estimator
7981
///
8082
CorrMapParam, ///< parameters for CorrectionMapsLoader configuration
83+
///
84+
DistortionMapMC, ///< full distortions (static + IR dependant) for MC used in the digitizer
85+
DistortionMapDerivMC ///< derivative distortions for MC used in the digitizer for scaling
8186
};
8287

8388
/// Storage name in CCDB for each calibration and parameter type
@@ -129,13 +134,19 @@ const std::unordered_map<CDBType, const std::string> CDBTypeMap{
129134
// correction maps
130135
{CDBType::CalCorrMap, "TPC/Calib/CorrectionMapV2"},
131136
{CDBType::CalCorrMapRef, "TPC/Calib/CorrectionMapRefV2"},
137+
// correction maps for MC
138+
{CDBType::CalCorrMapMC, "TPC/Calib/CorrectionMapMCV2"},
139+
{CDBType::CalCorrDerivMapMC, "TPC/Calib/CorrectionMapDerivativeMCV2"},
132140
// derivative map correction
133141
{CDBType::CalCorrDerivMap, "TPC/Calib/CorrectionMapDerivativeV2"},
134142
// time series
135143
{CDBType::CalTimeSeries, "TPC/Calib/TimeSeries"},
136144
{CDBType::CalScaler, "TPC/Calib/Scaler"},
137145
// correction maps loader params
138146
{CDBType::CorrMapParam, "TPC/Calib/CorrMapParam"},
147+
// distortion maps
148+
{CDBType::DistortionMapMC, "TPC/Calib/DistortionMapMC"},
149+
{CDBType::DistortionMapDerivMC, "TPC/Calib/DistortionMapDerivativeMC"},
139150
};
140151

141152
} // namespace o2::tpc

Detectors/TPC/calibration/src/CorrectionMapsLoader.cxx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,16 @@ void CorrectionMapsLoader::extractCCDBInputs(ProcessingContext& pc)
6767
//________________________________________________________
6868
void CorrectionMapsLoader::requestCCDBInputs(std::vector<InputSpec>& inputs, std::vector<o2::framework::ConfigParamSpec>& options, const CorrectionMapsLoaderGloOpts& gloOpts)
6969
{
70-
addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent
7170
if (gloOpts.lumiMode == 0) {
71+
addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent
7272
addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapRef), {}, 0)}); // load once
7373
} else if (gloOpts.lumiMode == 1) {
74+
addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMap), {}, 1)}); // time-dependent
7475
addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMap), {}, 1)}); // time-dependent
76+
} else if (gloOpts.lumiMode == 2) {
77+
// for MC corrections
78+
addInput(inputs, {"tpcCorrMap", "TPC", "CorrMap", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrMapMC), {}, 1)}); // time-dependent
79+
addInput(inputs, {"tpcCorrMapRef", "TPC", "CorrMapRef", 0, Lifetime::Condition, ccdbParamSpec(CDBTypeMap.at(CDBType::CalCorrDerivMapMC), {}, 1)}); // time-dependent
7580
} else {
7681
LOG(fatal) << "Correction mode unknown! Choose either 0 (default) or 1 (derivative map) for flag corrmap-lumi-mode.";
7782
}
@@ -99,7 +104,7 @@ void CorrectionMapsLoader::addGlobalOptions(std::vector<ConfigParamSpec>& option
99104
{
100105
// these are options which should be added at the workflow level, since they modify the inputs of the devices
101106
addOption(options, ConfigParamSpec{"lumi-type", o2::framework::VariantType::Int, 0, {"1 = require CTP lumi for TPC correction scaling, 2 = require TPC scalers for TPC correction scaling"}});
102-
addOption(options, ConfigParamSpec{"corrmap-lumi-mode", o2::framework::VariantType::Int, 0, {"scaling mode: (default) 0 = static + scale * full; 1 = full + scale * derivative"}});
107+
addOption(options, ConfigParamSpec{"corrmap-lumi-mode", o2::framework::VariantType::Int, 0, {"scaling mode: (default) 0 = static + scale * full; 1 = full + scale * derivative; 2 = full + scale * derivative (for MC)"}});
103108
}
104109

105110
//________________________________________________________

Detectors/TPC/simulation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ o2_add_library(TPCSimulation
2222
src/SAMPAProcessing.cxx
2323
src/IDCSim.cxx
2424
PUBLIC_LINK_LIBRARIES O2::DetectorsBase O2::SimulationDataFormat
25-
O2::TPCBase O2::TPCSpaceCharge
25+
O2::TPCBase O2::TPCSpaceCharge O2::TPCCalibration
2626
ROOT::Physics)
2727

2828
o2_target_root_dictionary(TPCSimulation

Detectors/TPC/simulation/include/TPCSimulation/Digitizer.h

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ enum class SCDistortionType : int;
5353
class Digitizer
5454
{
5555
public:
56-
using SC = SpaceCharge<double>;
56+
using SC = SpaceCharge<float>;
5757

5858
/// Default constructor
5959
Digitizer();
@@ -121,6 +121,9 @@ class Digitizer
121121
/// \param spaceCharge unique pointer to spaceCharge object
122122
void setUseSCDistortions(SC* spaceCharge);
123123

124+
/// \param spaceCharge unique pointer to spaceCharge object
125+
void setSCDistortionsDerivative(SC* spaceCharge);
126+
124127
/// Enable the use of space-charge distortions by providing global distortions and global corrections stored in a ROOT file
125128
/// The storage of the values should be done by the methods provided in the SpaceCharge class
126129
/// \param file containing distortions
@@ -129,17 +132,26 @@ class Digitizer
129132
void setVDrift(float v) { mVDrift = v; }
130133
void setTDriftOffset(float t) { mTDriftOffset = t; }
131134

135+
void setDistortionScaleType(int distortionScaleType) { mDistortionScaleType = distortionScaleType; }
136+
int getDistortionScaleType() const { return mDistortionScaleType; }
137+
void setLumiScaleFactor();
138+
void setMeanLumiDistortions(float meanLumi);
139+
void setMeanLumiDistortionsDerivative(float meanLumi);
140+
132141
private:
133-
DigitContainer mDigitContainer; ///< Container for the Digits
134-
std::unique_ptr<SC> mSpaceCharge; ///< Handler of space-charge distortions
135-
Sector mSector = -1; ///< ID of the currently processed sector
136-
double mEventTime = 0.f; ///< Time of the currently processed event
137-
double mOutputDigitTimeOffset = 0; ///< Time of the first IR sampled in the digitizer
138-
float mVDrift = 0; ///< VDrift for current timestamp
139-
float mTDriftOffset = 0; ///< drift time additive offset in \mus
140-
bool mIsContinuous; ///< Switch for continuous readout
141-
bool mUseSCDistortions = false; ///< Flag to switch on the use of space-charge distortions
142-
ClassDefNV(Digitizer, 1);
142+
DigitContainer mDigitContainer; ///< Container for the Digits
143+
std::unique_ptr<SC> mSpaceCharge; ///< Handler of full distortions (static + IR dependant)
144+
std::unique_ptr<SC> mSpaceChargeDer; ///< Handler of reference static distortions
145+
Sector mSector = -1; ///< ID of the currently processed sector
146+
double mEventTime = 0.f; ///< Time of the currently processed event
147+
double mOutputDigitTimeOffset = 0; ///< Time of the first IR sampled in the digitizer
148+
float mVDrift = 0; ///< VDrift for current timestamp
149+
float mTDriftOffset = 0; ///< drift time additive offset in \mus
150+
bool mIsContinuous; ///< Switch for continuous readout
151+
bool mUseSCDistortions = false; ///< Flag to switch on the use of space-charge distortions
152+
int mDistortionScaleType = 0; ///< type=0: no scaling of distortions, type=1 distortions without any scaling, type=2 distortions scaling with lumi
153+
float mLumiScaleFactor = 0; ///< value used to scale the derivative map
154+
ClassDefNV(Digitizer, 2);
143155
};
144156
} // namespace tpc
145157
} // namespace o2

Detectors/TPC/simulation/src/Digitizer.cxx

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "TPCBase/CDBInterface.h"
2828
#include "TPCSpaceCharge/SpaceCharge.h"
2929
#include "TPCBase/Mapper.h"
30+
#include "TPCCalibration/CorrMapParam.h"
3031

3132
#include <fairlogger/Logger.h>
3233

@@ -40,10 +41,6 @@ Digitizer::Digitizer() = default;
4041

4142
void Digitizer::init()
4243
{
43-
// Calculate distortion lookup tables if initial space-charge density is provided
44-
if (mUseSCDistortions) {
45-
mSpaceCharge->init();
46-
}
4744
auto& gemAmplification = GEMAmplification::instance();
4845
gemAmplification.updateParameters();
4946
auto& electronTransport = ElectronTransport::instance();
@@ -83,8 +80,10 @@ void Digitizer::process(const std::vector<o2::tpc::HitGroup>& hits,
8380
GlobalPosition3D posEle(eh.GetX(), eh.GetY(), eh.GetZ());
8481

8582
// Distort the electron position in case space-charge distortions are used
86-
if (mUseSCDistortions) {
83+
if (mDistortionScaleType == 1) {
8784
mSpaceCharge->distortElectron(posEle);
85+
} else if (mDistortionScaleType == 2) {
86+
mSpaceCharge->distortElectron(posEle, mSpaceChargeDer.get(), mLumiScaleFactor);
8887
}
8988

9089
/// Remove electrons that end up more than three sigma of the hit's average diffusion away from the current sector
@@ -190,6 +189,15 @@ void Digitizer::setUseSCDistortions(SC* spaceCharge)
190189
{
191190
mUseSCDistortions = true;
192191
mSpaceCharge.reset(spaceCharge);
192+
mSpaceCharge->initAfterReadingFromFile();
193+
mSpaceCharge->printMetaData();
194+
}
195+
196+
void Digitizer::setSCDistortionsDerivative(SC* spaceCharge)
197+
{
198+
mSpaceChargeDer.reset(spaceCharge);
199+
mSpaceChargeDer->initAfterReadingFromFile();
200+
mSpaceChargeDer->printMetaData();
193201
}
194202

195203
void Digitizer::setUseSCDistortions(std::string_view finp)
@@ -213,3 +221,19 @@ void Digitizer::setStartTime(double time)
213221
sampaProcessing.updateParameters(mVDrift);
214222
mDigitContainer.setStartTime(sampaProcessing.getTimeBinFromTime(time - mOutputDigitTimeOffset));
215223
}
224+
225+
void Digitizer::setLumiScaleFactor()
226+
{
227+
mLumiScaleFactor = (CorrMapParam::Instance().lumiInst - mSpaceCharge->getMeanLumi()) / mSpaceChargeDer->getMeanLumi();
228+
LOGP(info, "Setting Lumi scale factor: lumiInst: {} lumi mean: {} lumi mean derivative: {} lumi scale factor: {}", CorrMapParam::Instance().lumiInst, mSpaceCharge->getMeanLumi(), mSpaceChargeDer->getMeanLumi(), mLumiScaleFactor);
229+
}
230+
231+
void Digitizer::setMeanLumiDistortions(float meanLumi)
232+
{
233+
mSpaceCharge->setMeanLumi(meanLumi);
234+
}
235+
236+
void Digitizer::setMeanLumiDistortionsDerivative(float meanLumi)
237+
{
238+
mSpaceChargeDer->setMeanLumi(meanLumi);
239+
}

Detectors/TPC/spacecharge/include/TPCSpaceCharge/SpaceCharge.h

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,9 @@ class SpaceCharge
572572

573573
/// Distort electron position using distortion lookup tables
574574
/// \param point 3D coordinates of the electron
575-
void distortElectron(GlobalPosition3D& point) const;
575+
/// \param scSCale other sc object which is used for scaling of the distortions
576+
/// \param scale scaling value
577+
void distortElectron(GlobalPosition3D& point, const SpaceCharge<DataT>* scSCale = nullptr, float scale = 0) const;
576578

577579
/// set the distortions directly from a look up table
578580
/// \param distdZ distortions in z direction
@@ -1170,12 +1172,24 @@ class SpaceCharge
11701172
/// substract global corrections from other sc object (global corrections -= other.global corrections)
11711173
/// can be used to calculate the derivative: (this - other)/normalization
11721174
/// for normalization see scaleCorrections()
1173-
void substractGlobalCorrections(const SpaceCharge<DataT>& otherSC, const Side side);
1175+
void subtractGlobalCorrections(const SpaceCharge<DataT>& otherSC, const Side side);
1176+
1177+
/// substract global distortions from other sc object (global distortions -= other.global distortions)
1178+
/// can be used to calculate the derivative: (this - other)/normalization
1179+
void subtractGlobalDistortions(const SpaceCharge<DataT>& otherSC, const Side side);
11741180

11751181
/// scale corrections by factor
11761182
/// \param scaleFac global corrections are multiplied by this factor
11771183
void scaleCorrections(const float scaleFac, const Side side);
11781184

1185+
/// setting meta data for this object
1186+
void setMetaData(const SCMetaData& meta) { mMeta = meta; }
1187+
const auto& getMetaData() const { return mMeta; }
1188+
void printMetaData() const { mMeta.print(); }
1189+
float getMeanLumi() const { return mMeta.meanLumi; }
1190+
void setMeanLumi(float lumi) { mMeta.meanLumi = lumi; }
1191+
void initAfterReadingFromFile();
1192+
11791193
private:
11801194
ParamSpaceCharge mParamGrid{}; ///< parameters of the grid on which the calculations are performed
11811195
inline static int sNThreads{getOMPMaxThreads()}; ///<! number of threads which are used during the calculations
@@ -1229,6 +1243,7 @@ class SpaceCharge
12291243
AnalyticalDistCorr<DataT> mAnaDistCorr; ///< analytical distortions and corrections
12301244
bool mUseAnaDistCorr{false}; ///< flag if analytical distortions will be used in the distortElectron() and getCorrections() function
12311245
BField mBField{}; ///<! B-Field ///<! B field
1246+
SCMetaData mMeta{}; ///< meta data
12321247

12331248
/// check if the addition of two values are close to zero.
12341249
/// This avoids errors during the integration of the electric fields when the sum of the nominal electric with the electric field from the space charge is close to 0 (usually this is not the case!).
@@ -1330,7 +1345,7 @@ class SpaceCharge
13301345
/// set potentialsdue to ROD misalignment
13311346
void initRodAlignmentVoltages(const MisalignmentType misalignmentType, const FCType fcType, const int sector, const Side side, const float deltaPot);
13321347

1333-
ClassDefNV(SpaceCharge, 5);
1348+
ClassDefNV(SpaceCharge, 6);
13341349
};
13351350

13361351
} // namespace tpc

Detectors/TPC/spacecharge/include/TPCSpaceCharge/SpaceChargeHelpers.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,41 @@
2323
#include "TPCSpaceCharge/TriCubic.h"
2424
#include "DataFormatsTPC/Defs.h"
2525
#include "TFormula.h"
26+
#include "Framework/Logger.h"
2627

2728
namespace o2
2829
{
2930
namespace tpc
3031
{
3132

33+
struct SCMetaData {
34+
35+
enum LumiType {
36+
CTP = 0,
37+
IDC = 1
38+
};
39+
40+
void print() const
41+
{
42+
const std::array<std::string, 2> collisionTypes{"PP", "Pb-Pb"};
43+
const std::array<std::string, 2> slumiSource{"CTP", "IDC"};
44+
if (collisionType < collisionTypes.size()) {
45+
LOGP(info, "meanLumi: {}, source of lumi: {}, IR: {}kHz, run: {}, collisionType {}", meanLumi, slumiSource[lumiSource], ir, run, collisionTypes[collisionType]);
46+
} else {
47+
LOGP(info, "Specified collision type {} not allowed", collisionType);
48+
}
49+
}
50+
51+
float meanLumi = 0; ///< mean lumi the sc object corresponds to
52+
float ir = 0; ///< IR
53+
int run = 0; ///< run number this object anchored to to
54+
int collisionType = 0; ///< 0=PP, 1-Pb-Pb
55+
LumiType lumiSource{}; ///< source of luminosity
56+
57+
private:
58+
ClassDefNV(SCMetaData, 1);
59+
};
60+
3261
///
3362
/// this class contains an analytical description of the space charge, potential and the electric fields.
3463
/// The analytical functions can be used to test the poisson solver and the caluclation of distortions/corrections.

0 commit comments

Comments
 (0)