Re: Single call of procedure works while recurring call in loop returns error.

From: Rene Brun <Rene.Brun_at_cern.ch>
Date: Sat, 27 Feb 2010 05:21:50 +0100


Hi Stephan,

I cannot reproduce the problem. Executing your script, I get: root [0] .L henry.C
root [1] henry()
initial chi2/Ndf: 528.202

Chi2/Ndf 528.202
Chi2/Ndf 528.202
Chi2/Ndf 528.202
Chi2/Ndf 528.202
Chi2/Ndf 528.202
Chi2/Ndf 528.202
Chi2/Ndf 528.202
Chi2/Ndf 528.202
Chi2/Ndf 528.202
Chi2/Ndf 528.202

root [2] .q

I tried too with ACLIC and get the same result. To use it with ACLIC, I had to make 2 small changes in the includes, see attachment.

Rene

Stephan Zimmer wrote:
> Oh sorry for that.
> The script to call is henry.C and the dat-file henry.dat (see
> attachment) I just wonder whether I did something stupid in my code.
> Thank you very much.
> The same behavior happens under 5.18/5.22/5.26
> Cheers, Stephan
>
> On 2/27/2010 5:01 AM, Rene Brun wrote:
>
>> Could you provide a complete script and the data file to execute it?
>>
>> Rene
>>
>> Stephan Zimmer wrote:
>>
>>> Hi ROOTers,
>>> I wonder if someone of you might understand why the following code
>>> crashes...
>>>
>>> double CotTheta(const double x_i, const double alpha[2]){
>>> // returns the estimate y(x_i) based on the theoretical distribution
>>> return alpha[0]*x_i - alpha[1]*pow(x_i,-1);
>>> }
>>>
>>> double CalculateChi2(const vector<double> x, const vector<double> y,
>>> const vect\
>>> or<double> yError, const double alpha[2]){
>>> // returns the chi2 value for a given set of parameters
>>> double sumchi2=0;
>>> for (unsigned int i = 0; i<x.size(); i++){
>>> sumchi2=sumchi2+(pow(yError[i],-2)*pow(y[i]-CotTheta(x[i],alpha),2));
>>> }
>>> return sumchi2;
>>> }
>>>
>>> void littleHenry(){
>>>
>>> TVirtualFitter::SetDefaultFitter("Minuit");
>>>
>>> // readout henry.dat
>>> vector<double> xVec;
>>> vector<double> xEVec;
>>> vector<double> yVec;
>>> vector<double> yEVec;
>>> double x(0),y(0),xE(0), yE(0);
>>> double output[3];
>>> FILE *data;
>>> char datafname[]="henry.dat";
>>>
>>> data = fopen(datafname,"r");
>>> while (fscanf(data, "%lf %lf %lf %lf",&x,&xE,&y,&yE) != EOF) {
>>> xVec.push_back(x);
>>> yVec.push_back(y);
>>> xEVec.push_back(xE);
>>> yEVec.push_back(yE);
>>> }
>>> double alpha[2];
>>> double chi2;
>>> alpha[0]=1e-4;
>>> alpha[1]=1e2;
>>> CalculateChi2(xVec,yVec,yEVec,alpha);
>>> --> that works...
>>>
>>>
>>> However, once I want to execute the routine CalculateChi2 more than
>>> twice, by putting it inside a loop I get a weird error message:
>>> for (int i = 0; i<5; i++){
>>> chi2=CalculateChi2(xVec,yVec,yEVec,alpha);
>>> cout << "Chi2/Ndf " << chi2/xVec.size() << endl;
>>> }
>>> ----> OUTPUT <-------
>>> Processing littleHenry.C...
>>> Chi2/Ndf 528.202
>>> Chi2/Ndf 528.202
>>> Error: Can't call vector<double,allocator<double>
>>>
>>>
>>>> ::vector<double,allocator<double> >((class
>>>>
>>>>
>>> vector<double>***&)148530456) in current scope littleHenry.C:34:
>>> Possible candidates are...
>>> (in vector<double,allocator<double> >)
>>> vector.dll -1:-1 0 public: vector<double,allocator<double> >
>>> vector<double,allocator<double> >::vector<double,allocator<double>
>>>
>>>> (void);
>>>>
>>> vector.dll -1:-1 0 public: vector<double,allocator<double> >
>>> vector<double,allocator<double> >::vector<double,allocator<double>
>>>
>>>
>>>> (vector<double,allocator<double> >::size_type n,const double&
>>>>
>>>>
>>> value=double());
>>> vector.dll -1:-1 0 public: vector<double,allocator<double> >
>>> vector<double,allocator<double> >::vector<double,allocator<double>
>>>
>>>
>>>> (const vector<double,allocator<double> >& x);
>>>>
>>>>
>>> vector.dll -1:-1 0 public: vector<double,allocator<double> >
>>> vector<double,allocator<double> >::vector<double,allocator<double>
>>>
>>>
>>>> (vector<double,allocator<double> >::const_iterator
>>>>
>>>>
>>> first,vector<double,allocator<double> >::const_iterator last);
>>> *** Interpreter error recovered ***
>>>
>>> I wonder if I somehow run out of the boundaries of the vector but that
>>> should not happen as they are not touched and treated as constants...
>>> Any ideas?
>>>
>>> Cheers,
>>> Stephan
>>>
>>>
>>>

Received on Sat Feb 27 2010 - 05:22:11 CET

This archive was generated by hypermail 2.2.0 : Sat Feb 27 2010 - 23:50:01 CET