CbmRoot
Loading...
Searching...
No Matches
CbmEvent.cxx
Go to the documentation of this file.
1/* Copyright (C) 2016-2020 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
2 SPDX-License-Identifier: GPL-3.0-only
3 Authors: Volker Friese [committer] */
4
10#include "CbmEvent.h"
11
12#include <algorithm> // for std::sort
13#include <iostream> // for operator<<, basic_ostream
14#include <sstream> // for stringstream
15#include <string> // for char_traits
16#include <utility> // for pair
17
18// ----- Add data to event ---------------------------------------------
20 : TObject(rhs)
21 , fNumber(rhs.fNumber)
22 , fTimeStart(rhs.fTimeStart)
23 , fTimeEnd(rhs.fTimeEnd)
24 , fVertex(rhs.fVertex)
25 , fMatch(nullptr)
26 , fIndexMap(rhs.fIndexMap)
27{
28 if (fMatch) fMatch = new CbmMatch(*(rhs.fMatch));
29}
30// -------------------------------------------------------------------------
31
32// ----- Add data to event ---------------------------------------------
33void CbmEvent::AddData(ECbmDataType type, uint32_t index) { fIndexMap[type].push_back(index); }
34// -------------------------------------------------------------------------
35
36// ----- Clear a specific data branch ---------------------------------------------
37void CbmEvent::ClearData(ECbmDataType type) { fIndexMap[type].clear(); }
38// -------------------------------------------------------------------------
39
40
41// ----- Get a data index ----------------------------------------------
42uint32_t CbmEvent::GetIndex(ECbmDataType type, uint32_t iData)
43{
44
45 if (fIndexMap.find(type) == fIndexMap.end()) return -1;
46 if (fIndexMap[type].size() <= iData) return -2;
47 return fIndexMap.at(type)[iData];
48}
49// -------------------------------------------------------------------------
50
51
52// ----- Get total number of data objects ------------------------------
54{
55 size_t result = 0;
56 for (auto& entry : fIndexMap) {
57 result += entry.second.size();
58 }
59 return result;
60}
61// -------------------------------------------------------------------------
62
63
64// ----- Get number of data of a type in this event --------------------
66{
67
68 if (fIndexMap.find(type) == fIndexMap.end()) return 0;
69 else
70 return fIndexMap.at(type).size();
71}
72// -------------------------------------------------------------------------
73
74
75// ----- Set the vertex parameters -------------------------------------
76void CbmEvent::SetVertex(double x, double y, double z, double chi2, int32_t ndf, int32_t nTracks,
77 const TMatrixFSym& covMat)
78{
79 fVertex.SetVertex(x, y, z, chi2, ndf, nTracks, covMat);
80}
81// -------------------------------------------------------------------------
82
83// ----- Swap two events
85{
86 std::swap(fNumber, e.fNumber);
87 std::swap(fTimeStart, e.fTimeStart);
88 std::swap(fTimeEnd, e.fTimeEnd);
89 std::swap(fVertex, e.fVertex);
90 std::swap(fMatch, e.fMatch);
91 std::swap(fIndexMap, e.fIndexMap);
92}
93
94
95// ----- String output -------------------------------------------------
96std::string CbmEvent::ToString() const
97{
98 std::stringstream ss;
99 ss << "Event " << fNumber << " at t = " << fTimeStart << " ns. Registered data types: " << fIndexMap.size()
100 << ", data objects: " << GetNofData() << (nullptr != fMatch ? ", with matches" : ", without matches") << "\n";
101 for (auto it = fIndexMap.begin(); it != fIndexMap.end(); it++) {
102 ss << " -- Data type " << it->first << ", number of data " << it->second.size() << "\n";
103 }
104 return ss.str();
105}
106// -------------------------------------------------------------------------
107
108// -------------------------------------------------------------------------
110{
111 for (auto it = fIndexMap.begin(); it != fIndexMap.end(); it++) {
112 std::sort(it->second.begin(), it->second.end());
113 }
114}
115// -------------------------------------------------------------------------
116
ClassImp(CbmConverterManager)
ECbmDataType
Definition CbmDefs.h:90
static constexpr size_t size()
Definition KfSimdPseudo.h:2
Class characterising one event by a collection of links (indices) to data objects,...
Definition CbmEvent.h:34
std::map< ECbmDataType, std::vector< uint32_t > > fIndexMap
Definition CbmEvent.h:225
size_t GetNofData() const
Definition CbmEvent.cxx:53
CbmMatch * fMatch
Match object to MCEvent.
Definition CbmEvent.h:222
CbmEvent()
Definition CbmEvent.h:38
void SetVertex(double x, double y, double z, double chi2, int32_t ndf, int32_t nTracks, const TMatrixFSym &covMat)
Definition CbmEvent.cxx:76
double fTimeStart
Event start time [ns].
Definition CbmEvent.h:218
int32_t fNumber
Event number.
Definition CbmEvent.h:217
void Swap(CbmEvent &e)
Definition CbmEvent.cxx:84
CbmVertex fVertex
Primary Vertex.
Definition CbmEvent.h:221
double fTimeEnd
Event end time [ns].
Definition CbmEvent.h:219
uint32_t GetIndex(ECbmDataType type, uint32_t iData)
Definition CbmEvent.cxx:42
void ClearData(ECbmDataType type)
Definition CbmEvent.cxx:37
void AddData(ECbmDataType type, uint32_t index)
Definition CbmEvent.cxx:33
void SortIndices()
Definition CbmEvent.cxx:109
std::string ToString() const
Definition CbmEvent.cxx:96
void SetVertex(double x, double y, double z, double chi2, int32_t ndf, int32_t nTracks, const TMatrixFSym &covMat)