hi, im new to root___
ive trying out this code, a simple mu vs events, but keeps on failing with --break segmentation–
//=============================
//6oct20 audiya
//read and analyze root file
//=============================
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TVector3.h>
#include <TLorentzVector.h>
#include "TMath.h"
#include "TChain.h"
#include "TBranch.h"
#include "TFile.h"
#include "TTree.h"
#include "TH1.h"
#include "stdio.h"
#include <iostream>
#include "TClonesArray.h"
#include "TObject.h"
using namespace std;
void analyzetree () { //.C file name
//load root file
// TFile *f = new TFile("/Users/applestudio/Desktop/sample28sept/10/10.root");
//get tree from file
//TTree *t = (TTree*) f->Get("Delphes/Muon");
//Get the tree (called nameoftree) from file
TChain *fChain = new TChain("Delphes");
//Load root file
fChain->Add("/Users/applestudio/Desktop/sample28sept/10/10.root");
// set address to variable
// Fixed size dimensions of array or collections stored in the TTree if any.
static constexpr Int_t kMaxMuon = 4;
//declaration of leaf type
Int_t Muon_;
UInt_t Muon_fUniqueID[kMaxMuon]; //[Muon_]
UInt_t Muon_fBits[kMaxMuon]; //[Muon_]
Float_t Muon_PT[kMaxMuon]; //[Muon_]
Float_t Muon_Eta[kMaxMuon]; //[Muon_]
Float_t Muon_Phi[kMaxMuon]; //[Muon_]
Float_t Muon_T[kMaxMuon]; //[Muon_]
Int_t Muon_Charge[kMaxMuon]; //[Muon_]
TRef Muon_Particle[kMaxMuon];
Float_t Muon_IsolationVar[kMaxMuon]; //[Muon_]
Float_t Muon_IsolationVarRhoCorr[kMaxMuon]; //[Muon_]
Float_t Muon_SumPtCharged[kMaxMuon]; //[Muon_]
Float_t Muon_SumPtNeutral[kMaxMuon]; //[Muon_]
Float_t Muon_SumPtChargedPU[kMaxMuon]; //[Muon_]
Float_t Muon_SumPt[kMaxMuon]; //[Muon_]
Float_t Muon_D0[kMaxMuon]; //[Muon_]
Float_t Muon_DZ[kMaxMuon]; //[Muon_]
Float_t Muon_ErrorD0[kMaxMuon]; //[Muon_]
Float_t Muon_ErrorDZ[kMaxMuon]; //[Muon_]
Int_t Muon_size;
// List of branches
//------muons------
TBranch *b_Muon_; //!
TBranch *b_Muon_fUniqueID; //!
TBranch *b_Muon_fBits; //!
TBranch *b_Muon_PT; //!
TBranch *b_Muon_Eta; //!
TBranch *b_Muon_Phi; //!
TBranch *b_Muon_T; //!
TBranch *b_Muon_Charge; //!
TBranch *b_Muon_Particle; //!
TBranch *b_Muon_IsolationVar; //!
TBranch *b_Muon_IsolationVarRhoCorr; //!
TBranch *b_Muon_SumPtCharged; //!
TBranch *b_Muon_SumPtNeutral; //!
TBranch *b_Muon_SumPtChargedPU; //!
TBranch *b_Muon_SumPt; //!
TBranch *b_Muon_D0; //!
TBranch *b_Muon_DZ; //!
TBranch *b_Muon_ErrorD0; //!
TBranch *b_Muon_ErrorDZ; //!
TBranch *b_Muon_size; //!
//set Branch address
//------muon------
fChain->SetBranchAddress("Muon", &Muon_, &b_Muon_);
fChain->SetBranchAddress("Muon.fUniqueID", Muon_fUniqueID, &b_Muon_fUniqueID);
fChain->SetBranchAddress("Muon.fBits", Muon_fBits, &b_Muon_fBits);
fChain->SetBranchAddress("Muon.PT", Muon_PT, &b_Muon_PT);
fChain->SetBranchAddress("Muon.Eta", Muon_Eta, &b_Muon_Eta);
fChain->SetBranchAddress("Muon.Phi", Muon_Phi, &b_Muon_Phi);
fChain->SetBranchAddress("Muon.T", Muon_T, &b_Muon_T);
fChain->SetBranchAddress("Muon.Charge", Muon_Charge, &b_Muon_Charge);
fChain->SetBranchAddress("Muon.Particle", Muon_Particle, &b_Muon_Particle);
fChain->SetBranchAddress("Muon.IsolationVar", Muon_IsolationVar, &b_Muon_IsolationVar);
fChain->SetBranchAddress("Muon.IsolationVarRhoCorr", Muon_IsolationVarRhoCorr, &b_Muon_IsolationVarRhoCorr);
fChain->SetBranchAddress("Muon.SumPtCharged", Muon_SumPtCharged, &b_Muon_SumPtCharged);
fChain->SetBranchAddress("Muon.SumPtNeutral", Muon_SumPtNeutral, &b_Muon_SumPtNeutral);
fChain->SetBranchAddress("Muon.SumPtChargedPU", Muon_SumPtChargedPU, &b_Muon_SumPtChargedPU);
fChain->SetBranchAddress("Muon.SumPt", Muon_SumPt, &b_Muon_SumPt);
fChain->SetBranchAddress("Muon.D0", Muon_D0, &b_Muon_D0);
fChain->SetBranchAddress("Muon.DZ", Muon_DZ, &b_Muon_DZ);
fChain->SetBranchAddress("Muon.ErrorD0", Muon_ErrorD0, &b_Muon_ErrorD0);
fChain->SetBranchAddress("Muon.ErrorDZ", Muon_ErrorDZ, &b_Muon_ErrorDZ);
fChain->SetBranchAddress("Muon_size", &Muon_size, &b_Muon_size);
//Declare histogram
TH1F *muPt = new TH1F("muPt", "p_{T #mu}[GeV]", 160, 0., 800.);
TH1F *muEta = new TH1F("muEta", "#eta_{#mu}", 160, -3, 3.);
TH1F *muPhi = new TH1F("muPhi", "#phi_{#mu}", 100, -5., 5.);
//loop over 100 event je (cuba) (klo nentries sume skli takot lama) in the tree
//Long64_t nentries = t->GetEntries();
// for(int i =0; i < nentries; i++)
Int_t nentries = fChain->GetEntries();
for (int i = 0; i < nentries ; i++)
{
//t->GetEntry(i);
fChain->GetEntry(i);
// Fill histogram
muPt->Fill(Muon_PT[i]);
muEta->Fill(Muon_Eta[i]);
muPhi->Fill(Muon_Phi[i]);
}
// Dram histogram
TCanvas *c1 = new TCanvas("c1", "muEtaPtPhi", 400, 200);
c1->Divide(2,2);
c1->cd(1);
muPt->GetXaxis()->SetTitle("Transverse Momentum (Gev/c)");
muPt->GetYaxis()->SetTitle("Events");
muPt->Draw();
c1->cd(2);
muEta->GetXaxis()->SetTitle("Psedo-rapidity");
muEta->GetYaxis()->SetTitle("Events");
muEta->Draw();
c1->cd(3);
muPhi->GetXaxis()->SetTitle("Azimuthal angle");
muPhi->GetYaxis()->SetTitle("Events");
muPhi->Draw();
}
*** Break *** segmentation violation
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/usr/lib/system/libsystem_c.dylib] _vsnprintf (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libTree.so] TBranch::GetEntry(long long, int) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libTree.so] TBranchElement::GetEntry(long long, int) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libTree.so] TTree::GetEntry(long long, int) (no debug info)
[] (no debug info)
[] (no debug info)
[] (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCore.so] TApplication::ExecuteFile(char const*, int*, bool) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libRint.so] TRint::Run(bool) (no debug info)
[/usr/local/Cellar/root/6.22.02/bin/root.exe] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
i also tried to plot others such as Z mass but failing with–break bus-- error
//==========================
//6 october 2020 audiya Zmass
//==========================
#include <TH2.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TVector3.h>
#include <TLorentzVector.h>
#include "TMath.h"
#include "TChain.h"
#include "TBranch.h"
#include "TFile.h"
#include "TTree.h"
#include "TH1.h"
#include "stdio.h"
#include <iostream>
#include "TClonesArray.h"
#include "TObject.h"
using namespace std;
void Zmass() {
// load file
TChain *fChain = new TChain("Delphes");
//Load root file
fChain->Add("/Users/applestudio/Desktop/sample28sept/10/10.root");
//load root file
// TFile *f = new TFile("/Users/applestudio/Desktop/sample28sept/10/10.root");
//get tree from file
//TTree *t = (TTree*) f->Get("Delphes/Muon");
// set address to variable
// Fixed size dimensions of array or collections stored in the TTree if any.
static constexpr Int_t kMaxMuon = 4;
//declaration of leaf type
Int_t Muon_;
UInt_t Muon_fUniqueID[kMaxMuon]; //[Muon_]
UInt_t Muon_fBits[kMaxMuon]; //[Muon_]
Float_t Muon_PT[kMaxMuon]; //[Muon_]
Float_t Muon_Eta[kMaxMuon]; //[Muon_]
Float_t Muon_Phi[kMaxMuon]; //[Muon_]
Float_t Muon_T[kMaxMuon]; //[Muon_]
Int_t Muon_Charge[kMaxMuon]; //[Muon_]
TRef Muon_Particle[kMaxMuon];
Float_t Muon_IsolationVar[kMaxMuon]; //[Muon_]
Float_t Muon_IsolationVarRhoCorr[kMaxMuon]; //[Muon_]
Float_t Muon_SumPtCharged[kMaxMuon]; //[Muon_]
Float_t Muon_SumPtNeutral[kMaxMuon]; //[Muon_]
Float_t Muon_SumPtChargedPU[kMaxMuon]; //[Muon_]
Float_t Muon_SumPt[kMaxMuon]; //[Muon_]
Float_t Muon_D0[kMaxMuon]; //[Muon_]
Float_t Muon_DZ[kMaxMuon]; //[Muon_]
Float_t Muon_ErrorD0[kMaxMuon]; //[Muon_]
Float_t Muon_ErrorDZ[kMaxMuon]; //[Muon_]
Int_t Muon_size;
// List of branches
//------muons------
TBranch *b_Muon_; //!
TBranch *b_Muon_fUniqueID; //!
TBranch *b_Muon_fBits; //!
TBranch *b_Muon_PT; //!
TBranch *b_Muon_Eta; //!
TBranch *b_Muon_Phi; //!
TBranch *b_Muon_T; //!
TBranch *b_Muon_Charge; //!
TBranch *b_Muon_Particle; //!
TBranch *b_Muon_IsolationVar; //!
TBranch *b_Muon_IsolationVarRhoCorr; //!
TBranch *b_Muon_SumPtCharged; //!
TBranch *b_Muon_SumPtNeutral; //!
TBranch *b_Muon_SumPtChargedPU; //!
TBranch *b_Muon_SumPt; //!
TBranch *b_Muon_D0; //!
TBranch *b_Muon_DZ; //!
TBranch *b_Muon_ErrorD0; //!
TBranch *b_Muon_ErrorDZ; //!
TBranch *b_Muon_size; //!
//set Branch address
//------muon------
fChain->SetBranchAddress("Muon", &Muon_, &b_Muon_);
fChain->SetBranchAddress("Muon.fUniqueID", Muon_fUniqueID, &b_Muon_fUniqueID);
fChain->SetBranchAddress("Muon.fBits", Muon_fBits, &b_Muon_fBits);
fChain->SetBranchAddress("Muon.PT", Muon_PT, &b_Muon_PT);
fChain->SetBranchAddress("Muon.Eta", Muon_Eta, &b_Muon_Eta);
fChain->SetBranchAddress("Muon.Phi", Muon_Phi, &b_Muon_Phi);
fChain->SetBranchAddress("Muon.T", Muon_T, &b_Muon_T);
fChain->SetBranchAddress("Muon.Charge", Muon_Charge, &b_Muon_Charge);
fChain->SetBranchAddress("Muon.Particle", Muon_Particle, &b_Muon_Particle);
fChain->SetBranchAddress("Muon.IsolationVar", Muon_IsolationVar, &b_Muon_IsolationVar);
fChain->SetBranchAddress("Muon.IsolationVarRhoCorr", Muon_IsolationVarRhoCorr, &b_Muon_IsolationVarRhoCorr);
fChain->SetBranchAddress("Muon.SumPtCharged", Muon_SumPtCharged, &b_Muon_SumPtCharged);
fChain->SetBranchAddress("Muon.SumPtNeutral", Muon_SumPtNeutral, &b_Muon_SumPtNeutral);
fChain->SetBranchAddress("Muon.SumPtChargedPU", Muon_SumPtChargedPU, &b_Muon_SumPtChargedPU);
fChain->SetBranchAddress("Muon.SumPt", Muon_SumPt, &b_Muon_SumPt);
fChain->SetBranchAddress("Muon.D0", Muon_D0, &b_Muon_D0);
fChain->SetBranchAddress("Muon.DZ", Muon_DZ, &b_Muon_DZ);
fChain->SetBranchAddress("Muon.ErrorD0", Muon_ErrorD0, &b_Muon_ErrorD0);
fChain->SetBranchAddress("Muon.ErrorDZ", Muon_ErrorDZ, &b_Muon_ErrorDZ);
fChain->SetBranchAddress("Muon_size", &Muon_size, &b_Muon_size);
//create local variable for the branches set as default (0,0,0,0)
TLorentzVector M1(0,0,0,0);
TLorentzVector M2(0,0,0,0);
//declare Histograms
TH1F *Zmass = new TH1F("muZmass", "Zmass", 50, 80., 100.);
//get enteries
Int_t nentries = fChain->GetEntries();
for (int i=0; i<nentries; i++)
{
//t->GetEntry(i);
fChain->GetEntry(i);
for (int m=0; m<Muon_ ; m++)
{
//aplly cuts
if (fabs(Muon_PT[m]<20)) continue;
if (Muon_Eta[2]<-2)continue;
if (m==0) M1.SetPtEtaPhiM(Muon_PT[m],Muon_Eta[m],Muon_Phi[m], 105.7);
if (m==1) M2.SetPtEtaPhiM(Muon_PT[m],Muon_Eta[m],Muon_Phi[m], 105.7);
double ZM = (M1+M2).M();
Zmass->Fill(ZM);
}
}
Zmass->GetXaxis()->SetTitle("Mass Gev/c^2");
Zmass->GetYaxis()->SetTitle("Events");
Zmass->Draw();
}
*** Break *** bus error
[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)
[/usr/lib/system/libsystem_c.dylib] _vsnprintf (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libTree.so] TBranch::GetEntry(long long, int) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libTree.so] TBranchElement::GetEntry(long long, int) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libTree.so] TTree::GetEntry(long long, int) (no debug info)
[] (no debug info)
[] (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value*) const (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::MetaSema::actOnxCommand(llvm::StringRef, llvm::StringRef, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::MetaParser::isXCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::MetaParser::isCommand(cling::MetaSema::ActionResult&, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCling.so] TCling::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libCore.so] TApplication::ExecuteFile(char const*, int*, bool) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)
[/usr/local/Cellar/root/6.22.02/lib/root/libRint.so] TRint::Run(bool) (no debug info)
[/usr/local/Cellar/root/6.22.02/bin/root.exe] main (no debug info)
[/usr/lib/system/libdyld.dylib] start (no debug info)
i assume that its related,
any suggestions on what im missing, thanks
Please read tips for efficient and successful posting and posting code
_ROOT Version: 6.23
Platform: Mac os catalina 10.15.6
Compiler: Apple clang version 11.0.3 (clang-1103.0.32.29)