#include "TMDisplayingHitsPerEventAll.h"
#include "TMHistogrammingHitsPerEventAll.h"
#include "TMMainFrame.h"
#include "TMControlSPD.h"
#include "SPDMood.h"
#include <TSystem.h>
#include <TCanvas.h>
#include <TGStatusBar.h>

ClassImp(TMDisplayingHitsPerEventAll)

//_____________________________________________________________________
TMDisplayingHitsPerEventAll::TMDisplayingHitsPerEventAll(const Char_t *frameName, const TGWindow *p, UInt_t width, UInt_t height, TMHistogramming *hist, UInt_t id, UInt_t plotNr, UInt_t cloneId) :
  TMDisplaying(frameName,p,width,height,hist,id,plotNr,cloneId,kTRUE)
{
  gClient->GetColorByName("green", green);
  gClient->GetColorByName("gray", gray);

  CreateTopFrame();
  CreateStatusFrame();
  CreateBottomFrame();

  MapSubwindows();
  Resize();
  MapWindow();

  TCanvas *canv = fTheCanvas->GetCanvas();
  fHist->Draw(canv);
  Update();
}
//_____________________________________________________________________
TMDisplayingHitsPerEventAll::~TMDisplayingHitsPerEventAll() {}
//_____________________________________________________________________
void TMDisplayingHitsPerEventAll::CreateStatusFrame() {
  fTotalStatus = new TGStatusBar(this, fWidth, 27, kHorizontalFrame | kFixedSize);
  fTotalStatus->Draw3DCorner(kFALSE);
  AddFrame(fTotalStatus, new TGLayoutHints(kLHintsExpandX, 0,0,0,0));
}
//_____________________________________________________________________
void TMDisplayingHitsPerEventAll::Update() {
  ULong_t nrhits = ((TMHistogrammingHitsPerEventAll*)fHist)->GetTotalNumberOfHits();
  UInt_t nrevents = fHist->GetNrEvents();
  TString totalmsg;
  if (nrevents>0) {
    totalmsg = Form("Hits Per Event For Full Detector: %.2f",(Float_t)nrhits/nrevents);
  }
  else {
    totalmsg = Form("Hits Per Event For Full Detector: -");
  }
  fTotalStatus->SetText(totalmsg.Data(),0);
  TMDisplaying::Update();
}
