X-Git-Url: http://git.uio.no/git/?a=blobdiff_plain;f=EMCAL%2FAliEMCALHistoUtilities.cxx;h=b48fb6f8ed962129397b7bc0d371a584d3b4c233;hb=ccfdd67fc2d34525a6ab8a2b7ae5f14bf2e48db2;hp=98a507b8ad44a7ee5ccad06d585cb74f87b5864a;hpb=7ec8695a929efc8efe1a213e0381aea03c3221a6;p=u%2Fmrichter%2FAliRoot.git diff --git a/EMCAL/AliEMCALHistoUtilities.cxx b/EMCAL/AliEMCALHistoUtilities.cxx index 98a507b8ad4..b48fb6f8ed9 100644 --- a/EMCAL/AliEMCALHistoUtilities.cxx +++ b/EMCAL/AliEMCALHistoUtilities.cxx @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include #include #include @@ -69,20 +71,25 @@ AliEMCALHistoUtilities::~AliEMCALHistoUtilities() //destructor } -TList* AliEMCALHistoUtilities::MoveHistsToList(const char* name, Bool_t putToBrowser) +TList* AliEMCALHistoUtilities::MoveHistsToList(const char* name, Bool_t putToBrowser, Bool_t setOwner) { // Move HIST to list gROOT->cd(); TIter nextHist(gDirectory->GetList()); TList *list = new TList; list->SetName(name); - TObject *objHist; + if(setOwner) list->SetOwner(setOwner); + TObject *objHist=0; + // Move from gROOT to list while((objHist=nextHist())){ + //objHist->Dump(); if (!objHist->InheritsFrom("TH1")) continue; - ((TH1*)objHist)->SetDirectory(0); // Remove from gROOT + ((TH1*)objHist)->SetDirectory(0); list->Add(objHist); - gDirectory->GetList()->Remove(objHist); } + // Clear gROOT + gDirectory->GetList()->Clear(); + if(putToBrowser) gROOT->GetListOfBrowsables()->Add((TObject*)list); return list; } @@ -95,10 +102,12 @@ void AliEMCALHistoUtilities::FillH1(TList *l, Int_t ind, Double_t x, Double_t w, if(l == 0) return; if(ind>=0 && ind < l->GetSize()){ - hid = (TH1*)l->At(ind); + hid = dynamic_cast(l->At(ind)); + if (hid==0) return; + if(error <= 0.0) { // standard way hid->Fill(x,w); - } else{ + } else { bin = hid->FindBin(x); hid->SetBinContent(bin,w); hid->SetBinError(bin,error); @@ -112,8 +121,30 @@ void AliEMCALHistoUtilities::FillH2(TList *l, Int_t ind, Double_t x, Double_t y, static TH2* hid=0; if(l == 0) return; if(ind>=0 && ind < l->GetSize()){ - hid = (TH2*)l->At(ind); - hid->Fill(x,y,w); + hid = dynamic_cast(l->At(ind)); + if(hid) hid->Fill(x,y,w); + } +} + +void AliEMCALHistoUtilities::FillHProf(TList *l, Int_t ind, Double_t x, Double_t y, Double_t w) +{ + // fill profile histogram + static TProfile* h=0; + if(l == 0) return; + if(ind>=0 && ind < l->GetSize()){ + h = dynamic_cast(l->At(ind)); + if(h) h->Fill(x,y,w); + } +} + +void AliEMCALHistoUtilities:: FillHnSparse(TList *l, Int_t ind, Double_t* x, Double_t w) +{ + // Nov 02,2010: fill THnSparse hist + static THnSparse* hsp=0; + if(l==0 || x==0) return; + if(ind>=0 && ind < l->GetSize()){ + hsp = dynamic_cast(l->At(ind)); + if(hsp) hsp->Fill(x,w); } } @@ -154,7 +185,7 @@ int AliEMCALHistoUtilities::SaveListOfHists(TList *mylist,const char* name,Bool_ return save; } -void AliEMCALHistoUtilities::AddToNameAndTitle(TH1 *h, const char *name, const char *title) +void AliEMCALHistoUtilities::AddToNameAndTitle(TNamed *h, const char *name, const char *title) { // Oct 15, 2007 if(h==0) return; @@ -169,8 +200,8 @@ void AliEMCALHistoUtilities::AddToNameAndTitleToList(TList *l, const char *name, if(name || title) { for(int i=0; iGetSize(); i++) { TObject *o = l->At(i); - if(o->InheritsFrom("TH1")) { - TH1 *h = (TH1*)o; + if(o->InheritsFrom("TNamed")) { + TNamed *h = dynamic_cast(o); AddToNameAndTitle(h, name, title); } } @@ -187,6 +218,55 @@ void AliEMCALHistoUtilities::ResetListOfHists(TList *l) } } +void AliEMCALHistoUtilities::Titles(TH1 *hid, const char *titx,const char *tity) +{ + if(hid) { + hid->SetXTitle(titx); + hid->SetYTitle(tity); + } else { + printf(" TAliasPAI::titles() -> hid is 0 !\n"); + } +} + +TList* AliEMCALHistoUtilities::CreateProjectionsX(TList *l, const Int_t ind, const Char_t* name) +{ + // Sep 4 - seperate list for projections + TH2F *hid = dynamic_cast(l->At(ind)); + if(hid == 0) { + printf(" Object at ind %i is %s : should ne TH2F \n", + ind, l->At(ind)->ClassName()); + return 0; + } + + TList *lpt = new TList; + lpt->SetName(Form("%s%s", hid->GetName(), name)); + l->Add(lpt); + + TAxis* yax = hid->GetYaxis(); + TString tity = yax->GetTitle(); + tity.ReplaceAll(" ",""); + TString name1 = hid->GetName(); + TString nam = name1(3,name1.Length()-3); + TString tit1 = hid->GetTitle(), tit=tit1; + + TH1::AddDirectory(0); + + TH1D *hd = hid->ProjectionX(Form("00_%sProx",nam.Data()), 1, yax->GetNbins()); + tit += Form(" : %5.2f < %s < %5.2f (GeV/c)", yax->GetXmin(),tity.Data(),yax->GetXmax()); + hd->SetTitle(tit.Data()); + lpt->Add(hd); + + for(Int_t iy=1; iy<=yax->GetNbins(); iy++){ + tit = tit1; + tit += Form(" : %5.2f < %s < %5.2f (GeV/c)", yax->GetBinLowEdge(iy), tity.Data(), yax->GetBinUpEdge(iy)); + hd = hid->ProjectionX(Form("%2.2i_%sProx%i",iy, nam.Data(),iy),iy,iy); + hd->SetTitle(tit.Data()); + lpt->Add(hd); + } + + return lpt; +} + TLatex *AliEMCALHistoUtilities::Lat(const char *text, Float_t x,Float_t y, Int_t align, Float_t tsize, short tcolor) { // Oct 15, 2007