本文整理汇总了C++中TSpectrum类的典型用法代码示例。如果您正苦于以下问题:C++ TSpectrum类的具体用法?C++ TSpectrum怎么用?C++ TSpectrum使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TSpectrum类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: DeconvolutionRL_wide
void DeconvolutionRL_wide() {
Int_t i;
const Int_t nbins = 256;
Double_t xmin = 0;
Double_t xmax = nbins;
Double_t source[nbins];
Double_t response[nbins];
gROOT->ForceStyle();
TString dir = gROOT->GetTutorialsDir();
TString file = dir+"/spectrum/TSpectrum.root";
TFile *f = new TFile(file.Data());
h = (TH1F*) f->Get("decon3");
h->SetTitle("Deconvolution of closely positioned overlapping peaks using Richardson-Lucy deconvolution method");
d = (TH1F*) f->Get("decon_response_wide");
for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
for (i = 0; i < nbins; i++) response[i]=d->GetBinContent(i + 1);
h->SetMaximum(30000);
h->Draw("L");
TSpectrum *s = new TSpectrum();
s->DeconvolutionRL(source,response,256,10000,1,1);
for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,source[i]);
d->SetLineColor(kRed);
d->Draw("SAME L");
}
示例2: while
int e428ana1::MakePara(Double_t thr){
int npeak,nlap;
double threshol,thrmin,thrmax;
TSpectrum *spec;
for (int i=0; i<4; i++) {
for (int j=0; j<127; j++) {
npeak=0;nlap=0;
threshol=thr;
thrmax=1;thrmin=0;
while (npeak!=4 && nlap<100){
spec = new TSpectrum(10);
npeak = spec->Search(hdssd[i][j],2,"",threshol);
if (npeak >3) {
thrmin=threshol;
}else thrmax=threshol;
threshol=(thrmax-thrmin)/2;
nlap++;
// printf("Npeak %d %d %d %f\n",i,j,npeak,threshol);
}
float *xpeak=spec->GetPositionX();
float *ypeak=spec->GetPositionY();
printf("Npeak %d %d %d",i,j,npeak);
for (int i1=0; i1<npeak; i1++) {
printf(" %f %f",xpeak[i1],ypeak[i1]);
}
printf("\n");
}
}
return 0;
}
示例3: Deconvolution_wide_boost
void Deconvolution_wide_boost() {
Int_t i;
const Int_t nbins = 256;
Double_t xmin = 0;
Double_t xmax = nbins;
Double_t source[nbins];
Double_t response[nbins];
gROOT->ForceStyle();
TH1F *h = new TH1F("h","Deconvolution",nbins,xmin,xmax);
TH1F *d = new TH1F("d","",nbins,xmin,xmax);
TString dir = gROOT->GetTutorialDir();
TString file = dir+"/spectrum/TSpectrum.root";
TFile *f = new TFile(file.Data());
h = (TH1F*) f->Get("decon3");
h->SetTitle("Deconvolution of closely positioned overlapping peaks using boosted Gold deconvolution method");
d = (TH1F*) f->Get("decon_response_wide");
for (i = 0; i < nbins; i++) source[i]=h->GetBinContent(i + 1);
for (i = 0; i < nbins; i++) response[i]=d->GetBinContent(i + 1);
h->SetMaximum(200000);
h->Draw("L");
TSpectrum *s = new TSpectrum();
s->Deconvolution(source,response,256,200,50,1.2);
for (i = 0; i < nbins; i++) d->SetBinContent(i + 1,source[i]);
d->SetLineColor(kRed);
d->Draw("SAME L");
}
示例4: autogain152
TGraph* autogain152(TH1 *hist) {
hist->GetXaxis()->SetRangeUser(200.,16000.);
TSpectrum *s = new TSpectrum();
Int_t nfound = s->Search(hist,6,"",0.08); //This will be dependent on the source used.
printf("Found %d candidate peaks to fit\n",nfound);
if(nfound > 6)
nfound = 6;
std::vector<float> vec;
for(int x=0;x<nfound;x++)
vec.push_back(s->GetPositionX()[x]);
std::sort(vec.begin(),vec.end());
Float_t energies[] = {121.7830, 244.6920, 344.276, 778.903, 964.131, 1408.011};
TGraph* slopefit = new TGraph(nfound, &(vec[0]), energies);
printf("Now fitting: Be patient\n");
slopefit->Fit("pol1");
if(slopefit->GetFunction("pol1")->GetChisquare() > 10.) {
slopefit->RemovePoint(slopefit->GetN()-1);
slopefit->Fit("pol1");
}
TChannel *chan = 0;
slopefit->Draw("AC*");
return slopefit;
}
示例5: peaks
void peaks(Int_t np=10) {
npeaks = TMath::Abs(np);
TH1F *h = new TH1F("h","test",500,0,1000);
//generate n peaks at random
Double_t par[3000];
par[0] = 0.8;
par[1] = -0.6/1000;
Int_t p;
for (p=0;p<npeaks;p++) {
par[3*p+2] = 1;
par[3*p+3] = 10+gRandom->Rndm()*980;
par[3*p+4] = 3+2*gRandom->Rndm();
}
TF1 *f = new TF1("f",fpeaks,0,1000,2+3*npeaks);
f->SetNpx(1000);
f->SetParameters(par);
TCanvas *c1 = new TCanvas("c1","c1",10,10,1000,900);
c1->Divide(1,2);
c1->cd(1);
h->FillRandom("f",200000);
h->Draw();
TH1F *h2 = (TH1F*)h->Clone("h2");
//Use TSpectrum to find the peak candidates
TSpectrum *s = new TSpectrum(2*npeaks);
Int_t nfound = s->Search(h,2,"",0.10);
printf("Found %d candidate peaks to fit\n",nfound);
//Estimate background using TSpectrum::Background
TH1 *hb = s->Background(h,20,"same");
if (hb) c1->Update();
if (np <0) return;
//estimate linear background using a fitting method
c1->cd(2);
TF1 *fline = new TF1("fline","pol1",0,1000);
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 = s->GetPositionX();
for (p=0;p<nfound;p++) {
Double_t xp = xpeaks[p];
Int_t bin = h->GetXaxis()->FindBin(xp);
Double_t yp = h->GetBinContent(bin);
if (yp-TMath::Sqrt(yp) < fline->Eval(xp)) continue;
par[3*npeaks+2] = yp;
par[3*npeaks+3] = xp;
par[3*npeaks+4] = 3;
npeaks++;
}
printf("Found %d useful peaks to fit\n",npeaks);
printf("Now fitting: Be patient\n");
TF1 *fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks);
//we may have more than the default 25 parameters
TVirtualFitter::Fitter(h2,10+3*npeaks);
fit->SetParameters(par);
fit->SetNpx(1000);
h2->Fit("fit");
}
示例6: Background_order
void Background_order() {
Int_t i;
const Int_t nbins = 4096;
Double_t xmin = 0;
Double_t xmax = 4096;
Double_t source[nbins];
gROOT->ForceStyle();
TH1F *d1 = new TH1F("d1","",nbins,xmin,xmax);
TH1F *d2 = new TH1F("d2","",nbins,xmin,xmax);
TH1F *d3 = new TH1F("d3","",nbins,xmin,xmax);
TH1F *d4 = new TH1F("d4","",nbins,xmin,xmax);
TString dir = gROOT->GetTutorialsDir();
TString file = dir+"/spectrum/TSpectrum.root";
TFile *f = new TFile(file.Data());
TH1F *back = (TH1F*) f->Get("back2");
back->SetTitle("Influence of clipping filter difference order on the estimated background");
back->SetAxisRange(1220,1460);
back->SetMaximum(3000);
back->Draw("L");
TSpectrum *s = new TSpectrum();
for (i = 0; i < nbins; i++) source[i]=back->GetBinContent(i + 1);
s->Background(source,nbins,40,TSpectrum::kBackDecreasingWindow,
TSpectrum::kBackOrder2,kFALSE,
TSpectrum::kBackSmoothing3,kFALSE);
for (i = 0; i < nbins; i++) d1->SetBinContent(i + 1,source[i]);
d1->SetLineColor(kRed);
d1->Draw("SAME L");
for (i = 0; i < nbins; i++) source[i]=back->GetBinContent(i + 1);
s->Background(source,nbins,40,TSpectrum::kBackDecreasingWindow,
TSpectrum::kBackOrder4,kFALSE,
TSpectrum::kBackSmoothing3,kFALSE);
for (i = 0; i < nbins; i++) d2->SetBinContent(i + 1,source[i]);
d2->SetLineColor(kBlue);
d2->Draw("SAME L");
for (i = 0; i < nbins; i++) source[i]=back->GetBinContent(i + 1);
s->Background(source,nbins,40,TSpectrum::kBackDecreasingWindow,
TSpectrum::kBackOrder6,kFALSE,
TSpectrum::kBackSmoothing3,kFALSE);
for (i = 0; i < nbins; i++) d3->SetBinContent(i + 1,source[i]);
d3->SetLineColor(kGreen);
d3->Draw("SAME L");
for (i = 0; i < nbins; i++) source[i]=back->GetBinContent(i + 1);
s->Background(source,nbins,40,TSpectrum::kBackDecreasingWindow,
TSpectrum::kBackOrder8,kFALSE,
TSpectrum::kBackSmoothing3,kFALSE);
for (i = 0; i < nbins; i++) d4->SetBinContent(i + 1,source[i]);
d4->SetLineColor(kMagenta);
d4->Draw("SAME L");
}
示例7: autogain
TGraph* autogain(TH1 *hist,TNucleus *nuc) { //Display The fits on a TPad
if(!hist || !nuc)
return 0;
nuc->SetSourceData();
if(nuc->GetA() == 152) {
return autogain152(hist);
}
// Search
hist->GetXaxis()->SetRangeUser(200.,16000.);
TSpectrum *s = new TSpectrum();
Int_t nfound = s->Search(hist,6,"",0.1); //This will be dependent on the source used.
printf("Found %d candidate peaks to fit\n",nfound);
// Match
nuc->TransitionList.Sort();
std::vector<float> engvec;
TIter iter(&(nuc->TransitionList));
TObject* obj;
while(obj = iter.Next()) {
if(!obj->InheritsFrom("TGRSITransition"))
continue;
TGRSITransition *tran = (TGRSITransition*)obj;
engvec.push_back(static_cast<float>(tran->energy));
if(engvec.size() == nfound)
break;
}
if(nfound != engvec.size())
return 0;
Float_t *posPeaks = s->GetPositionX();
Float_t *energies = &(engvec[0]);
for(int x=0;x<nfound;x++) {
printf("posPeaks[%i] = %f\t\tenrgies[%i] = %f\n",x,posPeaks[x],x,energies[x]);
}
TGraph *slopefit = new TGraph(nfound,posPeaks,energies );
printf("Now fitting: Be patient\n");
slopefit->Fit("pol1");
slopefit->Draw("AC*");
return slopefit;
}
示例8: Fit
//______________________________________________________________________________
void Fit(Int_t run)
{
// Perform fit.
Char_t tmp[256];
// delete old function
if (gFitFunc) delete gFitFunc;
// create fitting function
if (gFitFunc) delete gFitFunc;
sprintf(tmp, "fGauss_%d", run);
gFitFunc = new TF1(tmp, "expo(0)+gaus(2)");
gFitFunc->SetLineColor(2);
// estimate peak position
TSpectrum s;
s.Search(gH, 10, "goff nobackground", 0.05);
Double_t peak = TMath::MaxElement(s.GetNPeaks(), s.GetPositionX());
// prepare fitting function
gFitFunc->SetRange(gMin, gMax);
gFitFunc->SetParameter(2, gH->GetXaxis()->FindBin(peak));
gFitFunc->SetParLimits(2, 0, 100000);
gFitFunc->SetParameter(3, peak);
gFitFunc->SetParameter(4, 20);
gFitFunc->SetParLimits(4, 18, 100);
for (Int_t i = 0; i < 10; i++)
if (!gH->Fit(gFitFunc, "RBQ0")) break;
// get peak
peak = gFitFunc->GetParameter(3);
// indicator line
gLine->SetX1(peak);
gLine->SetX2(peak);
gLine->SetY1(0);
gLine->SetY2(gH->GetMaximum());
// draw
gCFit->cd();
gH->GetXaxis()->SetRangeUser(0, 2000);
gH->Draw();
gFitFunc->Draw("same");
gLine->Draw("same");
// fill overview histogram
gHOverview->SetBinContent(run+1, peak);
gHOverview->SetBinError(run+1, 0.0001);
}
示例9: getValByKeyword
//Given an input histogram and TSpectrum returns a numeric value based on the input keyword; supported keywords are "AMPLITUDE,MEAN,PEAK,SIGMA"
float AnalyzeResponseUniformity::getValByKeyword(string strInputKeyword, shared_ptr<TH1F> hInput, TSpectrum &specInput){
//Try to automatically assign a value
if (0 == strInputKeyword.compare("AMPLITUDE") ) { //Case: Histo Amplitude
return hInput->GetBinContent( hInput->GetMaximumBin() );
} //End Case: Histo Amplitude
else if (0 == strInputKeyword.compare("MEAN") ) { //Case: Histo Mean
return hInput->GetMean();
} //End Case: Histo Mean
else if ( 0 == strInputKeyword.compare("PEAK") ){ //Case: Histo Peak
Double_t *dPeakPos = specInput.GetPositionX();
return dPeakPos[0];
} //End Case: Histo Peak
else if (0 == strInputKeyword.compare("SIGMA") ) { //Case: Histo RMS
return hInput->GetRMS();
} //End Case: Histo RMS
else{ //Case: manual assignment
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword","Error! Input Keyword Not Recognized");
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword", ("\tGiven: " + strInputKeyword ).c_str() );
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword","\tRecognized Keywords:\n");
for (int i=0; i < vec_strSupportedKeywords.size(); ++i) {
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword", vec_strSupportedKeywords[i].c_str() );
}
printClassMethodMsg("AnalyzeResponseUniformity","getValByKeyword","\tUndefined Behavior May Occur");
return -1e12;
} //End Case: manual assignment
} //End AnalyzeResponseUniformity::getValByKeyword()
示例10: write_spectrum
void MSSM_spectrum_plotter::write_spectrum(const TSpectrum& spectrum, std::ofstream& filestr) const
{
for (std::size_t s = 0; s < spectrum.size(); ++s) {
if (!filestr.good()) {
ERROR("MSSM_spectrum_plotter::write_spectrum: "
"file stream is corrupted");
break;
}
const std::string& name = spectrum[s].name;
const std::string& latex_name = spectrum[s].latex_name;
const std::valarray<double>& masses = spectrum[s].masses;
const std::size_t multiplicity = masses.size();
filestr << std::left << "# " << name << '\n';
for (std::size_t i = 0; i < multiplicity; ++i) {
std::string lname("$" + latex_name + "$");
std::stringstream lname_with_index;
lname_with_index << "$" << latex_name;
if (multiplicity > 1)
lname_with_index << "_{" << (i+1) << "}";
lname_with_index << "$";
filestr << std::left << std::setw(width) << s
<< std::left << std::setw(width) << masses[i]
<< std::left << std::setw(width) << name
<< std::left << std::setw(2*width) << lname
<< std::left << std::setw(2*width) << lname_with_index.str()
<< '\n';
}
}
}
示例11: FindPeak
void FindPeak(TH1 *hm, int * i, char * namefile){
int np =5, p, max = 0;
int npeaks = TMath::Abs(np);
double par[3000];
par[0] = 0.8;
par[1] = -0.6/1000;
for (p=0;p<npeaks;p++) {
par[3*p+2] = 1;
par[3*p+3] = 10+gRandom->Rndm()*980;
par[3*p+4] = 3+2*gRandom->Rndm();
}
TSpectrum *s = new TSpectrum(2*npeaks,1);
int nfound = s->Search(hm,2,"",0.10);
printf("Found %d candidate peaks to fit\n",nfound);
TH1 *hb = s->Background(hm,20,"same");
if (np <0) return;
// loope over peaks
TF1 *fline = new TF1("fline","pol1",0,1000);
hm->Fit("fline","qn");
par[0] = fline->GetParameter(0);
par[1] = fline->GetParameter(1);
npeaks = 0;
float *xpeaks = s->GetPositionX();
for (p=0;p<nfound;p++) {
float xp = xpeaks[p];
int bin = hm->GetXaxis()->FindBin(xp);
float yp = hm->GetBinContent(bin);
if (yp-TMath::Sqrt(yp) < fline->Eval(xp)) continue;
par[3*npeaks+2] = yp;
par[3*npeaks+3] = xp;
par[3*npeaks+4] = 3;
npeaks++;
}
printf("Found %d useful peaks to fit\n",npeaks);
printf("Now fitting: Be patient\n");
if (max < npeaks) max = npeaks;
TF1 *fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks);
TVirtualFitter::Fitter(hm,10+3*npeaks);
fit->SetParameters(par);
fit->SetNpx(1000);
hm->Fit("fit");
}
示例12: Load
//// This version needs thought
void SiCalibrator::FindPeaks() {
Load();
int iterate = 25;
int nbins;
TSpectrum* spec = new TSpectrum(10);
avesigma = 0;
int nsigma = 0;
for (int src=0; src < CalData.size(); src++) {
if (CalData[src].hSource != 0) {
for (int ch=0; ch<CalData[src].sourcedata.size(); ch++) {
TH1D* hbi = CalData[src].hSource->ProjectionY("hb",ch+1,ch+1);
nbins = hbi->GetNbinsX();
TH1D* hbk1 = (TH1D*) spec->Background(hbi,iterate);
hbi->Add(hbk1,-1);
//Estimate parameters
double lim = 5;
double max = 0;
double peak = 0;
int i = nbins - 1;
while (hbi->GetBinContent(i) < lim && i > 0) {
max = i;
i--;
}
double sigma = (max/CalibSource::sourcelist[src].betas.back().E)*2; //2 keV
if (sigma > 1) {
avesigma += sigma;
nsigma++;
}
gErrorIgnoreLevel = kError;
int npeaks = spec->Search(hbi,sigma,"nodraw ",0.001);
float* adc = spec->GetPositionX();
float* amp = spec->GetPositionY();
for (int i=0; i<npeaks; i++) {
CalData[src].sourcedata[ch].ADC.push_back(adc[i]);
CalData[src].sourcedata[ch].Amp.push_back(amp[i]);
}
}
}
}
avesigma = avesigma/nsigma;
}
示例13: DiffPeak
/*
Finds peak in timing difference spectrum
*/
double DiffPeak(TTree *&tree, TString pidcut = "PID>1000")
{
TSpectrum *spec = new TSpectrum(10); // peak finder
TH1D *diff = new TH1D("diff","diff",200,-5,5);
tree->Project("diff","diff",pidcut.Data());
spec->Search(diff,2,"nodraw",0.7);
double diffpeak = spec->GetPositionX()[0];
// testing
//TCanvas *c_tmp = new TCanvas();
//diff->Draw();
//c_tmp->WaitPrimitive();
//delete c_tmp;
delete diff;
delete spec;
return diffpeak;
} // end DiffPeak()
示例14: draw_ToF_Calib_Tower
void draw_ToF_Calib_Tower() {
ofstream fout("ToF_Calib_Tower.txt");
TFile* f = new TFile("/phenix/plhf/zji/taxi/Run13pp510MinBias/8328/data/total.root");
TH2I* h_hitmap_tof_energy_PbSc = (TH2I*)f->Get("hitmap_tof_energy_PbSc");
TH2I* h_hitmap_tof_energy_PbGl = (TH2I*)f->Get("hitmap_tof_energy_PbGl");
TH2I* h_hitmap_tof_tower = (TH2I*)f->Get("hitmap_tof_tower");
TCanvas* c = new TCanvas("c", "Canvas", 1800, 600);
gStyle->SetOptStat(1);
gStyle->SetOptFit(1);
c->Divide(3,1);
c->cd(1);
h_hitmap_tof_energy_PbSc->Draw("colz");
c->cd(2);
h_hitmap_tof_energy_PbGl->Draw("colz");
c->cd(3);
fout << "towerid ToF peak" << endl;
for(Int_t id=0; id<25000; id++) {
TH1D* hp_hitmap_tof_tower = (TH1D*)h_hitmap_tof_tower->ProjectionY("_py",id+1,id+1);
TSpectrum* peak = new TSpectrum();
Int_t nfound = peak->Search(hp_hitmap_tof_tower,2.,"nodraw");
if(nfound) {
Float_t peakX = *peak->GetPositionX();
hp_hitmap_tof_tower->Fit("gaus","Q0","",peakX-3.,peakX+3.);
TF1* f_hitmap_tof_tower = hp_hitmap_tof_tower->GetFunction("gaus");
Double_t mean_hitmap_tof_tower = f_hitmap_tof_tower->GetParameter(1);
fout << id << " " << mean_hitmap_tof_tower << endl;
f_hitmap_tof_tower->Delete();
}
else {
fout << id << " " << "-100." << endl;
}
delete peak;
hp_hitmap_tof_tower->Delete();
}
fout.close();
TH1D* hp_hitmap_tof_tower = (TH1D*)h_hitmap_tof_tower->ProjectionY("_py",100,100);
TSpectrum* peak = new TSpectrum();
peak->Search(hp_hitmap_tof_tower,2.,"nodraw");
Float_t peakX = *peak->GetPositionX();
hp_hitmap_tof_tower->Fit("gaus","","",peakX-3.,peakX+3.);
TF1* f_hitmap_tof_tower = hp_hitmap_tof_tower->GetFunction("gaus");
Double_t mean_hitmap_tof_tower = f_hitmap_tof_tower->GetParameter(1);
cout << "peakX=" << peakX << endl;
cout << "ToF mean=" << mean_hitmap_tof_tower << endl;
c->Print("ToF_Calib_Tower.pdf");
}
示例15: peaks
//________________________________________________________________________________
void peaks(TH1* h, Int_t np=10, Int_t ij=0) {
if (! h) return;
npeaks = TMath::Abs(np);
if (! c1) c1 = new TCanvas();
else c1->Clear();
if (c2 && ij > 0) {c2->cd(ij); h->Draw(); c2->Update();}
c1->Divide(1,2);
c1->cd(1);
h->Draw();
TH1F *h2 = (TH1F*)h->Clone("h2");
//Use TSpectrum to find the peak candidates
TSpectrum *s = new TSpectrum(2*npeaks);
Int_t nfound = s->Search(h,5,"",0.05);
printf("Found %d candidate peaks to fit\n",nfound);
if (! nfound) return;
//Estimate background using TSpectrum::Background
TH1 *hb = s->Background(h,20,"same");
hb->Draw("same");
c1->Update();
if (c2 && ij > 0) {c2->cd(ij); h->Draw(); c2->Update();}
if (np <0) return;
//estimate linear background using a fitting method
c1->cd(2);
TF1 *fline = new TF1("fline","pol1",0,1000);
fline->FixParameter(1,0.);
h->Fit("fline","qnlw");
if (c2 && ij > 0) {c2->cd(ij+1); h->Draw(); c2->Update(); c1->cd(2);}
//Loop on all found peaks. Eliminate peaks at the background level
Double_t par[3000];
par[0] = fline->GetParameter(0);
par[1] = fline->GetParameter(1);
npeaks = 0;
Float_t *xpeaks = s->GetPositionX();
Float_t ymax = 0;
for (Int_t p=0;p<nfound;p++) {
Float_t xp = xpeaks[p];
Int_t bin = h->GetXaxis()->FindBin(xp);
Float_t yp = h->GetBinContent(bin);
if (yp-3*TMath::Sqrt(yp) < fline->Eval(xp)) continue;
par[3*npeaks+2] = yp;
if (yp > ymax) ymax = yp;
par[3*npeaks+3] = xp;
par[3*npeaks+4] = 3;
npeaks++;
}
cout << "Found " << npeaks << " useful peaks to fit" << endl;
Int_t NP = 0;
Int_t nbad = 0;
TString LineH(" {\""); LineH += h->GetName(); LineH += "\"";
TString Line("");
struct ParErr_t {Double_t par, err;};
ParErr_t parErr[10];
TF1 *fit = 0;
if (ymax > 2*par[0]) {
cout << "Now fitting: Be patient" << endl;
fit = new TF1("fit",fpeaks,0,1000,2+3*npeaks);
TVirtualFitter::Fitter(h2,10+3*npeaks); //we may have more than the default 25 parameters
fit->SetParameter(0,par[0]);
fit->FixParameter(1,0.);
for (Int_t p = 0; p < npeaks; p++) {
fit->SetParName(3*p+2,Form("A%i",p));
fit->SetParLimits(3*p+2,0,1e6);
fit->SetParameter(3*p+2,par[3*p+2]);
fit->SetParName(3*p+3,Form("#mu%i",p));
fit->SetParLimits(3*p+3,TMath::Max(0.,par[3*p+3]-2), TMath::Min(240.,par[3*p+3]+2));
fit->SetParameter(3*p+3,par[3*p+3]);
fit->SetParName(3*p+4,Form("#sigma%i",p));
fit->SetParLimits(3*p+4,0.01,20);
fit->SetParameter(3*p+4,par[3*p+4]);
}
fit->SetNpx(1000);
h2->SetStats(0);
h2->Fit("fit","l");
if (c2 && ij > 0) {c2->cd(ij); h2->Draw("same"); c2->Update(); c1->cd(2);}
fit->GetParameters(par);
for (Int_t p = 0; p<np;p++) {
if (p < npeaks && par[3*p+2] > 5*fit->GetParError(3*p+2) &&
par[3*p+2] > par[0]) {
if (TMath::Abs(par[3*p+4]) > 5.0) nbad++;
// Line += Form(",%f,%f,%7.2f,%5.2f",par[3*p+2],fit->GetParError(3*p+2),par[3*p+3],TMath::Abs(par[3*p+4]));
parErr[NP].par = par[3*p+3];
parErr[NP].err = TMath::Abs(par[3*p+4]);
for (Int_t i = 0; i < NP; i++) {
if (parErr[i].par > parErr[NP].par) {
ParErr_t temp = parErr[i];
parErr[i] = parErr[NP];
parErr[NP] = temp;
}
}
NP++;
}
}
}
for (Int_t p = 0; p < np; p++) {
if (p < NP) Line += Form(",%7.2f,%5.2f",parErr[p].par,parErr[p].err);
else Line += ",0,0";
}
Line += "},";
//.........这里部分代码省略.........