--- /dev/null
+/**
+ * @file ChargeSpektrum.c
+ * @brief Use brief, otherwise the index won't have a brief explanation.
+ *
+ * Detailed explanation.
+ *
+ *
+ */
+
+#include "Run.h"
+#include "MAPS.h"
+
+
+/**
+ * @file
+ * @brief Use brief, otherwise the index won't have a brief explanation.
+ *
+ * Detailed explanation.
+ *
+ *
+ */
+
+// bad c- style fix me
+#include "Run.c"
+#include "MAPS.c"
+#include "CSVRow.h"
+#include "CSVRow.C"
+#include <TTimeStamp.h>
+
+Int_t* ReadRunList();
+void plotAllRuns();
+
+Run** runs;
+Int_t numberRuns;
+
+void ChargeSpektrum(Int_t runnumber = -1)
+{
+ cout << endl << endl;
+ Bool_t isBatch = kFALSE;
+ if (gROOT->IsBatch())
+ isBatch = kTRUE;
+
+ numberRuns=0;
+ Int_t* runList;
+ if (runnumber > 0)
+ {
+ numberRuns=1;
+ runList=new Int_t[numberRuns];
+ runList[0]=runnumber;
+ }
+ else
+ {
+ /// number of runs to be analyzed, number of lines read by @c ReadRunList()
+ numberRuns=0;
+ ReadRunList();
+ /// array with run numbers
+ runList=new Int_t[numberRuns];
+ runList=ReadRunList();
+ }
+ runs = new Run*[numberRuns];
+
+ cout << "Found " << numberRuns << " run(s) in 'runlist.txt'." << endl;
+ for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
+ {
+ runs[runi] = new Run(runList[runi]);
+ if (runi%2)
+ {
+ // check if devided matrix is investigated
+ if (runList[runi-1] == runList[runi])
+ {
+ cout << "Using devided matrix upper" << endl;
+ runs[runi]->dividedmatrix = 1;
+ runs[runi]->upperpart = 1;
+ }
+ }
+ if (runi+1 < numberRuns)
+ {
+ if (runList[runi] == runList[runi+1] )
+ {
+ cout << "Using devided matrix lower" << endl;
+ runs[runi]->dividedmatrix = 1;
+ runs[runi]->upperpart = 0;
+ }
+ }
+ runs[runi]->setResultsPath("./results/");
+ runs[runi]->setPlotStyle(runi);
+ runs[runi]->useDynamicalNoise(true);
+ runs[runi]->analyzeRun(false); // creates or opens .root file, can analyze the RAW data
+// gROOT->SetBatch(kTRUE);
+// runs[runi]->plotSeed();
+// runs[runi]->plotSum();
+// runs[runi]->plotVeto();
+// runs[runi]->plotNoise();
+ if (!isBatch)
+ gROOT->SetBatch(kFALSE);
+ runs[runi]->plotAllHistograms();
+// runs[runi]->plotAllHistogramsCalibrated();
+ runs[runi]->writeAllHistogramsToFile();
+ }
+
+
+ plotAllRuns();
+
+ // TTimeStamp* time = new TTimeStamp();
+ // TCanvas* canvas = new TCanvas(Form("%d",time->GetNanoSec()), "Summary", 800, 600);
+ // canvas->SetGridy(kTRUE);
+ // canvas->SetGridx(kTRUE);
+ // TLegend* leg = new TLegend(0.5,0.8,0.89,0.89);
+ // leg->SetFillColor(0);
+ // leg->SetBorderSize(0);
+ // for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
+ // {
+ // runs[runi]->histogram.Seed->Draw("SAME");
+ // leg->AddEntry(runs[runi]->histogram.Seed, runs[runi]->histogram.Seed->GetTitle(), "l");
+ // }
+ // leg->SetTextSize(0.03);
+ // leg->Draw();
+ // canvas->Modified();
+ // canvas->cd();
+ // canvas->SetSelected(canvas);
+
+// canvas -> SaveAs( savepathresults + "/" + runcode + " " + histogram->GetName() + ".eps");
+//
+// TImage *img = TImage::Create();
+// img->FromPad(canvas);
+// img->WriteImage(savepathresults + "/" + runcode + " " + histogram->GetName() + ".png");
+//
+// TFile *f = new TFile(savepathresults + "/" + runcode + " " + histogram->GetName() + ".root","UPDATE");
+// f->WriteTObject(canvas);
+// f->WriteTObject(img);
+
+
+}
+
+Int_t* ReadRunList()
+{
+ Int_t* runList=new Int_t[1000];
+
+ std::ifstream file("runlist.txt");
+ CSVRow row;
+ Int_t runLauf=0;
+ while (file >> row)
+ {
+ try
+ {
+ runList[runLauf]=atoi(row[0].c_str());
+ runLauf++;
+ }
+ catch(...)
+ {
+ cout << "File ended";
+ }
+ }
+ numberRuns=runLauf;
+ return runList;
+}
+
+
+// void plotNoiseComparison()
+// {
+//
+// }
+
+void plotAllRuns()
+{
+ Float_t lastbin;
+ TTimeStamp* time = new TTimeStamp();
+ TCanvas* canvas = new TCanvas(Form("%d",time->GetNanoSec()), "Summary", 1600, 1000);
+ canvas->Divide(2,2);
+ Float_t height = numberRuns * 0.04;
+ TLegend* leg1 = new TLegend(0.3,1.0-height,0.89,0.89);//(0.6,0.7,0.89,0.89);
+ TLegend* leg2 = new TLegend(0.6,1.0-height,0.89,0.89);//(0.6,0.7,0.89,0.89);
+ leg1->SetTextSize(0.02);
+ leg2->SetTextSize(0.02);
+ leg1->SetFillColor(0); leg1->SetBorderSize(0);
+ leg2->SetFillColor(0); leg2->SetBorderSize(0);
+ TString legendEntry;
+
+ for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
+ {
+ canvas->cd(1);
+ runs[runi]->histogram.Seed->Draw("SAME");
+ lastbin = runs[runi]->histogram.Seed->GetBinCenter(runs[runi]->histogram.Seed->FindLastBinAbove(2,1));
+ runs[runi]->histogram.Seed->SetAxisRange(0,lastbin*1.1,"X");
+ gPad->SetLogy(1);
+ legendEntry = Form("%s", runs[runi]->histogram.Seed->GetTitle());
+ leg1->AddEntry(runs[runi]->histogram.Veto, legendEntry, "l");
+ leg1->Draw("SAME");
+ canvas->cd(2);
+ runs[runi]->histogram.Sum->Draw("SAME");
+ lastbin = runs[runi]->histogram.Sum->GetBinCenter(runs[runi]->histogram.Sum->FindLastBinAbove(2,1));
+ runs[runi]->histogram.Sum->SetAxisRange(0,lastbin*1.1,"X");
+ canvas->cd(3);
+ runs[runi]->histogram.Veto->Draw("SAME");
+ runs[runi]->histogram.Veto->SetAxisRange(runs[runi]->histogram.posVeto*0.7,runs[runi]->histogram.posVeto*1.4,"X");
+ canvas->cd(4);
+ runs[runi]->histogram.Noise->Draw("SAME");
+ legendEntry = Form("%s, Noise: %.2f", runs[runi]->labbook.matrix.Data(), runs[runi]->histogram.avgNoise);
+ leg2->AddEntry(runs[runi]->histogram.Veto, legendEntry, "l");
+ leg2->Draw("SAME");
+ }
+
+ // canvas -> Print( runs[0]->savepathresults + "/" + canvastitle + ".eps");
+
+ TImageDump *img = new TImageDump(runs[0]->savepathresults + "/" + Form("%s - %s",runs[0]->runcode.Data(), runs[numberRuns-1]->runcode.Data()) + ".png");
+ canvas->Paint();
+ img->Close();
+
+ TFile *f = new TFile(runs[0]->savepathresults + "/" + Form("%s - %s",runs[0]->runcode.Data(),runs[numberRuns-1]->runcode.Data()) + ".root","RECREATE");
+ f->cd();
+ f->Append(canvas);
+ f->Append(img);
+ f->Write();
+}
+