AculCalParsScintFile.cpp 3.79 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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
/*
 * AculCalParsScintFile.cpp
 *
 *  Created on: Oct 25, 2016
 *      Author: vratik
 */

#include "AculCalParsScintFile.h"

AculCalParsScintFile::AculCalParsScintFile() {
	// TODO Auto-generated constructor stub
//	fFileID = 0;
	fNoCrystals = 0;
	fE = 0;
	Init();
}

AculCalParsScintFile::~AculCalParsScintFile() {
	// TODO Auto-generated destructor stub
}

void AculCalParsScintFile::Init() {
//	fNoCrystals = 0;
//	fE = 0;

	fPeakMin.resize(fNoCrystals);
	fPeakMax.resize(fNoCrystals);

	fCutName.resize(0);
}


const char* AculCalParsScintFile::GetCutName(Int_t i) {

	if ( i >= (Int_t)fCutName.size() ) {
		cout << "\"AculCalParsScintFile::GetCutName\" Cut number " << i
				<< " is not available. Maximal i can be set as "
				<< fCutName.size() - 1 << "." << endl;
	}
	return fCutName[i].Data();
}

TCutG* AculCalParsScintFile::GetCut(Int_t i) {
	if ( i >= (Int_t)fCut.size() ) {
		cerr << "\"AculCalParsScintFile::GetCut\"  index i cannot be higher than " << fCut.size() - 1 << endl;
		return 0;
	}
	return &fCut[i];
}

TCutG* AculCalParsScintFile::GetCut(const char* cutName) {

	const TString cName = cutName;

	for (Int_t i = 0; i <= (Int_t)fCut.size(); i++) {
		if (cName.EqualTo(fCutName[i])) { return &fCut[i]; }
	}


	cerr << "\"AculCalParsScint::GetCut\"  cut \"" << cutName << "\" was not found." << endl;
	return 0;
}

Int_t AculCalParsScintFile::GetPeakMin(Int_t crystalID) {
	if ( crystalID >= (Int_t)fPeakMin.size() ) {
		cerr << "\"AculCalParsScintFile::GetPeakMin\"  index \"crystal\" cannot be higher than "
				<< fPeakMin.size() - 1 << endl;
		return 0;
	}

	return fPeakMin[crystalID];
}

Int_t AculCalParsScintFile::GetPeakMax(Int_t crystalID) {
	if ( crystalID >= (Int_t)fPeakMax.size() ) {
		cerr << "\"AculCalParsScintFile::GetPeakMax\"  index \"crystal\" cannot be higher than "
				<< fPeakMax.size() - 1 << endl;
		return 0;
	}

	return fPeakMax[crystalID];
}

void AculCalParsScintFile::SetRawFileName(const char* filename) {
	fFileName = filename;
//	fFileID++;
}

void AculCalParsScintFile::SetCutFileName(const char* filename) {
	fCutsFileName = filename;
}

void AculCalParsScintFile::SetNoCuts(Int_t noCuts) {
	fCutName.resize(noCuts);
}

void AculCalParsScintFile::SetCutName(Int_t i, const char* cutname) {
	if ( i >= (Int_t)fCutName.size() ) {
		cout << "\"AculCalParsScintFile::SetCutName\" vector for cut names is not enough large. Maximal i can be set as "
				<< fCutName.size() - 1 << "." << endl;
	}
	fCutName[i] = cutname;
}

void AculCalParsScintFile::SetPeakMin(Int_t crystalID, Double_t limit) {
	if ( crystalID>=(Int_t)fPeakMin.size() ) {
		cerr << "\"AculCalParsScintFile::SetPeakMin\" maximal allowed crystal ID is " << fPeakMin.size() << "."<< endl;
		return;
	}
	fPeakMin[crystalID] = limit;
}

void AculCalParsScintFile::SetPeakMax(Int_t crystalID, Double_t limit) {
	if ( crystalID>=(Int_t)fPeakMax.size() ) {
		cerr << "\"AculCalParsScintFile::SetPeakMax\" maximal allowed crystal ID is " << fPeakMax.size() << "."<< endl;
		return;
	}
	fPeakMax[crystalID] = limit;
}

void AculCalParsScintFile::LoadCuts() {

	if (fCutsFileName.Length() == 0) {
		printf("AculCalParsScintFile::LoadCuts: Name of file (*.root) with cuts was not provided.\n");
		printf("AculCalParsScintFile::LoadCuts: No cuts has been loaded.\n");
		return;
	}

	TFile cutFile(fCutsFileName.Data(), "READ");
	if(!cutFile.IsOpen()) {
		cerr << "\"AculCalParsScintFile::LoadCuts\" File " << fCutsFileName.Data()
				<< " was not open and no cuts were loaded." << endl;
		return;
	}

	for (Int_t i = 0; i < (Int_t)fCutName.size(); i++) {
		TCutG *currentCut = (TCutG*)cutFile.Get(fCutName[i]);
		if (!currentCut) {
			cout << "\"AculCalParsScintFile::LoadCuts\" Cut \"" << fCutName[i]
				<< "\" was not found in file " << fCutsFileName << "." << endl;
			continue;
		}
		fCut.push_back(*currentCut);
	}

}

/*void AculCalParsScintFile::Reset() {

}*/