Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding of a function to obtain MC indices array and a parents tuples … #112

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions analyzers/dataframe/MCParticle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,13 @@ ROOT::VecOps::RVec<int> MCParticle::get_parentid(ROOT::VecOps::RVec<int> mcind,
return result;
}

ROOT::VecOps::RVec<int> get_index(ROOT::VecOps::RVec<edm4hep::MCParticleData> mc){
Copy link
Contributor

Choose a reason for hiding this comment

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

I do not see the point of this function, it just return the list of indices of the collection. The result will always be a vector of int between 0 and size-1. Why is that needed?

Copy link
Author

Choose a reason for hiding this comment

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

It was needed to be able to use the MCParticle::get_parentid() method directly on the MC sample (the list of indices is an input of this method).

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, I understand that but I think this is something that could go in the define directly, After checking with RDF experts, seems something like this should be the most efficient way:

df.Define("idxs", "RVecI v(sz); std::iota(...); return v;")

Copy link
Author

Choose a reason for hiding this comment

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

Ok I see, interesting , it is another way to do that directly in the analysis.py script.

Copy link
Contributor

Choose a reason for hiding this comment

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

could you check it does work the same and remove the corresponding C++ code ?

Copy link
Author

Choose a reason for hiding this comment

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

I will check that later.

Copy link
Author

Choose a reason for hiding this comment

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

It's removed.

Copy link
Author

Choose a reason for hiding this comment

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

When I try to use std::iota in the analysis.py, the following error occurred:

input_line_101:2:108: error: no matching function for call to 'iota'
auto lambda21 = [](ROOT::VecOps::RVecedm4hep::MCParticleData& var0){ROOT::RVecI list_index(var0.size()); std::iota(list_index,list_index+list_index.size(),0); return list_index;
^~~~~~~~~
/cvmfs/sw.hsf.org/contrib/gcc/11.2.0/x86_64-centos7-gcc8.3.0-opt/d3epy/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../include/c++/11.2.0/bits/stl_numeric.h:88:5: note: candidate template ignored: deduced conflicting types for parameter '_ForwardIterator' ('RVec' vs. 'RVec')
iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
^
python3: /tmp/gitlab-runner/spack-stage/spack-stage-root-6.26.02-oqvm2mao7vull7th2vj4tmyo3i4jqsdp/spack-src/interpreter/llvm/src/tools/clang/lib/AST/DeclCXX.cpp:1391: clang::CXXMethodDecl* clang::CXXRecordDecl::getLambdaCallOperator() const: Assertion !Calls.empty() && "Missing lambda call operator!"' failed. *** Break *** abort ^Cinput_line_102:2:108: error: no matching function for call to 'iota' auto lambda21 = [](ROOT::VecOps::RVec<edm4hep::MCParticleData>& var0){ROOT::RVecI list_index(var0.size()); std::iota(list_index,list_index+list_index.size(),0); return list_index; ^~~~~~~~~ /cvmfs/sw.hsf.org/contrib/gcc/11.2.0/x86_64-centos7-gcc8.3.0-opt/d3epy/lib/gcc/x86_64-pc-linux-gnu/11.2.0/../../../../include/c++/11.2.0/bits/stl_numeric.h:88:5: note: candidate template ignored: deduced conflicting types for parameter '_ForwardIterator' ('RVec<int>' vs. 'RVec<unsigned long>') iota(_ForwardIterator __first, _ForwardIterator __last, _Tp __value) ^ python3: /tmp/gitlab-runner/spack-stage/spack-stage-root-6.26.02-oqvm2mao7vull7th2vj4tmyo3i4jqsdp/spack-src/interpreter/llvm/src/tools/clang/lib/AST/DeclCXX.cpp:1391: clang::CXXMethodDecl* clang::CXXRecordDecl::getLambdaCallOperator() const: Assertion !Calls.empty() && "Missing lambda call operator!"' failed.
*** Break *** abort

I have certainly something wrong but I don't understand what, have you any idea ?

thanks

ROOT::VecOps::RVec<int> result;
for (size_t i = 0; i < mc.size(); ++i) {
result.push_back(i);
}
return result;
}

// ----------------------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -676,9 +683,20 @@ ROOT::VecOps::RVec<float> MCParticle::AngleBetweenTwoMCParticles( ROOT::VecOps::
}

return result;
}

ROOT::VecOps::RVec<edm4hep::MCParticleData> MCParticle::get_MC_from_indices(ROOT::VecOps::RVec<int> index, ROOT::VecOps::RVec<edm4hep::MCParticleData> in){
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would go for somehting like get_subMC

Copy link
Author

Choose a reason for hiding this comment

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

Done

ROOT::VecOps::RVec<edm4hep::MCParticleData> result;
for (size_t i = 0; i < index.size(); ++i) {
if (index[i]>-1)
result.push_back(in.at(index[i]));
//else
// std::cout << "electron index negative " << index[i]<<std::endl;
}
return result;
}





7 changes: 6 additions & 1 deletion analyzers/dataframe/MCParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ namespace MCParticle{
bool m_chargeconjugate = true;
ROOT::VecOps::RVec<edm4hep::MCParticleData> operator() (ROOT::VecOps::RVec<edm4hep::MCParticleData> in);
};

Copy link
Contributor

Choose a reason for hiding this comment

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

remove 2 spaces



/// get MC history tree for a given MCParticle index
struct get_tree{
Expand Down Expand Up @@ -91,6 +93,8 @@ namespace MCParticle{
ROOT::VecOps::RVec<edm4hep::MCParticleData> in ,
ROOT::VecOps::RVec<int> ind);

/// return indices of MC particles
ROOT::VecOps::RVec<int> get_index(ROOT::VecOps::RVec<edm4hep::MCParticleData> mc);

/// return the parent index of a given list of MC particles
ROOT::VecOps::RVec<int> get_parentid(ROOT::VecOps::RVec<int> mcind, ROOT::VecOps::RVec<edm4hep::MCParticleData> mc, ROOT::VecOps::RVec<int> parents);
Expand Down Expand Up @@ -200,7 +204,8 @@ namespace MCParticle{
ROOT::VecOps::RVec<edm4hep::MCParticleData> in,
ROOT::VecOps::RVec<int> ind) ;


/// get a list of MCParticle from a list of indices
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should write somethig like: return a sub list of MCParticles

Copy link
Author

Choose a reason for hiding this comment

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

Done

ROOT::VecOps::RVec<edm4hep::MCParticleData> get_MC_from_indices(ROOT::VecOps::RVec<int> index, ROOT::VecOps::RVec<edm4hep::MCParticleData> in);


}
Expand Down