Getting error when I run my code

Dear friends,

I hope you are well

I want to calculate invariant mass of two opposite charge muons, my code is:

#include "TFile.h"
#include "TTree.h"
#include "TCanvas.h"
#include"TVector3.h"
#include"TH1F.h"
#include <TLatex.h>
#include<iostream>
using namespace std;

//task1

void readEvents(){
TFile * f = new TFile("data.root");
TTree * tree=(TTree *)f->Get("events");
Int_t nEntries=tree->GetEntries();
cout<<"There are"<<nEntries<<"entries in your ntuple"<<endl;

//task2

 Int_t NMuon;
 Int_t Muon_Charge[5];
 Float_t Muon_Px[5];
 Float_t Muon_Py[5];
 Float_t Muon_Pz[5];
 Float_t Muon_E[5];
 
 
//task3

 tree->SetBranchAddress("NMuon",&NMuon);
 tree->SetBranchAddress("Muon_Charge",&Muon_Charge);
 tree->SetBranchAddress("Muon_Px", &Muon_Px);
 tree->SetBranchAddress("Muon_Py", &Muon_Py);
 tree->SetBranchAddress("Muon_Pz", &Muon_Pz);
 tree->SetBranchAddress("Muon_E", &Muon_E);

 //task4
 
 for(Int_t entry=0;entry<nEntries; entry++){
 
   TLorentzVector masspositive;
   TLorentzVector massnegative;
   TLorentzVector Mass;
   
   if(NMuon==2)
     if(Muon_Charge[1]!=Muon_Charge[2])
   
     masspositive.SetPxPyPzE(Muon_Px[1],Muon_Py[1],Muon_Pz[1],Muon_E[1]);
    
      massnegative.SetPxPyPzE(Muon_Px[2],Muon_Py[2],Muon_Pz[2],Muon_E[2]);
      Mass=masspositive+massnegative;
      Double_t invariantmass=Mass.Dot(Mass);
      cout<<invariantmass<<endl;
    
}
}

and I get this error:

cling::DynamicLibraryManager::loadLibrary(): /home/zahra/root/macros/HEPTutorial_0/HEPTutorial/files/example.x: cannot dynamically load position-independent executable
Error in <TCling__LazyFunctionCreatorAutoloadForModule>: Failed to load library /home/zahra/root/macros/HEPTutorial_0/HEPTutorial/files/example.x
cling::DynamicLibraryManager::loadLibrary(): /home/zahra/root/macros/HEPTutorial_0/HEPTutorial/files/example.x: cannot dynamically load position-independent executable
Error in <TCling__LazyFunctionCreatorAutoloadForModule>: Failed to load library /home/zahra/root/macros/HEPTutorial_0/HEPTutorial/files/example.x
IncrementalExecutor::executeFunction: symbol '_ZN6TClass8GetClassIiEEPS_bb' unresolved while linking [cling interface function]!
You are probably missing the definition of TClass* TClass::GetClass<int>(bool, bool)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZN6TClass8GetClassIA5_iEEPS_bb' unresolved while linking [cling interface function]!
You are probably missing the definition of TClass* TClass::GetClass<int [5]>(bool, bool)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZN6TClass8GetClassIA5_fEEPS_bb' unresolved while linking [cling interface function]!
You are probably missing the definition of TClass* TClass::GetClass<float [5]>(bool, bool)
Maybe you need to load the corresponding shared library?

Can anybody help me?

Thanks a lot

_ROOT Version: 6.22/06
_Platform:Ubuntu 20
_Compiler: Linux terminal


Hello,

There’s possibly some issue with your ROOT installation, how did you install ROOT?

Side note: please note that you can also do the same with RDataFrame, example:

https://root.cern.ch/doc/master/df102__NanoAODDimuonAnalysis_8C.html

Thanks for your answer.

I install ROOT from the website of CERN ROOT. Actually other codes are run. I do not know what is the problem in this code.

I also see the RDataFrame, I think it uses classes. I did not write my code in this style.

I guess you are running this code as a ROOT macro from the ROOT prompt? What is the example.x file you see in the error message?

Perhaps @Axel will know better what can be going on.

Try renaming the file to example.cxx - does that help? (.x isn’t a common C++ file extension.)