I have two TH1D. When I Fit one with a function, there is no problem and I can show the TH1D together with the Fit function. But when I Fit a second graph, there comes an error and the program is quitted. here is what I write :
TH1D* result1; //get from a function
TCanvas* c1 = new TCanvas(“c”, “c”);
c1->cd(1);
c1->cd(2);
c1->Show();
 
             
            
              
            
           
          
            
              
                couet  
              
                  
                    December 14, 2023,  1:51pm
                   
                  2 
               
             
            
              Welcome to the ROOT forum.
Which error message to you get ?
I am sure @moneta  can help
             
            
              
            
           
          
            
            
              Hello 
notice that I have written on the Console the result of the second Fit, before it leaves …
             
            
              
            
           
          
            
              
                couet  
              
                  
                    December 14, 2023,  2:00pm
                   
                  4 
               
             
            
              Can you provide a script we can run in ROOT ?
             
            
              
            
           
          
            
            
              Here it is !
int taille_min=5;
 
if you want you can fill it :
for (int i(taille_min); i <= taille_max; ++i) {
 
and you have to launch an application
TApplication app(“lifting square_wave”, &argc, argv);
 
             
            
              
            
           
          
            
              
                couet  
                
                  
                    December 14, 2023,  2:45pm
                   
                  6 
               
             
            
              fitsame.C :double fit1 (double *x,double *p) {
   return x[0] * x[0] * p[0];
}
void fitsame(){
   int taille_min=5;
   int taille_max=100;
   TH1D* result1 = new TH1D("Kemeny","Kemeny", taille_max - taille_min + 1, (double)taille_min, (double)taille_max + 1.);
   TH1D* result2 = new TH1D("inverse_gap","inverse_gap", taille_max - taille_min + 1, (double)taille_min, (double)taille_max + 1.);
   for (int i(taille_min); i <= taille_max; ++i) {
      result2->Fill((double)i + 0.5, 1.3 * ((double) (i * i)) );
      result1->Fill((double)i + 0.5, 1.7 * ((double) (i * i)) );
   }
   TCanvas* c1 = new TCanvas("c", "c");
   c1->Divide(2, 1);
   c1->cd(1);
   TF1* fonction = new TF1("x_2", fit1, (double)taille_min, (double)taille_max + 1.,1);
   result1->Fit(fonction, "", "", (double)taille_min, (double)taille_max + 1.);
   result1->Draw("HIST");
   fonction->Draw("SAME");
   c1->cd(2);
   TF1* fonction2= new TF1("x_3", fit1, (double)taille_min, (double)taille_max + 1.,1);
   result2->Fit(fonction2, "", "", (double)taille_min, (double)taille_max + 1.);
   result2->Draw("HIST");
   fonction2->Draw("SAME");
}
$ root
root [0] .x fitsame.C
****************************************
Minimizer is Minuit2 / Migrad
Chi2                      =     0.112309
NDf                       =           95
Edm                       =   1.0364e-16
NCalls                    =           13
p0                        =      1.64395   +/-   0.167883    
****************************************
Minimizer is Minuit2 / Migrad
Chi2                      =     0.112309
NDf                       =           95
Edm                       =  4.38049e-17
NCalls                    =           13
p0                        =      1.25714   +/-   0.128381    
root [1] 
             
            
              
            
           
          
            
            
              
at home it doesn’t work 
             
            
              
            
           
          
            
              
                couet  
              
                  
                    December 14, 2023,  3:08pm
                   
                  8 
               
             
            
              I tried several time, for me this works. From the 2nd time I get Warnings saying that le histograms already exist, but that’s normal.
Can you copy/paste the messages you get ?
             
            
              
            
           
          
            
              
                couet  
              
                  
                    December 14, 2023,  3:15pm
                   
                  9 
               
             
            
              We tried on Windows, it is also working. We only get the warnings.
             
            
              
            
           
          
            
            
              Hello !
             
            
              1 Like 
            
            
           
          
            
              
                system  
              
                  
                    December 28, 2023,  3:46pm
                   
                  11 
               
             
            
              This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.