#include "TObjArray.h"
#include "TH1I.h"
#include "TH2F.h"
+#include "TMath.h"
#include <memory>
#include <algorithm>
#include <iostream>
}
file->cd();
if (fHistograms) {
+ for (int i=0; i<fHistograms->GetEntries(); i++) {
+ if (fHistograms->At(i)==NULL ||
+ !fHistograms->At(i)->InheritsFrom("TH1") ||
+ fHistograms->At(i)->InheritsFrom("TH2") ||
+ fHistograms->At(i)->InheritsFrom("TH3")
+ ) continue;
+ TH1* h=reinterpret_cast<TH1*>(fHistograms->At(i));
+ if (!h) continue;
+ float entropy=CalcEntropy(h);
+ if (entropy<0) continue;
+ TString title=h->GetTitle();
+ title+=Form(" entropy %.2f", entropy);
+ h->SetTitle(title);
+ }
fHistograms->Write();
}
file->Close();
}
+float AliHLTDataDeflaterSimple::CalcEntropy(TH1* histo, const char* /*option*/, int mode)
+{
+
+ if (!histo) return -1000.;
+
+ float l2=TMath::Log(2.0);
+ float integral=histo->Integral(0,histo->GetNbinsX());
+ int centerbin=mode*histo->GetNbinsX()/2;
+ int nofBins=histo->GetNbinsX()-centerbin;
+ float entropy=0.0;
+ for (int offset=0; offset<nofBins; offset++) {
+ float abundance=histo->GetBinContent(offset);
+ if (abundance<1.0) continue;
+ entropy += (- (Double_t) abundance / (Double_t) integral ) * log( ( (Double_t) abundance / (Double_t) integral )) / (l2);
+ }
+
+ return entropy;
+}
+
void AliHLTDataDeflaterSimple::Print(Option_t *option) const
{
// print info
/// DataDeflaterSimple has deflater version 1
virtual int GetDeflaterVersion() const {return 1;}
+ static float CalcEntropy(TH1* histo, const char* option="", int mode=0);
+
protected:
private:
/// copy constructor prohibited