Skip to content

[PWGEM] [WIP] Check TTCA weight calculation in PWGEM/Dilepton tasks#48

Merged
feisenhu merged 2 commits intomasterfrom
copilot/ttca-gewichtsberechnung-bug-check
Apr 14, 2026
Merged

[PWGEM] [WIP] Check TTCA weight calculation in PWGEM/Dilepton tasks#48
feisenhu merged 2 commits intomasterfrom
copilot/ttca-gewichtsberechnung-bug-check

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 14, 2026

When cfgRequireTrueAssociation = true, tracks/pairs failing the MC collision association check were correctly rejected during histogram filling, but still counted in the TTCA weight denominator — causing weights of 1/N instead of 1/1 and under-filled histograms.

Affected files

  • PWGEM/Dilepton/Core/SingleTrackQCMC.hfillTrackWeightMap(): missing check for both electron and muon loops
  • PWGEM/Dilepton/Core/DileptonMC.hfillPairWeightMap(): missing check for ULS, LS++, and LS-- combination loops
  • PWGEM/Dilepton/Tasks/checkMCPairTemplate.cxxfillPairWeightMap(): same as above

Fix

Added cfgRequireTrueAssociation guard in each weight-building loop to mirror the filter already applied at fill time:

// fillPairWeightMap — now consistent with fillPairInfo
if (cfgRequireTrueAssociation &&
    (mcpos.emmceventId() != collision.emmceventId() ||
     mcneg.emmceventId() != collision.emmceventId())) {
  continue;  // skip pairs that would be rejected at fill time
}

This ensures only tracks/pairs that actually enter histograms are counted in N, keeping weight = 1/N correct under all configurations.

Original prompt

Recherche: TTCA-Gewichtsberechnung-Bug in anderen PWGEM/Dilepton Tasks

Aufgabe

Überprüfe alle Task-Dateien im PWGEM/Dilepton Verzeichnis, ob sie das gleiche TTCA-Gewichtsberechnung-Problem haben wie SingleTrackQCMC.h.

Problem-Muster

Suche nach Dateien, die:

  1. Eine cfgRequireTrueAssociation Configurable verwenden
  2. Eine fillTrackWeightMap() oder ähnliche Gewichtsberechnung-Funktion haben
  3. Den True Association Check in der Gewichtsberechnung nicht durchführen, während er in runQCMC() oder ähnlichen Funktionen durchgeführt wird

Betroffenes Muster

// In fillTrackWeightMap: FEHLT cfgRequireTrueAssociation Check
auto mccollision_from_track = mctrack.template emmcevent_as<TMCCollisions>();
if (cfgEventGeneratorType >= 0 && ...) { continue; }
// ❌ FEHLT: if (cfgRequireTrueAssociation && (...)) { continue; }
passed_trackIds.emplace_back(track.globalIndex());

// In runQCMC: VORHANDEN cfgRequireTrueAssociation Check
if (cfgRequireTrueAssociation && (mctrack.emmceventId() != collision.emmceventId())) {
  continue;  // ✅ Hier ist der Check!
}

Dateien zum Überprüfen

  • PWGEM/Dilepton/Tasks/*.cxx
  • PWGEM/Dilepton/Core/*.h

Fokus auf:

  • SingleTrackQCMC (bereits bekannt) ✓
  • DileptonMC.h
  • Andere QC/Analyse-Tasks mit Gewichtsberechnung

Zu dokumentieren

  1. Welche Dateien haben das gleiche Problem
  2. In welchen Funktionen/Zeilen das Problem auftritt
  3. Ob und wie das Problem behoben werden sollte

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: In dem Task SingleTrackQCMC.h task gibt es die Configurable cfgRequireTrueAssociation.
Wie beeinflusst diese das füllen der Histogramme?
In dem Task kann zusätzlich die TTCAweigths angewendet werden, die den Beitrag gewichten. Erkläre mir wie diese Gewichte berechnet werden, und ob die cfgRequireTrueAssociation das Gewicht beeinflusst.

cfgRequireTrueAssociation sollte nur dann Tracks in die Histogramme füllen, wenn der Track tatsächlich zur Kollision gehört. Das weight sollte dementsprechend angepasst werden, sodass das weight nur dann von 1 verschieden ist, wenn tracks mehrfach aufgrund der Assoziierung von dem selben tracks zu unterschiedlichen Kollisionen stattfindet und dadurch mehrfach in das selbe Histogramm gefüllt wird.

Assistant: Ich werde mir den Task SingleTrackQCMC.h ansehen und die Auswirkungen von cfgRequireTrueAssociation und den TTCAweights analysieren.

Assistant: Lass mich die konkrete SingleTrackQCMC.h Datei in der Dilepton-Struktur finden:

Assistant: Jetzt habe ich den vollständigen SingleTrackQCMC.h Code. Lassen Sie mich eine detaillierte Analyse erstellen:

Analyse: cfgRequireTrueAssociation und TTCAweights in SingleTrackQCMC

1. Wirkung von cfgRequireTrueAssociation auf die Histogrammfüllung

Die Configurable cfgRequireTrueAssociation (Zeile 101) steuert, ob nur Tracks akzeptiert werden, deren MC-Partikel zur gleichen MC-Collision gehört wie die rekonstruierte Collision.

In der runQCMC-Funktion (Zeile 862-864):

if (cfgRequireTrueAssociation && (mctrack.emmceventId() != collision.emmceventId())) {
  continue;  // Track wird NICHT in Histogramme gefüllt
}

Effekt:

  • Wenn FALSE (default): Tracks werden unabhängig davon akzeptiert, ob sie zur richtigen Collision gehören. Dies kann zu Kontamination führen, wenn ein Track mehreren Collisionen zugeordnet wird.
  • Wenn TRUE: Nur Tracks, deren MC-Herkunfts-Collision mit der rekonstruierten Collision übereinstimmt, werden verarbeitet. Dies eliminiert falsch assoziierte Tracks.

2. TTCA Weights - Berechnung und Zweck

TTCA = "Time To Collision Association"

Die Weights werden in der Funktion fillTrackWeightMap (Zeile 1025-1119) berechnet:

std::unordered_map<int, float> map_weight;  // globalIndex -> weight

void fillTrackWeightMap(...) {
  std::vector<int> passed_trackIds;  // Alle Tracks, die cuts bestehen
  
  // ... Tracks sammeln, die Cuts erfüllen ...
  passed_trackIds.emplace_back(track.globalIndex());
  
  // WICHTIG: Für jeden Track alle "ambiguous" (mehrdeutig zugeordneten) Tracks finden
  for (const auto& trackId : passed_trackIds) {
    auto track = tracks.rawIteratorAt(trackId);
    auto ambIds = track.ambiguousElectronsIds();  // oder ambiguousMuonsIds()
    
    float n = 1.f;  // Zähle mich selbst mit
    for (const auto& ambId : ambIds) {
      if (std::find(passed_trackIds.begin(), passed_trackIds.end(), ambId) 
          != passed_trackIds.end()) {
        n += 1.f;  // Zähle jeden Ambiguity, der auch Cuts erfüllt
      }
    }
    map_weight[trackId] = 1.f / n;  // Weight = 1 / Anzahl der Ambiguities
  }
}

Beispiel:

  • Ein Track T ist zu 3 verschiedenen Collisionen zugeordnet → n = 3
  • Weight = 1/30.333
  • Der Track trägt also nur mit 1/3 zu jedem Histogramm bei

In fillTrackInfo (Zeile 635-638):

float weight = 1.f;
if (cfgApplyWeightTTCA) {
  weight = map_weight[track.g...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

…DileptonMC.h, SingleTrackQCMC.h, and checkMCPairTemplate.cxx

Agent-Logs-Url: https://github.com/feisenhu/O2Physics/sessions/1d6d35c8-a846-4be0-b49e-97d5dba066f8

Co-authored-by: feisenhu <53603353+feisenhu@users.noreply.github.com>
Copilot AI changed the title [WIP] Check TTCA weight calculation in PWGEM/Dilepton tasks Fix cfgRequireTrueAssociation not applied in TTCA weight calculation Apr 14, 2026
Copilot AI requested a review from feisenhu April 14, 2026 11:52
@github-actions github-actions bot added the pwgem label Apr 14, 2026
@github-actions github-actions bot changed the title Fix cfgRequireTrueAssociation not applied in TTCA weight calculation [PWGEM] [WIP] Check TTCA weight calculation in PWGEM/Dilepton tasks Apr 14, 2026
@github-actions github-actions bot changed the title [PWGEM] [WIP] Check TTCA weight calculation in PWGEM/Dilepton tasks [PWGEM] Fix cfgRequireTrueAssociation not applied in TTCA weight calculation Apr 14, 2026
@github-actions github-actions bot changed the title [PWGEM] Fix cfgRequireTrueAssociation not applied in TTCA weight calculation [PWGEM] [WIP] Check TTCA weight calculation in PWGEM/Dilepton tasks Apr 14, 2026
@feisenhu feisenhu marked this pull request as ready for review April 14, 2026 12:00
Copilot AI review requested due to automatic review settings April 14, 2026 12:00
@feisenhu feisenhu merged commit a210bd0 into master Apr 14, 2026
14 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes TTCA weight normalization when cfgRequireTrueAssociation = true in PWGEM/Dilepton MC QC tasks by ensuring tracks/pairs that fail the MC collision association are also excluded from the TTCA denominator (consistent with the existing fill-time filtering).

Changes:

  • Add cfgRequireTrueAssociation filtering to fillTrackWeightMap() in SingleTrackQCMC.h for both dielectron and dimuon paths.
  • Add cfgRequireTrueAssociation filtering to fillPairWeightMap() in DileptonMC.h for ULS / LS++ / LS-- combinations.
  • Apply the same pair-weight fix to the task-level implementation in checkMCPairTemplate.cxx.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
PWGEM/Dilepton/Core/SingleTrackQCMC.h Excludes non-true-associated tracks from the TTCA weight denominator in track weight map building.
PWGEM/Dilepton/Core/DileptonMC.h Excludes non-true-associated pairs from the TTCA weight denominator in pair weight map building (ULS/LS++/LS--).
PWGEM/Dilepton/Tasks/checkMCPairTemplate.cxx Mirrors the pair TTCA denominator fix in the task implementation to keep weighting consistent with fill-time selection.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants