Skip to content

Commit 944643b

Browse files
HistHelpers: make histID template argument (#4478)
1 parent 77182fb commit 944643b

3 files changed

Lines changed: 140 additions & 139 deletions

File tree

Analysis/Core/include/Analysis/HistHelpers.h

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@
3131

3232
#include "Framework/Logger.h"
3333

34-
namespace o2
35-
{
36-
namespace experimental
37-
{
38-
namespace histhelpers
34+
namespace o2::experimental::histhelpers
3935
{
4036

4137
template <typename T>
@@ -62,18 +58,16 @@ class HistContainer : private RootContainer
6258
}
6359
HistContainer(const HistContainer& other)
6460
{
65-
// pseudo copy ctor to move around empty collection on construction (no real copy constructor!)
66-
// this is needed to be able to put this in OutputObj
67-
// Memo: default copy ctor does not work for TList based collections since
68-
// their copy constructor is implicitly deleted as opposed to TObjArrays
61+
// pseudo copy ctor to move around empty collection on construction (e.g. when put in OutputObj)
62+
// this is needed to make HistContainer also work with TLists since these dont have a copy constructor (as opposed to TObjArrays)
6963
RootContainer::SetOwner(false);
7064
RootContainer::SetName(other.GetName());
7165
}
7266

7367
using HistType = std::variant<std::shared_ptr<THn>, std::shared_ptr<THnSparse>, std::shared_ptr<TH3>, std::shared_ptr<TH2>, std::shared_ptr<TH1>, std::shared_ptr<TProfile3D>, std::shared_ptr<TProfile2D>, std::shared_ptr<TProfile>>;
7468

75-
template <typename T>
76-
void Add(uint8_t histID, T&& hist)
69+
template <uint8_t histID, typename T>
70+
void Add(T&& hist)
7771
{
7872
if (mHistos.find(histID) != mHistos.end()) {
7973
LOGF(WARNING, "HistContainer %s already holds a histogram at histID = %d. Overriding it now...", RootContainer::GetName(), histID);
@@ -111,15 +105,15 @@ class HistContainer : private RootContainer
111105
}
112106

113107
// fill histogram or profile with arguments x,y,z,... and weight if requested
114-
template <bool fillWeight = false, typename... Ts>
115-
void Fill(uint8_t histID, Ts&&... position)
108+
template <uint8_t histID, bool fillWeight = false, typename... Ts>
109+
void Fill(Ts&&... position)
116110
{
117111
std::visit([this, &position...](auto&& hist) { GenericFill<fillWeight>(hist, std::forward<Ts>(position)...); }, mHistos[histID]);
118112
}
119-
template <typename... Ts>
120-
void FillWeight(uint8_t histID, Ts&&... positionAndWeight)
113+
template <uint8_t histID, typename... Ts>
114+
void FillWeight(Ts&&... positionAndWeight)
121115
{
122-
Fill<true>(histID, std::forward<Ts>(positionAndWeight)...);
116+
Fill<histID, true>(std::forward<Ts>(positionAndWeight)...);
123117
}
124118

125119
// make accessible only the RootContainer functions needed for writing to file
@@ -176,8 +170,8 @@ class HistContainer : private RootContainer
176170
}
177171
std::optional<HistType> GetHistVariant(std::shared_ptr<TObject> obj)
178172
{
179-
// Remember: TProfile3D is TH3, TProfile2D is TH2, TH3 is TH1, TH2 is TH1, TProfile is TH1
180173
if (obj) {
174+
// TProfile3D is TH3, TProfile2D is TH2, TH3 is TH1, TH2 is TH1, TProfile is TH1
181175
return GetHistVariant<THn, THnSparse, TProfile3D, TH3, TProfile2D, TH2, TProfile, TH1>(obj);
182176
}
183177
return std::nullopt;
@@ -337,8 +331,6 @@ class Hist
337331
}
338332
};
339333

340-
} // namespace histhelpers
341-
} // namespace experimental
342-
} // namespace o2
334+
} // namespace o2::experimental::histhelpers
343335

344336
#endif

Analysis/Tasks/trackqa.cxx

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -95,75 +95,75 @@ struct TrackQATask {
9595
void init(o2::framework::InitContext&)
9696
{
9797
// kine histograms
98-
kine->Add(pt, new TH1D("pt", "#it{p}_{T};#it{p}_{T} [GeV/c]", 200, 0., 5.));
99-
kine->Add(eta, new TH1D("eta", "#eta;#eta", 180, -0.9, 0.9));
100-
kine->Add(phi, new TH1D("phi", "#phi;#phi [rad]", 180, 0., 2 * M_PI));
98+
kine->Add<pt>(new TH1D("pt", "#it{p}_{T};#it{p}_{T} [GeV/c]", 200, 0., 5.));
99+
kine->Add<eta>(new TH1D("eta", "#eta;#eta", 180, -0.9, 0.9));
100+
kine->Add<phi>(new TH1D("phi", "#phi;#phi [rad]", 180, 0., 2 * M_PI));
101101

102102
// track histograms
103-
trackpar->Add(x, new TH1D("x", "track #it{x} position at dca in local coordinate system;#it{x} [cm]", 200, -0.36, 0.36));
104-
trackpar->Add(y, new TH1D("y", "track #it{y} position at dca in local coordinate system;#it{y} [cm]", 200, -0.5, 0.5));
105-
trackpar->Add(z, new TH1D("z", "track #it{z} position at dca in local coordinate system;#it{z} [cm]", 200, -11., 11.));
106-
trackpar->Add(alpha, new TH1D("alpha", "rotation angle of local wrt. global coordinate system;#alpha [rad]", 36, -M_PI, M_PI));
107-
trackpar->Add(signed1Pt, new TH1D("signed1Pt", "track signed 1/#it{p}_{T};#it{q}/#it{p}_{T}", 200, -8, 8));
108-
trackpar->Add(snp, new TH1D("snp", "sinus of track momentum azimuthal angle;snp", 11, -0.1, 0.1));
109-
trackpar->Add(tgl, new TH1D("tgl", "tangent of the track momentum dip angle;tgl;", 200, -1., 1.));
110-
trackpar->Add(flags, new TH1D("flags", "track flag;flag bit", 64, -0.5, 63.5));
111-
trackpar->Add(dcaXY, new TH1D("dcaXY", "distance of closest approach in #it{xy} plane;#it{dcaXY} [cm];", 200, -0.15, 0.15));
112-
trackpar->Add(dcaZ, new TH1D("dcaZ", "distance of closest approach in #it{z};#it{dcaZ} [cm];", 200, -0.15, 0.15));
103+
trackpar->Add<x>(new TH1D("x", "track #it{x} position at dca in local coordinate system;#it{x} [cm]", 200, -0.36, 0.36));
104+
trackpar->Add<y>(new TH1D("y", "track #it{y} position at dca in local coordinate system;#it{y} [cm]", 200, -0.5, 0.5));
105+
trackpar->Add<z>(new TH1D("z", "track #it{z} position at dca in local coordinate system;#it{z} [cm]", 200, -11., 11.));
106+
trackpar->Add<alpha>(new TH1D("alpha", "rotation angle of local wrt. global coordinate system;#alpha [rad]", 36, -M_PI, M_PI));
107+
trackpar->Add<signed1Pt>(new TH1D("signed1Pt", "track signed 1/#it{p}_{T};#it{q}/#it{p}_{T}", 200, -8, 8));
108+
trackpar->Add<snp>(new TH1D("snp", "sinus of track momentum azimuthal angle;snp", 11, -0.1, 0.1));
109+
trackpar->Add<tgl>(new TH1D("tgl", "tangent of the track momentum dip angle;tgl;", 200, -1., 1.));
110+
trackpar->Add<flags>(new TH1D("flags", "track flag;flag bit", 64, -0.5, 63.5));
111+
trackpar->Add<dcaXY>(new TH1D("dcaXY", "distance of closest approach in #it{xy} plane;#it{dcaXY} [cm];", 200, -0.15, 0.15));
112+
trackpar->Add<dcaZ>(new TH1D("dcaZ", "distance of closest approach in #it{z};#it{dcaZ} [cm];", 200, -0.15, 0.15));
113113

114114
// its histograms
115-
its->Add(itsNCls, new TH1D("itsNCls", "number of found ITS clusters;# clusters ITS", 8, -0.5, 7.5));
116-
its->Add(itsChi2NCl, new TH1D("itsChi2NCl", "chi2 per ITS cluster;chi2 / cluster ITS", 100, 0, 40));
117-
its->Add(itsHits, new TH1D("itsHits", "hitmap ITS;layer ITS", 7, -0.5, 6.5));
115+
its->Add<itsNCls>(new TH1D("itsNCls", "number of found ITS clusters;# clusters ITS", 8, -0.5, 7.5));
116+
its->Add<itsChi2NCl>(new TH1D("itsChi2NCl", "chi2 per ITS cluster;chi2 / cluster ITS", 100, 0, 40));
117+
its->Add<itsHits>(new TH1D("itsHits", "hitmap ITS;layer ITS", 7, -0.5, 6.5));
118118

119119
// tpc histograms
120-
tpc->Add(tpcNClsFindable, new TH1D("tpcNClsFindable", "number of findable TPC clusters;# findable clusters TPC", 165, -0.5, 164.5));
121-
tpc->Add(tpcNClsFound, new TH1D("tpcNClsFound", "number of found TPC clusters;# clusters TPC", 165, -0.5, 164.5));
122-
tpc->Add(tpcNClsShared, new TH1D("tpcNClsShared", "number of shared TPC clusters;# shared clusters TPC", 165, -0.5, 164.5));
123-
tpc->Add(tpcNClsCrossedRows, new TH1D("tpcNClsCrossedRows", "number of crossed TPC rows;# crossed rows TPC", 165, -0.5, 164.5));
124-
tpc->Add(tpcFractionSharedCls, new TH1D("tpcFractionSharedCls", "fraction of shared TPC clusters;fraction shared clusters TPC", 100, 0., 1.));
125-
tpc->Add(tpcCrossedRowsOverFindableCls, new TH1D("tpcCrossedRowsOverFindableCls", "crossed TPC rows over findable clusters;crossed rows / findable clusters TPC", 120, 0.0, 1.2));
126-
tpc->Add(tpcChi2NCl, new TH1D("tpcChi2NCl", "chi2 per cluster in TPC;chi2 / cluster TPC", 100, 0, 10));
120+
tpc->Add<tpcNClsFindable>(new TH1D("tpcNClsFindable", "number of findable TPC clusters;# findable clusters TPC", 165, -0.5, 164.5));
121+
tpc->Add<tpcNClsFound>(new TH1D("tpcNClsFound", "number of found TPC clusters;# clusters TPC", 165, -0.5, 164.5));
122+
tpc->Add<tpcNClsShared>(new TH1D("tpcNClsShared", "number of shared TPC clusters;# shared clusters TPC", 165, -0.5, 164.5));
123+
tpc->Add<tpcNClsCrossedRows>(new TH1D("tpcNClsCrossedRows", "number of crossed TPC rows;# crossed rows TPC", 165, -0.5, 164.5));
124+
tpc->Add<tpcFractionSharedCls>(new TH1D("tpcFractionSharedCls", "fraction of shared TPC clusters;fraction shared clusters TPC", 100, 0., 1.));
125+
tpc->Add<tpcCrossedRowsOverFindableCls>(new TH1D("tpcCrossedRowsOverFindableCls", "crossed TPC rows over findable clusters;crossed rows / findable clusters TPC", 120, 0.0, 1.2));
126+
tpc->Add<tpcChi2NCl>(new TH1D("tpcChi2NCl", "chi2 per cluster in TPC;chi2 / cluster TPC", 100, 0, 10));
127127
}
128128

129129
void process(soa::Filtered<soa::Join<aod::FullTracks, aod::TracksExtended, aod::TrackSelection>>::iterator const& track)
130130
{
131131
// fill kinematic variables
132-
kine->Fill(pt, track.pt());
133-
kine->Fill(eta, track.eta());
134-
kine->Fill(phi, track.phi());
132+
kine->Fill<pt>(track.pt());
133+
kine->Fill<eta>(track.eta());
134+
kine->Fill<phi>(track.phi());
135135

136136
// fill track parameters
137-
trackpar->Fill(alpha, track.alpha());
138-
trackpar->Fill(x, track.x());
139-
trackpar->Fill(y, track.y());
140-
trackpar->Fill(z, track.z());
141-
trackpar->Fill(signed1Pt, track.signed1Pt());
142-
trackpar->Fill(snp, track.snp());
143-
trackpar->Fill(tgl, track.tgl());
137+
trackpar->Fill<alpha>(track.alpha());
138+
trackpar->Fill<x>(track.x());
139+
trackpar->Fill<y>(track.y());
140+
trackpar->Fill<z>(track.z());
141+
trackpar->Fill<signed1Pt>(track.signed1Pt());
142+
trackpar->Fill<snp>(track.snp());
143+
trackpar->Fill<tgl>(track.tgl());
144144
for (unsigned int i = 0; i < 64; i++) {
145145
if (track.flags() & (1 << i))
146-
trackpar->Fill(flags, i);
146+
trackpar->Fill<flags>(i);
147147
}
148-
trackpar->Fill(dcaXY, track.dcaXY());
149-
trackpar->Fill(dcaZ, track.dcaZ());
148+
trackpar->Fill<dcaXY>(track.dcaXY());
149+
trackpar->Fill<dcaZ>(track.dcaZ());
150150

151151
// fill ITS variables
152-
its->Fill(itsNCls, track.itsNCls());
153-
its->Fill(itsChi2NCl, track.itsChi2NCl());
152+
its->Fill<itsNCls>(track.itsNCls());
153+
its->Fill<itsChi2NCl>(track.itsChi2NCl());
154154
for (unsigned int i = 0; i < 7; i++) {
155155
if (track.itsClusterMap() & (1 << i))
156-
its->Fill(itsHits, i);
156+
its->Fill<itsHits>(i);
157157
}
158158

159159
// fill TPC variables
160-
tpc->Fill(tpcNClsFindable, track.tpcNClsFindable());
161-
tpc->Fill(tpcNClsFound, track.tpcNClsFound());
162-
tpc->Fill(tpcNClsShared, track.tpcNClsShared());
163-
tpc->Fill(tpcNClsCrossedRows, track.tpcNClsCrossedRows());
164-
tpc->Fill(tpcCrossedRowsOverFindableCls, track.tpcCrossedRowsOverFindableCls());
165-
tpc->Fill(tpcFractionSharedCls, track.tpcFractionSharedCls());
166-
tpc->Fill(tpcChi2NCl, track.tpcChi2NCl());
160+
tpc->Fill<tpcNClsFindable>(track.tpcNClsFindable());
161+
tpc->Fill<tpcNClsFound>(track.tpcNClsFound());
162+
tpc->Fill<tpcNClsShared>(track.tpcNClsShared());
163+
tpc->Fill<tpcNClsCrossedRows>(track.tpcNClsCrossedRows());
164+
tpc->Fill<tpcCrossedRowsOverFindableCls>(track.tpcCrossedRowsOverFindableCls());
165+
tpc->Fill<tpcFractionSharedCls>(track.tpcFractionSharedCls());
166+
tpc->Fill<tpcChi2NCl>(track.tpcChi2NCl());
167167

168168
// fill TRD variables
169169

0 commit comments

Comments
 (0)