From 212afdba7175f93e2f75e9fee9e0d4b228de4776 Mon Sep 17 00:00:00 2001 From: Benjamin Linnik Date: Mon, 4 May 2015 15:17:02 +0200 Subject: [PATCH] bot/Analyzer: added option to plot seed, veto spectrum in one panel, bot bugfixes --- MABS_run_analyzer/ChargeSpektrum.c | 163 ++++++--- MABS_run_analyzer/MAPS.c | 20 +- MABS_run_analyzer/Run.c | 484 ++++++++++++++++++++++----- MABS_run_analyzer/Run.h | 119 +++++-- bot/Functions/Header.au3 | 2 + bot/Functions/WaitForTemperature.au3 | 6 +- bot/Functions/mysql_functions.au3 | 15 +- bot/Mimosa_Autorun_USB.au3 | 3 + 8 files changed, 627 insertions(+), 185 deletions(-) diff --git a/MABS_run_analyzer/ChargeSpektrum.c b/MABS_run_analyzer/ChargeSpektrum.c index ffef131..f8a50a8 100644 --- a/MABS_run_analyzer/ChargeSpektrum.c +++ b/MABS_run_analyzer/ChargeSpektrum.c @@ -25,22 +25,39 @@ #include "MAPS.c" #include "CSVRow.h" #include "CSVRow.C" +#include Int_t* ReadRunList(Int_t*); +void plotAllRuns(); Run** runs; +Int_t numberRuns; -void ChargeSpektrum() +void ChargeSpektrum(Int_t runnumber = -1) { cout << endl << endl; + Bool_t isBatch = kFALSE; + if (gROOT->IsBatch()) + isBatch = kTRUE; - /// number of runs to be analyzed, number of lines read by @c ReadRunList() - Int_t numberRuns=0; - ReadRunList(&numberRuns); - /// array with run numbers - Int_t* runList=new Int_t[numberRuns]; - runList=ReadRunList(&numberRuns); - runs = new Run*[numberRuns]; + 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(&numberRuns); + /// array with run numbers + runList=new Int_t[numberRuns]; + runList=ReadRunList(&numberRuns); + } + runs = new Run*[numberRuns]; cout << "Found " << numberRuns << " run(s) in 'runlist.txt'." << endl; for(Int_t runi=0;runiupperpart = 0; } } - runs[runi]->setResultsPath("/home/blinnik/Dropbox/Promotion/MABS_Analyse/HR18vs20/"); + runs[runi]->setResultsPath("/home/blinnik/Dropbox/Promotion/MABS_Analyse/NoiseUntersuchung1014neq/"); runs[runi]->setPlotStyle(runi); runs[runi]->useDynamicalNoise(true); - runs[runi]->analyzeRun(true); // creates or opens .root file, can analyze the RAW data - gROOT->SetBatch(kTRUE); - runs[runi]->plotSeed(); - runs[runi]->plotSum(); + 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(); - gROOT->SetBatch(kFALSE); - runs[runi]->plotAllHistograms(); - runs[runi]->writeAllHistogramsToFile(); +// runs[runi]->plotNoise(); + if (!isBatch) + gROOT->SetBatch(kFALSE); +// runs[runi]->plotAllHistograms(); +// runs[runi]->plotAllHistogramsCalibrated(); +// runs[runi]->writeAllHistogramsToFile(); } + - TCanvas* canvas = new TCanvas("Summary", "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;runihistogram.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); +// 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;runihistogram.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"); // @@ -107,11 +130,6 @@ void ChargeSpektrum() // f->WriteTObject(img); - -// cout << "Bevor delete! " << endl; -// for(Int_t runi=0;runiGetNanoSec()), "Summary", 1600, 1000); + canvas->Divide(2,2); + Float_t height = numberRuns * 0.08; + 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.03); + leg2->SetTextSize(0.03); + leg1->SetFillColor(0); leg1->SetBorderSize(0); + leg2->SetFillColor(0); leg2->SetBorderSize(0); + TString legendEntry; + + for(Int_t runi=0;runicd(1); + runs[runi]->histogram.Seed->Draw("SAME"); + lastbin = runs[runi]->histogram.Seed->GetBinCenter(runs[runi]->histogram.Seed->FindLastBinAbove(10,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(10,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(); +} diff --git a/MABS_run_analyzer/MAPS.c b/MABS_run_analyzer/MAPS.c index f15d7f2..c39143a 100644 --- a/MABS_run_analyzer/MAPS.c +++ b/MABS_run_analyzer/MAPS.c @@ -47,7 +47,7 @@ Bool_t MAPS::initNewRootFile() { { //----------------------------------------------- //Check and open Data Files - int MaxFiles = FileTotalEvNbInConfig/FileEvNbInConfig; + int MaxFiles = TMath::Ceil((Float_t) FileTotalEvNbInConfig/FileEvNbInConfig); if( checkDataFiles(MaxFiles) ) { fOutputFile = new TFile(fRootFile,"RECREATE"); @@ -79,7 +79,7 @@ Bool_t MAPS::initOldRootFile() { fOutputFile = new TFile(fRootFile,"READ"); if (fOutputFile->IsZombie()) { - cout << colorred << "Error opening old ROOT file!"<< endlr; + cout << colorred << "Error opening old ROOT file! -> Zombie"<< endlr; return 1; } fHitTree = (TTree*) fOutputFile->Get("hit"); @@ -121,7 +121,6 @@ MAPS::~MAPS(void) { hint1->Write("",TObject::kOverwrite); hint2->Write("",TObject::kOverwrite); - fOutputFile->Save(); fOutputFile->Close(); @@ -392,15 +391,15 @@ bool MAPS::checkDataFiles( Int_t MaxFiles ) { cout<< "TOTAL FRAMES FOUND: "<= 20000) + cout << "\033[1;31mRun could be corrupted, number of events in file doesn't match configuration! ("<< Frames << " != " << FileEvNbInConfig << ") \033[0m\n"; // cout<Reset(); + fNoiseTree = new TTree("noise", "noise"); + fNoiseTree->Reset(); fNoiseTree->Branch("pixel" , &PIXEL , "pixel/i" , 32000); fNoiseTree->Branch("noise" , &NOISE , "noise/F" , 32000); fNoiseTree->Branch("pedestal" , &PEDESTAL , "pedestal/F" , 32000); diff --git a/MABS_run_analyzer/Run.c b/MABS_run_analyzer/Run.c index c331da2..34f412b 100644 --- a/MABS_run_analyzer/Run.c +++ b/MABS_run_analyzer/Run.c @@ -25,12 +25,13 @@ Run::~Run( void) Run::Run(Int_t runnumber) { labbook.runnumber = runnumber; - + random1 = new TRandom; + random1->SetSeed(0); db = TSQLServer::Connect(SERVERPATH,SERVERUSER,SERVERPWD); //db = TSQLServer::Connect("mysql://jspc29.x-matter.uni-frankfurt.de","radhard","mimosa88"); try { - string selectquery = prepareSQLStatement("select `System`, `TempCooling`, COALESCE(`TempChipStart`,-10000) as `TempChipStart`, COALESCE(`TempChipEnd`,-10000) as `TempChipEnd`, `ChipNum`, `RadiationSource`, `Matrix`, `Clock`, `StorePath`, `ChipGen`,COALESCE(`VetoPeak`,-1) as `VetoPeak` from `radhard`.`labbook` WHERE `runnumber`=" + numberToString<>(labbook.runnumber)); + string selectquery = prepareSQLStatement("select `System`, `TempCooling`, COALESCE(`TempChipStart`,-10000) as `TempChipStart`, COALESCE(`TempChipEnd`,-10000) as `TempChipEnd`, `ChipNum`, `RadiationSource`, `Matrix`, `Clock`, `StorePath`, `ChipGen`,COALESCE(`VetoPeak`,-1) as `VetoPeak`,COALESCE(`SeedPeak`,-1) as `SeedPeak`,COALESCE(`SumPeak`,-1) as `SumPeak`,COALESCE(`Gain`,-1) as `Gain`,COALESCE(`Avg.Noise`,-1) as `Avg.Noise`,COALESCE(`Avg.Noise+`,-1) as `Avg.Noise+`,COALESCE(`Avg.Noise-`,-1) as `Avg.Noise-`,COALESCE(`CCE_1`,-1) as `CCE_1`,COALESCE(`CCE_25`,-1) as `CCE_25` from `radhard`.`labbook` WHERE `runnumber`=" + numberToString<>(labbook.runnumber)); res = db->Query(selectquery.c_str()); nrows = res->GetRowCount(); if (nrows > 0) @@ -69,6 +70,14 @@ Run::Run(Int_t runnumber) savepathresults = storepathRAWLinux; labbook.chipGen = (rowsql->GetField(9) != NULL)?std::string(rowsql->GetField(9)):""; labbook.posVetoDB = (rowsql->GetField(10) != NULL)?atoi(rowsql->GetField(10)):-1; + labbook.posSeedDB = (rowsql->GetField(11) != NULL)?atoi(rowsql->GetField(11)):-1; + labbook.posSumDB = (rowsql->GetField(12) != NULL)?atoi(rowsql->GetField(12)):-1; + labbook.gainDB = (rowsql->GetField(13) != NULL)?atoi(rowsql->GetField(13)):-1; + labbook.NoiseAvgDB = (rowsql->GetField(14) != NULL)?atoi(rowsql->GetField(14)):-1; + labbook.NoiseAvgPlusDB = (rowsql->GetField(15) != NULL)?atoi(rowsql->GetField(15)):-1; + labbook.NoiseAvgMinusDB = (rowsql->GetField(16) != NULL)?atoi(rowsql->GetField(16)):-1; + labbook.CCE_in_Perc_1DB = (rowsql->GetField(17) != NULL)?atoi(rowsql->GetField(17)):-1; + labbook.CCE_in_Perc_25DB = (rowsql->GetField(18) != NULL)?atoi(rowsql->GetField(18)):-1; delete res; if (labbook.chip.Length() > 0 && labbook.chipGen.Length() > 0) // versuche infos zum Chip aus der ChipDatenbank zu bekommen { @@ -85,7 +94,8 @@ Run::Run(Int_t runnumber) delete res; } } - if (!(labbook.posVetoDB > 0) && (labbook.source != "Fe55")) // no veto peak position found for this run +// if (!(labbook.posVetoDB > 0) && (labbook.source != "Fe55")) // no veto peak position found for this run + if (labbook.source != "Fe55") // no veto peak position found for this run { getVetoPeakPositionFromFe55Run(); } @@ -96,8 +106,9 @@ Run::Run(Int_t runnumber) cout << colorwhite << "initRootParameters():" << endlr; initRootParameters(); cout << colorwhite << "initHistograms():" << endlr; - initHistograms(); + initHistograms(&histogram); runexistsinDB = 1; + debugDBreadout(); } else { @@ -110,6 +121,37 @@ Run::Run(Int_t runnumber) } } +Bool_t Run::debugDBreadout() +{ + cout << endlr; + cout << " _____ " << colorwhite << "database values" << colorreset << " ________ " << endlr; + cout << "| runnumber: " << std::right << colorwhite << labbook.runnumber << endlr; + cout << "| system: " << std::right << colorwhite << labbook.system << endlr; + cout << "| temp: " << std::right << colorwhite << labbook.temp << endlr; + cout << "| tempSens: " << std::right << colorwhite << labbook.tempSens << endlr; + cout << "| chip: " << std::right << colorwhite << labbook.chip << endlr; + cout << "| chipGen: " << std::right << colorwhite << labbook.chipGen << endlr; + cout << "| source: " << std::right << colorwhite << labbook.source << endlr; + cout << "| matrix: " << std::right << colorwhite << labbook.matrix << endlr; + cout << "| radDoseIon: " << std::right << colorwhite << labbook.radDoseIon << endlr; + cout << "| radDoseNonIon: " << std::right << colorwhite << labbook.radDoseNonIon << endlr; + cout << "| resistivity: " << std::right << colorwhite << labbook.resistivity << endlr; + cout << "| epi_thickness: " << std::right << colorwhite << labbook.epi_thickness << endlr; + cout << "| clock: " << std::right << colorwhite << labbook.clock << endlr; + cout << "| storepath: " << std::right << colorwhite << labbook.storepath << endlr; + cout << "| posSeedDB: " << std::right << colorwhite << labbook.posSeedDB << endlr; + cout << "| posSumDB: " << std::right << colorwhite << labbook.posSumDB << endlr; + cout << "| posVetoDB: " << std::right << colorwhite << labbook.posVetoDB << endlr; + cout << "| gainDB: " << std::right << colorwhite << labbook.gainDB << endlr; + cout << "| NoiseAvgDB: " << std::right << colorwhite << labbook.NoiseAvgDB << endlr; + cout << "| NoiseAvgPlusDB: " << std::right << colorwhite << labbook.NoiseAvgPlusDB << endlr; + cout << "| NoiseAvgMinusDB: " << std::right << colorwhite << labbook.NoiseAvgMinusDB << endlr; + cout << "| CCE_in_Perc_25DB:" << std::right << colorwhite << labbook.CCE_in_Perc_25DB << endlr; + cout << "| CCE_in_Perc_1DB: " << std::right << colorwhite << labbook.CCE_in_Perc_1DB << endlr; + cout << "|______________________________ " << endlr; + cout << endlr; +} + Bool_t Run::useDynamicalNoise(Bool_t var) { cout<<" Dynamical Noise calc. : " << colorwhite << (var?"1":"0") << colorreset << " <-- only used if RAW files are analyzed, force analysis to make sure" << endl; @@ -153,16 +195,7 @@ Bool_t Run::analyzeRun(Bool_t force) // processed->filterCommonMode(); processed->hitana(); if (dynamicalNoise) - { - processed->RefillNoiseBranch=true; processed->regetDynNoise(); - if (processed->RefillNoiseBranch && processed->RefilledNoiseBranch) - { - binNoise(); - plotNoise(); - processed->RefilledNoiseBranch = false; - } - } progress = (Int_t)(((i-start)*100)/(nframes-1)*10); if (progress!=progress_tmp) { print_progress( (((i-start)*100.)/(nframes-1)) ); progress_tmp=progress;} } @@ -172,6 +205,9 @@ Bool_t Run::analyzeRun(Bool_t force) fstream* fout = new fstream(storepathRAWLinux + "/rootfilecreated",std::ios::out); *fout << "" << endl; fout->close(); + + // TODO + } else { @@ -185,6 +221,12 @@ Bool_t Run::analyzeRun(Bool_t force) binNoise(); cout << colorwhite << "binSeedSumVeto():" << endlr; binSeedSumVeto(); + cout << colorwhite << "rescaleHistograms():" << endlr; + histogramCalibrated.calibrated = rescaleHistograms(); + cout << colorwhite << "calculateCCE():" << endlr; + calculteCCE(); + cout << colorwhite << "updateDatabase():" << endlr; + updateDatabase(); cout << colorwhite << "delete processed:" << endlr; delete processed; return true; @@ -194,6 +236,74 @@ Bool_t Run::analyzeRun(Bool_t force) return false; } +Bool_t Run::calculteCCE() +{ + if (labbook.source.Contains("Fe")) + { + CCE_in_Perc_1 = histogram.posSeed / histogram.posVeto * 100.0; + CCE_in_Perc_25 = histogram.posSum / histogram.posVeto * 100.0; + } + return 0; +} + +Bool_t Run::rescaleHistograms() +{ + float_t vetopeakposition = -1; + if ( histogram.posVeto > 0 ) + { + vetopeakposition = histogram.posVeto; + cout << colorwhite << "Use calibration obtained from this run, position veto: " << vetopeakposition << endlr; + } + else if ( labbook.posVetoDB > 0 ) + { + vetopeakposition = labbook.posVetoDB; + cout << colorwhite << "Use calibration obtained from database value of this run, position veto: " << vetopeakposition << endlr; + } + else if ( Fe55run.posVeto > 0 ) + { + vetopeakposition = Fe55run.posVeto; + cout << colorwhite << "Use calibration obtained from Fe55 run in database, position veto: " << vetopeakposition << endlr; + cout << " Run number: " << Fe55run.posVetorunnumber << endl; + cout << " Temperature: " << Fe55run.temperature << endl; + } + else + { + cout << coloryellow << "Cannot rescale run from [ADU] to [e] units, no calibration peak found." << endlr; + return 0; + } + gain = 1640.0/vetopeakposition; + + rescaleHistogram(histogramCalibrated.Seed, histogram.Seed); + rescaleHistogram(histogramCalibrated.Sum, histogram.Sum); + rescaleHistogram(histogramCalibrated.Veto, histogram.Veto); + rescaleHistogram(histogramCalibrated.Noise, histogram.Noise); + + histogramCalibrated.posSeed = histogram.posSeed * gain; + histogramCalibrated.posSum = histogram.posSum * gain; + histogramCalibrated.posVeto = histogram.posVeto * gain; + histogramCalibrated.avgNoise = histogram.avgNoise * gain; + histogramCalibrated.avgNoisePlus = histogram.avgNoisePlus * gain; + histogramCalibrated.avgNoiseMinus = histogram.avgNoiseMinus * gain; + + return 1; +} + +void Run::rescaleHistogram(TH1F* &histogrampointernew, TH1F* &histogrampointerold ) +{ + histogrampointernew = (TH1F*)histogrampointerold->Clone(); + histogrampointernew->SetName(Form("%sC", histogrampointerold->GetName())); + histogrampointernew->SetTitle(Form("%sC", histogrampointerold->GetTitle())); + histogrampointernew->GetXaxis()->SetTitle("Q_coll [e]"); + int nbins = histogrampointernew->GetXaxis()->GetNbins(); + double new_bins[nbins+1]; + for(int i=0; i <= nbins; i++){ + new_bins[i] = histogrampointernew->GetBinCenter(i)*gain; + } + histogrampointernew->SetBins(nbins, new_bins); + histogrampointernew->GetYaxis()->SetTitle(Form("Entries [1/%.1f e]",histogrampointernew->GetBinWidth(1))); +} + + Bool_t Run::analyzeFrame(Int_t frame) { if (runexistsinDB) @@ -354,7 +464,8 @@ void Run::getVetoPeakPositionFromFe55Run() rowsql = res->Next(); Fe55run.posVeto = (rowsql->GetField(0) != NULL)?atof(rowsql->GetField(0)):-1; Fe55run.posVetorunnumber = (rowsql->GetField(0) != NULL && rowsql->GetField(1) != NULL)?atoi(rowsql->GetField(1)):0; - } while (posVeto == -1 && (--nrows)!=0); + Fe55run.temperature = labbook.temp; + } while (Fe55run.posVeto == -1 && (--nrows)!=0); delete res; } else @@ -363,7 +474,7 @@ void Run::getVetoPeakPositionFromFe55Run() } if (!(Fe55run.posVeto > 0)) // no calibration peak found { - query=prepareSQLStatement("select COALESCE(VetoPeak,-1) as VetoPeak, runnumber, TempCooling from radhard.labbook WHERE ChipNum='" + numberToString<>(labbook.chip) + "' AND RadiationSource='Fe55' AND Matrix='" + numberToString<>(labbook.matrix) + "' AND System='" + numberToString<>(labbook.system) + "'"); + query=prepareSQLStatement("select COALESCE(VetoPeak,-1) as VetoPeak, runnumber, `TempCooling` from radhard.labbook WHERE ChipNum='" + numberToString<>(labbook.chip) + "' AND RadiationSource='Fe55' AND Matrix='" + numberToString<>(labbook.matrix) + "' AND System='" + numberToString<>(labbook.system) + "'"); res = db->Query(query.Data()); nrows = res->GetRowCount(); if (nrows > 0) @@ -396,6 +507,7 @@ void Run::getVetoPeakPositionFromFe55Run() void Run::constructUpdateString(string *sqlupdatequery, const string databasevaluename, const Float_t value, const int precision=3) { +// cout << colorred << databasevaluename << " : " << value << endlr; if (value>0) { if ((*sqlupdatequery).length() > 0) @@ -405,14 +517,14 @@ void Run::constructUpdateString(string *sqlupdatequery, const string databaseval } void Run::updateDatabase() { - string sqlupdatequery = ""; + string sqlupdatequery = ""; constructUpdateString(&sqlupdatequery, "Gain", gain); - constructUpdateString(&sqlupdatequery, "SumPeak", posSum); - constructUpdateString(&sqlupdatequery, "SeedPeak", posSeed); - constructUpdateString(&sqlupdatequery, "VetoPeak", posVeto); - constructUpdateString(&sqlupdatequery, "Avg.Noise", NoiseAvg, 2); - constructUpdateString(&sqlupdatequery, "Avg.Noise+", NoiseAvgPlus, 2); - constructUpdateString(&sqlupdatequery, "Avg.Noise-", NoiseAvgMinus, 2); + constructUpdateString(&sqlupdatequery, "SumPeak", histogram.posSum, 4); + constructUpdateString(&sqlupdatequery, "SeedPeak", histogram.posSeed, 4); + constructUpdateString(&sqlupdatequery, "VetoPeak", histogram.posVeto, 4); + constructUpdateString(&sqlupdatequery, "Avg.Noise", histogramCalibrated.avgNoise); + constructUpdateString(&sqlupdatequery, "Avg.Noise+", histogramCalibrated.avgNoisePlus, 2); + constructUpdateString(&sqlupdatequery, "Avg.Noise-", histogramCalibrated.avgNoiseMinus, 2); constructUpdateString(&sqlupdatequery, "CCE_1", CCE_in_Perc_1); constructUpdateString(&sqlupdatequery, "CCE_25", CCE_in_Perc_25); @@ -420,7 +532,7 @@ void Run::updateDatabase() { { try { - sqlupdatequery = prepareSQLStatement("UPDATE `labbook` SET " + sqlupdatequery + " WHERE `runnumber`=" + numberToString<>(labbook.runnumber)); + sqlupdatequery = prepareSQLStatement("UPDATE `radhard`.`labbook` SET " + sqlupdatequery + " WHERE `runnumber`=" + numberToString<>(labbook.runnumber)); Bool_t sucess = db->Exec(sqlupdatequery.c_str()); if (!sucess) { @@ -451,14 +563,17 @@ Bool_t Run::binNoise() Double_t const probabilities[] = {0.3415/2, 0.5, 1-0.3415/2}; // sigma/2 from gaus to the left and to the right //{0.17, 0.5, 1-0.17}; histogram.Noise->Reset(); - processed->fDynNoiseTree->SetBranchAddress("noise", &noise, &noiseBranch); + processed->fNoiseTree->SetBranchAddress("noise", &noise, &noiseBranch); - for (Int_t cnt=0; cntfDynNoiseTree->GetEntries(); cnt++) { - processed->fDynNoiseTree->GetEntry(cnt); + for (Int_t cnt=0; cntfNoiseTree->GetEntries(); cnt++) { + processed->fNoiseTree->GetEntry(cnt); histogram.Noise->Fill(noise); } histogram.Noise->GetQuantiles( 3, noisequantiles, probabilities); + histogram.avgNoise = noisequantiles[1]; + histogram.avgNoisePlus = noisequantiles[2] - noisequantiles[1]; + histogram.avgNoiseMinus = noisequantiles[1] - noisequantiles[0]; // if (labbook.system == "PXI") // for (int j=0; j<3; j++) // noisequantiles[j] /= 16.0; // TODO analyze PXI scales @@ -509,6 +624,12 @@ Bool_t Run::binSeedSumVeto() } } } + gROOT->SetBatch(kTRUE); + if (labbook.source.Contains("Fe")) + histogram.posVeto=FitPerform(histogram.Veto, "gaus"); + histogram.posSeed=FitPerform(histogram.Seed); + histogram.posSum=FitPerform(histogram.Sum, "gaus"); + gROOT->SetBatch(kFALSE); } void Run::setPlotStyle(Int_t x){ @@ -523,8 +644,8 @@ Bool_t Run::plotNoise() { if (!error) { - TString legendEntry = Form("Noise: %.2f + %.2f - %.2f",noisequantiles[1],noisequantiles[1] - noisequantiles[0],noisequantiles[2] - noisequantiles[1] ); - TCanvas* canvas = plot1DHistogram(histogram.Noise, "", legendEntry); + TString legendEntry = Form("Noise: %.2f + %.2f - %.2f", histogram.avgNoise, histogram.avgNoisePlus, histogram.avgNoiseMinus ); + noisecanvas = plot1DHistogram(histogram.Noise, "landau", "", legendEntry); return 0; } return 0; @@ -534,7 +655,7 @@ Bool_t Run::plotSeed() { if (!error) { - plot1DHistogram(histogram.Seed); + plot1DHistogram(histogram.Seed, "landau"); return 0; } } @@ -544,7 +665,7 @@ Bool_t Run::plotSum() { if (!error) { - plot1DHistogram(histogram.Sum); + plot1DHistogram(histogram.Sum, "gaus"); return 0; } return 0; @@ -554,45 +675,229 @@ Bool_t Run::plotVeto() { if (!error) { - plot1DHistogram(histogram.Veto); + plot1DHistogram(histogram.Veto, "gaus"); return 0; } return 0; } -Bool_t Run::plotAllHistograms() +// Int_t findMaxBin(TH1F* th1fpointer) { +// Int_t maxbinval = th1fpointer->GetM +// +// } + +Bool_t Run::plotAllHistograms(histogramstruct* histogramstructpointer) { if (!error) { + Float_t lastbin; + Int_t random = random1->Rndm()*100000; TString canvastitle = Form("%s", runcode.Data()); - TCanvas* canvas = new TCanvas(canvastitle, canvastitle, 1200, 800); + if (histogramstructpointer->calibrated) + canvastitle += "_el"; + TString canvasname = Form("%s%d",runcode.Data(),random); + TCanvas* canvas = new TCanvas(canvasname, canvastitle, 1200, 800); canvas->Divide(2,2); canvas->cd(1); - histogram.Seed->Draw(); + histogramstructpointer->Seed->Draw(""); + plotVerticalLine(histogramstructpointer->Seed, histogramstructpointer->posSeed); + lastbin = histogramstructpointer->Seed->GetBinCenter(histogramstructpointer->Seed->FindLastBinAbove(10,1)); + histogramstructpointer->Seed->SetAxisRange(0,lastbin*1.1,"X"); + gPad->SetLogy(1); canvas->cd(2); - histogram.Sum->Draw(); + histogramstructpointer->Sum->Draw(); + plotVerticalLine(histogramstructpointer->Sum, histogramstructpointer->posSum); + lastbin = histogramstructpointer->Sum->GetBinCenter(histogramstructpointer->Sum->FindLastBinAbove(10,1)); + histogramstructpointer->Sum->SetAxisRange(0,lastbin*1.1,"X"); canvas->cd(3); histogram.Veto->Draw(); + if (labbook.source.Contains("Fe")) + plotVerticalLine(histogram.Veto, histogram.posVeto); + histogram.Veto->SetAxisRange(histogram.posVeto*0.7,histogram.posVeto*1.4,"X"); canvas->cd(4); - histogram.Noise->Draw(); - TString legendEntry = Form("Noise: %.2f + %.2f - %.2f",noisequantiles[1],noisequantiles[1] - noisequantiles[0],noisequantiles[2] - noisequantiles[1] ); + histogramstructpointer->Noise->Draw(); + TString legendEntry = Form("Noise: %.2f + %.2f - %.2f",histogramstructpointer->avgNoise, histogramstructpointer->avgNoisePlus, histogramstructpointer->avgNoiseMinus); TLegend* leg = new TLegend(0.5,0.8,0.89,0.89);//(0.6,0.7,0.89,0.89); - leg->AddEntry(histogram.Veto, legendEntry, "l"); + leg->AddEntry(histogramstructpointer->Veto, legendEntry, "l"); leg->SetTextSize(0.03); - leg->Draw(); + leg->Draw(); + +// canvas -> Print( savepathresults + "/" + canvastitle + ".eps"); + + TImageDump *img = new TImageDump(savepathresults + "/" + canvastitle + ".png"); + canvas->Paint(); + img->Close(); + + TFile *f = new TFile(savepathresults + "/" + canvastitle + ".root","RECREATE"); + f->cd(); + f->Append(canvas); + f->Append(img); + f->Write(); + +// gStyle->SetPaperSize(10.,10.); +// canvas->Print(savepathresults + "/" + canvastitle + ".tex"); + + return 0; + } +} + +Bool_t Run::plotAllHistograms() +{ + if (!error) + { + plotAllHistograms(&histogram); return 0; } } -TCanvas* Run::plot1DHistogram(TH1F* onehistogram, TString titlestr, TString legendstr) +Bool_t Run::plotAllHistogramsCalibrated() +{ + if (!error) + { + if (histogramCalibrated.calibrated) { + plotAllHistograms(&histogramCalibrated); + return 0; + } + } + return 1; +} + +Float_t Run::FitPerform(TH1F* histogrampointer, TString fitFuncType) { + Float_t posMax = 0; + Float_t posMaxValHist = histogrampointer->GetXaxis()->GetXmax(); + + if (doFits) + { + histogrampointer->GetXaxis()->SetRange(histogrampointer->GetXaxis()->FindBin(posMaxValHist/15),histogrampointer->GetXaxis()->FindBin(posMaxValHist)); // look only for maxima with x greater than posMaxValHist/15, cut away noise +// Int_t xValMax = histogrampointer->GetBinCenter(histogrampointer->GetMaximumBin()); + TF1* fitFunc = new TF1("fitFunc",fitFuncType,posMaxValHist/15,posMaxValHist); + + if (fitFuncType.Contains("gaus")) + { + if (TString(histogrampointer->GetName()).Contains("Veto")) + { +// histogrampointer->GetXaxis()->SetRange(200,histogrampointer->GetXaxis()->FindBin(posMaxValHist)); // look only for maxima with x greater than posMaxValHist/15, cut away noise + + Float_t peak11 = histogrampointer->GetXaxis()->GetBinCenter(histogrampointer->GetMaximumBin()); + Float_t peak1 = histogrampointer->GetMaximumBin(); + Float_t peak1val = histogrampointer->GetBinContent(histogrampointer->GetMaximumBin()); + Float_t avg = 0; + for(Int_t bin=histogrampointer->GetXaxis()->FindBin(posMaxValHist/15);binFindLastBinAbove(0);bin++) + { + avg += histogrampointer->GetBinContent(bin); + } + avg /= histogrampointer->FindLastBinAbove(0) - histogrampointer->GetXaxis()->FindBin(posMaxValHist/15); + Float_t peak2 = histogrampointer->FindLastBinAbove(avg/4); + Float_t peak21 = histogrampointer->GetXaxis()->GetBinCenter(peak2); + Float_t peak2val = histogrampointer->GetBinContent(peak2); + histogrampointer->GetXaxis()->SetRange(peak1,peak2); // look only for maxima with x greater than posMaxValHist/15, cut away noise + // + cout << coloryellow << "peak1 " << peak11 << endlr; + cout << coloryellow << "peak1val " << peak1val << endlr; + cout << coloryellow << "peak2 " << peak21 << endlr; + cout << coloryellow << "peak2val " << peak1val << endlr; + cout << coloryellow << "avg " << avg << endlr; + + Float_t min = histogrampointer->GetMinimumBin(); + cout << coloryellow << "min " << histogrampointer->GetXaxis()->GetBinCenter( min ) << endlr; + histogrampointer->GetXaxis()->SetRange(min,histogrampointer->FindLastBinAbove(0)); // look only for maxima with x greater than posMaxValHist/15, cut away noise + + + + histogrampointer->Fit(fitFunc, "N,Q,W", "", histogrampointer->GetXaxis()->GetBinCenter(min), posMaxValHist); + } else { + histogrampointer->Fit(fitFunc, "N,Q,W", "", posMaxValHist/15, posMaxValHist); + } + Float_t sigma = fitFunc->GetParameter(2); + if (sigma > 50) + { + cout << coloryellow << "sigma suspiciously height when fitting " << histogrampointer->GetName() << " spectrum: " << sigma << endlr; + return 0; + } + posMax = fitFunc->GetMaximumX(); + fitFunc->DrawCopy("same"); + TString legendEntry = TString(Form("%s",runcode.Data())); + TLegend* leg = new TLegend(0.5,0.5,0.89,0.89);//(0.6,0.7,0.89,0.89); + // leg->SetHeader();//"Legend Title"); + leg->SetFillStyle(0); + leg->AddEntry((TObject*) 0, legendEntry, ""); + leg->SetTextSize(0.05); + leg->Draw(); + + } + else if (fitFuncType=="landau") + { + Float_t fitMax1 = 1000; + Float_t fitMax2 = 1000; + Float_t fitMax3 = 1000; + Float_t minFitMax = 1000; + Float_t maxFitMax = 1000; + + cout << "posMaxValHist/15: " << posMaxValHist/15 << endl; + + histogrampointer->Fit(fitFunc, "N,Q,W", "", posMaxValHist/15, posMaxValHist); + fitMax1 = fitFunc->GetMaximumX(); + fitFunc->DrawCopy("same"); + histogrampointer->Fit(fitFunc, "N,Q,W", "", posMaxValHist/15, fitMax1*1.1); + fitMax2 = fitFunc->GetMaximumX(); + fitFunc->SetLineColor(kBlue); + fitFunc->SetLineStyle(2); // dashed + fitFunc->DrawCopy("same"); + histogrampointer->Fit(fitFunc, "N,Q,W", "", fitMax1*0.9, posMaxValHist); +// histogrampointer->Fit(fitFunc, "N,Q,W", "", fitMax1, histogrampointer->GetBinCenter(bini)); + fitMax3 = fitFunc->GetMaximumX(); + fitFunc->SetLineColor(kGreen); + fitFunc->DrawCopy("same"); + fitFunc->SetLineStyle(1); // normal for the following fits + + // Sort the three fits and save error estimation + minFitMax = TMath::Min(TMath::Min(fitMax1,fitMax2),fitMax3); + maxFitMax = TMath::Max(TMath::Max(fitMax1,fitMax2),fitMax3); + posMax = fitMax1 + fitMax2 + fitMax3 - minFitMax - maxFitMax; + + //fitLandauErrorLeft.push_back(posMax - minFitMax); + //fitLandauErrorRight.push_back(maxFitMax - posMax); + } + } + + return posMax; +} + +void Run::plotVerticalLine(TH1F* histogrampointer, Float_t xVal) { + if (xVal > 0) + { + Float_t posMaxValue = 0; + posMaxValue = histogrampointer->GetXaxis()->FindBin(xVal); + posMaxValue = histogrampointer->GetBinContent(posMaxValue); + TLine *l = new TLine(xVal,0.5,xVal,posMaxValue); + l->SetLineColor(kRed); + l->SetLineStyle(2); // dashed + l->Draw("same"); + + TString legendEntry = TString(Form("peak position: %.1f",xVal )); + TLegend* leg = new TLegend(0.5,0.8,0.89,0.89);//(0.6,0.7,0.89,0.89); + leg->SetFillColor(0); + leg->SetBorderSize(0); + leg->AddEntry((TObject*) 0, legendEntry, ""); + leg->SetTextSize(0.03); + leg->Draw(); + } +} + +TCanvas* Run::plot1DHistogram(TH1F* onehistogram, TString fitFuncType, TString titlestr, TString legendstr) +{ + Int_t random = random1->Rndm()*100000; if (titlestr.Length() < 1) titlestr = Form("%s",onehistogram->GetTitle()); TString canvastitle = Form("%s %s", onehistogram->GetName(), runcode.Data()); - TCanvas* canvas = new TCanvas(canvastitle, canvastitle, 700, 500); + TString canvasname = Form("%s %s %d", onehistogram->GetName(), runcode.Data(), random); + TCanvas* canvas = new TCanvas(canvasname, canvastitle, 900, 700); onehistogram->SetTitle(titlestr); onehistogram->Draw(); - TLegend* leg = new TLegend(0.5,0.8,0.89,0.89);//(0.6,0.7,0.89,0.89); + Float_t maxValue = FitPerform(onehistogram, fitFuncType); + plotVerticalLine(onehistogram, maxValue); + TLegend* leg = new TLegend(0.8,0.8,0.89,0.89);//(0.6,0.7,0.89,0.89); leg->SetFillColor(0); leg->SetBorderSize(0); if (legendstr.Length() < 1) @@ -604,13 +909,15 @@ TCanvas* Run::plot1DHistogram(TH1F* onehistogram, TString titlestr, TString lege canvas -> SaveAs( savepathresults + "/" + runcode + " " + onehistogram->GetName() + ".eps"); - TImage *img = TImage::Create(); - img->FromPad(canvas); - img->WriteImage(savepathresults + "/" + runcode + " " + onehistogram->GetName() + ".png"); + TImageDump *img = new TImageDump(savepathresults + "/" + runcode + " " + onehistogram->GetName() + ".png"); + canvas->Paint(); + img->Close(); - TFile *f = new TFile(savepathresults + "/" + runcode + " " + onehistogram->GetName() + ".root","UPDATE"); - f->WriteTObject(canvas); - f->WriteTObject(img); + TFile *f = new TFile(savepathresults + "/" + runcode + " " + onehistogram->GetName() + ".root","RECREATE"); + f->cd(); + f->Append(canvas); + f->Append(img); + f->Write(); gStyle->SetPaperSize(10.,10.); canvas->Print(savepathresults + "/" + runcode + " " + onehistogram->GetName() + ".tex"); @@ -644,17 +951,23 @@ Bool_t Run::writeAllHistogramsToFile() { system("mkdir "+ savepathresults + " -p"); TString filename= savepathresults + "/" + runcode + " histograms.dat"; - fstream* fout = new fstream(filename,ios::out); + fstream* fout = new fstream(filename,ios::out); - TString header = Form("#bin [ADU]\tSeed\tSum\t\Veto\tbin noise\tnoise\tbin [e]\tbin [Veto%]\tSeed"); + TString header = Form("#bin [ADU]\tbin [e]\tSeed\tSum\t\Veto\tbin noise [ADU]\tbin noise [e]\tnoise\tbin [Veto%]\tSeed\n"); + header += Form("#posVeto, run: %.1f, DB: %.1f, Fe55 DB (%d, %.1f): %.1f\n", histogram.posVeto, labbook.posVetoDB, Fe55run.posVetorunnumber, Fe55run.temperature, Fe55run.posVeto); + header += Form("#posSeed, run: %.1f, DB: %.1f\n", histogram.posSeed, labbook.posSeedDB); + header += Form("#posSum, run: %.1f, DB: %.1f\n", histogram.posSum, labbook.posSumDB); + header += Form("#Noise [ADU]: %.2f +%.2f -%.2f\n", histogram.avgNoise, histogram.avgNoisePlus, histogram.avgNoiseMinus ); + if (histogramCalibrated.calibrated) + header += Form("#Noise [e]: %.2f +%.2f -%.2f",histogramCalibrated.avgNoise, histogramCalibrated.avgNoisePlus, histogramCalibrated.avgNoiseMinus ); *fout << header << endl; TString outline; for(Int_t bin=0;binGetNbinsX();bin++) { - outline=Form("%.1f\t%.1f\t%.1f\t%.1f", histogram.Seed->GetBinCenter(bin), histogram.Seed->GetBinContent(bin), histogram.Sum->GetBinContent(bin), histogram.Veto->GetBinContent(bin)); + outline=Form("%.1f\t%.1f\t%.1f\t%.1f", histogram.Seed->GetBinCenter(bin), histogramCalibrated.calibrated?histogramCalibrated.Seed->GetBinCenter(bin):0, histogram.Seed->GetBinContent(bin), histogram.Sum->GetBinContent(bin), histogram.Veto->GetBinContent(bin)); if (bin < systemparamcur.nbinsnoise) - outline+=Form("\t%.1f\t%.1f", histogram.Noise->GetBinCenter(bin),histogram.Noise->GetBinContent(bin)); + outline+=Form("\t%.1f\t%.1f", histogram.Noise->GetBinCenter(bin),histogramCalibrated.calibrated?histogramCalibrated.Noise->GetBinCenter(bin):0,histogram.Noise->GetBinContent(bin)); *fout<close(); @@ -763,50 +1076,39 @@ void Run::MakeGnuplotFile() //system("okular "+ ergebnisfile + ".png &"); } -void Run::initHistograms() +void Run::initHistograms(histogramstruct* histogramstructpointer) { - TString prefix = "Seed"; - TString humanreadablestr = Form("%s, %s spectrum, Mi%s, chip %s, %s, T=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), labbook.temp); - histogram.Seed=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.nbins, 0, systemparamcur.maxbin); - histogram.Seed->SetLineStyle(rootlinestyle[plotStyle]); - histogram.Seed->SetLineColor(rootcolors[plotStyle]); - histogram.Seed->SetStats(kTRUE); - histogram.Seed->SetStats(111111111); - histogram.Seed->SetLineWidth(3); - - prefix = "Sum"; - humanreadablestr = Form("%s, %s spectrum, Mi%s, chip %s, %s, T=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), labbook.temp); - histogram.Sum=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.nbins, 0, systemparamcur.maxbin); - histogram.Sum->SetLineStyle(rootlinestyle[plotStyle]); - histogram.Sum->SetLineColor(rootcolors[plotStyle]); - histogram.Sum->SetLineWidth(3); - - /// TH1F histogram with veto spectrum, used to identify the veto peak - prefix = "Veto"; - humanreadablestr = Form("%s, %s spectrum, Mi%s, chip %s, %s, T=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), labbook.temp); - histogram.Veto=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.nbins, 0, systemparamcur.maxbin); - histogram.Veto->SetLineStyle(rootlinestyle[plotStyle]); - histogram.Veto->SetLineColor(rootcolors[plotStyle]); - histogram.Veto->SetLineWidth(3); - histogram.Veto->SetAxisRange(300,550,"X"); + initHistogram(histogramstructpointer->Seed, "Seed"); + initHistogram(histogramstructpointer->Sum, "Sum"); + initHistogram(histogramstructpointer->Veto, "Veto"); - prefix = "Noise"; - humanreadablestr = Form("%s, %s spectrum, Mi%s, chip %s, %s, T=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), labbook.temp); - histogram.Noise=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.nbinsnoise, 0, systemparamcur.maxbinnoise); - histogram.Noise->SetLineStyle(rootlinestyle[plotStyle]); - histogram.Noise->SetLineColor(rootcolors[plotStyle]); - histogram.Noise->SetLineWidth(3); + TString prefix = "Noise"; + TString humanreadablestr = Form("%s, %s spectrum, Mi%s, chip %s, %s, T=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), labbook.temp); + histogramstructpointer->Noise=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.nbinsnoise, 0, systemparamcur.maxbinnoise); + histogramstructpointer->Noise->SetLineStyle(rootlinestyle[plotStyle]); + histogramstructpointer->Noise->SetLineColor(rootcolors[plotStyle]); + histogramstructpointer->Noise->SetLineWidth(3); + histogramstructpointer->Noise->GetXaxis()->SetTitle("Q_coll [ADU]"); + histogramstructpointer->Noise->GetYaxis()->SetTitle(Form("Entries [1/%.1f ADU]",histogramstructpointer->Noise->GetBinWidth(1))); + histogramstructpointer->Noise->GetXaxis()->CenterTitle(); + histogramstructpointer->Noise->GetYaxis()->CenterTitle(); } +void Run::initHistogram(TH1F* &histogrampointer, TString prefix) +{ + TString humanreadablestr = Form("%s, %s spectrum, Mi%s, chip %s, %s, T=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), labbook.temp); + histogrampointer=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.nbins, 0, systemparamcur.maxbin); + histogrampointer->SetLineStyle(rootlinestyle[plotStyle]); + histogrampointer->SetLineColor(rootcolors[plotStyle]); + histogrampointer->SetStats(kTRUE); + histogrampointer->SetStats(111111111); + histogrampointer->SetLineWidth(3); + histogrampointer->GetXaxis()->SetTitle("Q_coll [ADU]"); + histogrampointer->GetYaxis()->SetTitle(Form("Entries [1/%.1f ADU]",histogrampointer->GetBinWidth(1))); + histogrampointer->GetXaxis()->CenterTitle(); + histogrampointer->GetYaxis()->CenterTitle(); +} -// void Run::initHistogram(TH1F* curhistogram, TString prefix) -// { -// TString humanreadablestr = Form("%s, %s spectrum, Mi%s, chip %s, %s, T=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), labbook.temp); -// curhistogram=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.maxbin, 0, systemparamcur.nbins); -// curhistogram->SetLineStyle(rootlinestyle[plotStyle]); -// curhistogram->SetLineColor(rootcolors[plotStyle]); -// curhistogram->SetLineWidth(3); -// } void Run::initRootParameters() { rootcolors = new Int_t[13]{1, 2, 4, 6, 8, 13, 46, 28, 32, 33, 12, 20, 40}; diff --git a/MABS_run_analyzer/Run.h b/MABS_run_analyzer/Run.h index a11303e..f776ec9 100644 --- a/MABS_run_analyzer/Run.h +++ b/MABS_run_analyzer/Run.h @@ -13,9 +13,11 @@ #include #include #include +#include #include #include #include +#include #include "help.h" @@ -50,6 +52,8 @@ private: Int_t plotStyle=0; + TCanvas* noisecanvas = NULL; + /** * @brief Takes a number, returns a string, used to build SQL queries */ @@ -131,6 +135,8 @@ private: /// is set to true if an error occured Bool_t error = 0; + TRandom* random1; + /** * @brief fills noise #histogram */ Bool_t binNoise(); @@ -140,7 +146,40 @@ private: /// noise quantiles: mean value, sigma in postive direction and sigma in negative direction Double_t noisequantiles[3]; - TCanvas* plot1DHistogram(TH1F* onehistogram, TString titlestr = "", TString legendstr = ""); + TCanvas* plot1DHistogram(TH1F* onehistogram, TString fitFuncType = "landau", TString titlestr = "", TString legendstr = ""); + + + /** + * @brief Plots vertical dotted red line from x-axis to graph at place x + * + * @param histogrampointer histogram pointer to calculate vertical line end + * @param xVal position of the vertical line at x-axis + * + */ + void plotVerticalLine(TH1F* histogrampointer, Float_t xVal); + + /** + * @brief intern function to calculate and plot fit curve to given histogram + * + * @param histNtuple histogram pointer to calculate fit to + * @return peak position of the fit + * + */ + Float_t FitPerform(TH1F*, TString fitFuncType="landau"); + + + + /** + * @brief rescales all histograms from ADU to electrons */ + Bool_t rescaleHistograms(); + + /** + * @brief rescales one specific histogram from ADU to electrons */ + void rescaleHistogram(TH1F* &histogrampointernew, TH1F* &histogrampointerold ); + + /** + * @brief calculates Charge Collection Efficiency if Fe55 run */ + Bool_t calculteCCE(); /** * @brief Checks if a file exists @@ -184,12 +223,9 @@ private: Int_t* rootcolors; Int_t* rootlinestyle; - - /// init all histograms, set binwidth, bin amount and names - void initHistograms(); - - // init one specific histogram -// void initHistogram(TH1F* curhistogram, TString prefix); + + /// init one specific histogram + void initHistogram(TH1F* &histogrampointer, TString prefix); void initRootParameters(); @@ -216,6 +252,9 @@ public: /** @brief Plots all histograms from #histogram into one canvas */ Bool_t plotAllHistograms(); + /** @brief Plots all histograms from #histogram into one canvas */ + Bool_t plotAllHistogramsCalibrated(); + /** @brief Writes a given histogram into a file */ Bool_t writeHistogramToFile(TH1F* onehistogram); @@ -251,6 +290,9 @@ public: Bool_t plotSum(); Bool_t plotVeto(); + /** @brief Prints all data gathered from the database */ + Bool_t debugDBreadout(); + /** @brief Turn on or off the use of dynamical noise adjustment @c MAPS::regetDynNoise() */ Bool_t useDynamicalNoise(Bool_t); @@ -284,8 +326,24 @@ public: 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; /// the resistivity of the epitexial layer of the chip Int_t resistivity = -1; /// Thickness of epitexial layer in micro meters @@ -327,10 +385,32 @@ public: TH1F* Veto; /// Noise histogram TH1F* Noise; + + /// fitted position of the most probable value of the seed spectrum + Float_t posSeed=0; + /// fitted position of the most probable value in the over cluster summed spectrum + Float_t posSum=0; + /// fitted position of the calibration peak of Fe55-beta-photons in the seed spectrum, from a run best suited to the current + Float_t posVeto=0; - TF1* SeedSr90PeakFit; + /// Average Noise value + Float_t avgNoise = 0; + /// Positive Noise sigma + Float_t avgNoisePlus = 0; + /// Negative Noise sigma + Float_t avgNoiseMinus = 0; + + /// set to true, if bins are in electrons, otherwise in ADU + Bool_t calibrated = false; }; histogramstruct histogram; + histogramstruct histogramCalibrated; + + /** @brief Plots all histograms from #histogram into one canvas */ + Bool_t plotAllHistograms(histogramstruct*); + + /// init all histograms, set binwidth, bin amount and names + void initHistograms(histogramstruct*); pixelinfo pixelinfoMi34[32]; @@ -339,15 +419,10 @@ public: /// if #dividedmatrix ist set to true, which part to analyze? Bool_t upperpart = false; - /// fitted position of the most probable value of the seed spectrum - Float_t posSeed=0; - /// fitted position of the most probable value in the over cluster summed spectrum - Float_t posSum=0; - /// fitted position of the calibration peak of Fe55-beta-photons in the seed spectrum, from a run best suited to the current - Float_t posVeto=0; - - Int_t maxbin; - + /// set to TRUE if fits should be drawn and calculated + Bool_t doFits = true; + /// fit curve ro use, gauss or landau + /** @brief related Fe55 run * * if the analyzed run is not a Fe55 calibration run, find a related Fe55 run @@ -361,9 +436,9 @@ public: // /// runnumber from where the position of the veto peak was taken Int_t posVetorunnumber = 0; /// fitted position of the calibration peak of Fe55-beta-photons in the seed spectrum, from a run best suited to the current - Float_t posVeto=0; + Float_t posVeto=-1; /// temperature - Float_t temperature; + Float_t temperature = -1; }; /** @brief related Fe55 run * @@ -374,12 +449,6 @@ public: * Fe55 calibration peak. ADU can be converted to e- */ OtherRun Fe55run; - /// noise average in ADU - Float_t NoiseAvg=0; - /// positive noise error in ADU - Float_t NoiseAvgPlus=0; - /// negative noise error in ADU - Float_t NoiseAvgMinus=0; /// to convert from ADU to values in electron one has to divide by this value, it is given in [1/e] Float_t gain=0; /// Charge collection efficciency of the cluster in percent diff --git a/bot/Functions/Header.au3 b/bot/Functions/Header.au3 index 5ad6aec..9a7a26f 100755 --- a/bot/Functions/Header.au3 +++ b/bot/Functions/Header.au3 @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -37,6 +38,7 @@ $cellNote = 16 $estimate = 0 $totalrealruns = 0 $temperaturebefore = -10000 +Dim $skippedruns[1] ; TODO fix skipping runs ; set external parameters $FileName = IniRead($configfile, "experimental setup", "ExcelPath", "H:\dennis doering\Arbeitsprogramme\Mimosa34\LaborbuchMi34_PXI.xls") ; read path to Excel file diff --git a/bot/Functions/WaitForTemperature.au3 b/bot/Functions/WaitForTemperature.au3 index 8bc911f..8e5cfc1 100755 --- a/bot/Functions/WaitForTemperature.au3 +++ b/bot/Functions/WaitForTemperature.au3 @@ -12,10 +12,12 @@ While Not $tempcorrent $tempcorrent = True ExitLoop 1 EndIf - If ($TempCooling < $currenttemp + 0.5 And $TempCooling > $currenttemp - 0.5) Then + ;If ($TempCooling < $currenttemp + 0.5 And $TempCooling > $currenttemp - 0.5) Then + If ($TempCooling < $currenttemp + 5 And $TempCooling > $currenttemp - 5) Then ;Dennis changed to 5°C difference $tempcorrent = True Else - If $tempwaiti > 5 Then ; after 30 minutes give up waiting + ;If $tempwaiti > 5 Then ; after 30 minutes give up waiting + If $tempwaiti > 1 Then ; Dennis changed to 5 Minutes to accelerate noise-T-scan $currenttempchip = GetTemperatureForSure("Chip" & $system) RefreshGUISendNtfct("Cooling could not reach needed temperature of " & $TempCooling & " °C within 30 minutes. Current cooling temperature is " & $currenttemp & ", chip temperature is " & $currenttempchip & ". Will proceed anyway.") $tempcorrent = True diff --git a/bot/Functions/mysql_functions.au3 b/bot/Functions/mysql_functions.au3 index 08d996a..5455d55 100755 --- a/bot/Functions/mysql_functions.au3 +++ b/bot/Functions/mysql_functions.au3 @@ -96,14 +96,19 @@ Func ReturnSuitRun($ChipGen, $ChipNum, $ChipRadiation, $RadiationSource, $System $sqlstring = $sqlstring & "MABS_comment IS NULL AND " $sqlstring = $sqlstring & "(datetime='1970-01-01 00:00:00' OR datetime IS NULL OR datetime='0000-00-00 00:00:00')" If $clock <> 0 Then $sqlstring = $sqlstring & " AND Clock=" & $Clock - $sqlstring = $sqlstring & " LIMIT 1" -;~ ConsoleWrite($sqlstring & @CRLF) + For $skippedrun In $skippedruns + If StringLen($skippedrun) > 0 Then + $sqlstring = $sqlstring & " AND runnumber != " & $skippedrun + EndIf + Next + $sqlstring = $sqlstring & " LIMIT 1" + ConsoleWrite($sqlstring & @CRLF) - $var = _Query($sql, $sqlstring) + $runcandidates = _Query($sql, $sqlstring) Local $runparam[7] - If NOT $var.EOF Then - With $var + If NOT $runcandidates.EOF Then + With $runcandidates $runparam[0] = .Fields("id").value $runparam[1] = .Fields("TempCooling").value $runparam[2] = .Fields("TempWaitFor").value diff --git a/bot/Mimosa_Autorun_USB.au3 b/bot/Mimosa_Autorun_USB.au3 index e9e14c5..f37c847 100755 --- a/bot/Mimosa_Autorun_USB.au3 +++ b/bot/Mimosa_Autorun_USB.au3 @@ -140,6 +140,7 @@ If (Not @error) Then ; Check again if everything went well Sleep(1000) If (WinExists("Avertissement")) Then RefreshGUISendNtfct("Skipped run " & $runnumber & " could overwrite data.") + _ArrayAdd($skippedruns, $runnumber) $comment = "Skipped: Could overwrite data." #include "Functions/SaveToSQL.au3" Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(48, ''Warning'', ''Skipped run ' & $runnumber & ', could overwrite data!'')"') @@ -164,6 +165,7 @@ If (Not @error) Then ; Check again if everything went well If ($vref > 1000 Or $vref < 300) Then StopRun() RefreshGUISendNtfct("Skipped run " & $runnumber & ", vref value could not be set properly. Frequency: " & $clock) + _ArrayAdd($skippedruns, $runnumber) Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(48, ''Warning'', ''Skipped run ' & $runnumber & ', vref value needs to be too low (<300) or too high (>1000), please check manually!'')"') FileDelete($savedir & "/" & $runnumber & "/*") $vref = 650 @@ -183,6 +185,7 @@ If (Not @error) Then ; Check again if everything went well If ($j > 10) Then StopRun() RefreshGUISendNtfct("Skipped run " & $runnumber & ", vref value could not be set properly. Clock: " & $clock & " Mhz") + _ArrayAdd($skippedruns, $runnumber) Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox(48, ''Warning'', ''Skipped run ' & $runnumber & ', vref value needs to be too low (<300) or too high (>1000), please check manually!'')"') FileDelete($savedir & "/" & $runnumber & "/*") $vref = 650 -- 2.43.0