TCanvas *c1=new TCanvas;
TFile *f=new TFile("liquidpsd.root");
c1->Clear();
g00020->SetLineColor(kBlue);
g00020->Draw();
g00030->SetLineColor(kRed);
g00030->Draw("same");
c1->Draw();
基线修正
代码示例
void BaseCorrection(int gindex, TGraph *gb)
{
//从文件指针*f中得到name为“g00020”的TGraph指针,Form()函数用法与c语言中的printf类似;
TGraph *g=(TGraph*)f->Get(Form("g%05d",gindex));
double *y=g->GetY();//将TGraph的y轴数值按顺序填入数组y;
double yb[250];
double base=0;
for(int i=0;i<40;i++) {
base += y[i];
}
base /=40.;
cout<<base<<endl;
gb->Clear();
gb->SetTitle(Form("gindex=%d",gindex));
for(int i=0;i<250;i++) {
yb[i]=y[i]-base;
gb->SetPoint(i,i,yb[i]);
}
}
TGraph *gb=new TGraph;
BaseCorrection(30,gb);
c1->Clear();
gb->Draw();
c1->Draw();
代码示例
void TimeCorrection(TGraph *gb, TGraph *gc)
{
double *y=gb->GetY();//将TGraph的y轴数值按顺序填入数组y;
gc->Clear();
double yc[250];
int xmax=TMath::LocMax(250,y);//TMath::LocMax(n,data),从data数组的0-n范围内找到最大值,返回最大值所在的数组索引数字
cout<<xmax<<endl;
int dx=59-xmax;
for(int i=0;i<250;i++) {
if(i+dx<0 || i+dx>=250) yc[i]=0;//防止数组超界
else yc[i]=y[i+dx];
gc->SetPoint(i,i,yc[i]);
}
gc->SetTitle(gb->GetTitle());
}
TGraph *gc=new TGraph;
TimeCorrection(gb,gc);
c1->Clear();
g00030->SetMaximum(3500);
g00030->SetMinimum(-50);
g00030->Draw();
gb->Draw("same");
gb->SetLineColor(kRed);
gc->Draw("same");
gc->SetLineColor(kBlue);
c1->Draw();
int t0=50;//fast,total门的左边界
int t1=70;//fast的右边界
int t2=250;//total的右边界
double fast=0;
double total=0;
double tail;
double *y=g->GetY();
for(int i=t0;i<t1;i++) fast += y[i];
for(int i=t0;i<t2;i++) total += y[i];
tail=total-fast;
double psd=tail/total;