void ZOffset3D( TH3* h, float z0) { // This boosts the height for each bin of a histogram by a given constant value of z int nbinx = h->GetNbinsX(); int nbiny = h->GetNbinsY(); int nbinz = h->GetNbinsZ(); for (int i=1; i<=nbinx; i++) { for (int j=1; j<=nbiny; j++) { for (int k=1; k<=nbinz; k++) { int h0=(h->GetBinContent(i,j,k)); if (h0>0){h->SetBinContent(i,j,k,z0+h0);} } } } h->SetMinimum(0); } void NewPalette(int top, int z0,int MaxCol, int MinCol){ Int_t palette[top]; int q0; int co; for (int qq=0;qq=z0){ // Set the rest of the values between MinCol and Max co= (MinCol+(MaxCol-MinCol)*q0*pow(top-z0,-1)); palette[qq]=co; } } gStyle->SetPalette(top,palette); } void Many3DHistograms(int Nc, int N){ // Nc is the number of "layers" I want, N is the ammount of bins on each axis per layer TCanvas * c16 = new TCanvas("c16","c16",600,400); gStyle->SetCanvasPreferGL(true); gStyle->SetOptStat(kFALSE); // Bins for the histograms Float_t Xh[N+1],Yh[N+1],Zh[2*Nc]; int cc2=0; int Z[Nc]; //The distances between histograms for (int cc=0;ccRndm()); int y1=N*(gRandom->Rndm()); int xL=N*(gRandom->Rndm()); int yL=N*(gRandom->Rndm()); int z1=Z[0]-5; int zL=Z[Nc-1]+5; int elem=1+Nc; // Ri (i=x,y,z) contains all lines float Rx[2*elem],Ry[2*elem],Rz[2*elem]; Rx[0]=x1; Rx[2*elem-1]=xL; Ry[0]=y1; Ry[2*elem-1]=yL; Rz[0]=z1; Rz[2*elem-1]=zL; float sloped, slopeu; // sloped is the slope for the lines below each layer, and slopeu is for the one on top of each layer // It'll be the same for all the objects ending with "-d" (for down) or "-u" (for up). // I'll fill all the Ri lists int ee2=1; for (int ee=0;eeRndm()); yc=N*(gRandom->Rndm()); hc->Fill(xc,yc,zc); } // To make the straight lines, two per layer. float Rxd[2]={Rx[ind],Rx[ind+1]}; float Rxu[2]={Rx[ind+2],Rx[ind+3]}; float Ryd[2]={Ry[ind],Ry[ind+1]}; float Ryu[2]={Ry[ind+2],Ry[ind+3]}; float Rzd[2]={Rz[ind],Rz[ind+1]}; float Rzu[2]={Rz[ind+2],Rz[ind+3]}; // cout<<"Down: "<SetLineColor(kRed); gd->SetLineWidth(7); gu->SetLineColor(kRed); gu->SetLineWidth(7); // "Offset in volume" for the histogram ZOffset3D(hc, 100); // Drawing the histograms and lines. if (c==0){ int T=hc->GetMaximum(); NewPalette(T, 100,19,12); //greys, works great gd->Draw(); hc->Draw("box2z fb same"); gu->Draw("same"); } else{ gd->Draw("same"); hc->Draw("box2 fb same"); gu->Draw("same"); } c16->Modified(); } } int N=10; int Nc=3; Many3DHistograms(Nc,N);