Not sure why this is so difficult. I have a .root file in the following format:
file.root
|—> a2MC (tree)
|—>|—> PanelHits (branch)
|—>|—>|—> fHit (leaf)
|—>|—>|—> fRun (leaf)
|—>|—>|—> fPanelID (leaf)
etc etc.
I just want the number of entries with given panel ID. I have tried using a dataframe:
ROOT::RDataFrame* d = new ROOT::RDataFrame("a2MC",sfile.c_str());
auto entries = d->Filter("PanelHits.fPanelID == 0").Count()
(ROOT::RDF::RResultPtr<ULong64_t>) @0x560314c83b20
Then:
entries.GetValue()
gives
/home/lgolino/packages/root/install/include/ROOT/RDF/InterfaceUtils.hxx:300:4: error: static_assert failed due to requirement 'std::is_convertible<ROOT::VecOps::RVec<int>, bool>::value' "filter expression returns a type that is not convertible to bool"
static_assert(std::is_convertible<FilterRet_t, bool>::value,
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lgolino/packages/root/install/include/ROOT/RDF/InterfaceUtils.hxx:428:4: note: in instantiation of function template specialization 'ROOT::Internal::RDF::CheckFilter<R_rdf::(lambda at input_line_56:2:16)>' requested here
CheckFilter(f);
^
input_line_63:2:23: note: in instantiation of function template specialization 'ROOT::Internal::RDF::JitFilterHelper<R_rdf::(lambda at input_line_56:2:16) &, ROOT::Detail::RDF::RNodeBase>' requested here
ROOT::Internal::RDF::JitFilterHelper(R_rdf::lambda0, new const char*[1]{"PanelHits.fPanelID"}, 1, "", reinterpret_cast<std::weak_ptr<ROOT::Detail::RDF::RJittedFilter>*>(0x5603134c58d0), reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>(0x560312905260),reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(0x56031348fec0));
^
In module 'ROOTDataFrame':
/home/lgolino/packages/root/install/include/ROOT/RDF/RFilter.hxx:114:14: error: no viable conversion from returned value of type 'ROOT::VecOps::RVec<int>' to function return type 'bool'
return fFilter(fValues[slot][S]->template Get<ColTypes>(entry)...);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/lgolino/packages/root/install/include/ROOT/RDF/RFilter.hxx:98:27: note: in instantiation of function template specialization 'ROOT::Detail::RDF::RFilter<R_rdf::(lambda at input_line_56:2:16), ROOT::Detail::RDF::RNodeBase>::CheckFilterHelper<ROOT::VecOps::RVec<int> , 0>' requested here
auto passed = CheckFilterHelper(slot, entry, ColumnTypes_t{}, TypeInd_t{});
^
/home/lgolino/packages/root/install/include/ROOT/RDF/RFilter.hxx:71:4: note: in instantiation of member function 'ROOT::Detail::RDF::RFilter<R_rdf::(lambda at input_line_56:2:16), ROOT::Detail::RDF::RNodeBase>::CheckFilters' requested here
RFilter(FilterF f, const ROOT::RDF::ColumnNames_t &columns, std::shared_ptr<PrevNode_t> pd,
^
/home/lgolino/packages/root/install/include/ROOT/RDF/InterfaceUtils.hxx:437:40: note: in instantiation of member function 'ROOT::Detail::RDF::RFilter<R_rdf::(lambda at input_line_56:2:16), ROOT::Detail::RDF::RNodeBase>::RFilter' requested here
std::unique_ptr<RFilterBase>(new F_t(std::forward<F>(f), cols, *prevNodeOnHeap, *colRegister, name)));
^
input_line_63:2:23: note: in instantiation of function template specialization 'ROOT::Internal::RDF::JitFilterHelper<R_rdf::(lambda at input_line_56:2:16) &, ROOT::Detail::RDF::RNodeBase>' requested here
ROOT::Internal::RDF::JitFilterHelper(R_rdf::lambda0, new const char*[1]{"PanelHits.fPanelID"}, 1, "", reinterpret_cast<std::weak_ptr<ROOT::Detail::RDF::RJittedFilter>*>(0x5603134c58d0), reinterpret_cast<std::shared_ptr<ROOT::Detail::RDF::RNodeBase>*>(0x560312905260),reinterpret_cast<ROOT::Internal::RDF::RColumnRegister*>(0x56031348fec0));
^
/home/lgolino/packages/root/install/include/ROOT/RVec.hxx:1246:4: note: candidate template ignored: could not match 'RVecN<type-parameter-0-0, N>' against 'bool'
operator RVecN<U, M>() const
^
/home/lgolino/packages/root/install/include/ROOT/RVec.hxx:1507:4: note: candidate template ignored: could not match 'RVec<type-parameter-0-0>' against 'bool'
operator RVec<U>() const
^
Error in <TRint::HandleTermInput()>: std::runtime_error caught:
An error occurred during just-in-time compilation in RLoopManager::Run. The lines above might indicate the cause of the crash
All RDF objects that have not run their event loop yet should be considered in an invalid state.
And it seems anything else I do with the dataframe gives the same issue, the only thing I can really do is DrawClone on the histogram.
I have also tried:
int main()
{
// Here's the input file
// Without the 'recreate' argument, ROOT will assume this file exists to be read in.
TFile f("../root/a2MC-2022-08-05-13-28-33_0.root");
// We will now "Get" the tree from the file and assign it to
// a new local variable.
TTree *input_tree = (TTree*)f.Get("a2MC");
TBranch *input_branch = (TBranch*)f.Get("PanelHits");
int panelID;
// Assign these variables to specific branch addresses
input_tree->SetBranchAddress("fPanelID",&panelID);
//Also tried this: input_tree->SetBranchAddress("PanelHits.fPanelID",&panelID);
// Get the number of events in the file
Int_t nevents = input_tree->GetEntries();
for (Int_t i=0;i<nevents;i++) {
// Get the values for the i`th event and fill all our local variables
// that were assigned to TBranches
input_tree->GetEntry(i);
// Print the number of jets in this event
printf("%d\n",panelID);
}
return 0;
}
Which just seg faults.
It cannot be this difficult to access members of a root file? What am I missing. I can’t find a single thing online to access members of a root file that actually works. Please help. Cheers.
Please read tips for efficient and successful posting and posting code
ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided