13 #include "StMultiH2F.h"
17 #include "TDirectory.h"
23 StMultiH2F::StMultiH2F(
const char *name,
const char *title,Int_t nbinsx,
24 Axis_t xlow,Axis_t xup,Int_t nbinsy,Axis_t ylow,
25 Axis_t yup,Int_t nbinsz) :
26 TH3F(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,-0.5,-0.5+nbinsz),
29 StMultiH2F::~StMultiH2F() {
31 int zbins = TMath::Min(GetNbinsZ(),StMultiH2FMaxBins);
32 for (
int zbin=0; zbin<zbins; zbin++)
delete subHists[zbin];
36 void StMultiH2F::Draw(Option_t *option) {
39 int x0 = fXaxis.GetFirst();
40 int x1 = fXaxis.GetLast();
41 int y0 = fYaxis.GetFirst();
42 int y1 = fYaxis.GetLast();
45 int zbins = TMath::Min(GetNbinsZ(),StMultiH2FMaxBins);
48 if (!subHists) { subHists =
new TH2D*[zbins]; memset(subHists,0,zbins*
sizeof(TH2D*)); }
52 subHists[0] = XYProjection(GetName());
53 subHists[0]->SetStats((!TestBit(kNoStats)));
54 TAxis* taxisX = subHists[0]->GetXaxis();
55 TAxis* taxisY = subHists[0]->GetYaxis();
58 taxisX->SetRange(x0,x1);
59 taxisY->SetRange(y0,y1);
60 fXaxis.SetRange(x0,x1);
61 fYaxis.SetRange(y0,y1);
62 subHists[0]->Draw(option);
70 TLegend *legend =
new TLegend(0.80,0.84,0.98,0.98,
"Legend",
"NDC");
71 legend->SetFillColor(0);
72 legend->SetFillStyle(0);
73 legend->SetMargin(0.25);
76 double maxval = -999999.;
80 for (zbin=0; zbin<zbins; zbin++) {
81 if ((zbin >= 10) || (names[zbin].IsNull())) n0 = GetName();
82 else n0 = names[zbin];
84 delete subHists[zbin];
85 subHists[zbin] = XYProjection(n0.Data(),slice);
86 subHists[zbin]->SetLineColor(60+40*(zbin/(zbins-1)));
87 subHists[zbin]->SetStats(kFALSE);
88 TAxis* taxisX = subHists[zbin]->GetXaxis();
89 TAxis* taxisY = subHists[zbin]->GetYaxis();
92 taxisX->SetRange(x0,x1);
93 taxisY->SetRange(y0,y1);
95 double binmax = subHists[zbin]->GetMaximum();
96 if (binmax > maxval) {
100 legend->AddEntry(subHists[zbin],n0.Data(),
"l");
103 subHists[maxbin]->SetTitle(GetTitle());
104 subHists[maxbin]->Draw(option);
105 TString sameoption = option; sameoption +=
"same";
106 for (zbin=0; zbin<zbins; zbin++) {
107 if (zbin != maxbin) subHists[zbin]->Draw(sameoption.Data());
111 if (!TestBit(kNoStats)) {
113 subHists[0] = XYProjection(GetName());
114 subHists[0]->Reset();
115 subHists[0]->SetEntries(GetEntries());
116 subHists[0]->SetStats(kTRUE);
117 subHists[0]->Draw(sameoption.Data());
124 fXaxis.SetRange(x0,x1);
125 fYaxis.SetRange(y0,y1);
128 TH2D* StMultiH2F::XYProjection(
const char* name, Int_t zbin) {
129 static char buf[256];
130 if (zbin<0) sprintf(buf,
"%s.",name);
131 else sprintf(buf,
"%s_%d_%s",GetName(),zbin,name);
133 TList* tgList = gDirectory->GetList();
134 TH2D* temp = (TH2D*) tgList->FindObject(buf);
135 if (temp) tgList->Remove(temp);
137 if (zbin<0) fZaxis.SetRange();
138 else fZaxis.SetRange(zbin,zbin);
139 temp = (TH2D*) Project3D(
"yx");
141 TAttLine::Copy(*temp);
142 TAttFill::Copy(*temp);
143 TAttMarker::Copy(*temp);
144 temp->GetXaxis()->SetRange(fXaxis.GetFirst(),fXaxis.GetLast());
145 temp->GetYaxis()->SetRange(fYaxis.GetFirst(),fYaxis.GetLast());
149 void StMultiH2F::SavePrimitive(ostream& out, Option_t* option) {
152 bool nonEqiX = kFALSE;
153 bool nonEqiY = kFALSE;
158 if (GetXaxis()->GetXbins()->fN && GetXaxis()->GetXbins()->fArray) {
160 out <<
" Double_t xAxis[" << GetXaxis()->GetXbins()->fN
162 for (i = 0; i < GetXaxis()->GetXbins()->fN; i++) {
163 if (i != 0) out <<
", ";
164 out << GetXaxis()->GetXbins()->fArray[i];
166 out <<
"}; " << endl;
171 if (GetYaxis()->GetXbins()->fN && GetYaxis()->GetXbins()->fArray) {
173 out <<
" Double_t yAxis[" << GetYaxis()->GetXbins()->fN
175 for (i = 0; i < GetYaxis()->GetXbins()->fN; i++) {
176 if (i != 0) out <<
", ";
177 out << GetYaxis()->GetXbins()->fArray[i];
179 out <<
"}; " << endl;
184 out <<
" TH1 *" << GetName() <<
" = new " << ClassName() <<
"("
185 << quote << GetName() << quote <<
"," << quote << GetTitle() << quote
186 <<
"," << GetXaxis()->GetNbins();
190 out <<
"," << GetXaxis()->GetXmin()
191 <<
"," << GetXaxis()->GetXmax();
195 out <<
"," << GetYaxis()->GetXmin()
196 <<
"," << GetYaxis()->GetXmax();
197 out <<
"," << GetZaxis()->GetNbins() <<
");" << endl;
201 for (bin=0;bin<fNcells;bin++) {
202 double bc = GetBinContent(bin);
204 out<<
" "<<GetName()<<
"->SetBinContent("<<bin<<
","<<bc<<
");"<<endl;
210 for (bin=0;bin<fNcells;bin++) {
211 double be = GetBinError(bin);
213 out <<
" "<<GetName()<<
"->SetBinError("<<bin<<
","<<be<<
");"<<endl;
218 for (bin=0;bin<GetZaxis()->GetNbins();bin++) {
219 if (!(names[bin].IsNull()))
220 out <<
" "<<GetName()<<
"->Rebin(" << bin <<
","
221 << quote << names[bin] << quote <<
");" << endl;
224 TH1::SavePrimitiveHelp(out, option);