Please read tips for efficient and successful posting and posting code
Hi, everyone!
I’m trying to fit the typical signal waveform read from SiPM (detecting photons from plastic scintillator, when hit by cosmic Muon rays)
My rough judgement of the waveform is the function below
a*z/exp(z)+d, z=bx+c
my initialization of the function(red) is drawn along with the actual sig waveform(blue)
horizontal axis: (s) vertical axis: (V) (forgive me)
but once i add codes to fit it, the terminal seems to get stuck…
the UI only reveal the sig waveform and the peak point
the terminal does not give any feed back and does not response any longer
when i interrupt (Ctrl+C) sometimes terminal gets frozen(this case i had to terminate the terminal to reactivate it)
i tried to print out FitResult but made no difference…
This is my fit function
auto myfit(double* x, double* par) -> double
{
gStyle->SetOptFit(1);
double a(par[0]), b(par[1]), c(par[2]), d(par[3]);
double z = b * x[0] + c;
double y = a * z / exp(z) + d;
return y;
}
This is my main method
auto typSig_fit() -> int
{
TFile* file = new TFile("test.root", "READ");
TH1D const* sig = (TH1D*)file->Get("h1");
TCanvas* c1 = new TCanvas("c1", "c1", 1000, 500);
//non-critical oper. to histo.
double const* source = y;
//peak finding using TSpectrum
Double_t bscl = sum / 100;//basic line
TF1* f = new TF1("myfit", myfit, startX, endX, 4);//start&end points marked in canvas
double a,b,c,d;//compute my initial para.s
a=exp(1)*(ypeaks[0]-bscl);
b=1/(xpeaks[0]-startX);
c=startX*b;
d=bscl;
f->SetParameter(0, a);
f->SetParameter(1, b);
f->SetParameter(2, c);
f->SetParameter(3, d);
TH1D* h2 = (TH1D*)sig->Clone();
TFitResultPtr fitresult = h2->Fit(f,"WQRSN");// ## stuck here ##
fitresult = h2->Fit(f,"RMS");
fitresult->Print();
h2->Draw();
marker1->Draw("same");
marker2->Draw("same");
f->Draw("same");
c1->Update();
c1->SaveAs("typSig_fit2.png");
ROOT Version: 6.30/04
Platform: wsl?(I have no concept)
Compiler: g++
___i might have some obvious mistakes (im still a runoob) but hope those don’t influence you find my key problem.