# Fitting Histograms :: null pointer error

**URL:** <https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440>\
**Category:** ROOT\
**Created:** [March 17, 2020, 6:03pm UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440 "2020-03-17T18:03:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mansi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@Mansi](https://root-forum.cern.ch/u/Mansi)\
**Post date:** [March 17, 2020, 6:03pm UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/1 "2020-03-17T18:03:40Z")

</div>

Hello,

I have a fitting routine written to fit peaks in a histogram.  
But unfortunately it breaks down with the following error -

root [1] [/Users/mansisaxena/build\_6.18/lib/libCling.so] cling\_runtime\_internal\_throwIfInvalidPointer (no debug info)

[] (no debug info)

[] (no debug info)

[/Users/mansisaxena/build\_6.18/lib/libCling.so] cling::IncrementalExecutor::executeWrapper(llvm::StringRef, cling::Value\*) const (no debug info)

[/Users/mansisaxena/build\_6.18/lib/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const\*, cling::Value\*) (no debug info)

[/Users/mansisaxena/build\_6.18/lib/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)

[/Users/mansisaxena/build\_6.18/lib/libCling.so] cling::Interpreter::process(std::\_\_1::basic\_string\<char, std::\_\_1::char\_traits, std::\_\_1::allocator \> const&, cling::Value\*, cling::Transaction\*\*, bool) (no debug info)

[/Users/mansisaxena/build\_6.18/lib/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value\*, bool) (no debug info)

[/Users/mansisaxena/build\_6.18/lib/libCling.so] HandleInterpreterException(cling::MetaProcessor\*, char const\*, cling::Interpreter::CompilationResult&, cling::Value\*) /Users/mansisaxena/Downloads/root-6.18.04/core/metacling/src/TCling.cxx:2161

[/Users/mansisaxena/build\_6.18/lib/libCling.so] TCling::ProcessLine(char const\*, TInterpreter::EErrorCode\*) /Users/mansisaxena/Downloads/root-6.18.04/core/metacling/src/TCling.cxx:2310

[/Users/mansisaxena/build\_6.18/lib/libCore.so] TROOT::ProcessLine(char const\*, int\*) /Users/mansisaxena/Downloads/root-6.18.04/core/base/src/TROOT.cxx:2371

[/Users/mansisaxena/build\_6.18/lib/libGpad.so] TPad::AutoExec() /Users/mansisaxena/Downloads/root-6.18.04/graf2d/gpad/src/TPad.cxx:455

[/Users/mansisaxena/build\_6.18/lib/libGpad.so] TCanvas::HandleInput(EEventType, int, int) /Users/mansisaxena/Downloads/root-6.18.04/graf2d/gpad/src/TCanvas.cxx:1284

[/Users/mansisaxena/build\_6.18/lib/libGui.so] TRootCanvas::HandleContainerButton(Event\_t\*) /Users/mansisaxena/Downloads/root-6.18.04/gui/gui/src/TRootCanvas.cxx:0

[/Users/mansisaxena/build\_6.18/lib/libGui.so] TRootContainer::HandleButton(Event\_t\*) /Users/mansisaxena/Downloads/root-6.18.04/gui/gui/src/TRootCanvas.cxx:296

[/Users/mansisaxena/build\_6.18/lib/libGui.so] TGFrame::HandleEvent(Event\_t\*) /Users/mansisaxena/Downloads/root-6.18.04/gui/gui/src/TGFrame.cxx:518

[/Users/mansisaxena/build\_6.18/lib/libGui.so] TGClient::HandleEvent(Event\_t\*) /Users/mansisaxena/Downloads/root-6.18.04/gui/gui/src/TGClient.cxx:0

[/Users/mansisaxena/build\_6.18/lib/libGui.so] TGClient::ProcessOneEvent() /Users/mansisaxena/Downloads/root-6.18.04/gui/gui/src/TGClient.cxx:653

[/Users/mansisaxena/build\_6.18/lib/libGui.so] TGInputHandler::Notify() /Users/mansisaxena/Downloads/root-6.18.04/gui/gui/src/TGClient.cxx:700

[/Users/mansisaxena/build\_6.18/lib/libCore.so] TMacOSXSystem::DispatchOneEvent(bool) /Users/mansisaxena/Downloads/root-6.18.04/core/macosx/src/TMacOSXSystem.mm:421

[/Users/mansisaxena/build\_6.18/lib/libCore.so] TSystem::InnerLoop() /Users/mansisaxena/Downloads/root-6.18.04/core/base/src/TSystem.cxx:413

[/Users/mansisaxena/build\_6.18/lib/libCore.so] TSystem::Run() /Users/mansisaxena/Downloads/root-6.18.04/core/base/src/TSystem.cxx:363

[/Users/mansisaxena/build\_6.18/lib/libCore.so] TApplication::Run(bool) /Users/mansisaxena/Downloads/root-6.18.04/core/base/src/TApplication.cxx:1179

[/Users/mansisaxena/build\_6.18/lib/libRint.so] TRint::Run(bool) /Users/mansisaxena/Downloads/root-6.18.04/core/rint/src/TRint.cxx:463

[/Users/mansisaxena/build\_6.18/bin/root.exe] main /Users/mansisaxena/Downloads/root-6.18.04/main/src/rmain.cxx:32

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

Error in : Trying to dereference null pointer or trying to call routine taking non-null arguments.

Execution of your code was aborted.

In file included from input\_line\_8:1:

**/Users/mansisaxena/57ZnBetaP/e18018/e18018\_home/Efficiency/Clover\_Analyzer.C:134:10:**  **warning:** **null passed to a callee that requires a non-null argument [-Wnonnull]**

if(h1-\>GetBinContent(k) \> py) {

**^~**

Any ideas please ???

Thanks  
Mansi

---

<div class="post-metadata">

**Author:** ![dwielane](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dwielane/32/12354_2.png) [@dwielane](https://root-forum.cern.ch/u/dwielane)\
**Post date:** [March 17, 2020, 9:45pm UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/2 "2020-03-17T21:45:41Z")

</div>

Hi,  
It’s hard to say without code, but for me seems that h1 is null or deleted.

---

<div class="post-metadata">

**Author:** ![Mansi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@Mansi](https://root-forum.cern.ch/u/Mansi)\
**Post date:** [March 17, 2020, 9:50pm UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/3 "2020-03-17T21:50:20Z")

</div>

[Clover\_Analyzer.C](https://root-forum.cern.ch/uploads/short-url/efePTU3f6ooUbJAOUHEruufmzSc.C) (20.5 KB)

Hey,  
I attached my script.

It might have few iterations, as I was trying with different things.

Mansi

---

<div class="post-metadata">

**Author:** ![dwielane](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dwielane/32/12354_2.png) [@dwielane](https://root-forum.cern.ch/u/dwielane)\
**Post date:** [March 17, 2020, 10:20pm UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/4 "2020-03-17T22:20:04Z")

</div>

Hi,  
it seems that the source of problem is that you use global h1 (line 32) in Position\_Selector, whereas you load only local h1 (declared at line 546)

---

<div class="post-metadata">

**Author:** ![Mansi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@Mansi](https://root-forum.cern.ch/u/Mansi)\
**Post date:** [March 17, 2020, 10:28pm UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/5 "2020-03-17T22:28:33Z")

</div>

Yeah,  
I noticed that now.  
Now, I can have the histogram plotted

But, still the fitting routine completely fails.

I attached the root file, just for checking.

Mansi[Test-for-Chain-003.root](https://root-forum.cern.ch/uploads/short-url/9OtL4oBFJrdxRLxD3bQCO5HX2I8.root) (602.7 KB)

---

<div class="post-metadata">

**Author:** ![Mansi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@Mansi](https://root-forum.cern.ch/u/Mansi)\
**Post date:** [March 17, 2020, 11:07pm UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/6 "2020-03-17T23:07:07Z")

</div>

The Fit fails at  
h1-\>GetBinContent(bin)

I can’t seem to understand why ?

Any ideas will be very helpful.

Thanks

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 18, 2020, 8:04am UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/7 "2020-03-18T08:04:46Z")

</div>

At least, remove “`TH1D *h1;`” from “`void Clover_Analyzer()`”.

---

<div class="post-metadata">

**Author:** ![Mansi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@Mansi](https://root-forum.cern.ch/u/Mansi)\
**Post date:** [March 18, 2020, 11:10am UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/8 "2020-03-18T11:10:10Z")

</div>

Thank you,

As suggested I removed the TH1D \*h1 from the main program.

But now it fails at  
h1-\>GetBinContent(bin);

please help.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [March 19, 2020, 8:47am UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/9 "2020-03-19T08:47:57Z")

</div>

Well, try to add “`gPad->Modifed(); gPad->Update();`” right before “`gPad->AddExec(...);`”.

[If you are using Mac OS X with Cocoa, maybe you need to add one or two calls “`gSystem->ProcessEvents();`” after each “`some_pad_or_canvas->Update();`”.](https://root-forum.cern.ch/t/canvas-will-not-show/27582/10)

If it doesn’t help, maybe @couet has some idea.

---

<div class="post-metadata">

**Author:** ![Mansi](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/9e8a1a/32.png) [@Mansi](https://root-forum.cern.ch/u/Mansi)\
**Post date:** [March 25, 2020, 1:27am UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/10 "2020-03-25T01:27:41Z")

</div>

Hi,

Thanks.  
I tried that.  
But it cannot evaluate h1-\>GetBinContent(bin) correctly.

Any ideas please ??

Mansi

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [April 8, 2020, 1:27am UTC](https://root-forum.cern.ch/t/fitting-histograms-null-pointer-error/38440/11 "2020-04-08T01:27:42Z")

</div>

Closed on April 8, 2020, 1:27am UTC

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