Break Segmentation

ROOT Version: v6-13-02
Platform: macosx64
Compiler: Not Provided

Dear All,

I am trying to create a histogram from a periodic

root [3] h = new **TH1F** ("h","h",100,-20,20);

root [4] for **(** i=0; i<h->GetNbinsX(); i++ **)**

*** Break *** segmentation violation

[/usr/lib/system/libsystem_platform.dylib] _sigtramp (no debug info)

[<unknown binary>] (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenFunction::EmitScalarConversion(llvm::Value*, clang::QualType, clang::QualType, clang::SourceLocation) (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenFunction::EmitForStmt(clang::ForStmt const&, llvm::ArrayRef<clang::Attr const*>) (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*) (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::CodeGen::FunctionArgList&, clang::Stmt const*) (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (no debug info)

[/Users/sn/root/lib/] clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (no debug info)

[/Users/sn/root/lib/] clang::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) (no debug info)

[/Users/sn/root/lib/] cling::DeclCollector::HandleTopLevelDecl(clang::DeclGroupRef) (no debug info)

[/Users/sn/root/lib/] cling::IncrementalParser::ParseInternal(llvm::StringRef) (no debug info)

[/Users/sn/root/lib/] cling::IncrementalParser::Compile(llvm::StringRef, cling::CompilationOptions const&) (no debug info)

[/Users/sn/root/lib/] cling::Interpreter::EvaluateInternal(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::CompilationOptions, cling::Value*, cling::Transaction**, unsigned long) (no debug info)

[/Users/sn/root/lib/] cling::Interpreter::process(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, cling::Value*, cling::Transaction**, bool) (no debug info)

[/Users/sn/root/lib/] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)

[/Users/sn/root/lib/] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) (no debug info)

[/Users/sn/root/lib/] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) (no debug info)

[/Users/sn/root/lib/] TRint::ProcessLineNr(char const*, char const*, int*) (no debug info)

[/Users/sn/root/lib/] TRint::HandleTermInput() (no debug info)

[/Users/sn/root/lib/] TUnixSystem::CheckDescriptors() (no debug info)

[/Users/sn/root/lib/] TUnixSystem::DispatchOneEvent(bool) (no debug info)

[/Users/sn/root/lib/] TSystem::InnerLoop() (no debug info)

[/Users/sn/root/lib/] TSystem::Run() (no debug info)

[/Users/sn/root/lib/] TApplication::Run(bool) (no debug info)

[/Users/sn/root/lib/] TRint::Run(bool) (no debug info)

[/Users/sn/root/bin/root.exe] main (no debug info)

[/usr/lib/system/libdyld.dylib] start (no debug info)

Root > h->SetBinContent(i,f->Eval(h->GetBinCenter(i)));

Can someone kindly assist me with correcting this error, please?

Thanks All

You need to define “i” in the “for” loop, and if you write “SetBinContent” in a separate line, you need brackets (alternatively, write SetBinContent in the same line as “for”, if it is the only command inside the loop). Supposing you already defined “f” before this:

root [4] for (Int_t i=0; iGetNbinsX(); i++ ) h->SetBinContent(i,f->Eval(h->GetBinCenter(i)));
root [4] for (Int_t i=0; iGetNbinsX(); i++ ) {
root (cont’ed, cancel with .@) [5]h->SetBinContent(i,f->Eval(h->GetBinCenter(i)));
root (cont’ed, cancel with .@) [6] (any other lines inside the loop, with “;”, brackets after the last one) }

EDIT: By the way, you probably want to start filling the histogram from bin = 1, not zero, check here:
so either start the loop from i=1, or use h->SetBinContent(i+1,…)

Yes, “f” was defined before. Thank you so much for your response.

The problem is the missing declaration of i as int i, e.g. in for (int i=0;

That’s a bug, thanks for reporting! I’ll let you know what happens to it!


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

I opened a bug report, finally: