Skip to content

Add MC filtering tools - #2510

Open
alcaliva wants to merge 1 commit into
AliceO2Group:masterfrom
alcaliva:master
Open

alcaliva wants to merge 1 commit into
AliceO2Group:masterfrom
alcaliva:master

Conversation

@alcaliva

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions

Copy link
Copy Markdown

REQUEST FOR PRODUCTION RELEASES:
To request your PR to be included in production software, please add the corresponding labels called "async-" to your PR. Add the labels directly (if you have the permissions) or add a comment of the form (note that labels are separated by a ",")

+async-label <label1>, <label2>, !<label3> ...

This will add <label1> and <label2> and removes <label3>.

The following labels are available
async-2023-pbpb-apass4
async-2023-pp-apass4
async-2024-pp-apass1
async-2022-pp-apass7
async-2024-pp-cpass0
async-2024-PbPb-apass1
async-2024-ppRef-apass1
async-2024-PbPb-apass2
async-2023-PbPb-apass5

@alcaliva
alcaliva enabled auto-merge (squash) October 19, 2026 13:34

@sawenzel sawenzel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please consider general comments and in-line comments

for (Long64_t oldParticleId = 0; oldParticleId < numberOfParticles; ++oldParticleId) {
inputTree->GetEntry(oldParticleId);
particleMcCollisionId[oldParticleId] = mcCollisionId;
const int safeMothersSize = std::min(mothersSize, kMaxMothers);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This check comes after GetEntry, which has already written mothersSize entries into the fixed mothers[kMaxMothers] buffer. The PDG macro checks GetMaximum("fIndexArray_Mothers_size") before the loop; could you do the same here?

Long64_t newlyInvalidatedReferences = 0;
for (Long64_t row = 0; row < numberOfRows; ++row) {
inputTree->GetEntry(row);
if (idsSize > kMaxCaloLabels) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above for the calo labels: the overflow has already happened when this triggers. The PDG macro's GetMaximum pre-check would fix it.

// A daughter slice represents a contiguous interval
// [firstDaughter, lastDaughter]. Preserve the surviving daughters if their
// remapped indices remain contiguous.
bool survivingDaughterSliceIsContiguous = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since oldToNew preserves order, the survivors of a contiguous old range are always contiguous, so this check never fails. Only slices with no survivors get cleared. That is fine, but the counter "incomplete daughter slices cleared" really counts empty slices, while incomplete ones are kept (see the general comment on truncation).

};
int getSubGeneratorIdFromGeneratorsID(Short_t generatorsID) {
const auto encoded = static_cast<UShort_t>(generatorsID);
const int encodedSubGeneratorId = static_cast<int>((encoded >> 11) & 0x1Fu);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this use o2::mcgenid::getSubGeneratorId() from SimulationDataFormat/MCGenProperties.h instead of repeating the bit layout?

delete object;
continue;
}
if (!object->InheritsFrom(TDirectory::Class())) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

parentFiles in merged AO2Ds is a TMap as well, and it needs kSingleKey like metaData; otherwise each entry ends up as its own key.

Suggested change
if (!object->InheritsFrom(TDirectory::Class())) {
if (key->GetName() == std::string("parentFiles")) {
outputFile->cd();
object->Write("parentFiles", TObject::kSingleKey | TObject::kOverwrite);
delete object;
continue;
}
if (!object->InheritsFrom(TDirectory::Class())) {

TIter next(inDir->GetListOfKeys());
TKey* key = nullptr;

while ((key = static_cast<TKey*>(next()))) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here and in the top-level loop at L1164: the gap macro skips older key cycles (key->GetCycle() != dir->GetKey(name)->GetCycle()); this one doesn't, and with kOverwrite the older cycle, being read last, wins.


const std::string name = obj->GetName();

if (!obj->InheritsFrom(TDirectory::Class())) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same parentFiles / kSingleKey point as in the gap macro.


const Long64_t inputBytes = inFile->GetSize();

auto* outFile = TFile::Open(output, "RECREATE");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same compression point as in the gap macro:

Suggested change
auto* outFile = TFile::Open(output, "RECREATE");
auto* outFile = TFile::Open(output, "RECREATE", "", 505);

void filterAO2DMCParticlesPdg(
const char* input = "AO2D.root",
const char* output = "AO2D_filter.root",
const std::vector<int>& pdgs = {211, 2212},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is {211, 2212} intended as a default? It keeps almost everything; maybe no default, or the Λ example from the usage line.

int firstNewDaughter = -1;
int lastNewDaughter = -1;
int previousNewDaughter = -1;
bool validSlice = true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as in the gap macro: with an order-preserving map this can't become false.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants