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) const
43{
44 auto it = fIndexMap.find(type);
45 if (it == fIndexMap.end()) {
46 return -1;
47 }
48 const auto& indices = it->second;
49 if (indices.size() <= iData) {
50 return -2;
51 }
52 return indices[iData];
53}
54// -------------------------------------------------------------------------
55
56
57// ----- Get total number of data objects ------------------------------
59{
60 size_t result = 0;
61 for (auto& entry : fIndexMap) {
62 result += entry.second.size();
63 }
64 return result;
65}
66// -------------------------------------------------------------------------
67
68
69// ----- Get number of data of a type in this event --------------------
71{
72
73 if (fIndexMap.find(type) == fIndexMap.end()) return 0;
74 else
75 return fIndexMap.at(type).size();
76}
77// -------------------------------------------------------------------------
78
79
80// ----- Set the vertex parameters -------------------------------------
81void CbmEvent::SetVertex(double x, double y, double z, double chi2, int32_t ndf, int32_t nTracks,
82 const TMatrixFSym& covMat)
83{
84 fVertex.SetVertex(x, y, z, chi2, ndf, nTracks, covMat);
85}
86// -------------------------------------------------------------------------
87
88// ----- Swap two events
90{
91 std::swap(fNumber, e.fNumber);
92 std::swap(fTimeStart, e.fTimeStart);
93 std::swap(fTimeEnd, e.fTimeEnd);
94 std::swap(fVertex, e.fVertex);
95 std::swap(fMatch, e.fMatch);
96 std::swap(fIndexMap, e.fIndexMap);
97}
98
99
100// ----- String output -------------------------------------------------
101std::string CbmEvent::ToString() const
102{
103 std::stringstream ss;
104 ss << "Event " << fNumber << " at t = " << fTimeStart << " ns. Registered data types: " << fIndexMap.size()
105 << ", data objects: " << GetNofData() << (nullptr != fMatch ? ", with matches" : ", without matches") << "\n";
106 for (auto it = fIndexMap.begin(); it != fIndexMap.end(); it++) {
107 ss << " -- Data type " << it->first << ", number of data " << it->second.size() << "\n";
108 }
109 return ss.str();
110}
111// -------------------------------------------------------------------------
112
113// -------------------------------------------------------------------------
115{
116 for (auto it = fIndexMap.begin(); it != fIndexMap.end(); it++) {
117 std::sort(it->second.begin(), it->second.end());
118 }
119}
120// -------------------------------------------------------------------------
121
ClassImp(CbmConverterManager)
ECbmDataType
Definition CbmDefs.h:90
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:232
size_t GetNofData() const
Definition CbmEvent.cxx:58
CbmMatch * fMatch
Match object to MCEvent.
Definition CbmEvent.h:229
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:81
double fTimeStart
Event start time [ns].
Definition CbmEvent.h:225
int32_t fNumber
Event number.
Definition CbmEvent.h:224
void Swap(CbmEvent &e)
Definition CbmEvent.cxx:89
uint32_t GetIndex(ECbmDataType type, uint32_t iData) const
Definition CbmEvent.cxx:42
CbmVertex fVertex
Primary Vertex.
Definition CbmEvent.h:228
double fTimeEnd
Event end time [ns].
Definition CbmEvent.h:226
void ClearData(ECbmDataType type)
Definition CbmEvent.cxx:37
void AddData(ECbmDataType type, uint32_t index)
Definition CbmEvent.cxx:33
void SortIndices()
Definition CbmEvent.cxx:114
std::string ToString() const
Definition CbmEvent.cxx:101
void SetVertex(double x, double y, double z, double chi2, int32_t ndf, int32_t nTracks, const TMatrixFSym &covMat)