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
Changes from 1 commit
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
@@ -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;
}

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

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

return result;
}

ROOT::VecOps::RVec<edm4hep::MCParticleData> MCParticle::get(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 guess this is to get a list of MCParticle from a list of indices. The name get is then very confusing.

Copy link
Author

Choose a reason for hiding this comment

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

I change it in a new commit, don't hesitate if you have any other suggestion for the name.

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;
}





5 changes: 5 additions & 0 deletions analyzers/dataframe/MCParticle.h
Original file line number Diff line number Diff line change
@@ -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{
@@ -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);
@@ -201,6 +205,7 @@ namespace MCParticle{
ROOT::VecOps::RVec<int> ind) ;


ROOT::VecOps::RVec<edm4hep::MCParticleData> get(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.

missing a documentation line

Copy link
Author

Choose a reason for hiding this comment

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

Added in a new commit



}