Corruption when iterating and copying a tree

I have some code that iterates over a TChain (the old fashioned way) and rewrites the tree with a modification to a weight column (an enhanced hadd, in effect). However the weights in the output tree show significant corruption.

The code is available at https://gist.github.com/beojan/dfd281dd359cb755d6c71907b035c392.

I am testing by merging one file, so the weights shouldn’t change. I can verify this while running:image

However, the weights before and after merging do not match:
Before:
image

After:
image

Does anyone have any tips on what could be causing this? We originally saw the issue on EOS but this test was run with both the input and output files in my AFS work directory.


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22
Platform: CentOS 7 (lxplus) with LCG 98
Compiler: GCC 8.2.0


@pcanal might have some ideas about this.

Does the information logged by

spdlog::info("Evt {} Norm {:.3g} Wgt {:.4g} -> {:.4g} ({:.4g})", i, norm_, wgt_old, wgt, wgt_old * norm_);

look valid?

What does

one_of_tree->GetBranch("mc_sf")->Print();

print to the screen?

Does the information logged by

spdlog::info("Evt {} Norm {:.3g} Wgt {:.4g} -> {:.4g} ({:.4g})", i, norm_, wgt_old, wgt, wgt_old * norm_);

look valid?

Yes, that’s shown in the first screenshot.

one_of_tree->GetBranch("mc_sf")->Print();

Unmerged
image

Merged
image

Change:

std::vector<double>* mc_sf = nullptr; // pointer because this is an STL container

to

std::vector<float>* mc_sf = nullptr; // pointer because this is an STL container

The I/O sub-system is capable of doing the conversion from std::vector<float> to std::vector<double> when reading (hence the correct printed information) but not when writing.

1 Like

Thanks. That fixed it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.