From b52314c1b4ec8d4f0f36464d1f750cd71de86e8c Mon Sep 17 00:00:00 2001 From: Benjamin Linnik Date: Tue, 9 Jun 2015 14:16:29 +0200 Subject: [PATCH] Anylyzer: Added real frame number counter to database and code, added noise threshold finder and Sr90 spectrum integration --- MABS_run_analyzer/ChargeSpektrum.c | 8 +-- MABS_run_analyzer/Run.c | 81 ++++++++++++++++++++++++++++-- MABS_run_analyzer/Run.h | 32 +++++++++--- 3 files changed, 107 insertions(+), 14 deletions(-) diff --git a/MABS_run_analyzer/ChargeSpektrum.c b/MABS_run_analyzer/ChargeSpektrum.c index 231d85f..603e8e8 100644 --- a/MABS_run_analyzer/ChargeSpektrum.c +++ b/MABS_run_analyzer/ChargeSpektrum.c @@ -176,16 +176,16 @@ void ChargeSpektrum(TString runnumber = "") { // gROOT->SetBatch(kTRUE); // runs[runi]->plotSeed(); -// runs[runi]->plotSeedThresholdCalibrated(); + runs[runi]->plotSeedThresholdCalibrated(); // runs[runi]->plotSeedThreshold(); - runs[runi]->plotSeed(); +// runs[runi]->plotSeed(); // runs[runi]->plotSum(); // runs[runi]->plotVeto(); // runs[runi]->plotNoise(); if (!isBatch) gROOT->SetBatch(kFALSE); - runs[runi]->plotAllHistograms(); -// runs[runi]->plotAllHistogramsThresholdCluster(); +// runs[runi]->plotAllHistograms(); + runs[runi]->plotAllHistogramsThresholdCluster(); // runs[runi]->plotAllHistogramsThresholdClusterCalibrated(); // runs[runi]->plotAllHistogramsCalibrated(); runs[runi]->writeAllHistogramsToFile(); diff --git a/MABS_run_analyzer/Run.c b/MABS_run_analyzer/Run.c index b07e6ca..ff8cf4f 100644 --- a/MABS_run_analyzer/Run.c +++ b/MABS_run_analyzer/Run.c @@ -40,7 +40,7 @@ Run::Run(Int_t runnumber, Int_t loopi) //db = TSQLServer::Connect("mysql://jspc29.x-matter.uni-frankfurt.de","radhard","mimosa88"); try { - string selectquery = prepareSQLStatement("select `System`, `TempCooling`, COALESCE(`TempChipStart`,-10000) as `TempChipStart`, COALESCE(`TempChipEnd`,-10000) as `TempChipEnd`, `ChipNum`, `RadiationSource`, `Matrix`, `Clock`, `StorePath`, `ChipGen`,COALESCE(`VetoPeak`,-1) as `VetoPeak`,COALESCE(`SeedPeak`,-1) as `SeedPeak`,COALESCE(`SumPeak`,-1) as `SumPeak`,COALESCE(`Gain`,-1) as `Gain`,COALESCE(`Avg.Noise`,-1) as `Avg.Noise`,COALESCE(`Avg.Noise+`,-1) as `Avg.Noise+`,COALESCE(`Avg.Noise-`,-1) as `Avg.Noise-`,COALESCE(`CCE_1`,-1) as `CCE_1`,COALESCE(`CCE_25`,-1) as `CCE_25` from `radhard`.`labbook` WHERE `runnumber`=" + numberToString<>(labbook.runnumber)); + string selectquery = prepareSQLStatement("select `System`, `TempCooling`, COALESCE(`TempChipStart`,-10000) as `TempChipStart`, COALESCE(`TempChipEnd`,-10000) as `TempChipEnd`, `ChipNum`, `RadiationSource`, `Matrix`, `Clock`, `StorePath`, `ChipGen`,COALESCE(`VetoPeak`,-1) as `VetoPeak`,COALESCE(`SeedPeak`,-1) as `SeedPeak`,COALESCE(`SumPeak`,-1) as `SumPeak`,COALESCE(`Gain`,-1) as `Gain`,COALESCE(`Avg.Noise`,-1) as `Avg.Noise`,COALESCE(`Avg.Noise+`,-1) as `Avg.Noise+`,COALESCE(`Avg.Noise-`,-1) as `Avg.Noise-`,COALESCE(`CCE_1`,-1) as `CCE_1`,COALESCE(`CCE_25`,-1) as `CCE_25`,COALESCE(`Frames_found`,-1) as `Frames_found` from `radhard`.`labbook` WHERE `runnumber`=" + numberToString<>(labbook.runnumber)); res = db->Query(selectquery.c_str()); nrows = res->GetRowCount(); if (nrows > 0) @@ -96,6 +96,7 @@ Run::Run(Int_t runnumber, Int_t loopi) labbook.NoiseAvgMinusDB = (rowsql->GetField(16) != NULL)?atoi(rowsql->GetField(16)):-1; labbook.CCE_in_Perc_1DB = (rowsql->GetField(17) != NULL)?atoi(rowsql->GetField(17)):-1; labbook.CCE_in_Perc_25DB = (rowsql->GetField(18) != NULL)?atoi(rowsql->GetField(18)):-1; + labbook.frames_foundDB = (rowsql->GetField(19) != NULL)?atoi(rowsql->GetField(19)):-1; delete res; if (labbook.chip.Length() > 0 && labbook.chipGen.Length() > 0) // versuche infos zum Chip aus der ChipDatenbank zu bekommen { @@ -278,6 +279,10 @@ Bool_t Run::analyzeRun(Bool_t force) histogramthresholdCalibrated.calibrated = histogramCalibrated.calibrated; cout << colorwhite << "calculateCCE():" << endlr; calculteCCE(); + if (labbook.source.Contains("Sr90")) { + cout << colorwhite << "integrateSr90Spectra():" << endlr; + integrateSr90Spectra(histogramthresholdCalibrated.Seed); + } cout << colorwhite << "updateDatabase():" << endlr; updateDatabase(); cout << colorwhite << "delete MAPS class:" << endlr; @@ -350,6 +355,7 @@ Bool_t Run::rescaleHistograms() histogramthresholdCalibrated.avgNoise = histogramthreshold.avgNoise * gain; histogramthresholdCalibrated.avgNoisePlus = histogramthreshold.avgNoisePlus * gain; histogramthresholdCalibrated.avgNoiseMinus = histogramthreshold.avgNoiseMinus * gain; + return 1; } @@ -576,10 +582,10 @@ void Run::getVetoPeakPositionFromFe55Run() } } -void Run::constructUpdateString(string *sqlupdatequery, const string databasevaluename, const Float_t value, const int precision=3) +void Run::constructUpdateString(string *sqlupdatequery, const string databasevaluename, const Double_t value, const int precision=3) { // cout << colorred << databasevaluename << " : " << value << endlr; - if (!isinf(value)) + if (!std::isinf(value)) { if (value>0) { @@ -604,6 +610,7 @@ void Run::updateDatabase() { constructUpdateString(&sqlupdatequery, "CCE_1", CCE_in_Perc_1); constructUpdateString(&sqlupdatequery, "CCE_25", CCE_in_Perc_25); constructUpdateString(&sqlupdatequery, "Frames_found", frames_found,100000000); + constructUpdateString(&sqlupdatequery, "Sr90IntegralVal", sr90IntegralVal,1000000000); if (sqlupdatequery.length()>0) { @@ -904,12 +911,78 @@ Bool_t Run::plotAllHistogramsThresholdClusterCalibrated() return 1; } +Bool_t Run::integrateSr90Spectra(TH1F* histogrampointer, Bool_t verbose) +{ + Float_t posMaxValHist = histogrampointer->GetXaxis()->GetXmax(); + + TH1F* smoothedcurce = (TH1F*)histogrampointer->Clone(); + smoothedcurce->Smooth(4); + + Int_t rising = 0; + Int_t bini =smoothedcurce->GetMaximumBin(); + Float_t curval = smoothedcurce->GetXaxis()->GetBinCenter(bini); + Float_t thresholdbincurcandidate = 0; + + do { + curval=smoothedcurce->GetBinContent(bini++); + if (curval*0.95 <= smoothedcurce->GetBinContent(bini)) + { + rising++; +// cout << "rising at " << smoothedcurce->GetXaxis()->GetBinCenter(bini) << " as " << curval << " < " << smoothedcurce->GetBinContent(bini) << endl; // debug + } + else + { + rising = 0; + thresholdbincurcandidate = bini; + } + } while (rising < 3 && biniGetNbinsX()); + + + +// histogrampointer->GetXaxis()->SetRange(histogrampointer->GetXaxis()->FindBin(0),histogrampointer->GetXaxis()->FindBin(posMaxValHist)); +// Float_t posNoiseMax= histogrampointer->GetMaximum(); +// histogrampointer->GetXaxis()->SetRange(posNoiseMax,histogrampointer->GetXaxis()->FindBin(posMaxValHist)); +// Float_t posChargeMax= histogrampointer->GetMaximum(); + + noisethresholdborder = histogrampointer->GetXaxis()->GetBinUpEdge(thresholdbincurcandidate); + + if (verbose) { + cout << " Noise threshold at " << noisethresholdborder; + TString histtitle=histogrampointer->GetXaxis()->GetTitle(); + if (histtitle.Contains("[e]")) + { + cout << " e" << endl; + if (noisethresholdborder > 300) { + cout << coloryellow << " This noise threshold seems too high, please check manually the " << histogrampointer->GetName() << " spectrum." << endlr; + } + } + else + { + cout << " ADU" << endl; + if (noisethresholdborder > 75) { + cout << coloryellow << " This noise threshold seems too high, please check manually the " << histogrampointer->GetName() << " spectrum." << endlr; + } + } + } + sr90IntegralVal = histogrampointer->IntegralAndError(thresholdbincurcandidate,histogrampointer->GetMaximumBin(), sr90IntegralErr); + sr90IntegralErr /= sr90IntegralVal/100; + cout << " "; + if (labbook.frames_foundDB>0 || frames_found>0) + { + sr90IntegralVal/=(labbook.frames_foundDB>0)?labbook.frames_foundDB:frames_found; + cout << "Scaled "; + } + cout << "Integral is " << Form("%e",sr90IntegralVal) << ", error " << sr90IntegralErr << "%" << endl; + + return 0; +} + Float_t Run::FitPerform(TH1F* histogrampointer, TString fitFuncType, Bool_t verbose) { Float_t posMax = 0; Float_t posMax2 = 0; Float_t posMaxValHist = histogrampointer->GetXaxis()->GetXmax(); - Float_t noiseborder = 90; // posMaxValHist/10 for USB system, the value is 90 + Float_t noiseborder = (noisethresholdborder>0)?noisethresholdborder:90; // posMaxValHist/10 for USB system, the value is 90 if (doFits) { diff --git a/MABS_run_analyzer/Run.h b/MABS_run_analyzer/Run.h index bab9734..7f7314a 100644 --- a/MABS_run_analyzer/Run.h +++ b/MABS_run_analyzer/Run.h @@ -4,7 +4,7 @@ #include #include #include "sys/stat.h" -#include /* isinf, sqrt */ +#include /* isinf, sqrt */ #include #include @@ -77,7 +77,7 @@ private: /** * @brief takes a float value and a precision and appends it to an SQL statement used to update the database */ - void constructUpdateString(string*, const string, const Float_t, int); + void constructUpdateString(string*, const string, const Double_t, int); /** * @brief A structure to hold information about a given sensor, like number of #columns and #rows @@ -146,6 +146,7 @@ private: Bool_t binSeedSumVeto(); /// noise quantiles: mean value, sigma in postive direction and sigma in negative direction Double_t noisequantiles[3]; + TCanvas* plot1DHistogram(TH1F* onehistogram, TString fitFuncType = "landau", TString titlestr = "", TString legendstr = ""); @@ -162,13 +163,23 @@ private: /** * @brief intern function to calculate and plot fit curve to given histogram * - * @param histNtuple histogram pointer to calculate fit to + * @param histogrampointer histogram pointer to calculate fit to * @return peak position of the fit * */ Float_t FitPerform(TH1F*, TString fitFuncType="landau", Bool_t verbose=true); - - + + /** + * @brief find the border between the noise and the signal in Sr90 runs + * + * writes the found threshold into the private variable #posNoiseThreshold + * + * @param histogrampointer pointer to the histogram structure, threshold will be searched in seed spectra + * @return true if succesfull + * + */ + Bool_t integrateSr90Spectra(TH1F* histogrampointer, Bool_t verbose=true); + /** * @brief rescales all histograms from ADU to electrons */ @@ -209,7 +220,7 @@ private: }; systemparam systemparamUSB { 2800, // maxbin; - 2800/8,// nbins; + 2800/4,// nbins; 25, //vetothreshold 10, 100 @@ -384,6 +395,8 @@ public: Int_t clock = 100; /// path to the RAW files as seen from system which took the run TString storepath = ""; + /// number of frames analyzed for this run + Int_t frames_foundDB = -1; }; /// stores information from the SQL database of a given run labbooksctruct labbook; @@ -494,6 +507,13 @@ public: Float_t CCE_in_Perc_25=0; /// Charge collection efficciency of the seed pixel in percent Float_t CCE_in_Perc_1=0; + /// threshold for integrating the Sr90 spectrum, is set dynamically in @c integrateSr90Spectra() + Float_t noisethresholdborder = -1; + /// Integral value, after integrating from #noisethresholdborder to maxbin. + Double_t sr90IntegralVal = -1; + Double_t sr90IntegralErr = -1; + + /// specific string wich encodes the database information of the run TString runcode=""; -- 2.43.0