From f75d3bfd3cb86a390424039e806f53c0ee1aae69 Mon Sep 17 00:00:00 2001 From: "Kostyleva D.A" Date: Thu, 20 Oct 2016 16:08:13 +0300 Subject: [PATCH] Added new function AculCalibration::FindAverageEnergies --- AculData/AculCalibration.cpp | 60 +++++++++++++++++++++++++++++++++++- AculData/AculCalibration.h | 15 ++++++--- 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/AculData/AculCalibration.cpp b/AculData/AculCalibration.cpp index 2f7d770..2a1fbb8 100755 --- a/AculData/AculCalibration.cpp +++ b/AculData/AculCalibration.cpp @@ -1107,7 +1107,65 @@ void AculCalibration::FindEnergyPeaks(TCanvas *c1, const char* ifile, const char } ofile.close(); -} +} + +void AculCalibration::FindAverageEnergies(const char* ifile, const char* outfile) { + + TString iFile = ifile; + TFile *fr = new TFile(iFile.Data()); + if ( !fr->IsOpen() ) { + Error("FindAverageEnergies", "File %s was not opened and won't be processed.", iFile.Data()); + return; + } + + TList *histList = fr->GetListOfKeys(); + Info("FindAverageEnergies", "%d keys found in file %s.", histList->GetEntries(), fr->GetName()); + + //creation of output text file with average values of peak energies 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; + Double_t hArray[histList->GetEntries()][kRaNOPEAKS]; + Double_t hSumE1 = 0.; + Double_t hAvrE1 = 0.; + Double_t hSumE2 = 0.; + Double_t hAvrE2 = 0.; + Double_t hSumE3 = 0.; + Double_t hAvrE3 = 0.; + Double_t hSumE4 = 0.; + Double_t hAvrE4 = 0.; +// c1->Clear(); +// c1->Divide(6, 6); + + for (Int_t i = 0; i < histList->GetEntries(); i++) { + fr->GetObject(histList->At(i)->GetName(), hWork); + PeaksFitting(hWork); + for(Int_t j = 0; j < kRaNOPEAKS; j++) { + hArray[i][j] = fPeak[j]; + if(fPeak[j]==0.){ + Error("FindAverageEnergies", "No peak in channel %i !", histList->GetEntries()); + } + } + hSumE1 += hArray[i][0]; + hSumE2 += hArray[i][1]; + hSumE3 += hArray[i][2]; + hSumE4 += hArray[i][3]; +// std::cout<<"i "<GetEntries(); + hAvrE2 = hSumE2/histList->GetEntries(); + hAvrE3 = hSumE3/histList->GetEntries(); + hAvrE4 = hSumE4/histList->GetEntries(); + ofile <<"Average energies are:\t"<