CbmRoot
Loading...
Searching...
No Matches
CaMcData.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 "CaMcData.h"
11
12#include "CaMcHitInfo.h"
13
14#include <iomanip>
15#include <sstream>
16#include <utility> // for std::move
17
19
20// ---------------------------------------------------------------------------------------------------------------------
21//
23
24// ---------------------------------------------------------------------------------------------------------------------
25//
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 fpMcHitInfos = &vHits;
89 for (auto& aTrk : fvTracks) {
90 // Assign hits to tracks
91 aTrk.ClearHitIndexes();
92 auto& vHitIds = aTrk.GetHitIndexes();
93 for (int iP : aTrk.GetPointIndexes()) {
94 const auto& point = fvPoints[iP];
95 for (int iH : point.GetHitIndexes()) {
96 if (std::find(vHitIds.begin(), vHitIds.end(), iH) == vHitIds.end()) {
97 aTrk.AddHitIndex(iH);
98 }
99 }
100 }
101 // Initialize arrangements of points and hits within stations
102 aTrk.InitPointsInfo(fvPoints);
103 aTrk.InitHitsInfo(vHits);
104 }
105}
106
107// ---------------------------------------------------------------------------------------------------------------------
108//
109std::string McData::ToString(int verbose) const
110{
111 if (verbose < 1) {
112 return std::string();
113 }
114 std::stringstream msg;
115 msg << "McData: " << fvTracks.size() << " tracks, " << fvPoints.size() << " points, ";
116 msg << fmTrackLinkMap.size() << " track links, " << fmPointLinkMap.size() << " point links";
117 if (verbose > 1) {
118 using std::setfill;
119 using std::setw;
120 constexpr int kMaxLines = 100;
121 int nTracks = std::min(kMaxLines, GetNofTracks());
122 int nPoints = std::min(kMaxLines, GetNofPoints());
123 msg << "\n Track sample (first " << nTracks << " tracks):";
124 msg << '\n' << setw(10) << setfill(' ') << fvTracks[0].ToString(verbose, true); // header of the table
125 for (int i = 0; i < nTracks; ++i) {
126 msg << '\n' << setw(10) << setfill(' ') << fvTracks[i].ToString(verbose);
127 }
128 msg << "\n Point sample (first " << nPoints << " points):";
129 msg << '\n' << setw(10) << setfill(' ') << fvPoints[0].ToString(verbose, true); // header of the table
130 for (int i = 0; i < nPoints; ++i) {
131 msg << '\n' << setw(10) << setfill(' ') << fvPoints[i].ToString(verbose);
132 }
133 }
134 return msg.str();
135}
Data structure for internal tracking MC-information (header)
McData()
Default constructor.
Definition CaMcData.cxx:22
This class represents a package for tracking-related data.
Definition CaMcData.h:33
McData & operator=(const McData &other)
Copy assignment operator.
Definition CaMcData.cxx:42
int GetNofPoints() const
Gets number of points in this event/TS.
Definition CaMcData.h:126
std::unordered_map< McLinkKey, int > fmPointLinkMap
MC point internal index vs. link.
Definition CaMcData.h:232
void Swap(McData &other) noexcept
Swap method.
Definition CaMcData.cxx:63
void SetMcHitInfo(const ca::Vector< cbm::algo::ca::McHitInfo > &vHits)
Initialize information about points and hits association with MC track.
Definition CaMcData.cxx:86
std::array< int, constants::size::MaxNdetectors > fvNofPointsUsed
Number of points used vs. detector.
Definition CaMcData.h:230
void Clear()
Clears contents.
Definition CaMcData.cxx:76
const ca::Vector< cbm::algo::ca::McHitInfo > * fpMcHitInfos
Definition CaMcData.h:235
McData()
Default constructor.
Definition CaMcData.cxx:22
ca::Vector< McPoint > fvPoints
Container of points.
Definition CaMcData.h:226
int GetNofTracks() const
Gets number of tracks in this event/TS.
Definition CaMcData.h:123
ca::Vector< McTrack > fvTracks
Container of tracks.
Definition CaMcData.h:227
std::array< int, constants::size::MaxNdetectors > fvNofPointsOrig
Total number of points by detector.
Definition CaMcData.h:229
std::unordered_map< McLinkKey, int > fmTrackLinkMap
MC track internal index vs. link.
Definition CaMcData.h:233
std::string ToString(int verbose=1) const
Definition CaMcData.cxx:109