{ gROOT->ProcessLine(".L th1fmorph.C"); // Dependency gStyle->SetOptStat(false); gStyle->SetOptTitle(false); TF1 *pdf1 = new TF1("pdf1","ROOT::Math::normal_pdf(x, [0],[1])",-5,5); TF1 *pdf2 = new TF1("pdf2","ROOT::Math::normal_pdf(x, [0],[1])",-5,5); TF1 *pdfmid = new TF1("pdfmid","ROOT::Math::normal_pdf(x, [0],[1])",-5,5); Double_t sigma1=0.07, sigma2=0.25, sigmamid=0.5*(sigma1+sigma2); pdf1->SetParameters(sigma1,-4); pdf2->SetParameters(sigma2,4); pdfmid->SetParameters(sigmamid,0); TH1F *hdf1=(TH1F *)gROOT->FindObject("hdf1"); if(hdf1) delete hdf1; TH1F *hdf2=(TH1F *)gROOT->FindObject("hdf2"); if(hdf2) delete hdf2; TH1F *hdfmid=(TH1F *)gROOT->FindObject("hdfmid"); if(hdfmid) delete hdfmid; hdf1=new TH1F("hdf1","new",500,-5.,5.); hdf2=new TH1F("hdf2","new",500,-5.,5.); hdfmid=new TH1F("hdfmid","new",500,-5.,5.); hdf1->FillRandom("pdf1",100000); hdf2->FillRandom("pdf2",300000); hdfmid->FillRandom("pdfmid",200000); hdf1->SetLineStyle(2); hdf2->SetLineStyle(2); hdfmid->SetLineStyle(2); hdf1->Draw(); hdf2->Draw("same"); hdfmid->Draw("same"); TH1F *ginterpnew, *ginterpprev; ostringstream histname; TString hname; ginterpprev = 0; for(Double_t x=0.0;x<1.001;x+=0.001) { x = x < 1 ? x : 1; // Prepare the new distribution histname.seekp(0); histname << "ginterp" << x; hname = histname.str(); ginterpnew=(TH1F *)gROOT->FindObject(hname); if (ginterpnew) delete ginterpnew; ginterpnew = (TH1F *)th1fmorph((Char_t *)hname,"Interpolated gaussian" ,hdf1,hdf2,0.,1.,x,0.,0); // Draw the new distribution. ginterpnew->Draw("same"); // Delete the previous disttribution if (ginterpprev) delete ginterpprev; // Swap what is new and previous for the next iteration ginterpprev = ginterpnew; c1->Update(); gSystem->Sleep(0020); } }