# Getting error when I run my code

**URL:** <https://root-forum.cern.ch/t/getting-error-when-i-run-my-code/43639>\
**Category:** Newbie\
**Created:** [February 21, 2021, 9:34am UTC](https://root-forum.cern.ch/t/getting-error-when-i-run-my-code/43639 "2021-02-21T09:34:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohebtash](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mohebtash](https://root-forum.cern.ch/u/mohebtash)\
**Post date:** [February 21, 2021, 9:34am UTC](https://root-forum.cern.ch/t/getting-error-when-i-run-my-code/43639/1 "2021-02-21T09:34:38Z")

</div>

Dear friends,

I hope you are well

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

```auto
#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:

```auto
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

* * *

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [February 22, 2021, 11:04am UTC](https://root-forum.cern.ch/t/getting-error-when-i-run-my-code/43639/2 "2021-02-22T11:04:50Z")

</div>

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](https://root.cern.ch/doc/master/df102__NanoAODDimuonAnalysis_8C.html)

---

<div class="post-metadata">

**Author:** ![mohebtash](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/9de053/32.png) [@mohebtash](https://root-forum.cern.ch/u/mohebtash)\
**Post date:** [February 27, 2021, 1:33pm UTC](https://root-forum.cern.ch/t/getting-error-when-i-run-my-code/43639/3 "2021-02-27T13:33:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [April 13, 2021, 8:46am UTC](https://root-forum.cern.ch/t/getting-error-when-i-run-my-code/43639/4 "2021-04-13T08:46:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [April 13, 2021, 9:31am UTC](https://root-forum.cern.ch/t/getting-error-when-i-run-my-code/43639/5 "2021-04-13T09:31:22Z")

</div>

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