}
void HistogramType::initHistogram(TH1F* &histogrampointer, TString prefix, Int_t color, Int_t style) {
- histogrampointer=new TH1F(Form("%d %s",labbook->runnumber, prefix.Data()), Form("%d %s, %s",labbook->runnumber,prefix.Data(), humanreadablestr.Data()), cursystempar->nbins, 0, cursystempar->maxbin);
+ histogrampointer=new TH1F(Form("%d %s",labbook->runnumber, prefix.Data()), Form("%s, %s",prefix.Data(), humanreadablestr.Data()), cursystempar->nbins, 0, cursystempar->maxbin);
histogrampointer->SetLineStyle(style);
histogrampointer->SetLineColor(color);
histogrampointer->SetStats(kTRUE);
histogrampointer->SetStats(111111111);
- histogrampointer->SetLineWidth(2); // TODO: set to 3 again
+ histogrampointer->SetLineWidth(3); // TODO: set to 3 again
histogrampointer->GetXaxis()->SetTitle("Q_coll [ADU]");
histogrampointer->GetYaxis()->SetTitle(Form("Entries [1/%.1f ADU]",histogrampointer->GetBinWidth(1)));
histogrampointer->GetXaxis()->CenterTitle();
Float_t posMaxValHist = histogrampointer->GetXaxis()->GetXmax();
// posMaxValHist/10 for USB system, the value is 90
Float_t noiseborder = 90;
- if (noisethresholdborder>0)
- noiseborder = noisethresholdborder;
- else if (noisethresholdborder > 0)
+ if (noisethresholdborder>=0)
noiseborder = noisethresholdborder;
if (fitFuncType.Contains("gaus"))
if (TString(histogrampointer->GetName()).Contains("Veto"))
{
+// if (verbose)
+// cout << "Range: " << histogrampointer->GetXaxis()->FindBin(noiseborder) << " to " << histogrampointer->GetXaxis()->FindBin(posMaxValHist) << endl;
Float_t peak1 = histogrampointer->GetMaximumBin();
Float_t peak2;
+// if (verbose)
+// cout << "histogrampointer->GetBinCenter(peak1) " << histogrampointer->GetBinCenter(peak1) << endl;
if (histogrampointer->GetBinCenter(peak1)<3.3*noiseborder) // vermutlich ist veto peak nicht am höchsten
{
+// if (verbose)
+// cout << "histogrampointer->GetBinCenter(peak1) " << histogrampointer->GetBinCenter(peak1) << " < 3 * noiseborder " << noiseborder << endl;
Float_t avg = 0;
for(Int_t bin=histogrampointer->GetXaxis()->FindBin(noiseborder);bin<histogrampointer->FindLastBinAbove(0);bin++)
avg += histogrampointer->GetBinContent(bin);
Float_t min = histogrampointer->GetMinimumBin();
histogrampointer->GetXaxis()->SetRange(min,histogrampointer->FindLastBinAbove(0)); // look only for maxima with x greater than noiseborder, cut away noise
// DEBUG
- // if (verbose)
- // {
- // cout << coloryellow << "peak1 " << histogrampointer->GetXaxis()->GetBinCenter(peak1) << endlr;
- // cout << coloryellow << "peak1val " << histogrampointer->GetBinContent(peak1) << endlr;
- // cout << coloryellow << "peak2 " << histogrampointer->GetXaxis()->GetBinCenter(peak2) << endlr;
- // cout << coloryellow << "peak2val " << histogrampointer->GetBinContent(peak2) << endlr;
- // cout << coloryellow << "min " << histogrampointer->GetXaxis()->GetBinCenter( min ) << endlr;
- // }
- histogrampointer->Fit(fitFunc, "N,Q,W", "", histogrampointer->GetXaxis()->GetBinCenter(min), posMaxValHist);
+// if (verbose)
+// {
+// cout << coloryellow << "noisethresholdborder " << noisethresholdborder << endlr;
+// cout << coloryellow << "peak1 " << histogrampointer->GetXaxis()->GetBinCenter(peak1) << endlr;
+// cout << coloryellow << "peak1val " << histogrampointer->GetBinContent(peak1) << endlr;
+// cout << coloryellow << "peak2 " << histogrampointer->GetXaxis()->GetBinCenter(peak2) << endlr;
+// cout << coloryellow << "peak2val " << histogrampointer->GetBinContent(peak2) << endlr;
+// cout << coloryellow << "min " << histogrampointer->GetXaxis()->GetBinCenter( min ) << endlr;
+// cout << coloryellow << "lastbin " << histogrampointer->FindLastBinAbove(0) << endl;
+// cout << coloryellow << "posMaxValHist " << posMaxValHist << endl;
+// }
+// cout << colorred << gMinuit->fCstatu.Data() << endlr;
+// cout << colorred << gMinuit->GetStatus() << endlr;
+// cout << colorred << fitFunc->GetChisquare() << endlr;
+ //histogrampointer->Fit(fitFunc, "N,Q,W", "", 70, 500);
+ int fittries = 0;
+ do {
+// cout << fittries << ": New range: " << histogrampointer->GetXaxis()->GetBinCenter(min+fittries*min/20) << " to " << posMaxValHist << endl;
+ histogrampointer->Fit(fitFunc, "N,Q,W", "", histogrampointer->GetXaxis()->GetBinCenter(min+fittries++*min/20), posMaxValHist);
+// cout << colorred << gMinuit->fCstatu.Data() << endlr;
+ } while (gMinuit->fCstatu.Contains("FAILED") && fittries < 8);
posMax = histogrampointer->GetXaxis()->GetBinCenter(histogrampointer->GetMaximumBin()); // Methode 1
+// if (verbose)
+// {
+// cout << coloryellow << "min " << histogrampointer->GetXaxis()->GetBinCenter( min ) << endlr;
+// cout << coloryellow << "posMax " << posMax << endlr;
+// }
histogrampointer->GetXaxis()->SetRange(histogrampointer->GetXaxis()->FindBin(noiseborder),histogrampointer->GetXaxis()->FindBin(posMaxValHist)); // look only for maxima with x greater than noiseborder, cut away noise
+// TCanvas* canvas = new TCanvas("2121", "212121212", 900, 700);
+// histogrampointer->Draw();
+// fitFunc->DrawCopy("same");
} else {
histogrampointer->Fit(fitFunc, "N,Q,W", "", noiseborder, posMaxValHist);
posMax = fitFunc->GetMaximumX(); // Methode 2
}
Float_t sigma = fitFunc->GetParameter(2);
posMax2 = fitFunc->GetMaximumX(); // Methode 2
+// if (verbose)
+// cout << coloryellow << "posMax2 " << posMax2 << endlr;
Float_t peakposdifperc = abs(posMax-posMax2)/min(posMax,posMax2);
if (sigma > 260 || peakposdifperc>0.3)
{
}
}
}
- // fitFunc->DrawCopy("same");
- TString legendEntry = TString(Form("%s","Gaus fit"));
- 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);
+
+// TString legendEntry = TString(Form("%s","Gaus fit"));
+// 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();
//
}
smoothedcurce->SetAxisRange(0,histogrampointer->GetBinCenter(histogrampointer->GetNbinsX()));
if (verbose) {
+ cout << colorwhite << histogrampointer->GetName() << endlr;
TString canvastitle = Form("%s Noisethreshold border", histogrampointer->GetName());
TString canvasname = Form("%s Noisethreshold border", histogrampointer->GetName());
TCanvas* canvas = new TCanvas(canvasname, canvastitle, 900, 700);
canvas->Update();
}
+ // Int_t bini =smoothedcurce->GetMaximumBin();
+ // thresholdbincurcandidate = bini;
+ // if (verbose)
+ // cout << "GetMaximumBin: smoothedcurce->GetBinContent(" << bini << "): " << smoothedcurce->GetBinContent(bini) << endl;
+ Int_t bini = 0;
+ Int_t falling = 0;
+ Int_t noisepeakcandidate = 0;
+
+ do {
+ Float_t curval=smoothedcurce->GetBinContent(bini++);
+ if (curval*0.95 <= smoothedcurce->GetBinContent(bini))
+ {
+ falling = 0;
+ noisepeakcandidate = bini;
+ }
+ else
+ {
+ falling++;
+ if (verbose)
+ cout << "falling at " << smoothedcurce->GetXaxis()->GetBinCenter(bini) << " as " << curval << " < " << smoothedcurce->GetBinContent(bini) << endl; // debug
+ }
+ } while (falling < 2 && bini<smoothedcurce->GetNbinsX());
+ if (verbose) {
+ cout << "Noise peak at: smoothedcurce->GetBinContent(" << noisepeakcandidate << "): " << smoothedcurce->GetBinContent(noisepeakcandidate) << endl;
+ }
Int_t thresholdbincurcandidate = 0;
- Int_t rising = 0;
- Int_t bini =smoothedcurce->GetMaximumBin();
- thresholdbincurcandidate = bini;
- // cout << "GetMaximumBin: smoothedcurce->GetXaxis()->GetBinCenter(" << bini << "): " << curval << endl;
+ bini = noisepeakcandidate;
+ Int_t rising = 0;
do {
Float_t curval=smoothedcurce->GetBinContent(bini++);
if (curval*0.95 <= smoothedcurce->GetBinContent(bini))
{
rising++;
- // cout << "rising at " << smoothedcurce->GetXaxis()->GetBinCenter(bini) << " as " << curval << " < " << smoothedcurce->GetBinContent(bini) << endl; // debug
+ if (verbose)
+ cout << "rising at bin " << bini << ":" << smoothedcurce->GetXaxis()->GetBinCenter(bini) << " as " << curval << " < " << smoothedcurce->GetBinContent(bini) << endl; // debug
}
else
{
rising = 0;
thresholdbincurcandidate = bini;
+ if (verbose)
+ cout << "falling at bin " << bini << ":" << smoothedcurce->GetXaxis()->GetBinCenter(bini) << " as " << curval << " < " << smoothedcurce->GetBinContent(bini) << endl; // debug
}
} while (rising < 3 && bini<smoothedcurce->GetNbinsX());
thresholdbincurcandidate *= rebinningfactor;
noisethresholdborder = histogrampointer->GetXaxis()->GetBinUpEdge(thresholdbincurcandidate);
if (verbose) {
- cout << " Noise threshold at " << noisethresholdborder;
+ cout << " Noise threshold at " << noisethresholdborder << endl;
}
return 0;
}