Skip to content

Commit deba975

Browse files
matthias-kleinershahor02
authored andcommitted
TPC: Adding scaler weights for 1D-distortion fluctuation correction
1 parent 6373d0f commit deba975

7 files changed

Lines changed: 118 additions & 19 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ enum class CDBType {
7878
///
7979
CalTimeSeries, ///< integrated DCAs for longer time interval
8080
CalScaler, ///< Scaler from IDCs or combined estimator
81+
CalScalerWeights, ///< Weights for scalers
8182
///
8283
CorrMapParam, ///< parameters for CorrectionMapsLoader configuration
8384
///
@@ -142,6 +143,7 @@ const std::unordered_map<CDBType, const std::string> CDBTypeMap{
142143
// time series
143144
{CDBType::CalTimeSeries, "TPC/Calib/TimeSeries"},
144145
{CDBType::CalScaler, "TPC/Calib/Scaler"},
146+
{CDBType::CalScalerWeights, "TPC/Calib/ScalerWeights"},
145147
// correction maps loader params
146148
{CDBType::CorrMapParam, "TPC/Calib/CorrMapParam"},
147149
// distortion maps

Detectors/TPC/calibration/include/TPCCalibration/TPCScaler.h

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ namespace o2::tpc
2727
Class for storing the scalers which are used to calculate an estimate for the mean space-charge density for the last ion drift time
2828
*/
2929

30+
struct TPCScalerWeights {
31+
float getWeight(float deltaTime) const;
32+
bool isValid() const { return (mSamplingTimeMS > 0 && !mWeights.empty()); }
33+
float getDurationMS() const { return mSamplingTimeMS * mWeights.size(); }
34+
float mSamplingTimeMS = -1; ///< sampling of the stored weights
35+
float mFirstTimeStampMS = 0; ///< first timestamp
36+
std::vector<float> mWeights; ///< stored weights
37+
38+
ClassDefNV(TPCScalerWeights, 1);
39+
};
40+
3041
class TPCScaler
3142
{
3243
public:
@@ -87,6 +98,9 @@ class TPCScaler
8798
/// \return return first time in ms
8899
double getStartTimeStampMS() const { return mTimeStampMS; }
89100

101+
/// \return return end time in ms
102+
double getEndTimeStampMS(o2::tpc::Side side) const { return mTimeStampMS + getDurationMS(side); }
103+
90104
/// \return returns integration time for each scaler value
91105
float getIntegrationTimeMS() const { return mIntegrationTimeMS; }
92106

@@ -97,16 +111,36 @@ class TPCScaler
97111
/// \param timestamp timestamp for which the last values are used to calculate the mean
98112
float getMeanScaler(double timestamp, o2::tpc::Side side) const;
99113

114+
/// \return returns duration in ms for which the scalers are defined
115+
float getDurationMS(o2::tpc::Side side) const { return mIntegrationTimeMS * getNValues(side); }
116+
117+
/// setting the weights for the scalers
118+
void setScalerWeights(const TPCScalerWeights& weights) { mScalerWeights = weights; }
119+
120+
/// \return returns stored weights for TPC scalers
121+
const auto& getScalerWeights() const { return mScalerWeights; }
122+
123+
/// enable usage of weights
124+
void useWeights(bool useWeights) { mUseWeights = useWeights; }
125+
126+
/// return if weights are used
127+
bool weightsUsed() const { return mUseWeights; }
128+
100129
private:
101-
float mIonDriftTimeMS{200}; ///< ion drift time in ms
102-
int mRun{}; ///< run for which this object is valid
103-
unsigned int mFirstTFOrbit{}; ///< first TF orbit of the stored scalers
104-
double mTimeStampMS{}; ///< time stamp of the first stored values
105-
float mIntegrationTimeMS{1.}; ///< integration time for each stored value in ms
106-
std::vector<float> mScalerA{}; ///< TPC scaler for A-side
107-
std::vector<float> mScalerC{}; ///< TPC scaler for C-side
108-
109-
ClassDefNV(TPCScaler, 1);
130+
float mIonDriftTimeMS{200}; ///< ion drift time in ms
131+
int mRun{}; ///< run for which this object is valid
132+
unsigned int mFirstTFOrbit{}; ///< first TF orbit of the stored scalers
133+
double mTimeStampMS{}; ///< time stamp of the first stored values
134+
float mIntegrationTimeMS{1.}; ///< integration time for each stored value in ms
135+
std::vector<float> mScalerA{}; ///< TPC scaler for A-side
136+
std::vector<float> mScalerC{}; ///< TPC scaler for C-side
137+
TPCScalerWeights mScalerWeights{}; ///< weights for the scalers for A-side
138+
bool mUseWeights{false}; ///< use weights when calculating the mean scaler
139+
140+
// get index to data for given timestamp
141+
int getDataIdx(double timestamp) const { return (timestamp - mTimeStampMS) / mIntegrationTimeMS + 0.5; }
142+
143+
ClassDefNV(TPCScaler, 2);
110144
};
111145

112146
} // namespace o2::tpc

Detectors/TPC/calibration/src/TPCCalibrationLinkDef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,5 @@
113113

114114
#pragma link C++ class o2::tpc::CalculatedEdx + ;
115115
#pragma link C++ class o2::tpc::TPCScaler + ;
116+
#pragma link C++ struct o2::tpc::TPCScalerWeights + ;
116117
#endif

Detectors/TPC/calibration/src/TPCScaler.cxx

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ using namespace o2::tpc;
2424
void TPCScaler::dumpToFile(const char* file, const char* name)
2525
{
2626
TFile out(file, "RECREATE");
27-
TTree tree("TPCScaler", "TPCScaler");
27+
TTree tree(name, name);
28+
tree.SetAutoSave(0);
2829
tree.Branch("TPCScaler", this);
2930
tree.Fill();
3031
out.WriteObject(&tree, name);
@@ -53,7 +54,7 @@ void TPCScaler::setFromTree(TTree& tpcScalerTree)
5354
float TPCScaler::getMeanScaler(double timestamp, o2::tpc::Side side) const
5455
{
5556
// index to data buffer
56-
const int idxData = (timestamp - mTimeStampMS) / mIntegrationTimeMS + 0.5;
57+
const int idxData = getDataIdx(timestamp);
5758
const int nVals = getNValuesIonDriftTime();
5859
const int nValues = getNValues(side);
5960
if ((nVals == 0) || (nVals > nValues)) {
@@ -67,8 +68,44 @@ float TPCScaler::getMeanScaler(double timestamp, o2::tpc::Side side) const
6768

6869
// sump up values from last ion drift time
6970
float sum = 0;
71+
float sumW = 0;
72+
const bool useWeights = mUseWeights && getScalerWeights().isValid();
7073
for (int i = firstIdx; i < lastIdx; ++i) {
71-
sum += getScalers(i, side);
74+
float weight = 1;
75+
if (useWeights) {
76+
const double relTSMS = mTimeStampMS + i * mIntegrationTimeMS - timestamp;
77+
weight = getScalerWeights().getWeight(relTSMS);
78+
}
79+
sum += getScalers(i, side) * weight;
80+
sumW += weight;
81+
}
82+
if (sumW != 0) {
83+
return (sum / sumW);
84+
}
85+
return 0;
86+
}
87+
88+
float TPCScalerWeights::getWeight(float deltaTime) const
89+
{
90+
const float idxF = (deltaTime - mFirstTimeStampMS) / mSamplingTimeMS;
91+
const int idx = idxF;
92+
if ((idx < 0) || (idx > mWeights.size() - 1)) {
93+
LOGP(error, "Index out of range for deltaTime: {} mFirstTimeStampMS: {} mSamplingTimeMS: {}", deltaTime, mFirstTimeStampMS, mSamplingTimeMS);
94+
// set weight 1 to in case it is out of range. This can only happen if the TPC scaler is not valid for given time
95+
return 1;
96+
}
97+
98+
if ((idxF == idx) || (idx == mWeights.size() - 1)) {
99+
// no interpolation required
100+
return mWeights[idx];
101+
} else {
102+
// interpolate scaler
103+
const float y0 = mWeights[idx];
104+
const float y1 = mWeights[idx + 1];
105+
const float x0 = idx;
106+
const float x1 = idx + 1;
107+
const float x = idxF;
108+
const float y = ((y0 * (x1 - x)) + y1 * (x - x0)) / (x1 - x0);
109+
return y;
72110
}
73-
return (sum / nVals);
74111
}

Detectors/TPC/workflow/include/TPCWorkflow/TPCScalerSpec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace o2
1919
namespace tpc
2020
{
2121

22-
o2::framework::DataProcessorSpec getTPCScalerSpec();
22+
o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableWeights);
2323

2424
} // end namespace tpc
2525
} // end namespace o2

Detectors/TPC/workflow/src/TPCScalerSpec.cxx

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace tpc
3434
class TPCScalerSpec : public Task
3535
{
3636
public:
37-
TPCScalerSpec(std::shared_ptr<o2::base::GRPGeomRequest> req) : mCCDBRequest(req){};
37+
TPCScalerSpec(std::shared_ptr<o2::base::GRPGeomRequest> req, bool enableWeights) : mCCDBRequest(req), mEnableWeights(enableWeights){};
3838

3939
void init(framework::InitContext& ic) final
4040
{
@@ -49,6 +49,12 @@ class TPCScalerSpec : public Task
4949
pc.inputs().get<TTree*>("tpcscaler");
5050
}
5151

52+
if (mEnableWeights) {
53+
if (pc.inputs().isValid("tpcscalerw")) {
54+
pc.inputs().get<TPCScalerWeights*>("tpcscalerw");
55+
}
56+
}
57+
5258
if (pc.services().get<o2::framework::TimingInfo>().runNumber != mTPCScaler.getRun()) {
5359
LOGP(error, "Run number {} of processed data and run number {} of loaded TPC scaler doesnt match!", pc.services().get<o2::framework::TimingInfo>().runNumber, mTPCScaler.getRun());
5460
}
@@ -73,19 +79,35 @@ class TPCScalerSpec : public Task
7379
LOGP(info, "Setting ion drift time to: {}", mIonDriftTimeMS);
7480
mTPCScaler.setIonDriftTimeMS(mIonDriftTimeMS);
7581
}
82+
if (mScalerWeights.isValid()) {
83+
LOGP(info, "Setting TPC scaler weights");
84+
mTPCScaler.setScalerWeights(mScalerWeights);
85+
mTPCScaler.useWeights(true);
86+
}
87+
}
88+
if (matcher == ConcreteDataMatcher(o2::header::gDataOriginTPC, "TPCSCALERWCCDB", 0)) {
89+
LOGP(info, "Updating TPC scaler weights");
90+
mScalerWeights = *(TPCScalerWeights*)obj;
91+
mTPCScaler.setScalerWeights(mScalerWeights);
92+
mTPCScaler.useWeights(true);
7693
}
7794
}
7895

7996
private:
8097
std::shared_ptr<o2::base::GRPGeomRequest> mCCDBRequest; ///< info for CCDB request
98+
const bool mEnableWeights{false}; ///< use weights for TPC scalers
99+
TPCScalerWeights mScalerWeights{}; ///< scaler weights
81100
float mIonDriftTimeMS{-1}; ///< ion drift time
82101
TPCScaler mTPCScaler; ///< tpc scaler
83102
};
84103

85-
o2::framework::DataProcessorSpec getTPCScalerSpec()
104+
o2::framework::DataProcessorSpec getTPCScalerSpec(bool enableWeights)
86105
{
87106
std::vector<InputSpec> inputs;
88107
inputs.emplace_back("tpcscaler", o2::header::gDataOriginTPC, "TPCSCALERCCDB", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalScaler), {}, 1)); // time-dependent
108+
if (enableWeights) {
109+
inputs.emplace_back("tpcscalerw", o2::header::gDataOriginTPC, "TPCSCALERWCCDB", 0, Lifetime::Condition, ccdbParamSpec(o2::tpc::CDBTypeMap.at(o2::tpc::CDBType::CalScalerWeights), {}, 0)); // non time-dependent
110+
}
89111

90112
auto ccdbRequest = std::make_shared<o2::base::GRPGeomRequest>(true, // orbitResetTime
91113
false, // GRPECS=true for nHBF per TF
@@ -102,7 +124,7 @@ o2::framework::DataProcessorSpec getTPCScalerSpec()
102124
"tpc-scaler",
103125
inputs,
104126
outputs,
105-
AlgorithmSpec{adaptFromTask<TPCScalerSpec>(ccdbRequest)},
127+
AlgorithmSpec{adaptFromTask<TPCScalerSpec>(ccdbRequest, enableWeights)},
106128
Options{
107129
{"ion-drift-time", VariantType::Float, -1.f, {"Overwrite ion drift time if a value >0 is provided"}}}};
108130
}

Detectors/TPC/workflow/src/tpc-scaler.cxx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ using namespace o2::framework;
2121
void customize(std::vector<o2::framework::ConfigParamSpec>& workflowOptions)
2222
{
2323
// option allowing to set parameters
24-
std::vector<ConfigParamSpec> options{ConfigParamSpec{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}}};
24+
std::vector<ConfigParamSpec> options{
25+
ConfigParamSpec{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings"}},
26+
{"enableWeights", VariantType::Bool, false, {"Enable weights for TPC scalers"}}};
2527
std::swap(workflowOptions, options);
2628
}
2729

@@ -31,6 +33,7 @@ WorkflowSpec defineDataProcessing(ConfigContext const& config)
3133
{
3234
WorkflowSpec workflow;
3335
o2::conf::ConfigurableParam::updateFromString(config.options().get<std::string>("configKeyValues"));
34-
workflow.emplace_back(o2::tpc::getTPCScalerSpec());
36+
const bool enableWeights = config.options().get<bool>("enableWeights");
37+
workflow.emplace_back(o2::tpc::getTPCScalerSpec(enableWeights));
3538
return workflow;
3639
}

0 commit comments

Comments
 (0)