82 auto start_time = std::chrono::high_resolution_clock::now();
83 constexpr float PS2MUS = 1e-6;
85 auto flagUsed2 = [&usedData](
int idx,
int src) {
87 usedData[
src][idx] = 1;
90 auto flagUsed = [&usedData, &flagUsed2](
const GTrackID gidx) { flagUsed2(gidx.getIndex(), gidx.getSource()); };
91 auto isUsed2 = [&usedData](
int idx,
int src) {
return (!usedData[
src].
empty()) && (usedData[
src][idx] != 0); };
92 auto isUsed = [&usedData, isUsed2](
const GTrackID gidx) {
return isUsed2(gidx.getIndex(), gidx.getSource()); };
106 const auto tracksTPCTRD = getTPCTRDTracks<o2::trd::TrackTRD>();
111 const auto tracksITSTPCTRD = getITSTPCTRDTracks<o2::trd::TrackTRD>();
129 static int BCDiffErrCount = 0;
130 constexpr int MAXBCDiffErrCount = 5;
144 if (srcSel[currentSource]) {
145 if (matchesITSTPCTRDTOF.size() && (!tofClusters.size() || !tracksITSTPCTRD.size())) {
146 throw std::runtime_error(fmt::format(
"Global-TOF tracks ({}) require ITS-TPC-TRD tracks ({}) and TOF clusters ({})",
147 matchesITSTPCTRDTOF.size(), tracksITSTPCTRD.size(), tofClusters.size()));
149 for (
unsigned i = 0;
i < matchesITSTPCTRDTOF.size();
i++) {
150 const auto&
match = matchesITSTPCTRDTOF[
i];
151 auto gidx =
match.getTrackRef();
155 const float timeErr = 0.010f;
156 if (creator(tracksITSTPCTRD[gidx.getIndex()], {i, currentSource}, timeTOFMUS, timeErr)) {
166 if (srcSel[currentSource]) {
167 if (matchesTPCTRDTOF.size() && (!tofClusters.size() || !tracksTPCTRD.size())) {
168 throw std::runtime_error(fmt::format(
"Global-TOF tracks ({}) require TPC-TRD tracks ({}) and TOF clusters ({})",
169 matchesTPCTRDTOF.size(), tracksTPCTRD.size(), tofClusters.size()));
171 for (
unsigned i = 0;
i < matchesTPCTRDTOF.size();
i++) {
172 const auto&
match = matchesTPCTRDTOF[
i];
173 auto gidx =
match.getTrackRef();
176 const float timeErr = 0.010f;
177 if (creator(tracksTPCTRD[gidx.getIndex()], {i, currentSource}, timeTOFMUS, timeErr)) {
187 if (srcSel[currentSource]) {
189 for (
unsigned itr = 0; itr < trigITSTPCTRD.size(); itr++) {
190 const auto& trig = trigITSTPCTRD[itr];
191 auto bcdiff = getBCDiff(trig.getBCData());
193 for (
unsigned int i = trig.getTrackRefs().getFirstEntry();
i < (
unsigned int)trig.getTrackRefs().getEntriesBound();
i++) {
194 const auto& trc = tracksITSTPCTRD[
i];
195 if (isUsed2(
i, currentSource)) {
196 flagUsed(trc.getRefGlobalTrackId());
200 if (trc.hasPileUpInfo()) {
201 t0Err += trc.getPileUpTimeErrorMUS();
203 if (creator(trc, {
i, currentSource}, t0Trig, t0Err)) {
204 flagUsed(trc.getRefGlobalTrackId());
214 if (srcSel[currentSource]) {
215 if (matchesITSTPCTOF.size() && (!tofClusters.size() || !tracksTPCITS.size())) {
216 throw std::runtime_error(fmt::format(
"Global-TOF tracks ({}) require ITS-TPC tracks ({}) and TOF clusters ({})",
217 matchesITSTPCTOF.size(), tracksTPCITS.size(), tofClusters.size()));
219 for (
unsigned i = 0;
i < matchesITSTPCTOF.size();
i++) {
220 const auto&
match = matchesITSTPCTOF[
i];
221 auto gidx =
match.getTrackRef();
228 const float timeErr = 0.010f;
229 if (creator(tracksTPCITS[gidx.getIndex()], {i, currentSource}, timeTOFMUS, timeErr)) {
239 if (srcSel[currentSource]) {
241 for (
unsigned itr = 0; itr < trigTPCTRD.size(); itr++) {
242 const auto& trig = trigTPCTRD[itr];
243 auto bcdiff = getBCDiff(trig.getBCData());
245 for (
unsigned int i = trig.getTrackRefs().getFirstEntry();
i < (
unsigned int)trig.getTrackRefs().getEntriesBound();
i++) {
246 const auto& trc = tracksTPCTRD[
i];
247 if (isUsed2(
i, currentSource)) {
248 flagUsed(trc.getRefGlobalTrackId());
252 if (trc.hasPileUpInfo()) {
253 t0Err += trc.getPileUpTimeErrorMUS();
255 if (creator(trc, {
i, currentSource}, t0Trig, t0Err)) {
256 flagUsed(trc.getRefGlobalTrackId());
266 if (srcSel[currentSource]) {
267 for (
unsigned i = 0;
i < tracksTPCITS.size();
i++) {
268 const auto& matchTr = tracksTPCITS[
i];
269 if (isUsed2(
i, currentSource)) {
270 flagUsed(matchTr.getRefITS());
271 flagUsed(matchTr.getRefTPC());
274 if (creator(matchTr, {
i, currentSource}, matchTr.getTimeMUS().getTimeStamp(), matchTr.getTimeMUS().getTimeStampError())) {
275 flagUsed(matchTr.getRefITS());
276 flagUsed(matchTr.getRefTPC());
285 if (srcSel[currentSource]) {
286 if (matchesTPCTOF.size() && !tracksTPCTOF.size()) {
287 throw std::runtime_error(fmt::format(
"TPC-TOF matched tracks ({}) require TPCTOF matches ({}) and TPCTOF tracks ({})",
288 -1, matchesTPCTOF.size(), tracksTPCTOF.size()));
290 for (
unsigned i = 0;
i < matchesTPCTOF.size();
i++) {
291 const auto&
match = matchesTPCTOF[
i];
292 const auto& gidx =
match.getTrackRef();
296 const auto& trc = tracksTPCTOF[
i];
297 if (creator(trc, {
i, currentSource}, trc.getTimeMUS().getTimeStamp(), trc.getTimeMUS().getTimeStampError())) {
307 if (srcSel[currentSource]) {
308 for (
unsigned i = 0;
i < tracksMFTMCH.size();
i++) {
309 const auto& matchTr = tracksMFTMCH[
i];
310 if (creator(matchTr, {
i, currentSource}, matchTr.getTimeMUS().getTimeStamp(), matchTr.getTimeMUS().getTimeStampError())) {
321 if (srcSel[currentSource]) {
322 if (matchesMCHMID.size() && !tracksMCH.size()) {
323 throw std::runtime_error(fmt::format(
"MCH-MID matched tracks ({}) require MCHMID matches ({}) and MCH tracks ({})",
324 -1, matchesMCHMID.size(), tracksMCH.size()));
326 for (
unsigned i = 0;
i < matchesMCHMID.size();
i++) {
327 const auto&
match = matchesMCHMID[
i];
328 auto [trcTime, isInTF] =
match.getTimeMUS(
startIR, 256, BCDiffErrCount < MAXBCDiffErrCount);
329 if (!isInTF && BCDiffErrCount < MAXBCDiffErrCount) {
332 auto gidxMCH =
match.getMCHRef();
333 const auto& trc = tracksMCH[gidxMCH.getIndex()];
334 if (creator(trc, {
i, currentSource}, trcTime.getTimeStamp(), trcTime.getTimeStampError())) {
336 flagUsed(
match.getMIDRef());
345 if (srcSel[currentSource]) {
347 for (
unsigned irof = 0; irof < rofrs.size(); irof++) {
348 const auto& rofRec = rofrs[irof];
349 auto bcdiff = getBCDiff(rofRec.getBCData());
351 int trlim = rofRec.getFirstEntry() + rofRec.getNEntries();
352 for (
int it = rofRec.getFirstEntry(); it < trlim; it++) {
353 if (isUsed2(it, currentSource)) {
357 const auto& trc = tracksITS[it];
358 creator(trc, gidITS,
t0, 0.5);
367 if (srcSel[currentSource]) {
369 for (
unsigned irof = 0; irof < rofrs.size(); irof++) {
370 const auto& rofRec = rofrs[irof];
371 auto bcdiff = getBCDiff(rofRec.getBCData());
373 int trlim = rofRec.getFirstEntry() + rofRec.getNEntries();
374 for (
int it = rofRec.getFirstEntry(); it < trlim; it++) {
375 if (isUsed2(it, currentSource)) {
379 const auto& trc = tracksMFT[it];
380 creator(trc, gidMFT,
t0, 0.5);
389 if (srcSel[currentSource]) {
391 for (
const auto& rof : rofs) {
392 if (rof.getNEntries() == 0) {
395 auto [trcTime, isInTF] = rof.getTimeMUS(
startIR, 256, BCDiffErrCount < MAXBCDiffErrCount);
396 if (!isInTF && BCDiffErrCount < MAXBCDiffErrCount) {
399 for (
int idx = rof.getFirstIdx(); idx <= rof.getLastIdx(); ++idx) {
400 if (isUsed2(idx, currentSource)) {
403 GTrackID gidMCH(idx, currentSource);
404 const auto& trc = tracksMCH[idx];
405 creator(trc, gidMCH, trcTime.getTimeStamp(), trcTime.getTimeStampError());
414 if (srcSel[currentSource]) {
416 for (
const auto& rof : rofs) {
417 if (rof.nEntries == 0) {
420 auto [trcTime, isInTF] = rof.getTimeMUS(
startIR, 256, BCDiffErrCount < MAXBCDiffErrCount);
421 if (!isInTF && BCDiffErrCount < MAXBCDiffErrCount) {
424 if (trcTime.getTimeStamp() < 0.f) {
425 if (BCDiffErrCount - 1 < MAXBCDiffErrCount) {
426 LOGP(alarm,
"Skipping MID ROF with {} entries since it precedes TF start", rof.nEntries);
430 for (
int idx = rof.firstEntry; idx < rof.getEndIndex(); ++idx) {
431 if (isUsed2(idx, currentSource)) {
434 GTrackID gidMID(idx, currentSource);
435 const auto& trc = tracksMID[idx];
436 creator(trc, gidMID, trcTime.getTimeStamp(), trcTime.getTimeStampError());
445 if (srcSel[currentSource]) {
446 int nacc = 0, noffer = 0;
447 for (
unsigned i = 0;
i < tracksTPC.size();
i++) {
448 if (isUsed2(
i, currentSource)) {
451 const auto& trc = tracksTPC[
i];
452 creator(trc, {
i, currentSource}, trc.getTime0() + 0.5 * (trc.getDeltaTFwd() - trc.getDeltaTBwd()), 0.5 * (trc.getDeltaTFwd() + trc.getDeltaTBwd()));
457 auto current_time = std::chrono::high_resolution_clock::now();
458 LOG(info) <<
"RecoContainer::createTracks took " << std::chrono::duration_cast<std::chrono::microseconds>(current_time - start_time).count() * 1e-6 <<
" CPU s.";