From d9014519f9f5d53fc367129ca1e942885f498941 Mon Sep 17 00:00:00 2001 From: Benjamin Linnik Date: Tue, 24 Nov 2015 16:22:03 +0100 Subject: [PATCH] Run analyzer: added summary table to cout output --- MABS_run_analyzer/ChargeSpektrumFunctions.c | 134 ++++++++++++++++---- MABS_run_analyzer/HistogramType.c | 14 +- MABS_run_analyzer/HistogramType.h | 6 +- MABS_run_analyzer/Run.c | 6 +- MABS_run_analyzer/Run.h | 59 --------- MABS_run_analyzer/help.h | 59 +++++++++ 6 files changed, 184 insertions(+), 94 deletions(-) diff --git a/MABS_run_analyzer/ChargeSpektrumFunctions.c b/MABS_run_analyzer/ChargeSpektrumFunctions.c index acad5bf..b9091b1 100644 --- a/MABS_run_analyzer/ChargeSpektrumFunctions.c +++ b/MABS_run_analyzer/ChargeSpektrumFunctions.c @@ -6,6 +6,9 @@ * */ #include +#include +#include +using namespace std; Int_t* ReadRunList(); Int_t ReadRunList(std::vector*); @@ -19,6 +22,9 @@ Bool_t plotAllRuns(vector*); * Call #writeObservableToFile() in #ChargeSpectrum.c to create a file with all the TH1F histogram data * */ +/** @brief Prints a line with fixed width in the summary table */ +template string printTableElement(varType t1, varType t2, const int precision=1); + Bool_t writeObservableToFile(); /** @brief A vector able to hold pointer of type #Run::histogramstruct * @@ -31,6 +37,12 @@ Bool_t writeObservableToFile(); vector compareHistogramClassVector; vector compareHistogramClassVector2; vector compareHistogramClassVector3; +/** @brief Prints a summary table with all the analyzed run data */ +Bool_t printSummaryTable(vector*); +/** @brief Tests if all runs in vector are from same type, calibrated or not calibrated */ +Bool_t testifMixingCalibration(vector*); +/** @brief Turns a value into a string with fixed precision */ +string to_str_w_prec(const Float_t a_value, int precision = 1); vector compareHistogramVector; TString ownpath = ""; @@ -123,32 +135,36 @@ Bool_t plotAllRuns() { return plotAllRuns(&compareHistogramClassVector); } +Bool_t testifMixingCalibration(vector* ptCompareHistogramClassVector) { + if ( !ptCompareHistogramClassVector->size() ) + { + 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 < ptCompareHistogramClassVector->size(); histogrami++) + { + 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; + if ( !(calibrated != uncalibrated)) // XOR operator != + { + cout << colorred << "plotCompareHistograms(): Mixing of calibrated and uncalibrated histograms when comparing plots. Aborting." << endlr; + return 1; + } + return 0; +} Bool_t plotAllRuns(vector* ptCompareHistogramClassVector) { if (numberRuns>0) { - if ( !ptCompareHistogramClassVector->size() ) - { - 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 < ptCompareHistogramClassVector->size(); histogrami++) - { - 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; - if ( !(calibrated != uncalibrated)) // XOR operator != - { - cout << colorred << "plotCompareHistograms(): Mixing of calibrated and uncalibrated histograms when comparing plots. Aborting." << endlr; - return 1; - } + if (testifMixingCalibration(ptCompareHistogramClassVector)) return 1; // legend entries Float_t height = ptCompareHistogramClassVector->size() * 0.04; @@ -175,7 +191,7 @@ Bool_t plotAllRuns(vector* ptCompareHistogramClassVector) curhistogramclone = (TH1F*) curhistogramclassp->Seed->Clone(); // curhistogramclone->SetLineColor(rootcolors[histogrami]); curhistogramclone->Draw("SAME"); - legendEntry = Form("%d %s", curhistogramclassp->runnumber, curhistogramclone->GetTitle()); + legendEntry = Form("%d %s", curhistogramclassp->labbook->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; @@ -200,7 +216,7 @@ Bool_t plotAllRuns(vector* ptCompareHistogramClassVector) curhistogramclone = (TH1F*) curhistogramclassp->Noise->Clone(); // curhistogramclone->SetLineColor(rootcolors[histogrami]); curhistogramclone->Draw("SAME"); - legendEntry = Form("%d Noise: %.2f + %.2f - %.2f",curhistogramclassp->runnumber, curhistogramclassp->avgNoise, curhistogramclassp->avgNoisePlus, curhistogramclassp->avgNoiseMinus); + legendEntry = Form("%d Noise: %.2f + %.2f - %.2f",curhistogramclassp->labbook->runnumber, curhistogramclassp->avgNoise, curhistogramclassp->avgNoisePlus, curhistogramclassp->avgNoiseMinus); leg2->AddEntry(curhistogramclone, legendEntry, "l"); leg2->Draw(); } @@ -210,3 +226,75 @@ Bool_t plotAllRuns(vector* ptCompareHistogramClassVector) return 1; } +Bool_t printSummaryTable(vector* ptCompareHistogramClassVector) +{ + if (ptCompareHistogramClassVector->size()>0) + { + if (testifMixingCalibration(ptCompareHistogramClassVector)) return 1; + const int width = 15; + cout << endlr << colorwhite << right << setw(width*9) << setfill('=') << " " << endl; + cout << left << setw(width*1) << setfill(' ') << "Cut type: "<< left << setw(width*8) << setfill(' ') << ptCompareHistogramClassVector->at(0)->histogramdescription << endl; + + cout << left << setw(width-5) << setfill(' ') << "Runnumber"; + cout << left << setw(width-10) << setfill(' ') << "Mtrx"; + Float_t printradion = 0; + for (vector::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++) + printradion += (*curHistogramClass)->labbook->radDoseIon; + if (printradion != 0) cout << left << setw(width-5) << setfill(' ') << "Rad. ion"; + Float_t printradnonion = 0; + for (vector::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++) + printradnonion += (*curHistogramClass)->labbook->radDoseNonIon; + if (printradnonion != 0) cout << left << setw(width-5) << setfill(' ') << "Rad. non-ion"; + Float_t printCCE = 0; + for (vector::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++) { + printCCE += (*curHistogramClass)->CCE_in_Perc_1; printCCE += (*curHistogramClass)->CCE_in_Perc_25; + } + if (printCCE != 0) cout << left << setw(width) << setfill(' ') << "CCE_1"; + if (printCCE != 0) cout << left << setw(width) << setfill(' ') << "CCE_25"; + Float_t printStoN = 0; + for (vector::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++) + printStoN += (*curHistogramClass)->StoN; + if (printStoN != 0) cout << left << setw(width) << setfill(' ') << "S/N"; + Float_t printIntegral = 0; + for (vector::iterator curHistogramClass = ptCompareHistogramClassVector->begin(); curHistogramClass != ptCompareHistogramClassVector->end(); curHistogramClass++) + printIntegral += (*curHistogramClass)->sr90IntegralVal; + if (printIntegral != 0) cout << left << setw(width) << setfill(' ') << "Integral"; + cout << left << setw(width) << setfill(' ') << "Noise"; + cout << endl; + for (UInt_t histogrami=0; histogrami < ptCompareHistogramClassVector->size(); histogrami++) + { + HistogramType* curhistogramclassp = ptCompareHistogramClassVector->at(histogrami); + cout << left << setw(width-5) << setfill(' ') << curhistogramclassp->labbook->runnumber; + cout << left << setw(width-10) << setfill(' ') << curhistogramclassp->labbook->matrix; + if (printradion != 0) cout << left << setw(width-5) << setfill(' ') << curhistogramclassp->labbook->radDoseIon; + if (printradnonion != 0) cout << left << setw(width-5) << setfill(' ') << curhistogramclassp->labbook->radDoseNonIon; + if (printCCE != 0) cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->CCE_in_Perc_1,ptCompareHistogramClassVector->at(0)->CCE_in_Perc_1); + if (printCCE != 0) cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->CCE_in_Perc_25,ptCompareHistogramClassVector->at(0)->CCE_in_Perc_25); + if (printStoN != 0) cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->StoN,ptCompareHistogramClassVector->at(0)->StoN); + if (printIntegral != 0) cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->sr90IntegralVal,ptCompareHistogramClassVector->at(0)->sr90IntegralVal); + cout << left << setw(width) << setfill(' ') << printTableElement(curhistogramclassp->avgNoise,ptCompareHistogramClassVector->at(0)->avgNoise); + cout << "" << endl; + } + cout << right << setw(width*9) << setfill('=') << " " << endl; + } + return 0; +} + +template string printTableElement(varType t1, varType t2, const int precision) +{ + float percentage = t1/t2*100.0; + string value = to_str_w_prec(t1, precision) + " (" + to_str_w_prec(percentage,0) + "%)"; + return value; +} + +string to_str_w_prec(const Float_t a_value, const int precision) +{ + std::ostringstream out; + if (abs(a_value) > 1) { + out << std::fixed << std::setprecision(precision) << a_value; + } else { + out << std::scientific << std::setprecision(precision) << a_value << std::fixed; out.setf(ios_base::fixed); + } + return out.str(); +} + diff --git a/MABS_run_analyzer/HistogramType.c b/MABS_run_analyzer/HistogramType.c index f04fae9..2ba9f9e 100644 --- a/MABS_run_analyzer/HistogramType.c +++ b/MABS_run_analyzer/HistogramType.c @@ -19,11 +19,11 @@ HistogramType::~HistogramType( void) { } -HistogramType::HistogramType(TString suffix, systemparam* gotsystempar, sensorinfostruct* gotsensorinfo, TString gothumanreadablestr, Int_t gotrunnumber, Int_t gotcolor, Int_t gotstyle ) { +HistogramType::HistogramType(TString suffix, systemparam* gotsystempar, sensorinfostruct* gotsensorinfo, TString gothumanreadablestr, labbooksctruct* plabbook, Int_t gotcolor, Int_t gotstyle ) { histogramdescription = suffix; humanreadablestr = gothumanreadablestr; cursystempar = gotsystempar; - runnumber = gotrunnumber; + labbook = plabbook; cursensorinfo = gotsensorinfo; initHistograms(gotcolor, gotstyle); }; @@ -49,7 +49,7 @@ 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("%d %s, %s",runnumber,prefix.Data(), humanreadablestr.Data()), cursystempar->nbins, 0, cursystempar->maxbin); + histogrampointer=new TH1F(Form("%d %s",labbook->runnumber, prefix.Data()), Form("%d %s, %s",labbook->runnumber,prefix.Data(), humanreadablestr.Data()), cursystempar->nbins, 0, cursystempar->maxbin); histogrampointer->SetLineStyle(style); histogrampointer->SetLineColor(color); histogrampointer->SetStats(kTRUE); @@ -83,8 +83,7 @@ Bool_t HistogramType::calibrateHistograms( Float_t gotgain ) { return 1; } gain = gotgain; - - calibrated = new HistogramType(histogramdescription+" calibrated", cursystempar, cursensorinfo, isthresholdclustertype, color, style); + calibrated = new HistogramType(histogramdescription+" calibrated", cursystempar, cursensorinfo, humanreadablestr, labbook, color, style); if (Seed != 0) calibrateHistogram(calibrated->Seed, Seed); if (Sum != 0) calibrateHistogram(calibrated->Sum, Sum); if (Veto != 0) calibrateHistogram(calibrated->Veto, Veto); @@ -98,6 +97,9 @@ Bool_t HistogramType::calibrateHistograms( Float_t gotgain ) { calibrated->avgNoisePlus = avgNoisePlus * gain; calibrated->avgNoiseMinus = avgNoiseMinus * gain; calibrated->sr90IntegralVal = sr90IntegralVal * gain; + calibrated->StoN = StoN; + calibrated->CCE_in_Perc_1 = CCE_in_Perc_1; + calibrated->CCE_in_Perc_25 = CCE_in_Perc_25; calibrated->iscalibrated = true; @@ -231,7 +233,7 @@ Float_t HistogramType::FitPerform(TH1F* histogrampointer, TString fitFuncType, B leg->AddEntry((TObject*) 0, legendEntry, ""); leg->SetTextSize(0.05); // leg->Draw(); - +// } else if (fitFuncType=="landau") { diff --git a/MABS_run_analyzer/HistogramType.h b/MABS_run_analyzer/HistogramType.h index fcdb130..1d1ff18 100644 --- a/MABS_run_analyzer/HistogramType.h +++ b/MABS_run_analyzer/HistogramType.h @@ -90,7 +90,7 @@ public: ~HistogramType(void); /** @brief constructor */ - HistogramType(TString suffix, systemparam* gotsystempar, sensorinfostruct* gotsensorinfo, TString gothumanreadablestr="", Int_t gotrunnumber=0, Int_t gotcolor=0, Int_t gotstyle=0); + HistogramType(TString suffix, systemparam* gotsystempar, sensorinfostruct* gotsensorinfo, TString gothumanreadablestr="", labbooksctruct* plabbook=0, Int_t gotcolor=0, Int_t gotstyle=0); //***************** // TH HISTOGRAMS @@ -149,8 +149,6 @@ public: //***************** /// A string representing the current run database information in a human readable format TString humanreadablestr=""; - /// Runnumber provided by Run.c from the database, used for names of histograms - Int_t runnumber = 0; /// type in here what the histogram is intended for or how it is calculated, will be added to filenames TString histogramdescription = ""; /// The gain used to rescale the histograms @@ -167,6 +165,8 @@ public: Float_t CCE_in_Perc_1=0; /// Signal to noise ratio Float_t StoN=0; + /// stores information from the SQL database of a given run + labbooksctruct* labbook; //***************** // METHODS APPLYABLE TO HISTOGRAMS diff --git a/MABS_run_analyzer/Run.c b/MABS_run_analyzer/Run.c index e12a6bc..793118a 100644 --- a/MABS_run_analyzer/Run.c +++ b/MABS_run_analyzer/Run.c @@ -151,13 +151,13 @@ Run::Run(Int_t runnumber, Int_t loopi) cout << colorwhite << "init Histogram classes:" << endlr; // default histogram class, no special cuts applied - histogram = new HistogramType("", &cursystemparam, &cursensorinfo, humanreadablestr, labbook.runnumber, rootcolors[plotStyle], rootlinestyle[plotStyle] ); + histogram = new HistogramType("", &cursystemparam, &cursensorinfo, humanreadablestr, &labbook, rootcolors[plotStyle], rootlinestyle[plotStyle] ); HistogramClassVector.push_back(histogram); // dynamical cluster threshold cut - histogramthreshold = new HistogramType(" Threshold", &cursystemparam, &cursensorinfo, humanreadablestr, labbook.runnumber, rootcolors[plotStyle], rootlinestyle[plotStyle] ); + histogramthreshold = new HistogramType(" Threshold", &cursystemparam, &cursensorinfo, humanreadablestr, &labbook, rootcolors[plotStyle], rootlinestyle[plotStyle] ); HistogramClassVector.push_back(histogramthreshold); // fixed threshold cut - histogramfixedthreshold = new HistogramType(" fixed Threshold", &cursystemparam, &cursensorinfo, humanreadablestr, labbook.runnumber, rootcolors[plotStyle], rootlinestyle[plotStyle] ); + histogramfixedthreshold = new HistogramType(" fixed Threshold", &cursystemparam, &cursensorinfo, humanreadablestr, &labbook, rootcolors[plotStyle], rootlinestyle[plotStyle] ); HistogramClassVector.push_back(histogramfixedthreshold); debugDBreadout(); diff --git a/MABS_run_analyzer/Run.h b/MABS_run_analyzer/Run.h index 3f176bd..6a2d78b 100644 --- a/MABS_run_analyzer/Run.h +++ b/MABS_run_analyzer/Run.h @@ -30,7 +30,6 @@ #include "help.h" - #define SERVERPATH "mysql://jspc29.x-matter.uni-frankfurt.de" #define SERVERUSER "radhard" #define SERVERPWD "mimosa88" @@ -307,64 +306,6 @@ public: */ Bool_t setDynamicalNoiseMode(TString mode); - /** - * @brief provides information from the SQL database - */ - struct labbooksctruct - { - /// runnumber for which the data is provided - Int_t runnumber = 0; - /// system, "USB" or "PXI" - TString system = ""; - /// temperature the run supposed to run with in °C - Float_t temp = -272; - /// actual temperature the chip had when meausurement started in °C - Float_t tempSens = -272; - /// number of chip/sensor used - TString chip = ""; - /// generation of the sensor - TString chipGen = ""; - /// the radioactive source the chip was radiated with during measurement - TString source = ""; - /// submatrix for which the measurement was done - TString matrix = ""; - /// ionizing radiation dose of the measured chip in MRad - Float_t radDoseIon = -1; - /// non-ionizing radiation dose of the chip in \f$ 10^{10} \frac{\text{neq}}{\text{cm}^2} \f$ - Float_t radDoseNonIon = -1; - /// position of th seed peak found in the database in ADU for this specific run - Float_t posSeedDB = -1; - /// position of th sum peak found in the database in ADU for this specific run - Float_t posSumDB = -1; - /// position of th veto peak found in the database in ADU for this specific run - Float_t posVetoDB = -1; - /// gain found in db - Float_t gainDB = -1; - /// average noise found in db - Float_t NoiseAvgDB = -1; - /// Positive noise error found in db - Float_t NoiseAvgPlusDB = -1; - /// Negative noise error found in db - Float_t NoiseAvgMinusDB = -1; - /// Charge collection efficciency of the cluster in percent found in db - 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 - Int_t epi_thickness = -1; - /// clock rate at wich the chip was measured in MHz - 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; diff --git a/MABS_run_analyzer/help.h b/MABS_run_analyzer/help.h index 16dc6a9..851462d 100644 --- a/MABS_run_analyzer/help.h +++ b/MABS_run_analyzer/help.h @@ -161,6 +161,65 @@ const TString colorcyan = "\033[1;36m"; const TString colorreset = "\033[0m"; const TString endlr = "\033[0m\n"; +/** + * @brief stores information from the SQL database + */ +struct labbooksctruct +{ + /// runnumber for which the data is provided + Int_t runnumber = 0; + /// system, "USB" or "PXI" + TString system = ""; + /// temperature the run supposed to run with in °C + Float_t temp = -272; + /// actual temperature the chip had when meausurement started in °C + Float_t tempSens = -272; + /// number of chip/sensor used + TString chip = ""; + /// generation of the sensor + TString chipGen = ""; + /// the radioactive source the chip was radiated with during measurement + TString source = ""; + /// submatrix for which the measurement was done + TString matrix = ""; + /// ionizing radiation dose of the measured chip in MRad + Float_t radDoseIon = -1; + /// non-ionizing radiation dose of the chip in \f$ 10^{10} \frac{\text{neq}}{\text{cm}^2} \f$ + Float_t radDoseNonIon = -1; + /// position of th seed peak found in the database in ADU for this specific run + Float_t posSeedDB = -1; + /// position of th sum peak found in the database in ADU for this specific run + Float_t posSumDB = -1; + /// position of th veto peak found in the database in ADU for this specific run + Float_t posVetoDB = -1; + /// gain found in db + Float_t gainDB = -1; + /// average noise found in db + Float_t NoiseAvgDB = -1; + /// Positive noise error found in db + Float_t NoiseAvgPlusDB = -1; + /// Negative noise error found in db + Float_t NoiseAvgMinusDB = -1; + /// Charge collection efficciency of the cluster in percent found in db + 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 + Int_t epi_thickness = -1; + /// clock rate at wich the chip was measured in MHz + 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; +}; + void preparecanvas() { // TCanvas* canvas = new TCanvas("Canvas1", 700, 500); // histogram->SetTitle(titlestr); -- 2.43.0