23 #ifndef GW_BASECALIB_H
49 BaseCalib::BaseCalib()
68 fRaw.AddAt(channel,
fRaw.GetSize()-1);
76 printf(
"Info in <BaseCalib::Calibrate> function NOT defined !!\n");
79 if (function->GetNpar() >
fRaw.GetSize()) {
80 printf(
"Info in <BaseCalib::Calibrate> Nb of points < Nb of fit parameters, abort calibration !!\n");
83 TGraphErrors *graph =
new TGraphErrors(
fRaw.GetSize(),
fRaw.GetArray(),
fTabulated.GetArray());
84 graph->Fit(
function,
"",
"",graph->GetXaxis()->GetXmin(),graph->GetXaxis()->GetXmax());
93 printf(
"Info in <BaseCalib::Calibrate> function NOT defined !!\n");
96 TGraphErrors *graph =
new TGraphErrors(filename);
98 fRaw.Set(graph->GetN(),graph->GetX());
99 if (function->GetNpar() >
fRaw.GetSize()) {
100 printf(
"Info in <BaseCalib::Calibrate> Nb of points < Nb of fit parameters, abort calibration !!\n");
103 graph->Fit(
function,
"",
"",graph->GetXaxis()->GetXmin(),graph->GetXaxis()->GetXmax());
112 printf(
"Info in <BaseCalib::Calibrate> function NOT defined !!\n");
115 TGraphErrors *graph =
new TGraphErrors(nbpoints,raw,tabulated);
117 fRaw.Set(graph->GetN(),graph->GetX());
118 if (function->GetNpar() >
fRaw.GetSize()) {
119 printf(
"Info in <BaseCalib::Calibrate> Nb of points < Nb of fit parameters, abort calibration !!\n");
122 graph->Fit(
function,
"",
"",graph->GetXaxis()->GetXmin(),graph->GetXaxis()->GetXmax());
130 TMath::Abs(dimension);
132 for (Int_t i=1 ; i<dimension ; i++) {
133 str +=
"["; str += i; str +=
"*"; str +=
"TMath::Power(x,"; str += i; str +=
")";
135 TF1 *ftemp =
new TF1(
"ftemp",str.Data());
136 if (ftemp->GetNpar() >
fRaw.GetSize()) {
137 printf(
"Info in <BaseCalib::Calibrate> Nb of points < Nb of fit parameters, abort calibration !!\n");
140 TGraphErrors *graph =
new TGraphErrors(
fRaw.GetSize(),
fRaw.GetArray(),
fTabulated.GetArray());
141 graph->Fit(ftemp,
"",
"",graph->GetXaxis()->GetXmin(),graph->GetXaxis()->GetXmax());
145 if (ftemp)
delete ftemp;
150 const Bool_t invert,
const Double_t xmin,
const Double_t xmax)
163 printf(
"Info in <BaseCalib::AlignMax> function NOT defined !!\n");
167 printf(
"Info in <BaseCalib::AlignMax> histo NOT defined !!\n");
171 if (histo->GetDimension() > 1) {
172 printf(
"Info in <BaseCalib::AlignMax> Method not yet defined for Histogram Dimension >= 2 !!\n");
176 Double_t maxvalue=0.0, shift=0.0;
177 histo->GetXaxis()->SetRangeUser(xmin,xmax);
178 maxvalue = histo->GetBinCenter(histo->GetMaximumBin());
179 if (invert ==
false) {
180 shift = AlignValue - maxvalue;
181 function->SetParameter(0,shift);
182 function->SetParameter(1,1.0);
184 shift = AlignValue + maxvalue;
185 function->SetParameter(0,shift);
186 function->SetParameter(1,-1.0);
193 const Double_t ProportionalCoef,
const Bool_t invert,
const Double_t xmin,
const Double_t xmax)
206 printf(
"Info in <BaseCalib::AlignMax> function NOT defined !!\n");
210 printf(
"Info in <BaseCalib::AlignMax> histo NOT defined !!\n");
214 if (histo->GetDimension() > 1) {
215 printf(
"Info in <BaseCalib::AlignMax> Method not yet defined for Histogram Dimension >= 2 !!\n");
219 Double_t maxvalue=0.0, shift=0.0;
220 histo->GetXaxis()->SetRangeUser(xmin,xmax);
221 maxvalue = histo->GetBinCenter(histo->GetMaximumBin());
222 if (invert ==
false) {
223 shift = AlignValue - ProportionalCoef*maxvalue;
224 function->SetParameter(0,shift);
225 function->SetParameter(1,ProportionalCoef);
227 shift = AlignValue + ProportionalCoef*maxvalue;
228 function->SetParameter(0,shift);
229 function->SetParameter(1,-ProportionalCoef);
241 printf(
"Info in <BaseCalib::CheckCalibration> histo NOT defined !!\n");
244 if (histo->GetDimension() > 1) {
245 printf(
"Info in <BaseCalib::CheckCalibration> Method not yet defined for Histogram Dimension >= 2 !!\n");
249 if (xmin == -1111) xmin = histo->GetXaxis()->GetXmin();
250 if (xmax == -1111) xmax = histo->GetXaxis()->GetXmax();
251 if (xmin > xmax) histo->GetXaxis()->SetRangeUser(xmax,xmin);
else histo->GetXaxis()->SetRangeUser(xmin,xmax);
254 TLine *line =
new TLine();
255 line->SetLineColor(color); line->SetLineStyle(2);
257 line->DrawLine(value,0.0,value,histo->GetMaximum());
262 Double_t xmin, Double_t xmax,
const Int_t color)
268 printf(
"Info in <BaseCalib::CheckCalibration> histo NOT defined !!\n");
271 if (histo->GetDimension() > 1) {
272 printf(
"Info in <BaseCalib::CheckCalibration> Method not yet defined for Histogram Dimension >= 2 !!\n");
276 if (xmin == -1111) xmin = histo->GetXaxis()->GetXmin();
277 if (xmax == -1111) xmax = histo->GetXaxis()->GetXmax();
278 if (xmin > xmax) histo->GetXaxis()->SetRangeUser(xmax,xmin);
else histo->GetXaxis()->SetRangeUser(xmin,xmax);
280 TArrayD array(nbvalue,values);
283 for (Int_t i=0 ; i<array.GetSize() ; i++) {
284 TLine *line =
new TLine();
285 line->SetLineColor(color); line->SetLineStyle(2);
286 line->DrawLine(array[i],0.0,array[i],histo->GetMaximum());
297 TString opt = SourceName;
300 Double_t *energies = 0;
303 if ( (!opt.CompareTo(
"co60")) or (!opt.CompareTo(
"60co")) ) {
304 energies =
new Double_t[2];
305 energies[0] = 1173.228;
306 energies[1] = 1332.492;
309 }
else if ( (!opt.CompareTo(
"eu152")) or (!opt.CompareTo(
"152eu")) ) {
310 energies =
new Double_t[7];
311 energies[0] = 121.7830;
312 energies[1] = 244.6920;
313 energies[2] = 344.2760;
314 energies[3] = 778.9030;
315 energies[4] = 964.1310;
316 energies[5] = 1112.1160;
317 energies[6] = 1408.0110;
319 }
else if ( (!opt.CompareTo(
"ba133")) or (!opt.CompareTo(
"133ba")) ) {
320 energies =
new Double_t[4];
321 energies[0] = 80.9971;
322 energies[1] = 276.3997;
323 energies[2] = 302.8510;
324 energies[3] = 356.0134;
326 }
else if ( (!opt.CompareTo(
"na22")) or (!opt.CompareTo(
"22na")) ) {
327 energies =
new Double_t[2];
329 energies[1] = 1274.537;
331 }
else if ( (!opt.CompareTo(
"k40")) or (!opt.CompareTo(
"40k")) ) {
332 energies =
new Double_t[1];
333 energies[0] = 1311.07;
335 }
else if ( (!opt.CompareTo(
"y88")) or (!opt.CompareTo(
"88y")) ) {
336 energies =
new Double_t[2];
337 energies[0] = 898.042;
338 energies[1] = 1836.063;
341 printf(
"Info in <BaseCalib::CheckCalibration> This source is not yet defined - use the manual method !!\n");
344 if (energies != 0)
delete [] energies;
352 printf(
"Info in <BaseCalib::DrawResults> function NOT defined !!\n");
356 printf(
"***************************************\n");
357 printf(
"*** RESULTS FROM CALIBRATION ***\n");
358 printf(
"***************************************\n");
359 for (Int_t i=0 ; i<
function->GetNpar() ; i++) {
360 printf(
"* par #%3i = %10.5f +- %10.5f *\n",i,function->GetParameter(i),
function->GetParError(i));
362 printf(
"***************************************\n");
printf("******************************************************************** \n")
void AddPoint(const Double_t channel, const Double_t energy)
static void CheckCalibration(TH1 *histo, const Double_t value, Double_t xmin=-1111, Double_t xmax=-1111, const Int_t color=2)
header file for the calibration facility
BaseCalib is a tool class.
void Calibrate(TF1 *function) const
void DrawResults(const TF1 *function) const
void AlignMax(TH1 *histo, TF1 *function, const Double_t AlignValue, const Bool_t invert=false, const Double_t xmin=0, const Double_t xmax=0)
Perform alignment of the maximum of a TH1 on a value.