How to use RDataFrame in pyROOT to loop events and calculate weighted efficiency?


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/06
Platform: macOS 11.1 arm64
Compiler: Not Provided


The attached weights.root file contains an 2D histogram which has the weights for given values of two variables, B_PT and nTracks.

The attached data.root contains all the data events.

The goal is to calculate the weighted efficiency of a certain cut. For simplicity, let’s use B_M>5300 as the cut.

Currently, I use the following code to do this job

# get_eff.py
import ROOT
fdata = ROOT.TFile.Open('data.root', 'READ')
fweight = ROOT.TFile.Open('weights.root', 'READ')
hweight = fweight.Get('hweight')

tree = fdata.Get('DecayTree')
ntot = tree.GetEntries() 

weight_pass = 0 # store the passed events weights
weight_all = 0  # store the total weights of all events

# Loop through all events
for i in range(ntot):
	tree.GetEntry(i)
	weight = hweight.GetBinContent(hweight.FindBin(tree.B_PT, tree.nTracks))
	weight_all += weight
	if tree.B_M>5300:
		weight_pass += weight
	
eff = weight_pass / weight_all
print('The weighted efficiency is ' + str(eff))

However, looping over all events seems to be very slow in python as I have 60 million events to process. I saw people mentioned RDataFrame is very efficient to loop through events. Indeed, I found using RDataFrame to apply simple cut like RDataFrame.Filter('B_M>5300') is tremendously faster than for loop. But I don’t know how to use RDataFrame to perform such a task in the code above - to calculate a weighted efficiency.

Could you please teach me how I can modify my code to implement RDataFrame in such case?

weights.root (54.2 KB) data.root (325.0 KB) get_eff.py (526 字节)

@eguiraud could you please take a look? thanks!

Hi @Patrick_Wu,
I think we need an interpreter trick to make hweight available in RDataFrame’s C++ event loop:

ROOT.gInterpreter.Declare("""                                                                                           
auto fweight = TFile::Open("weights.root");                                                                             
auto hweight = fweight->Get<TH2D>("hweight");                                                                           
""")                                                                                                                    
                                                                                                                        
df = ROOT.RDataFrame("DecayTree", "data.root")                                                                          
df2 = df.Define("weight", "hweight->GetBinContent(hweight->FindBin(B_PT, nTracks))")                                    
weight_all = df2.Sum("weight")                                                                                          
weight_pass = df2.Filter("B_M > 5300").Sum("weight")                                                                    
                                                                                                                        
print(f'The weighted efficiency with RDF is {weight_pass.GetValue() / weight_all.GetValue()}')

You will see the RDF version has a higher start-up cost, because it needs to just-in-time compile those strings into C++ code, but will then run much faster on large datasets.

@etejedor might know a prettier way to declare hweight to the interpreter.

Cheers,
Enrico

1 Like

Thanks a lot, Enrico! This Interpreter seems to open up lots of possibilities. I’m so glad to know this.

But the code seems not robust enough. As you can see below the shell outputs message, I ran the code twice successively with no changes in between. The first time it gave me segmentation violation error but second time it went through fine.

First run

$ pythhon3 get_eff.py
 *** Break *** bus error
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TUnixSystem::DispatchSignals(ESignals) (no debug info)
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TList::Streamer(TBuffer&) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TBufferFile::ReadFastArray(void**, TClass const*, int, bool, TMemberStreamer*, TClass const*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TStreamerInfoActions::GenericReadAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TBufferFile::ReadClassBuffer(TClass const*, void*, int, unsigned int, unsigned int, TClass const*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libHist.6.22.06.so] TH1::Streamer(TBuffer&) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TStreamerBase::ReadBuffer(TBuffer&, char*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TStreamerInfoActions::GenericReadAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TBufferFile::ReadClassBuffer(TClass const*, void*, int, unsigned int, unsigned int, TClass const*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libHist.6.22.06.so] TH2::Streamer(TBuffer&) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TStreamerBase::ReadBuffer(TBuffer&, char*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] int TStreamerInfo::ReadBuffer<char**>(TBuffer&, char** const&, TStreamerInfo::TCompInfo* const*, int, int, int, int, int) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TStreamerInfoActions::GenericReadAction(TBuffer&, void*, TStreamerInfoActions::TConfiguration const*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TBufferFile::ApplySequence(TStreamerInfoActions::TActionSequence const&, void*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TBufferFile::ReadClassBuffer(TClass const*, void*, int, unsigned int, unsigned int, TClass const*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libHist.6.22.06.so] TH2D::Streamer(TBuffer&) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TKey::ReadObjectAny(TClass const*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.6.22.06.so] TDirectoryFile::GetObjectChecked(char const*, TClass const*) (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCling.6.22.06.so] cling::IncrementalExecutor::runStaticInitializersOnce(cling::Transaction const&) const (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCling.6.22.06.so] cling::Interpreter::executeTransaction(cling::Transaction&) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCling.6.22.06.so] cling::IncrementalParser::commitTransaction(llvm::PointerIntPair<cling::Transaction*, 2u, cling::IncrementalParser::EParseResult, llvm::PointerLikeTypeTraits<cling::Transaction*>, llvm::PointerIntPairInfo<cling::Transaction*, 2u, llvm::PointerLikeTypeTraits<cling::Transaction*> > >&, bool) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCling.6.22.06.so] cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCling.6.22.06.so] cling::Interpreter::declare(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::Transaction**) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCling.6.22.06.so] TCling::LoadText(char const*) const (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCling.6.22.06.so] TCling::Declare(char const*) (no debug info)
[<unknown binary>] (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy_backend3_9.6.22.06.so] WrapperCall(long, unsigned long, void*, void*, void*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy_backend3_9.6.22.06.so] Cppyy::CallB(long, void*, unsigned long, void*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::(anonymous namespace)::BoolExecutor::Execute(long, void*, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPMethod::ExecuteFast(void*, long, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPMethod::ExecuteProtected(void*, long, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object*, _object*, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::(anonymous namespace)::mp_call(CPyCppyy::CPPOverload*, _object*, _object*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] _PyObject_MakeTpCall (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] call_function (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] _PyEval_EvalFrameDefault (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] _PyEval_EvalCode (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] PyRun_FileExFlags (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] PyRun_SimpleFileExFlags (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] pymain_run_file (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] pymain_run_python (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] Py_RunMain (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] pymain_main (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
Traceback (most recent call last):
  File "/Users/hangyi/Desktop/get_eff.py", line 3, in <module>
    ROOT.gInterpreter.Declare("""
cppyy.ll.SegmentationViolation: bool TInterpreter::Declare(const char* code) =>
    SegmentationViolation: segfault in C++; program state was reset
 *** Break *** segmentation violation
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TUnixSystem::DispatchSignals(ESignals) (no debug info)
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TROOT::CloseFiles() (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TROOT::EndOfProcessCleanups() (no debug info)
[<unknown binary>] (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy_backend3_9.6.22.06.so] WrapperCall(long, unsigned long, void*, void*, void*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::(anonymous namespace)::VoidExecutor::Execute(long, void*, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPMethod::ExecuteFast(void*, long, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPMethod::ExecuteProtected(void*, long, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::CPPMethod::Call(CPyCppyy::CPPInstance*&, _object*, _object*, CPyCppyy::CallContext*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libcppyy3_9.6.22.06.so] CPyCppyy::(anonymous namespace)::mp_call(CPyCppyy::CPPOverload*, _object*, _object*) (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] _PyObject_MakeTpCall (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] call_function (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] _PyEval_EvalFrameDefault (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] _PyFunction_Vectorcall (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] atexit_callfuncs (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] Py_FinalizeEx (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] Py_RunMain (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] pymain_main (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/bin/python3] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/python3.9/site-packages/ROOT/__init__.py", line 113, in cleanup
    backend.gROOT.EndOfProcessCleanups()
cppyy.ll.SegmentationViolation: void TROOT::EndOfProcessCleanups() =>
    SegmentationViolation: segfault in C++; program state was reset
 *** Break *** bus error
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TUnixSystem::DispatchSignals(ESignals) (no debug info)
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TROOT::CloseFiles() (no debug info)
[/usr/lib/system/libsystem_c.dylib] __cxa_finalize_ranges (no debug info)
[/usr/lib/system/libsystem_c.dylib] exit (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
 *** Break *** bus error
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TUnixSystem::DispatchSignals(ESignals) (no debug info)
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[<unknown binary>] (no debug info)
[/opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.6.22.06.so] TROOT::CloseFiles() (no debug info)
[/usr/lib/system/libsystem_c.dylib] __cxa_finalize_ranges (no debug info)
[/usr/lib/system/libsystem_c.dylib] exit (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
^C

Second run

$ python3 get_eff.py
The weighted efficiency with RDF is 0.3483978540941734

Hi,
uhm looks like there was a crash during the reading of the histogram.
You might want to add a check for fweight != nullptr and hweight != nullptr before you use those pointers. Other than that, hard to say what’s wrong. Does the crash happen often? Can you reproduce it e.g. on lxplus, where I could try things out too? Do you also get a crash if you simply run (in a loop, for a while) a program that only extracts “hweight” from “weights.root”, e.g.

#include <TFile.h>
#include <TH2D.h>

int main() {
  auto fweight = TFile::Open("weights.root");                                                                             
  auto hweight = fweight->Get<TH2D>("hweight");
  return 0;
}

and

$ g++ -o main main.cpp $(root-config --libs --cflags) && for i in $(seq 1 1000); do ./main; done

?

Hi,

Do you also get a crash if you simply run (in a loop, for a while) a program that only extracts “hweight” from “weights.root”

No, there’s no crash if I only run

import ROOT
ROOT.gInterpreter.Declare("""                                                                                           
auto fweight = TFile::Open("weights.root");                                                                             
auto hweight = fweight->Get<TH2D>("hweight");                                                                           
""")

This compilation command doesn’t work for me likely due to the arm64 architecture…

g++ -o main main.cpp $(root-config --libs --cflags) && for i in $(seq 1 1000); do ./main; done

with the main.cpp file being the C++ code you provided.

But I did create a folder containing all related files on lxplus. Please find them here: /afs/cern.ch/work/h/hawu/public/rdf

On lxplus this won’t be exactly the same as running on my local machine but the quickest way to set up the environment and run this code is to:

cd /afs/cern.ch/work/h/hawu/public/rdf
lb-conda default bash # enter the lxplus default conda env where I can use ROOT with python3 (v3.8.6)
python3 get_eff.py

In principle this should have the same behavior as running on my local machine. However, I couldn’t get the code to work any more. The error message is saved in file /afs/cern.ch/work/h/hawu/public/rdf/log

PS. ROOT and python3 on my local machine were installed in a miniconda environment.

1 Like

ROOT should compile fine on ARM. Did you activate the conda environment where ROOT is installed before trying to compile? What’s the exact error?

I don’t have a lb-conda command on lxplus, so I used instead source /cvmfs/sft.cern.ch/lcg/views/LCG_99/x86_64-centos7-gcc8-dbg/setup.sh to setup an environment with Python 3.8 and ROOT v6.22.06. I see the crash when running python get_eff.py, I’m investigating.

Looks like ROOT.gInterpreter.Declare is not enough here, you need ROOT.gInterpreter.ProcessLine, my bad. That should fix it.

The segfault’s stacktrace is really weird/hard to interpret though, @Axel @pcanal I/O gone wrong because we are doing it within Declare isntead of ProcessLine is something known/expected?

1 Like

Change from Declare to ProcessLine did help! Thank you very much!!

ROOT should compile fine on ARM. Did you activate the conda environment where ROOT is installed before trying to compile? What’s the exact error?

Yes. I’m in the pyROOT conda environment.

The error after running

g++ -o main main.cpp $(root-config --libs --cflags) && for i in $(seq 1 1000); do ./main; done

is

ld: warning: ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libImt.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libCore.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRIO.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libNet.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libGpad.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libHist.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libTree.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libTreePlayer.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libRint.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libPostscript.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libROOTVecOps.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libGraf3d.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libMatrix.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libGraf.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libMathCore.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libROOTDataFrame.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libMultiProc.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64ld: warning:
ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libThread.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libPhysics.so, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /opt/homebrew/Caskroom/miniconda/base/envs/analysis/lib/libc++.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
Undefined symbols for architecture arm64:
  "TVersionCheck::TVersionCheck(int)", referenced from:
      ___cxx_global_var_init in main-6acc8c.o
  "TH2D::Class()", referenced from:
      TClass* ROOT::Internal::GetClassHelper<TH2D>(bool, bool, std::__1::integral_constant<bool, true>) in main-6acc8c.o
  "TFile::Open(char const*, char const*, char const*, int, int)", referenced from:
      _main in main-6acc8c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

The content in main.cpp

#include <TFile.h>
#include <TH2D.h>

int main() {
  auto fweight = TFile::Open("weights.root");
  auto hweight = fweight->Get<TH2D>("hweight");
  return 0;
}

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