From: Benjamin Linnik Date: Fri, 11 Sep 2015 16:58:45 +0000 (+0200) Subject: Run analyzer: Added the function Run::plotCompareHistograms(), see documentation... X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=3f634cfc20887c5cc0d8c4e3b988ecbebc870b97;p=radhard.git Run analyzer: Added the function Run::plotCompareHistograms(), see documentation for usage --- diff --git a/MABS_run_analyzer/MAPS.c b/MABS_run_analyzer/MAPS.c index 6efd43b..0757651 100644 --- a/MABS_run_analyzer/MAPS.c +++ b/MABS_run_analyzer/MAPS.c @@ -59,6 +59,7 @@ Bool_t MAPS::initNewRootFile() { fHitTree->Branch("pixel" , &fFrameInfo.pixel[0] , "pixel[hits]/i" , 32000); fHitTree->Branch("pixelRaw" , &fFrameInfo.pixelRaw[0] , "pixelRaw[hits]/i" , 32000); fHitTree->Branch("pixelthreshold", &fFrameInfo.pixelthreshold[0],"pixelthreshold[hits]/i", 32000); + fHitTree->Branch("pixelfixedthreshold", &fFrameInfo.pixelfixedthreshold[0],"pixelfixedthreshold[hits]/i", 32000); for(int i=0; i<25; i++) { fHitTree->Branch( Form("p%i",i+1) , &fFrameInfo.p[i][0] , Form("p%i [hits]/F",i+1) , 32000); } @@ -93,6 +94,8 @@ Bool_t MAPS::initOldRootFile() { fHitTree->SetBranchAddress("hits" , &fFrameInfo.hits ); fHitTree->SetBranchAddress ("pixel", &fFrameInfo.pixel[0]); fHitTree->SetBranchAddress ("pixelthreshold", &fFrameInfo.pixelthreshold[0]); + fHitTree->SetBranchAddress ("pixelfixedthreshold", &fFrameInfo.pixelfixedthreshold[0]); + for(int i=0; i<25; i++) { fHitTree->SetBranchAddress( Form("p%i",i+1) , &fFrameInfo.p[i][0]); } @@ -1640,6 +1643,11 @@ void MAPS::hitana() { fFrameInfo.pixelthreshold[fHits] = Hitlist[hit]; else fFrameInfo.pixelthreshold[fHits] = 0; + + if (1.0*chargesumincluster4 > 150) + fFrameInfo.pixelfixedthreshold[fHits] = Hitlist[hit]; + else + fFrameInfo.pixelfixedthreshold[fHits] = 0; } else { @@ -1647,6 +1655,11 @@ void MAPS::hitana() { fFrameInfo.pixelthreshold[fHits] = Hitlist[hit]; else fFrameInfo.pixelthreshold[fHits] = 0; + + if (1.0*chargesumincluster > 150) + fFrameInfo.pixelfixedthreshold[fHits] = Hitlist[hit]; + else + fFrameInfo.pixelfixedthreshold[fHits] = 0; } if(fSave) { hint1->Fill( Hitlist[hit]%fColumns, (int)(Hitlist[hit]/fColumns) ); diff --git a/MABS_run_analyzer/Run.c b/MABS_run_analyzer/Run.c index d316bf9..76ca7c7 100644 --- a/MABS_run_analyzer/Run.c +++ b/MABS_run_analyzer/Run.c @@ -148,7 +148,8 @@ Run::Run(Int_t runnumber, Int_t loopi) initRootParameters(); cout << colorwhite << "initHistograms():" << endlr; initHistograms(&histogram); - initHistograms(&histogramthreshold, " threshold"); + initHistograms(&histogramthreshold, "threshold"); + initHistograms(&histogramfixedthreshold, "fixed threshold"); debugDBreadout(); } else @@ -276,7 +277,7 @@ Bool_t Run::analyzeRun(Bool_t force) int start = 0; int nframes = processed->GetNumberFrames(); // for(int i=0; i<1000;i++) // TODO remove 100000 run 342272 - for(int i=0; igetFrame(i); @@ -316,6 +317,7 @@ Bool_t Run::analyzeRun(Bool_t force) cout << colorwhite << "rescaleHistograms():" << endlr; histogramCalibrated.calibrated = rescaleHistograms(); histogramthresholdCalibrated.calibrated = histogramCalibrated.calibrated; + histogramfixedthresholdCalibrated.calibrated = histogramCalibrated.calibrated; cout << colorwhite << "calculateCCE():" << endlr; calculteCCE(); if (labbook.source.Contains("Sr90")) { @@ -400,6 +402,18 @@ Bool_t Run::rescaleHistograms() histogramthresholdCalibrated.avgNoisePlus = histogramthreshold.avgNoisePlus * gain; histogramthresholdCalibrated.avgNoiseMinus = histogramthreshold.avgNoiseMinus * gain; + rescaleHistogram(histogramfixedthresholdCalibrated.Seed, histogramfixedthreshold.Seed); + rescaleHistogram(histogramfixedthresholdCalibrated.Sum, histogramfixedthreshold.Sum); + rescaleHistogram(histogramfixedthresholdCalibrated.Veto, histogramfixedthreshold.Veto); + rescaleHistogram(histogramfixedthresholdCalibrated.Noise, histogramfixedthreshold.Noise); + + histogramfixedthresholdCalibrated.posSeed = histogramfixedthreshold.posSeed * gain; + histogramfixedthresholdCalibrated.posSum = histogramfixedthreshold.posSum * gain; + histogramfixedthresholdCalibrated.posVeto = histogramfixedthreshold.posVeto * gain; + histogramfixedthresholdCalibrated.avgNoise = histogramfixedthreshold.avgNoise * gain; + histogramfixedthresholdCalibrated.avgNoisePlus = histogramfixedthreshold.avgNoisePlus * gain; + histogramfixedthresholdCalibrated.avgNoiseMinus = histogramfixedthreshold.avgNoiseMinus * gain; + if (histogramthreshold.histAvgCluster != nullptr) { rescale2DHistogramCounts(histogramthresholdCalibrated.histAvgCluster, histogramthreshold.histAvgCluster); @@ -770,6 +784,9 @@ Bool_t Run::binNoise() histogramthreshold.avgNoise = histogram.avgNoise; histogramthreshold.avgNoisePlus = histogram.avgNoisePlus; histogramthreshold.avgNoiseMinus = histogram.avgNoiseMinus; + histogramfixedthreshold.avgNoise = histogram.avgNoise; + histogramfixedthreshold.avgNoisePlus = histogram.avgNoisePlus; + histogramfixedthreshold.avgNoiseMinus = histogram.avgNoiseMinus; // if (labbook.system == "PXI") // for (int j=0; j<3; j++) // noisequantiles[j] /= 16.0; // TODO analyze PXI scales @@ -853,6 +870,16 @@ Bool_t Run::binSeedSumVeto() if (TMath::Abs(notSeedSum) < systemparamcur.vetothreshold && (labbook.source.Contains("Fe")||labbook.source.Contains("Cd"))) histogramthreshold.Veto->Fill(processed->fFrameInfo.p[12][hiti]); // histogram with the single pixel } + + if (processed->fFrameInfo.pixelfixedthreshold[hiti]>0) + { + histogramfixedthreshold.numberofhits++; + + histogramfixedthreshold.Seed->Fill(processed->fFrameInfo.p[12][hiti]); + histogramfixedthreshold.Sum->Fill(pixelSum); + if (TMath::Abs(notSeedSum) < systemparamcur.vetothreshold && (labbook.source.Contains("Fe")||labbook.source.Contains("Cd"))) + histogramfixedthreshold.Veto->Fill(processed->fFrameInfo.p[12][hiti]); // histogram with the single pixel + } } } } @@ -866,6 +893,10 @@ Bool_t Run::binSeedSumVeto() histogramthreshold.posVeto=FitPerform(histogram.Veto, "gaus", false); histogramthreshold.posSeed=FitPerform(histogram.Seed, "landau", false); histogramthreshold.posSum=FitPerform(histogram.Sum, "gaus", false); + if (labbook.source.Contains("Fe")||labbook.source.Contains("Cd")) + histogramfixedthreshold.posVeto=FitPerform(histogramfixedthreshold.Veto, "gaus", false); + histogramfixedthreshold.posSeed=FitPerform(histogramfixedthreshold.Seed, "landau", false); + histogramfixedthreshold.posSum=FitPerform(histogramfixedthreshold.Sum, "gaus", false); // gROOT->SetBatch(kFALSE); return 0; } @@ -932,6 +963,8 @@ Bool_t Run::binCluster() histogram.histAvgCluster->Fill(xcoord,ycoord,processed->fFrameInfo.p[clusteri][hiti]); if (processed->fFrameInfo.pixelthreshold[hiti]>0) histogramthreshold.histAvgCluster->Fill(xcoord,ycoord,processed->fFrameInfo.p[clusteri][hiti]); + if (processed->fFrameInfo.pixelfixedthreshold[hiti]>0) + histogramfixedthreshold.histAvgCluster->Fill(xcoord,ycoord,processed->fFrameInfo.p[clusteri][hiti]); } } else // Diode sitzt unten im SeedPixel, da nach PitchY angeordnet @@ -961,6 +994,8 @@ Bool_t Run::binCluster() histogram.histAvgCluster->Fill(xcoord,ycoord,processed->fFrameInfo.p[clusteri][hiti]); if (processed->fFrameInfo.pixelthreshold[hiti]>0) histogramthreshold.histAvgCluster->Fill(xcoord,ycoord,processed->fFrameInfo.p[clusteri][hiti]); + if (processed->fFrameInfo.pixelfixedthreshold[hiti]>0) + histogramfixedthreshold.histAvgCluster->Fill(xcoord,ycoord,processed->fFrameInfo.p[clusteri][hiti]); } } } @@ -972,6 +1007,7 @@ Bool_t Run::binCluster() for (Int_t clustery = 1; clustery <=histogram.histAvgCluster->GetYaxis()->GetNbins();clustery++) { histogram.histAvgCluster->SetBinContent(clusterx,clustery,histogram.histAvgCluster->GetBinContent(clusterx,clustery)/histogram.numberofhits); histogramthreshold.histAvgCluster->SetBinContent(clusterx,clustery,histogramthreshold.histAvgCluster->GetBinContent(clusterx,clustery)/histogramthreshold.numberofhits); + histogramfixedthreshold.histAvgCluster->SetBinContent(clusterx,clustery,histogramfixedthreshold.histAvgCluster->GetBinContent(clusterx,clustery)/histogramfixedthreshold.numberofhits); } } @@ -1156,19 +1192,106 @@ Bool_t Run::plotVeto() // // } + +Bool_t Run::plotCompareHistograms() +{ + if (!error) + { + if ( !plothistogramstructpointerarray.size() ) // XOR operator != + { + cout << colorred << "plotCompareHistograms(): No plots to compare, please push them into the vector: Run::plothistogramstructpointerarray." << endlr; + return 1; + } + Bool_t calibrated = true; + Bool_t uncalibrated = true; + for (UInt_t histogrami=0; histogrami < plothistogramstructpointerarray.size(); histogrami++) + { + calibrated = calibrated && plothistogramstructpointerarray.at(histogrami)->calibrated; + uncalibrated = uncalibrated && !plothistogramstructpointerarray.at(histogrami)->calibrated; + cout << colorcyan << plothistogramstructpointerarray.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; + } + + // legend entries + Float_t height = plothistogramstructpointerarray.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); + TLegend* leg2 = (TLegend*) leg1->Clone(); + TString legendEntry; + + Float_t lastbin1=0; + Float_t lastbin2=0; + Float_t lastbin3=0; + Float_t lastbin4=0; + Int_t random = random1->Rndm()*1000000; + TString canvastitle = Form("%s Comparison", runcode.Data()); + if (calibrated) + canvastitle += "_el"; + TString canvasname = Form("%s%d",runcode.Data(),random); + TCanvas* canvas = new TCanvas(canvasname, canvastitle, 1200, 800); + canvas->Divide(2,2); + for (UInt_t histogrami=0; histogrami < plothistogramstructpointerarray.size(); histogrami++) + { + histogramstruct* curhistogramstructp = plothistogramstructpointerarray.at(histogrami); + TH1F* curhistogramclone; + canvas->cd(1); + curhistogramclone = (TH1F*) curhistogramstructp->Seed->Clone(); + curhistogramclone->SetLineColor(rootcolors[histogrami]); + curhistogramclone->Draw("SAME"); + legendEntry = Form("%s", 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; + curhistogramclone->SetAxisRange(0,lastbin1*1.1,"X"); + gPad->SetLogy(1); + canvas->cd(2); + curhistogramclone = (TH1F*) curhistogramstructp->Sum->Clone(); + curhistogramclone->SetLineColor(rootcolors[histogrami]); + curhistogramclone->Draw("SAME"); + leg1->Draw("SAME"); + lastbin2 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1))>lastbin2)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1)):lastbin2; + curhistogramclone->SetAxisRange(0,lastbin2*1.1,"X"); + gPad->SetLogy(1); + canvas->cd(3); + curhistogramclone = (TH1F*) curhistogramstructp->Veto->Clone(); + curhistogramclone->SetLineColor(rootcolors[histogrami]); + curhistogramclone->Draw("SAME"); + leg1->Draw("SAME"); + lastbin3 = (curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1))>lastbin3)?curhistogramclone->GetBinCenter(curhistogramclone->FindLastBinAbove(2,1)):lastbin3; + curhistogramclone->SetAxisRange(0,lastbin3*1.1,"X"); + canvas->cd(4); + curhistogramclone = (TH1F*) curhistogramstructp->Noise->Clone(); + curhistogramclone->SetLineColor(rootcolors[histogrami]); + curhistogramclone->Draw(); + legendEntry = Form("Noise: %.2f + %.2f - %.2f",curhistogramstructp->avgNoise, curhistogramstructp->avgNoisePlus, curhistogramstructp->avgNoiseMinus); + leg2->AddEntry(curhistogramclone, legendEntry, "l"); + leg2->Draw(); + } + + return 0; + } + return 1; +} + + Bool_t Run::plotAllHistograms(histogramstruct* histogramstructpointer) { if (!error) { Float_t lastbin; - Int_t random = random1->Rndm()*100000; - TString canvastitle = Form("%s", runcode.Data()); + Int_t random = random1->Rndm()*1000000; + TString canvastitle = Form("%s %s", runcode.Data(), histogramstructpointer->histogramdescription.Data()); if (histogramstructpointer->calibrated) canvastitle += "_el"; - if (histogramstructpointer->thresholdcluster) - canvastitle += "_trsh"; TString canvasname = Form("%s%d",runcode.Data(),random); - TCanvas* canvas = new TCanvas(canvasname, canvastitle, 1200, 800); + TCanvas* canvas = new TCanvas(canvasname, canvastitle, 1200, 800); canvas->Divide(2,2); canvas->cd(1); histogramstructpointer->Seed->Draw(""); @@ -1894,11 +2017,12 @@ void Run::MakeGnuplotFile() void Run::initHistograms(histogramstruct* histogramstructpointer, TString suffix) { - initHistogram(histogramstructpointer->Seed, "Seed" + suffix); - initHistogram(histogramstructpointer->Sum, "Sum" + suffix); - initHistogram(histogramstructpointer->Veto, "Veto" + suffix); + histogramstructpointer->histogramdescription = suffix; + initHistogram(histogramstructpointer->Seed, "Seed " + suffix); + initHistogram(histogramstructpointer->Sum, "Sum " + suffix); + initHistogram(histogramstructpointer->Veto, "Veto " + suffix); - TString prefix = "Noise" + suffix; + TString prefix = "Noise " + suffix; TString humanreadablestr = Form("%s, %s spectrum, %s, chip %s, %s, %sT=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), humanreadablesuffix.Data(), labbook.temp); if (suffix.Contains("threshold")) @@ -1950,6 +2074,7 @@ void Run::initClusters(Float_t xcoord_min_step, Float_t xcoord_abs_min, Float_t initCluster(&histogram, "", xcoord_min_step, xcoord_abs_min, xcoord_abs_max, ycoord_min_step, ycoord_abs_min, ycoord_abs_max); initCluster(&histogramthreshold, "_threshold", xcoord_min_step, xcoord_abs_min, xcoord_abs_max, ycoord_min_step, ycoord_abs_min, ycoord_abs_max); + initCluster(&histogramfixedthreshold, "_fixed_threshold", xcoord_min_step, xcoord_abs_min, xcoord_abs_max, ycoord_min_step, ycoord_abs_min, ycoord_abs_max); } void Run::initCluster(histogramstruct* histogramstructpointer, TString suffix, Float_t xcoord_min_step, Float_t xcoord_abs_min, Float_t xcoord_abs_max, Float_t ycoord_min_step, Float_t ycoord_abs_min, Float_t ycoord_abs_max) @@ -1966,9 +2091,9 @@ void Run::initCluster(histogramstruct* histogramstructpointer, TString suffix, F } void Run::initRootParameters() -{ rootcolors = new Int_t[13]{1, 2, 4, 6, 8, 13, 46, 28, 32, 33, 12, 20, 40}; +{ + rootcolors = new Int_t[13]{1, 2, 4, 6, 8, 13, 46, 28, 32, 33, 12, 20, 40}; rootlinestyle = new Int_t[13]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; - } #endif diff --git a/MABS_run_analyzer/Run.h b/MABS_run_analyzer/Run.h index bb3a74f..d638ced 100644 --- a/MABS_run_analyzer/Run.h +++ b/MABS_run_analyzer/Run.h @@ -326,6 +326,23 @@ public: systemparam systemparamcur; void setPlotStyle(Int_t); + + /** @brief Compare histograms + * + * Compare histograms given in the vector + * #Run::plothistogramstructpointerarray which holds structures + * of type #Run::histogram into one canvas + * * + * Use a line such as + * @code runs[runi]->plothistogramstructpointerarray.push_back(&runs[runi]->histogramfixedthreshold); + * @endcode + * to add histograms to compare, after adding a few, execute + * @code runs[runi]->plotCompareHistograms() + * @endcode + * in ChargeSpectrum.c + * + */ + Bool_t plotCompareHistograms( ); /** @brief Plot all histograms from @c Run::histogram into one canvas */ Bool_t plotAllHistograms(); @@ -531,20 +548,26 @@ public: /// number of hits/clusters used to generate all distributions Double_t numberofhits = 0; + + /// type in here what the histogram is intended for or how it is calculated, will be added to filenames + TString histogramdescription = ""; }; histogramstruct histogram; histogramstruct histogramCalibrated; histogramstruct histogramthreshold; histogramstruct histogramthresholdCalibrated; + histogramstruct histogramfixedthreshold; + histogramstruct histogramfixedthresholdCalibrated; histogramstruct* plothistogramstructpointer; TH1F** plothistogrampointer; - + vector plothistogramstructpointerarray; + /** @brief Plots all histograms from #Run::histogramstruct into one canvas * * @param histogramstruct pointer to a histogram structure of type #Run::histogramstruct */ Bool_t plotAllHistograms(histogramstruct*); - + /** @brief Plots average cluster charge distribution * * Creates a graphical view of the average charge distribution in a diff --git a/MABS_run_analyzer/help.h b/MABS_run_analyzer/help.h index 04b8045..4ab1196 100644 --- a/MABS_run_analyzer/help.h +++ b/MABS_run_analyzer/help.h @@ -111,6 +111,8 @@ struct frameInfo{ UInt_t pixelRaw [MAXHITS]; /// holds pixel number of hitted cluster seed pixel over the threshold in frame UInt_t pixelthreshold [MAXHITS]; + /// holds pixel number of hitted cluster seed pixel over a fixed threshold in frame + UInt_t pixelfixedthreshold [MAXHITS]; /// holds charge collected by cluster for a given hit in frame, p[12][7] f.e. holds seed pixel charge of hit number 8 in frame Float_t p [25][MAXHITS]; };