Rev 47 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#include "TROOT.h"
#include "TFile.h"
#include "TBenchmark.h"
#include "TH1F.h"
#include "TH2F.h"
#include "TCanvas.h"
#include "TStyle.h"
#include "TPad.h"
#include "TPaveText.h"
//#include "TLabel.h"
#include "TF1.h"
#include "TGraph.h"
#include "TSpectrum.h"
#include "stdio.h"
#include "include/RTUtil.h"
int focus(char filename[256] = "test", int chX=3, int chY=2, double parameter1=16.90, double parameter2=17.20, bool debug = false)
{
const int c_nChannels = 64;
int map[8][8]={{32,34,53,55,40,42,61,63},
{48,50,37,39,56,58,45,47},
{33,35,52,54,41,43,60,62},
{49,51,36,38,57,59,44,46},
{17,19,4,6,25,27,12,14},
{1,3,20,22,9,11,28,30},
{16,18,5,7,24,26,13,15},
{0,2,21,23,8,10,29,31}
};
char fnameroot[256];
TFile* rootfile;
sprintf(fnameroot, "root/%s.root", filename);
rootfile = (TFile *) gROOT->FindObject(filename);
if(rootfile==NULL) rootfile = new TFile(fnameroot);
if(rootfile==NULL) {
printf("Cannot open root file %s!!!\n",fnameroot);
return(0);
}
// set draw style
RTSetStyle(gStyle);
/** Draws the beam profile and fits it with error function
* on some background function
*/
TCanvas* canvas9 = new TCanvas("canvas9","canvas9", 500,500);
canvas9->cd();
char hname[128];
int channel = map[chX][chY];
sprintf(hname, "hnhitsy%d", channel);
TH1F* h_laser = (TH1F*)rootfile->Get(hname);
h_laser->Draw();
h_laser->SetStats(1);
//TF1* err = new TF1("err","[0]+[1]*TMath::Erf((x-[2])/[3])",parameter1,parameter2);
TF1* err = new TF1("err","[0]+[1]*TMath::Erf((x-[2])/[3])",h_laser->GetBinCenter(3), h_laser->GetBinCenter(h_laser->GetMaximumBin()));
err->SetParameter(0, h_laser->GetMinimum());
err->SetParameter(1, h_laser->GetMaximum() - h_laser->GetMinimum());
err->SetParameter(2, h_laser->GetBinCenter(h_laser->GetMaximumBin()));
err->SetParameter(3, 0.025);
h_laser->Fit(err,"qr");
h_laser->Fit(err,"lr");
double sigma = err->GetParameter(3);
printf("sigma = %2.0f um, FWHM = %2.0f um\n", sigma*1000, 2.35*sigma*1000);
return 0;
}