Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5D scatter plot #17185

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions hist/hist/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Hist
TGraphSmooth.h
TGraphTime.h
TScatter.h
TScatter2D.h
TH1C.h
TH1D.h
TH1F.h
Expand Down Expand Up @@ -136,6 +137,7 @@ ROOT_STANDARD_LIBRARY_PACKAGE(Hist
TGraphSmooth.cxx
TGraphTime.cxx
TScatter.cxx
TScatter2D.cxx
TH1.cxx
TH1K.cxx
TH1Merger.cxx
Expand Down
1 change: 1 addition & 0 deletions hist/hist/inc/LinkDef.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#pragma link C++ class TGraphMultiErrors+;
#pragma link C++ class TGraphBentErrors+;
#pragma link C++ class TScatter+;
#pragma link C++ class TScatter2D+;
#pragma link C++ class TGraph2D-;
#pragma link C++ class TGraph2DErrors-;
#pragma link C++ class TGraph2DAsymmErrors-;
Expand Down
1 change: 1 addition & 0 deletions hist/hist/inc/TGraph2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ class TGraph2D : public TNamed, public TAttLine, public TAttFill, public TAttMar
virtual void Apply(TF2 *f);
void Browse(TBrowser *) override;
void Clear(Option_t *option="") override;
virtual void ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const;
virtual void DirectoryAutoAdd(TDirectory *);
Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
void Draw(Option_t *option="P0") override;
Expand Down
75 changes: 75 additions & 0 deletions hist/hist/inc/TScatter2D.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// @(#)root/hist:$Id$
// Author: Olivier Couet 03/12/2024

/*************************************************************************
* Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/

#ifndef ROOT_TScatter2D
#define ROOT_TScatter2D


//////////////////////////////////////////////////////////////////////////
// //
// TScatter2D //
// //
// A scatter plot able to draw five variables on a single plot //
// //
//////////////////////////////////////////////////////////////////////////

#include "TNamed.h"
#include "TAttLine.h"
#include "TAttFill.h"
#include "TAttMarker.h"
#include "TGraph2D.h"

class TH3F;

class TScatter2D : public TNamed, public TAttLine, public TAttFill, public TAttMarker {

protected:
Int_t fNpoints{-1}; ///< Number of points of arrays fX, fY and fZ
TH3F *fHistogram{nullptr}; ///< Pointer to histogram used for drawing axis
TGraph2D *fGraph{nullptr}; ///< Pointer to graph holding X, Y and Z positions
Double_t *fColor{nullptr}; ///< [fNpoints] array of colors
Double_t *fSize{nullptr}; ///< [fNpoints] array of marker sizes
Double_t fMaxMarkerSize{5.}; ///< Largest marker size used to paint the markers
Double_t fMinMarkerSize{1.}; ///< Smallest marker size used to paint the markers
Double_t fMargin{.1}; ///< Margin around the plot in %

public:
TScatter2D();
TScatter2D(Int_t n);
TScatter2D(Int_t n, Double_t *x, Double_t *y, Double_t *z, const Double_t *col = nullptr, const Double_t *size = nullptr);
~TScatter2D() override;

Int_t DistancetoPrimitive(Int_t px, Int_t py) override;
void ExecuteEvent(Int_t event, Int_t px, Int_t py) override;
Double_t *GetColor() const {return fColor;} ///< Get the array of colors
Double_t *GetSize() const {return fSize;} ///< Get the array of marker sizes
Double_t GetMargin() const {return fMargin;} ///< Set the margin around the plot in %
Double_t GetMaxMarkerSize() const {return fMaxMarkerSize;} ///< Get the largest marker size used to paint the markers
Double_t GetMinMarkerSize() const {return fMinMarkerSize;} ///< Get the smallest marker size used to paint the markers
TGraph2D *GetGraph() const {return fGraph;} ///< Get the graph holding X, Y and Z positions
TH3F *GetHistogram() const; ///< Get the graph histogram used for drawing axis
TAxis *GetXaxis() const ;
TAxis *GetYaxis() const ;
TAxis *GetZaxis() const ;

void SetMaxMarkerSize(Double_t max) {fMaxMarkerSize = max;} ///< Set the largest marker size used to paint the markers
void SetMinMarkerSize(Double_t min) {fMinMarkerSize = min;} ///< Set the smallest marker size used to paint the markers
void SetMargin(Double_t);
void SetHistogram(TH3F *h) {fHistogram = h;}
void Print(Option_t *chopt="") const override;
void SavePrimitive(std::ostream &out, Option_t *option = "") override;
void Paint(Option_t *chopt="") override;


ClassDefOverride(TScatter2D,1) //A 2D scatter plot
};
#endif

3 changes: 3 additions & 0 deletions hist/hist/inc/TVirtualGraphPainter.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
#include "TObject.h"

class TGraph;
class TGraph2D;
class TScatter;
class TScatter2D;
class TF1;

class TVirtualGraphPainter : public TObject {
Expand All @@ -42,6 +44,7 @@ class TVirtualGraphPainter : public TObject {
virtual void PaintGraph(TGraph *theGraph, Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt) = 0;
virtual void PaintGrapHist(TGraph *theGraph, Int_t npoints, const Double_t *x, const Double_t *y, Option_t *chopt) = 0;
virtual void PaintScatter(TScatter *theScatter, Option_t *option) = 0;
virtual void PaintScatter(TScatter2D *theScatter, Option_t *option) = 0;
virtual void PaintStats(TGraph *theGraph, TF1 *fit) = 0;
virtual void SetHighlight(TGraph *theGraph) = 0;

Expand Down
34 changes: 34 additions & 0 deletions hist/hist/src/TGraph2D.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1781,3 +1781,37 @@ void TGraph2D::Streamer(TBuffer &b)
b.WriteClassBuffer(TGraph2D::Class(), this);
}
}

////////////////////////////////////////////////////////////////////////////////
/// Compute the x/y/z range of the points in this graph

void TGraph2D::ComputeRange(Double_t &xmin, Double_t &ymin, Double_t &zmin, Double_t &xmax, Double_t &ymax, Double_t &zmax) const
{
if (fNpoints <= 0) {
xmin = xmax = ymin = ymax = zmin = zmax = 0;
return;
}
xmin = xmax = fX[0];
ymin = ymax = fY[0];
zmin = zmax = fZ[0];

Double_t xminl = 0; // Positive minimum. Used in case of log scale along X axis.
Double_t yminl = 0; // Positive minimum. Used in case of log scale along Y axis.
Double_t zminl = 0; // Positive minimum. Used in case of log scale along Z axis.

for (Int_t i = 1; i < fNpoints; i++) {
if (fX[i] < xmin) xmin = fX[i];
if (fX[i] > xmax) xmax = fX[i];
if (fY[i] < ymin) ymin = fY[i];
if (fY[i] > ymax) ymax = fY[i];
if (fZ[i] < zmin) zmin = fZ[i];
if (fZ[i] > zmax) zmax = fZ[i];
if (zmin>0 && (zminl==0 || zmin<zminl)) zminl = zmin;
if (ymin>0 && (yminl==0 || ymin<yminl)) yminl = ymin;
if (xmin>0 && (xminl==0 || xmin<xminl)) xminl = xmin;
}

if (gPad && gPad->GetLogz() && zminl>0) zmin = zminl;
if (gPad && gPad->GetLogy() && yminl>0) ymin = yminl;
if (gPad && gPad->GetLogx() && xminl>0) xmin = xminl;
}
9 changes: 1 addition & 8 deletions hist/hist/src/TScatter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,12 @@
#include "TROOT.h"
#include "TBuffer.h"
#include "TScatter.h"
#include "TStyle.h"
#include "TMath.h"
#include "TVirtualPad.h"
#include "TH2.h"
#include "TVirtualGraphPainter.h"
#include "strtok.h"

#include <iostream>
#include <fstream>
#include <cstring>
#include <string>

ClassImp(TScatter);

Expand Down Expand Up @@ -83,8 +78,6 @@ TScatter::TScatter(Int_t n)

////////////////////////////////////////////////////////////////////////////////
/// TScatter normal constructor.
///
/// if ex or ey are null, the corresponding arrays are preset to zero

TScatter::TScatter(Int_t n, const Double_t *x, const Double_t *y, const Double_t *col, const Double_t *size)
{
Expand Down Expand Up @@ -167,7 +160,7 @@ TH2F *TScatter::GetHistogram() const
{
if (!fHistogram) {
// do not add the histogram to gDirectory
// use local TDirectory::TContect that will set temporarly gDirectory to a nullptr and
// use local TDirectory::TContext that will set temporarly gDirectory to a nullptr and
// will avoid that histogram is added in the global directory
TDirectory::TContext ctx(nullptr);
double rwxmin, rwymin, rwxmax, rwymax;
Expand Down
Loading
Loading