Project
Loading...
Searching...
No Matches
EventTimeMaker.h
Go to the documentation of this file.
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
17
18#ifndef ALICEO2_TOF_EVENTTIMEMAKER_H
19#define ALICEO2_TOF_EVENTTIMEMAKER_H
20
21#include "TRandom.h"
22#include "TMath.h"
24#include "Framework/Logger.h"
27
28namespace o2
29{
30
31namespace tof
32{
33struct EventTimeTOFParams : public o2::conf::ConfigurableParamHelper<EventTimeTOFParams> {
34 float maxNsigma = 3.0;
37};
38
40 eventTimeContainer(const float& e, const float& err, const float& diamond) : mEventTime{e}, mEventTimeError{err}, mDiamondSpread{diamond} {};
41 static int getMaxNtracksInSet() { return TMath::Min(maxNtracksInSet <= 0 ? EventTimeTOFParams::Instance().maxNtracksInSet : maxNtracksInSet, 19); }
42 static void setMaxNtracksInSet(int v = -1) { maxNtracksInSet = v; }
43
44 // Values
45 double mEventTime = 0.f;
46 double mEventTimeError = 0.f;
47 unsigned short mEventTimeMultiplicity = 0;
48
49 double mSumOfWeights = 0.f;
50 std::vector<float> mWeights;
51 std::vector<double> mTrackTimes;
52 float mDiamondSpread = 6.f;
53
54 // Aliases
55 const double& eventTime = mEventTime;
58 const double& sumweights = mSumOfWeights;
59 const std::vector<float>& weights = mWeights;
60 const std::vector<double>& tracktime = mTrackTimes;
61
62 void reset()
63 {
64 // reset info
65 mSumOfWeights = 0.;
66 mWeights.clear();
67 mTrackTimes.clear();
68 mEventTime = 0.;
69 mEventTimeError = mDiamondSpread * 33.356409f; // move from diamond spread (cm) to spread on event time (ps)
71 }
72
73 template <typename trackType,
74 bool (*trackFilter)(const trackType&)>
75 void removeBias(const trackType& track,
76 int& nTrackIndex /* index of the track to remove the bias */,
77 float& eventTimeValue,
78 float& eventTimeError,
79 const unsigned short& minimumMultiplicity = 2) const
80 {
81 double evTime = eventTimeValue;
82 double evTimeRes = eventTimeError;
83 removeBias<trackType, trackFilter>(track, nTrackIndex, evTime, evTimeRes);
84 eventTimeValue = evTime;
85 eventTimeError = evTimeRes;
86 }
87
88 template <typename trackType,
89 bool (*trackFilter)(const trackType&)>
90 void removeBias(const trackType& track,
91 int& nTrackIndex /* index of the track to remove the bias */,
92 double& eventTimeValue,
93 double& eventTimeError,
94 const unsigned short& minimumMultiplicity = 2) const
95 {
96 eventTimeValue = mEventTime;
98 if (!trackFilter(track)) { // Check if the track was usable for the event time
99 nTrackIndex++;
100 return;
101 }
102 if (mEventTimeMultiplicity <= minimumMultiplicity && mWeights[nTrackIndex] > 1E-6f) { // Check if a track was used for the event time and if the multiplicity is low
103 eventTimeValue = 0.f;
104 eventTimeError = mDiamondSpread * 33.356409f; // move from diamond (cm) to spread on event time (ps)
105 LOG(debug) << mEventTimeMultiplicity << " <= " << minimumMultiplicity << " and " << mWeights[nTrackIndex] << ": track was used, setting " << eventTimeValue << " " << eventTimeError;
106 nTrackIndex++;
107 return;
108 }
109 // Remove the bias
110 double sumw = 1.f / eventTimeError / eventTimeError;
111 LOG(debug) << "sumw " << sumw;
112 eventTimeValue *= sumw;
113 eventTimeValue -= mWeights[nTrackIndex] * mTrackTimes[nTrackIndex];
114 sumw -= mWeights[nTrackIndex];
115 eventTimeValue /= sumw;
116 eventTimeError = sqrt(1.f / sumw);
117 nTrackIndex++;
118 }
119 static void printConfig()
120 {
121 LOG(info) << "eventTimeContainer configuration:";
122 LOG(info) << " maxNtracksInSet = " << maxNtracksInSet;
123 }
124
125 void print()
126 {
127 LOG(info) << "eventTimeContainer " << mEventTime << " +- " << mEventTimeError << " sum of weights " << mSumOfWeights << " tracks used " << mEventTimeMultiplicity;
128 }
129
130 private:
131 // Configuration
132 static int maxNtracksInSet;
133};
134
136 eventTimeTrack() = default;
137 eventTimeTrack(double tof, float expt[3], float expsigma[3]) : mSignal(tof)
138 {
139 for (int i = 0; i < 3; i++) {
140 expTimes[i] = expt[i];
141 expSigma[i] = expsigma[i];
142 }
143 }
144 double tofSignal() const { return mSignal; }
145 float tofExpSignalPi() const { return expTimes[0]; }
146 float tofExpSignalKa() const { return expTimes[1]; }
147 float tofExpSignalPr() const { return expTimes[2]; }
148 float tofExpSigmaPi() const { return expSigma[0]; }
149 float tofExpSigmaKa() const { return expSigma[1]; }
150 float tofExpSigmaPr() const { return expSigma[2]; }
151 double mSignal = 0.f;
152 float expTimes[3] = {0.f, 0.f, 0.f};
153 float expSigma[3] = {999.f, 999.f, 999.f};
154};
155
157 float tofChi2() const { return mTOFChi2; }
158 float pt() const { return mPt; }
159 float p() const { return mP; }
160 float length() const { return mLength; }
161 int masshypo() const { return mHypo; }
162 float mTOFChi2 = -1.f;
163 float mPt = 0.f;
164 float mP = 0.f;
165 float mLength = 0.f;
166 int mHypo = 0;
167};
168
169void generateEvTimeTracks(std::vector<eventTimeTrackTest>& tracks, int ntracks, float evTime = 0.0);
170
171template <typename trackType>
172bool filterDummy(const trackType& tr)
173{
174 return (tr.tofChi2() >= 0 && tr.p() < 2.0);
175} // accept all
176
177void computeEvTime(const std::vector<eventTimeTrack>& tracks, const std::vector<int>& trkIndex, eventTimeContainer& evtime);
178void computeEvTimeFast(const std::vector<eventTimeTrack>& tracks, const std::vector<int>& trkIndex, eventTimeContainer& evtime);
179int getStartTimeInSet(const std::vector<eventTimeTrack>& tracks, std::vector<int>& trackInSet, unsigned long& bestComb, double refT0 = 0);
180int getStartTimeInSetFast(const std::vector<eventTimeTrack>& tracks, std::vector<int>& trackInSet, unsigned long& bestComb);
181
182template <typename trackTypeContainer,
183 typename trackType,
184 bool (*trackFilter)(const trackType&)>
185eventTimeContainer evTimeMaker(const trackTypeContainer& tracks,
186 const float& diamond = 6.0 /* spread of primary verdex in cm */,
187 bool isFast = false)
188{
189 static std::vector<eventTimeTrack> trkWork;
190 trkWork.clear();
191 static std::vector<int> trkIndex; // indexes of working tracks in the track original array
192 trkIndex.clear();
193
194 static float expt[3], expsigma[3];
195
196 static eventTimeContainer result = {0, 0, diamond};
197
198 // reset info
199 result.reset();
200
201 for (auto track : tracks) { // Loop on tracks
202 if (trackFilter(track)) { // Select tracks good for T0 computation
203 expt[0] = track.tofExpSignalPi();
204 expt[1] = track.tofExpSignalKa();
205 expt[2] = track.tofExpSignalPr();
206 expsigma[0] = track.tofExpSigmaPi();
207 expsigma[1] = track.tofExpSigmaKa();
208 expsigma[2] = track.tofExpSigmaPr();
209 trkWork.emplace_back(track.tofSignal(), expt, expsigma);
210 trkIndex.push_back(result.mWeights.size());
211 }
212 result.mWeights.push_back(0.);
213 result.mTrackTimes.push_back(0.);
214 }
215 if (!isFast) {
216 computeEvTime(trkWork, trkIndex, result);
217 } else {
218 computeEvTimeFast(trkWork, trkIndex, result);
219 }
220 return result;
221}
222
223template <typename trackTypeContainer,
224 typename trackType,
225 bool (*trackFilter)(const trackType&),
226 template <typename T, o2::track::PID::ID> typename response,
227 typename responseParametersType>
228eventTimeContainer evTimeMakerFromParam(const trackTypeContainer& tracks,
229 const responseParametersType& responseParameters,
230 const float& diamond = 6.0 /* spread of primary verdex in cm */,
231 bool isFast = false)
232{
233 static std::vector<eventTimeTrack> trkWork;
234 trkWork.clear();
235 static std::vector<int> trkIndex; // indexes of working tracks in the track original array
236 trkIndex.clear();
237
238 constexpr auto responsePi = response<trackType, o2::track::PID::Pion>();
239 constexpr auto responseKa = response<trackType, o2::track::PID::Kaon>();
240 constexpr auto responsePr = response<trackType, o2::track::PID::Proton>();
241
242 static float expt[3], expsigma[3];
243
244 static eventTimeContainer result = {0, 0, diamond};
245
246 // reset info
247 result.reset();
248
249 for (auto track : tracks) { // Loop on tracks
250 if (trackFilter(track)) { // Select tracks good for T0 computation
251 expt[0] = responsePi.GetCorrectedExpectedSignal(responseParameters, track);
252 expt[1] = responseKa.GetCorrectedExpectedSignal(responseParameters, track);
253 expt[2] = responsePr.GetCorrectedExpectedSignal(responseParameters, track);
254 expsigma[0] = responsePi.GetExpectedSigmaTracking(responseParameters, track);
255 expsigma[1] = responseKa.GetExpectedSigmaTracking(responseParameters, track);
256 expsigma[2] = responsePr.GetExpectedSigmaTracking(responseParameters, track);
257 trkWork.emplace_back(track.tofSignal(), expt, expsigma);
258 trkIndex.push_back(result.mWeights.size());
259 }
260 result.mWeights.push_back(0.);
261 result.mTrackTimes.push_back(0.);
262 }
263 if (!isFast) {
264 computeEvTime(trkWork, trkIndex, result);
265 } else {
266 computeEvTimeFast(trkWork, trkIndex, result);
267 }
268 return result;
269}
270} // namespace tof
271} // namespace o2
272
273#endif /* ALICEO2_TOF_EVENTTIMEMAKER_H */
particle ids, masses, names class definition
int32_t i
std::ostringstream debug
GLsizei const GLuint const GLfloat * weights
Definition glcorearb.h:5475
GLuint64EXT * result
Definition glcorearb.h:5662
const GLdouble * v
Definition glcorearb.h:832
bool filterDummy(const trackType &tr)
int getStartTimeInSet(const std::vector< eventTimeTrack > &tracks, std::vector< int > &trackInSet, unsigned long &bestComb, double refT0=0)
eventTimeContainer evTimeMaker(const trackTypeContainer &tracks, const float &diamond=6.0, bool isFast=false)
void computeEvTimeFast(const std::vector< eventTimeTrack > &tracks, const std::vector< int > &trkIndex, eventTimeContainer &evtime)
eventTimeContainer evTimeMakerFromParam(const trackTypeContainer &tracks, const responseParametersType &responseParameters, const float &diamond=6.0, bool isFast=false)
void computeEvTime(const std::vector< eventTimeTrack > &tracks, const std::vector< int > &trkIndex, eventTimeContainer &evtime)
int getStartTimeInSetFast(const std::vector< eventTimeTrack > &tracks, std::vector< int > &trackInSet, unsigned long &bestComb)
void generateEvTimeTracks(std::vector< eventTimeTrackTest > &tracks, int ntracks, float evTime=0.0)
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
O2ParamDef(EventTimeTOFParams, "EventTimeTOF")
double mSumOfWeights
Track multiplicity used to compute the event time.
std::vector< double > mTrackTimes
weights (1/sigma^2) associated to a track in event time computation, 0 if track not used
float mDiamondSpread
eventtime provided by a single track
double mEventTimeError
Value of the event time.
unsigned short mEventTimeMultiplicity
Uncertainty on the computed event time.
const std::vector< double > & tracktime
eventTimeContainer(const float &e, const float &err, const float &diamond)
const double & eventTime
spread of primary verdex in cm. Used when resetting the container to the default value
std::vector< float > mWeights
sum of weights of all track contributors
void removeBias(const trackType &track, int &nTrackIndex, double &eventTimeValue, double &eventTimeError, const unsigned short &minimumMultiplicity=2) const
void removeBias(const trackType &track, int &nTrackIndex, float &eventTimeValue, float &eventTimeError, const unsigned short &minimumMultiplicity=2) const
const unsigned short & eventTimeMultiplicity
static void setMaxNtracksInSet(int v=-1)
eventTimeTrack(double tof, float expt[3], float expsigma[3])
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"