33int eventTimeContainer::maxNtracksInSet = -1;
35constexpr unsigned long combinatorial[20] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907, 43046721, 129140163, 387420489, 1162261467};
40 static constexpr int maxNumberOfSets = 200;
41 static constexpr float weightLimit = 1E-6;
43 const int ntracks = tracks.size();
44 LOG(
debug) <<
"For the collision time using " << ntracks <<
" tracks";
47 std::map<int, int> bcCand;
48 for (
const auto& trk : tracks) {
55 for (
const auto& [
bc,
count] : bcCand) {
56 if (
count > maxcount) {
67 LOG(
debug) <<
"Skipping event because at least 2 tracks are required";
72 int hypo[maxNtrackInSet];
74 int nmaxtracksinset = ntracks > 22 ? 6 : maxNtrackInSet;
77 LOG(
debug) <<
"nmaxtracksinset " << nmaxtracksinset;
78 int ntracksinset = std::min(ntracks, nmaxtracksinset);
79 LOG(
debug) <<
"ntracksinset " << ntracksinset;
81 int nset = ((ntracks - 1) / ntracksinset) + 1;
83 int ntrackUsable = ntracks;
84 LOG(
debug) <<
"ntrackUsable " << ntrackUsable;
86 if (nset > maxNumberOfSets) {
87 nset = maxNumberOfSets;
88 LOG(
debug) <<
"resetting nset " << nset;
89 ntrackUsable = nmaxtracksinset * nset;
90 LOG(
debug) <<
"resetting ntrackUsable " << ntrackUsable;
94 std::vector<int> trackInSet[maxNumberOfSets];
96 for (
int i = 0;
i < ntrackUsable;
i++) {
99 trackInSet[iset].push_back(
i);
104 for (
int iset = 0; iset < nset; iset++) {
105 LOG(
debug) <<
"iset " << iset <<
" has size " << trackInSet[iset].size();
106 unsigned long bestComb = 0;
107 while (!(status =
getStartTimeInSet(tracks, trackInSet[iset], bestComb, t0fill))) {
111 int ntracks = trackInSet[iset].size();
113 for (
int itrk = 0; itrk < ntracks; itrk++) {
114 hypo[itrk] = bestComb % 3;
117 int index = trkIndex[trackInSet[iset][itrk]];
119 LOG(
debug) <<
"Using hypothesis: " << hypo[itrk] <<
" tofSignal: " << ctrack.
mSignal <<
" exp. time: " << ctrack.
expTimes[hypo[itrk]] <<
" exp. sigma: " << ctrack.
expSigma[hypo[itrk]];
126 LOG(
debug) <<
"iset " << iset <<
" did not have good status";
132 double finalTime = 0, allweights = 0;
136 finalTime = 0, allweights = 0;
148 double averageBest = finalTime / allweights;
156 if (err > errworse) {
168 LOG(
debug) <<
"Removed " << nRemoved <<
" tracks from start time calculation";
170 if (allweights < weightLimit) {
171 LOG(
debug) <<
"Skipping because allweights " << allweights <<
" are lower than " << weightLimit;
182 static constexpr int maxNumberOfSets = 200;
183 static constexpr float weightLimit = 1E-6;
185 const int ntracks = tracks.size();
186 LOG(
debug) <<
"For the collision time using " << ntracks;
189 LOG(
debug) <<
"Skipping event because at least 2 tracks are required";
194 int hypo[maxNtrackInSet];
196 int nmaxtracksinset = ntracks > 22 ? 6 : maxNtrackInSet;
197 int ntracksinset = std::min(ntracks, nmaxtracksinset);
199 int nset = ((ntracks - 1) / ntracksinset) + 1;
200 int ntrackUsable = ntracks;
202 if (nset > maxNumberOfSets) {
203 nset = maxNumberOfSets;
204 ntrackUsable = nmaxtracksinset * nset;
208 std::vector<int> trackInSet[maxNumberOfSets];
210 for (
int i = 0;
i < ntrackUsable;
i++) {
213 trackInSet[iset].push_back(
i);
218 for (
int iset = 0; iset < nset; iset++) {
219 unsigned long bestComb = 0;
224 int ntracks = trackInSet[iset].size();
226 for (
int itrk = 0; itrk < ntracks; itrk++) {
227 hypo[itrk] = bestComb % 3;
230 int index = trkIndex[trackInSet[iset][itrk]];
232 LOG(
debug) <<
"Using hypothesis: " << hypo[itrk] <<
" tofSignal: " << ctrack.
mSignal <<
" exp. time: " << ctrack.
expTimes[hypo[itrk]] <<
" exp. sigma: " << ctrack.
expSigma[hypo[itrk]];
242 double finalTime = 0, allweights = 0;
253 if (allweights < weightLimit) {
254 LOG(
debug) <<
"Skipping because allweights " << allweights <<
" are lower than " << weightLimit;
263int getStartTimeInSet(
const std::vector<eventTimeTrack>& tracks, std::vector<int>& trackInSet,
unsigned long& bestComb,
double refT0)
266 float errworse =
params.maxNsigma;
268 float chi2, chi2best;
269 double averageBest = 0;
270 int hypo[maxNtrackInSet];
271 double starttime[maxNtrackInSet], weighttime[maxNtrackInSet];
274 int ntracks = trackInSet.size();
275 LOG(
debug) <<
"Computing the start time in set with " << ntracks <<
" tracks";
283 for (
unsigned long comb = 0; comb < ncomb; comb++) {
284 unsigned long curr = comb;
288 double sumweights = 0;
290 for (
int itrk = 0; itrk < ntracks; itrk++) {
291 hypo[itrk] = curr % 3;
296 if (std::abs(starttime[itrk] - refT0) < 2000) {
297 weighttime[itrk] = 1. / (ctrack.
expSigma[hypo[itrk]] * ctrack.
expSigma[hypo[itrk]]);
298 average += starttime[itrk] * weighttime[itrk];
299 sumweights += weighttime[itrk];
304 average /= sumweights;
309 for (
int itrk = 0; itrk < ntracks; itrk++) {
310 deltat = starttime[itrk] - average;
311 chi2 += deltat * deltat * weighttime[itrk];
315 if (chi2 < chi2best) {
318 averageBest = average;
324 unsigned long curr = bestComb;
325 for (
int itrk = 0; itrk < ntracks; itrk++) {
326 hypo[itrk] = curr % 3;
330 float err = ctrack.
mSignal - ctrack.
expTimes[hypo[itrk]] - averageBest;
333 if (err > errworse) {
342 trackInSet.erase(trackInSet.begin() + worse);
349int getStartTimeInSetFast(
const std::vector<eventTimeTrack>& tracks, std::vector<int>& trackInSet,
unsigned long& bestComb)
352 float chi2, chi2best;
353 double averageBest = 0;
354 int hypo[maxNtrackInSet];
355 double starttime[maxNtrackInSet], weighttime[maxNtrackInSet];
358 int ntracks = trackInSet.size();
366 unsigned long comb = 0;
370 double sumweights = 0;
373 for (
int itrk = 0; itrk < ntracks; itrk++) {
377 weighttime[itrk] = 1. / (ctrack.
expSigma[hypo[itrk]] * ctrack.
expSigma[hypo[itrk]]);
379 average += starttime[itrk] * weighttime[itrk];
380 sumweights += weighttime[itrk];
384 average /= sumweights;
389 for (
int itrk = 0; itrk < ntracks; itrk++) {
390 deltat = starttime[itrk] - average;
391 chi2 += deltat * deltat * weighttime[itrk];
397 averageBest = average;
403 for (
int itrk = 0; itrk < ntracks; itrk++) {
405 float err = ctrack.
mSignal - ctrack.
expTimes[hypo[itrk]] - averageBest;
408 if (err > errworse) {
417 trackInSet.erase(trackInSet.begin() + worse);
427 constexpr float masses[3] = {0.13957000, 0.49367700, 0.93827200};
428 constexpr float kCSPEED = TMath::C() * 1.0e2f * 1.0e-12f;
430 float betas[3] = {0.f};
432 float pMismatch = ntracks * 0.00005;
434 for (
int i = 0;
i < ntracks;
i++) {
436 track.
mP = gRandom->Exp(1);
437 track.
mPt = track.
mP;
439 track.
mHypo = gRandom->Exp(1);
440 if (track.
mHypo > 2) {
443 for (
int j = 0;
j < 3;
j++) {
444 energy = sqrt(masses[
j] * masses[
j] + track.
mP * track.
mP);
445 betas[
j] = track.
mP / energy;
451 if (gRandom->Rndm() < pMismatch) {
452 float p = gRandom->Exp(1);
454 int hypo = gRandom->Exp(1);
458 energy = sqrt(masses[hypo] * masses[hypo] + p * p);
459 float beta = p / energy;
460 track.
mSignal = l / (beta * kCSPEED) + gRandom->Gaus(0.f, track.
expSigma[
j]);
464 tracks.push_back(track);
#define O2ParamImpl(classname)
Definition of the TOF event time maker.
static const EventTimeTOFParams & Instance()
static constexpr Double_t BC_TIME_INPS
static constexpr Double_t BC_TIME_INPS_INV
GLenum const GLfloat * params
int getStartTimeInSet(const std::vector< eventTimeTrack > &tracks, std::vector< int > &trackInSet, unsigned long &bestComb, double refT0=0)
void computeEvTimeFast(const std::vector< eventTimeTrack > &tracks, const std::vector< int > &trkIndex, eventTimeContainer &evtime)
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)
constexpr unsigned long combinatorial[20]
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< double > mTrackTimes
weights (1/sigma^2) associated to a track in event time computation, 0 if track not used
double mEventTimeError
Value of the event time.
unsigned short mEventTimeMultiplicity
Uncertainty on the computed event time.
std::vector< float > mWeights
sum of weights of all track contributors
static int getMaxNtracksInSet()
LOG(info)<< "Compressed in "<< sw.CpuTime()<< " s"