00001
00002
00003
00004
00005
00007
00008 #ifdef __HP_aCC
00009 #include <Stiostream.h>
00010 #else
00011 #include "Stiostream.h"
00012 #endif
00013 #include "StMultiH2F.h"
00014 #include "TString.h"
00015 #include "TLegend.h"
00016 #include "TPad.h"
00017 #include "TDirectory.h"
00018
00019 ClassImp(StMultiH2F)
00020
00021 StMultiH2F::StMultiH2F() {}
00022
00023 StMultiH2F::StMultiH2F(const char *name,const char *title,Int_t nbinsx,
00024 Axis_t xlow,Axis_t xup,Int_t nbinsy,Axis_t ylow,
00025 Axis_t yup,Int_t nbinsz) :
00026 TH3F(name,title,nbinsx,xlow,xup,nbinsy,ylow,yup,nbinsz,-0.5,-0.5+nbinsz) {}
00027
00028 void StMultiH2F::Draw(Option_t *option) {
00029
00030
00031 TAxis* axisX = GetXaxis();
00032 TAxis* axisY = GetYaxis();
00033 Int_t x0 = axisX->GetFirst();
00034 Int_t x1 = axisX->GetLast();
00035 Int_t y0 = axisY->GetFirst();
00036 Int_t y1 = axisY->GetLast();
00037 axisX->SetRange();
00038 axisY->SetRange();
00039 Int_t zbins = GetNbinsZ();
00040 if (zbins == 1) {
00041 TH2D* temp0 = XYProjection(GetName());
00042 temp0->SetStats((!TestBit(kNoStats)));
00043 TAxis* taxisX = temp0->GetXaxis();
00044 TAxis* taxisY = temp0->GetYaxis();
00045 axisX->Copy(*taxisX);
00046 axisY->Copy(*taxisY);
00047 taxisX->SetRange(x0,x1);
00048 taxisY->SetRange(y0,y1);
00049 axisX->SetRange(x0,x1);
00050 axisY->SetRange(y0,y1);
00051 temp0->Draw(option);
00052 return;
00053 }
00054
00055
00056
00057
00058
00059 TLegend *legend = new TLegend(0.80,0.84,0.98,0.98,"Legend","NDC");
00060 legend->SetFillColor(0);
00061 legend->SetFillStyle(0);
00062 legend->SetMargin(0.25);
00063
00064 Int_t zbin;
00065 Double_t maxval = -999999.;
00066 Int_t maxbin = -1;
00067
00068
00069 TH2D** temp = new TH2D*[zbins];
00070
00071 TString n0;
00072 for (zbin=0; zbin<zbins; zbin++) {
00073 if ((zbin >= 10) || (names[zbin].IsNull())) n0 = GetName();
00074 else n0 = names[zbin];
00075 Int_t slice = zbin+1;
00076 temp[zbin] = XYProjection(n0.Data(),slice);
00077 temp[zbin]->SetLineColor(60+40*(zbin/(zbins-1)));
00078 temp[zbin]->SetStats(kFALSE);
00079 TAxis* taxisX = temp[zbin]->GetXaxis();
00080 TAxis* taxisY = temp[zbin]->GetYaxis();
00081 axisX->Copy(*taxisX);
00082 axisY->Copy(*taxisY);
00083 taxisX->SetRange(x0,x1);
00084 taxisY->SetRange(y0,y1);
00085
00086 Double_t binmax = temp[zbin]->GetMaximum();
00087 if (binmax > maxval) {
00088 maxval = binmax;
00089 maxbin = zbin;
00090 }
00091 legend->AddEntry(temp[zbin],n0.Data(),"l");
00092 }
00093
00094 temp[maxbin]->SetTitle(GetTitle());
00095 temp[maxbin]->Draw(option);
00096 TString sameoption = option; sameoption += "same";
00097 for (zbin=0; zbin<zbins; zbin++) {
00098 if (zbin != maxbin) temp[zbin]->Draw(sameoption.Data());
00099 }
00100
00101
00102 if (!TestBit(kNoStats)) {
00103 temp[0] = XYProjection(GetName());
00104 temp[0]->Reset();
00105 temp[0]->SetEntries(GetEntries());
00106 temp[0]->SetStats(kTRUE);
00107 temp[0]->Draw(sameoption.Data());
00108 legend->SetX1(0.59);
00109 legend->SetX2(0.77);
00110 }
00111
00112 legend->Draw();
00113
00114 axisX->SetRange(x0,x1);
00115 axisY->SetRange(y0,y1);
00116 }
00117
00118 TH2D* StMultiH2F::XYProjection(const char* name, Int_t zbin) {
00119 static char buf[256];
00120 if (zbin<0) sprintf(buf,"%s.",name);
00121 else sprintf(buf,"%s_%d_%s",GetName(),zbin,name);
00122
00123 TList* tgList = gDirectory->GetList();
00124 TH2D* temp = (TH2D*) tgList->FindObject(buf);
00125 if (temp) tgList->Remove(temp);
00126
00127 if (zbin<0) GetZaxis()->SetRange();
00128 else GetZaxis()->SetRange(zbin,zbin);
00129 temp = (TH2D*) Project3D("yx");
00130 temp->SetName(buf);
00131 TAttLine::Copy(*temp);
00132 TAttFill::Copy(*temp);
00133 TAttMarker::Copy(*temp);
00134 temp->GetXaxis()->SetRange(GetXaxis()->GetFirst(),GetXaxis()->GetLast());
00135 temp->GetYaxis()->SetRange(GetYaxis()->GetFirst(),GetYaxis()->GetLast());
00136 return temp;
00137 }
00138
00139 void StMultiH2F::SavePrimitive(ostream& out, Option_t* option) {
00140
00141
00142 Bool_t nonEqiX = kFALSE;
00143 Bool_t nonEqiY = kFALSE;
00144 Int_t i;
00145
00146
00147
00148 if (GetXaxis()->GetXbins()->fN && GetXaxis()->GetXbins()->fArray) {
00149 nonEqiX = kTRUE;
00150 out << " Double_t xAxis[" << GetXaxis()->GetXbins()->fN
00151 << "] = {";
00152 for (i = 0; i < GetXaxis()->GetXbins()->fN; i++) {
00153 if (i != 0) out << ", ";
00154 out << GetXaxis()->GetXbins()->fArray[i];
00155 }
00156 out << "}; " << endl;
00157 }
00158
00159
00160
00161 if (GetYaxis()->GetXbins()->fN && GetYaxis()->GetXbins()->fArray) {
00162 nonEqiY = kTRUE;
00163 out << " Double_t yAxis[" << GetYaxis()->GetXbins()->fN
00164 << "] = {";
00165 for (i = 0; i < GetYaxis()->GetXbins()->fN; i++) {
00166 if (i != 0) out << ", ";
00167 out << GetYaxis()->GetXbins()->fArray[i];
00168 }
00169 out << "}; " << endl;
00170 }
00171
00172 char quote = '"';
00173 out <<" "<<endl;
00174 out <<" TH1 *" << GetName() << " = new " << ClassName() << "("
00175 << quote << GetName() << quote << "," << quote << GetTitle() << quote
00176 << "," << GetXaxis()->GetNbins();
00177 if (nonEqiX)
00178 out << ", xAxis";
00179 else
00180 out << "," << GetXaxis()->GetXmin()
00181 << "," << GetXaxis()->GetXmax();
00182 if (nonEqiX)
00183 out << ", yAxis";
00184 else
00185 out << "," << GetYaxis()->GetXmin()
00186 << "," << GetYaxis()->GetXmax();
00187 out << "," << GetZaxis()->GetNbins() << ");" << endl;
00188
00189
00190 Int_t bin;
00191 for (bin=0;bin<fNcells;bin++) {
00192 Double_t bc = GetBinContent(bin);
00193 if (bc) {
00194 out<<" "<<GetName()<<"->SetBinContent("<<bin<<","<<bc<<");"<<endl;
00195 }
00196 }
00197
00198
00199 if (fSumw2.fN) {
00200 for (bin=0;bin<fNcells;bin++) {
00201 Double_t be = GetBinError(bin);
00202 if (be) {
00203 out <<" "<<GetName()<<"->SetBinError("<<bin<<","<<be<<");"<<endl;
00204 }
00205 }
00206 }
00207
00208 for (bin=0;bin<GetZaxis()->GetNbins();bin++) {
00209 if (!(names[bin].IsNull()))
00210 out <<" "<<GetName()<< "->Rebin(" << bin << ","
00211 << quote << names[bin] << quote << ");" << endl;
00212 }
00213
00214 TH1::SavePrimitiveHelp(out, option);
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234