Commit 7be6accf authored by Vratislav Chudoba's avatar Vratislav Chudoba

Function AculCalibration::FindEnergyPeaks(...) added.

parent 28706779
......@@ -147,18 +147,6 @@ Int_t AculCalibration::PeaksFitting(TH1* hSpectrum, Option_t* option, Double_t s
return 1;
}
//creation of output text file with positions of peaks in MeV
TString workFile;
workFile.Form("energies.txt");
ofstream outenergfile;
outenergfile.open(workFile.Data());
if (!outenergfile.is_open()) {
Error("PeaksFitting", "Output file %s was not opened", workFile.Data());
return 0;
}
//should be optional output
Info("PeaksFitting", "Number of peaks in %s: %d", hSpectrum->GetName(), peaksNumber);
......@@ -268,8 +256,6 @@ Int_t AculCalibration::PeaksFitting(TH1* hSpectrum, Option_t* option, Double_t s
}
}//for
outenergfile << hSpectrum->GetName()<<"\t"<< fPeak[0] <<"\t"<< fPeak[1] <<"\t"<< fPeak[2] <<"\t"<< fPeak[3] <<endl;
outenergfile.close();
return 0;
}
......@@ -410,7 +396,8 @@ Bool_t AculCalibration::SetCalibrationParameters(const char* calparfile)
char line[lineLength];
// Int_t crate;
char crate[100];
Int_t i, j;
// Int_t i, j;
Int_t j;
char cA[40], cB[40], cC[40], cD[40];
//open file with calibration parameters
......@@ -432,8 +419,8 @@ Bool_t AculCalibration::SetCalibrationParameters(const char* calparfile)
sscanf(line, "%s %d %s %s %s %s", crate, /*&i*,*/ &j, cA, cB, cC, cD); //
fA[j] = atof(cA);
fB[j] = atof(cB);
fC[0][j] = atof(cC);
fD[0][j] = atof(cD);
// fC[0][j] = atof(cC);
// fD[0][j] = atof(cD);
}
}
......@@ -445,7 +432,7 @@ void AculCalibration::PrintCalibrationParameters(const Int_t blockmin, const Int
{
// for (Int_t i = blockmin; i <= blockmax; i++) {
for (Int_t j = 0; j < ADDRESSNUMBER; j++) {
cout << "C3[" << "used to be blocksnumber" << "][" << j << "]" << setw(10) << fA[j] << setw(10) << fB[j] << setw(10) << fC[j] << setw(10) << fD[j] << endl;
cout << "C3[" << "used to be blocksnumber" << "][" << j << "]" << setw(10) << fA[j] << setw(10) << fB[j] /*<< setw(10) << fC[j] << setw(10) << fD[j]*/ << endl;
}
//}
}
......@@ -847,7 +834,7 @@ Bool_t AculCalibration::CalculateCalibParameters(const char* inputfile, const ch
fw->cd();
hEnergy->Write();
}//for
}//for; detector channels
fw->Close();
fr->Close();
......@@ -1100,6 +1087,43 @@ void AculCalibration::CalibrateRawSpectra(const char* inputfile, const char* blo
}
void AculCalibration::FindEnergyPeaks(TCanvas *c1, const char* ifile, const char* outfile) {
TString iFile = ifile;
TFile *fr = new TFile(iFile.Data());
if ( !fr->IsOpen() ) {
Error("FindEnergyPeaks", "File %s was not opened and won't be processed.", iFile.Data());
return;
}
TList *histList = fr->GetListOfKeys();
Info("FindEnergyPeaks", "%d keys found in file %s.", histList->GetEntries(), fr->GetName());
//creation of output text file with positions of peaks in MeV
TString workFile = outfile;
ofstream ofile;
ofile.open(workFile.Data());
if (!ofile.is_open()) {
Error("PeaksFitting", "Output file %s was not opened", workFile.Data());
return;
}
TH1 *hWork = 0;
c1->Clear();
c1->Divide(6, 6);
for (Int_t i = 0; i < histList->GetEntries(); i++) {
fr->GetObject(histList->At(i)->GetName(), hWork);
c1->cd(i+1);
PeaksFitting(hWork);
hWork->Draw();
ofile << hWork->GetName()<<"\t"<< fPeak[0] <<"\t"<< fPeak[1] <<"\t"<< fPeak[2] <<"\t"<< fPeak[3] <<endl;
}
ofile.close();
}
void AculCalibration::ShowAnalyzedSpectra(const char *filename, TCanvas* fittedRawCanvas, Int_t xaxismin, Int_t xaxismax, Int_t subaddress)
{
......@@ -1422,8 +1446,8 @@ void AculCalibration::Reset()
for (Int_t j = 0; j < ADDRESSNUMBER; j++) {
fA[j] = 0;
fB[j] = 0;
fC[0][j] = 0.;
fD[0][j] = 0.;
// fC[0][j] = 0.;
// fD[0][j] = 0.;
// fMeanSigma[i][j] = 0;
}
//}
......
......@@ -78,8 +78,8 @@ public:
//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
// Double_t fC[BLOCKSNUMBER][ADDRESSNUMBER]; //treti kalibracni parametr, jine zavislosti nez pol1
// Double_t fD[BLOCKSNUMBER][ADDRESSNUMBER]; //ctvrty kalibracni parametr
private:
TArrayD fA;
......@@ -94,7 +94,7 @@ public:
Double_t GetA(Int_t i); //to obtain calib parameter A
Double_t GetB(Int_t i); //to obtain calib parameter B
//private:
private:
Double_t fPeak[DEFAULTNOPEAKS]; //v teto promenne je ulozena momentalni hodnota piku v kanalech, zejmena v jedne fci, mozno udelat ji jako lokalni, bude navratovou hodnotou fce PeaksFitting, predelat delku pole
public:
......@@ -180,13 +180,18 @@ public:
void CalibrateRawSpectra(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);
// Bool_t EnergyPositions(const char* inputfile, const char* block,
void FindEnergyPeaks(TCanvas *c1, const char* ifile, const char* outfile);
// const char* inputfile, const char* block,
// const Int_t address, const Int_t address, const char* treename, Int_t lowerchannel = 0,
// Int_t upperchannel = 4095, Int_t lowersubaddress = 0, Int_t uppersubaddress = ADDRESSNUMBER-1);
Int_t PeaksFitting(TH1* hSpectrum, Option_t* option = "", Double_t sigmamin = 2);
//return values:
// 0: OK
// 1: something wrong
// 2: something other wrong
//
//possible options: "V", "Q", ""
//possible options: "V", "Q", "", ?"gp"?
Int_t SearchPeaks(const TH1 *hin, Double_t sigma = 2, Option_t *option = "", const Int_t searchedpeaks = 100);
......
{
gSystem->Load("/home/dariak/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.CalculateCalibParameters("clb08_0001.root", "SQ22", "AnalysisxTree", 100, 4095);
// cal.CalculateCalibParameters("clb08_0001.root", "SQ22", "AnalysisxTree", 100, 4095);
cal.CalculateCalibParameters("macros/myMacros/clb01_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);
......
void calibration2()
{
gSystem->Load("/home/dariak/AculUtils/libAculData.so");
......@@ -9,7 +10,8 @@
TCanvas *c1 = new TCanvas();
cal->CalibrateRawSpectra("clb09_0001.root", "SQ22", "AnalysisxTree", 100, 800, 500); //takes data from raw file and calibrates it with obtained calibration parameters
cal->CalibrateRawSpectra("clb09_0001.root", "SQ22", "AnalysisxTree", 100, 800, 500); //takes data from raw file and calibrates it with obtained calibration parameters
//return;
TFile fr("SQ22[]E.root");
cout << fr.GetListOfKeys()->GetEntries() << " histograms" << endl;
......
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