CbmRoot
Loading...
Searching...
No Matches
CaToolsMCData.cxx
Go to the documentation of this file.
1/* Copyright (C) 2022-2023 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Sergei Zharko [committer] */
4
9
10#include "CaToolsMCData.h"
11
12#include "CbmL1Hit.h"
13
14#include <iomanip>
15#include <sstream>
16#include <utility> // for std::move
17
19
20// ---------------------------------------------------------------------------------------------------------------------
21//
23
24// ---------------------------------------------------------------------------------------------------------------------
25//
27 : fvPoints(other.fvPoints)
28 , fvTracks(other.fvTracks)
29 , fvNofPointsOrig(other.fvNofPointsOrig)
30 , fvNofPointsUsed(other.fvNofPointsUsed)
31 , fmPointLinkMap(other.fmPointLinkMap)
32 , fmTrackLinkMap(other.fmTrackLinkMap)
33{
34}
35
36// ---------------------------------------------------------------------------------------------------------------------
37//
38MCData::MCData(MCData&& other) noexcept { this->Swap(other); }
39
40// ---------------------------------------------------------------------------------------------------------------------
41//
43{
44 if (this != &other) {
45 MCData(other).Swap(*this);
46 }
47 return *this;
48}
49
50// ---------------------------------------------------------------------------------------------------------------------
51//
53{
54 if (this != &other) {
55 MCData tmp(std::move(other));
56 this->Swap(tmp);
57 }
58 return *this;
59}
60
61// ---------------------------------------------------------------------------------------------------------------------
62//
63void MCData::Swap(MCData& other) noexcept
64{
65 std::swap(fvPoints, other.fvPoints);
66 std::swap(fvTracks, other.fvTracks);
67 std::swap(fvNofPointsOrig, other.fvNofPointsOrig);
68 std::swap(fvNofPointsUsed, other.fvNofPointsUsed);
69 std::swap(fmPointLinkMap, other.fmPointLinkMap);
70 std::swap(fmTrackLinkMap, other.fmTrackLinkMap);
71}
72
73
74// ---------------------------------------------------------------------------------------------------------------------
75//
77{
78 fvPoints.clear();
79 fvTracks.clear();
80 fmPointLinkMap.clear();
81 fmTrackLinkMap.clear();
82}
83
84// ---------------------------------------------------------------------------------------------------------------------
85//
87{
88 for (auto& aTrk : fvTracks) {
89 // Assign hits to tracks
90 aTrk.ClearHitIndexes();
91 auto& vHitIds = aTrk.GetHitIndexes();
92 for (int iP : aTrk.GetPointIndexes()) {
93 const auto& point = fvPoints[iP];
94 for (int iH : point.GetHitIndexes()) {
95 if (std::find(vHitIds.begin(), vHitIds.end(), iH) == vHitIds.end()) {
96 aTrk.AddHitIndex(iH);
97 }
98 }
99 }
100 // Initialize arrangements of points and hits within stations
101 aTrk.InitPointsInfo(fvPoints);
102 aTrk.InitHitsInfo(vHits);
103 }
104}
105
106// ---------------------------------------------------------------------------------------------------------------------
107//
108std::string MCData::ToString(int verbose) const
109{
110 if (verbose < 1) {
111 return std::string();
112 }
113 std::stringstream msg;
114 msg << "MCData: " << fvTracks.size() << " tracks, " << fvPoints.size() << " points, ";
115 msg << fmTrackLinkMap.size() << " track links, " << fmPointLinkMap.size() << " point links";
116 if (verbose > 1) {
117 using std::setfill;
118 using std::setw;
119 constexpr int kMaxLines = 100;
120 int nTracks = std::min(kMaxLines, GetNofTracks());
121 int nPoints = std::min(kMaxLines, GetNofPoints());
122 msg << "\n Track sample (first " << nTracks << " tracks):";
123 msg << '\n' << setw(10) << setfill(' ') << fvTracks[0].ToString(verbose, true); // header of the table
124 for (int i = 0; i < nTracks; ++i) {
125 msg << '\n' << setw(10) << setfill(' ') << fvTracks[i].ToString(verbose);
126 }
127 msg << "\n Point sample (first " << nPoints << " points):";
128 msg << '\n' << setw(10) << setfill(' ') << fvPoints[0].ToString(verbose, true); // header of the table
129 for (int i = 0; i < nPoints; ++i) {
130 msg << '\n' << setw(10) << setfill(' ') << fvPoints[i].ToString(verbose);
131 }
132 }
133 return msg.str();
134}
Data structure for internal tracking MC-information (header)
This class represents a package for tracking-related data.
std::string ToString(int verbose=1) const
int GetNofPoints() const
Gets number of points in this event/TS.
void InitTrackInfo(const ca::Vector< CbmL1HitDebugInfo > &vHits)
Initialize information about points and hits association with MC track.
MCData()
Default constructor.
MCData & operator=(const MCData &other)
Copy assignment operator.
ca::Vector< MCPoint > fvPoints
Container of points.
int GetNofTracks() const
Gets number of tracks in this event/TS.
ca::Vector< MCTrack > fvTracks
Container of tracks.
std::unordered_map< LinkKey, int > fmTrackLinkMap
MC track internal index vs. link.
std::unordered_map< LinkKey, int > fmPointLinkMap
MC point internal index vs. link.
void Swap(MCData &other) noexcept
Swap method.
void Clear()
Clears contents.