From bc9cb991dc7e1b734acb8b9946a74359e01f390c Mon Sep 17 00:00:00 2001 From: Benjamin Linnik Date: Mon, 23 Nov 2015 13:05:37 +0100 Subject: [PATCH] Run analyzer: added S/N database integration and calculation, code cleanup, better markup --- MABS_run_analyzer/ChargeSpektrumFunctions.c | 35 +++-- MABS_run_analyzer/HistogramType.c | 150 +++++++++++++------- MABS_run_analyzer/HistogramType.h | 28 +++- MABS_run_analyzer/Run.c | 49 ++++--- MABS_run_analyzer/Run.h | 6 +- 5 files changed, 176 insertions(+), 92 deletions(-) diff --git a/MABS_run_analyzer/ChargeSpektrumFunctions.c b/MABS_run_analyzer/ChargeSpektrumFunctions.c index abb3399..acad5bf 100644 --- a/MABS_run_analyzer/ChargeSpektrumFunctions.c +++ b/MABS_run_analyzer/ChargeSpektrumFunctions.c @@ -10,6 +10,7 @@ Int_t* ReadRunList(); Int_t ReadRunList(std::vector*); Bool_t plotAllRuns(); +Bool_t plotAllRuns(vector*); /** @brief A function to plot TH1F histograms of different runs into one file * * You push in #ChargeSpectrum.c a pointer of the type TH1F into the vector #compareHistogramVector and then @@ -28,8 +29,9 @@ Bool_t writeObservableToFile(); * */ vector compareHistogramClassVector; +vector compareHistogramClassVector2; +vector compareHistogramClassVector3; vector compareHistogramVector; - TString ownpath = ""; void setCustomPath(TString setOwnpath) @@ -117,23 +119,28 @@ Bool_t writeObservableToFile() } +Bool_t plotAllRuns() { + return plotAllRuns(&compareHistogramClassVector); +} + -Bool_t plotAllRuns() +Bool_t plotAllRuns(vector* ptCompareHistogramClassVector) { if (numberRuns>0) { - if ( !compareHistogramClassVector.size() ) + if ( !ptCompareHistogramClassVector->size() ) { - cout << colorred << "plotCompareHistograms(): No plots to compare, please push them into the vector: compareHistogramClassVector." << endlr; + cout << colorwhite << ptCompareHistogramClassVector->size() << endl; + cout << colorred << "plotCompareHistograms(): No plots to compare, please push them into the vector: CompareHistogramClassVector" << endlr; return 1; } Bool_t calibrated = true; Bool_t uncalibrated = true; - for (UInt_t histogrami=0; histogrami < compareHistogramClassVector.size(); histogrami++) + for (UInt_t histogrami=0; histogrami < ptCompareHistogramClassVector->size(); histogrami++) { - calibrated = calibrated && compareHistogramClassVector.at(histogrami)->iscalibrated; - uncalibrated = uncalibrated && !compareHistogramClassVector.at(histogrami)->iscalibrated; - // cout << colorcyan << compareHistogramClassVector.at(histogrami)->histogramdescription << endlr; + calibrated = calibrated && ptCompareHistogramClassVector->at(histogrami)->iscalibrated; + uncalibrated = uncalibrated && !ptCompareHistogramClassVector->at(histogrami)->iscalibrated; + // cout << colorcyan << ptCompareHistogramClassVector->at(histogrami)->histogramdescription << endlr; } // cout << "Calibrated " << (calibrated?"Yes":"No") << endl; // cout << "Uncalibrated " << (uncalibrated?"Yes":"No") << endl; @@ -144,7 +151,7 @@ Bool_t plotAllRuns() } // legend entries - Float_t height = compareHistogramClassVector.size() * 0.04; + Float_t height = ptCompareHistogramClassVector->size() * 0.04; TLegend* leg1 = new TLegend(0.4,0.89-height,0.89,0.89);//(0.6,0.7,0.89,0.89); leg1->SetTextSize(0.02); leg1->SetFillColor(0); leg1->SetBorderSize(0); @@ -160,15 +167,15 @@ Bool_t plotAllRuns() TString canvasname = Form("%d",time->GetNanoSec()); TCanvas* canvas = new TCanvas(canvasname, canvastitle, 1200, 800); canvas->Divide(2,2); - for (UInt_t histogrami=0; histogrami < compareHistogramClassVector.size(); histogrami++) + for (UInt_t histogrami=0; histogrami < ptCompareHistogramClassVector->size(); histogrami++) { - HistogramType* curhistogramclassp = compareHistogramClassVector.at(histogrami); + HistogramType* curhistogramclassp = ptCompareHistogramClassVector->at(histogrami); TH1F* curhistogramclone; canvas->cd(1); curhistogramclone = (TH1F*) curhistogramclassp->Seed->Clone(); // curhistogramclone->SetLineColor(rootcolors[histogrami]); curhistogramclone->Draw("SAME"); - legendEntry = Form("%s", curhistogramclone->GetTitle()); + legendEntry = Form("%d %s", curhistogramclassp->runnumber, curhistogramclone->GetTitle()); leg1->AddEntry(curhistogramclone, legendEntry, "l"); leg1->Draw("SAME"); lastbin1 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1))>lastbin1)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1)):lastbin1; @@ -192,8 +199,8 @@ Bool_t plotAllRuns() canvas->cd(4); curhistogramclone = (TH1F*) curhistogramclassp->Noise->Clone(); // curhistogramclone->SetLineColor(rootcolors[histogrami]); - curhistogramclone->Draw(); - legendEntry = Form("Noise: %.2f + %.2f - %.2f",curhistogramclassp->avgNoise, curhistogramclassp->avgNoisePlus, curhistogramclassp->avgNoiseMinus); + curhistogramclone->Draw("SAME"); + legendEntry = Form("%d Noise: %.2f + %.2f - %.2f",curhistogramclassp->runnumber, curhistogramclassp->avgNoise, curhistogramclassp->avgNoisePlus, curhistogramclassp->avgNoiseMinus); leg2->AddEntry(curhistogramclone, legendEntry, "l"); leg2->Draw(); } diff --git a/MABS_run_analyzer/HistogramType.c b/MABS_run_analyzer/HistogramType.c index 7d76841..f04fae9 100644 --- a/MABS_run_analyzer/HistogramType.c +++ b/MABS_run_analyzer/HistogramType.c @@ -49,12 +49,12 @@ void HistogramType::initHistograms(Int_t gotcolor, Int_t gotstyle) { } void HistogramType::initHistogram(TH1F* &histogrampointer, TString prefix, Int_t color, Int_t style) { - histogrampointer=new TH1F(Form("%d %s",runnumber, prefix.Data()), Form("%s, %s",prefix.Data(), humanreadablestr.Data()), cursystempar->nbins, 0, cursystempar->maxbin); + histogrampointer=new TH1F(Form("%d %s",runnumber, prefix.Data()), Form("%d %s, %s",runnumber,prefix.Data(), humanreadablestr.Data()), cursystempar->nbins, 0, cursystempar->maxbin); histogrampointer->SetLineStyle(style); histogrampointer->SetLineColor(color); histogrampointer->SetStats(kTRUE); histogrampointer->SetStats(111111111); - histogrampointer->SetLineWidth(3); + histogrampointer->SetLineWidth(2); // TODO: set to 3 again histogrampointer->GetXaxis()->SetTitle("Q_coll [ADU]"); histogrampointer->GetYaxis()->SetTitle(Form("Entries [1/%.1f ADU]",histogrampointer->GetBinWidth(1))); histogrampointer->GetXaxis()->CenterTitle(); @@ -112,7 +112,8 @@ void HistogramType::calibrateHistogram(TH1F* &histogrampointernew, TH1F* &histog int nbins = histogrampointernew->GetXaxis()->GetNbins(); double new_bins[nbins+1]; for(int i=0; i <= nbins; i++){ - new_bins[i] = histogrampointernew->GetBinCenter(i)*gain; + new_bins[i] = histogrampointernew->GetBinLowEdge(i)*gain; +// cout << "histogrampointernew->GetBinCenter(i): " << histogrampointernew->GetBinLowEdge(i) << " * gain " << gain << " = " << histogrampointernew->GetBinLowEdge(i)*gain << endl; } histogrampointernew->SetBins(nbins, new_bins); histogrampointernew->GetYaxis()->SetTitle(Form("Entries [1/%.1f e]",histogrampointernew->GetBinWidth(1))); @@ -244,24 +245,35 @@ Float_t HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType, B Float_t minFitMax = 1000; Float_t maxFitMax = 1000; histogrampointer->Fit(fitFunc, "N,Q,W", "", noiseborder, posMaxValHist); + posMax = fitFunc->GetParameter(1); // new method, just use MPV of fit, as noise border is well known. Compare with old method anyway and warn if something suspecious. +// cout << "fitFunc->GetParameter(0): " << fitFunc->GetParameter(0) << endl; +// cout << "fitFunc->GetParameter(1): " << fitFunc->GetParameter(1) << endl; +// cout << "fitFunc->GetParameter(2): " << fitFunc->GetParameter(2) << endl; +// cout << colorred << "noiseborder: " << noiseborder << endlr; fitMax1 = fitFunc->GetMaximumX(); - // fitFunc->DrawCopy("same"); +// fitFunc->DrawCopy("same"); histogrampointer->Fit(fitFunc, "N,Q,W", "", noiseborder, fitMax1*1.1); fitMax2 = fitFunc->GetMaximumX(); fitFunc->SetLineColor(kBlue); fitFunc->SetLineStyle(2); // dashed - // fitFunc->DrawCopy("same"); +// fitFunc->DrawCopy("same"); histogrampointer->Fit(fitFunc, "N,Q,W", "", fitMax1*0.9, posMaxValHist); // histogrampointer->Fit(fitFunc, "N,Q,W", "", fitMax1, histogrampointer->GetBinCenter(bini)); fitMax3 = fitFunc->GetMaximumX(); fitFunc->SetLineColor(kGreen); - // fitFunc->DrawCopy("same"); +// fitFunc->DrawCopy("same"); fitFunc->SetLineStyle(1); // normal for the following fits - // Sort the three fits and save error estimation + //Sort the three fits and save error estimation minFitMax = TMath::Min(TMath::Min(fitMax1,fitMax2),fitMax3); maxFitMax = TMath::Max(TMath::Max(fitMax1,fitMax2),fitMax3); - posMax = fitMax1 + fitMax2 + fitMax3 - minFitMax - maxFitMax; + posMax2 = fitMax1 + fitMax2 + fitMax3 - minFitMax - maxFitMax; + if (abs(posMax-posMax2)/posMax > 0.11) + { + cout << coloryellow << " Please check the Landau MPV value fit, as two alternate methods revealed results wich differ " << abs(posMax-posMax2)/posMax*100 << " %." << endlr; + cout << " Primary, new MPV method: " << posMax << endl; + cout << " Secondary, mean maxima mathod: " << posMax2 << endl; + } //fitLandauErrorLeft.push_back(posMax - minFitMax); //fitLandauErrorRight.push_back(maxFitMax - posMax); @@ -304,102 +316,134 @@ Float_t HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType, B return posMax; } -Bool_t HistogramType::calculteCCE() { +Bool_t HistogramType::calculteCCE(Bool_t verbose) { if (posSeed > 0 && posVeto > 0) CCE_in_Perc_1 = posSeed / posVeto * 100.0; if (posSum > 0 && posVeto > 0) CCE_in_Perc_25 = posSum / posVeto * 100.0; if (CCE_in_Perc_1 > 0 || CCE_in_Perc_25 > 0) return 0; + if (verbose) { + cout << " CCE Seed: " << colorgreen << CCE_in_Perc_1 << " %" << endlr; + cout << " CCE Sum: " << colorgreen << CCE_in_Perc_25 << " %" << endlr; + } return 1; } -Bool_t HistogramType::integrateSr90Spectra(TH1F* histogrampointer, Int_t frames_found, Float_t thresholdborder, Bool_t verbose) { +Bool_t HistogramType::FindNoisethresholdborder(TH1F* histogrampointer, Bool_t verbose) { Float_t posMaxValHist = histogrampointer->GetXaxis()->GetXmax(); TH1F* smoothedcurce = (TH1F*)histogrampointer->Clone(); - smoothedcurce->Smooth(4); + // smoothedcurce->Smooth(4); // not working method, rescaling is easier and more reliable + Int_t rebinningfactor = 4; + smoothedcurce->RebinX(rebinningfactor); smoothedcurce->SetAxisRange(0,histogrampointer->GetBinCenter(histogrampointer->GetNbinsX())); -// TString canvastitle = Form("%s sdfasdf", histogrampointer->GetName()); -// TString canvasname = Form("%s dfgsdfgsdfg", histogrampointer->GetName()); -// TCanvas* canvas = new TCanvas(canvasname, canvastitle, 900, 700); -// smoothedcurce->Draw(); + if (verbose) { + TString canvastitle = Form("%s Noisethreshold border", histogrampointer->GetName()); + TString canvasname = Form("%s Noisethreshold border", histogrampointer->GetName()); + TCanvas* canvas = new TCanvas(canvasname, canvastitle, 900, 700); + smoothedcurce->SetLineColor(color+1); + smoothedcurce->Draw(); + histogrampointer->Draw("SAME"); + canvas->Update(); + } + + Int_t thresholdbincurcandidate = 0; + Int_t rising = 0; + Int_t bini =smoothedcurce->GetMaximumBin(); + thresholdbincurcandidate = bini; + // cout << "GetMaximumBin: smoothedcurce->GetXaxis()->GetBinCenter(" << bini << "): " << curval << endl; + + do { + Float_t 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()); + thresholdbincurcandidate *= rebinningfactor; + noisethresholdborder = histogrampointer->GetXaxis()->GetBinUpEdge(thresholdbincurcandidate); + if (verbose) { + cout << " Noise threshold at " << noisethresholdborder; + } + return 0; +} + +Bool_t HistogramType::integrateSr90Spectra(TH1F* histogrampointer, Int_t frames_found, Float_t thresholdborder, Bool_t verbose) { + Int_t thresholdbincurcandidate = 0; if (thresholdborder < 0) { - Int_t rising = 0; - Int_t bini =smoothedcurce->GetMaximumBin(); - thresholdbincurcandidate = bini; - Float_t curval = smoothedcurce->GetXaxis()->GetBinCenter(bini); -// cout << "GetMaximumBin: smoothedcurce->GetXaxis()->GetBinCenter(" << bini << "): " << curval << endl; - - 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()); + if (noisethresholdborder < 0) { + FindNoisethresholdborder(histogrampointer, verbose); + } + thresholdbincurcandidate = histogrampointer->GetXaxis()->FindBin(noisethresholdborder); } else { thresholdbincurcandidate = histogrampointer->GetXaxis()->FindBin(thresholdborder); + noisethresholdborder = thresholdborder; } - - - // 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); -// cout << "thresholdbincurcandidate: " << thresholdbincurcandidate << endl; -// cout << "noisethresholdborder: " << noisethresholdborder << endl; - if (verbose) { - cout << " Integrating " << histogrampointer->GetTitle() << endlr; - cout << " Noise threshold at " << noisethresholdborder; + //cout << " Integrating " << histogrampointer->GetTitle() << endlr; + cout << " Integrating histogram '" << histogrampointer->GetName() << "' in class: <" << colorwhite << histogramdescription << colorreset << " >" << endlr; + 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; + 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; + cout << coloryellow << " This noise threshold seems too high, please check manually the " << histogrampointer->GetName() << " spectrum." << endlr; } } } sr90IntegralVal = histogrampointer->IntegralAndError(thresholdbincurcandidate,histogrampointer->GetNbinsX(), sr90IntegralErr); - // cout << "Integrate from bin " << thresholdbincurcandidate << " to " << histogrampointer->GetNbinsX() << endl; +// cout << "Integrate from bin " << thresholdbincurcandidate << " to " << histogrampointer->GetNbinsX() << endl; sr90IntegralErr /= sr90IntegralVal/100; // cout << " Unscaled integral is " << Form("%e",sr90IntegralVal) << ", error " << sr90IntegralErr << "%" << endl; -// cout << " "; + // cout << " "; + if (verbose) + cout << " "; if (frames_found>0) { sr90IntegralVal/=frames_found; if (verbose) - cout << " Scaled"; + cout << "Scaled "; } if (verbose) - cout << " Integral is " << Form("%e",sr90IntegralVal) << ", error " << sr90IntegralErr << "%" << endl; + cout << "Integral is " << colorgreen << Form("%e",sr90IntegralVal) << colorreset << ", error " << sr90IntegralErr << "%" << endl; return 0; } +Bool_t HistogramType::calculteStoN(Bool_t verbose) { +// cout << "posSeed: " << posSeed << endl << "avgNoise: " << avgNoise << endlr; + if (posSeed > 0 && avgNoise > 0) { + StoN = posSeed / avgNoise; + if (verbose) + cout << colorgreen << " S/N : " << StoN << endlr; + return 1; + } else { + cout << " S/N : wrong values for posSeed and/or avgNoise" << endlr; + } + return 0; +} + //***************** // OTHER HELPFUL FUNCTIONS diff --git a/MABS_run_analyzer/HistogramType.h b/MABS_run_analyzer/HistogramType.h index ac60cc0..fcdb130 100644 --- a/MABS_run_analyzer/HistogramType.h +++ b/MABS_run_analyzer/HistogramType.h @@ -165,6 +165,8 @@ public: Float_t CCE_in_Perc_25=0; /// Charge collection efficciency of the seed pixel in percent Float_t CCE_in_Perc_1=0; + /// Signal to noise ratio + Float_t StoN=0; //***************** // METHODS APPLYABLE TO HISTOGRAMS @@ -185,11 +187,11 @@ public: */ Float_t FitPerform(TH1F* histogrampointer, TString fitFuncType, Bool_t verbose = 0, Double_t* parameters = 0); /** @brief calculates Charge Collection Efficiency if Fe55 run */ - Bool_t calculteCCE(); + Bool_t calculteCCE(Bool_t verbose=false); /** - * @brief find the border between the noise and the signal in Sr90 runs + * @brief Integrates a BetaSource spectrum * - * writes the found threshold into the private variable @c Run::posNoiseThreshold + * writes the found scaled integral into variable @c Run::sr90IntegralVal * * @param histogrampointer pointer to the histogram structure, threshold will be searched in seed spectra * @param thresholdborder value from which the integral will be calculated, if not set, the algorithms tries to find the best value @@ -198,6 +200,26 @@ public: */ Bool_t integrateSr90Spectra(TH1F* histogrampointer, Int_t frames_found=-1, Float_t thresholdborder=-1, Bool_t verbose=true); + /** + * @brief Tries to find a border between the noise and the signal + * + * writes the found noise threshold border into the private variable @c Run::posNoiseThreshold + * + * @return true if succesfull + * + */ + Bool_t FindNoisethresholdborder(TH1F* histogrampointer, Bool_t verbose=false); + + /** + * @brief calculates StoN ratio, if beta source was used + * + * writes the found S/N ratio into the variable @c Run::posNoiseThreshold + * + * @return true if succesfull + * + */ + Bool_t calculteStoN(Bool_t calculteStoN = false); + //***************** // OTHER diff --git a/MABS_run_analyzer/Run.c b/MABS_run_analyzer/Run.c index 19edd69..e12a6bc 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`,COALESCE(`Frames_found`,-1) as `Frames_found` 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`,COALESCE(`Sr90IntegralVal`,-1) as `Sr90IntegralVal`,COALESCE(`StoN`,-1) as `StoN` from `radhard`.`labbook` WHERE `runnumber`=" + numberToString<>(labbook.runnumber)); res = db->Query(selectquery.c_str()); nrows = res->GetRowCount(); if (nrows > 0) @@ -98,6 +98,8 @@ Run::Run(Int_t runnumber, Int_t loopi) labbook.CCE_in_Perc_1DB = (rowsql->GetField(17) != NULL)?atof(rowsql->GetField(17)):-1; labbook.CCE_in_Perc_25DB = (rowsql->GetField(18) != NULL)?atof(rowsql->GetField(18)):-1; labbook.frames_foundDB = (rowsql->GetField(19) != NULL)?atoi(rowsql->GetField(19)):-1; + labbook.Sr90IntegralVal = (rowsql->GetField(20) != NULL)?atof(rowsql->GetField(20)):-1; + labbook.StoN = (rowsql->GetField(21) != NULL)?atof(rowsql->GetField(21)):-1; // labbook.frames_Analyzed = (rowsql->GetField(20) != NULL)?atoi(rowsql->GetField(20)):-1; delete res; if (labbook.chipGen.Length() > 0) @@ -157,9 +159,6 @@ Run::Run(Int_t runnumber, Int_t loopi) // fixed threshold cut histogramfixedthreshold = new HistogramType(" fixed Threshold", &cursystemparam, &cursensorinfo, humanreadablestr, labbook.runnumber, rootcolors[plotStyle], rootlinestyle[plotStyle] ); HistogramClassVector.push_back(histogramfixedthreshold); - // dennis megacut - dennismegacut = new HistogramType(" Dennis Mega Cut", &cursystemparam, &cursensorinfo, humanreadablestr, labbook.runnumber, rootcolors[plotStyle], rootlinestyle[plotStyle] ); - HistogramClassVector.push_back(dennismegacut); debugDBreadout(); } @@ -192,8 +191,8 @@ Bool_t Run::debugDBreadout() cout << "| pitch Y: " << std::right << colorwhite << curpixelinfo.pitchY << endlr; cout << "| staggered: " << std::right << colorwhite << (curpixelinfo.staggered?"Yes":"No") << endlr; cout << "| matrix: " << std::right << colorwhite << labbook.matrix << endlr; - cout << "| radDoseIon: " << std::right << colorwhite << labbook.radDoseIon << endlr; - cout << "| radDoseNonIon: " << std::right << colorwhite << labbook.radDoseNonIon << endlr; + cout << "| radDoseIon: " << std::right << coloryellow << labbook.radDoseIon << endlr; + cout << "| radDoseNonIon: " << std::right << coloryellow << labbook.radDoseNonIon << endlr; cout << "| resistivity: " << std::right << colorwhite << labbook.resistivity << endlr; cout << "| epi_thickness: " << std::right << colorwhite << labbook.epi_thickness << endlr; cout << "| clock: " << std::right << colorwhite << labbook.clock << endlr; @@ -207,6 +206,8 @@ Bool_t Run::debugDBreadout() cout << "| NoiseAvgMinusDB: " << std::right << colorwhite << labbook.NoiseAvgMinusDB << endlr; cout << "| CCE_in_Perc_25DB:" << std::right << colorwhite << labbook.CCE_in_Perc_25DB << endlr; cout << "| CCE_in_Perc_1DB: " << std::right << colorwhite << labbook.CCE_in_Perc_1DB << endlr; + cout << "| StoN: " << std::right << colorwhite << labbook.StoN << endlr; + cout << "| Sr90IntegralVal: " << std::right << colorwhite << std::scientific << labbook.Sr90IntegralVal << endlr; std::cout.unsetf ( std::ios::scientific ); cout << "| frames_foundDB : " << std::right << colorwhite << labbook.frames_foundDB << endlr; cout << "|______________________________ " << endlr; cout << endlr; @@ -215,6 +216,7 @@ Bool_t Run::debugDBreadout() void Run::setSystemSpecificParameters() { +// systemparam systemparamUSB (2800/*maxbin*/,2800/4/*nbins*/, 25/*vetothreshold*/, 10/*maxbinnoise*/, 100/*nbinsnoise*/); // TODO: uncomment and add again old binning systemparam systemparamUSB (2800/*maxbin*/,2800/4/*nbins*/, 25/*vetothreshold*/, 10/*maxbinnoise*/, 100/*nbinsnoise*/); systemparam systemparamPegasus (2800,2800/2,20,10,100); systemparam systemparamPXI (800*16,800,75,150,150); @@ -389,17 +391,24 @@ Bool_t Run::analyzeRun(Bool_t force) binSeedSumVeto(); cout << colorwhite << "binCluster():" << endlr; binCluster(); + cout << "---------- loop over all classes --------" << endl; for (vector::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++) { + cout << "Processing histograms in class: <" << colorwhite << (*curHistogramClass)->histogramdescription << colorreset << " >" << endlr; binNoise((*curHistogramClass)); if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) { - cout << colorwhite << "calculateCCE():" << endlr; - (*curHistogramClass)->calculteCCE(); + cout << colorwhite << " calculateCCE():" << endlr; + (*curHistogramClass)->calculteCCE(true); } if (labbook.source.Contains("Sr90")) { - cout << colorwhite << "integrateSr90Spectra():" << endlr; + //cout << colorwhite << " integrateSr90Spectra():" << endlr; (*curHistogramClass)->integrateSr90Spectra((*curHistogramClass)->Seed, frames_found, -1, false); + cout << colorwhite << " calculteStoN():" << endlr; + (*curHistogramClass)->calculteStoN(true); } } + cout << "---------------------------------" << endl; + cout << colorwhite << "integrateSr90Spectra():" << endlr; + histogramthreshold->integrateSr90Spectra(histogramthreshold->Seed, frames_found, -1, true); histogramfixedthreshold->integrateSr90Spectra(histogramfixedthreshold->Seed, frames_found, 0); rescaleHistogramClasses(); cout << colorwhite << "updateDatabase():" << endlr; @@ -485,6 +494,7 @@ Bool_t Run::checkFileExists(TString file) Bool_t Run::generateReadableRunCode() { humanreadablestr = Form("%s, %s, chip %s, %s, %sT=%.1f", labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), humanreadablesuffix.Data(), labbook.temp); + cout << colorwhite << " " << colorgreen << humanreadablestr << colorwhite <<" " << endlr; for (vector::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++) (*curHistogramClass)->humanreadablestr = humanreadablestr; @@ -682,6 +692,7 @@ void Run::updateDatabase() { constructUpdateString(&sqlupdatequery, "Avg.Noise-", histogram->calibrated->avgNoiseMinus, 2); constructUpdateString(&sqlupdatequery, "CCE_1", histogram->CCE_in_Perc_1); constructUpdateString(&sqlupdatequery, "CCE_25", histogram->CCE_in_Perc_25); + constructUpdateString(&sqlupdatequery, "StoN", histogram->StoN, 3); constructUpdateString(&sqlupdatequery, "Avg.NoiseADC", histogram->avgNoise); constructUpdateString(&sqlupdatequery, "Frames_found", frames_found,100000000); constructUpdateString(&sqlupdatequery, "Sr90IntegralVal", histogramfixedthreshold->calibrated->sr90IntegralVal,1000000000); @@ -690,7 +701,7 @@ void Run::updateDatabase() { { try { - sqlupdatequery = prepareSQLStatement("UPDATE `radhard`.`labbook` SET " + sqlupdatequery + " WHERE `runnumber`=" + numberToString<>(labbook.runnumber)); + sqlupdatequery = prepareSQLStatement(" UPDATE `radhard`.`labbook` SET " + sqlupdatequery + " WHERE `runnumber`=" + numberToString<>(labbook.runnumber)); Bool_t sucess = db->Exec(sqlupdatequery.c_str()); if (!sucess) { @@ -816,15 +827,6 @@ Bool_t Run::binSeedSumVeto() histogramfixedthreshold->Veto->Fill(processed->fFrameInfo.p[12][hiti]); // histogram with the single pixel } - if (processed->fFrameInfo.pixel[hiti]>200) - { - dennismegacut->numberofhits++; - - dennismegacut->Seed->Fill(processed->fFrameInfo.p[12][hiti]); - dennismegacut->Sum->Fill(pixelSum); - if (TMath::Abs(notSeedSum) < cursystemparam.vetothreshold && (labbook.source.Contains("Fe")||labbook.source.Contains("Cd"))) - dennismegacut->Veto->Fill(processed->fFrameInfo.p[12][hiti]); // histogram with the single pixel - } } } } @@ -832,10 +834,15 @@ Bool_t Run::binSeedSumVeto() // gROOT->SetBatch(kTRUE); for (vector::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++) { + (*curHistogramClass)->FindNoisethresholdborder((*curHistogramClass)->Seed, false); if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) (*curHistogramClass)->posVeto=(*curHistogramClass)->FitPerform((*curHistogramClass)->Veto, "gaus", true); (*curHistogramClass)->posSeed=(*curHistogramClass)->FitPerform((*curHistogramClass)->Seed, "landau", true); (*curHistogramClass)->posSum=(*curHistogramClass)->FitPerform((*curHistogramClass)->Sum, "gaus", true); + for (Int_t bini=1; bini <= cursystemparam.nbins; bini++) { // TODO: rescaled histogram to number of frames found, remove the inner for loop later +// (*curHistogramClass)->Seed->SetBinContent(bini,(*curHistogramClass)->Seed->GetBinContent(bini)/(frames_found*1.0)); +// (*curHistogramClass)->Sum->SetBinContent(bini,(*curHistogramClass)->Sum->GetBinContent(bini)/(frames_found*1.0)); + } } // gROOT->SetBatch(kFALSE); return 0; @@ -1505,12 +1512,12 @@ Bool_t Run::writeAllHistogramsToFile() TString outline; for(Int_t bin=1;bin<=cursystemparam.nbins;bin++) { - outline=Form("%.1f\t%.1f\t", histogram->Seed->GetBinCenter(bin), histogram->iscalibrated?histogram->calibrated->Seed->GetBinCenter(bin):0); + outline=Form("%.1f\t%.1f\t", histogram->Seed->GetBinCenter(bin), histogram->calibrated!=0?histogram->calibrated->Seed->GetBinCenter(bin):0); for (vector::iterator curHistogramClass = HistogramClassVector.begin(); curHistogramClass != HistogramClassVector.end(); curHistogramClass++) { outline+=Form("%.1f\t%.1f\t%.1f\t", (*curHistogramClass)->Seed->GetBinContent(bin), (*curHistogramClass)->Sum->GetBinContent(bin), (*curHistogramClass)->Veto->GetBinContent(bin)); } if (bin <= cursystemparam.nbinsnoise) - outline+=Form("%.1f\t%.1f\t%.1f", histogram->Noise->GetBinCenter(bin),histogram->iscalibrated?histogram->calibrated->Noise->GetBinCenter(bin):0,histogram->Noise->GetBinContent(bin)); + outline+=Form("%.1f\t%.1f\t%.1f", histogram->Noise->GetBinCenter(bin),histogram->calibrated!=0?histogram->calibrated->Noise->GetBinCenter(bin):0,histogram->Noise->GetBinContent(bin)); *fout<close(); diff --git a/MABS_run_analyzer/Run.h b/MABS_run_analyzer/Run.h index c71d41d..3f176bd 100644 --- a/MABS_run_analyzer/Run.h +++ b/MABS_run_analyzer/Run.h @@ -350,6 +350,10 @@ public: Float_t CCE_in_Perc_25DB=-1; /// Charge collection efficciency of the seed pixel in percent found in db Float_t CCE_in_Perc_1DB=-1; + /// Signal to Noise ratio + Float_t StoN=-1; + /// Integral value + Float_t Sr90IntegralVal=-1; /// the resistivity of the epitexial layer of the chip Int_t resistivity = -1; /// Thickness of epitexial layer in micro meters @@ -392,7 +396,7 @@ public: HistogramType* histogram; HistogramType* histogramthreshold; HistogramType* histogramfixedthreshold; - HistogramType* dennismegacut; + /// /** @brief A vector able to hold pointer of type #Run::histogramstruct * -- 2.43.0