CalPars.cpp 1.73 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
#include "CalPars.h"

ClassImp(CalPars);


CalPars::CalPars(const char* clbfile) {

	ReadParFile(clbfile);

}

CalPars::~CalPars() {

	printf("CalPars::Destructor called.\n");

}

Double_t CalPars::GetA(Int_t i) {

	if (i >= fA.GetSize()) {
		return 0.;
	}
	return fA[i];
}

Double_t CalPars::GetB(Int_t i) {

	if (i >= fB.GetSize()) {
		return 0.;
	}
	return fB[i];
}

Double_t CalPars::GetC(Int_t i) {

	if (i >= fC.GetSize()) {
		return 0.;
	}
	return fC[i];
}

void CalPars::ReadParFile(const char* clbfile) {

	clbFile = clbfile;	

	std::ifstream infile(clbfile);
	if ( !infile.is_open() ) {
		printf("CalPars::ReadParFile: File %s was not open.\n", clbfile);
		printf("CalPars::ReadParFile: Calibration parameters are empty!!!\n");
		return;
	}	

	TString line;
	Int_t nopars;
	Double_t a, b;
	Int_t c;		//threshold

	printf("CalPars::ReadParFile: File %s was open.\n", clbfile);

	line.ReadLine(infile);
	sscanf(line.Data(), "%*d %d", &nopars);
//	Info("CalPars::ReadParFile", "%d calibration parameters will be loaded", nopars);
	printf("CalPars::ReadParFile: %d calibration parameters will be loaded\n", nopars);

	fA.Set(nopars);
	fB.Set(nopars);
	fC.Set(nopars);

	for (Int_t i = 0; i <nopars; i++) {
		line.ReadLine(infile);

//		if ( line.BeginsWith("#") ) continue;

//		cout << line.Data() << endl;
		sscanf(line.Data(), "%lf %lf %d", &b, &a, &c);
		fA[i] = a;
		fB[i] = b;
		fC[i] = c;
//		printf("fA[%d]: %f,\tfB[%d]: %f\n", i, fA[i], i, fB[i]);
//		printf("fA[%d]: %f,\tfB[%d]: %f\n\n", i, a, i, b);
	}

}

void CalPars::PrintClbPars() {

	printf("CalPars::PrintClbPars: %d calibration parameters from %s file.\n", fA.GetSize(), clbFile.Data());
	
	for (Int_t i = 0; i<fA.GetSize(); i++) {
		printf("%d\t%f\t%f\t%f\n", i, GetA(i), GetB(i), GetC(i));
	}

}