#ifndef ANALYSIS_IROOTHISTOGRAM_HXX #define ANALYSIS_IROOTHISTOGRAM_HXX #include "IHistogram.hxx" #include #include #include #include #include #include #include namespace COMET{ class IRootHistogram; template class IHist1; template class IHist2; template class IHist3; typedef IHist1 IH1F; typedef IHist1 IH1D; typedef IHist1 IH1I; typedef IHist2 IH2F; typedef IHist2 IH2D; typedef IHist2 IH2I; typedef IHist3 IH3F; typedef IHist3 IH3D; typedef IHist3 IH3I; } class COMET::IRootHistogram:public COMET::IVHistogram{ public: IRootHistogram(std::string name_space="", std::string name="", std::string title=""): COMET::IVHistogram(name_space,name) {} virtual ~IRootHistogram(){} using COMET::IVHistogram::SetLegendEntry; using COMET::IVHistogram::GetLegendEntry; using COMET::IVHistogram::SetDrawStyle; protected: template void SetLegendEntry(std::string name, THist* hist){ hist->GetListOfFunctions()->Add(new TNamed("legend",name.c_str())); } template std::string GetLegendEntry(const THist* hist)const{ TObject* label=const_cast(hist)->GetListOfFunctions()->FindObject("legend"); if(label) return label->GetTitle(); return ""; } template void SetDrawStyle(std::string style,THist* hist){ fDrawStyle=style; hist->GetListOfFunctions()->Add(new TNamed("style",fDrawStyle.c_str())); } std::string GetDrawStyle()const{ return fDrawStyle; } private: std::string fDrawStyle; }; #ifndef __CINT__ template class COMET::IHist1:public COMET::IRootHistogram,public TH1_t{ public: IHist1(std::string name_space, std::string name, std::string title, int n_bins, double x_low, double x_high): COMET::IRootHistogram(name_space,name), TH1_t(name.c_str(),title.c_str(), GetBins(n_bins,'x'),GetLow(x_low,'x'),GetHigh(x_high,'x')){} IHist1(std::string name_space, std::string name, std::string title): COMET::IRootHistogram(name_space,name), TH1_t(name.c_str(),title.c_str(),100,0,0){} virtual void Setup( const std::string & x_title, int x_bins, double x_low, double x_high){ TH1_t::SetBins(GetBins(x_bins,'x'),GetLow(x_low,'x'),GetHigh(x_high,'x')); TH1_t::GetXaxis()->SetTitle(x_title.c_str()); } int GetNAxes()const{return 1;} const TH1* Hist()const{return dynamic_cast(this);} TH1* Hist(){return dynamic_cast(this);} virtual std::string GetLegendEntry()const { return COMET::IRootHistogram::GetLegendEntry((TH1_t*)this); } virtual void SetLegendEntry(std::string name) { COMET::IRootHistogram::SetLegendEntry(name,(TH1_t*)this); } virtual void SetDrawStyle(std::string style) { COMET::IRootHistogram::SetDrawStyle(style,(TH1_t*)this); } virtual void SetAppearance(int colour,int style){ TH1_t::SetLineColor(colour); TH1_t::SetLineStyle(style); } virtual void FillWith(double val ) {TH1_t::Fill(val);} virtual void FillWith(double val ,double weight){TH1_t::Fill(val,weight);} virtual Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const{ return TH1_t::Write(name,option,bufsize); } virtual Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0){ return TH1_t::Write(name,option,bufsize); } using TH1_t::GetName; virtual void SetDirectory(TDirectory* dir){ TH1_t::SetDirectory(dir);} virtual const TDirectory* GetDirectory()const{ return TH1_t::GetDirectory();} virtual void ls(Option_t* option = "") const{ TH1_t::ls(option); } virtual void Normalize(double norm){ TH1_t::Scale(norm); } virtual void Normalize(COMET::IVHistogram* normalisation_hist, double scale=1){ TH1* norm=normalisation_hist->Hist(); if(!norm) { COMETError("Cannot normalise histogram "< class COMET::IHist2:public COMET::IRootHistogram,public TH2_t{ public: IHist2(std::string name_space, std::string name, std::string title, int x_bins, double x_low, double x_high, int y_bins, double y_low, double y_high): COMET::IRootHistogram(name_space,name), TH2_t(name.c_str(),title.c_str(), GetBins(x_bins,'x'),GetLow(x_low,'x'),GetHigh(x_high,'x'), GetBins(y_bins,'y'),GetLow(y_low,'y'),GetHigh(y_high,'y')){} IHist2(std::string name_space, std::string name, std::string title): COMET::IRootHistogram(name_space,name), TH2_t(name.c_str(),title.c_str(),100,0,0,100,0,0){} virtual void Setup( const std::string & x_title, int x_bins, double x_low, double x_high, const std::string & y_title, int y_bins, double y_low, double y_high){ TH2_t::SetBins(GetBins(x_bins,'x'),GetLow(x_low,'x'),GetHigh(x_high,'x'), GetBins(y_bins,'y'),GetLow(y_low,'y'),GetHigh(y_high,'y')); TH2_t::GetXaxis()->SetTitle(x_title.c_str()); TH2_t::GetYaxis()->SetTitle(y_title.c_str()); } int GetNAxes()const{return 2;} const TH1* Hist()const{return dynamic_cast(this);} TH1* Hist(){return dynamic_cast(this);} virtual void SetAppearance(int colour,int style){ TH2_t::SetMarkerColor(colour); TH2_t::SetLineColor(colour); TH2_t::SetLineStyle(style); TH2_t::SetFillStyle(style); } virtual std::string GetLegendEntry()const { return COMET::IRootHistogram::GetLegendEntry((TH2_t*)this); } virtual void SetLegendEntry(std::string name) { COMET::IRootHistogram::SetLegendEntry(name,(TH2_t*)this); } virtual void SetDrawStyle(std::string style) { COMET::IRootHistogram::SetDrawStyle(style,(TH2_t*)this); } virtual void FillWith(double val_1 ,double val_2 ){TH2_t::Fill(val_1,val_2);} virtual void FillWith(double val_1 ,double val_2 ,double weight){TH2_t::Fill(val_1,val_2,weight);} virtual Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const{ return TH2_t::Write(name,option,bufsize); } virtual Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0){ return TH2_t::Write(name,option,bufsize); } using TH2_t::GetName; virtual void SetDirectory(TDirectory* dir){ TH2_t::SetDirectory(dir);} virtual const TDirectory* GetDirectory()const{ return TH2_t::GetDirectory();} virtual void ls(Option_t* option = "") const{ TH2_t::ls(option); } virtual void Normalize(double norm){ TH2_t::Scale(norm); } virtual void Normalize(COMET::IVHistogram* normalisation_hist, double scale=1){ TH2* norm=dynamic_cast(normalisation_hist->Hist()); if(!norm) { COMETError("Cannot normalise histogram "< class COMET::IHist3:public COMET::IRootHistogram,public TH3_t{ public: IHist3(std::string name_space, std::string name, std::string title, int x_bins, double x_low, double x_high, int y_bins, double y_low, double y_high, int z_bins, double z_low, double z_high): COMET::IRootHistogram(name_space,name), TH3_t(name.c_str(),title.c_str(), GetBins(x_bins,'x'),GetLow(x_low,'x'),GetHigh(x_high,'x'), GetBins(y_bins,'y'),GetLow(y_low,'y'),GetHigh(y_high,'y'), GetBins(z_bins,'z'),GetLow(z_low,'z'),GetHigh(z_high,'z')){} IHist3(std::string name_space, std::string name, std::string title): COMET::IRootHistogram(name_space,name), TH3_t(name.c_str(),title.c_str(),100,0,0,100,0,0,100,0,0){} virtual void Setup( const std::string & x_title, int x_bins, double x_low, double x_high, const std::string & y_title, int y_bins, double y_low, double y_high, const std::string & z_title, int z_bins, double z_low, double z_high){ TH3_t::SetBins( GetBins(x_bins,'x'),GetLow(x_low,'x'),GetHigh(x_high,'x'), GetBins(y_bins,'y'),GetLow(y_low,'y'),GetHigh(y_high,'y'), GetBins(z_bins,'z'),GetLow(z_low,'z'),GetHigh(z_high,'z')); TH3_t::GetXaxis()->SetTitle(x_title.c_str()); TH3_t::GetYaxis()->SetTitle(y_title.c_str()); TH3_t::GetZaxis()->SetTitle(z_title.c_str()); } int GetNAxes()const{return 3;} const TH1* Hist()const{return dynamic_cast(this);} TH1* Hist(){return dynamic_cast(this);} virtual void SetAppearance(int ,int ){ } virtual std::string GetLegendEntry()const { return COMET::IRootHistogram::GetLegendEntry((TH3_t*)this); } virtual void SetLegendEntry(std::string name) { COMET::IRootHistogram::SetLegendEntry(name,(TH3_t*)this); } virtual void SetDrawStyle(std::string style) { COMET::IRootHistogram::SetDrawStyle(style,(TH3_t*)this); } virtual void FillWith(double val_1 ,double val_2 ,double val_3){TH3_t::Fill(val_1,val_2,val_3);} virtual void FillWith(double val_1 ,double val_2 ,double val_3,double weight){TH3_t::Fill(val_1,val_2,val_3,weight);} virtual Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0) const{ return TH3_t::Write(name,option,bufsize); } virtual Int_t Write(const char* name = 0, Int_t option = 0, Int_t bufsize = 0){ return TH3_t::Write(name,option,bufsize); } using TH3_t::GetName; virtual void SetDirectory(TDirectory* dir){ TH3_t::SetDirectory(dir);} virtual const TDirectory* GetDirectory()const{ return TH3_t::GetDirectory();} virtual void ls(Option_t* option = "") const{ TH3_t::ls(option); } virtual void Normalize(double norm){ TH3_t::Scale(norm); } virtual void Normalize(COMET::IVHistogram* normalisation_hist, double scale=1){ TH3* norm=dynamic_cast(normalisation_hist->Hist()); if(!norm) { COMETError("Cannot normalise histogram "<