Skip to content

Commit 40862e2

Browse files
authored
o2-eve: calorimeters display, fixes in json serialisation (#8755)
* o2-eve: calorimeters display, fixes in json serialisation * reformatting * fixed merge errors
1 parent 7d55de1 commit 40862e2

20 files changed

+798
-270
lines changed

EventVisualisation/DataConverter/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ o2_add_library(EventVisualisationDataConverter
1313
SOURCES src/VisualisationEvent.cxx
1414
src/VisualisationTrack.cxx
1515
src/VisualisationCluster.cxx
16+
src/VisualisationCalo.cxx
17+
src/VisualisationEventSerializer.cxx
18+
src/VisualisationEventJSONSerializer.cxx
1619
PUBLIC_LINK_LIBRARIES RapidJSON::RapidJSON
1720
O2::ReconstructionDataFormats
1821
)
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
///
13+
/// \file VisualisationCalo.h
14+
/// \author Julian Myrcha
15+
///
16+
17+
#ifndef O2EVE_VISUALISATIONCALO_H
18+
#define O2EVE_VISUALISATIONCALO_H
19+
20+
#include "rapidjson/document.h"
21+
#include "ReconstructionDataFormats/GlobalTrackID.h"
22+
23+
namespace o2
24+
{
25+
namespace event_visualisation
26+
{
27+
class VisualisationCalo
28+
{
29+
friend class VisualisationEventJSONSerializer;
30+
friend class VisualisationEventROOTSerializer;
31+
32+
public:
33+
// Default constructor
34+
VisualisationCalo();
35+
36+
/// constructor parametrisation (Value Object) for VisualisationCalo class
37+
///
38+
/// Simplifies passing parameters to constructor of VisualisationCalo
39+
/// by providing their names
40+
struct VisualisationCaloVO {
41+
float time = 0;
42+
float energy = 0.0f;
43+
float phi = 0;
44+
float eta = 0;
45+
int PID = 0;
46+
std::string gid = "";
47+
o2::dataformats::GlobalTrackID::Source source;
48+
};
49+
// Constructor with properties initialisation
50+
VisualisationCalo(const VisualisationCaloVO& vo);
51+
52+
VisualisationCalo(const VisualisationCalo& src);
53+
54+
// Energy getter
55+
float getEnergy() const
56+
{
57+
return mEnergy;
58+
}
59+
60+
// Time getter
61+
float getTime() const
62+
{
63+
return mTime;
64+
}
65+
66+
// PID (particle identification code) getter
67+
int getPID() const
68+
{
69+
return mPID;
70+
}
71+
72+
// GID getter
73+
std::string getGIDAsString() const
74+
{
75+
return mGID;
76+
}
77+
78+
// Source Getter
79+
o2::dataformats::GlobalTrackID::Source getSource() const
80+
{
81+
return mSource;
82+
}
83+
84+
// Phi getter
85+
float getPhi() const
86+
{
87+
return mPhi;
88+
}
89+
90+
// Theta getter
91+
float getEta() const
92+
{
93+
return mEta;
94+
}
95+
96+
private:
97+
// Set coordinates of the beginning of the track
98+
void addStartCoordinates(const float xyz[3]);
99+
100+
float mTime; /// time
101+
float mEnergy; /// Energy of the particle
102+
103+
int mPID; /// PDG code of the particle
104+
std::string mGID; /// String representation of gid
105+
106+
float mStartCoordinates[3]; /// Vector of track's start coordinates
107+
108+
float mEta; /// An angle from Z-axis to the radius vector pointing to the particle
109+
float mPhi; /// An angle from X-axis to the radius vector pointing to the particle
110+
111+
// std::vector<int> mChildrenIDs; /// Unique IDs of children particles
112+
o2::dataformats::GlobalTrackID::Source mSource; /// data source of the track (debug)
113+
};
114+
115+
} // namespace event_visualisation
116+
} // namespace o2
117+
118+
#endif // O2EVE_VISUALISATIONCALO_H

EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationCluster.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ namespace event_visualisation
3636

3737
class VisualisationCluster
3838
{
39-
public:
40-
VisualisationCluster(rapidjson::Value& tree);
41-
rapidjson::Value jsonTree(rapidjson::Document::AllocatorType& allocator);
39+
friend class VisualisationEventJSONSerializer;
40+
friend class VisualisationEventROOTSerializer;
4241

42+
public:
4343
// Default constructor
4444
VisualisationCluster(float XYZ[], float time);
4545

EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationConstants.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ enum EVisualisationGroup {
3333
MFT,
3434
MCH,
3535
MID,
36+
EMC,
37+
PHS,
38+
CPV,
3639
NvisualisationGroups
3740
};
3841

@@ -43,7 +46,10 @@ const std::string gVisualisationGroupName[NvisualisationGroups] = {
4346
"TOF",
4447
"MFT",
4548
"MCH",
46-
"MID"};
49+
"MID",
50+
"EMC",
51+
"PHS",
52+
"CPV"};
4753

4854
const bool R3Visualisation[NvisualisationGroups] = {
4955
true, //"ITS",
@@ -52,18 +58,23 @@ const bool R3Visualisation[NvisualisationGroups] = {
5258
true, //"TOF",
5359
true, // "MFT"
5460
true, //"MCH",
55-
true //"MID",
61+
true, //"MID",
62+
true, //"EMC",
63+
true, //"PHS",
64+
true, // "CPV"
5665
};
5766

5867
enum EVisualisationDataType {
59-
Clusters, ///< Reconstructed clusters (RecPoints)
60-
Tracks, ///< Event Summary Data
61-
NdataTypes ///< number of supported data types
68+
Clusters, ///< Reconstructed clusters (RecPoints)
69+
Tracks, ///< Event Summary Data
70+
Calorimeters, ///< Calorimeters
71+
NdataTypes ///< number of supported data types
6272
};
6373

6474
const std::string gDataTypeNames[NdataTypes] = {
6575
"Clusters",
66-
"Tracks"};
76+
"Tracks",
77+
"Calorimeters"};
6778

6879
} // namespace event_visualisation
6980
} // namespace o2

EventVisualisation/DataConverter/include/EventVisualisationDataConverter/VisualisationEvent.h

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121

2222
#include "EventVisualisationDataConverter/VisualisationTrack.h"
2323
#include "EventVisualisationDataConverter/VisualisationCluster.h"
24+
#include "EventVisualisationDataConverter/VisualisationCalo.h"
2425
#include "EventVisualisationDataConverter/VisualisationConstants.h"
2526
#include <forward_list>
2627
#include <ctime>
28+
#include <gsl/span>
2729

2830
namespace o2
2931
{
@@ -39,19 +41,17 @@ namespace event_visualisation
3941

4042
class VisualisationEvent
4143
{
44+
friend class VisualisationEventJSONSerializer;
45+
friend class VisualisationEventROOTSerializer;
46+
4247
public:
4348
struct GIDVisualisation {
4449
bool contains[o2::dataformats::GlobalTrackID::NSources][o2::event_visualisation::EVisualisationGroup::NvisualisationGroups];
4550
};
4651
static GIDVisualisation mVis;
47-
std::string toJson();
48-
void fromJson(std::string json);
49-
bool fromFile(std::string fileName);
5052
VisualisationEvent();
5153
VisualisationEvent(std::string fileName);
5254
VisualisationEvent(const VisualisationEvent& source, EVisualisationGroup filter, float minTime, float maxTime);
53-
void toFile(std::string fileName);
54-
static std::string fileNameIndexed(const std::string fileName, const int index);
5555

5656
/// constructor parametrisation (Value Object) for VisualisationEvent class
5757
///
@@ -105,6 +105,26 @@ class VisualisationEvent
105105
return mTracks.size();
106106
}
107107

108+
gsl::span<const VisualisationCluster> getClustersSpan() const
109+
{
110+
return mClusters;
111+
}
112+
113+
gsl::span<const VisualisationTrack> getTracksSpan() const
114+
{
115+
return mTracks;
116+
}
117+
118+
gsl::span<const VisualisationCalo> getCalorimetersSpan() const
119+
{
120+
return mCalo;
121+
}
122+
123+
size_t getCaloCount() const
124+
{
125+
return mCalo.size();
126+
}
127+
108128
// Returns number of tracks with ITS contribution (including standalone)
109129
size_t getITSTrackCount() const
110130
{
@@ -118,38 +138,59 @@ class VisualisationEvent
118138
{
119139
mTracks.clear();
120140
mClusters.clear();
141+
mCalo.clear();
121142
}
122143

123144
const VisualisationCluster& getCluster(int i) const { return mClusters[i]; };
124145
size_t getClusterCount() const { return mClusters.size(); } // Returns number of clusters
125146
void setWorkflowVersion(float workflowVersion) { this->mWorkflowVersion = workflowVersion; }
126147
void setWorkflowParameters(const std::string& workflowParameters) { this->mWorkflowParameters = workflowParameters; }
127148

128-
o2::header::DataHeader::RunNumberType getRunNumber() const { return this->mRunNumber; }
129-
void setRunNumber(o2::header::DataHeader::RunNumberType runNumber) { this->mRunNumber = runNumber; }
130-
131149
std::string getCollisionTime() const { return this->mCollisionTime; }
132150
void setCollisionTime(std::string collisionTime) { this->mCollisionTime = collisionTime; }
133151

134152
float getMinTimeOfTracks() const { return this->mMinTimeOfTracks; }
135153
float getMaxTimeOfTracks() const { return this->mMaxTimeOfTracks; } /// maximum time of tracks in the event
136154

155+
bool isEmpty() const { return getTrackCount() == 0 && getClusterCount() == 0; }
156+
157+
int getClMask() const { return mClMask; }
158+
void setClMask(int value) { mClMask = value; }
159+
160+
int getTrkMask() const { return mTrkMask; }
161+
void setTrkMask(int value) { mTrkMask = value; }
162+
163+
o2::header::DataHeader::RunNumberType getRunNumber() const { return this->mRunNumber; }
164+
void setRunNumber(o2::header::DataHeader::RunNumberType runNumber) { this->mRunNumber = runNumber; }
165+
166+
o2::header::DataHeader::TFCounterType getTfCounter() const { return this->mTfCounter; }
167+
void setTfCounter(o2::header::DataHeader::TFCounterType value) { this->mTfCounter = value; }
168+
169+
o2::header::DataHeader::TForbitType getFirstTForbit() const { return this->mFirstTForbit; }
170+
void setFirstTForbit(o2::header::DataHeader::TForbitType value) { this->mFirstTForbit = value; }
171+
137172
private:
173+
int mClMask; /// clusters requested during aquisition
174+
int mTrkMask; /// tracks requested during aquisition
175+
o2::header::DataHeader::RunNumberType mRunNumber; /// run number
176+
o2::header::DataHeader::TFCounterType mTfCounter;
177+
o2::header::DataHeader::TForbitType mFirstTForbit;
178+
138179
float mMinTimeOfTracks; /// minimum time of tracks in the event
139180
float mMaxTimeOfTracks; /// maximum time of tracks in the event
140181
float mWorkflowVersion; /// workflow version used to generate this Event
141182
std::string mWorkflowParameters; /// workflow parameters used to generate this Event
142183
int mEventNumber; /// event number in file
143-
o2::header::DataHeader::RunNumberType mRunNumber; /// run number
144184
double mEnergy; /// energy of the collision
145185
int mMultiplicity; /// number of particles reconstructed
146186
std::string mCollidingSystem; /// colliding system (e.g. proton-proton)
147187
std::string mCollisionTime; /// collision timestamp
148188
std::vector<VisualisationTrack> mTracks; /// an array of visualisation tracks
149189
std::vector<VisualisationCluster> mClusters; /// an array of visualisation clusters
190+
std::vector<VisualisationCalo> mCalo; /// an array of visualisation calorimeters
150191
};
151192

152193
} // namespace event_visualisation
153194
} // namespace o2
154195

155-
#endif // ALICE_O2_EVENTVISUALISATION_BASE_VISUALISATIONEVENT_H
196+
#endif // ALICE_O2_EVENTVISUALISATION_BASE_VISUALISATIONEVENT_H
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2+
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3+
// All rights not expressly granted are reserved.
4+
//
5+
// This software is distributed under the terms of the GNU General Public
6+
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7+
//
8+
// In applying this license CERN does not waive the privileges and immunities
9+
// granted to it by virtue of its status as an Intergovernmental Organization
10+
// or submit itself to any jurisdiction.
11+
12+
///
13+
/// \file VisualisationEventSerializer.h
14+
/// \author Julian Myrcha
15+
///
16+
17+
#ifndef O2EVE_VISUALISATIONEVENTJSONSERIALIZER_H
18+
#define O2EVE_VISUALISATIONEVENTJSONSERIALIZER_H
19+
20+
#include "EventVisualisationDataConverter/VisualisationEventSerializer.h"
21+
#include "EventVisualisationDataConverter/VisualisationTrack.h"
22+
#include <string>
23+
24+
namespace o2
25+
{
26+
namespace event_visualisation
27+
{
28+
29+
class VisualisationEventJSONSerializer : public VisualisationEventSerializer
30+
{
31+
static int getIntOrDefault(rapidjson::Value& tree, const char* key, int defaultValue = 0);
32+
33+
std::string toJson(const VisualisationEvent& event) const;
34+
void fromJson(VisualisationEvent& event, std::string json);
35+
36+
// create calo from their JSON representation
37+
VisualisationCalo caloFromJSON(rapidjson::Value& tree);
38+
// create JSON representation of the calo
39+
rapidjson::Value jsonTree(const VisualisationCalo& calo, rapidjson::Document::AllocatorType& allocator) const;
40+
41+
// create cluster from their JSON representation
42+
VisualisationCluster clusterFromJSON(rapidjson::Value& tree);
43+
rapidjson::Value jsonTree(const VisualisationCluster& cluster, rapidjson::Document::AllocatorType& allocator) const;
44+
45+
// create track from their JSON representation
46+
VisualisationTrack trackFromJSON(rapidjson::Value& tree);
47+
// create JSON representation of the track
48+
rapidjson::Value jsonTree(const VisualisationTrack& track, rapidjson::Document::AllocatorType& allocator) const;
49+
50+
public:
51+
bool fromFile(VisualisationEvent& event, std::string fileName) override;
52+
void toFile(const VisualisationEvent& event, std::string fileName) override;
53+
};
54+
55+
} // namespace event_visualisation
56+
} // namespace o2
57+
58+
#endif // O2EVE_VISUALISATIONEVENTJSONSERIALIZER_H

0 commit comments

Comments
 (0)