Skip to content

Commit 9849cbc

Browse files
committed
add TPC occupancy est. to SVStudy output
1 parent 89fbec2 commit 9849cbc

File tree

4 files changed

+110
-10
lines changed

4 files changed

+110
-10
lines changed

Detectors/GlobalTrackingWorkflow/study/include/GlobalTrackingStudy/SVStudy.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace o2::svstudy
2323
{
2424
/// create a processor spec
25-
o2::framework::DataProcessorSpec getSVStudySpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, bool useMC);
25+
o2::framework::DataProcessorSpec getSVStudySpec(o2::dataformats::GlobalTrackID::mask_t srcTracks, o2::dataformats::GlobalTrackID::mask_t srcCls, bool useMC);
2626

2727
} // namespace o2::svstudy
2828

Detectors/GlobalTrackingWorkflow/study/src/SVStudy.cxx

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
#include "DCAFitter/DCAFitterN.h"
4545
#include "MathUtils/fit.h"
4646
#include "GlobalTrackingStudy/V0Ext.h"
47+
#include "GPUO2InterfaceConfiguration.h"
48+
// #include "GPUSettingsO2.h"
49+
#include "GPUParam.h"
50+
#include "GPUParam.inc"
51+
#include "GPUO2InterfaceRefit.h"
52+
#include "GPUO2InterfaceUtils.h"
4753

4854
namespace o2::svstudy
4955
{
@@ -64,8 +70,8 @@ using timeEst = o2::dataformats::TimeStampWithError<float, float>;
6470
class SVStudySpec : public Task
6571
{
6672
public:
67-
SVStudySpec(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, GTrackID::mask_t src, bool useMC)
68-
: mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mUseMC(useMC) {}
73+
SVStudySpec(std::shared_ptr<DataRequest> dr, std::shared_ptr<o2::base::GRPGeomRequest> gr, GTrackID::mask_t src, bool useTPCCl, bool useMC)
74+
: mDataRequest(dr), mGGCCDBRequest(gr), mTracksSrc(src), mUseTPCCl(useTPCCl), mUseMC(useMC) {}
6975
~SVStudySpec() final = default;
7076
void init(InitContext& ic) final;
7177
void run(ProcessingContext& pc) final;
@@ -83,11 +89,18 @@ class SVStudySpec : public Task
8389
std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut;
8490
float mSelK0 = -1;
8591
bool mRefit = false;
92+
bool mUseTPCCl = false;
8693
float mMaxEta = 0.8;
8794
float mBz = 0;
95+
int mNHBPerTF = 0;
96+
int mNTPCOccBinLength = 0; ///< TPC occ. histo bin length in TBs
97+
float mNTPCOccBinLengthInv;
98+
float mTPCTBinMUSInv = 0.f;
8899
GTrackID::mask_t mTracksSrc{};
89100
o2::vertexing::DCAFitterN<2> mFitterV0;
101+
std::vector<float> mTBinClOccAft, mTBinClOccBef;
90102
std::unique_ptr<o2::steer::MCKinematicsReader> mcReader; // reader of MC information
103+
std::shared_ptr<o2::gpu::GPUParam> mParam = nullptr;
91104
};
92105

93106
void SVStudySpec::init(InitContext& ic)
@@ -107,6 +120,48 @@ void SVStudySpec::run(ProcessingContext& pc)
107120
o2::globaltracking::RecoContainer recoData;
108121
recoData.collectData(pc, *mDataRequest.get()); // select tracks of needed type, with minimal cuts, the real selected will be done in the vertexer
109122
updateTimeDependentParams(pc); // Make sure this is called after recoData.collectData, which may load some conditions
123+
124+
size_t occupancyMapSizeBytes = o2::gpu::GPUO2InterfaceRefit::fillOccupancyMapGetSize(mNHBPerTF, mParam.get());
125+
gsl::span<const unsigned int> TPCRefitterOccMap = recoData.occupancyMapTPC;
126+
o2::gpu::GPUO2InterfaceUtils::paramUseExternalOccupancyMap(mParam.get(), mNHBPerTF, TPCRefitterOccMap.data(), occupancyMapSizeBytes);
127+
128+
mTBinClOccBef.resize(1);
129+
mTBinClOccAft.resize(1);
130+
if (recoData.inputsTPCclusters && mUseTPCCl) {
131+
mNTPCOccBinLength = mParam->rec.tpc.occupancyMapTimeBins;
132+
mTBinClOccBef.clear();
133+
mTBinClOccAft.clear();
134+
// prepare TPC occupancy data
135+
if (mNTPCOccBinLength > 1 && recoData.occupancyMapTPC.size()) {
136+
mNTPCOccBinLengthInv = 1. / mNTPCOccBinLength;
137+
int nTPCBins = mNHBPerTF * o2::constants::lhc::LHCMaxBunches / 8, ninteg = 0;
138+
int nTPCOccBins = nTPCBins * mNTPCOccBinLengthInv, sumBins = std::max(1, int(o2::constants::lhc::LHCMaxBunches / 8 * mNTPCOccBinLengthInv));
139+
mTBinClOccAft.resize(nTPCOccBins);
140+
mTBinClOccBef.resize(nTPCOccBins);
141+
float sm = 0., tb = 0.5 * mNTPCOccBinLength;
142+
std::vector<float> mltHistTB(nTPCOccBins);
143+
for (int i = 0; i < nTPCOccBins; i++) {
144+
mltHistTB[i] = mParam->GetUnscaledMult(tb);
145+
tb += mNTPCOccBinLength;
146+
}
147+
for (int i = nTPCOccBins; i--;) {
148+
sm += mltHistTB[i];
149+
if (i + sumBins < nTPCOccBins) {
150+
sm -= mltHistTB[i + sumBins];
151+
}
152+
mTBinClOccAft[i] = sm;
153+
}
154+
sm = 0;
155+
for (int i = 0; i < nTPCOccBins; i++) {
156+
sm += mltHistTB[i];
157+
if (i - sumBins > 0) {
158+
sm -= mltHistTB[i - sumBins];
159+
}
160+
mTBinClOccBef[i] = sm;
161+
}
162+
}
163+
}
164+
110165
process(recoData);
111166
}
112167

@@ -133,6 +188,12 @@ void SVStudySpec::updateTimeDependentParams(ProcessingContext& pc)
133188
mFitterV0.setMaxStep(svparam.maxStep);
134189
mFitterV0.setMaxSnp(svparam.maxSnp);
135190
mFitterV0.setMinXSeed(svparam.minXSeed);
191+
192+
mNHBPerTF = o2::base::GRPGeomHelper::instance().getGRPECS()->getNHBFPerTF();
193+
if (!mParam) {
194+
// for occupancy estimator
195+
mParam = o2::gpu::GPUO2InterfaceUtils::getFullParamShared(0.f, mNHBPerTF);
196+
}
136197
}
137198
mBz = o2::base::Propagator::Instance()->getNominalBz();
138199
mFitterV0.setBz(mBz);
@@ -268,8 +329,13 @@ void SVStudySpec::process(o2::globaltracking::RecoContainer& recoData)
268329
}
269330
if (v0extVec.size()) {
270331
const auto& pv = recoData.getPrimaryVertex(pvID);
332+
float tpcOccBef = 0., tpcOccAft = 0.;
333+
int tb = pv.getTimeStamp().getTimeStamp() * mTPCTBinMUSInv * mNTPCOccBinLengthInv;
334+
tpcOccBef = tb < 0 ? mTBinClOccBef[0] : (tb >= mTBinClOccBef.size() ? mTBinClOccBef.back() : mTBinClOccBef[tb]);
335+
tpcOccAft = tb < 0 ? mTBinClOccAft[0] : (tb >= mTBinClOccAft.size() ? mTBinClOccAft.back() : mTBinClOccAft[tb]);
336+
271337
(*mDBGOut) << "v0"
272-
<< "orbit=" << recoData.startIR.orbit << "tfID=" << tfID
338+
<< "orbit=" << recoData.startIR.orbit << "tfID=" << tfID << "tpcOccBef=" << tpcOccBef << "tpcOccAft=" << tpcOccAft
273339
<< "v0Ext=" << v0extVec
274340
<< "pv=" << pv
275341
<< "\n";
@@ -334,12 +400,13 @@ void SVStudySpec::finaliseCCDB(ConcreteDataMatcher& matcher, void* obj)
334400
}
335401
}
336402

337-
DataProcessorSpec getSVStudySpec(GTrackID::mask_t srcTracks, bool useMC)
403+
DataProcessorSpec getSVStudySpec(GTrackID::mask_t srcTracks, GTrackID::mask_t srcCls, bool useMC)
338404
{
339405
std::vector<OutputSpec> outputs;
340406
auto dataRequest = std::make_shared<DataRequest>();
341407

342408
dataRequest->requestTracks(srcTracks, useMC);
409+
dataRequest->requestClusters(srcCls, false);
343410
dataRequest->requestPrimaryVertices(useMC);
344411
dataRequest->requestSecondaryVertices(useMC);
345412
dataRequest->inputs.emplace_back("meanvtx", "GLO", "MEANVERTEX", 0, Lifetime::Condition, ccdbParamSpec("GLO/Calib/MeanVertex", {}, 1));
@@ -351,12 +418,12 @@ DataProcessorSpec getSVStudySpec(GTrackID::mask_t srcTracks, bool useMC)
351418
o2::base::GRPGeomRequest::None, // geometry
352419
dataRequest->inputs,
353420
true);
354-
421+
bool useTPCcl = srcCls[GTrackID::TPC];
355422
return DataProcessorSpec{
356423
"sv-study",
357424
dataRequest->inputs,
358425
outputs,
359-
AlgorithmSpec{adaptFromTask<SVStudySpec>(dataRequest, ggRequest, srcTracks, useMC)},
426+
AlgorithmSpec{adaptFromTask<SVStudySpec>(dataRequest, ggRequest, srcTracks, useTPCcl, useMC)},
360427
Options{
361428
{"refit", VariantType::Bool, false, {"refit SVertices"}},
362429
{"sel-k0", VariantType::Float, -1.f, {"If positive, select K0s with this mass margin"}},

Detectors/GlobalTrackingWorkflow/study/src/TrackingStudy.cxx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "GPUParam.inc"
5050
#include "Steer/MCKinematicsReader.h"
5151
#include "MathUtils/fit.h"
52+
#include <TF1.h>
5253

5354
namespace o2::trackstudy
5455
{
@@ -93,7 +94,8 @@ class TrackingStudySpec : public Task
9394
std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOut;
9495
std::unique_ptr<o2::utils::TreeStreamRedirector> mDBGOutVtx;
9596
std::unique_ptr<o2::gpu::GPUO2InterfaceRefit> mTPCRefitter; ///< TPC refitter used for TPC tracks refit during the reconstruction
96-
std::vector<float> mTBinClOccAft, mTBinClOccBef; ///< TPC occupancy histo: i-th entry is the integrated occupancy for ~1 orbit starting/preceding from the TB = i*mNTPCOccBinLength
97+
std::vector<float> mTBinClOccAft, mTBinClOccBef, mTBinClOccWgh; ///< TPC occupancy histo: i-th entry is the integrated occupancy for ~1 orbit starting/preceding from the TB = i*mNTPCOccBinLength
98+
std::unique_ptr<TF1> mOccWghFun;
9799
float mITSROFrameLengthMUS = 0.f;
98100
float mTPCTBinMUS = 0.f; // TPC bin in microseconds
99101
float mTPCTBinMUSInv = 0.f;
@@ -139,6 +141,10 @@ void TrackingStudySpec::init(InitContext& ic)
139141
mDCAYFormula = ic.options().get<std::string>("dcay-vs-pt");
140142
mDCAZFormula = ic.options().get<std::string>("dcaz-vs-pt");
141143
mDoPairsCorr = ic.options().get<bool>("pair-correlations");
144+
auto str = ic.options().get<std::string>("occ-weight-fun");
145+
if (!str.empty()) {
146+
mOccWghFun = std::make_unique<TF1>("occFun", str.c_str(), -100., 100.);
147+
}
142148
}
143149

144150
void TrackingStudySpec::run(ProcessingContext& pc)
@@ -154,16 +160,37 @@ void TrackingStudySpec::run(ProcessingContext& pc)
154160
mNTPCOccBinLength = mTPCRefitter->getParam()->rec.tpc.occupancyMapTimeBins;
155161
mTBinClOccBef.clear();
156162
mTBinClOccAft.clear();
163+
mTBinClOccWgh.clear();
157164
}
165+
158166
// prepare TPC occupancy data
159167
if (mNTPCOccBinLength > 1 && recoData.occupancyMapTPC.size()) {
160168
mNTPCOccBinLengthInv = 1. / mNTPCOccBinLength;
161169
int nTPCBins = mNHBPerTF * o2::constants::lhc::LHCMaxBunches / 8, ninteg = 0;
162170
int nTPCOccBins = nTPCBins * mNTPCOccBinLengthInv, sumBins = std::max(1, int(o2::constants::lhc::LHCMaxBunches / 8 * mNTPCOccBinLengthInv));
163171
mTBinClOccAft.resize(nTPCOccBins);
164172
mTBinClOccBef.resize(nTPCOccBins);
165-
std::vector<float> mltHistTB(nTPCOccBins);
166173
float sm = 0., tb = 0.5 * mNTPCOccBinLength;
174+
/* // at the moment not used
175+
if (mOccWghFun) {
176+
mTBinClOccWgh.resize(nTPCBins);
177+
float occBin2MUS = 8 * o2::constants::lhc::LHCBunchSpacingMUS;
178+
int covWghTB = TMath::NInt(100./occBin2MUS); // coverage of weighted occ. in TBins
179+
for (int i = 0; i < nTPCBins; i++) {
180+
sm = 0.;
181+
for (int j=-covWghTB;j<covWghTB;j++) {
182+
if (j+i<0 || j+i>=nTPCBins) {
183+
continue;
184+
}
185+
sm += mOccWghFun->Eval(j*occBin2MUS)*mTPCRefitter->getParam()->GetUnscaledMult(j+i);
186+
}
187+
mTBinClOccWgh[i] = sm;
188+
}
189+
} else {
190+
mTBinClOccWgh.resize(1);
191+
}
192+
*/
193+
std::vector<float> mltHistTB(nTPCOccBins);
167194
for (int i = 0; i < nTPCOccBins; i++) {
168195
mltHistTB[i] = mTPCRefitter->getParam()->GetUnscaledMult(tb);
169196
tb += mNTPCOccBinLength;
@@ -719,6 +746,7 @@ DataProcessorSpec getTrackingStudySpec(GTrackID::mask_t srcTracks, GTrackID::mas
719746
{"min-pt", VariantType::Float, 0.1f, {"Cut on track pT"}},
720747
{"with-its-only", VariantType::Bool, false, {"Store tracks with ITS only"}},
721748
{"pair-correlations", VariantType::Bool, false, {"Do pairs correlation"}},
749+
{"occ-weight-fun", VariantType::String, "(x>=-40&&x<-5) ? (1./1225*pow(x+40,2)) : ((x>-5&&x<15) ? 1. : ((x>=15&&x<40) ? (-0.4/25*x+1.24 ) : ( (x>40&&x<100) ? -0.4/60*x+0.6+0.8/3 : 0)))", {"Occupancy weighting f-n vs time in musec"}},
722750
{"min-x-prop", VariantType::Float, 100.f, {"track should be propagated to this X at least"}},
723751
};
724752
o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);

Detectors/GlobalTrackingWorkflow/study/src/sv-study-workflow.cxx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ void customize(std::vector<ConfigParamSpec>& workflowOptions)
3939
{"disable-mc", o2::framework::VariantType::Bool, false, {"disable MC propagation"}},
4040
{"track-sources", VariantType::String, std::string{GID::ALL}, {"comma-separated list of track sources to use"}},
4141
{"disable-root-input", VariantType::Bool, false, {"disable root-files input reader"}},
42+
{"ignore-tpc-occ", VariantType::Bool, false, {"do not fill TPC occupancy (needs TPC clusters)"}},
4243
{"configKeyValues", VariantType::String, "", {"Semicolon separated key=value strings ..."}}};
4344
o2::raw::HBFUtilsInitializer::addConfigOption(options);
4445
std::swap(workflowOptions, options);
@@ -61,10 +62,14 @@ WorkflowSpec defineDataProcessing(ConfigContext const& configcontext)
6162

6263
GID::mask_t srcTrc = allowedSourcesTrc & GID::getSourcesMask(configcontext.options().get<std::string>("track-sources"));
6364
GID::mask_t srcCls{};
65+
bool fillTPCOcc = !configcontext.options().get<bool>("ignore-tpc-occ");
66+
if (fillTPCOcc) {
67+
srcCls = srcCls | GID::getSourcesMask("TPC");
68+
}
6469
o2::globaltracking::InputHelper::addInputSpecs(configcontext, specs, srcCls, srcTrc, srcTrc, useMC);
6570
o2::globaltracking::InputHelper::addInputSpecsPVertex(configcontext, specs, useMC); // P-vertex is always needed
6671
o2::globaltracking::InputHelper::addInputSpecsSVertex(configcontext, specs); // S-vertex is always needed
67-
specs.emplace_back(o2::svstudy::getSVStudySpec(srcTrc, useMC));
72+
specs.emplace_back(o2::svstudy::getSVStudySpec(srcTrc, srcCls, useMC));
6873

6974
// configure dpl timer to inject correct firstTForbit: start from the 1st orbit of TF containing 1st sampled orbit
7075
o2::raw::HBFUtilsInitializer hbfIni(configcontext, specs);

0 commit comments

Comments
 (0)