Fit invariant mass distribution with Breit-Wigner Function

Hi Rooters,

I’m trying to fit a mass distribution with this code:

Double_t mybw(Double_t* x, Double_t* par)
{
/*Definisco 2/pi */
  Double_t arg1 = 14.0/22.0;
/*Definisco i parametri Gamma[1] e Massa[2]*/
  Double_t arg2 = par[1]*par[1]*par[2]*par[2];
/*Definisco la funzione di Breit-Wigner*/
  Double_t arg3 = ((x[0]*x[0]) - (par[2]*par[2]))*((x[0]*x[0]) - (par[2]*par[2]));
  Double_t arg4 = x[0]*x[0]*x[0]*x[0]*((par[1]*par[1])/(par[2]*par[2]));
  return par[0]*arg1*arg2/(arg3 + arg4);
}

void massa_invariante() {
/*Creo un TH1F, istogramma monodimensionale, verrà successivamente riempito tramite valori di massa invariante*/    
    TH1F mass_inv("Note","Distribuzione in massa invariante del processo K0s#rightarrow #pi^{0}#pi^{0}", 150,0.4,.9);
/*Genero un numero n di eventi, ogni evento presenterà k particelle*/
    for (Int_t n=0;n<10;n++){
/*Definisco un numero k di TLorentzVector per ogni particella contenuta in un evento*/   
		Int_t k=1000; 	
        TLorentzVector beam[k];
/*Imposto in modo random le componenti di questi quadri-vettori*/
        for (Int_t i=0; i<k; i++) {
/*Definisce il range di pseudorapidità*/
            Double_t eta = gRandom->Uniform(-1,1);
/*Setto l'angolo in modo random, voglio che il decadimento sia isotropo*/
            Double_t phi = gRandom->Uniform(0,TMath::Pi()*2); 
/*Imposto un impulso trasverso in modo random secondo un'esponenziale con slope -100 MeV*/
            Double_t pt = gRandom->Exp(-100);
/*Definisco le masse delle particelle che voglio analizzare, sono espresse in Gev/c
la rho->pi+pi-   w-> pi+pi- (1.53%)      k0s-> pi0 pi0     phi->K+ k-*/
            Double_t m_rho=0.770,m_omega=0.782,m_k0s=0.497,m_phi=1.020;
/*riempio il TLorentzVector della particella madre*/
            beam[i].SetPtEtaPhiM(pt, eta, phi, m_k0s);
            }
/*Fisso le masse delle particelle figlie*/
    Double_t m_p=0.139,m_k=0.493; 
        Double_t masses[2]= {m_p, m_p};
/*Invoco la classe TGenPhaseSpace, mi permette di descrivere decadimenti a n-corpi*/
        TGenPhaseSpace event[k];
/*Creo un ciclo che descriva il decadimento delle particelle madri*/
        for (Int_t i=0; i<k; i++) event[i].SetDecay(beam[i], 2, masses);
/*Creo un vettore*/   
        Double_t weight[k];
/*Imposto il peso di ogni singolo evento generato*/ 
        for (Int_t i=0; i<k; i++) weight[i] = event[i].Generate();
/*Definisco i TLorentzVector dei prodotti di decadimento*/        
        TLorentzVector *pmeno[k], *ppiu[k];
/*assegno i valori dei TLorentzVector di decadimento*/
        for (Int_t i=0; i<k; i++) {
            pmeno[i] = event[i].GetDecay(0);
            ppiu[i]  = event[i].GetDecay(1);
            }
/*Costruisco lo spettro in massa invariante, simulando la presenza di un rivelatore*/
        for (Int_t i=0; i<k; i++) {
            for (Int_t j=0; j<k; j++) {
                TLorentzVector E = *ppiu[i] + *pmeno[j];
                TLorentzVector R (gRandom->Gaus(0, 0.0001), gRandom->Gaus(0, 0.0001), gRandom->Gaus(0, 0.0001),gRandom->Gaus(0, 0.0001) );
                TLorentzVector T = E + R;
                mass_inv.Fill(T.M());
            }
        }    
    }
 /*Definisco un Canvas, esso mi permette di agire direttamente sul grafico*/   
    TCanvas *c1=new TCanvas();
/*Imposto i titoli degli assi*/  
    mass_inv.SetXTitle("M_{#pi^{0}#pi^{0}} GeV");
    mass_inv.SetYTitle("N");
/*Imposto il colore dell'istogramma*/
    mass_inv.SetFillColor(kBlue);
/*Fitto l'istogramma con una Breit-Wigner, data la presenza di una risonanza*/
    TF1 *BW = new TF1("mybw",mybw,0.485, 0.505,3);
    BW->SetParName(0,"const");  
    BW->SetParameter(0,5.0);   
    BW->SetParName(1,"Gamma");
    BW->SetParameter(1,0.06); 
    BW->SetParName(2,"Mass");
    BW->SetParameter(2,0.497);     
    
	mass_inv.Fit("mybw","QR");
/*Stampo sul Canvas l'istogramma*/    
    mass_inv.DrawCopy(); 
    c1->SaveAs("massa_inv_K0s(497).pdf"); 
}
    

and i receive this output :

massa_inv_K0s(497).pdf (15.8 KB)

the fit is so bad, how can i improve it?

and why the parameter doesnt appear on the terminal ?

Someone can help me please?

Best Regards


_ROOT Version: 6.13/03
_Platform: Xubuntu 18.04
_Compiler: gcc version 7.3.0


Try to play with fit options (e.g. try with “IR”, “WR”, “IWR”, “LR”, “ILR” ).

If your fit misbehaves / fails … make sure that you set “reasonable” initial values for all parameters of your fit function … otherwise … maybe your fit function is not able to describe your data points well.

If you want to see parameters’ values, add gStyle->SetOptFit(1112); and / or do not use the “Q” fit option.

Thanks, it works very good.

Best Regards.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.