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)
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
{
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();
}
cout << colorwhite << "initRootParameters():" << endlr;
initRootParameters();
cout << colorwhite << "initHistograms():" << endlr;
- initHistograms();
+ initHistograms(&histogram);
runexistsinDB = 1;
+ debugDBreadout();
}
else
{
}
}
+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;
// 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;}
}
fstream* fout = new fstream(storepathRAWLinux + "/rootfilecreated",std::ios::out);
*fout << "" << endl;
fout->close();
+
+ // TODO
+
}
else
{
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;
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)
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
}
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)
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)
}
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);
{
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)
{
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; cnt<processed->fDynNoiseTree->GetEntries(); cnt++) {
- processed->fDynNoiseTree->GetEntry(cnt);
+ for (Int_t cnt=0; cnt<processed->fNoiseTree->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
}
}
}
+ 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){
{
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;
{
if (!error)
{
- plot1DHistogram(histogram.Seed);
+ plot1DHistogram(histogram.Seed, "landau");
return 0;
}
}
{
if (!error)
{
- plot1DHistogram(histogram.Sum);
+ plot1DHistogram(histogram.Sum, "gaus");
return 0;
}
return 0;
{
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);bin<histogrampointer->FindLastBinAbove(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)
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");
{
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;bin<histogram.Seed->GetNbinsX();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<<outline<<endl;
}
fout->close();
//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};