Skip to content

Commit 5db6ab2

Browse files
committed
Always write track references in addition to binned residuals
1 parent abf84c4 commit 5db6ab2

10 files changed

Lines changed: 60 additions & 20 deletions

File tree

Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCResidualAggregatorSpec.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class ResidualAggregatorDevice : public o2::framework::Task
111111
std::chrono::duration<double, std::milli> ccdbUpdateTime = std::chrono::high_resolution_clock::now() - runStartTime;
112112

113113
auto residualsData = pc.inputs().get<gsl::span<o2::tpc::UnbinnedResid>>("unbinnedRes");
114+
auto trackRefs = pc.inputs().get<gsl::span<o2::tpc::TrackDataCompact>>("trackRefs");
115+
114116
// track data input is optional
115117
const gsl::span<const o2::tpc::TrackData>* trkDataPtr = nullptr;
116118
using trkDataType = std::decay_t<decltype(pc.inputs().get<gsl::span<o2::tpc::TrackData>>(""))>;
@@ -129,10 +131,9 @@ class ResidualAggregatorDevice : public o2::framework::Task
129131
lumi = &lumiInput.value();
130132
}
131133

132-
auto data = std::make_pair<gsl::span<const o2::tpc::TrackData>, gsl::span<const o2::tpc::UnbinnedResid>>(std::move(*trkData), std::move(residualsData));
133134
o2::base::TFIDInfoHelper::fillTFIDInfo(pc, mAggregator->getCurrentTFInfo());
134135
LOG(info) << "Processing TF " << mAggregator->getCurrentTFInfo().tfCounter << " with " << trkData->size() << " tracks and " << residualsData.size() << " unbinned residuals associated to them";
135-
mAggregator->process(data, lumi);
136+
mAggregator->process(residualsData, trackRefs, trkDataPtr, lumi);
136137
std::chrono::duration<double, std::milli> runDuration = std::chrono::high_resolution_clock::now() - runStartTime;
137138
LOGP(info, "Duration for run method: {} ms. From this taken for time dependent param update: {} ms",
138139
std::chrono::duration_cast<std::chrono::milliseconds>(runDuration).count(),
@@ -179,6 +180,7 @@ DataProcessorSpec getTPCResidualAggregatorSpec(bool trackInput, bool ctpInput, b
179180
}
180181
auto& inputs = dataRequest->inputs;
181182
inputs.emplace_back("unbinnedRes", "GLO", "UNBINNEDRES");
183+
inputs.emplace_back("trackRefs", "GLO", "TRKREFS");
182184
if (trackInput) {
183185
inputs.emplace_back("trkData", "GLO", "TRKDATA");
184186
}

Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/include/TPCInterpolationWorkflow/TPCUnbinnedResidualReaderSpec.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class TPCUnbinnedResidualReader : public o2::framework::Task
4444
std::string mInTreeName;
4545
std::vector<UnbinnedResid> mUnbinnedResid, *mUnbinnedResidPtr = &mUnbinnedResid;
4646
std::vector<TrackData> mTrackData, *mTrackDataPtr = &mTrackData;
47+
std::vector<TrackDataCompact> mTrackDataCompact, *mTrackDataCompactPtr = &mTrackDataCompact;
4748
};
4849

4950
/// read unbinned TPC residuals and reference tracks from a root file

Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCInterpolationSpec.cxx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ void TPCInterpolationDPL::run(ProcessingContext& pc)
156156
}
157157
}
158158
pc.outputs().snapshot(Output{"GLO", "UNBINNEDRES", 0, Lifetime::Timeframe}, mInterpolation.getClusterResiduals());
159+
pc.outputs().snapshot(Output{"GLO", "TRKREFS", 0, Lifetime::Timeframe}, mInterpolation.getTrackDataCompact());
159160
if (mSendTrackData) {
160161
pc.outputs().snapshot(Output{"GLO", "TRKDATA", 0, Lifetime::Timeframe}, mInterpolation.getReferenceTracks());
161162
}
@@ -192,10 +193,15 @@ DataProcessorSpec getTPCInterpolationSpec(GTrackID::mask_t src, bool useMC, bool
192193
o2::tpc::VDriftHelper::requestCCDBInputs(dataRequest->inputs);
193194
if (SpacePointsCalibConfParam::Instance().writeUnfiltered) {
194195
outputs.emplace_back("GLO", "TPCINT_TRK", 0, Lifetime::Timeframe);
195-
outputs.emplace_back("GLO", "TPCINT_RES", 0, Lifetime::Timeframe);
196+
if (sendTrackData) {
197+
outputs.emplace_back("GLO", "TPCINT_RES", 0, Lifetime::Timeframe);
198+
}
196199
}
197200
outputs.emplace_back("GLO", "UNBINNEDRES", 0, Lifetime::Timeframe);
198-
outputs.emplace_back("GLO", "TRKDATA", 0, Lifetime::Timeframe);
201+
outputs.emplace_back("GLO", "TRKREFS", 0, Lifetime::Timeframe);
202+
if (sendTrackData) {
203+
outputs.emplace_back("GLO", "TRKDATA", 0, Lifetime::Timeframe);
204+
}
199205

200206
return DataProcessorSpec{
201207
"tpc-track-interpolation",

Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCResidualWriterSpec.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ DataProcessorSpec getTPCResidualWriterSpec(bool writeTrackData)
3838
BranchDefinition<std::vector<TrackData>>{InputSpec{"tracksUnfiltered", "GLO", "TPCINT_TRK", 0}, "tracksUnfiltered", ((writeUnfiltered && writeTrackData) ? 1 : 0)},
3939
BranchDefinition<std::vector<TPCClusterResiduals>>{InputSpec{"residualsUnfiltered", "GLO", "TPCINT_RES", 0}, "residualsUnfiltered", (writeUnfiltered ? 1 : 0)},
4040
BranchDefinition<std::vector<UnbinnedResid>>{InputSpec{"residuals", "GLO", "UNBINNEDRES"}, "residuals"},
41+
BranchDefinition<std::vector<TrackDataCompact>>{InputSpec{"trackRefs", "GLO", "TRKREFS"}, "trackRefs"},
4142
BranchDefinition<std::vector<TrackData>>{InputSpec{"tracks", "GLO", "TRKDATA"}, "tracks", (writeTrackData ? 1 : 0)})();
4243
}
4344

Detectors/GlobalTrackingWorkflow/tpcinterpolationworkflow/src/TPCUnbinnedResidualReaderSpec.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void TPCUnbinnedResidualReader::connectTree()
4343
mTreeIn.reset((TTree*)mFileIn->Get(mInTreeName.c_str()));
4444
assert(mTreeIn);
4545
mTreeIn->SetBranchAddress("residuals", &mUnbinnedResidPtr);
46+
mTreeIn->SetBranchAddress("trackRefs", &mTrackDataCompactPtr);
4647
if (mTrackInput) {
4748
mTreeIn->SetBranchAddress("tracks", &mTrackDataPtr);
4849
}
@@ -56,6 +57,7 @@ void TPCUnbinnedResidualReader::run(ProcessingContext& pc)
5657
mTreeIn->GetEntry(currEntry);
5758
LOG(info) << "Pushing " << mUnbinnedResid.size() << " unbinned residuals at entry " << currEntry;
5859
pc.outputs().snapshot(Output{"GLO", "UNBINNEDRES", 0, Lifetime::Timeframe}, mUnbinnedResid);
60+
pc.outputs().snapshot(Output{"GLO", "TRKREFS", 0, Lifetime::Timeframe}, mTrackDataCompact);
5961
if (mTrackInput) {
6062
LOG(info) << "Pushing " << mTrackData.size() << " reference tracks for these residuals";
6163
pc.outputs().snapshot(Output{"GLO", "TRKDATA", 0, Lifetime::Timeframe}, mTrackData);
@@ -71,6 +73,7 @@ DataProcessorSpec getUnbinnedTPCResidualsReaderSpec(bool trkInput)
7173
{
7274
std::vector<OutputSpec> outputs;
7375
outputs.emplace_back("GLO", "UNBINNEDRES", 0, Lifetime::Timeframe);
76+
outputs.emplace_back("GLO", "TRKREFS", 0, Lifetime::Timeframe);
7477
if (trkInput) {
7578
outputs.emplace_back("GLO", "TRKDATA", 0, Lifetime::Timeframe);
7679
}

Detectors/TPC/calibration/SpacePoints/include/SpacePoints/ResidualAggregator.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct ResidualsContainer {
4949
void fillStatisticsBranches();
5050
uint64_t getNEntries() const { return nResidualsTotal; }
5151

52-
void fill(const o2::dataformats::TFIDInfo& ti, const std::pair<gsl::span<const o2::tpc::TrackData>, gsl::span<const UnbinnedResid>> data, const o2::ctp::LumiInfo* lumiInput);
52+
void fill(const o2::dataformats::TFIDInfo& ti, const gsl::span<const UnbinnedResid> resid, const gsl::span<const o2::tpc::TrackDataCompact> trkRefsIn, const gsl::span<const o2::tpc::TrackData>* trkDataIn, const o2::ctp::LumiInfo* lumiInput);
5353
void merge(ResidualsContainer* prev);
5454
void print();
5555
void writeToFile(bool closeFileAfterwards);
@@ -63,8 +63,9 @@ struct ResidualsContainer {
6363
std::vector<uint32_t> tfOrbits, *tfOrbitsPtr{&tfOrbits}; ///< first TF orbit
6464
std::vector<uint32_t> sumOfResiduals, *sumOfResidualsPtr{&sumOfResiduals}; ///< sum of residuals for each TF
6565
std::vector<o2::ctp::LumiInfo> lumi, *lumiPtr{&lumi}; ///< luminosity information from CTP per TF
66-
std::vector<UnbinnedResid> unbinnedRes, *unbinnedResPtr{&unbinnedRes}; // unbinned residuals
67-
std::vector<TrackData> trkData, *trkDataPtr{&trkData}; // track data and cluster ranges
66+
std::vector<UnbinnedResid> unbinnedRes, *unbinnedResPtr{&unbinnedRes}; ///< unbinned residuals
67+
std::vector<TrackData> trkData, *trkDataPtr{&trkData}; ///< track data and cluster ranges
68+
std::vector<TrackDataCompact> trackInfo, *trackInfoPtr{&trackInfo}; ///< allows to obtain track type for each binned residual downstream
6869

6970
std::string fileName{"o2tpc_residuals"};
7071
std::string treeNameResiduals{"resid"};
@@ -77,15 +78,17 @@ struct ResidualsContainer {
7778
std::unique_ptr<TTree> treeOutStats{nullptr};
7879
std::unique_ptr<TTree> treeOutRecords{nullptr};
7980

80-
bool writeToRootFile{true};
81-
bool writeBinnedResid{false};
82-
bool writeUnbinnedResiduals{false};
83-
bool writeTrackData{false};
84-
int autosaveInterval{0};
85-
TFType firstSeenTF{o2::calibration::INFINITE_TF};
86-
TFType lastSeenTF{0};
87-
88-
uint64_t nResidualsTotal{0};
81+
// settings
82+
bool writeToRootFile{true}; ///< set to false to avoid that any output file is produced
83+
bool writeBinnedResid{false}; ///< flag, whether binned residuals should be written out
84+
bool writeUnbinnedResiduals{false}; ///< flag, whether unbinned residuals should be written out
85+
bool writeTrackData{false}; ///< flag, whether full seeding track information should be written out
86+
int autosaveInterval{0}; ///< if > 0, then the output written to file for every n-th TF
87+
88+
// additional info
89+
TFType firstSeenTF{o2::calibration::INFINITE_TF}; ///< the first TF which was added to this container
90+
TFType lastSeenTF{0}; ///< the last TF which was added to this container
91+
uint64_t nResidualsTotal{0}; ///< the total number of residuals for this container
8992

9093
ClassDefNV(ResidualsContainer, 4);
9194
};

Detectors/TPC/calibration/SpacePoints/include/SpacePoints/TrackInterpolation.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ struct UnbinnedResid {
8787
ClassDefNV(UnbinnedResid, 1);
8888
};
8989

90+
/// Structure for the information required to associate each residual with a given track type (ITS-TPC-TRD-TOF, etc)
91+
struct TrackDataCompact {
92+
TrackDataCompact() = default;
93+
TrackDataCompact(uint32_t idx, uint8_t nRes, uint8_t source) : idxFirstResidual(idx), nResiduals(nRes), sourceId(source) {}
94+
uint32_t idxFirstResidual; ///< the index of the first residual from this track
95+
uint8_t nResiduals; ///< total number of residuals associated to this track
96+
uint8_t sourceId; ///< source ID obtained from the global track ID
97+
ClassDefNV(TrackDataCompact, 1);
98+
};
99+
90100
/// Structure filled for each track with track quality information and a vector with TPCClusterResiduals
91101
struct TrackData {
92102
o2::dataformats::GlobalTrackID gid{}; ///< global track ID for seeding track
@@ -210,6 +220,7 @@ class TrackInterpolation
210220

211221
// --------------------------------- output ---------------------------------------------
212222
std::vector<UnbinnedResid>& getClusterResiduals() { return mClRes; }
223+
std::vector<TrackDataCompact>& getTrackDataCompact() { return mTrackDataCompact; }
213224
std::vector<TrackData>& getReferenceTracks() { return mTrackData; }
214225
std::vector<TPCClusterResiduals>& getClusterResidualsUnfiltered() { return mClResUnfiltered; }
215226
std::vector<TrackData>& getReferenceTracksUnfiltered() { return mTrackDataUnfiltered; }
@@ -234,6 +245,7 @@ class TrackInterpolation
234245

235246
// output
236247
std::vector<TrackData> mTrackData{}; ///< this vector is used to store the track quality information on a per track basis
248+
std::vector<TrackDataCompact> mTrackDataCompact{}; ///< required to connect each residual to a global track
237249
std::vector<UnbinnedResid> mClRes{}; ///< residuals for each available TPC cluster of all tracks
238250
std::vector<TrackData> mTrackDataUnfiltered{}; ///< same as mTrackData, but for all tracks before outlier filtering
239251
std::vector<TPCClusterResiduals> mClResUnfiltered{}; ///< same as mClRes, but for all residuals before outlier filtering

Detectors/TPC/calibration/SpacePoints/src/ResidualAggregator.cxx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ ResidualsContainer::ResidualsContainer(ResidualsContainer&& rhs)
6767
tfOrbits = std::move(rhs.tfOrbits);
6868
sumOfResiduals = std::move(rhs.sumOfResiduals);
6969
lumi = std::move(rhs.lumi);
70+
unbinnedRes = std::move(rhs.unbinnedRes);
71+
trackInfo = std::move(rhs.trackInfo);
72+
trkData = std::move(rhs.trkData);
7073
firstSeenTF = rhs.firstSeenTF;
7174
lastSeenTF = rhs.lastSeenTF;
7275
}
@@ -114,6 +117,7 @@ void ResidualsContainer::init(const TrackResiduals* residualsEngine, std::string
114117
treeOutResiduals->Branch(Form("sec%d", iSec), &residualsPtr[iSec]);
115118
treeOutStats->Branch(Form("sec%d", iSec), &statsPtr[iSec]);
116119
}
120+
treeOutResiduals->Branch("trackInfo", &trackInfoPtr);
117121
treeOutRecords->Branch("firstTForbit", &tfOrbitsPtr);
118122
treeOutRecords->Branch("sumOfResiduals", &sumOfResidualsPtr);
119123
treeOutRecords->Branch("lumi", &lumiPtr);
@@ -131,19 +135,19 @@ void ResidualsContainer::fillStatisticsBranches()
131135
}
132136
}
133137

134-
void ResidualsContainer::fill(const o2::dataformats::TFIDInfo& ti, const std::pair<gsl::span<const o2::tpc::TrackData>, gsl::span<const UnbinnedResid>> data, const o2::ctp::LumiInfo* lumiInput)
138+
void ResidualsContainer::fill(const o2::dataformats::TFIDInfo& ti, const gsl::span<const UnbinnedResid> resid, const gsl::span<const o2::tpc::TrackDataCompact> trkRefsIn, const gsl::span<const o2::tpc::TrackData>* trkDataIn, const o2::ctp::LumiInfo* lumiInput)
135139
{
136140
// receives large vector of unbinned residuals and fills the sector-wise vectors
137141
// with binned residuals and statistics
138-
LOG(debug) << "Filling ResidualsContainer with vector of size " << data.second.size();
142+
LOG(debug) << "Filling ResidualsContainer with vector of size " << resid.size();
139143
uint32_t nResidualsInTF = 0;
140144
if (ti.tfCounter > lastSeenTF) {
141145
lastSeenTF = ti.tfCounter;
142146
}
143147
if (ti.tfCounter < firstSeenTF) {
144148
firstSeenTF = ti.tfCounter;
145149
}
146-
for (const auto& residIn : data.second) {
150+
for (const auto& residIn : resid) {
147151
bool counterIncremented = false;
148152
if (writeUnbinnedResiduals) {
149153
unbinnedRes.push_back(residIn);
@@ -180,15 +184,19 @@ void ResidualsContainer::fill(const o2::dataformats::TFIDInfo& ti, const std::pa
180184
}
181185
++nResidualsInTF;
182186
}
187+
for (const auto& trkRef : trkRefsIn) {
188+
trackInfo.push_back(trkRef);
189+
}
183190
if (writeBinnedResid) {
184191
treeOutResiduals->Fill();
192+
trackInfo.clear();
185193
sumOfResiduals.push_back(nResidualsInTF);
186194
}
187195
for (auto& residVecOut : residuals) {
188196
residVecOut.clear();
189197
}
190198
if (writeTrackData) {
191-
for (const auto& trkIn : data.first) {
199+
for (const auto& trkIn : *trkDataIn) {
192200
trkData.push_back(trkIn);
193201
}
194202
treeOutTrackData->Fill();

Detectors/TPC/calibration/SpacePoints/src/SpacePointCalibLinkDef.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
#pragma link C++ class o2::tpc::TrackInterpolation + ;
1919
#pragma link C++ class o2::tpc::TrackResiduals + ;
20+
#pragma link C++ class o2::tpc::TrackDataCompact + ;
21+
#pragma link C++ class std::vector < o2::tpc::TrackDataCompact> + ;
2022
#pragma link C++ class o2::tpc::TrackData + ;
2123
#pragma link C++ class std::vector < o2::tpc::TrackData> + ;
2224
#pragma link C++ class o2::tpc::TPCClusterResiduals + ;

Detectors/TPC/calibration/SpacePoints/src/TrackInterpolation.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ void TrackInterpolation::interpolateTrack(int iSeed)
299299
trackData.clIdx.setEntries(nClValidated);
300300
mTrackData.push_back(std::move(trackData));
301301
mGIDsSuccess.push_back((*mGIDs)[iSeed]);
302+
mTrackDataCompact.emplace_back(mClRes.size() - nClValidated, nClValidated, (*mGIDs)[iSeed].getSource());
302303
}
303304
if (mParams->writeUnfiltered) {
304305
TrackData trkDataTmp = trackData;
@@ -751,6 +752,7 @@ void TrackInterpolation::diffToMA(const int np, const std::array<float, param::N
751752
void TrackInterpolation::reset()
752753
{
753754
mTrackData.clear();
755+
mTrackDataCompact.clear();
754756
mClRes.clear();
755757
mTrackDataUnfiltered.clear();
756758
mClResUnfiltered.clear();

0 commit comments

Comments
 (0)