From 709053b258ba03c365ff5cf3117daa42aa8d9bee Mon Sep 17 00:00:00 2001 From: richterm Date: Wed, 14 Sep 2011 14:22:10 +0000 Subject: [PATCH] calculating entropy for parameter histograms --- HLT/BASE/AliHLTDataDeflaterSimple.cxx | 34 +++++++++++++++++++++++++++ HLT/BASE/AliHLTDataDeflaterSimple.h | 2 ++ 2 files changed, 36 insertions(+) diff --git a/HLT/BASE/AliHLTDataDeflaterSimple.cxx b/HLT/BASE/AliHLTDataDeflaterSimple.cxx index c684271085c..bc96e7ff330 100644 --- a/HLT/BASE/AliHLTDataDeflaterSimple.cxx +++ b/HLT/BASE/AliHLTDataDeflaterSimple.cxx @@ -28,6 +28,7 @@ #include "TObjArray.h" #include "TH1I.h" #include "TH2F.h" +#include "TMath.h" #include #include #include @@ -163,12 +164,45 @@ void AliHLTDataDeflaterSimple::SaveAs(const char *filename,Option_t */*option*/) } file->cd(); if (fHistograms) { + for (int i=0; iGetEntries(); 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(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; offsetGetBinContent(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 diff --git a/HLT/BASE/AliHLTDataDeflaterSimple.h b/HLT/BASE/AliHLTDataDeflaterSimple.h index eeea64762ea..3fd9bbdc09a 100644 --- a/HLT/BASE/AliHLTDataDeflaterSimple.h +++ b/HLT/BASE/AliHLTDataDeflaterSimple.h @@ -131,6 +131,8 @@ public: /// 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 -- 2.43.0