-
Notifications
You must be signed in to change notification settings - Fork 652
Expand file tree
/
Copy pathPairCuts.h
More file actions
341 lines (273 loc) · 11 KB
/
PairCuts.h
File metadata and controls
341 lines (273 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
#ifndef PWGCF_CORE_PAIRCUTS_H_
#define PWGCF_CORE_PAIRCUTS_H_
#include <CommonConstants/MathConstants.h>
#include <Framework/HistogramRegistry.h>
#include <Framework/HistogramSpec.h>
#include <Framework/Logger.h>
#include <RtypesCore.h>
#include <cmath>
// Functions which cut on particle pairs (decays, conversions, two-track cuts)
//
// Author: Jan Fiete Grosse-Oetringhaus
class PairCuts
{
public:
enum Particle { Photon = 0,
K0,
Lambda,
Phi,
Rho,
ParticlesLastEntry };
void SetHistogramRegistry(o2::framework::HistogramRegistry* registry) { histogramRegistry = registry; }
void SetPairCut(Particle particle, float cut)
{
LOGF(info, "Enabled pair cut for %d with value %f", static_cast<int>(particle), cut);
mCuts[particle] = cut;
if (histogramRegistry != nullptr && histogramRegistry->contains(HIST("ControlConvResonances")) == false) {
histogramRegistry->add("ControlConvResonances", "", {o2::framework::HistType::kTH2F, {{6, -0.5, 5.5, "id"}, {500, -0.5, 0.5, "delta mass"}}});
}
}
void SetTwoTrackCuts(float distance = 0.02f, float radius = 0.8f)
{
LOGF(info, "Enabled two-track cut with distance %f and radius %f", distance, radius);
mTwoTrackDistance = distance;
mTwoTrackRadius = radius;
if (histogramRegistry != nullptr && histogramRegistry->contains(HIST("TwoTrackDistancePt_0")) == false) {
histogramRegistry->add("TwoTrackDistancePt_0", "", {o2::framework::HistType::kTH3F, {{100, -0.15, 0.15, "#Delta#eta"}, {100, -0.05, 0.05, "#Delta#varphi^{*}_{min}"}, {20, 0, 10, "#Delta p_{T}"}}});
histogramRegistry->addClone("TwoTrackDistancePt_0", "TwoTrackDistancePt_1");
}
}
template <typename T>
bool conversionCuts(T const& track1, T const& track2);
template <typename T>
bool twoTrackCut(T const& track1, T const& track2, int magField);
protected:
float mCuts[ParticlesLastEntry] = {-1};
float mTwoTrackDistance = -1; // distance below which the pair is flagged as to be removed
float mTwoTrackRadius = 0.8f; // radius at which the two track cuts are applied
o2::framework::HistogramRegistry* histogramRegistry = nullptr; // if set, control histograms are stored here
template <typename T>
bool conversionCut(T const& track1, T const& track2, Particle conv, double cut);
template <typename T>
double getInvMassSquared(T const& track1, double m0_1, T const& track2, double m0_2);
template <typename T>
double getInvMassSquaredFast(T const& track1, double m0_1, T const& track2, double m0_2);
template <typename T>
float getDPhiStar(T const& track1, T const& track2, float radius, int magField);
};
template <typename T>
bool PairCuts::conversionCuts(T const& track1, T const& track2)
{
// skip if like sign
if (track1.sign() * track2.sign() > 0) {
return false;
}
for (int i = 0; i < static_cast<int>(ParticlesLastEntry); i++) {
Particle particle = static_cast<Particle>(i);
if (mCuts[i] > 0) {
if (conversionCut(track1, track2, particle, mCuts[i])) {
return true;
}
if (particle == Lambda) {
if (conversionCut(track2, track1, particle, mCuts[i])) {
return true;
}
}
}
}
return false;
}
template <typename T>
bool PairCuts::twoTrackCut(T const& track1, T const& track2, int magField)
{
// the variables & cut have been developed in Run 1 by the CF - HBT group
//
// Parameters:
// magField: B field in kG
auto deta = track1.eta() - track2.eta();
// optimization
if (std::fabs(deta) < mTwoTrackDistance * 2.5 * 3) {
// check first boundaries to see if is worth to loop and find the minimum
float dphistar1 = getDPhiStar(track1, track2, mTwoTrackRadius, magField);
float dphistar2 = getDPhiStar(track1, track2, 2.5, magField);
const float kLimit = mTwoTrackDistance * 3;
if (std::fabs(dphistar1) < kLimit || std::fabs(dphistar2) < kLimit || dphistar1 * dphistar2 < 0) {
float dphistarminabs = 1e5;
float dphistarmin = 1e5;
for (Double_t rad = mTwoTrackRadius; rad < 2.51; rad += 0.01) {
float dphistar = getDPhiStar(track1, track2, rad, magField);
float dphistarabs = std::fabs(dphistar);
if (dphistarabs < dphistarminabs) {
dphistarmin = dphistar;
dphistarminabs = dphistarabs;
}
}
if (histogramRegistry != nullptr) {
histogramRegistry->fill(HIST("TwoTrackDistancePt_0"), deta, dphistarmin, std::fabs(track1.pt() - track2.pt()));
}
if (dphistarminabs < mTwoTrackDistance && std::fabs(deta) < mTwoTrackDistance) {
// LOGF(debug, "Removed track pair %ld %ld with %f %f %f %f %d %f %f %d %d", track1.index(), track2.index(), deta, dphistarminabs, track1.phi2(), track1.pt(), track1.sign(), track2.phi2(), track2.pt(), track2.sign(), magField);
return true;
}
if (histogramRegistry != nullptr) {
histogramRegistry->fill(HIST("TwoTrackDistancePt_1"), deta, dphistarmin, std::fabs(track1.pt() - track2.pt()));
}
}
}
return false;
}
template <typename T>
bool PairCuts::conversionCut(T const& track1, T const& track2, Particle conv, double cut)
{
// LOGF(info, "pt is %f %f", track1.pt(), track2.pt());
if (cut < 0) {
return false;
}
double massD1, massD2, massM;
switch (conv) {
case Photon:
massD1 = 0.51e-3;
massD2 = 0.51e-3;
massM = 0;
break;
case K0:
massD1 = 0.1396;
massD2 = 0.1396;
massM = 0.4976;
break;
case Lambda:
massD1 = 0.9383;
massD2 = 0.1396;
massM = 1.115;
break;
case Phi:
massD1 = 0.4937;
massD2 = 0.4937;
massM = 1.019;
break;
case Rho:
massD1 = 0.1396;
massD2 = 0.1396;
massM = 0.770;
break;
default:
LOGF(fatal, "Particle now known");
return false;
break;
}
auto massC = getInvMassSquaredFast(track1, massD1, track2, massD2);
if (std::fabs(massC - massM * massM) > cut * 5) {
return false;
}
massC = getInvMassSquared(track1, massD1, track2, massD2);
if (histogramRegistry != nullptr) {
histogramRegistry->fill(HIST("ControlConvResonances"), static_cast<int>(conv), massC - massM * massM);
}
if (massC > (massM - cut) * (massM - cut) && massC < (massM + cut) * (massM + cut)) {
return true;
}
return false;
}
template <typename T>
double PairCuts::getInvMassSquared(T const& track1, double m0_1, T const& track2, double m0_2)
{
// calculate inv mass squared
// same can be achieved, but with more computing time with
/*TLorentzVector photon, p1, p2;
p1.SetPtEtaPhiM(triggerParticle->Pt(), triggerEta, triggerParticle->Phi(), 0.510e-3);
p2.SetPtEtaPhiM(particle->Pt(), eta[j], particle->Phi(), 0.510e-3);
photon = p1+p2;
photon.M()*/
float tantheta1 = 1e10;
if (track1.eta() < -1e-10 || track1.eta() > 1e-10) {
float expTmp = std::exp(-track1.eta());
tantheta1 = 2.0 * expTmp / (1.0 - expTmp * expTmp);
}
float tantheta2 = 1e10;
if (track2.eta() < -1e-10 || track2.eta() > 1e-10) {
float expTmp = std::exp(-track2.eta());
tantheta2 = 2.0 * expTmp / (1.0 - expTmp * expTmp);
}
float e1squ = m0_1 * m0_1 + track1.pt() * track1.pt() * (1.0 + 1.0 / tantheta1 / tantheta1);
float e2squ = m0_2 * m0_2 + track2.pt() * track2.pt() * (1.0 + 1.0 / tantheta2 / tantheta2);
float mass2 = m0_1 * m0_1 + m0_2 * m0_2 + 2 * (std::sqrt(e1squ * e2squ) - (track1.pt() * track2.pt() * (std::cos(track1.phi() - track2.phi()) + 1.0 / tantheta1 / tantheta2)));
// LOGF(debug, "%f %f %f %f %f %f %f %f %f", pt1, eta1, phi1, pt2, eta2, phi2, m0_1, m0_2, mass2);
return mass2;
}
template <typename T>
double PairCuts::getInvMassSquaredFast(T const& track1, double m0_1, T const& track2, double m0_2)
{
// calculate inv mass squared approximately
const float eta1 = track1.eta();
const float eta2 = track2.eta();
const float phi1 = track1.phi();
const float phi2 = track2.phi();
const float pt1 = track1.pt();
const float pt2 = track2.pt();
float tantheta1 = 1e10f;
if (eta1 < -1e-10f || eta1 > 1e-10f) {
float expTmp = 1.0f - eta1 + eta1 * eta1 / 2.0f - eta1 * eta1 * eta1 / 6.0f + eta1 * eta1 * eta1 * eta1 / 24.0f;
tantheta1 = 2.0f * expTmp / (1.0f - expTmp * expTmp);
}
float tantheta2 = 1e10f;
if (eta2 < -1e-10f || eta2 > 1e-10f) {
float expTmp = 1.0f - eta2 + eta2 * eta2 / 2.0f - eta2 * eta2 * eta2 / 6.0f + eta2 * eta2 * eta2 * eta2 / 24.0f;
tantheta2 = 2.0f * expTmp / (1.0f - expTmp * expTmp);
}
float e1squ = m0_1 * m0_1 + pt1 * pt1 * (1.0f + 1.0f / tantheta1 / tantheta1);
float e2squ = m0_2 * m0_2 + pt2 * pt2 * (1.0f + 1.0f / tantheta2 / tantheta2);
// fold onto 0...pi
float deltaPhi = std::fabs(phi1 - phi2);
while (deltaPhi > o2::constants::math::TwoPI) {
deltaPhi -= o2::constants::math::TwoPI;
}
if (deltaPhi > o2::constants::math::PI) {
deltaPhi = o2::constants::math::TwoPI - deltaPhi;
}
float cosDeltaPhi = 0;
if (deltaPhi < o2::constants::math::PI / 3.0f) {
cosDeltaPhi = 1.0 - deltaPhi * deltaPhi / 2 + deltaPhi * deltaPhi * deltaPhi * deltaPhi / 24;
} else if (deltaPhi < 2.0f * o2::constants::math::PI / 3.0f) {
cosDeltaPhi = -(deltaPhi - o2::constants::math::PI / 2) + 1.0 / 6 * std::pow((deltaPhi - o2::constants::math::PI / 2), 3);
} else {
cosDeltaPhi = -1.0f + 1.0f / 2.0f * (deltaPhi - o2::constants::math::PI) * (deltaPhi - o2::constants::math::PI) - 1.0f / 24.0f * std::pow(deltaPhi - o2::constants::math::PI, 4.0f);
}
double mass2 = m0_1 * m0_1 + m0_2 * m0_2 + 2.0f * (std::sqrt(e1squ * e2squ) - (pt1 * pt2 * (cosDeltaPhi + 1.0f / tantheta1 / tantheta2)));
// LOGF(debug, "%f %f %f %f %f %f %f %f %f", pt1, eta1, phi1, pt2, eta2, phi2, m0_1, m0_2, mass2);
return mass2;
}
template <typename T>
float PairCuts::getDPhiStar(T const& track1, T const& track2, float radius, int magField)
{
//
// calculates dphistar
//
auto phi1 = track1.phi();
auto pt1 = track1.pt();
auto charge1 = track1.sign();
auto phi2 = track2.phi();
auto pt2 = track2.pt();
auto charge2 = track2.sign();
float dphistar = phi1 - phi2 - charge1 * std::asin(0.015 * magField * radius / pt1) + charge2 * std::asin(0.015 * magField * radius / pt2);
if (dphistar > o2::constants::math::PI) {
dphistar = o2::constants::math::TwoPI - dphistar;
}
if (dphistar < -o2::constants::math::PI) {
dphistar = -o2::constants::math::TwoPI - dphistar;
}
if (dphistar > o2::constants::math::PI) { // might look funny but is needed
dphistar = o2::constants::math::TwoPI - dphistar;
}
return dphistar;
}
#endif // PWGCF_CORE_PAIRCUTS_H_