legend-exp / remage

Simulation framework for germanium experiments
https://remage.readthedocs.io
GNU Lesser General Public License v3.0
4 stars 5 forks source link

Flat tuples register NtupleID only for the first detector (bug) #110

Closed EricMEsch closed 3 months ago

EricMEsch commented 3 months ago

When using flat tuples the Ntuple will only be registered once. This is how it should be. However look at the code below:

auto ntuple_name = this->GetNtupleName(det.second.uid);
auto had_name = registered_ntuples.emplace(ntuple_name);
if (!had_name.second) continue;

auto id =
     rmg_man->RegisterNtuple(det.second.uid, ana_man->CreateNtuple(ntuple_name, "Event data"));

The line rmg_man->RegisterNtuple(det.second.uid, ana_man->CreateNtuple(ntuple_name, "Event data")); will only be executed for the first detector of its type, as then the flat ntuple_name will always be the same (one tuple per type). So only this single det.second.ui will have the correct entry in the map fNtupleIDs of RMGManager. Lets say you register 4 Germanium and 4 Optical detectors. The first Germanium and Optical detectors will be registered correctly. For the rest rmg_man->GetNtupleID(hit->detector_uid); will just return 0.

When using a single detector type this issue does not occur, as the NtupleID of 0 is correct (by chance). However, when using more than one detector type this is an issue. In the example above, the 3 Optical detectors following the first will write in the tuple 0, which belongs to the germanium detectors, producing unpredictable results.

This is (obviously) not an issue when writing seperate tuples for each detector.

ManuelHu commented 3 months ago

Thanks for the bug reports. I already found fixes for both bugs, and will push them after testing. Unfortunately we do not have automated tests for all output code in place (that is also why those bugs existed in the first place...)