Exemplo n.º 1
0
//______________________________________________________________________________
TTree* toTree(THnSparse* h)
{
   // Creates a TTree and fills it with the coordinates of all
   // filled bins. The tree will have one branch for each dimension,
   // and one for the bin content.

   Int_t dim = h->GetNdimensions();
   TString name(h->GetName()); name += "_tree";
   TString title(h->GetTitle()); title += " tree";

   TTree* tree = new TTree(name, title);
   Double_t* x = new Double_t[dim + 1];
   memset(x, 0, sizeof(Double_t) * (dim + 1));

   TString branchname;
   for (Int_t d = 0; d < dim; ++d) {
      if (branchname.Length())
         branchname += ":";
      TAxis* axis = h->GetAxis(d);
      branchname += axis->GetName();
      branchname += "/D";
   }
   tree->Branch("coord", x, branchname);
   tree->Branch("bincontent", &x[dim], "bincontent/D");

   Int_t *bins = new Int_t[dim];
   for (Long64_t i = 0; i < h->GetNbins(); ++i) {
      x[dim] = h->GetBinContent(i, bins);
      for (Int_t d = 0; d < dim; ++d) {
         x[d] = h->GetAxis(d)->GetBinCenter(bins[d]);
      }

      tree->Fill();
   }

   delete [] bins;
   //delete [] x;
   return tree;
}
Exemplo n.º 2
0
	virtual void PaintBarH(Option_t * option)
	{
		/**
		Copied from https://root.cern.ch/root/html/src/THistPainter.cxx.html#s5vHLC
		Added option ("RTOL") to draw histograms from right to left
		*/
		Int_t nch = strlen(option)+1;
		char choption[nch];
		strlcpy(choption,option,nch);
		for (Int_t i=0;i<nch;i++) choption[i] = toupper(choption[i]);
		
		bool inverseHorizontally = strstr(choption, "RTOL");
		if (! inverseHorizontally) {
			THistPainter::PaintBarH(option);
		}
		else {
			/* Begin_html
			<a href="#HP10">Draw a bar char in a rotated pad (X vertical, Y horizontal).</a>
			End_html */

			gPad->SetVertical(kFALSE);

			PaintInitH();

			TAxis *xaxis = fXaxis;
			TAxis *yaxis = fYaxis;
			if (!strcmp(xaxis->GetName(),"xaxis")) {
				fXaxis = yaxis;
				fYaxis = xaxis;
			}

			PaintFrame();

			Int_t bar = 0;//Hoption.Bar - 20;
			Double_t xmin,xmax,ymin,ymax,umin,umax,w;
			Double_t offset = fH->GetBarOffset();
			Double_t width  = fH->GetBarWidth();
			TBox box;
			Int_t hcolor = fH->GetFillColor();
			if (hcolor == gPad->GetFrameFillColor()) ++hcolor;
			Int_t hstyle = fH->GetFillStyle();
			box.SetFillColor(hcolor);
			box.SetFillStyle(hstyle);
			for (Int_t bin=fYaxis->GetFirst();bin<=fYaxis->GetLast();bin++) {
				ymin = gPad->YtoPad(fYaxis->GetBinLowEdge(bin));
				ymax = gPad->YtoPad(fYaxis->GetBinUpEdge(bin));
				xmin = (inverseHorizontally ? -gPad->XtoPad(fH->GetBinContent(bin)) : gPad->GetUxmin());
				xmax = (inverseHorizontally ? gPad->GetUxmax() : gPad->XtoPad(fH->GetBinContent(bin)));
				if (xmax < gPad->GetUxmin()) continue;
				if (xmax > gPad->GetUxmax()) xmax = gPad->GetUxmax();
				if (xmin < gPad->GetUxmin()) xmin = gPad->GetUxmin();
				if (gStyle->GetHistMinimumZero() && xmin < 0)
					xmin=TMath::Min(0.,gPad->GetUxmax());
				w = (ymax-ymin)*width;
				ymin += offset*(ymax-ymin);
				ymax = ymin + w;
				if (bar < 1) {
					box.PaintBox(xmin,ymin,xmax,ymax);
				} else {
					umin = ymin + bar*(ymax-ymin)/10.;
					umax = ymax - bar*(ymax-ymin)/10.;
					box.SetFillColor(TColor::GetColorDark(hcolor)); //dark
					box.PaintBox(xmin,ymin,xmax,umin);
					box.SetFillColor(hcolor);
					box.PaintBox(xmin,umin,xmax,umax);
					box.SetFillColor(TColor::GetColorBright(hcolor)); //bright
					box.PaintBox(xmin,umax,xmax,ymax);
				}
			}

			PaintTitle();
			// Draw box with histogram statistics and/or fit parameters
			if (false) {
			//if (Hoption.Same != 1 && !fH->TestBit(TH1::kNoStats)) {  // bit set via TH1::SetStats
				TIter next(fFunctions);
				TObject *obj = 0;
				while ((obj = next())) {
					if (obj->InheritsFrom(TF1::Class())) break;
					obj = 0;
				}
				PaintStat(gStyle->GetOptStat(),(TF1*)obj);
			}

			PaintAxis(kFALSE);
			fXaxis = xaxis;
			fYaxis = yaxis;
		}
	}