#include #include #include #include #include "TTree.h" #include "TBranch.h" #include "TFile.h" #include "TCanvas.h" #include "TPad.h" #include "TBranch.h" #include "TCut.h" #include "TGraph.h" #include "TGraphErrors.h" #include "TH1D.h" #include "TH2D.h" #include "TString.h" #include "TMultiGraph.h" using namespace std; //finito il terzo ciclo di campi magnetici, divido il file in due (i primi 3 sono con FC nostra e quelli dopo con FC di MilanoBi) //prendo la serie delle tre migliore //sovrappongo i due plot e devono coincidere Int_t npeaks = 100; Double_t fpeaks(Double_t *x, Double_t *par) { Double_t result = par[0] + par[1]*x[0]; for (Int_t p=0;p> B[i] >> eB[i] >> i_DF[i] >> ei_DF[i] >> dummy >> dummy >> i_MiB[i] >> ei_MiB[i] >> i_TES[i] >> ei_TES[i]; //cout << B[i] << " " << eB[i] << " " << i_DF[i] << endl; //ok, funziona //cout << "ciao" << endl; } TCanvas *c1 = new TCanvas(); c1->Divide(1,2); //c1->cd(1); TGraphErrors *g = new TGraphErrors(Npts, B, i_TES, eB, ei_TES); //g->Draw("AP*"); TH1F *h=new TH1F("h","test",490,4780,5050); h->Clear(); h->Reset(); auto nPoints = g->GetN(); // number of points in your TGraph for(int i=0; i < nPoints; ++i) { double x = g->GetX()[i]; double y = g->GetY()[i]; int k = h->FindBin(x); h->SetBinContent(k,y); //h->SetBinError(k, ei_TES); } h->Draw("HIST"); TH1F *h2 = (TH1F*)h->Clone("h2"); // Use TSpectrum to find the peak candidates TSpectrum *s = new TSpectrum(2*npeaks); Int_t nfound = s->Search(h2,2,"",0.001); printf("Found %d candidate peaks to fit\n",nfound); TF1 *fline = new TF1("fline","pol1",4650,4750); h->Fit("fline","qn"); // Loop on all found peaks. Eliminate peaks at the background level par[0] = fline->GetParameter(0); par[1] = fline->GetParameter(1); npeaks = 0; Double_t *xpeaks; xpeaks = s->GetPositionX(); for (Int_t p=0;pGetXaxis()->FindBin(xp); Double_t yp = h2->GetBinContent(bin); par[3*npeaks+2] = yp; // "height" par[3*npeaks+3] = xp; // "mean" par[3*npeaks+4] =2; // "sigma" #if defined(__PEAKS_C_FIT_AREAS__) par[3*npeaks+2] *= par[3*npeaks+4] * (TMath::Sqrt(TMath::TwoPi())); // "area" #endif /* defined(__PEAKS_C_FIT_AREAS__) */ npeaks++; } printf("Found %d useful peaks to fit\n",npeaks); printf("Now fitting: Be patient\n"); TF1 *fit = new TF1("fit",fpeaks,4700,5060,3*npeaks+2); // We may have more than the default 25 parameters TVirtualFitter::Fitter(h2,npeaks); fit->SetParameters(par); //fit->SetNpx(1000); h2->Fit("fit"); }