Cycle "for" creates a break

Hello,

I’m creating a script where I need to execute one macro many times (let’s say 100 times). After each execution I take some values from the macro. I’ve used for cycle:

for(Int_t ha=0; ha < 2*step; ha++) { a=(a1-a1*change/100+ha*rstep); ofstream aha ("FitTemplates.C", ios::in); aha.seekp(1489, ios::beg); aha<<a; aha.close(); gROOT->Macro("FitTemplates.C"); ofstream zapis ("Preplot.csv", ios::app); zapis<<alphafix<<","<<vysl<<","<<nex<<endl; zapis.close(); }
There is no problem in the code, it can run perfectly for the first time, but that’s it. When it should run for 2nd time it gives me a break:

[code]jan@Honzuv-PC:~/Documents/pT$ root -l -b exper.C
root [0]
Processing exper.C…
What should be the difference of alpha? (in %)
10
How many steps should be made?
4
What channel should be used? (0= -2.7<y<-1.9 or 1= -1.9<y<-1.2)
0

RooFit v3.59 – Developed by Wouter Verkerke and David Kirkby
Copyright © 2000-2013 NIKHEF, University of California & Stanford University
All rights reserved, please read http://roofit.sourceforge.net/license.txt

Warning: Automatic variable fix is allocated FitTemplates.C:51:
I-FitTemplates, using binsiz = 0.15 , nbinspT = 13 and ptmax = 1.95
[#1] INFO:DataHandling – RooDataSet::read: reading file TXT/esd/ver1/pTyM_pPb_esd.txt
[#0] ERROR:DataHandling – RooDataSet::read(static): read error at line 1819
[#1] INFO:DataHandling – RooDataSet::read: read 1155 events (ignored 663 out of range events)
[#1] INFO:DataHandling – RooDataSet::read: reading file TXT/esd/ver1/pTyM_pPb_esd_ls.txt
[#0] ERROR:DataHandling – RooDataSet::read(static): read error at line 481
[#1] INFO:DataHandling – RooDataSet::read: read 272 events (ignored 208 out of range events)
[#1] INFO:Minization – RooMinuit::optimizeConst: activating const optimization
[#1] INFO:Minization – The following expressions will be evaluated in cache-and-track mode: (cb,Bkgd)


** 13 **MIGRAD 3500 1


FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
START MIGRAD MINIMIZATION. STRATEGY 1. CONVERGENCE WHEN EDM .LT. 1.00e-03
FCN=-2547.47 FROM MIGRAD STATUS=INITIATE 96 CALLS 97 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 alpha 8.59807e-01 constant
2 lambda -1.00000e+00 5.00000e-01 0.00000e+00 -2.54323e+02
3 m0 3.09692e+00 1.00000e-02 0.00000e+00 -2.03315e+01
4 n 3.68212e-01 2.00000e+00 0.00000e+00 -8.41974e+01
5 nBG 1.11600e+02 5.58000e+01 0.00000e+00 -1.47111e+02
6 nCB 4.46400e+02 5.58000e+01 0.00000e+00 3.67767e+01
7 sig 4.97710e-02 1.90000e-02 -3.54103e-01 1.26222e-01
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=-2656.8 FROM MIGRAD STATUS=CONVERGED 441 CALLS 442 TOTAL
EDM=6.12553e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 alpha 8.59807e-01 constant
2 lambda -9.32331e-01 6.91205e-02 8.45179e-04 1.94679e-01
3 m0 3.10694e+00 4.32685e-03 2.76038e-03 -4.75899e-02
4 n 1.45651e+01 1.12099e+01 8.82613e-02 -1.53262e-03
5 nBG 3.99593e+02 2.13583e+01 2.93510e-03 -6.06329e-03
6 nCB 1.58410e+02 1.46967e+01 1.96517e-03 1.99423e-02
7 sig 3.47453e-02 3.52132e-03 1.62457e-03 2.33885e-03
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 6 ERR DEF=0.5
4.779e-03 -4.569e-08 -5.879e-03 3.745e-02 -3.745e-02 -5.840e-06
-4.569e-08 1.877e-05 -5.206e-02 -1.474e-04 1.527e-04 -6.469e-06
-5.879e-03 -5.206e-02 1.162e+03 1.123e+02 -1.126e+02 5.356e-02
3.745e-02 -1.474e-04 1.123e+02 4.573e+02 -5.768e+01 -4.230e-03
-3.745e-02 1.527e-04 -1.126e+02 -5.768e+01 2.162e+02 4.230e-03
-5.840e-06 -6.469e-06 5.356e-02 -4.230e-03 4.230e-03 1.241e-05
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 2 3 4 5 6 7
2 0.04747 1.000 -0.000 -0.002 0.025 -0.037 -0.024
3 0.46199 -0.000 1.000 -0.352 -0.002 0.002 -0.424
4 0.55980 -0.002 -0.352 1.000 0.154 -0.225 0.446
5 0.24407 0.025 -0.002 0.154 1.000 -0.183 -0.056
6 0.32861 -0.037 0.002 -0.225 -0.183 1.000 0.082
7 0.56066 -0.024 -0.424 0.446 -0.056 0.082 1.000


** 18 **HESSE 3500


FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=-2656.8 FROM HESSE STATUS=OK 40 CALLS 483 TOTAL
EDM=6.25753e-05 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 alpha 8.59807e-01 constant
2 lambda -9.32331e-01 6.91216e-02 1.69036e-04 9.50204e-01
3 m0 3.10694e+00 4.40439e-03 5.52076e-04 1.39311e-01
4 n 1.45651e+01 1.03041e+01 3.53045e-03 4.74073e-01
5 nBG 3.99593e+02 2.14323e+01 1.17404e-04 4.46968e-01
6 nCB 1.58410e+02 1.48010e+01 3.93035e-04 -4.46956e-01
7 sig 3.47453e-02 3.62116e-03 6.49830e-05 -8.32361e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 6 ERR DEF=0.5
4.779e-03 8.844e-08 -7.710e-03 3.748e-02 -3.747e-02 -6.021e-06
8.844e-08 1.945e-05 -6.183e-02 -1.516e-03 1.517e-03 -7.180e-06
-7.710e-03 -6.183e-02 1.281e+03 1.333e+02 -1.334e+02 6.363e-02
3.748e-02 -1.516e-03 1.333e+02 4.605e+02 -6.088e+01 -2.848e-03
-3.747e-02 1.517e-03 -1.334e+02 -6.088e+01 2.193e+02 2.847e-03
-6.021e-06 -7.180e-06 6.363e-02 -2.848e-03 2.847e-03 1.313e-05
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 2 3 4 5 6 7
2 0.04783 1.000 0.000 -0.003 0.025 -0.037 -0.024
3 0.49088 0.000 1.000 -0.392 -0.016 0.023 -0.449
4 0.60685 -0.003 -0.392 1.000 0.174 -0.252 0.491
5 0.25704 0.025 -0.016 0.174 1.000 -0.192 -0.037
6 0.34718 -0.037 0.023 -0.252 -0.192 1.000 0.053
7 0.59302 -0.024 -0.449 0.491 -0.037 0.053 1.000
[#1] INFO:Minization – RooMinuit::optimizeConst: deactivating const optimization
[#1] INFO:Eval – RooRealVar::setRange(m) new range named ‘JPsiMassRange’ created with bounds [2.9,3.2]
######################
N(J/psi): 157 +/- 15 , Nexp: 45 +/- 2
Alpha: 0.859807 +/- 0 , M(J/psi): 3.10694 +/- 0.00440439 , Sigma: 0.0347453 +/- 0.00362116
n: 14.5651 +/- 10.3041 , Lambda: -0.932331 +/- 0.0691216
######################
I-FitTemplates, used binsiz = 0.15 , nbinspT = 13 and ptmax = 1.95
Warning in TCanvas::Constructor: Deleting canvas with same name: c3
Warning: Automatic variable fix is allocated FitTemplates.C:51:
I-FitTemplates, using binsiz = 0.15 , nbinspT = 13 and ptmax = 1.95
[#1] INFO:DataHandling – RooDataSet::read: reading file TXT/esd/ver1/pTyM_pPb_esd.txt
[#0] ERROR:DataHandling – RooDataSet::read(static): read error at line 1819
[#1] INFO:DataHandling – RooDataSet::read: read 1155 events (ignored 663 out of range events)
[#1] INFO:DataHandling – RooDataSet::read: reading file TXT/esd/ver1/pTyM_pPb_esd_ls.txt
[#0] ERROR:DataHandling – RooDataSet::read(static): read error at line 481
[#1] INFO:DataHandling – RooDataSet::read: read 272 events (ignored 208 out of range events)
[#1] INFO:Minization – RooMinuit::optimizeConst: activating const optimization
[#1] INFO:Minization – The following expressions will be evaluated in cache-and-track mode: (cb,Bkgd)


** 13 **MIGRAD 3500 1


FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
START MIGRAD MINIMIZATION. STRATEGY 1. CONVERGENCE WHEN EDM .LT. 1.00e-03
FCN=-2549.59 FROM MIGRAD STATUS=INITIATE 92 CALLS 93 TOTAL
EDM= unknown STRATEGY= 1 NO ERROR MATRIX
EXT PARAMETER CURRENT GUESS STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 alpha 8.83697e-01 constant
2 lambda -1.00000e+00 5.00000e-01 0.00000e+00 -2.46699e+02
3 m0 3.09692e+00 1.00000e-02 0.00000e+00 -2.25254e+01
4 n 4.43976e-01 2.00000e+00 0.00000e+00 -3.59459e+00
5 nBG 1.11600e+02 5.58000e+01 0.00000e+00 -1.55540e+02
6 nCB 4.46400e+02 5.58000e+01 0.00000e+00 3.88840e+01
7 sig 4.73424e-02 1.90000e-02 -3.85888e-01 1.70725e+00
ERR DEF= 0.5
MIGRAD MINIMIZATION HAS CONVERGED.
MIGRAD WILL VERIFY CONVERGENCE AND ERROR MATRIX.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=-2656.76 FROM MIGRAD STATUS=CONVERGED 428 CALLS 429 TOTAL
EDM=5.03701e-06 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 alpha 8.83697e-01 constant
2 lambda -9.32724e-01 6.91216e-02 8.45251e-04 -8.34251e-02
3 m0 3.10674e+00 4.36261e-03 2.76681e-03 -1.00812e-02
4 n 1.22024e+01 1.47057e+01 6.99439e-02 -3.21206e-04
5 nBG 3.99620e+02 2.13948e+01 2.93630e-03 1.37421e-03
6 nCB 1.58376e+02 1.47463e+01 1.96545e-03 -1.01838e-02
7 sig 3.48926e-02 3.56896e-03 1.62912e-03 -6.77225e-03
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 6 ERR DEF=0.5
4.779e-03 1.402e-07 -6.083e-03 3.719e-02 -3.719e-02 -5.993e-06
1.402e-07 1.908e-05 -3.964e-02 -5.562e-04 5.627e-04 -6.765e-06
-6.083e-03 -3.964e-02 6.229e+02 8.721e+01 -8.744e+01 4.079e-02
3.719e-02 -5.562e-04 8.721e+01 4.588e+02 -5.919e+01 -3.769e-03
-3.719e-02 5.627e-04 -8.744e+01 -5.919e+01 2.177e+02 3.767e-03
-5.993e-06 -6.765e-06 4.079e-02 -3.769e-03 3.767e-03 1.275e-05
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 2 3 4 5 6 7
2 0.04750 1.000 0.000 -0.004 0.025 -0.036 -0.024
3 0.47230 0.000 1.000 -0.364 -0.006 0.009 -0.434
4 0.57481 -0.004 -0.364 1.000 0.163 -0.237 0.458
5 0.25003 0.025 -0.006 0.163 1.000 -0.187 -0.049
6 0.33734 -0.036 0.009 -0.237 -0.187 1.000 0.071
7 0.57052 -0.024 -0.434 0.458 -0.049 0.071 1.000


** 18 **HESSE 3500


FIRST CALL TO USER FUNCTION AT NEW START POINT, WITH IFLAG=4.
COVARIANCE MATRIX CALCULATED SUCCESSFULLY
FCN=-2656.76 FROM HESSE STATUS=OK 40 CALLS 470 TOTAL
EDM=5.02966e-06 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER INTERNAL INTERNAL
NO. NAME VALUE ERROR STEP SIZE VALUE
1 alpha 8.83697e-01 constant
2 lambda -9.32724e-01 6.91229e-02 1.69050e-04 9.50068e-01
3 m0 3.10674e+00 4.43173e-03 5.53361e-04 1.35310e-01
4 n 1.22024e+01 1.43075e+01 2.79776e-03 2.22059e-01
5 nBG 3.99620e+02 2.14647e+01 1.17452e-04 4.47073e-01
6 nCB 1.58376e+02 1.48443e+01 3.93089e-04 -4.47090e-01
7 sig 3.48926e-02 3.65741e-03 6.51649e-05 -8.30062e-01
ERR DEF= 0.5
EXTERNAL ERROR MATRIX. NDIM= 25 NPAR= 6 ERR DEF=0.5
4.779e-03 3.063e-07 -7.783e-03 3.714e-02 -3.713e-02 -6.207e-06
3.063e-07 1.969e-05 -4.586e-02 -1.806e-03 1.807e-03 -7.404e-06
-7.783e-03 -4.586e-02 6.771e+02 1.010e+02 -1.010e+02 4.720e-02
3.714e-02 -1.806e-03 1.010e+02 4.619e+02 -6.222e+01 -2.507e-03
-3.713e-02 1.807e-03 -1.010e+02 -6.222e+01 2.206e+02 2.506e-03
-6.207e-06 -7.404e-06 4.720e-02 -2.507e-03 2.506e-03 1.339e-05
PARAMETER CORRELATION COEFFICIENTS
NO. GLOBAL 2 3 4 5 6 7
2 0.04789 1.000 0.001 -0.004 0.025 -0.036 -0.025
3 0.49717 0.001 1.000 -0.397 -0.019 0.027 -0.456
4 0.61439 -0.004 -0.397 1.000 0.181 -0.261 0.496
5 0.26196 0.025 -0.019 0.181 1.000 -0.195 -0.032
6 0.35422 -0.036 0.027 -0.261 -0.195 1.000 0.046
7 0.59813 -0.025 -0.456 0.496 -0.032 0.046 1.000
[#1] INFO:Minization – RooMinuit::optimizeConst: deactivating const optimization
[#1] INFO:Eval – RooRealVar::setRange(m) new range named ‘JPsiMassRange’ created with bounds [2.9,3.2]
######################
N(J/psi): 156 +/- 15 , Nexp: 45 +/- 2
Alpha: 0.883697 +/- 0 , M(J/psi): 3.10674 +/- 0.00443173 , Sigma: 0.0348926 +/- 0.00365741
n: 12.2024 +/- 14.3075 , Lambda: -0.932724 +/- 0.0691229
######################
I-FitTemplates, used binsiz = 0.15 , nbinspT = 13 and ptmax = 1.95

*** Break *** segmentation violation

===========================================================
There was a crash.
This is the entire stack trace of all threads:

#0 0x00007f947e86d99c in __libc_waitpid (pid=9810, stat_loc=stat_loc
entry=0x7fffc93a89c0, options=options
entry=0) at …/sysdeps/unix/sysv/linux/waitpid.c:31
#1 0x00007f947e7f25a2 in do_system (line=) at …/sysdeps/posix/system.c:148
#2 0x00007f947f6e63a3 in TUnixSystem::StackTrace() () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#3 0x00007f947f6e807c in TUnixSystem::DispatchSignals(ESignals) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#4
#5 0x00007f947d8eac64 in G__LD_p0_double () from /usr/lib/x86_64-linux-gnu/libCint.so.5.34
#6 0x00007f947d81be49 in G__exec_asm () from /usr/lib/x86_64-linux-gnu/libCint.so.5.34
#7 0x00007f947d8e0df8 in ?? () from /usr/lib/x86_64-linux-gnu/libCint.so.5.34
#8 0x00007f947d8dcc38 in G__exec_statement () from /usr/lib/x86_64-linux-gnu/libCint.so.5.34
#9 0x00007f947d83f651 in ?? () from /usr/lib/x86_64-linux-gnu/libCint.so.5.34
#10 0x00007f947d840bbb in G__exec_tempfile () from /usr/lib/x86_64-linux-gnu/libCint.so.5.34
#11 0x00007f947d8ea019 in G__process_cmd () from /usr/lib/x86_64-linux-gnu/libCint.so.5.34
#12 0x00007f947f6af830 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#13 0x00007f947f6a884b in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#14 0x00007f947f618b34 in TApplication::ExecuteFile(char const*, int*, bool) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#15 0x00007f947f618012 in TApplication::ProcessLine(char const*, bool, int*) () from /usr/lib/x86_64-linux-gnu/libCore.so.5.34
#16 0x00007f947f2ba36d in TRint::Run(bool) () from /usr/lib/x86_64-linux-gnu/libRint.so.5.34
#17 0x0000000000400fec in main ()

The crash is most likely caused by a problem in your script.
Try to compile it (.L myscript.C+g) and fix any errors.
If that does not help then please submit a bug report at
http://root.cern.ch/bugs. Please post the ENTIRE stack trace
from above as an attachment in addition to anything else
that might help us fixing this issue.
[/code]

Can you please tell me what’s wrong?
Thank you very much
Jan

Hi Jan,

sometimes running repeatedly the same macro root session can be tricky.
In your case, what I would suggest is to wrap FitTemplates.C in a function with a as parameter and to call the function n times.

Cheers,
Danilo

Thank you for your help, but I don’t understand what you mean :frowning:
What function can it be? the “a” is a variable used in FitTemplates, that I overwrite everytime I run the macro.
Thank you very much
Jan

I’ve found out that it’s not the FitTemplates.C that creates the problem. If I remove the ofstream zapis, it can run many times. So can someone help me? I really don’t know what to do :frowning:

Thank you very much
Jan

Hi,

you should transform the code in the macro in a function with one parameter, a, and then call this function from within the loop rather than changing the code and re-interpret it each time.