#include "ASellmeierFormula.h"
#include "AOpticsManager.h"
#include "TMath.h"
#include "TROOT.h"
ClassImp(ASellmeierFormula);
ASellmeierFormula::ASellmeierFormula() : ARefractiveIndex() {}
ASellmeierFormula::ASellmeierFormula(Double_t B1, Double_t B2, Double_t B3,
Double_t C1, Double_t C2, Double_t C3)
: ARefractiveIndex() {
fPar[0] = B1;
fPar[1] = B2;
fPar[2] = B3;
fPar[3] = C1;
fPar[4] = C2;
fPar[5] = C3;
}
ASellmeierFormula::ASellmeierFormula(const Double_t* p) {
for (Int_t i = 0; i < 6; i++) {
fPar[i] = p[i];
}
}
Double_t ASellmeierFormula::GetRefractiveIndex(Double_t lambda) const {
lambda /= AOpticsManager::um();
Double_t lambda2 = lambda * lambda;
return TMath::Sqrt(1 + fPar[0] * lambda2 / (lambda2 - fPar[3]) +
fPar[1] * lambda2 / (lambda2 - fPar[4]) +
fPar[2] * lambda2 / (lambda2 - fPar[5]));
}
TF1* ASellmeierFormula::FitData(TGraph* graph, const char* tf1name,
Option_t* option) {
if (graph == 0 or tf1name == 0) {
return 0;
}
TF1* f = (TF1*)gROOT->GetFunction(tf1name);
if (!f) {
Double_t xmin = TMath::MinElement(graph->GetN(), graph->GetX());
Double_t xmax = TMath::MaxElement(graph->GetN(), graph->GetX());
f = MakeGraph(tf1name, xmin, xmax);
}
f->SetParLimits(0, 0, 1e1);
f->SetParLimits(1, 0, 1e0);
f->SetParLimits(2, 0, 1e1);
f->SetParLimits(3, 0, 1e-1);
f->SetParLimits(4, 0, 1e-1);
f->SetParLimits(5, 0, 1e3);
f->SetParameter(0, 1.);
f->SetParameter(1, .2);
f->SetParameter(2, 1.);
f->SetParameter(3, 5e-3);
f->SetParameter(4, 2e-2);
f->SetParameter(5, 1e2);
graph->Fit(f, option);
for (Int_t i = 0; i < (Int_t)(sizeof(fPar) / sizeof(Double_t)); i++) {
fPar[i] = f->GetParameter(i);
}
return f;
}
TF1* ASellmeierFormula::MakeGraph(const char* tf1name, Double_t xmin,
Double_t xmax) {
Double_t um = AOpticsManager::um();
TF1* f = new TF1(tf1name,
Form("sqrt(1 + [0]*(x/%f)**2/((x/%f)**2 - [3]) + "
"[1]*(x/%f)**2/((x/%f)**2 - [4]) + "
"[2]*(x/%f)**2/((x/%f)**2 - [5]))",
um, um, um, um, um, um),
xmin, xmax);
for (Int_t i = 0; i < (Int_t)(sizeof(fPar) / sizeof(Double_t)); i++) {
f->SetParameter(i, fPar[i]);
}
f->SetParNames("B1", "B2", "B3", "C1", "C2", "C3");
return f;
}
ASellmeierFormula.cxx:100 ASellmeierFormula.cxx:101 ASellmeierFormula.cxx:102 ASellmeierFormula.cxx:103 ASellmeierFormula.cxx:104 ASellmeierFormula.cxx:105 ASellmeierFormula.cxx:106 ASellmeierFormula.cxx:107 ASellmeierFormula.cxx:108 ASellmeierFormula.cxx:109 ASellmeierFormula.cxx:110 ASellmeierFormula.cxx:111 ASellmeierFormula.cxx:112 ASellmeierFormula.cxx:113 ASellmeierFormula.cxx:114