Skip to content

Commit 194e9c2

Browse files
committed
Improve code
1 parent e633298 commit 194e9c2

File tree

3 files changed

+135
-138
lines changed

3 files changed

+135
-138
lines changed

Tutorials/PWGHF/DataModelMini.h

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ DECLARE_SOA_INDEX_COLUMN_FULL(Prong1, prong1, int, Tracks, "_1"); //! prong 1
4444
} // namespace hf_track_index
4545

4646
// Track index skim table
47-
DECLARE_SOA_TABLE(HfT2Prongs, "AOD", "HFT2PRONG", //! table with prongs indices
47+
DECLARE_SOA_TABLE(HfT2Prongs, "AOD", "HFT2PRONG", //! table with prong indices
4848
hf_track_index::Prong0Id,
4949
hf_track_index::Prong1Id);
5050

@@ -53,36 +53,36 @@ namespace hf_cand_prong2
5353
{
5454
// Candidate columns
5555
// collision properties
56-
DECLARE_SOA_INDEX_COLUMN(Collision, collision); //! collisions
56+
DECLARE_SOA_INDEX_COLUMN(Collision, collision); //! collision
5757
// secondary vertex
58-
DECLARE_SOA_COLUMN(XSecondaryVertex, xSecondaryVertex, float); //! x coordinate of the secondary vertex
59-
DECLARE_SOA_COLUMN(YSecondaryVertex, ySecondaryVertex, float); //! y coordinate of the secondary vertex
60-
DECLARE_SOA_COLUMN(ZSecondaryVertex, zSecondaryVertex, float); //! z coordinate of the secondary vertex
61-
DECLARE_SOA_DYNAMIC_COLUMN(RSecondaryVertex, rSecondaryVertex, //! radius of the secondary vertex
58+
DECLARE_SOA_COLUMN(XSecondaryVertex, xSecondaryVertex, float); //! x coordinate of the secondary vertex [cm]
59+
DECLARE_SOA_COLUMN(YSecondaryVertex, ySecondaryVertex, float); //! y coordinate of the secondary vertex [cm]
60+
DECLARE_SOA_COLUMN(ZSecondaryVertex, zSecondaryVertex, float); //! z coordinate of the secondary vertex [cm]
61+
DECLARE_SOA_DYNAMIC_COLUMN(RSecondaryVertex, rSecondaryVertex, //! radius of the secondary vertex [cm]
6262
[](float xVtxS, float yVtxS) -> float { return RecoDecay::sqrtSumOfSquares(xVtxS, yVtxS); });
6363
// prong properties
64-
DECLARE_SOA_COLUMN(PxProng0, pxProng0, float); //! px of prong 0
65-
DECLARE_SOA_COLUMN(PyProng0, pyProng0, float); //! py of prong 0
66-
DECLARE_SOA_COLUMN(PzProng0, pzProng0, float); //! pz of prong 0
67-
DECLARE_SOA_DYNAMIC_COLUMN(PtProng0, ptProng0, //! pt of prong 0
64+
DECLARE_SOA_COLUMN(PxProng0, pxProng0, float); //! px of prong 0 [GeV/c]
65+
DECLARE_SOA_COLUMN(PyProng0, pyProng0, float); //! py of prong 0 [GeV/c]
66+
DECLARE_SOA_COLUMN(PzProng0, pzProng0, float); //! pz of prong 0 [GeV/c]
67+
DECLARE_SOA_DYNAMIC_COLUMN(PtProng0, ptProng0, //! pt of prong 0 [GeV/c]
6868
[](float px, float py) -> float { return RecoDecay::pt(px, py); });
69-
DECLARE_SOA_COLUMN(PxProng1, pxProng1, float); //! px of prong 1
70-
DECLARE_SOA_COLUMN(PyProng1, pyProng1, float); //! py of prong 1
71-
DECLARE_SOA_COLUMN(PzProng1, pzProng1, float); //! pz of prong 1
72-
DECLARE_SOA_DYNAMIC_COLUMN(PtProng1, ptProng1, //! pt of prong 1
69+
DECLARE_SOA_COLUMN(PxProng1, pxProng1, float); //! px of prong 1 [GeV/c]
70+
DECLARE_SOA_COLUMN(PyProng1, pyProng1, float); //! py of prong 1 [GeV/c]
71+
DECLARE_SOA_COLUMN(PzProng1, pzProng1, float); //! pz of prong 1 [GeV/c]
72+
DECLARE_SOA_DYNAMIC_COLUMN(PtProng1, ptProng1, //! pt of prong 1 [GeV/c]
7373
[](float px, float py) -> float { return RecoDecay::pt(px, py); });
7474
// candidate properties
75-
DECLARE_SOA_DYNAMIC_COLUMN(DecayLength, decayLength, //! decay length of candidate
75+
DECLARE_SOA_DYNAMIC_COLUMN(DecayLength, decayLength, //! decay length of candidate [cm]
7676
[](float xVtxP, float yVtxP, float zVtxP, float xVtxS, float yVtxS, float zVtxS) -> float { return RecoDecay::distance(std::array{xVtxP, yVtxP, zVtxP}, std::array{xVtxS, yVtxS, zVtxS}); });
77-
DECLARE_SOA_DYNAMIC_COLUMN(Pt, pt, //! pt of candidate
77+
DECLARE_SOA_DYNAMIC_COLUMN(Pt, pt, //! pt of candidate [GeV/c]
7878
[](float px, float py) -> float { return RecoDecay::pt(px, py); });
79-
DECLARE_SOA_EXPRESSION_COLUMN(Px, px, //! px of candidate
79+
DECLARE_SOA_EXPRESSION_COLUMN(Px, px, //! px of candidate [GeV/c]
8080
float, 1.f * pxProng0 + 1.f * pxProng1);
81-
DECLARE_SOA_EXPRESSION_COLUMN(Py, py, //! py of candidate
81+
DECLARE_SOA_EXPRESSION_COLUMN(Py, py, //! py of candidate [GeV/c]
8282
float, 1.f * pyProng0 + 1.f * pyProng1);
83-
DECLARE_SOA_EXPRESSION_COLUMN(Pz, pz, //! pz of candidate
83+
DECLARE_SOA_EXPRESSION_COLUMN(Pz, pz, //! pz of candidate [GeV/c]
8484
float, 1.f * pzProng0 + 1.f * pzProng1);
85-
DECLARE_SOA_DYNAMIC_COLUMN(M, m, //! invariant mass of candidate
85+
DECLARE_SOA_DYNAMIC_COLUMN(M, m, //! invariant mass of candidate [GeV/c^2]
8686
[](float px0, float py0, float pz0, float px1, float py1, float pz1, const std::array<double, 2>& m) -> float { return RecoDecay::m(std::array{std::array{px0, py0, pz0}, std::array{px1, py1, pz1}}, m); });
8787
DECLARE_SOA_DYNAMIC_COLUMN(Cpa, cpa, //! cosine of pointing angle of candidate
8888
[](float xVtxP, float yVtxP, float zVtxP, float xVtxS, float yVtxS, float zVtxS, float px, float py, float pz) -> float { return RecoDecay::cpa(std::array{xVtxP, yVtxP, zVtxP}, std::array{xVtxS, yVtxS, zVtxS}, std::array{px, py, pz}); });
@@ -116,7 +116,7 @@ namespace hf_selcandidate_d0
116116
{
117117
// Candidate selection columns
118118
DECLARE_SOA_COLUMN(IsSelD0, isSelD0, int); //! selection flag for D0
119-
DECLARE_SOA_COLUMN(IsSelD0bar, isSelD0bar, int); //! selection flag for D0 bar
119+
DECLARE_SOA_COLUMN(IsSelD0bar, isSelD0bar, int); //! selection flag for D0bar
120120
} // namespace hf_selcandidate_d0
121121

122122
// Candidate selection table

Tutorials/PWGHF/skimCreatorMini.cxx

Lines changed: 67 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ using namespace o2;
4141
using namespace o2::aod;
4242
using namespace o2::framework;
4343
using namespace o2::framework::expressions;
44+
using namespace o2::constants::physics;
4445

4546
// Track selection =====================================================================
4647

@@ -49,67 +50,62 @@ struct HfSkimCreatorMiniTagSelTracks {
4950
Produces<aod::HfTSelTrack> rowSelectedTrack;
5051

5152
// 2-prong cuts
52-
Configurable<float> ptTrackMin{"ptTrackMin", 0.3, "min. track pT for 2 prong candidate"};
53-
Configurable<float> etaTrackMax{"etaTrackMax", 0.8, "max. pseudorapidity for 2 prong candidate"};
54-
Configurable<float> dcaTrackMin{"dcaTrackMin", 0.0025, "min. DCA for 2 prong candidate"};
53+
Configurable<float> ptTrackMin{"ptTrackMin", 0.3f, "min. track pT for 2 prong candidate [GeV/c]"};
54+
Configurable<float> etaTrackMax{"etaTrackMax", 0.8f, "max. pseudorapidity for 2 prong candidate"};
55+
Configurable<float> dcaTrackMin{"dcaTrackMin", 0.0025f, "min. DCA for 2 prong candidate [cm]"};
5556

5657
using TracksWDcaSel = soa::Join<aod::Tracks, aod::TracksDCA, aod::TrackSelection>;
5758

58-
HistogramRegistry registry{
59-
"registry",
60-
{}};
59+
HistogramRegistry registry{"registry"};
6160

6261
void init(InitContext&)
6362
{
64-
const TString strTitle = "D^{0} candidates";
6563
const TString strPt = "#it{p}_{T}^{track} (GeV/#it{c})";
6664
const TString strEntries = "entries";
67-
registry.add("hPtNoCuts", "all tracks;" + strPt + ";" + strEntries, {HistType::kTH1F, {{100, 0., 10.}}});
68-
registry.add("hPtCuts2Prong", "tracks selected for 2-prong vertexing;" + strPt + ";" + strEntries, {HistType::kTH1F, {{100, 0., 10.}}});
65+
registry.add("hPtNoCuts", "all tracks;" + strPt + ";" + strEntries, {HistType::kTH1D, {{100, 0., 10.}}});
66+
registry.add("hPtCuts2Prong", "tracks selected for 2-prong vertexing;" + strPt + ";" + strEntries, {HistType::kTH1D, {{100, 0., 10.}}});
6967
registry.add("hPtVsDcaXYToPvCuts2Prong", "tracks selected for 2-prong vertexing;" + strPt + ";" + "DCAxy to prim. vtx. (cm)" + ";" + strEntries, {HistType::kTH2F, {{100, 0., 10.}, {400, -2., 2.}}});
70-
registry.add("hEtaCuts2Prong", "tracks selected for 2-prong vertexing;#it{#eta};" + strEntries, {HistType::kTH1F, {{static_cast<int>(1.2 * etaTrackMax * 100), -1.2 * etaTrackMax, 1.2 * etaTrackMax}}});
68+
registry.add("hEtaCuts2Prong", "tracks selected for 2-prong vertexing;#it{#eta};" + strEntries, {HistType::kTH1D, {{static_cast<int>(1.2 * etaTrackMax * 100), -1.2 * etaTrackMax, 1.2 * etaTrackMax}}});
7169
}
7270

73-
void process(TracksWDcaSel const& tracks)
71+
void process(TracksWDcaSel::iterator const& track)
7472
{
75-
for (const auto& track : tracks) {
76-
bool statusProng = true;
73+
const auto ptTrack{track.pt()};
74+
registry.fill(HIST("hPtNoCuts"), ptTrack);
7775

78-
auto ptTrack = track.pt();
79-
registry.fill(HIST("hPtNoCuts"), ptTrack);
76+
bool statusProng{true};
8077

81-
// pT cut
82-
if (ptTrack < ptTrackMin) {
83-
statusProng = false;
84-
}
85-
86-
// eta cut
87-
auto etaTrack = track.eta();
88-
if (statusProng && std::abs(etaTrack) > etaTrackMax) {
89-
statusProng = false;
90-
}
78+
// pT cut
79+
if (ptTrack < ptTrackMin) {
80+
statusProng = false;
81+
}
9182

92-
// quality cut
93-
if (!track.isGlobalTrackWoDCA()) {
94-
statusProng = false;
95-
}
83+
// eta cut
84+
const auto etaTrack{track.eta()};
85+
if (statusProng && std::abs(etaTrack) > etaTrackMax) {
86+
statusProng = false;
87+
}
9688

97-
// DCA cut
98-
auto dcaXY = track.dcaXY();
99-
if (statusProng && std::abs(dcaXY) < dcaTrackMin) {
100-
statusProng = false;
101-
}
89+
// quality cut
90+
if (!track.isGlobalTrackWoDCA()) {
91+
statusProng = false;
92+
}
10293

103-
// fill histograms
104-
if (statusProng) {
105-
registry.fill(HIST("hPtCuts2Prong"), ptTrack);
106-
registry.fill(HIST("hEtaCuts2Prong"), etaTrack);
107-
registry.fill(HIST("hPtVsDcaXYToPvCuts2Prong"), ptTrack, dcaXY);
108-
}
94+
// DCA cut
95+
const auto dcaXY{track.dcaXY()};
96+
if (statusProng && std::abs(dcaXY) < dcaTrackMin) {
97+
statusProng = false;
98+
}
10999

110-
// fill table row
111-
rowSelectedTrack(statusProng);
100+
// fill histograms
101+
if (statusProng) {
102+
registry.fill(HIST("hPtCuts2Prong"), ptTrack);
103+
registry.fill(HIST("hEtaCuts2Prong"), etaTrack);
104+
registry.fill(HIST("hPtVsDcaXYToPvCuts2Prong"), ptTrack, dcaXY);
112105
}
106+
107+
// fill table row
108+
rowSelectedTrack(statusProng);
113109
}
114110
};
115111

@@ -121,30 +117,30 @@ struct HfSkimCreatorMini {
121117
Produces<aod::HfT2Prongs> rowTrackIndexProng2;
122118

123119
// vertexing parameters
124-
Configurable<float> magneticField{"magneticField", 5., "magnetic field [kG]"};
125-
Configurable<bool> propagateToPCA{"propagateToPCA", true, "create tracks version propagated to PCA"};
120+
Configurable<float> magneticField{"magneticField", 5.f, "magnetic field [kG]"};
121+
Configurable<bool> propagateToPCA{"propagateToPCA", true, "Create tracks version propagated to PCA"};
126122
Configurable<bool> useAbsDCA{"useAbsDCA", false, "Minimise abs. distance rather than chi2"};
127-
Configurable<float> maxR{"maxR", 200., "reject PCA's above this radius"};
128-
Configurable<float> maxDZIni{"maxDZIni", 4., "reject (if>0) PCA candidate if tracks DZ exceeds threshold"};
129-
Configurable<float> minParamChange{"minParamChange", 1.e-3, "stop iterations if largest change of any X is smaller than this"};
130-
Configurable<float> minRelChi2Change{"minRelChi2Change", 0.9, "stop iterations if chi2/chi2old > this"};
123+
Configurable<float> maxR{"maxR", 200.f, "Reject PCA's above this radius"};
124+
Configurable<float> maxDZIni{"maxDZIni", 4.f, "Reject (if>0) PCA candidate if tracks DZ exceeds threshold"};
125+
Configurable<float> minParamChange{"minParamChange", 1.e-3f, "Stop iterations if largest change of any X is smaller than this"};
126+
Configurable<float> minRelChi2Change{"minRelChi2Change", 0.9f, "Stop iterations if chi2/chi2old > this"};
131127

132-
o2::vertexing::DCAFitterN<2> fitter; // 2-prong vertex fitter
128+
o2::vertexing::DCAFitterN<2> fitter{}; // 2-prong vertex fitter
133129

134130
using SelectedTracks = soa::Filtered<soa::Join<aod::Tracks, aod::TracksCov, aod::HfTSelTrack>>;
135131

136132
Filter filterSelectTracks = aod::hf_seltrack::isSelProng == true;
137133

138-
HistogramRegistry registry{
139-
"registry",
140-
{// 2-prong histograms
141-
{"hVtx2ProngX", "2-prong candidates;#it{x}_{sec. vtx.} (cm);entries", {HistType::kTH1F, {{1000, -2., 2.}}}},
142-
{"hVtx2ProngY", "2-prong candidates;#it{y}_{sec. vtx.} (cm);entries", {HistType::kTH1F, {{1000, -2., 2.}}}},
143-
{"hVtx2ProngZ", "2-prong candidates;#it{z}_{sec. vtx.} (cm);entries", {HistType::kTH1F, {{1000, -20., 20.}}}},
144-
{"hMassD0ToPiK", "D^{0} candidates;inv. mass (#pi K) (GeV/#it{c}^{2});entries", {HistType::kTH1F, {{500, 0., 5.}}}}}};
134+
HistogramRegistry registry{"registry"};
145135

146136
void init(InitContext&)
147137
{
138+
// 2-prong histograms
139+
registry.add("hVtx2ProngX", "2-prong candidates;#it{x}_{sec. vtx.} (cm);entries", {HistType::kTH1D, {{1000, -2., 2.}}});
140+
registry.add("hVtx2ProngY", "2-prong candidates;#it{y}_{sec. vtx.} (cm);entries", {HistType::kTH1D, {{1000, -2., 2.}}});
141+
registry.add("hVtx2ProngZ", "2-prong candidates;#it{z}_{sec. vtx.} (cm);entries", {HistType::kTH1D, {{1000, -20., 20.}}});
142+
registry.add("hMassD0", "D^{0} candidates;inv. mass (#pi K) (GeV/#it{c}^{2});entries", {HistType::kTH1D, {{500, 0., 5.}}});
143+
148144
// Configure the vertexer
149145
fitter.setBz(magneticField);
150146
fitter.setPropagateToPCA(propagateToPCA);
@@ -159,23 +155,23 @@ struct HfSkimCreatorMini {
159155
SelectedTracks const& tracks)
160156
{
161157
// loop over positive tracks
162-
for (const auto& trackPos1 : tracks) {
163-
if (trackPos1.signed1Pt() < 0) {
158+
for (const auto& trackPos : tracks) {
159+
if (trackPos.signed1Pt() < 0) {
164160
continue;
165161
}
166-
auto trackParVarPos1 = getTrackParCov(trackPos1);
162+
const auto trackParVarPos{getTrackParCov(trackPos)};
167163

168164
// loop over negative tracks
169-
for (const auto& trackNeg1 : tracks) {
170-
if (trackNeg1.signed1Pt() > 0) {
165+
for (const auto& trackNeg : tracks) {
166+
if (trackNeg.signed1Pt() > 0) {
171167
continue;
172168
}
173-
auto trackParVarNeg1 = getTrackParCov(trackNeg1);
169+
const auto trackParVarNeg{getTrackParCov(trackNeg)};
174170

175-
// secondary vertex reconstruction and further 2-prong selections
171+
// secondary-vertex reconstruction and further 2-prong selections
176172
int nVtxFromFitter = 0;
177173
try {
178-
nVtxFromFitter = fitter.process(trackParVarPos1, trackParVarNeg1);
174+
nVtxFromFitter = fitter.process(trackParVarPos, trackParVarNeg);
179175
} catch (...) {
180176
}
181177
if (nVtxFromFitter == 0) {
@@ -190,16 +186,18 @@ struct HfSkimCreatorMini {
190186
fitter.getTrack(1).getPxPyPzGlo(pVec1);
191187

192188
// fill table row
193-
rowTrackIndexProng2(trackPos1.globalIndex(),
194-
trackNeg1.globalIndex());
189+
rowTrackIndexProng2(trackPos.globalIndex(),
190+
trackNeg.globalIndex());
195191

196192
// fill histograms
197193
registry.fill(HIST("hVtx2ProngX"), secondaryVertex[0]);
198194
registry.fill(HIST("hVtx2ProngY"), secondaryVertex[1]);
199195
registry.fill(HIST("hVtx2ProngZ"), secondaryVertex[2]);
200-
std::array<std::array<float, 3>, 2> arrMom = {pVec0, pVec1};
201-
auto mass2Prong = RecoDecay::m(arrMom, std::array{o2::constants::physics::MassPiPlus, o2::constants::physics::MassKPlus});
202-
registry.fill(HIST("hMassD0ToPiK"), mass2Prong);
196+
const std::array arrayMomenta{pVec0, pVec1};
197+
const auto massPiK{RecoDecay::m(arrayMomenta, std::array{MassPiPlus, MassKPlus})};
198+
const auto massKPi{RecoDecay::m(arrayMomenta, std::array{MassKPlus, MassPiPlus})};
199+
registry.fill(HIST("hMassD0"), massPiK);
200+
registry.fill(HIST("hMassD0"), massKPi);
203201
}
204202
}
205203
}

0 commit comments

Comments
 (0)