From e421af518322d9a2ee84bea3f0bb3224f48a0c3d Mon Sep 17 00:00:00 2001 From: Benjamin Linnik Date: Mon, 21 Sep 2015 17:00:29 +0200 Subject: [PATCH] Run analyzer: Added routine writeObservableToFile() and the vector compareHistogramVector to write out only specific histograms (of different runs) into one file --- MABS_run_analyzer/ChargeSpektrum.c | 2 + MABS_run_analyzer/ChargeSpektrumFunctions.c | 134 ++++++-------------- MABS_run_analyzer/HistogramType.c | 5 +- MABS_run_analyzer/HistogramType.h | 4 +- MABS_run_analyzer/Run.c | 8 +- MABS_run_analyzer/Run.h | 9 +- 6 files changed, 51 insertions(+), 111 deletions(-) diff --git a/MABS_run_analyzer/ChargeSpektrum.c b/MABS_run_analyzer/ChargeSpektrum.c index 316b814..9029615 100644 --- a/MABS_run_analyzer/ChargeSpektrum.c +++ b/MABS_run_analyzer/ChargeSpektrum.c @@ -153,6 +153,7 @@ void ChargeSpektrum(TString runnumber = "") runs[runi]->plot1DHistogram(runs[runi]->histogram->calibrated, runs[runi]->histogram->Seed, "landau"); runs[runi]->plot1DHistogram(runs[runi]->histogram->calibrated, runs[runi]->histogram->calibrated->Seed, "landau"); compareHistogramClassVector.push_back(runs[runi]->histogram->calibrated); + compareHistogramVector.push_back(runs[runi]->histogram->Seed); // runs[runi]->integrateSr90Spectra(&runs[runi]->histogramfixedthresholdCalibrated, runs[runi]->histogramfixedthresholdCalibrated.Seed, 0); // runs[runi]->plot1DHistogram(&runs[runi]->histogramfixedthresholdCalibrated, runs[runi]->histogramfixedthresholdCalibrated.Seed, "landau"); // runs[runi]->plot1DHistogram(&runs[runi]->histogramthresholdCalibrated, runs[runi]->histogramthresholdCalibrated.Seed, "landau"); @@ -170,6 +171,7 @@ void ChargeSpektrum(TString runnumber = "") } } plotAllRuns(); + writeObservableToFile(); // plotAllRuns("seed threshold calibrated"); // setCustomPath("Excel/"); // writeObservableToFile("seed threshold calibrated"); diff --git a/MABS_run_analyzer/ChargeSpektrumFunctions.c b/MABS_run_analyzer/ChargeSpektrumFunctions.c index 9362888..eabe580 100644 --- a/MABS_run_analyzer/ChargeSpektrumFunctions.c +++ b/MABS_run_analyzer/ChargeSpektrumFunctions.c @@ -10,10 +10,15 @@ Int_t* ReadRunList(); Int_t ReadRunList(std::vector*); Bool_t plotAllRuns(); -Bool_t plotAllRuns(TString); -Bool_t writeObservableToFile(TString); +/** @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 + * you can compare different histograms of the different runs. + * + * Call #writeObservableToFile() in #ChargeSpectrum.c to create a file with all the TH1F histogram data + * + */ Bool_t writeObservableToFile(); -void writeObservableToFileHistSelect(TString); /** @brief A vector able to hold pointer of type #Run::histogramstruct * * You push in pointer of the type Run::histogramstruct in ChargeSpectrum.C and then @@ -23,6 +28,7 @@ void writeObservableToFileHistSelect(TString); * */ vector compareHistogramClassVector; +vector compareHistogramVector; TString ownpath = ""; @@ -68,113 +74,45 @@ Int_t ReadRunList(std::vector* runlist) } -// void plotNoiseComparison() -// { -// -// } - -Bool_t writeObservableToFile(TString histogramtype) -{ - if (histogramtype.Contains("threshold")) - { - if (histogramtype.Contains("calibrated")) - { - for(Int_t runi=0;runihistogramthreshold->iscalibrated) - runs[runi]->plothistogramclasspointer = runs[runi]->histogramthreshold->calibrated; - else - return 1; - } - } - else - { - for(Int_t runi=0;runiplothistogramclasspointer = runs[runi]->histogramthreshold; - } - - } - else if (histogramtype.Contains("calibrated") || histogramtype.Contains("electron")) { - for(Int_t runi=0;runihistogram->iscalibrated) - runs[runi]->plothistogramclasspointer = runs[runi]->histogram->calibrated; - else return 1; } } - else { - for(Int_t runi=0;runiplothistogramclasspointer = runs[runi]->histogram; } } - writeObservableToFileHistSelect(histogramtype); - return 0; -} -void writeObservableToFileHistSelect(TString histogramtype) -{ - if (histogramtype.Contains("Seed") || histogramtype.Contains("seed")) { - for(Int_t runi=0;runiplothistogrampointer = runs[runi]->plothistogramclasspointer->Seed; } } - else if (histogramtype.Contains("Sum") || histogramtype.Contains("sum")) { - for(Int_t runi=0;runiplothistogrampointer = runs[runi]->plothistogramclasspointer->Sum; } } - else if (histogramtype.Contains("Veto") || histogramtype.Contains("veto")) { - for(Int_t runi=0;runiplothistogrampointer = runs[runi]->plothistogramclasspointer->Veto; } } - else { - for(Int_t runi=0;runiplothistogrampointer = runs[runi]->plothistogramclasspointer->Seed; } } - writeObservableToFile(); -} - Bool_t writeObservableToFile() { - system("mkdir "+ runs[0]->savepathresults + " -p"); - TString headerInfo = ""; - for(Int_t runi=0;runiruncode+"\t\t\t"; - } - TH1F* plothistogrampointer = runs[0]->plothistogrampointer; - TString runnumberListe=""; - TString header=""; - for(Int_t runi=0;runierror) - { - plothistogrampointer = runs[runi]->plothistogrampointer; - runnumberListe+=Form("%d_",runs[runi]->labbook.runnumber); - header+=Form("%d\t%s\t\t\t", runs[runi]->labbook.runnumber, plothistogrampointer->GetName()); - } - } - } - TString filename= runs[0]->savepathresults + "/" + ownpath + runnumberListe + Form("%s",plothistogrampointer->GetName())+"histograms.dat"; - fstream* fout = new fstream(filename,ios::out); - *fout << headerInfo << endl; - *fout << header << endl; - for(Int_t bini=0;biniGetNbinsX();bini++) + if (numberRuns>0) { + system("mkdir "+ runs[0]->savepathresults + " -p"); + + TString filename = runs[0]->savepathresults + "/Spectra"; + TString header = ""; for(Int_t runi=0;runierror) { - plothistogrampointer = runs[runi]->plothistogrampointer; - TString outline; - Double_t binContentNorm=plothistogrampointer->GetBinContent(bini)/runs[runi]->labbook.frames_foundDB*10000000; - Double_t binSumme=0.0; - for(Int_t binSummei=bini;binSummeiGetNbinsX();binSummei++)//Sum up from bini beginning (cut condition for detection eff.) - { - Double_t binContentNormInSumme=plothistogrampointer->GetBinContent(binSummei)/runs[runi]->labbook.frames_foundDB*10000000; - binSumme=binSumme+binContentNormInSumme; - } - outline=Form("%.1f\t%.1f\t%.1f\t%.1f\t",plothistogrampointer->GetBinCenter(bini),plothistogrampointer->GetBinContent(bini),binContentNorm,binSumme); - *fout<labbook.runnumber); + header += Form("#%s %lu frames\n", runs[runi]->runcode.Data(), runs[runi]->frames_found); } } } - *fout<close(); - + filename+=".dat"; + fstream* fout = new fstream(filename,ios::out); + header += Form("#"); + for (vector::iterator curHistogram = compareHistogramVector.begin(); curHistogram != compareHistogramVector.end(); curHistogram++) { + header += Form("bin\t%s\t",(*curHistogram)->GetName()); + } + *fout << header << endl; + TString outline; + for(Int_t bin=1;bin<=runs[0]->cursystemparam.nbins;bin++) + { + outline =""; + for (vector::iterator curHistogram = compareHistogramVector.begin(); curHistogram != compareHistogramVector.end(); curHistogram++) { + outline+=Form("%.1f\t%.1f\t", (*curHistogram)->GetBinCenter(bin), (*curHistogram)->GetBinContent(bin)); + } + *fout<close(); + return 0; + + } return 0; } diff --git a/MABS_run_analyzer/HistogramType.c b/MABS_run_analyzer/HistogramType.c index 1402d7d..590d37f 100644 --- a/MABS_run_analyzer/HistogramType.c +++ b/MABS_run_analyzer/HistogramType.c @@ -19,10 +19,11 @@ HistogramType::~HistogramType( void) { } -HistogramType::HistogramType(TString suffix, systemparam* gotsystempar, sensorinfostruct* gotsensorinfo, TString gothumanreadablestr, Int_t gotcolor, Int_t gotstyle ) { +HistogramType::HistogramType(TString suffix, systemparam* gotsystempar, sensorinfostruct* gotsensorinfo, TString gothumanreadablestr, Int_t gotrunnumber, Int_t gotcolor, Int_t gotstyle ) { histogramdescription = suffix; humanreadablestr = gothumanreadablestr; cursystempar = gotsystempar; + runnumber = gotrunnumber; cursensorinfo = gotsensorinfo; initHistograms(gotcolor, gotstyle); }; @@ -48,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(prefix.Data(), Form("%s, %s",prefix.Data(), humanreadablestr.Data()), cursystempar->nbins, 0, cursystempar->maxbin); + histogrampointer=new TH1F(Form("%d %s",runnumber, prefix.Data()), Form("%s, %s",prefix.Data(), humanreadablestr.Data()), cursystempar->nbins, 0, cursystempar->maxbin); histogrampointer->SetLineStyle(style); histogrampointer->SetLineColor(color); histogrampointer->SetStats(kTRUE); diff --git a/MABS_run_analyzer/HistogramType.h b/MABS_run_analyzer/HistogramType.h index c6f542a..ac60cc0 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 gotcolor=0, Int_t gotstyle=0); + HistogramType(TString suffix, systemparam* gotsystempar, sensorinfostruct* gotsensorinfo, TString gothumanreadablestr="", Int_t gotrunnumber=0, Int_t gotcolor=0, Int_t gotstyle=0); //***************** // TH HISTOGRAMS @@ -149,6 +149,8 @@ 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 diff --git a/MABS_run_analyzer/Run.c b/MABS_run_analyzer/Run.c index f5a3304..ecb0af7 100644 --- a/MABS_run_analyzer/Run.c +++ b/MABS_run_analyzer/Run.c @@ -149,16 +149,16 @@ 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, rootcolors[plotStyle], rootlinestyle[plotStyle] ); + histogram = new HistogramType("", &cursystemparam, &cursensorinfo, humanreadablestr, labbook.runnumber, rootcolors[plotStyle], rootlinestyle[plotStyle] ); HistogramClassVector.push_back(histogram); // dynamical cluster threshold cut - histogramthreshold = new HistogramType(" Threshold", &cursystemparam, &cursensorinfo, humanreadablestr, rootcolors[plotStyle], rootlinestyle[plotStyle] ); + histogramthreshold = new HistogramType(" Threshold", &cursystemparam, &cursensorinfo, humanreadablestr, labbook.runnumber, rootcolors[plotStyle], rootlinestyle[plotStyle] ); HistogramClassVector.push_back(histogramthreshold); // fixed threshold cut - histogramfixedthreshold = new HistogramType(" fixed Threshold", &cursystemparam, &cursensorinfo, humanreadablestr, rootcolors[plotStyle], rootlinestyle[plotStyle] ); + 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, rootcolors[plotStyle], rootlinestyle[plotStyle] ); + dennismegacut = new HistogramType(" Dennis Mega Cut", &cursystemparam, &cursensorinfo, humanreadablestr, labbook.runnumber, rootcolors[plotStyle], rootlinestyle[plotStyle] ); HistogramClassVector.push_back(dennismegacut); debugDBreadout(); diff --git a/MABS_run_analyzer/Run.h b/MABS_run_analyzer/Run.h index bfea9ab..c71d41d 100644 --- a/MABS_run_analyzer/Run.h +++ b/MABS_run_analyzer/Run.h @@ -121,10 +121,7 @@ private: u_int submatrix_y_start; /// If you set this variable to a value, #Run::binSeedSumVeto() and #Run::binCluster() will only account for hits in given range u_int submatrix_y_end; - - /// number of frames found in given folder - ULong_t frames_found = 0; - + /** * @brief Generates a human readable string with information about the run * @@ -372,6 +369,8 @@ public: TString storepathOutLinux = "/d/garlic/Mi34/rootFiles"; /// path to the RAW files on LINUX systems TString savepathresults = "."; + /// number of frames found in given folder + ULong_t frames_found = 0; TFile* rootfile; @@ -393,9 +392,7 @@ public: HistogramType* histogram; HistogramType* histogramthreshold; HistogramType* histogramfixedthreshold; - HistogramType* plothistogramclasspointer; HistogramType* dennismegacut; - TH1F* plothistogrampointer; /// /** @brief A vector able to hold pointer of type #Run::histogramstruct * -- 2.43.0