GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGo4FitLinearTrans.cxx
Go to the documentation of this file.
1 // $Id: TGo4FitLinearTrans.cxx 2749 2020-04-16 10:05:15Z linev $
2 //-----------------------------------------------------------------------
3 // The GSI Online Offline Object Oriented (Go4) Project
4 // Experiment Data Processing at EE department, GSI
5 //-----------------------------------------------------------------------
6 // Copyright (C) 2000- GSI Helmholtzzentrum fuer Schwerionenforschung GmbH
7 // Planckstr. 1, 64291 Darmstadt, Germany
8 // Contact: http://go4.gsi.de
9 //-----------------------------------------------------------------------
10 // This software can be used under the license agreements as stated
11 // in Go4License.txt file which is part of the distribution.
12 //-----------------------------------------------------------------------
13 
14 #include "TGo4FitLinearTrans.h"
15 
16 #include <iostream>
17 
18 #include "TGo4FitParameter.h"
19 
21 
22 TGo4FitLinearTrans::TGo4FitLinearTrans(const char* iName, const char* iTitle, Int_t iAxis) :
23  TGo4FitAxisTrans(iName, iTitle), fiAxis(iAxis)
24 {
25  TGo4FitParameter* par = new TGo4FitParameter("CoefK","linear coefficient of calibration", 1.);
26  par->SetFixed(kTRUE);
27  AddPar(par);
28 
29  par = new TGo4FitParameter("CoefB","constant value of calibration", 0.);
30  par->SetFixed(kTRUE);
31  AddPar(par);
32 }
33 
35 }
36 
37 void TGo4FitLinearTrans::SetCoefByRange(Int_t nbins, Double_t y1, Double_t y2) {
38  Double_t k = (nbins>0) ? (y2-y1) / nbins : 0.;
39  SetCoef(k,y1);
40 }
41 
42 void TGo4FitLinearTrans::SetCoefByPoints(Double_t n1, Double_t y1, Double_t n2, Double_t y2) {
43  Double_t k = (n2-n1 != 0.) ? (y2-y1) / (n2 - n1) : 0.;
44  Double_t b = y1 - fdCoefK * n1;
45  SetCoef(k,b);
46 }
47 
48 void TGo4FitLinearTrans::Transformation(Double_t* scales, Int_t naxis) {
49  if ((scales!=0) && (naxis>GetAxis()))
50  scales[GetAxis()] = GetCoefK() * scales[GetAxis()] + GetCoefB();
51 }
52 
53 void TGo4FitLinearTrans::Print(Option_t* option) const {
54  std::cout << "Linear transformation of " << fiAxis << " axis" << std::endl;
56 }
virtual void Transformation(Double_t *scales, Int_t naxis)
virtual void Print(Option_t *option) const
void SetCoef(Double_t iCoefK, Double_t iCoefB)
void SetCoefByPoints(Double_t n1, Double_t y1, Double_t n2, Double_t y2)
void SetCoefByRange(Int_t nbins, Double_t y1, Double_t y2)
Int_t GetAxis() const
void SetFixed(Bool_t iFixed)
virtual void Print(Option_t *option) const
TGo4FitParameter * AddPar(TGo4FitParameter *par)