|
11 | 11 |
|
12 | 12 | #include <algorithm> |
13 | 13 | #include <array> |
| 14 | +#include <cstdint> |
14 | 15 | #include <format> |
15 | 16 | #include <map> |
16 | 17 | #include <memory> |
|
40 | 41 | #include "Framework/DataRefUtils.h" |
41 | 42 | #include "Framework/DeviceSpec.h" |
42 | 43 | #include "SimulationDataFormat/DigitizationContext.h" |
43 | | -#include "SimulationDataFormat/O2DatabasePDG.h" |
44 | | -#include "Steer/MCKinematicsReader.h" |
45 | 44 |
|
46 | 45 | using namespace o2::framework; |
47 | 46 | using namespace o2::its; |
@@ -245,6 +244,7 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc) |
245 | 244 | if (mIsMC) { |
246 | 245 | constexpr size_t NMultiplicityBins{8}; |
247 | 246 | constexpr auto multiplicityBinsLabel = "2,3,4-7,8-15,16-31,32-63,64-127,128+"; |
| 247 | + constexpr uint8_t firstThreeLayersMask = 0x7; |
248 | 248 | auto composeTruthLabel = [](const int eventId, const int sourceId) { |
249 | 249 | return o2::MCCompLabel{o2::MCCompLabel::maxTrackID(), eventId, sourceId, false}; |
250 | 250 | }; |
@@ -319,47 +319,98 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc) |
319 | 319 | std::map<o2::MCCompLabel, bool> uniqueTrueLabelsAll; |
320 | 320 | std::map<o2::MCCompLabel, bool> uniqueTrueLabelsFindable; |
321 | 321 | std::map<o2::MCCompLabel, int> truthMultiplicity; |
| 322 | + std::map<o2::MCCompLabel, bool> eligibleTruthEvents; |
| 323 | + std::map<o2::MCCompLabel, uint8_t> contributorLayerMask; |
| 324 | + std::map<o2::MCCompLabel, std::map<o2::MCCompLabel, bool>> lineContributors; |
322 | 325 | std::array<int, NMultiplicityBins> findableTruthBins{}; |
323 | 326 | std::array<int, NMultiplicityBins> uniqueTrueFoundBins{}; |
| 327 | + std::array<int, NMultiplicityBins> lineTruthFoundBins{}; |
324 | 328 | std::array<int, NMultiplicityBins> recoTotalBins{}; |
325 | 329 | std::array<int, NMultiplicityBins> recoTrueBins{}; |
326 | 330 | int nTrueVrt{0}; |
| 331 | + int nLineTrue{0}, nLineFake{0}, nLineTotal{0}, nLineFindable{0}, nLineUniqueTruth{0}; |
327 | 332 |
|
328 | 333 | const auto dc = o2::steer::DigitizationContext::loadFromFile("collisioncontext.root"); |
329 | 334 | const auto irs = dc->getEventRecords(); |
330 | 335 | const int64_t roFrameBiasInBC = o2::itsmft::DPLAlpideParam<o2::detectors::DetID::ITS>::Instance().getROFBiasInBC(1); |
331 | 336 | const auto firstSampledTFIR = o2::raw::HBFUtils::Instance().getFirstSampledTFIR(); |
332 | | - o2::steer::MCKinematicsReader mcReader(dc); |
333 | 337 | const int iSrc = 0; // take only events from collision generator |
334 | 338 | const auto eveId2colId = dc->getCollisionIndicesForSource(iSrc); |
335 | | - for (int iEve{0}; iEve < mcReader.getNEvents(iSrc); ++iEve) { |
336 | | - const auto colId = eveId2colId.find(iEve); |
337 | | - if (colId == eveId2colId.end()) { |
338 | | - mcReader.releaseTracksForSourceAndEvent(iSrc, iEve); |
339 | | - continue; |
340 | | - } |
341 | | - const auto& ir = irs[colId->second]; |
| 339 | + for (const auto& [iEve, iCol] : eveId2colId) { |
| 340 | + const auto& ir = irs[iCol]; |
342 | 341 | if (!ir.isDummy()) { |
343 | 342 | const auto bc = (ir - firstSampledTFIR).toLong() - roFrameBiasInBC; |
344 | 343 | if (bc >= 0 && upcPassRanForBC(bc)) { |
345 | | - const int nCont = std::ranges::count_if(mcReader.getTracks(iSrc, iEve), [](const auto& trk) { |
346 | | - if (!trk.isPrimary()) { |
347 | | - return false; |
348 | | - } |
349 | | - const auto* p = o2::O2DatabasePDG::Instance()->GetParticle(trk.GetPdgCode()); |
350 | | - return p && p->Charge() != 0; |
351 | | - }); |
352 | | - if (nCont > 1) { |
353 | | - const auto label = composeTruthLabel(iEve, iSrc); |
354 | | - truthMultiplicity[label] = nCont; |
355 | | - ++nTrueVrt; |
356 | | - if (const auto truthBin = getMultiplicityBin(nCont); truthBin >= 0) { |
357 | | - ++findableTruthBins[truthBin]; |
358 | | - } |
| 344 | + eligibleTruthEvents[composeTruthLabel(iEve, iSrc)] = true; |
| 345 | + } |
| 346 | + } |
| 347 | + } |
| 348 | + |
| 349 | + for (int layer = 0; layer < 3; ++layer) { |
| 350 | + for (const auto& cluster : mTimeFrame->getClusters()[layer]) { |
| 351 | + for (const auto& label : mTimeFrame->getClusterLabels(layer, cluster.clusterId)) { |
| 352 | + if (!label.isValid() || label.isFake()) { |
| 353 | + continue; |
| 354 | + } |
| 355 | + const auto eventLabel = composeTruthLabel(label.getEventID(), label.getSourceID()); |
| 356 | + if (!eligibleTruthEvents.contains(eventLabel)) { |
| 357 | + continue; |
359 | 358 | } |
| 359 | + contributorLayerMask[label] |= (1 << layer); |
| 360 | + } |
| 361 | + } |
| 362 | + } |
| 363 | + |
| 364 | + for (const auto& [label, layerMask] : contributorLayerMask) { |
| 365 | + if ((layerMask & firstThreeLayersMask) != firstThreeLayersMask) { |
| 366 | + continue; |
| 367 | + } |
| 368 | + ++truthMultiplicity[composeTruthLabel(label.getEventID(), label.getSourceID())]; |
| 369 | + } |
| 370 | + |
| 371 | + for (const auto& [label, nCont] : truthMultiplicity) { |
| 372 | + if (nCont > 1) { |
| 373 | + ++nTrueVrt; |
| 374 | + if (const auto truthBin = getMultiplicityBin(nCont); truthBin >= 0) { |
| 375 | + ++findableTruthBins[truthBin]; |
| 376 | + } |
| 377 | + } |
| 378 | + } |
| 379 | + |
| 380 | + for (int rofId = 0; rofId < mTimeFrame->getNrof(1); ++rofId) { |
| 381 | + for (const auto& label : mTimeFrame->getLinesLabel(rofId)) { |
| 382 | + ++nLineTotal; |
| 383 | + if (!label.isValid() || label.isFake()) { |
| 384 | + ++nLineFake; |
| 385 | + continue; |
| 386 | + } |
| 387 | + const auto eventLabel = composeTruthLabel(label.getEventID(), label.getSourceID()); |
| 388 | + if (!eligibleTruthEvents.contains(eventLabel)) { |
| 389 | + ++nLineFake; |
| 390 | + continue; |
| 391 | + } |
| 392 | + if (const auto found = contributorLayerMask.find(label); found != contributorLayerMask.end() && (found->second & firstThreeLayersMask) == firstThreeLayersMask) { |
| 393 | + ++nLineTrue; |
| 394 | + lineContributors[eventLabel][label] = true; |
| 395 | + } else { |
| 396 | + ++nLineFake; |
| 397 | + } |
| 398 | + } |
| 399 | + } |
| 400 | + |
| 401 | + for (const auto& [label, nCont] : truthMultiplicity) { |
| 402 | + if (nCont <= 1) { |
| 403 | + continue; |
| 404 | + } |
| 405 | + ++nLineFindable; |
| 406 | + const auto found = lineContributors.find(label); |
| 407 | + const auto nFoundContributors = found == lineContributors.end() ? 0 : static_cast<int>(found->second.size()); |
| 408 | + if (nFoundContributors > 1) { |
| 409 | + ++nLineUniqueTruth; |
| 410 | + if (const auto truthBin = getMultiplicityBin(nCont); truthBin >= 0) { |
| 411 | + ++lineTruthFoundBins[truthBin]; |
360 | 412 | } |
361 | 413 | } |
362 | | - mcReader.releaseTracksForSourceAndEvent(iSrc, iEve); |
363 | 414 | } |
364 | 415 |
|
365 | 416 | int nRecoVertices{0}, nFoundVrt{0}, nFakeVrt{0}, nUniqueTrueVertAll{0}, nUniqueTrueVertFindable{0}; |
@@ -394,10 +445,15 @@ void ITSTrackingInterface::run(framework::ProcessingContext& pc) |
394 | 445 | } |
395 | 446 |
|
396 | 447 | const auto efficiency = nTrueVrt > 0 ? static_cast<float>(nUniqueTrueVertFindable) / static_cast<float>(nTrueVrt) : 0.f; |
| 448 | + const auto lineEfficiency = nLineFindable > 0 ? static_cast<float>(nLineUniqueTruth) / static_cast<float>(nLineFindable) : 0.f; |
397 | 449 | const auto purity = nRecoVertices > 0 ? static_cast<float>(nFoundVrt) / static_cast<float>(nRecoVertices) : 0.f; |
398 | 450 | const auto fakeRate = nRecoVertices > 0 ? static_cast<float>(nFakeVrt) / static_cast<float>(nRecoVertices) : 0.f; |
399 | 451 | const auto duplicateRate = nFoundVrt > 0 ? static_cast<float>(nFoundVrt - nUniqueTrueVertAll) / static_cast<float>(nFoundVrt) : 0.f; |
400 | 452 | const auto f1 = (purity + efficiency) > 0.f ? 2.f * purity * efficiency / (purity + efficiency) : 0.f; |
| 453 | + LOGP(info, "ITS vertexer {} line validation: findable={} true_lines={} fake_lines={} total_lines={} unique_truth_ge2_lines={} eff={:.6f}", |
| 454 | + tuneUPC ? "UPC" : "all", nLineFindable, nLineTrue, nLineFake, nLineTotal, nLineUniqueTruth, lineEfficiency); |
| 455 | + LOGP(info, "ITS vertexer {} line multiplicity bins [{}]: truth_findable={} truth_ge2_lines={}", |
| 456 | + tuneUPC ? "UPC" : "all", multiplicityBinsLabel, formatCounts(findableTruthBins), formatCounts(lineTruthFoundBins)); |
401 | 457 | LOGP(info, "ITS vertexer {} validation: findable={} true_found={} unique_true_findable={} unique_true_all={} total_found={} eff={:.6f} purity={:.6f} fake_rate={:.6f} duplicate_rate={:.6f} f1={:.6f}", |
402 | 458 | tuneUPC ? "UPC" : "all", nTrueVrt, nFoundVrt, nUniqueTrueVertFindable, nUniqueTrueVertAll, nRecoVertices, efficiency, purity, fakeRate, duplicateRate, f1); |
403 | 459 | LOGP(info, "ITS vertexer {} multiplicity bins [{}]: truth_findable={} truth_found={} reco_total={} reco_true={}", |
|
0 commit comments