Hello everyone!
I’m trying to use Simulated Annealing algorithm on Ubuntu, ROOT 6.12/06, and I have a few questions about it.

1. Algorithm works and gives good result, but ROOT crashes without any error after finish, and I can’t understand why. What can cause this kind of a problem?
2. It seems that SetMaxFunctionCalls and SetMaxIterations doesn’t affect anything. Algorithm always works slow and does a lot of iterations. What am I doing wrong?
3. I don’t really understand how magnitude of Tolerance affects minimization. Where I can read about it?
4. I don’t need precise result of minimization, my function should be below some known value. Can I set some kind of threshold for minimization?
5. I set integer steps for some of my variables, but it still uses some strange double type steps. Where I can read about how it works?
This how I set parameters of minimizer and function, full code is pretty big and confusing.
NumMin.C (2.2 KB)

When I run your macro I get some C++ errors.
Do you see the same ?

``````root [0]
Processing NumMin.C...
In file included from input_line_11:1:
vector <peak> f_peaks;
^
vector <peak> f_peaks;
^
*hist_smooth =  Smoothing(hist, par[0], xmin, xmax);
^
Background(hist_smooth, par[1], par[2], xmin, xmax);
^
Deconvolution(hist_smooth,  par[3], par[4]*100, xmin, xmax);
^
f_peaks =  find_peaks (hist_smooth, diff.size() + 1,par[5], par[6]/100, xmin, xmax);
^
ROOT::Math::Functor funct(peak,7);
^
void all {
^
NumMin (); //this function works, results are printed, then ROOT crashes
^
}
^
;
``````

This is full version of my script. File output.root is about 1Gb and I cant upload it here.
indent2.C (29.6 KB)

What i mean is that in the first example you posted there is some C++ mistakes. Do you also get these errors when you run it ?

Yes, I get them. I wanted to show part with minimization algorithm, without redundant details.

How are we supposed to run the indent2.C script ?

In indent2.C call function find_peak(), it should recreate the problem.

running your code in debug mode I get:

``````root [0] .L indent2.C
root [1] find_peak()
Warning in <TFile::Init>: file smooth.root probably not closed, cannot read free segments
Warning in <TFile::Init>: file smooth.root probably not closed, trying to recover
Info in <TFile::Recover>: smooth.root, recovered key TH1F:front_no_MWPC_0 at address 218
Info in <TFile::Recover>: smooth.root, recovered key TH1F:front_0_sm_3_b_12_9_dec_2_10_pf_11_0.001_1 at address 2898
Warning in <TFile::Init>: successfully recovered 2 keys
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
test00
test01
test02
test03
0.414183
test03
15.9431
test03
2.3405
test03
2.90783
test03
1.35005
test03
1.35549
test03
0.0926126
test04
test1
test2
[/Users/couet/git/roottrunk-bin/lib/libCling.so] TCling__PrintStackTrace /Users/couet/git/roottrunk/core/metacling/src/TCling.cxx:359
[/Users/couet/git/roottrunk-bin/lib/libCling.so] TClingCallbacks::PrintStackTrace() /Users/couet/git/roottrunk/core/metacling/src/TClingCallbacks.cxx:808
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling::MultiplexInterpreterCallbacks::PrintStackTrace() (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling_runtime_internal_throwIfInvalidPointer (no debug info)
[<unknown binary>] (no debug info)
[<unknown binary>] (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] cling::Interpreter::RunFunction(clang::FunctionDecl const*, cling::Value*) (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] 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/couet/git/roottrunk-bin/lib/libCling.so] 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/couet/git/roottrunk-bin/lib/libCling.so] cling::MetaProcessor::process(llvm::StringRef, cling::Interpreter::CompilationResult&, cling::Value*, bool) (no debug info)
[/Users/couet/git/roottrunk-bin/lib/libCling.so] HandleInterpreterException(cling::MetaProcessor*, char const*, cling::Interpreter::CompilationResult&, cling::Value*) /Users/couet/git/roottrunk/core/metacling/src/TCling.cxx:2145
[/Users/couet/git/roottrunk-bin/lib/libCling.so] TCling::ProcessLine(char const*, TInterpreter::EErrorCode*) /Users/couet/git/roottrunk/core/metacling/src/TCling.cxx:2303
[/Users/couet/git/roottrunk-bin/lib/libCore.so] TApplication::ProcessLine(char const*, bool, int*) /Users/couet/git/roottrunk/core/base/src/TApplication.cxx:1031
[/Users/couet/git/roottrunk-bin/lib/libRint.so] TRint::ProcessLineNr(char const*, char const*, int*) /Users/couet/git/roottrunk/core/rint/src/TRint.cxx:746
[/Users/couet/git/roottrunk-bin/lib/libRint.so] TRint::HandleTermInput() /Users/couet/git/roottrunk/core/rint/src/TRint.cxx:607
[/Users/couet/git/roottrunk-bin/lib/libRint.so] TTermInputHandler::Notify() /Users/couet/git/roottrunk/core/rint/src/TRint.cxx:131
[/Users/couet/git/roottrunk-bin/lib/libCore.so] TUnixSystem::CheckDescriptors() /Users/couet/git/roottrunk/core/unix/src/TUnixSystem.cxx:1322
[/Users/couet/git/roottrunk-bin/lib/libCore.so] TMacOSXSystem::DispatchOneEvent(bool) /Users/couet/git/roottrunk/core/macosx/src/TMacOSXSystem.mm:378
[/Users/couet/git/roottrunk-bin/lib/libCore.so] TSystem::InnerLoop() /Users/couet/git/roottrunk/core/base/src/TSystem.cxx:413
[/Users/couet/git/roottrunk-bin/lib/libCore.so] TSystem::Run() /Users/couet/git/roottrunk/core/base/src/TSystem.cxx:362
[/Users/couet/git/roottrunk-bin/lib/libCore.so] TApplication::Run(bool) /Users/couet/git/roottrunk/core/base/src/TApplication.cxx:1184
[/Users/couet/git/roottrunk-bin/lib/libRint.so] TRint::Run(bool) /Users/couet/git/roottrunk/core/rint/src/TRint.cxx:460
[/Users/couet/git/roottrunk-bin/bin/root.exe] main /Users/couet/git/roottrunk/main/src/rmain.cxx:32
[/usr/lib/system/libdyld.dylib] start (no debug info)
[<unknown binary>] (no debug info)
Error in <HandleInterpreterException>: Trying to access a pointer that points to an invalid memory address..
Execution of your code was aborted.
In file included from input_line_11:1:
*front_smooth[1] = peak.smooth;
^~~~~~~~~~~~~~~
root [2]

``````
1 Like

Hmmm, I get something like this:

``````root [0] .L indent2.C
root [1] find_peak();
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
test00
test01
test02
test03
0.414183
test03
15.9431
test03
2.3405
test03
2.90783
test03
1.35005
test03
1.35549
test03
0.0926126
test04
dmitriy@dmitriy-ASUS:~/Progs0106/analysis p2\$
``````

What can cause such behavior?

Okay, reinstallation solved my problem with crash, but I still don’t understand how to control this algorithm. It looks like setting MaxFunctionCalls, MaxIteration or Tolerance doesn’t affect process of minimization.

1 Like

Well, ROOT told you that you had a problem in your code:

``````Users/couet/Downloads/indent2.C:922:4: warning: invalid memory pointer passed to a callee:
*front_smooth[1] = peak.smooth;
^~~~~~~~~~~~~~~
``````

Not sure how reinstalling ROOT would fix that?

Regarding the minimization: which problem are you trying to solve here?