Skip to content

Commit c13e262

Browse files
committed
Add track id to debug streamers for dEdx calculation in tracking, add Nico's changes to dEdx calcualtion class, minor improvements
1 parent 7f2e56a commit c13e262

6 files changed

Lines changed: 371 additions & 132 deletions

File tree

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

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "TPCCalibration/CorrectdEdxDistortions.h"
2929
#include "TPCFastTransformPOD.h"
3030
#include "GPUCommonRtypes.h"
31+
#include "SimulationDataFormat/MCCompLabel.h"
3132
#include <vector>
3233
#include <map>
3334
#include <unordered_map>
@@ -99,17 +100,27 @@ inline ClusterFlags operator|(ClusterFlags a, ClusterFlags b) { return static_ca
99100
/// used by calculatedEdxMultipleSettings() to evaluate several settings for the same track without repeating
100101
/// the track refit/propagation for every setting
101102
struct dEdxSettings {
102-
float low = 0.015f; ///< lower cluster cut
103-
float high = 0.6f; ///< higher cluster cut
104-
CorrectionFlags correctionMask = CorrectionFlags::TopologyPol | CorrectionFlags::dEdxResidual; ///< corrections to apply
105103
ClusterFlags clusterMask = ClusterFlags::None; ///< clusters to exclude
106-
int subthresholdMethod = 0; ///< subthreshold cluster charge filling method
107-
int stackBoundaryMethod = 0; ///< stack boundary cluster exclusion method
108-
std::string debugRootFile = "dEdxDebug.root"; ///< debug streamer output file used if mDebug is set
104+
CorrectionFlags correctionMask = CorrectionFlags::TopologyPol | CorrectionFlags::dEdxResidual; ///< corrections to apply
105+
unsigned short subthresholdMethod = 0; ///< subthreshold cluster charge filling method
106+
unsigned short stackBoundaryMethod = 0; ///< stack boundary cluster exclusion method
109107
float maxSubthresholdChargeTot = 100000.f; ///< upper limit for the per-region minimum qTot used as the virtual charge of a subthreshold cluster (default effectively disables the cap)
110108
float maxSubthresholdChargeMax = 100000.f; ///< upper limit for the per-region minimum qMax used as the virtual charge of a subthreshold cluster (default effectively disables the cap)
109+
float low = 0.015f; ///< lower cluster cut
110+
float high = 0.6f; ///< higher cluster cut
111+
std::string debugRootFile = "dEdxDebug.root"; ///< debug streamer output file used if mDebug is set
112+
};
113+
114+
/// \brief per-cluster info needed by the calculatedEdx()/calculatedEdxMultipleSettings() overloads that take clusters directly instead of extracting them from the track via mTPCTrackClIdxVecInput/mClusterIndex
115+
/// isShared cannot be looked up from mTPCRefitterShMap for externally supplied clusters, so it must be supplied by the caller
116+
struct ClInfo {
117+
unsigned char sectorIndex = 0;
118+
unsigned char rowIndex = 0;
119+
bool isShared = false;
111120
};
112121

122+
using ClInfoVec = std::vector<ClInfo>;
123+
113124
class CalculatedEdx
114125
{
115126
public:
@@ -189,6 +200,10 @@ class CalculatedEdx
189200
/// \param rowOrder (sector, row) keys in the order they are first encountered while scanning the track's native cluster references (0..nClusterReferences-1), i.e. the track's true physical row-traversal order
190201
void handleSameRowClusters(o2::tpc::TrackTPC& track, std::vector<std::pair<unsigned char, unsigned char>>& rowOrder, std::map<std::pair<unsigned char, unsigned char>, std::vector<int>>& clustersByRow, std::map<std::pair<unsigned char, unsigned char>, o2::tpc::ClusterNative>& combinedClustersByRow, std::map<int, std::tuple<unsigned char, unsigned char, unsigned int>>& clusterReferencesByIndex);
191202

203+
/// same as handleSameRowClusters() above, but groups/combines externally supplied clusters instead of the track's clusters accessed via mTPCTrackClIdxVecInput/mClusterIndex
204+
/// \param rowOrder (sector, row) keys in the order they are first encountered while scanning clusters (0..clusters.size()-1), i.e. the order they were supplied in
205+
void handleSameRowClusters(const std::vector<o2::tpc::ClusterNative>& clusters, const ClInfoVec& clusterInfos, std::vector<std::pair<unsigned char, unsigned char>>& rowOrder, std::map<std::pair<unsigned char, unsigned char>, std::vector<int>>& clustersByRow, std::map<std::pair<unsigned char, unsigned char>, o2::tpc::ClusterNative>& combinedClustersByRow);
206+
192207
/// get the truncated mean for the input track with the truncation range, charge type, region and corrections
193208
/// the cluster charge is normalized by effective length*gain, you can turn off the normalization by setting all corrections to false
194209
/// \param track input track
@@ -207,7 +222,18 @@ class CalculatedEdx
207222
/// \param outputs output dEdxInfo, filled with one entry per entry in settingsList, in the same order
208223
/// \param averageOcc output average cluster occupancy of the track, per TPC region; a single value, since occupancy does not depend on the dEdx settings and is therefore the same for every entry in settingsList
209224
/// \param settingsList list of dEdx settings to evaluate for this track
210-
void calculatedEdxMultipleSettings(TrackTPC& track, std::vector<dEdxInfo>& outputs, AverageOccupancy& averageOcc, const std::vector<dEdxSettings>& settingsList);
225+
/// \param mcLabel if non-null and mDebug is set, written to the "dEdxDebugTrack" row of every settingsList entry so debug rows can be matched back to the true MC track
226+
void calculatedEdxMultipleSettings(TrackTPC& track, std::vector<dEdxInfo>& outputs, AverageOccupancy& averageOcc, const std::vector<dEdxSettings>& settingsList, const MCCompLabel* mcLabel = nullptr);
227+
228+
/// same as calculatedEdx() above, but takes the track's clusters and per-cluster info directly instead of extracting them from the track via mTPCTrackClIdxVecInput/mClusterIndex
229+
/// \param clusters clusters of the track, one entry per entry in clusterInfos
230+
/// \param clusterInfos per-cluster (sectorIndex, rowIndex, isShared), one entry per entry in clusters
231+
void calculatedEdx(TrackTPC& track, const std::vector<o2::tpc::ClusterNative>& clusters, const ClInfoVec& clusterInfos, dEdxInfo& output, AverageOccupancy& averageOcc, float low = 0.015f, float high = 0.6f, CorrectionFlags correctionMask = CorrectionFlags::TopologyPol | CorrectionFlags::dEdxResidual, ClusterFlags clusterMask = ClusterFlags::None, int subthresholdMethod = 0, int stackBoundaryMethod = 0, const char* debugRootFile = "dEdxDebug.root", float maxSubthresholdChargeTot = 100000.f, float maxSubthresholdChargeMax = 100000.f);
232+
233+
/// same as calculatedEdxMultipleSettings() above, but takes the track's clusters and per-cluster info directly instead of extracting them from the track via mTPCTrackClIdxVecInput/mClusterIndex
234+
/// \param clusters clusters of the track, one entry per entry in clusterInfos
235+
/// \param clusterInfos per-cluster (sectorIndex, rowIndex, isShared), one entry per entry in clusters
236+
void calculatedEdxMultipleSettings(TrackTPC& track, const std::vector<o2::tpc::ClusterNative>& clusters, const ClInfoVec& clusterInfos, std::vector<dEdxInfo>& outputs, AverageOccupancy& averageOcc, const std::vector<dEdxSettings>& settingsList, const MCCompLabel* mcLabel = nullptr);
211237

212238
/// get the truncated mean for the input charge vector and the truncation range low*nCl<nCl<high*nCl
213239
/// \param charge input vector
@@ -328,6 +354,28 @@ class CalculatedEdx
328354
/// \param averageOcc output average cluster occupancy of the track, per TPC region
329355
void gatherRowClusterData(o2::tpc::TrackTPC& track, std::vector<RowClusterData>& rowData, AverageOccupancy& averageOcc);
330356

357+
/// same as gatherRowClusterData() above, but sources clusters from externally supplied clusters/clusterInfos instead of the track's own cluster references
358+
/// \param track input track, mutated in place by refit/propagation
359+
/// \param clusters clusters of the track, one entry per entry in clusterInfos
360+
/// \param clusterInfos per-cluster (sectorIndex, rowIndex, isShared), one entry per entry in clusters
361+
/// \param rowData output per-row data
362+
/// \param averageOcc output average cluster occupancy of the track, per TPC region
363+
void gatherRowClusterData(o2::tpc::TrackTPC& track, const std::vector<o2::tpc::ClusterNative>& clusters, const ClInfoVec& clusterInfos, std::vector<RowClusterData>& rowData, AverageOccupancy& averageOcc);
364+
365+
/// per-row processing shared by both gatherRowClusterData() overloads, once the row's cluster/sector/row/isCombined/isShared are known regardless of where they came from:
366+
/// refits/propagates the track to this row, looks up threshold/gain, checks the dead-channel map and missing-cluster gaps, and appends the resulting entry to rowData
367+
/// \param track input track, mutated in place by refit/propagation
368+
/// \param cl the (possibly same-row-combined) cluster for this row
369+
/// \param sectorIndex sector of this row
370+
/// \param rowIndex TPC row index
371+
/// \param isCombined true if cl is the result of combining multiple clusters in the same (sector, row)
372+
/// \param isShared true if the row's cluster(s) are shared between tracks
373+
/// \param rowIndexOld rowIndex of the previous entry appended to rowData (255 if this is the first row)
374+
/// \param sectorIndexOld sectorIndex of the previous entry appended to rowData (255 if this is the first row)
375+
/// \param occupancyROC per-region occupancy accumulator, updated in place
376+
/// \param rowData output per-row data; the new row is appended, and rowData.back() (if non-empty) is read as the previous row for the missing-cluster-gap check
377+
void gatherRowClusterDataForRow(o2::tpc::TrackTPC& track, const o2::tpc::ClusterNative& cl, unsigned char sectorIndex, unsigned char rowIndex, bool isCombined, bool isShared, unsigned char rowIndexOld, unsigned char sectorIndexOld, std::array<std::vector<unsigned int>, 4>& occupancyROC, std::vector<RowClusterData>& rowData);
378+
331379
/// compute the dEdx output for one dEdx settings entry from the row data previously gathered by gatherRowClusterData()
332380
/// \param rowData per row data gathered by gatherRowClusterData() for the track being processed
333381
/// \param settings dEdx settings to apply
@@ -336,7 +384,8 @@ class CalculatedEdx
336384
/// \param trackOrig pristine track (before refit/propagation mutated it), used for the debug "dEdxDebugTrack" row; ignored if mDebug is false
337385
/// \param averageOcc average cluster occupancy of the track as computed by gatherRowClusterData(), only used for the debug "dEdxDebugTrack" row; ignored if mDebug is false
338386
/// \param output output dEdxInfo
339-
void calculatedEdxFromRowData(const std::vector<RowClusterData>& rowData, const dEdxSettings& settings, size_t settingsIndex, float trackTime0, const o2::tpc::TrackTPC& trackOrig, const AverageOccupancy& averageOcc, dEdxInfo& output);
387+
/// \param mcLabel if non-null and mDebug is set, written to the "dEdxDebugTrack" row as the "mcLabel" branch
388+
void calculatedEdxFromRowData(const std::vector<RowClusterData>& rowData, const dEdxSettings& settings, size_t settingsIndex, float trackTime0, const o2::tpc::TrackTPC& trackOrig, const AverageOccupancy& averageOcc, dEdxInfo& output, const MCCompLabel* mcLabel = nullptr);
340389

341390
std::vector<TrackTPC>* mTracks{nullptr}; ///< vector containing the tpc tracks which will be processed
342391
std::vector<TPCClRefElem>* mTPCTrackClIdxVecInput{nullptr}; ///< input vector with TPC tracks cluster indicies

Detectors/TPC/calibration/macro/calculatedEdx.C

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void calculatedEdx(const std::string dir = ".",
147147
LOGP(error, "settingsList[{}]: invalid subthresholdMethod {}; expected 0 (minimum charge) or 1 (minimum charge / 2)", i, s.subthresholdMethod);
148148
return;
149149
}
150-
if (s.stackBoundaryMethod < 0 || s.stackBoundaryMethod > 2) {
150+
if (s.stackBoundaryMethod > 2) {
151151
LOGP(error, "settingsList[{}]: invalid stackBoundaryMethod {}; expected 0 (disabled), 1 (exclude boundary row) or 2 (also exclude the adjacent row)", i, s.stackBoundaryMethod);
152152
return;
153153
}
@@ -330,7 +330,7 @@ void calculatedEdx(const std::string dir = ".",
330330
TrackTPC track(tpcTracks[tpcIndex]); // local copy: refit/propagation inside calculatedEdxMultipleSettings mutate the track in place
331331
std::vector<dEdxInfo> dEdxVec;
332332
AverageOccupancy averageOcc;
333-
calcdEdx.calculatedEdxMultipleSettings(track, dEdxVec, averageOcc, threadSettingsList);
333+
calcdEdx.calculatedEdxMultipleSettings(track, dEdxVec, averageOcc, threadSettingsList, isMC ? &tpcMCTruth[tpcIndex] : nullptr);
334334

335335
tpcOut[iThread].emplace_back(track);
336336
dEdxOut[iThread].emplace_back(std::move(dEdxVec));

0 commit comments

Comments
 (0)