Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][ITS-tracking] Add track dumping in standalone debugger #5069

Merged
merged 3 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion Detectors/ITSMFT/ITS/tracking/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ o2_add_library(ITStracking
src/Label.cxx
src/PrimaryVertexContext.cxx
src/Road.cxx
# src/StandaloneDebugger.cxx
src/StandaloneDebugger.cxx
src/Tracker.cxx
src/TrackerTraitsCPU.cxx
src/TrackingConfigParam.cxx
Expand All @@ -36,6 +36,7 @@ o2_target_root_dictionary(ITStracking
HEADERS include/ITStracking/ClusterLines.h
include/ITStracking/Tracklet.h
include/ITStracking/TrackingConfigParam.h
include/ITStracking/StandaloneDebugger.h
LINKDEF src/TrackingLinkDef.h)

if(CUDA_ENABLED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <array>
#endif

//#define CA_DEBUG
#define CA_DEBUG
mconcas marked this conversation as resolved.
Show resolved Hide resolved

#ifdef CA_DEBUG
#define CA_DEBUGGER(x) x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,91 @@
#ifndef O2_ITS_STANDALONE_DEBUGGER_H_
#define O2_ITS_STANDALONE_DEBUGGER_H_

#include <string>
#include <iterator>

// Tracker
#include "DataFormatsITS/TrackITS.h"
#include "ITStracking/ROframe.h"

namespace o2
{

class MCCompLabel;
// class MCCompLabel;

namespace utils
{
class TreeStreamRedirector;
}

// namespace its
// {
// class TrackITSExt;
// }

namespace its
{
class Tracklet;
class Line;
class ROframe;
class ClusterLines;

using constants::its::UnusedIndex;

struct FakeTrackInfo {
public:
FakeTrackInfo();
FakeTrackInfo(const ROframe& event, TrackITSExt& track) : isFake{false}, isAmbiguousId{false}, mainLabel{UnusedIndex, UnusedIndex, UnusedIndex, false}
{
occurrences.clear();
for (size_t iCluster{0}; iCluster < 7; ++iCluster) {
int extIndex = track.getClusterIndex(iCluster);
o2::MCCompLabel mcLabel = event.getClusterLabels(iCluster, extIndex);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in principle, a cluster may have multiple labels. What is the reason to copy the labels into the ROframe, rather than fetching them by cluster index from the MC container?

Copy link
Collaborator Author

@mconcas mconcas Dec 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I just got this from the approach used in the tracker to access the labels, at some point I realised it is a duplication.
Unless I am forgetting some strong reason we might consider to simplify this, will check with Max to be sure.

bool found = false;

for (size_t iOcc{0}; iOcc < occurrences.size(); ++iOcc) {
std::pair<o2::MCCompLabel, int>& occurrence = occurrences[iOcc];
if (mcLabel == occurrence.first) {
++occurrence.second;
found = true;
mconcas marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (!found) {
occurrences.emplace_back(mcLabel, 1);
}
}
if (occurrences.size() > 1) {
isFake = true;
}
std::sort(std::begin(occurrences), std::end(occurrences), [](auto e1, auto e2) {
return e1.second > e2.second;
});
mainLabel = occurrences[0].first;

for (auto iOcc{1}; iOcc < occurrences.size(); ++iOcc) {
if (occurrences[iOcc].second == occurrences[0].second) {
isAmbiguousId = true;
break;
}
}
for (auto iCluster{0}; iCluster < TrackITSExt::MaxClusters; ++iCluster) {
int extIndex = track.getClusterIndex(iCluster);
o2::MCCompLabel lbl = event.getClusterLabels(iCluster, extIndex);
if (lbl == mainLabel && occurrences[0].second > 1 && !lbl.isNoise()) { // if 7 fake clusters -> occurrences[0].second = 1
clusStatuses[iCluster] = 1;
} else {
clusStatuses[iCluster] = 0;
++nFakeClusters;
}
}
}
std::vector<std::pair<MCCompLabel, int>> occurrences;
MCCompLabel mainLabel;
std::array<int, 7> clusStatuses = {-1, -1, -1, -1, -1, -1, -1};
bool isFake;
bool isAmbiguousId;
int nFakeClusters = 0;
};
mconcas marked this conversation as resolved.
Show resolved Hide resolved

class StandaloneDebugger
{
Expand Down Expand Up @@ -59,6 +129,9 @@ class StandaloneDebugger
void fillXYZHistogramTree(std::array<std::vector<int>, 3>, const std::array<int, 3>);
void fillVerticesInfoTree(float x, float y, float z, int size, int rId, int eId, float pur);

// Tracker debug utilities
void dumpTrackToBranchWithInfo(const ROframe event, o2::its::TrackITSExt track, std::string branchName);

static int getBinIndex(const float, const int, const float, const float);

private:
Expand Down
8 changes: 8 additions & 0 deletions Detectors/ITSMFT/ITS/tracking/include/ITStracking/Tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@

#include "Framework/Logger.h"

#ifdef CA_DEBUG
#include "ITStracking/StandaloneDebugger.h"
#endif

namespace o2
{
namespace gpu
Expand Down Expand Up @@ -105,6 +109,10 @@ class Tracker
std::vector<MCCompLabel> mTrackLabels;
o2::base::MatLayerCylSet* mMatLayerCylSet = nullptr;
o2::gpu::GPUChainITS* mRecoChain = nullptr;

#ifdef CA_DEBUG
StandaloneDebugger* mDebugger;
#endif
};

inline void Tracker::setParameters(const std::vector<MemoryParameters>& memPars, const std::vector<TrackingParameters>& trkPars)
Expand Down
23 changes: 20 additions & 3 deletions Detectors/ITSMFT/ITS/tracking/src/StandaloneDebugger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
/// \brief
/// \author matteo.concas@cern.ch

#include <string>
#include <iterator>

#include "ITStracking/Cluster.h"
#include "ITStracking/Tracklet.h"
#include "ITStracking/ClusterLines.h"
#include "CommonUtils/TreeStreamRedirector.h"
#include "ITStracking/ROframe.h"
#include "ITStracking/StandaloneDebugger.h"



#include "TH1I.h"
#include "TMath.h"

Expand Down Expand Up @@ -257,5 +258,21 @@ int StandaloneDebugger::getBinIndex(const float value, const int size, const flo
return std::distance(divisions.begin(), TMath::BinarySearch(divisions.begin(), divisions.end(), value));
}

// Tracker
void StandaloneDebugger::dumpTrackToBranchWithInfo(ROframe event, o2::its::TrackITSExt track,
std::string branchName)
{
// FakeTrackInfo t{event, track};

(*mTreeStream)
<< branchName.data()
<< track
mconcas marked this conversation as resolved.
Show resolved Hide resolved
<< "\n";

// (*mTreeStream)
// << "TracksInfo"
// << tInfo
// << "\n";
}
} // namespace its
} // namespace o2
16 changes: 14 additions & 2 deletions Detectors/ITSMFT/ITS/tracking/src/Tracker.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,21 @@ Tracker::Tracker(o2::its::TrackerTraits* traits)
/// Initialise standard configuration with 1 iteration
mTrkParams.resize(1);
mMemParams.resize(1);
assert(traits != nullptr);
assert(mTracks != nullptr);
mTraits = traits;
mPrimaryVertexContext = mTraits->getPrimaryVertexContext();
#ifdef CA_DEBUG
mDebugger = new StandaloneDebugger("dbg_ITSTrackerCPU.root");
#endif
}

#ifdef CA_DEBUG
Tracker::~Tracker()
{
delete mDebugger;
}
#else
Tracker::~Tracker() = default;
#endif

void Tracker::clustersToTracks(const ROframe& event, std::ostream& timeBenchmarkOutputStream)
{
Expand Down Expand Up @@ -292,6 +301,9 @@ void Tracker::findTracks(const ROframe& event)
temporaryTrack.getParamOut() = temporaryTrack;
temporaryTrack.resetCovariance();
fitSuccess = fitTrack(event, temporaryTrack, mTrkParams[0].NLayers - 1, -1, -1, mTrkParams[0].FitIterationMaxChi2[1]);
#ifdef CA_DEBUG
mDebugger->dumpTrackToBranchWithInfo(event, temporaryTrack, "testBranch");
#endif
if (!fitSuccess) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion Detectors/ITSMFT/ITS/tracking/src/TrackingLinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
#pragma link C++ class o2::its::Tracklet + ;

#pragma link C++ class o2::its::VertexerParamConfig + ;
#pragma link C++ class o2::conf::ConfigurableParamHelper <o2::its::VertexerParamConfig> + ;
#pragma link C++ class o2::conf::ConfigurableParamHelper < o2::its::VertexerParamConfig> + ;

#endif