what i intended to do is to have one master fit function (in this case the fit_func_x
). For every new idx
at jdx=0
, i call the master fit function to do the fit, then clone the master function to proceed with the rest of jdx
. Therefore, we should see at every jdx=0
the pointer of the master function is being called, and another pointer for jdx = 2~4
(different for all idx
, 2nd output in my posting).
void debug(){
vector <int> Filters = {6,4}; //{1,2,3,4,6};
int Ni= Filters.size();
vector <double> EndPoints = {40,150,350,550,650};
int Nj = EndPoints.size();
// TF1* fit_func_x = new TF1(Form(func_name_x, muonID, 0, 0), func_2freq_constA_constW, ta, tb, init_vals_x.size());
TF1* fit_func_x = new TF1("func_00", "[0] + [1]*cos([2]*x + [3]) + [4]*cos([5]*x + [6])",30,40);
fit_func_x->SetNpx(500000);
fit_func_x->SetLineColor(2);
// GRid scan !
cout << " scanning x graphs ... " << endl; //debug
for(int idx=0; idx<Ni; idx++){ // loop through fittiing of a graph at particular pts/Tc. clone the func at the beginning (8pts)
int pts = int(48/Filters[idx]);
TF1* fit_func_x_working=nullptr;
cout << " ptr of master func (every muonID, we use a new func): "<< fit_func_x << endl; //debug
for(int jdx=0; jdx<Nj; jdx++){ // for the same graph of pts, we study the change in fitting range
double endpt = EndPoints[jdx];
// cout << Form(" %d_%.0f",pts,endpt)<< endl;
if(jdx == 0){
fit_func_x_working = fit_func_x;
};
// I skip fitting codes here ...
cout << Form(" %d_%.0f. name : %s ; ptr is: (1 != 2=3=4=...)",pts,endpt, fit_func_x_working->GetName()) << fit_func_x_working << endl; //debug
cout << " "<< fit_func_x_working->GetName() << endl; // debug
if(jdx == 0){ // clone the state after the first fit. we want to maintain the state of the master func to the next pts (idx)
fit_func_x_working = (TF1*) fit_func_x->Clone(); //Form("%d_%d",idx,jdx)
// cout << fit_func_x_working << endl;
};
};
delete fit_func_x_working;
}
}
with the last line delete fit_func_x_working
, i got the following which is not expected:
ptr of master func (every muonID, we use a new func): 0x55a09cb5f330
8_40. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09cb5f330
8_150. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09c5f9eb0
8_350. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09c5f9eb0
8_550. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09c5f9eb0
8_650. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09c5f9eb0
ptr of master func (every muonID, we use a new func): 0x55a09cb5f330
12_40. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09cb5f330
12_150. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09c5f9eb0
12_350. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09c5f9eb0
12_550. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09c5f9eb0
12_650. name : func_00 ; ptr is: (1 != 2=3=4=...)0x55a09c5f9eb0
when i commented that line, i got expected result instead,
ptr of master func (every muonID, we use a new func): 0x561560a74e00
8_40. name : func_00 ; ptr is: (1 != 2=3=4=...)0x561560a74e00
8_150. name : func_00 ; ptr is: (1 != 2=3=4=...)0x56156055eba0
8_350. name : func_00 ; ptr is: (1 != 2=3=4=...)0x56156055eba0
8_550. name : func_00 ; ptr is: (1 != 2=3=4=...)0x56156055eba0
8_650. name : func_00 ; ptr is: (1 != 2=3=4=...)0x56156055eba0
ptr of master func (every muonID, we use a new func): 0x561560a74e00
12_40. name : func_00 ; ptr is: (1 != 2=3=4=...)0x561560a74e00
12_150. name : func_00 ; ptr is: (1 != 2=3=4=...)0x561560ab4dd0
12_350. name : func_00 ; ptr is: (1 != 2=3=4=...)0x561560ab4dd0
12_550. name : func_00 ; ptr is: (1 != 2=3=4=...)0x561560ab4dd0
12_650. name : func_00 ; ptr is: (1 != 2=3=4=...)0x561560ab4dd0
please help. omit fit quality for now .
ROOT Version: 6.26.00 (conda)
Platform: centos7
Compiler: gcc9