Skip to content

[PWGEM] [WIP] Fix TTCA weight calculation in fillTrackWeightMap#47

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-ttca-weight-calculation
Closed

[PWGEM] [WIP] Fix TTCA weight calculation in fillTrackWeightMap#47
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-ttca-weight-calculation

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 14, 2026

When cfgRequireTrueAssociation = true, fillTrackWeightMap still counted ambiguous track associations across all collisions, producing weights of 1/N even though runQCMC would only fill histograms for the true collision — resulting in systematic under-correction.

Changes

  • PWGEM/Dilepton/Core/SingleTrackQCMC.h: Added the true association guard in fillTrackWeightMap for both the Dielectron and Dimuon track loops, mirroring the existing check in runQCMC:
if (cfgRequireTrueAssociation && (mctrack.emmceventId() != collision.emmceventId())) {
  continue;
}

This ensures passed_trackIds only contains tracks that will actually be used downstream, so the computed 1/N weight is consistent with what gets filled into histograms.

Original prompt

Bug: cfgRequireTrueAssociation wird bei TTCA-Gewichtsberechnung nicht beachtet

Problem

In der fillTrackWeightMap-Funktion des SingleTrackQCMC.h werden die TTCA-Gewichte berechnet, ohne die cfgRequireTrueAssociation-Einstellung zu berücksichtigen. Dies führt zu inkonsistentem Verhalten:

Szenario mit cfgRequireTrueAssociation = TRUE:

  1. Ein Track T wird zu mehreren Collisionen (C1, C2, C3) zugeordnet, gehört aber MC-mäßig zu C1
  2. In fillTrackWeightMap: Weight wird als 1/3 berechnet (Track wird in allen 3 Collisionen akzeptiert)
  3. In runQCMC: Track wird nur in C1 gefüllt (wegen True Association Check)
  4. Ergebnis: Beitrag = 1/3 statt 1 → Underkorrektion

Ursache

Die Bedingung cfgRequireTrueAssociation && (mctrack.emmceventId() != collision.emmceventId()) fehlt in fillTrackWeightMap für beide Lepton-Typen (Dielectron und Dimuon).

Lösung

Die True Association-Bedingung in fillTrackWeightMap hinzufügen, damit:

  • Nur Tracks mit korrekter MC-Collision-Assoziierung in die Gewichtsberechnung eingehen
  • Das berechnete Gewicht korrekt ist, wenn später in runQCMC derselbe Check angewendet wird

Dateien

  • PWGEM/Dilepton/Core/SingleTrackQCMC.h (Zeilen 1025-1119)

Betroffene Code-Stellen

  1. Dielectron-Block (Zeile 1051-1069): Nach dem cfgEventGeneratorType Check
  2. Dimuon-Block (Zeile 1070-1088): Nach dem cfgEventGeneratorType Check

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.globalIndex()];  // Lookup weight
}
// Histogramme werden m...

</details>



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

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

…ght calculation

Agent-Logs-Url: https://github.com/feisenhu/O2Physics/sessions/a1ab7ba4-281c-421f-89c7-98bf25837d71

Co-authored-by: feisenhu <53603353+feisenhu@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix TTCA weight calculation in fillTrackWeightMap Fix: cfgRequireTrueAssociation not respected in TTCA weight calculation Apr 14, 2026
Copilot AI requested a review from feisenhu April 14, 2026 11:40
@github-actions github-actions bot added the pwgem label Apr 14, 2026
@github-actions github-actions bot changed the title Fix: cfgRequireTrueAssociation not respected in TTCA weight calculation [PWGEM] [WIP] Fix TTCA weight calculation in fillTrackWeightMap Apr 14, 2026
@github-actions github-actions bot changed the title Fix: cfgRequireTrueAssociation not respected in TTCA weight calculation [PWGEM] Fix: cfgRequireTrueAssociation not respected in TTCA weight calculation Apr 14, 2026
@github-actions github-actions bot changed the title [PWGEM] Fix: cfgRequireTrueAssociation not respected in TTCA weight calculation [PWGEM] [WIP] Fix TTCA weight calculation in fillTrackWeightMap Apr 14, 2026
@feisenhu feisenhu marked this pull request as ready for review April 14, 2026 12:01
Copilot AI review requested due to automatic review settings April 14, 2026 12:01
@feisenhu feisenhu closed this Apr 14, 2026
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 an inconsistency between fillTrackWeightMap (TTCA weight computation) and runQCMC when cfgRequireTrueAssociation = true, ensuring TTCA weights are computed only from tracks that will actually be used for histogram filling.

Changes:

  • Add a cfgRequireTrueAssociation guard in the dielectron branch of fillTrackWeightMap.
  • Add the same guard in the dimuon branch of fillTrackWeightMap.

💡 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