2022-06-22 19:33:20 -04:00
|
|
|
#include "armory/AnalysisLibrary.h"
|
|
|
|
|
|
|
|
double xMin1, xMax1;
|
2022-06-27 20:21:44 -04:00
|
|
|
TGraph fitGraph1;
|
2022-06-22 19:33:20 -04:00
|
|
|
Double_t fitFunc1(Double_t *x, Double_t *par) {
|
|
|
|
double pos = par[1]*x[0] + par[0];
|
2022-06-27 20:21:44 -04:00
|
|
|
return (xMax1 > pos && pos > xMin1 ? par[2] * fitGraph1.Eval(pos): 0);
|
2022-06-22 19:33:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
TF1 * FitHist1(TH1F * hist1, TH1F * hist2, double a0, double a1, double scale){
|
|
|
|
|
|
|
|
if( hist1->GetNbinsX() != hist2->GetNbinsX() ) return NULL;
|
|
|
|
|
|
|
|
xMin1 = hist1->GetXaxis()->GetXmin();
|
|
|
|
xMax1 = hist2->GetXaxis()->GetXmax();
|
|
|
|
int nBin = hist1->GetNbinsX();
|
|
|
|
|
2022-06-27 20:21:44 -04:00
|
|
|
fitGraph1.Clear();
|
2022-06-22 19:33:20 -04:00
|
|
|
for( int i = 0; i < nBin; i++){
|
2022-06-27 20:21:44 -04:00
|
|
|
fitGraph1.AddPoint(hist1->GetBinCenter(i), hist1->GetBinContent(i));
|
2022-06-22 19:33:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
double par[3] = {a0, a1, scale};
|
|
|
|
|
2022-06-27 20:21:44 -04:00
|
|
|
TF1 * fit1 = new TF1("fit1", fitFunc1, xMin1, xMax1, 3);
|
|
|
|
fit1->SetParameters(par);
|
|
|
|
fit1->SetParLimits(0, -20, 15);
|
|
|
|
fit1->SetParLimits(1, 0.6, 1.3);
|
|
|
|
//fit1->SetParLimits(2, 0.5*scale, 1.4*scale);
|
|
|
|
fit1->SetLineWidth(2);
|
|
|
|
fit1->SetLineColor(4);
|
|
|
|
fit1->SetNpx(1000);
|
|
|
|
|
|
|
|
hist2->Fit("fit1", "Rq");
|
|
|
|
|
|
|
|
return fit1;
|
2022-06-22 19:33:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
double xMin2, xMax2;
|
2022-06-27 20:21:44 -04:00
|
|
|
TGraph fitGraph2;
|
2022-06-22 19:33:20 -04:00
|
|
|
Double_t fitFunc2(Double_t *x, Double_t *par) {
|
2022-06-27 20:21:44 -04:00
|
|
|
|
|
|
|
|
|
|
|
double pos = par[3]*x[0]*x[0] + par[1]*x[0] + par[0];
|
2022-06-22 19:33:20 -04:00
|
|
|
|
|
|
|
//return (xMax2 > pos && pos > xMin2 ? par[2] * fitGraph2->Eval(pos) * exp(pos/1000./par[3]): 0);
|
2022-06-27 20:21:44 -04:00
|
|
|
|
|
|
|
return (xMax2 > pos && pos > xMin2 ? par[2] * fitGraph2.Eval(pos) : 0);
|
2022-06-22 19:33:20 -04:00
|
|
|
|
|
|
|
|
2022-06-27 20:21:44 -04:00
|
|
|
//if( x[0] < 3900 ){
|
|
|
|
// return (xMax2 > pos && pos > xMin2 ? par[2] * fitGraph2.Eval(pos): 0);
|
2022-06-22 19:33:20 -04:00
|
|
|
//}else{
|
2022-06-27 20:21:44 -04:00
|
|
|
// return (xMax2 > pos && pos > xMin2 ? par[3] * fitGraph2.Eval(pos): 0);
|
2022-06-22 19:33:20 -04:00
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TF1 * FitHist2(TH1F * hist1, TH1F * hist2, double a0, double a1, double scale, double scale2){
|
|
|
|
|
|
|
|
if( hist1->GetNbinsX() != hist2->GetNbinsX() ) return NULL;
|
|
|
|
|
|
|
|
xMin2 = hist1->GetXaxis()->GetXmin();
|
|
|
|
xMax2 = hist2->GetXaxis()->GetXmax();
|
|
|
|
int nBin = hist1->GetNbinsX();
|
|
|
|
|
2022-06-27 20:21:44 -04:00
|
|
|
fitGraph2.Clear();
|
2022-06-22 19:33:20 -04:00
|
|
|
for( int i = 0; i < nBin; i++){
|
2022-06-27 20:21:44 -04:00
|
|
|
fitGraph2.AddPoint(hist1->GetBinCenter(i), hist1->GetBinContent(i));
|
2022-06-22 19:33:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
double par[4] = {a0, a1, scale, scale2};
|
|
|
|
|
2022-06-27 20:21:44 -04:00
|
|
|
TF1 * fit2 = new TF1("fit2", fitFunc2, xMin2, xMax2, 4);
|
|
|
|
fit2->SetParameters(par);
|
|
|
|
fit2->SetParLimits(0, 0, 15);
|
|
|
|
fit2->SetParLimits(1, 0.6, 1.2);
|
|
|
|
fit2->SetParLimits(3, -0.00001, 0.00001);
|
|
|
|
//fit2->FixParameter(3, 0);
|
|
|
|
fit2->SetLineWidth(2);
|
|
|
|
fit2->SetLineColor(4);
|
|
|
|
fit2->SetNpx(1000);
|
|
|
|
|
|
|
|
hist2->Fit("fit2", "Rq");
|
|
|
|
|
|
|
|
return fit2;
|
2022-06-22 19:33:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void compareTH2D(int run1, int run2){
|
|
|
|
|
|
|
|
TFile * f1 = new TFile(Form("PID_%d.root", run1));
|
|
|
|
TH1F * hTOF1 = (TH1F*) f1->Get("hTOF");
|
|
|
|
TH1F * hdE1 = (TH1F*) f1->Get("hdE");
|
|
|
|
TH2F * hPID1 = (TH2F*) f1->Get("hPID0");
|
|
|
|
|
|
|
|
TFile * f2 = new TFile(Form("PID_%d.root", run2));
|
|
|
|
TH1F * hTOF2 = (TH1F*) f2->Get("hTOF");
|
|
|
|
TH1F * hdE2 = (TH1F*) f2->Get("hdE");
|
|
|
|
TH2F * hPID2 = (TH2F*) f2->Get("hPID0");
|
|
|
|
|
2022-06-27 20:21:44 -04:00
|
|
|
TCanvas * cc = (TCanvas *) gROOT->FindObjectAny("cc");
|
|
|
|
if( cc == NULL )cc = new TCanvas("cc", Form("cc %d, %d", run1, run2), 3000, 1000);
|
|
|
|
cc->Clear();
|
2022-06-22 19:33:20 -04:00
|
|
|
cc->Divide(3,1);
|
|
|
|
|
|
|
|
//================= TOF
|
|
|
|
cc->cd(1);
|
2022-06-27 20:21:44 -04:00
|
|
|
|
|
|
|
double yMax1 = hTOF1->GetMaximum();
|
|
|
|
double yMax2 = hTOF2->GetMaximum();
|
2022-06-22 19:33:20 -04:00
|
|
|
hTOF2->SetLineColor(2);
|
|
|
|
|
2022-06-27 20:21:44 -04:00
|
|
|
double scaleGuess = yMax2/yMax1;
|
|
|
|
|
|
|
|
if( yMax1 > yMax2 ) {
|
|
|
|
hTOF1->Draw("");
|
|
|
|
hTOF2->Draw("same");
|
|
|
|
}else{
|
|
|
|
hTOF2->Draw("");
|
|
|
|
hTOF1->Draw("same");
|
|
|
|
}
|
|
|
|
TF1 * fitTOF = FitHist1(hTOF1, hTOF2, -6, 1.0, scaleGuess);
|
2022-06-22 19:33:20 -04:00
|
|
|
fitTOF->Draw("same");
|
|
|
|
|
|
|
|
//TPad * chaha = (TPad*) (cc->cd(1))->Clone();
|
|
|
|
//cc->cd();
|
|
|
|
//chaha->Draw();
|
|
|
|
|
|
|
|
const Double_t* paraE_TOF = fitTOF->GetParErrors();
|
|
|
|
const Double_t* paraA_TOF = fitTOF->GetParameters();
|
|
|
|
|
|
|
|
printf("=================== TOF \n");
|
|
|
|
printf("a0 : %7.4f +- %7.4f \n", paraA_TOF[0], paraE_TOF[0]);
|
|
|
|
printf("a1 : %7.4f +- %7.4f \n", paraA_TOF[1], paraE_TOF[1]);
|
|
|
|
printf(" B : %7.4f +- %7.4f \n", paraA_TOF[2], paraE_TOF[2]);
|
|
|
|
|
|
|
|
|
|
|
|
//============== dE
|
|
|
|
cc->cd(2); cc->cd(2)->SetLogy();
|
|
|
|
hdE1->Draw("");
|
|
|
|
hdE2->SetLineColor(2);
|
|
|
|
hdE2->Draw("same");
|
|
|
|
|
2022-06-27 20:21:44 -04:00
|
|
|
TF1 * fitdE = FitHist2(hdE1, hdE2, -1, 1, 1, 0.0000001);
|
2022-06-22 19:33:20 -04:00
|
|
|
|
|
|
|
fitdE->Draw("same");
|
|
|
|
|
|
|
|
const Double_t* paraE_dE = fitdE->GetParErrors();
|
|
|
|
const Double_t* paraA_dE = fitdE->GetParameters();
|
|
|
|
|
|
|
|
printf("=================== dE \n");
|
|
|
|
printf("a0 : %7.4f +- %7.4f \n", paraA_dE[0], paraE_dE[0]);
|
|
|
|
printf("a1 : %7.4f +- %7.4f \n", paraA_dE[1], paraE_dE[1]);
|
|
|
|
printf(" B : %7.4f +- %7.4f \n", paraA_dE[2], paraE_dE[2]);
|
|
|
|
printf("B2 : %7.4f +- %7.4f \n", paraA_dE[3], paraE_dE[3]);
|
|
|
|
|
|
|
|
printf("################################\n");
|
2022-06-27 20:21:44 -04:00
|
|
|
printf("%3d %9.6f %9.6f %9.6f %9.6f %14.10f\n", run2, paraA_TOF[0], paraA_TOF[1], paraA_dE[0], paraA_dE[1], paraA_dE[3]);
|
2022-06-22 19:33:20 -04:00
|
|
|
printf("\n\n\n");
|
|
|
|
|
|
|
|
cc->cd(3);
|
|
|
|
hPID1->Draw("colz");
|
|
|
|
hPID2->Draw("same");
|
|
|
|
}
|