From 372bd58105da3e6d449f2e0f4a08f9163cb84868 Mon Sep 17 00:00:00 2001 From: Benjamin Linnik Date: Thu, 28 Jul 2016 16:20:26 +0200 Subject: [PATCH] run analyzer: Code cleanup --- MABS_run_analyzer/ChargeSpektrum.c | 132 +++----------------- MABS_run_analyzer/ChargeSpektrumFunctions.c | 103 +++++++++++++++ MABS_run_analyzer/MAPS.c | 81 +++++++----- MABS_run_analyzer/Run.c | 15 ++- 4 files changed, 182 insertions(+), 149 deletions(-) diff --git a/MABS_run_analyzer/ChargeSpektrum.c b/MABS_run_analyzer/ChargeSpektrum.c index 55b0a95..f52aa6d 100644 --- a/MABS_run_analyzer/ChargeSpektrum.c +++ b/MABS_run_analyzer/ChargeSpektrum.c @@ -1,8 +1,11 @@ /** * @file ChargeSpektrum.c - * @brief Use brief, otherwise the index won't have a brief explanation. + * @brief This is the main program, it manages the user input and creats classes of type Run.c * - * Detailed explanation. + * The main program reads in and interprets the user input, and organizes it. Each runnumber is used + * to create classes of type "Run.c". + * + * Modify this file to enable/disable plots and data outputs. * * */ @@ -24,113 +27,19 @@ TString savepathresults = "./results/"; void ChargeSpektrum(TString runnumber = "") { -#include "SetStyle.c" cout << endl << endl; if (gROOT->IsBatch()) isBatch = kTRUE; - + numberRuns=0; std::vector runList; std::vector runListForceAnalysis; std::vector runListCustomTitle; std::vector sumuprunList; // not used yet, add runs to each other, combine statistics - if (runnumber.Length() > 0) - { - if (runnumber.Contains("-")) { - TObjArray* runarray = runnumber.Tokenize("-"); - if (runarray->GetEntries()==2) - { - TObjString* tempstrobj; - tempstrobj=static_cast(runarray->At(0)); - if (tempstrobj->GetString().Length()>0) - { - Int_t tempintstart = tempstrobj->GetString().Atoi(); - tempstrobj=static_cast(runarray->At(1)); - if (tempstrobj->GetString().Length()>0) - { - Int_t tempintend = tempstrobj->GetString().Atoi(); - if (tempintend-tempintstart > 0) - { - for (Int_t i=tempintstart; i <= tempintend; i++) - { - runList.push_back(i); - runListForceAnalysis.push_back(kFALSE); - numberRuns++; - } - } - else - cout << coloryellow << "Invalid run number range "<< colorreset << colorwhite << tempintstart << " till " << tempintend << endlr; - } - else - cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr; - - } - else - cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr; - } - else - { - cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset << colorwhite << "," << colorreset << colorred << " or 2 runnumbers devided by " << colorreset << colorwhite << "-" << colorreset << colorred << "' and surrounded by '" << colorreset << colorwhite << "\"" << colorreset << colorred << "'." << endlr; - cout << "For example run: " << colorwhite << "root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl; - exit(1); - } - - } else { - TObjArray* runarray = runnumber.Tokenize(","); // seperate run numbers by ',' - if (runarray->GetEntries()>0) - { - TObjString* tempstrobj; - for (Int_t i=0; i < runarray->GetEntries(); i++) - { - tempstrobj=static_cast(runarray->At(i)); - if (tempstrobj->GetString().Length()>0) - { - TString sumrunsstr = ""; - TObjArray* sumrunarray = tempstrobj->GetString().Tokenize("+"); - TObjString* sumuprunsstrobj; - for (Int_t j=0; j < sumrunarray->GetEntries(); j++) - { - sumuprunsstrobj=static_cast(sumrunarray->At(j)); - TString currunnumberstr = sumuprunsstrobj->GetString(); - Int_t tempint = currunnumberstr.Atoi(); - if (tempint > 0) - { - runList.push_back(tempint); - if (currunnumberstr.Contains("!")) - runListForceAnalysis.push_back(kTRUE); - else - runListForceAnalysis.push_back(kFALSE); - if (currunnumberstr.Contains("=")) { - cout << colorcyan << currunnumberstr << endlr; - runListCustomTitle.push_back(currunnumberstr(currunnumberstr.Index('=')+1,currunnumberstr.Length()-currunnumberstr.Index('=')-1)); - } else { - runListCustomTitle.push_back(""); - } - sumrunsstr.Append(Form("%d,",tempint)); - numberRuns++; - } - else - cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempint << endlr; - } - sumuprunList.push_back(sumrunsstr); - } - else - cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr; - } - } - else - { - cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset << colorwhite << "," << colorreset << colorred << "' and surrounded by '" << colorreset << colorwhite << "\"" << colorreset << colorred << "'." << endlr; - cout << "For example run: " << colorwhite << "root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl; - exit(1); - } - } - } - else - { - /// number of runs to be analyzed, number of lines read by @c ReadRunList() - ReadRunList(&runList); - } + + #include "SetStyle.c" + InterpreteUserInput(runnumber, &runList, &runListForceAnalysis, &runListCustomTitle, &sumuprunList); + runs = new Run*[numberRuns]; cout << "Found " << numberRuns << " run(s) in 'runlist.txt' or given as parameters." << endl; @@ -149,9 +58,7 @@ void ChargeSpektrum(TString runnumber = "") //runs[runi]->setFixedThresholdValueElectrons(1440); //runs[runi]->setNoisethresholdborderADU(30); -// runs[runi]->analyzeFrame(57826); -// runs[runi]->analyzeFrame(57827); -// runs[runi]->analyzeFrame(983603); +// runs[runi]->analyzeFrame(1000); // creates or opens .root file, can analyze the RAW data if (runListForceAnalysis.size() >= (unsigned)runi+1) @@ -185,15 +92,16 @@ void ChargeSpektrum(TString runnumber = "") // runs[runi]->compareHistogramClassVector.push_back(runs[runi]->histogramthreshold->calibrated); // runs[runi]->compareHistogramClassVector.push_back(runs[runi]->histogramfixedthreshold); // runs[runi]->plotCompareHistograms(); -// runs[runi]->plotAllHistograms(runs[runi]->histogramthreshold); - compareHistogramClassVector.push_back(runs[runi]->histogramthreshold->normalized); - compareHistogramVector.push_back(runs[runi]->histogramthreshold->normalized->calibrated->Seed); - compareHistogramVector2.push_back(runs[runi]->histogramthreshold->normalized->Seed); + runs[runi]->plotAllHistograms(runs[runi]->histogram); + compareHistogramClassVector.push_back(runs[runi]->histogram->normalized); +// compareHistogramVector.push_back(runs[runi]->histogramthreshold->normalized->calibrated->Seed); +// compareHistogramVector2.push_back(runs[runi]->histogramthreshold->normalized->Seed); //compareHistogramClassVector.push_back(runs[runi]->histogram); // runs[runi]->plot1DHistogram(runs[runi]->histogramthreshold, runs[runi]->histogramthreshold->Veto, "gaus"); - runs[runi]->plot1DHistogram(runs[runi]->histogramthreshold, runs[runi]->histogramthreshold->normalized->Sum, "gaus", 1); - runs[runi]->plot1DHistogram(runs[runi]->histogramthreshold, runs[runi]->histogramthreshold->normalized->Veto, "GaussTail", 1); - // compareHistogramVector.push_back(runs[runi]->histogramthreshold->calibrated->normalized->Veto); +// runs[runi]->plot1DHistogram(runs[runi]->histogram, runs[runi]->histogram->Sum, "gaus", 1); +// runs[runi]->plot1DHistogram(runs[runi]->histogramthreshold, runs[runi]->histogramthreshold->Veto, "GaussTail", 1); + // compareHistogramVector.push_back(runs[runi]->histogramthreshold->calibrated->normalized->Veto); +// runs[runi]->plot1DHistogram(runs[runi]->histogram, runs[runi]->histogram->Seed, "landau", 1); runs[runi]->writeAllHistogramsToFile(); } //cout << runs[runi]->histogram @@ -217,7 +125,7 @@ void ChargeSpektrum(TString runnumber = "") // runs[3]->setLabel("HR18, P13, 5.0 V"); printSummaryTable(&compareHistogramClassVector); // CompareHistograms(&compareHistogramVector); -CompareHistograms(&compareHistogramVector2); +// CompareHistograms(&compareHistogramVector2); plotAllRuns(&compareHistogramClassVector); // plotAllRuns(&compareHistogramClassVector2); // plotAllRuns(&compareHistogramClassVector3); diff --git a/MABS_run_analyzer/ChargeSpektrumFunctions.c b/MABS_run_analyzer/ChargeSpektrumFunctions.c index 3a0776b..23656aa 100644 --- a/MABS_run_analyzer/ChargeSpektrumFunctions.c +++ b/MABS_run_analyzer/ChargeSpektrumFunctions.c @@ -19,6 +19,7 @@ using namespace std; Int_t* ReadRunList(); Int_t ReadRunList(std::vector*); +void InterpreteUserInput(TString, std::vector*, std::vector*, std::vector*, std::vector*); Bool_t plotAllRuns(); Bool_t plotAllRuns(vector*); /** @brief A function to plot TH1F histograms of different runs into one file @@ -80,6 +81,108 @@ void ChargeSpektrum(Int_t runnumber, Int_t runnumber2) exit(1); } +void InterpreteUserInput(TString runnumber, std::vector *runList, std::vector *runListForceAnalysis, std::vector *runListCustomTitle, std::vector *sumuprunList) +{ + if (runnumber.Length() > 0) + { + if (runnumber.Contains("-")) { + TObjArray* runarray = runnumber.Tokenize("-"); + if (runarray->GetEntries()==2) + { + TObjString* tempstrobj; + tempstrobj=static_cast(runarray->At(0)); + if (tempstrobj->GetString().Length()>0) + { + Int_t tempintstart = tempstrobj->GetString().Atoi(); + tempstrobj=static_cast(runarray->At(1)); + if (tempstrobj->GetString().Length()>0) + { + Int_t tempintend = tempstrobj->GetString().Atoi(); + if (tempintend-tempintstart > 0) + { + for (Int_t i=tempintstart; i <= tempintend; i++) + { + runList->push_back(i); + runListForceAnalysis->push_back(kFALSE); + numberRuns++; + } + } + else + cout << coloryellow << "Invalid run number range "<< colorreset << colorwhite << tempintstart << " till " << tempintend << endlr; + } + else + cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr; + + } + else + cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr; + } + else + { + cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset << colorwhite << "," << colorreset << colorred << " or 2 runnumbers devided by " << colorreset << colorwhite << "-" << colorreset << colorred << "' and surrounded by '" << colorreset << colorwhite << "\"" << colorreset << colorred << "'." << endlr; + cout << "For example run: " << colorwhite << "root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl; + exit(1); + } + + } else { + TObjArray* runarray = runnumber.Tokenize(","); // seperate run numbers by ',' + if (runarray->GetEntries()>0) + { + TObjString* tempstrobj; + for (Int_t i=0; i < runarray->GetEntries(); i++) + { + tempstrobj=static_cast(runarray->At(i)); + if (tempstrobj->GetString().Length()>0) + { + TString sumrunsstr = ""; + TObjArray* sumrunarray = tempstrobj->GetString().Tokenize("+"); + TObjString* sumuprunsstrobj; + for (Int_t j=0; j < sumrunarray->GetEntries(); j++) + { + sumuprunsstrobj=static_cast(sumrunarray->At(j)); + TString currunnumberstr = sumuprunsstrobj->GetString(); + Int_t tempint = currunnumberstr.Atoi(); + if (tempint > 0) + { + runList->push_back(tempint); + if (currunnumberstr.Contains("!")) + runListForceAnalysis->push_back(kTRUE); + else + runListForceAnalysis->push_back(kFALSE); + if (currunnumberstr.Contains("=")) { + cout << colorcyan << currunnumberstr << endlr; + runListCustomTitle->push_back(currunnumberstr(currunnumberstr.Index('=')+1,currunnumberstr.Length()-currunnumberstr.Index('=')-1)); + } else { + runListCustomTitle->push_back(""); + } + sumrunsstr.Append(Form("%d,",tempint)); + numberRuns++; + } + else + cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempint << endlr; + } + sumuprunList->push_back(sumrunsstr); + } + else + cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr; + } + } + else + { + cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset << colorwhite << "," << colorreset << colorred << "' and surrounded by '" << colorreset << colorwhite << "\"" << colorreset << colorred << "'." << endlr; + cout << "For example run: " << colorwhite << "root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl; + exit(1); + } + } + } + else + { + /// number of runs to be analyzed, number of lines read by @c ReadRunList() + ReadRunList(runList); + } +} + + Int_t ReadRunList(std::vector* runlist) { std::ifstream file("runlist.txt"); diff --git a/MABS_run_analyzer/MAPS.c b/MABS_run_analyzer/MAPS.c index e48397b..2bc586a 100644 --- a/MABS_run_analyzer/MAPS.c +++ b/MABS_run_analyzer/MAPS.c @@ -751,6 +751,7 @@ if(fOk) } PEDESTAL = PEDESTAL/Frames; + cout << colorcyan << "Pedestal :" << PEDESTAL << endlr; for(UInt_t j=0; j(fCdsmatrix, fPixels, fColumns, 2, 20); - // cout<<"Pedestals"<(fPedestals, fPixels, fColumns, 2, 20); +// cout<(fCdsmatrix, fPixels, fColumns, 2, 20); +// cout<<"Pedestals"<(fPedestals, fPixels, fColumns, 2, 20); for(Int_t i=0; i(fHittedPixel, fPixels, fColumns, 1, 1); +// cout<<"Hitted pixel discriminator matrix:"<(fHittedPixel, fPixels, fColumns, 1, 1); fHittedPixel[rechargePixellist[rechargingpixeli]] = -4; } @@ -1576,7 +1578,8 @@ void MAPS::hitana() { } } - +// if ( B < 10) CHANCE=0; // TODO remove me, buggy column 3 in Mi19, triing to ommit dirty? + @@ -1617,8 +1620,8 @@ void MAPS::hitana() { } } } - // cout<<"Hitted pixel discriminator matrix:"<(fHittedPixel, fPixels, fColumns, 1, 1); +// cout<<"Hitted pixel discriminator matrix:"<(fHittedPixel, fPixels, fColumns, 1, 1); if (bordercluster) fHittedPixel[Hitlist[hit]] = -2; else @@ -1676,19 +1679,22 @@ void MAPS::hitana() { // { // cout<<"Charge"<(fHittedPixel, fPixels, fColumns, 1, 1); - // for(Int_t row=0; row<5; row++) - // { - // for(Int_t column=0; column<5; column++) - // { - // std::cout.width(10); - // std::cout << std::fixed; - // std::cout << std::left << std::setprecision(2) << pixelchargeincluster[row*5+column]; - // } - // cout << endl; - // } - // cout << endl; + // Uncomment below to see hot cluster and their charge +// for(Int_t row=0; row<5; row++) +// { +// for(Int_t column=0; column<5; column++) +// { +// std::cout.width(10); +// std::cout << std::fixed; +// std::cout << std::left << std::setprecision(2) << pixelchargeincluster[row*5+column]; +// } +// cout << endl; +// } +// cout << "Charge sum: " << chargesumincluster << endl; +// cout << endl; // debugStream<>(cdsmatrixCorrPed, fPixels, fColumns, 1, 10); // } + fHits++; } @@ -1705,7 +1711,6 @@ void MAPS::hitana() { { fdiscriminatedhitmatrix->SetBinContent(i%fColumns, (int)(i/fColumns), fHittedPixel[i]); fADCHitmatrix->SetBinContent(i%fColumns, (int)(i/fColumns), fCdsmatrix[i]); - // cout<<"HITHERE"<(fF0matrix, fPixels/fColumns, fColumns, 0, 39); + cout<<"F1 matrix:"<(fF1matrix, fPixels/fColumns, fColumns, 0, 39); + cout<<"CDS matrix:"<(fCdsmatrix, fPixels, fColumns, 0, 39); + debugStream<>(fCdsmatrix, fPixels/fColumns, fColumns, 0, 39); Float_t cdsmatrixCorrPed[fPixels]; for(Int_t i=0; i(cdsmatrixCorrPed, fPixels, fColumns, 0, 10); - // cout<(cdsmatrixCorrPed, fPixels/fColumns, fColumns, 0, 10); +// cout<(fHittedPixel, fPixels, fColumns, 1, 1); + debugStream<>(fHittedPixel, fPixels/fColumns, fColumns, 1, 1); TCanvas* cm1 = new TCanvas(Form("Frame %d",FrameNumber),Form("Frame %d",FrameNumber),50,100,1200,800); cm1->Divide(2,3); @@ -1798,12 +1808,13 @@ void MAPS::plotFrame(Int_t FrameNumber) { TH2F *h1 = new TH2F("CDS matrix", "CDS matrix", fColumns, 0, fColumns, fRows, 0, fRows); TH2F *h2 = new TH2F("Frame 0 matrix", "Frame 0 matrix", fColumns, 0, fColumns, fRows, 0, fRows); TH2F *h3 = new TH2F("Frame 1 matrix", "Frame 1 matrix", fColumns, 0, fColumns, fRows, 0, fRows); + TH2F *h6 = new TH2F("CDS matrix - Pedestial", "CDS matrix - Pedestial", fColumns, 0, fColumns, fRows, 0, fRows); TH1F *h4 = new TH1F("Frame 0 histo", "Frame 0 histo", 2*16384, -16384, 16384); TH1F *h5 = new TH1F("Frame 1 histo", "Frame 1 histo", 2*16384, -16384, 16384); Int_t column; Int_t row; - Float_t F0,F1,CDS; + Float_t F0,F1,CDS,CDSminusPed; for(Int_t i=0; iFill(column,row,F1); h4->Fill(F0); h5->Fill(F1); + h6->Fill(column,row,CDSminusPed); } cm1->cd(1); - h1->Draw("colz"); - h1->GetXaxis()->SetTitle("column"); - h1->GetYaxis()->SetTitle("row"); - h1->GetZaxis()->SetTitle("Signal [ADC]"); + h6->Draw("colz"); + h6->GetXaxis()->SetTitle("column"); + h6->GetYaxis()->SetTitle("row"); + h6->GetZaxis()->SetTitle("Signal [ADC]"); cm1->cd(2); - h1->Draw("surf2z"); - h1->GetXaxis()->SetTitle("column"); - h1->GetYaxis()->SetTitle("row"); - h1->GetZaxis()->SetTitle("Signal [ADC]"); + h6->Draw("surf2z"); + h6->GetXaxis()->SetTitle("column"); + h6->GetYaxis()->SetTitle("row"); + h6->GetZaxis()->SetTitle("Signal [ADC]"); cm1->cd(3); h2->Draw("surf2z"); diff --git a/MABS_run_analyzer/Run.c b/MABS_run_analyzer/Run.c index 4a6ccf0..347b482 100644 --- a/MABS_run_analyzer/Run.c +++ b/MABS_run_analyzer/Run.c @@ -225,6 +225,7 @@ void Run::setSystemSpecificParameters() systemparam systemparamPegasus (2800,2800/2,20,10,100); systemparam systemparamPXI (800*16,800,75,150,150); systemparam systemparamFSBB (2800,2800/4,25,10,100); + systemparam systemparamUSBMi19 (400/*maxbin*/,400/1/*nbins*/, 25/*vetothreshold*/, 10/*maxbinnoise*/, 100/*nbinsnoise*/); if (labbook.system.EqualTo("USB") && labbook.chipGen.EqualTo("Mi34") ) cursystemparam = systemparamUSB; else if (labbook.system.EqualTo("USB") && labbook.chipGen.EqualTo("FSBB") ) @@ -233,6 +234,10 @@ void Run::setSystemSpecificParameters() cursystemparam = systemparamPXI; else if (labbook.system.EqualTo("Pegasus")) // && labbook.chipGen.EqualTo("34") ) cursystemparam = systemparamPegasus; + if (labbook.system.EqualTo("USB") && labbook.chipGen.EqualTo("Mi19") ) + cursystemparam = systemparamUSBMi19; + else if (labbook.system.EqualTo("USB")) // && labbook.chipGen.EqualTo("34") ) + cursystemparam = systemparamUSB; setSensorInSystemParam(); } @@ -243,6 +248,7 @@ void Run::setSensorInSystemParam() sensorinfostruct sensorinfoMi34PXI( 16, /* rows */ 64 /* columns */ ); sensorinfostruct sensorinfoPegasus( 8, 56 ); sensorinfostruct sensorinfoFSBB( 4, 416 ); + sensorinfostruct sensorinfoMi19USB( 192, /* rows */ 192 /* columns */ ); if (labbook.system.EqualTo("USB") && labbook.chipGen.EqualTo("Mi34") ) cursensorinfo=sensorinfoMi34USB; @@ -252,6 +258,8 @@ void Run::setSensorInSystemParam() cursensorinfo=sensorinfoMi34PXI; else if (labbook.system.EqualTo("Pegasus")) // && labbook.chipGen.EqualTo("34") ) cursensorinfo=sensorinfoPegasus; + else if (labbook.system.EqualTo("USB") && labbook.chipGen.EqualTo("Mi19") ) + cursensorinfo=sensorinfoMi19USB; } void Run::setMatrixSpecificParameters() @@ -356,7 +364,7 @@ Bool_t Run::analyzeRun(Bool_t force) processed->InitialDynNoise(); int start = 0; int nframes = processed->GetNumberFrames(); - // for(int i=0; i<1000;i++) // TODO remove 100000 run 342272 +// for(int i=0; i<10000;i++) // TODO remove 100000 run 342272 for(int i=0; ifHitTree->GetEntry(framei); // account only frames with less then 10 hits - if (processed->fFrameInfo.hits<(unsigned int)10) +// cout << colorcyan << processed->fFrameInfo.hits << endlr; +// if (processed->fFrameInfo.hits<(unsigned int)10) { for(Int_t hiti=0; (unsigned int)hitifFrameInfo.hits;hiti++) { @@ -845,6 +854,7 @@ Bool_t Run::binSeedSumVeto() // histogram with the single pixel histogram->Seed->Fill(processed->fFrameInfo.p[12][hiti]); +// cout << colorcyan << "filled seed" << endlr; // sum histogram pixelSum = 0; @@ -896,7 +906,6 @@ Bool_t Run::binSeedSumVeto() } if (histogramfixedthreshold != 0) { - cout << colorred << "NOT NULL! " << endlr; if (processed->fFrameInfo.pixelfixedthreshold[hiti]>0) { histogramfixedthreshold->numberofhits++; -- 2.43.0