Commit 6c480de9 authored by Vratislav Chudoba's avatar Vratislav Chudoba

User interface was optimalized.

parent 6e1dd979
......@@ -17,12 +17,13 @@
ClassImp(AculCalibration);
AculCalibration::AculCalibration() : fA(0), fB(0)
AculCalibration::AculCalibration() : fEnergy(0), fEnergyInput(0), fA(0), fB(0), fPeak(0)
{
//default constructor
fCurrentHStack = NULL;
fCurrentHistList.IsOwner();
// todo: change size of fA and fB in some other place
fA.Set(32);
fB.Set(32);
......@@ -34,16 +35,20 @@ AculCalibration::AculCalibration() : fA(0), fB(0)
fFitMinSigma = 0.;
fFitPeakThreshold = 0.;
for(Int_t i = 0; i < DEFAULTNOPEAKS; i++) {
fEnergy[i] = 0;
}
fDeadLayer = 0.;
/*for(Int_t i = 0; i < DEFAULTNOPEAKS; i++) {
// fEnergy[i] = 0.;
// fEnergyInput[i] = 0.;
// fPeak[i] = 0.;
}*/
fCalInformation = 0;
Reset();
}
AculCalibration::AculCalibration(const char* parfile)
AculCalibration::AculCalibration(const char* calfile) : fEnergy(0), fEnergyInput(0), fPeak(0)
{
//constructor which fills fAOld, fBOld, fC, fD from file parfile
......@@ -58,14 +63,26 @@ AculCalibration::AculCalibration(const char* parfile)
fFitMinSigma = 0.;
fFitPeakThreshold = 0.;
for(Int_t i = 0; i < DEFAULTNOPEAKS; i++) {
fEnergy[i] = 0;
}
/*for(Int_t i = 0; i < DEFAULTNOPEAKS; i++) {
// fEnergy[i] = 0.;
// fEnergyInput[i] = 0.;
// fPeak[i] = 0.;
}*/
fCalInformation = 0;
SetCalibrationParameters(parfile);
SetCalibrationParameters(calfile);
}
void AculCalibration::Reset()
{
for (Int_t j = 0; j < fA.GetSize(); j++) {
fA[j] = 0;
fB[j] = 0;
}
return;
}
AculCalibration::~AculCalibration()
......@@ -77,6 +94,13 @@ AculCalibration::~AculCalibration()
}
void AculCalibration::Init() {
SetELosses();
SetInputParameters();
SetCalEnergies();
}
Int_t AculCalibration::SearchPeaks(const TH1 *hin, Double_t sigma, Option_t *option, const Int_t searchedpeaks)
{
//Function searching peaks in inputed TH1 spectrum and selects the peaks in the histogram.
......@@ -140,7 +164,7 @@ Int_t AculCalibration::PeaksFitting(TH1* hSpectrum, Option_t* option, Double_t s
return 1;
}
Int_t peaksNumber = SearchPeaks(hSpectrum, sigmamin, "", kRaNOPEAKS);
const Int_t peaksNumber = SearchPeaks(hSpectrum, sigmamin, "", kRaNOPEAKS);
if (peaksNumber != kRaNOPEAKS) {
Info("PeaksFitting", "In histogram %s was found %d peaks", hSpectrum->GetName(), peaksNumber);
......@@ -231,7 +255,8 @@ Int_t AculCalibration::PeaksFitting(TH1* hSpectrum, Option_t* option, Double_t s
//peaks sorting
Int_t j[peaksNumber];
TMath::Sort(peaksNumber, peak, j, kFALSE);
for (Int_t i = 0; i < 4; i++) {
fPeak.Set(peaksNumber);
for (Int_t i = 0; i < peaksNumber; i++) {
fPeak[i] = peak[j[i]];
}
......@@ -272,97 +297,61 @@ Int_t AculCalibration::PeaksFitting(TH1* hSpectrum, Option_t* option, Double_t s
// return 1;
//}
Bool_t AculCalibration::SetInputParameters(const char* inputparfile)
{
const Int_t lineLength = 400;
Char_t line[lineLength];
Char_t parameter[100];
Char_t identificator[100];
ifstream fipr;
fipr.open(inputparfile);
if (!fipr.is_open()) {
Error("SetInputsParameters", "File with input parameters was not opened");
return kFALSE;
}
while (!fipr.eof()) {
fipr.getline(line, lineLength);
if (strlen(line) == 0) {
continue;
}
sscanf(line, "%s %s", parameter, identificator);
if ( strcmp(identificator, "nopeaks") == 0 ) {
kRaNOPEAKS = static_cast<Int_t>(atoi(parameter));
for (Int_t i = 0; i < kRaNOPEAKS; i++) {
fipr.getline(line, lineLength);
sscanf(line, "%s", parameter);
fEnergy[i] = static_cast<Double_t>(atof(parameter));
}
}//if
if ( strcmp(identificator, "lowerchannel") == 0 ) {
sscanf(line, "%s", parameter);
fLowerChannel = static_cast<Double_t>(atof(parameter));
}
if ( strcmp(identificator, "upperchannel") == 0 ) {
sscanf(line, "%s", parameter);
fUpperChannel = static_cast<Double_t>(atof(parameter));
}
if ( strcmp(identificator, "lowerpeakhight") == 0 ) {
sscanf(line, "%s", parameter);
fLowerPeakRelativeHight = static_cast<Double_t>(atof(parameter));
}
void AculCalibration::SetParFileName(const char *parfile) {
fParFileName = parfile;
}
if ( strcmp(identificator, "upperpeakhight") == 0 ) {
sscanf(line, "%s", parameter);
fUpperPeakRelativeHight = static_cast<Double_t>(atof(parameter));
}
void AculCalibration::SetELosses() {
if ( strcmp(identificator, "peakpositiontolerance") == 0 ) {
sscanf(line, "%s", parameter);
fPeakPositionTolerance = static_cast<Double_t>(atof(parameter));
}
Info("AculCalibration::SetELosses", "Combination of aplha particle with silicon material only.");
fAlphaSi.SetEL(1, 2.321); // density in g/cm3
fAlphaSi.AddEL(14., 28.086, 1); //Z, mass
// mSi.SetZP(1., 1.); //protons
fAlphaSi.SetZP(2., 4.); //alphas, Z, A
fAlphaSi.SetEtab(100000, 200.); // ?, MeV calculate ranges
fAlphaSi.SetDeltaEtab(300);
}
if ( strcmp(identificator, "fitfunctionlinewidth") == 0 ) {
sscanf(line, "%s", parameter);
fFitFuncLineWidth = static_cast<Width_t>(atoi(parameter));
}
void AculCalibration::SetCalEnergies() {
if ( strcmp(identificator, "minfitsigma") == 0 ) {
sscanf(line, "%s", parameter);
fFitMinSigma = static_cast<Double_t>(atof(parameter));
if (fDeadLayer<=0.) {
Warning("AculCalibration::SetCalEnergies", "Dead layer was set equal or less than 0.");
for(Int_t i = 0; i < kRaNOPEAKS; i++) {
fEnergy[i] = fEnergyInput[i];
}
if ( strcmp(identificator, "fithightthreshold") == 0 ) {
sscanf(line, "%s", parameter);
fFitPeakThreshold = static_cast<Double_t>(atof(parameter));
Info("AculCalibration::SetCalEnergies", "Energies used for calibration are the same as input file.");
return;
}
for(Int_t i = 0; i < kRaNOPEAKS; i++) {
fEnergy[i] = fAlphaSi.GetE(fEnergyInput[i], fDeadLayer);
}
Info("AculCalibration::SetCalEnergies", "Energies used for calibration considering %f mcm dead layer were set.", fDeadLayer);
fipr.close();
return kTRUE;
return;
}
void AculCalibration::PrintInputParameters()
{
//print alpha source parameters
cout << "Number of peaks: " << kRaNOPEAKS << endl
<< endl;
cout << "AculCalibration::PrintInputParameters:" << endl;
cout << "\tNumber of peaks: " << kRaNOPEAKS << endl;
for (Int_t i = 0; i < kRaNOPEAKS; i++) {
cout << "\t\tfEnergyInput[" << i << "] = " << fEnergyInput[i] << endl;
}
cout << "\tEnergies used for calibration:" << endl;
cout << "\t(deadLayer: " << fDeadLayer << " mcm)" << endl;
// Info("AculCalibration::PrintInputParameters", "Number of peaks: %d", kRaNOPEAKS);
for (Int_t i = 0; i < kRaNOPEAKS; i++) {
cout << "fEnergy[" << i << "] = " << fEnergy[i] << endl;
cout << "\t\tfEnergy[" << i << "] = " << fEnergy[i] << endl;
}
cout << "\tlowerChannel: " << fLowerChannel << "; upperChannel: " << fUpperChannel << ";" << endl;
cout << "\tlowerPeakHight: " << fLowerPeakRelativeHight << "; upperPeakHight: " << fUpperPeakRelativeHight << ";" << endl;
cout << "\tfitHightThreshold: " << fFitPeakThreshold << "; minFitSigma: " << fFitMinSigma << ";" << endl;
cout << "\tpeakPositionTolerance: " << fPeakPositionTolerance << ";" << endl;
cout << "\tfitFunctionLineWidth: " << fFitFuncLineWidth << ";" << endl;
return;
......@@ -723,7 +712,7 @@ Bool_t AculCalibration::CalculateCalibParameters(const char* inputfile, const ch
//promenne potrebne pro fitovani: presunout nize
//pohlidat delete
TF1 *calFunction = new TF1("calib", "pol1", 0, 1000); //predelat jako lokalni promennou fce (nebo snad tridy?)
TGraph *calGraph = new TGraph(kRaNOPEAKS, fPeak, fEnergy); //lokalni promenna, dohodit pocet vstupu pomoci parametru
TGraph *calGraph = new TGraph(kRaNOPEAKS, fPeak.GetArray(), fEnergy.GetArray()); //lokalni promenna, dohodit pocet vstupu pomoci parametru
TString detectorChannel;
TString histName;
......@@ -839,7 +828,7 @@ Bool_t AculCalibration::CalculateCalibParameters(const char* inputfile, const ch
}
void AculCalibration::CalibrateRawSpectra() {
//todo: implement this function
//function parameters:
const char* iFileName = "clb01_0001.root";
const char* treeName = "AnalysisxTree";
......@@ -1240,10 +1229,7 @@ void AculCalibration::ShowEnergySpectra(const char *filename, TCanvas* energyCan
fHEnergyStack.Add(hDraw);
}
}
// if (fHEnergyStack) {
// if (opt.Contains("+")) { fHEnergyStack->Draw(); }
// else { fHEnergyStack->Draw("nostack"); }
// }
if (opt.Contains("+")) { fHEnergyStack.Draw(); }
else { fHEnergyStack.Draw("nostack"); }
}
......@@ -1270,52 +1256,18 @@ void AculCalibration::ShowEnergySpectra(const char *filename, TCanvas* energyCan
hDraw->SetAxisRange(xaxismin, xaxismax, "X");
hDraw->Draw();
hDraw->SetDirectory(0);
// if (fHEnergyList) {
// fHEnergyList->Add(hDraw);
// }
fHEnergyList.Add(hDraw);
}
}//else
fr->Close();
// fFileName = filename;
// fFileName.Resize(fFileName.Length() - 6);
// fFileName.Append(".cal", 4);
energyCanvas->Update();
return;
}
void AculCalibration::DivideCanvas(TCanvas *c1, Int_t inputs) {}
Bool_t AculCalibration::AddCalFileToList(const char* calfilelist)
{
//this function does not work at the moment
//some problem with TString object fFileName
TString fl = calfilelist;
fl.ToLower();
ofstream fw;
fw.open(fl.Data(), ofstream::app);
if (!fw.is_open()) {
cout << "File " << fl.Data() << " was not opened" << endl;
return kFALSE;
}
// fw << fFileName.Data() << endl;
fw.close();
return kTRUE;
}
void AculCalibration::ClearHistograms(Option_t* option)
{
//clear THStack and TObjArray members
......@@ -1334,110 +1286,113 @@ void AculCalibration::ClearHistograms(Option_t* option)
}
void AculCalibration::MakeCalibrationFile(Char_t* calibrationfile, Char_t *calfilelist)
{
//calibrationfile: file with calibration parameters to be created
//calfilelist: file containing list of existing text files with calibration parameters
void AculCalibration::DeleteStacks(Option_t* option) {
ifstream calListR;
calListR.open(calfilelist);
if( !calListR.is_open() ) {
cout << "File with list of calibration files was not opened" << endl;
return;
if (fCurrentHStack) {
delete fCurrentHStack;
fCurrentHStack = NULL;
}
//asi fce Reset()
fCurrentHistList.Delete();
for (Int_t j = 0; j < ADDRESSNUMBER; j++) {
fA[j] = 0;
fB[j] = 0;
return;
}
void AculCalibration::SetInputParameters() {
// TString iFile = inputparfile;
if (fParFileName.Length()==0) {
Warning("AculCalibration::SetInputsParameters", "File with input parameters was not set.");
return;
}
const Int_t lineLength = 100;
char line[lineLength];
char filename[50];
// ifstream calFileR;
Int_t crate, /*i,*/ j, id;
// int crate, i, j, id;
char cA[40], cB[40], cSigma[40];
while (!calListR.eof()) {
calListR.getline(line, lineLength);
// cout << line << endl;
sscanf(line, "%s", filename);
cout << filename << endl;
ifstream calFileR;
calFileR.open(filename);
if (calFileR.is_open()) {
cout << filename << " processing" << endl;
calFileR.seekg(0);
while (!calFileR.eof()) {
// cout << " in inner while" << endl;
calFileR.getline(line, lineLength);
sscanf(line, "%d %d %s %s %d %s", &crate, /*&i,*/ &j, cA, cB, &id, cSigma);
// cout << line << endl;
if (id == 0) {
fA[j] = static_cast<Double_t>(atof(cA));
fB[j] = static_cast<Double_t>(atof(cB));
// fMeanSigma[i][j] = static_cast<Double_t>(atof(cSigma));
cout << fA[j] << "\t" << fB[j] << endl;
}//if
}//while
calFileR.close();
cout << "calFileR was closed" << endl << endl;
}//if
}//while
const Int_t lineLength = 400;
Char_t line[lineLength];
Char_t parameter[100];
Char_t identificator[100];
calListR.close();
ofstream CalibFileW;
CalibFileW.open(calibrationfile);
if (!CalibFileW.is_open()) {
cout << "Calibration file was not opened" << endl;
ifstream fipr;
fipr.open(fParFileName.Data());
if (!fipr.is_open()) {
Error("AculCalibration::SetInputsParameters", "File with input parameters \"%s\" was not opened.", fParFileName.Data());
return;
}
for (Int_t j = 0; j < ADDRESSNUMBER; j++) {
if (fA[j] != 0) {
CalibFileW << std::right
<< setw(2) << "3"
<< setw(4) << j
<< setw(12) << fA[j]
<< setw(12) << fB[j]
// << setw(10) << fMeanSigma[i][j]
<< endl;
Info("AculCalibration::SetInputsParameters", "File with input parameters \"%s\" will be processed.", fParFileName.Data());
while (!fipr.eof()) {
fipr.getline(line, lineLength);
if (strlen(line) < 2) {
continue;
}
sscanf(line, "%s %s", parameter, identificator);
if ( strcmp(identificator, "noPeaks") == 0 ) {
kRaNOPEAKS = static_cast<Int_t>(atoi(parameter));
fEnergyInput.Set(kRaNOPEAKS);
for (Int_t i = 0; i < kRaNOPEAKS; i++) {
fipr.getline(line, lineLength);
sscanf(line, "%s", parameter);
fEnergyInput[i] = static_cast<Double_t>(atof(parameter));
}
continue;
}//if
if ( strcmp(identificator, "lowerChannel") == 0 ) {
sscanf(line, "%s", parameter);
fLowerChannel = static_cast<Double_t>(atof(parameter));
}
CalibFileW.close();
if ( strcmp(identificator, "upperChannel") == 0 ) {
sscanf(line, "%s", parameter);
fUpperChannel = static_cast<Double_t>(atof(parameter));
}
return;
if ( strcmp(identificator, "lowerPeakHight") == 0 ) {
sscanf(line, "%s", parameter);
fLowerPeakRelativeHight = static_cast<Double_t>(atof(parameter));
}
}
if ( strcmp(identificator, "upperPeakHight") == 0 ) {
sscanf(line, "%s", parameter);
fUpperPeakRelativeHight = static_cast<Double_t>(atof(parameter));
}
void AculCalibration::DeleteStacks(Option_t* option) {
if ( strcmp(identificator, "peakPositionTolerance") == 0 ) {
sscanf(line, "%s", parameter);
fPeakPositionTolerance = static_cast<Double_t>(atof(parameter));
}
if (fCurrentHStack) {
delete fCurrentHStack;
fCurrentHStack = NULL;
if ( strcmp(identificator, "fitFunctionLineWidth") == 0 ) {
sscanf(line, "%s", parameter);
fFitFuncLineWidth = static_cast<Width_t>(atoi(parameter));
}
fCurrentHistList.Delete();
if ( strcmp(identificator, "minFitSigma") == 0 ) {
sscanf(line, "%s", parameter);
fFitMinSigma = static_cast<Double_t>(atof(parameter));
}
return;
}
if ( strcmp(identificator, "fitHightThreshold") == 0 ) {
sscanf(line, "%s", parameter);
fFitPeakThreshold = static_cast<Double_t>(atof(parameter));
}
void AculCalibration::Reset()
{
//reset calibration parameters fAOld, fBOld, fC, fD to zero
if ( strcmp(identificator, "deadLayer") == 0 ) {
sscanf(line, "%s", parameter);
fDeadLayer = static_cast<Double_t>(atof(parameter));
}
for (Int_t j = 0; j < ADDRESSNUMBER; j++) {
fA[j] = 0;
fB[j] = 0;
// fC[0][j] = 0.;
// fD[0][j] = 0.;
// fMeanSigma[i][j] = 0;
}
fipr.close();
return;
}
void AculCalibration::DivideCanvas(TCanvas *c1, Int_t inputs) {}
......@@ -22,6 +22,8 @@
#include <iomanip>
#include <sstream>
#include "../TELoss/TELoss.h"
#define DEFAULTNOPEAKS 20
#define ADDRESSNUMBER 32
......@@ -44,9 +46,9 @@ public:
//???? - pocet nespravne zkalibrovanych spekter
//fEnergy[4] - tabulka s energiemi piku, nacita se zvenci
//private:
private:
//todo: following variables should be deleted
// TObjArray *fHRawList; //list of raw histograms, list is set to owner
TObjArray fHRawList; //list of raw histograms, list is set to owner
TObjArray fHAnalyzedList; //list of fitted and analyzed histograms, list is set to owner
......@@ -74,20 +76,17 @@ public:
Double_t fFitMinSigma; //pouziva se, private
Double_t fFitPeakThreshold; //pouziva se, private, prozkoumat, k cemu vlastne slouzi ve fci ShowPeaks, popremyslet o vhodnem prednastaveni v konstruktoru
//these variables are the main for the class
// Double_t fAOld[BLOCKSNUMBER][ADDRESSNUMBER]; //calibration parameter, f(x) = fAOld*x + fBOld
// Double_t fBOld[BLOCKSNUMBER][ADDRESSNUMBER]; //calibration parameter, f(x) = fAOld*x + fBOld
// Double_t fC[BLOCKSNUMBER][ADDRESSNUMBER]; //treti kalibracni parametr, jine zavislosti nez pol1
// Double_t fD[BLOCKSNUMBER][ADDRESSNUMBER]; //ctvrty kalibracni parametr
private:
TArrayD fA;
TArrayD fB;
//these variables are the main for the class
TArrayD fA; //calibration parameter, f(x) = fA*x + fB
TArrayD fB; //calibration parameter, f(x) = fA*x + fB
// TArrayD fC;
// TArrayD fD;
TELoss fAlphaSi;
public:
//smysl je velmi pochybny
//it is very doubtful that we need this class variable
TFile *fCalInformation;
Double_t GetA(Int_t i); //to obtain calib parameter A
......@@ -99,8 +98,11 @@ private:
public:
AculCalibration();
//default constructor
AculCalibration(const char* parfile); //
AculCalibration(const char* calfile); //
virtual ~AculCalibration();
ClassDef(AculCalibration, 1);
void Init();
Bool_t SetInputParameters(const char* inputparfile = "parforcal.par");
// Function which loads text file containing parameters for calibration
......@@ -226,17 +228,19 @@ public:
//dodelat funkce TTree* Get...(...) pro raw, anal i E spectra
Bool_t AddCalFileToList(const char* calfilelist = "CalFileList.log");
// Bool_t AddCalFileToList(const char* calfilelist = "CalFileList.log");
void ClearHistograms(Option_t* option = "");
void DeleteStacks(Option_t* option = "");
void MakeCalibrationFile(Char_t* calibrationfile, Char_t* calfilelist);
// void MakeCalibrationFile(Char_t* calibrationfile, Char_t* calfilelist);
void Reset();
//reset calibration parameters fA, fB to zero
//private:
private:
void SetELosses();
ClassDef(AculCalibration, 1);
};
......@@ -2,7 +2,7 @@
# AculData input with some variables
################################################################################
ACULDATALIBS := -lCore -lCint -lRIO -lTree -lNet -lThread -lHist -lMatrix -lMathCore -lGpad -lGraf -lSpectrum
ACULDATALIBS := -lCore -lCint -lRIO -lTree -lNet -lThread -lHist -lMatrix -lMathCore -lGpad -lGraf -lSpectrum -lTELoss
# Add inputs and outputs from these tool invocations to the build variables
ACULDATA_HEADERS += \
......
{
gSystem->Load("/home/dariak/AculUtils/libAculData.so");
// gSystem->Load("/home/vratik/workspace/AculUtils/libAculData.so");
// gSystem->Load("/home/dariak/AculUtils/libAculData.so");
gSystem->Load("/home/vratik/workspace/AculUtils/libAculData.so");
AculCalibration cal;
cal.SetInputParameters(); //from .par
cal.SetInputParameters("../../parforcal.par"); //from .par
// cal.CalculateCalibParameters("clb08_0001.root", "SQ22", "AnalysisxTree", 100, 4095);
cal.CalculateCalibParameters("clb08_0001.root", "SQ22", "AnalysisxTree", 100, 4095);
cal.CalculateCalibParameters("../../clb_raw_files/clb08_0001.root", "SQ22", "AnalysisxTree", 100, 4095);
// CalculateCalibParameters(const char* inputfile, const char* block, const Int_t address, const char* treename, Int_t lowerchannel = 0, Int_t upperchannel = 4095, Int_t nEBins = 1000, Int_t lowersubaddress = 0, Int_t uppersubaddress = ADDRESSNUMBER-1);
TFile fr("SQ22[]E.root");
cout << fr.GetListOfKeys()->GetEntries() << " histograms" << endl;
TList *histList = fr.GetListOfKeys();
TH1 *hWork = 0;
for (Int_t i = 0; i < 32; i++)
{
fr.GetObject(histList->At(i)->GetName(), hWork);
cal->PeaksFitting(hWork);
}
// TFile fr("SQ22[]E.root");
// cout << fr.GetListOfKeys()->GetEntries() << " histograms" << endl;
// TList *histList = fr.GetListOfKeys();
// TH1 *hWork = 0;
// for (Int_t i = 0; i < 32; i++)
// {
// fr.GetObject(histList->At(i)->GetName(), hWork);
// cal->PeaksFitting(hWork);
// }
}
......@@ -61,10 +61,10 @@ $(TELOSS)/TELossCint.cpp:
-@echo ' '
#*.so files
libAculData.so: $(ACULDATAOBJS)
libAculData.so: libTELoss.so $(ACULDATAOBJS)
@echo 'Building target: $@'
@echo 'Invoking: GCC C++ Linker'
$(CC) -L $(ROOTLIBS) -shared -o"libAculData.so" $(ACULDATAOBJS) $(ACULDATALIBS)
$(CC) -L . -L $(ROOTLIBS) -shared -o"libAculData.so" $(ACULDATAOBJS) $(ACULDATALIBS)
@echo 'Finished building target: $@'
@echo ' '
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment