From ba46ac77ebd1dd8adfa30b77e1225501a470ef4e Mon Sep 17 00:00:00 2001
From: Matevz Tadel <matevz.tadel@cern.ch>
Date: Wed, 4 Jun 2008 19:32:56 +0000
Subject: [PATCH] - TEveCalo-classes:   Add possibility to plot E/Et values and
 enable absolute/relative   scaling.

- TEveUtil:
  Add utility functions to check if a phi interval lies within or
  overlaps with another interval taking into account the U(1)
  wrap-around.


git-svn-id: http://root.cern.ch/svn/root/trunk@24146 27541ba8-7e3a-0410-8455-c3a389f83636
---
 graf3d/eve/inc/TEveCalo.h             |  46 ++++----
 graf3d/eve/inc/TEveCaloData.h         |  10 +-
 graf3d/eve/inc/TEveCaloVizEditor.h    |  19 +++-
 graf3d/eve/inc/TEveUtil.h             |  24 ++++
 graf3d/eve/src/TEveCalo.cxx           |  91 ++++++++++------
 graf3d/eve/src/TEveCalo2DGL.cxx       |  71 ++++++------
 graf3d/eve/src/TEveCalo3DGL.cxx       |   7 +-
 graf3d/eve/src/TEveCaloData.cxx       | 105 ++++++++++--------
 graf3d/eve/src/TEveCaloLegoEditor.cxx |  17 +--
 graf3d/eve/src/TEveCaloLegoGL.cxx     |  49 +++++----
 graf3d/eve/src/TEveCaloVizEditor.cxx  | 151 ++++++++++++++++++++++----
 graf3d/eve/src/TEveLegoOverlay.cxx    |   2 +-
 graf3d/eve/src/TEveUtil.cxx           |  56 +++++++++-
 tutorials/eve/cms_calo.C              |  29 +----
 14 files changed, 434 insertions(+), 243 deletions(-)

diff --git a/graf3d/eve/inc/TEveCalo.h b/graf3d/eve/inc/TEveCalo.h
index 6379b5c71d7..2fd231d7e9c 100644
--- a/graf3d/eve/inc/TEveCalo.h
+++ b/graf3d/eve/inc/TEveCalo.h
@@ -47,10 +47,11 @@ protected:
    Float_t       fBarrelRadius;  // barrel raidus in cm
    Float_t       fEndCapPos;     // end cap z coordinate in cm
 
-   Float_t       fCellZScale;
+   Float_t       fPlotEt;
 
-   Bool_t        fUseExternalZMax;
-   Float_t       fExternalZMax;
+   Float_t           fMaxTowerH;
+   Bool_t            fScaleAbs;
+   Float_t           fMaxValAbs;
 
    Bool_t            fValueIsColor;   // Interpret signal value as RGBA color.
    TEveRGBAPalette*  fPalette;        // Pointer to signal-color palette.
@@ -61,30 +62,31 @@ protected:
 
    void SetupColorHeight(Float_t value, Int_t slice, Float_t& height, Bool_t &viz) const;
 
+   virtual Float_t GetValToHeight() const;
+
 public:
    TEveCaloViz(const Text_t* n="TEveCaloViz", const Text_t* t="");
    TEveCaloViz(TEveCaloData* data, const Text_t* n="TEveCaloViz", const Text_t* t="");
 
    virtual ~TEveCaloViz();
 
-   void InvalidateCache() { fCacheOK = kFALSE; ResetBBox(); }
-
    TEveCaloData* GetData() const { return fData; }
    virtual void  SetData(TEveCaloData* d);
 
    Float_t GetBarrelRadius() const { return fBarrelRadius; }
-   void SetBarrelRadius(Float_t r) { fBarrelRadius = r; ResetBBox(); }
+   void    SetBarrelRadius(Float_t r) { fBarrelRadius = r; ResetBBox(); }
    Float_t GetEndCapPos   () const { return fEndCapPos; }
-   void SetEndCapPos   (Float_t z) { fEndCapPos = z; ResetBBox(); }
-
-   virtual void    SetCellZScale(Float_t s) { fCellZScale = s; ResetBBox(); }
-   virtual Float_t GetDefaultCellHeight() const { return fBarrelRadius*fCellZScale; }
+   void    SetEndCapPos   (Float_t z) { fEndCapPos = z; ResetBBox(); }
 
-   void    SetUseExternalZMax(Bool_t x) { fUseExternalZMax = x; }
-   Bool_t  GetUseExternalZMax() const { return fUseExternalZMax; }
+   Bool_t  GetPlotEt() const { return fPlotEt; }
+   virtual void    SetPlotEt(Bool_t x);
 
-   void    SetExternalZMax(Float_t val) { fExternalZMax = val; }
-   Float_t GetExternalZMax() const { return fExternalZMax; }
+   void    SetMaxTowerH(Float_t x) { fMaxTowerH = x; }
+   Float_t GetMaxTowerH() const    { return fMaxTowerH; }
+   void    SetScaleAbs(Bool_t x) { fScaleAbs = x; }
+   Bool_t  GetScaleAbs() const { return fScaleAbs; }
+   void    SetMaxValAbs(Float_t x) { fMaxValAbs = x; }
+   Float_t GetMaxValAbs() const    { return fMaxValAbs; }
 
    Float_t GetTransitionEta() const;
    Float_t GetTransitionTheta() const;
@@ -108,8 +110,8 @@ public:
    Float_t GetPhiMax() const {return fPhi+fPhiOffset;}
    Float_t GetPhiRng() const {return fPhiOffset*2;}
 
-
    virtual void ResetCache() = 0;
+   void InvalidateCache() { fCacheOK=kFALSE; ResetBBox(); } // compute bbox
 
    virtual void Paint(Option_t* option="");
 
@@ -132,8 +134,8 @@ protected:
    TEveCaloData::vCellId_t fCellList;
 
 public:
-   TEveCalo3D(const Text_t* n="TEveCalo3D", const Text_t* t=""):TEveCaloViz(n, t){ fCellZScale = 0.2;}
-   TEveCalo3D(TEveCaloData* data): TEveCaloViz(data) { SetElementName("TEveCalo3D"); fCellZScale = 0.2;}
+   TEveCalo3D(const Text_t* n="TEveCalo3D", const Text_t* t=""):TEveCaloViz(n, t){}
+   TEveCalo3D(TEveCaloData* data): TEveCaloViz(data) { SetElementName("TEveCalo3D");}
    virtual ~TEveCalo3D() {}
    virtual void ComputeBBox();
 
@@ -226,8 +228,8 @@ public:
    UChar_t  GetPlaneTransparency() const { return fPlaneTransparency; }
    void     SetPlaneTransparency(UChar_t t) { fPlaneTransparency=t; }
 
-   Int_t  GetNZSteps() const { return fNZSteps; }
-   void   SetNZSteps(Int_t s) { fNZSteps = s;}
+   Int_t    GetNZSteps() const { return fNZSteps; }
+   void     SetNZSteps(Int_t s) { fNZSteps = s;}
 
    Int_t    GetBinWidth() const { return fBinWidth; }
    void     SetBinWidth(Int_t bw) { fBinWidth = bw; }
@@ -241,14 +243,12 @@ public:
    void       SetBoxMode(EBoxMode_e p) { fBoxMode = p; }
    EBoxMode_e  GetBoxMode() { return fBoxMode; }
 
-   Bool_t GetDrawHPlane() const { return fDrawHPlane; }
-   void   SetDrawHPlane(Bool_t s) { fDrawHPlane = s;}
+   Bool_t   GetDrawHPlane() const { return fDrawHPlane; }
+   void     SetDrawHPlane(Bool_t s) { fDrawHPlane = s;}
 
    Float_t  GetHPlaneVal() const { return fHPlaneVal; }
    void     SetHPlaneVal(Float_t s) { fHPlaneVal = s;}
 
-   virtual Float_t GetDefaultCellHeight() const;
-
    virtual void ResetCache();
 
    virtual void ComputeBBox();
diff --git a/graf3d/eve/inc/TEveCaloData.h b/graf3d/eve/inc/TEveCaloData.h
index 20ac3781d68..72944b3b7a8 100644
--- a/graf3d/eve/inc/TEveCaloData.h
+++ b/graf3d/eve/inc/TEveCaloData.h
@@ -40,7 +40,7 @@ public:
       Float_t fValue;
       Float_t fPhiMin;
       Float_t fPhiMax;
-      Float_t fThetaMin;
+      Float_t fThetaMin;  // theta=0 on z axis
       Float_t fThetaMax;
       Float_t fEtaMin;
       Float_t fEtaMax;
@@ -49,7 +49,7 @@ public:
       CellData_t(): fValue(0), fPhiMin(0), fPhiMax(0), fThetaMin(0), fThetaMax(0), fZSideSign(1) {}
       void Configure(Float_t v, Float_t e1, Float_t e2, Float_t p1, Float_t p2);
 
-      Float_t Value()    const { return fValue;    }
+      Float_t Value(Bool_t)    const;
 
       Float_t EtaMin()   const { return fEtaMin; }
       Float_t EtaMax()   const { return fEtaMax; }
@@ -94,7 +94,7 @@ public:
 
    virtual Int_t GetNSlices() const = 0;
 
-   virtual Float_t  GetMaxVal() const = 0;
+   virtual Float_t  GetMaxVal(Bool_t et) const = 0;
 
    virtual void  GetEtaLimits(Double_t &min, Double_t &max) const=0;
    virtual void  GetPhiLimits(Double_t &min, Double_t &max) const=0;
@@ -121,6 +121,8 @@ private:
 
 protected:
    THStack*    fHStack;
+   Float_t     fMaxValEt; // cached
+   Float_t     fMaxValE;  // cached
 
 public:
    TEveCaloDataHist();
@@ -135,7 +137,7 @@ public:
 
    virtual Int_t GetNSlices() const;
 
-   virtual Float_t GetMaxVal() const;
+   virtual Float_t GetMaxVal(Bool_t et) const {return (et)? fMaxValEt:fMaxValE;}
    virtual void    GetEtaLimits(Double_t &min, Double_t &max) const;
    virtual void    GetPhiLimits(Double_t &min, Double_t &max) const;
 
diff --git a/graf3d/eve/inc/TEveCaloVizEditor.h b/graf3d/eve/inc/TEveCaloVizEditor.h
index 33d3fd5eb21..4f3dc883ae6 100644
--- a/graf3d/eve/inc/TEveCaloVizEditor.h
+++ b/graf3d/eve/inc/TEveCaloVizEditor.h
@@ -19,6 +19,8 @@ class TGDoubleHSlider;
 class TEveGValuator;
 class TEveGDoubleValuator;
 class TEveRGBAPaletteSubEditor;
+class TGCheckButton;
+class TGRadioButton;
 
 class TGVerticalFrame;
 
@@ -31,6 +33,13 @@ private:
 protected:
    TEveCaloViz               *fM; // Model object.
 
+   TGRadioButton             *fPlotE;
+   TGRadioButton             *fPlotEt;
+
+   TGCheckButton             *fScaleAbs;
+   TEveGValuator             *fMaxValAbs;
+   TEveGValuator             *fMaxTowerH;
+
    TEveGDoubleValuator       *fEtaRng;
    TEveGValuator             *fPhi;
    TEveGValuator             *fPhiOffset;
@@ -38,8 +47,6 @@ protected:
    TGVerticalFrame            *fTower;
    TEveRGBAPaletteSubEditor   *fPalette;        // Palette sub-editor.x
 
-   TEveGValuator              *fCellZScale;
-
 public:
    TEveCaloVizEditor(const TGWindow* p=0, Int_t width=170, Int_t height=30,
                      UInt_t options=kChildFrame, Pixel_t back=GetDefaultFrameBackground());
@@ -47,12 +54,18 @@ public:
 
    virtual void SetModel(TObject* obj);
 
+   void DoMaxTowerH();
+   void DoScaleAbs();
+   void DoMaxValAbs();
+
+   void DoPlot();
+
    void DoEtaRange();
    void DoPhi();
 
-   void DoCellZScale();
    void DoPalette();
 
+
    ClassDef(TEveCaloVizEditor, 0); // GUI editor for TEveCaloVizEditor.
 };
 
diff --git a/graf3d/eve/inc/TEveUtil.h b/graf3d/eve/inc/TEveUtil.h
index cdc17dc7833..fc11e9223e2 100644
--- a/graf3d/eve/inc/TEveUtil.h
+++ b/graf3d/eve/inc/TEveUtil.h
@@ -57,9 +57,33 @@ public:
 
    static const char* FormAxisValue(Float_t x);
 
+   // Math utilities
+
+   static Bool_t IsU1IntervalContainedByMinMax  (Float_t minM, Float_t maxM,
+                                                 Float_t minQ, Float_t maxQ);
+   static Bool_t IsU1IntervalOverlappingByMinMax(Float_t minM, Float_t maxM,
+                                                 Float_t minQ, Float_t maxQ);
+
+   static Bool_t IsU1IntervalContainedByMeanDelta  (Float_t meanM, Float_t deltaM, 
+                                                    Float_t meanQ, Float_t deltaQ);
+   static Bool_t IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
+                                                    Float_t meanQ, Float_t deltaQ);
+
    ClassDef(TEveUtil, 0); // Standard utility functions for Reve.
 };
 
+inline Bool_t TEveUtil::IsU1IntervalContainedByMeanDelta(Float_t meanM, Float_t deltaM,
+                                                         Float_t meanQ, Float_t deltaQ)
+{
+   return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
+}
+
+inline Bool_t TEveUtil::IsU1IntervalOverlappingByMeanDelta(Float_t meanM, Float_t deltaM,
+                                                             Float_t meanQ, Float_t deltaQ)
+{
+   return IsU1IntervalContainedByMinMax(meanM - deltaM, meanM + deltaM, meanQ - deltaQ, meanQ + deltaQ);
+}
+
 
 /******************************************************************************/
 // Exceptions, string functions
diff --git a/graf3d/eve/src/TEveCalo.cxx b/graf3d/eve/src/TEveCalo.cxx
index cc7bf5b8094..9b700001123 100644
--- a/graf3d/eve/src/TEveCalo.cxx
+++ b/graf3d/eve/src/TEveCalo.cxx
@@ -51,10 +51,11 @@ TEveCaloViz::TEveCaloViz(const Text_t* n, const Text_t* t) :
    fBarrelRadius(-1.f),
    fEndCapPos(-1.f),
 
-   fCellZScale(1.),
+   fPlotEt(kTRUE),
 
-   fUseExternalZMax(kFALSE),
-   fExternalZMax(1),
+   fMaxTowerH(100),
+   fScaleAbs(kFALSE),
+   fMaxValAbs(100),
 
    fValueIsColor(kTRUE),
    fPalette(0),
@@ -82,10 +83,11 @@ TEveCaloViz::TEveCaloViz(TEveCaloData* data, const Text_t* n, const Text_t* t) :
    fBarrelRadius(-1.f),
    fEndCapPos(-1.f),
 
-   fCellZScale(1.),
+   fPlotEt(kTRUE),
 
-   fUseExternalZMax(kFALSE),
-   fExternalZMax(1),
+   fMaxTowerH(100),
+   fScaleAbs(kFALSE),
+   fMaxValAbs(100),
 
    fValueIsColor(kTRUE),
    fPalette(0),
@@ -94,6 +96,7 @@ TEveCaloViz::TEveCaloViz(TEveCaloData* data, const Text_t* n, const Text_t* t) :
 {
    // Constructor.
 
+   SetElementName("TEveCaloViz");
    SetData(data);
 }
 
@@ -120,7 +123,18 @@ void TEveCaloViz::SetEta(Float_t l, Float_t u)
    InvalidateCache();
 }
 
- //______________________________________________________________________________
+//______________________________________________________________________________
+void TEveCaloViz::SetPlotEt(Bool_t isEt)
+{
+   // Set E/Et plot.
+
+  fPlotEt=isEt;
+  fPalette->SetLimits(0, TMath::CeilNint(fData->GetMaxVal(fPlotEt)));
+
+  InvalidateCache();
+}
+
+//______________________________________________________________________________
 void TEveCaloViz::SetPhiWithRng(Float_t phi, Float_t rng)
 {
    // Set phi range.
@@ -161,13 +175,15 @@ void TEveCaloViz::SetData(TEveCaloData* data)
    fData = data;
    if (fData) fData->IncRefCount();
 
-
    fData->GetEtaLimits(fEtaMin, fEtaMax);
    Double_t min, max;
    fData->GetPhiLimits(min, max);
    fPhi = (max+min)*0.5;
    fPhiOffset =(max-min)*0.5;
 
+   AssertPalette();
+   fPalette->SetLimits(0, TMath::CeilNint(data->GetMaxVal(fPlotEt)));
+
    InvalidateCache();
 }
 
@@ -205,6 +221,21 @@ void TEveCaloViz::SetPalette(TEveRGBAPalette* p)
    if (fPalette) fPalette->IncRefCount();
 }
 
+//______________________________________________________________________________
+Float_t TEveCaloViz::GetValToHeight() const
+{
+   // Get transformation factor from E/Et to height
+
+   if (fScaleAbs)
+   {
+      return fMaxTowerH/fMaxValAbs;
+   }
+   else
+   {
+      return fMaxTowerH/fData->GetMaxVal(fPlotEt);
+   }
+}
+
 //______________________________________________________________________________
 TEveRGBAPalette* TEveCaloViz::AssertPalette()
 {
@@ -214,9 +245,11 @@ TEveRGBAPalette* TEveCaloViz::AssertPalette()
 
    if (fPalette == 0) {
       fPalette = new TEveRGBAPalette;
+      fPalette->SetDefaultColor((Color_t)4);
    }
    return fPalette;
 }
+
 //______________________________________________________________________________
 void TEveCaloViz::Paint(Option_t* /*option*/)
 {
@@ -255,25 +288,22 @@ void TEveCaloViz::SetupColorHeight(Float_t value, Int_t slice,
 {
    // Set color and height for a given value and slice using TEveRGBAPalette.
 
-   Int_t val = (Int_t) value;
-   outH = GetDefaultCellHeight();
    Bool_t visible = kFALSE;
-
    if (fPalette->GetShowDefValue())
    {
       if (value > fPalette->GetMinVal() && value < fPalette->GetMaxVal())
       {
          TGLUtil::Color(fPalette->GetDefaultColor() + slice);
-         outH *= ((value -fPalette->GetMinVal())*fData->GetNSlices()
-                  / (fPalette->GetHighLimit() - fPalette->GetLowLimit()));
+         outH = GetValToHeight()*value;
          visible = kTRUE;
       }
    }
 
-   if (fPalette->GetShowDefValue() == kFALSE && fPalette->WithinVisibleRange(val))
+   if (fPalette->GetShowDefValue() == kFALSE && fPalette->WithinVisibleRange((Int_t)value))
    {
+      outH = GetValToHeight()*fData->GetMaxVal(fPlotEt);
       UChar_t c[4];
-      fPalette->ColorFromValue(val, c);
+      fPalette->ColorFromValue((Int_t)value, c);
       TGLUtil::Color4ubv(c);
       visible = kTRUE;
    }
@@ -303,7 +333,7 @@ void TEveCalo3D::ComputeBBox()
 
    BBoxInit();
 
-   Float_t th = GetDefaultCellHeight()*fData->GetNSlices();
+   Float_t th = GetValToHeight() * fData->GetMaxVal(fPlotEt);
 
    fBBox[0] = -fBarrelRadius - th;
    fBBox[1] =  fBarrelRadius + th;
@@ -373,7 +403,7 @@ void TEveCalo2D::ComputeBBox()
    BBoxZero();
 
    Float_t x, y, z;
-   Float_t th = GetDefaultCellHeight()*fData->GetNSlices();
+   Float_t th = GetValToHeight()*fData->GetMaxVal(fPlotEt);
    Float_t r  = fBarrelRadius + th;
    Float_t ze = fEndCapPos + th;
 
@@ -416,7 +446,7 @@ TEveCaloLego::TEveCaloLego(const Text_t* n, const Text_t* t):
    TEveCaloViz(n, t),
 
    fFontColor(0),
-   fGridColor(kGray+3),
+   fGridColor(kGray+2),
    fPlaneColor(kRed-5),
    fPlaneTransparency(60),
 
@@ -433,6 +463,7 @@ TEveCaloLego::TEveCaloLego(const Text_t* n, const Text_t* t):
 {
    // Constructor.
 
+   fMaxTowerH = 1;
    SetElementNameTitle("TEveCaloLego", "TEveCaloLego");
 }
 
@@ -441,7 +472,7 @@ TEveCaloLego::TEveCaloLego(TEveCaloData* data):
    TEveCaloViz(),
 
    fFontColor(0),
-   fGridColor(kGray+3),
+   fGridColor(kGray+2),
    fPlaneColor(kRed-5),
    fPlaneTransparency(60),
 
@@ -460,23 +491,11 @@ TEveCaloLego::TEveCaloLego(TEveCaloData* data):
 {
    // Constructor.
 
+   fMaxTowerH = 1;
    SetElementNameTitle("TEveCaloLego", "TEveCaloLego");
    SetData(data);
 }
 
-//______________________________________________________________________________
-Float_t TEveCaloLego::GetDefaultCellHeight() const
-{
-   // Get default cell height.
-
-   Float_t h = 10;
-
-   if (fUseExternalZMax)
-      h *= (fData->GetMaxVal()/fExternalZMax);
-
-   return h;
-}
-
 //______________________________________________________________________________
 void TEveCaloLego::ResetCache()
 {
@@ -499,7 +518,7 @@ void TEveCaloLego::ComputeBBox()
    {
       Float_t ex = 1.2;
 
-      Float_t a = 0.5*GetDefaultCellHeight()*ex;
+      Float_t a = 0.5*ex;
 
       fBBox[0] = -a; 
       fBBox[1] =  a;
@@ -522,8 +541,8 @@ void TEveCaloLego::ComputeBBox()
          fBBox[1] *= r; 
       }
 
-      fBBox[4] =  GetDefaultCellHeight()*fCellZScale*(1-ex);
-      fBBox[5] =  GetDefaultCellHeight()*fCellZScale*ex;
-   }
+      fBBox[4] =  fMaxTowerH*(1-ex);
+      fBBox[5] =  fMaxTowerH*ex;
+   } 
 }
 
diff --git a/graf3d/eve/src/TEveCalo2DGL.cxx b/graf3d/eve/src/TEveCalo2DGL.cxx
index b1421bcd164..d92de47228c 100644
--- a/graf3d/eve/src/TEveCalo2DGL.cxx
+++ b/graf3d/eve/src/TEveCalo2DGL.cxx
@@ -115,44 +115,28 @@ Float_t TEveCalo2DGL::MakeRPhiCell(Float_t phiMin, Float_t phiMax, Float_t tower
 //______________________________________________________________________________
 void TEveCalo2DGL::DrawRPhi(TGLRnrCtx & rnrCtx) const
 {
-  // Draw calorimeter cells in RPhi projection.
+   // Draw calorimeter cells in RPhi projection.
 
    TEveCaloData* data = fM->GetData();
-   const TAxis* ax = data->GetPhiBins();
 
    if (fM->fCacheOK == kFALSE) {
       fM->ResetCache();
-      Float_t eta = fM->GetEta();
-      Float_t etaRng = fM->GetEtaRng();
-      Float_t pr[4];
-      // calculate the two intervals when circle is cut
-      Float_t phi1 = fM->GetPhiMin();
-      Float_t phi2 = fM->GetPhiMax();
-      if (phi2 >Pi() && phi1<-Pi()) {
-         pr[0] =  phi1;
-         pr[1] =  Pi();
-         pr[2] =  -Pi();
-         pr[3] =  -TwoPi()+phi2;
-      }
-      else if (phi1<-Pi() && phi2<=Pi()) {
-         pr[0] = -Pi();
-         pr[1] =  phi2;
-         pr[2] =  TwoPi()+phi1;
-         pr[3] =  Pi();
-      } else {
-         pr[0] = pr[2] = phi1;
-         pr[1] = pr[3] = phi2;
-      }
 
-      Int_t nBins = ax->GetNbins();
-      for (Int_t ibin=1; ibin<=nBins; ibin++) {
-         if ( (   ax->GetBinLowEdge(ibin)>=pr[0] && ax->GetBinUpEdge(ibin)<pr[1])
-              || (ax->GetBinLowEdge(ibin)>=pr[2] && ax->GetBinUpEdge(ibin)<pr[3]))
+      const TAxis* ay = data->GetPhiBins();
+      Int_t nBins = ay->GetNbins();
+
+
+      for (Int_t ibin=1; ibin<=nBins; ibin++)
+      {
+         if (TEveUtil::IsU1IntervalOverlappingByMinMax(fM->GetPhiMin(), fM->GetPhiMax(), 
+                                                       ay->GetBinLowEdge(ibin), ay->GetBinUpEdge(ibin)))
          {
             TEveCaloData::vCellId_t* clv = new TEveCaloData::vCellId_t();
-            Int_t nc = data->GetCellList(fM->fPalette->GetMinVal(), fM->fPalette->GetMaxVal(),
-                                         eta, etaRng, fM->fPhi+ax->GetBinCenter(ibin), ax->GetBinWidth(ibin),*clv);
-            if (nc)
+
+            data->GetCellList(fM->fPalette->GetMinVal(), fM->fPalette->GetMaxVal(),
+                              fM->GetEta(), fM->GetEtaRng(), ay->GetBinCenter(ibin), ay->GetBinWidth(ibin),*clv);
+
+            if (clv->empty() == kFALSE) 
                fM->fCellLists.push_back(clv);
             else
                delete clv;
@@ -167,16 +151,20 @@ void TEveCalo2DGL::DrawRPhi(TGLRnrCtx & rnrCtx) const
    Float_t towerH;
    Bool_t visible;
    if (rnrCtx.SecSelection()) glPushName(0);
-   for(UInt_t vi=0; vi<fM->fCellLists.size(); vi++) {
+
+
+   for(UInt_t vi=0; vi<fM->fCellLists.size(); vi++)
+   {
       // reset values
       Float_t off = 0;
       for (Int_t s=0; s<nSlices; s++)
          sliceVal[s]=0;
+
       // loop through eta bins
       TEveCaloData::vCellId_t* cids = fM->fCellLists[vi];
       for (TEveCaloData::vCellId_i it = cids->begin(); it != cids->end(); it++) {
          data->GetCellData(*it, cellData);
-         sliceVal[(*it).fSlice] += cellData.Value();
+         sliceVal[(*it).fSlice] += cellData.Value(fM->fPlotEt);
       }
       // draw
       if (rnrCtx.SecSelection()) {
@@ -265,14 +253,19 @@ void TEveCalo2DGL::DrawRhoZ(TGLRnrCtx & rnrCtx) const
       fM->ResetCache();
       const TAxis* ax = data->GetEtaBins();
       Int_t nBins = ax->GetNbins();
-      for (Int_t ibin=1; ibin<=nBins; ibin++){
+
+      for (Int_t ibin=1; ibin<=nBins; ibin++)
+      {
          if (ax->GetBinLowEdge(ibin)>fM->fEtaMin && ax->GetBinUpEdge(ibin)<=fM->fEtaMax)
          {
             TEveCaloData::vCellId_t* aa = new TEveCaloData::vCellId_t();
             data->GetCellList(fM->fPalette->GetMinVal(), fM->fPalette->GetMaxVal(),
-                              fM->GetEta() + ax->GetBinCenter(ibin), ax->GetBinWidth(ibin),
-                              fM->fPhi, fM->fPhiOffset, *aa);
-            if (aa->size()) fM->fCellLists.push_back(aa);
+                              ax->GetBinCenter(ibin), ax->GetBinWidth(ibin)+1e-5,
+                              fM->fPhi, fM->GetPhiRng(), *aa);
+            if (aa->size())
+               fM->fCellLists.push_back(aa);
+            else 
+               delete aa;
          }
       }
       fM->fCacheOK= kTRUE;
@@ -301,9 +294,9 @@ void TEveCalo2DGL::DrawRhoZ(TGLRnrCtx & rnrCtx) const
       for (TEveCaloData::vCellId_i it = fM->fCellLists[vi]->begin(); it !=  fM->fCellLists[vi]->end(); it++) {
          data->GetCellData(*it, cellData);
          if (cellData.Phi() > 0)
-            sliceValsUp[(*it).fSlice]  += cellData.Value();
+            sliceValsUp[(*it).fSlice]  += cellData.Value(fM->fPlotEt);
          else
-            sliceValsLow[(*it).fSlice] += cellData.Value();
+            sliceValsLow[(*it).fSlice] += cellData.Value(fM->fPlotEt);
       }
 
       // draw
@@ -339,8 +332,6 @@ void TEveCalo2DGL::DirectDraw(TGLRnrCtx & rnrCtx) const
    TGLCapabilitySwitch light_off  (GL_LIGHTING,  kFALSE);
    TGLCapabilitySwitch culling_ogg(GL_CULL_FACE, kFALSE);
 
-   fM->AssertPalette();
-
    TEveProjection::EPType_e pt = fM->fManager->GetProjection()->GetType();
    if (pt == TEveProjection::kPT_RhoZ)
       DrawRhoZ(rnrCtx);
diff --git a/graf3d/eve/src/TEveCalo3DGL.cxx b/graf3d/eve/src/TEveCalo3DGL.cxx
index 2f53efc33e3..157d936299e 100644
--- a/graf3d/eve/src/TEveCalo3DGL.cxx
+++ b/graf3d/eve/src/TEveCalo3DGL.cxx
@@ -225,7 +225,8 @@ Float_t TEveCalo3DGL::RenderBarrelCell(const TEveCaloData::CellData_t &cellData,
 
    RenderBox(box);
 
-   return offset + towerH*sin1;
+   return offset + towerH*Sin(cellData.ThetaMin());
+
 }// end RenderBarrelCell
 
 //______________________________________________________________________________
@@ -301,8 +302,6 @@ void TEveCalo3DGL::DirectDraw(TGLRnrCtx &rnrCtx) const
 {
    // GL rendering.
 
-   fM->AssertPalette();
-
    if (fM->fCacheOK == kFALSE)
    {
       fM->ResetCache();
@@ -332,7 +331,7 @@ void TEveCalo3DGL::DirectDraw(TGLRnrCtx &rnrCtx) const
          offset = 0;
          prevTower = fM->fCellList[i].fTower;
       }
-      fM->SetupColorHeight(cellData.Value(), fM->fCellList[i].fSlice, towerH, visible);
+      fM->SetupColorHeight(cellData.Value(fM->fPlotEt), fM->fCellList[i].fSlice, towerH, visible);
       if (visible)
       {
          if (rnrCtx.SecSelection()) glLoadName(i);
diff --git a/graf3d/eve/src/TEveCaloData.cxx b/graf3d/eve/src/TEveCaloData.cxx
index 33529950c09..560876ef042 100644
--- a/graf3d/eve/src/TEveCaloData.cxx
+++ b/graf3d/eve/src/TEveCaloData.cxx
@@ -33,6 +33,16 @@ TEveCaloData::TEveCaloData():TEveRefCnt(),
 
 }
 
+//______________________________________________________________________________
+Float_t TEveCaloData::CellData_t::Value(Bool_t isEt) const
+{
+   if (isEt)
+      return fValue;
+   else
+     return TMath::Abs(fValue/TMath::Cos(Theta()));
+
+}
+
 //______________________________________________________________________________
 void TEveCaloData::CellData_t::Configure(Float_t v, Float_t e1, Float_t e2, Float_t p1, Float_t p2)
 {
@@ -68,9 +78,9 @@ void TEveCaloData::CellData_t::Dump() const
 {
   // Print member data.
 
-   printf(">> theta %2.1f phi %2.1f val %2.2f \n",
+   printf(">> theta %2.1f phi %2.1f Et %2.2f E  %2.2f \n",
           Theta()*TMath::RadToDeg(),
-          Phi()*TMath::RadToDeg(), Value());
+          Phi()*TMath::RadToDeg(), Value(kFALSE), Value(kTRUE));
 }
 
 //______________________________________________________________________________
@@ -82,7 +92,10 @@ void TEveCaloData::CellData_t::Dump() const
 ClassImp(TEveCaloDataHist);
 
 
-TEveCaloDataHist::TEveCaloDataHist(): fHStack(0)
+TEveCaloDataHist::TEveCaloDataHist(): 
+   fHStack(0),
+   fMaxValEt(0),
+   fMaxValE(0)
 {
    // Constructor.
 
@@ -107,10 +120,11 @@ Int_t TEveCaloDataHist::GetCellList(Float_t minVal, Float_t maxVal,
 
    using namespace TMath;
 
-   Float_t phiMin = phi - phiD;
-   Float_t phiMax = phi + phiD;
-   Float_t etaMin = eta - etaD;
-   Float_t etaMax = eta + etaD;
+   Float_t etaMin = eta - etaD*0.5; 
+   Float_t etaMax = eta + etaD*0.5; 
+
+   Float_t phiMin = phi - phiD*0.5; 
+   Float_t phiMax = phi + phiD*0.5; 
 
    TH2F *hist0 = (TH2F*)fHStack->GetStack()->At(0);
    TAxis *ax = hist0->GetXaxis();
@@ -119,36 +133,14 @@ Int_t TEveCaloDataHist::GetCellList(Float_t minVal, Float_t maxVal,
 
    Int_t bin = 0;
    Float_t val = 0;
-   Double_t phi0, phi1;
-   Bool_t phiInside;
-   for (Int_t ieta=1; ieta<=ax->GetNbins(); ieta++) {
-      for (Int_t iphi=1; iphi<=ay->GetNbins(); iphi++)  {
-         if ( ax->GetBinLowEdge(ieta)>=etaMin && ax->GetBinUpEdge(ieta)<=etaMax)
+   for (Int_t ieta=1; ieta<=ax->GetNbins(); ieta++) 
+   {
+      if (ax->GetBinLowEdge(ieta) >= etaMin && ax->GetBinUpEdge(ieta) <= etaMax)
+      {
+         for (Int_t iphi = 1; iphi <= ay->GetNbins(); iphi++)
          {
-            phiInside = kFALSE;
-            phi0 = ay->GetBinLowEdge(iphi);
-            phi1 = ay->GetBinUpEdge(iphi);
-
-            if ( phi0>=phiMin && phi1 <=phiMax)
-            {
-               phiInside = kTRUE;
-            }
-            else if (phiMax>Pi() && phi1<phiMin)
-            {
-               phi0 += TwoPi();
-               phi1 += TwoPi();
-               if (phi0>phiMin && phi1<phiMax)
-                  phiInside = kTRUE;
-            }
-            else if (phiMin<-Pi() && phi0>phiMax)
-            {
-               phi0 -= TwoPi();
-               phi1 -= TwoPi();
-               if (phi0>=phiMin && phi1<=phiMax)
-                  phiInside = kTRUE;
-            }
-
-            if (phiInside)
+            if (TEveUtil::IsU1IntervalOverlappingByMinMax
+                (phiMin+1e-5, phiMax-1e-5, ay->GetBinLowEdge(iphi), ay->GetBinUpEdge(iphi)))            
             {
                TIter next(fHStack->GetHists());
                Int_t slice = 0;
@@ -162,9 +154,9 @@ Int_t TEveCaloDataHist::GetCellList(Float_t minVal, Float_t maxVal,
                   slice++;
                }
             }
-         }
-      }
-   }
+         } // phi bind  
+      } // if eta rng
+   } // eta bins
    return out.size();
 }
 
@@ -225,9 +217,34 @@ void TEveCaloDataHist::GetCellData(const TEveCaloData::CellId_t &id, Float_t phi
 //______________________________________________________________________________
 void TEveCaloDataHist::AddHistogram(TH2F* h)
 {
-   // Add  new slice to calo tower.
+   // Add  new slice to calo tower. Updates cached variables fMaxValE and fMaxValEt
+
+   using namespace TMath;
 
    fHStack->Add(h);
+
+   fMaxValE = 0;
+   fMaxValEt = 0;
+   TH2 *stack =  (TH2*)fHStack->GetStack()->Last();
+   TAxis *ax = stack->GetXaxis();
+   TAxis *ay = stack->GetYaxis();
+   Int_t bin;
+   Double_t value, cos, eta;
+   for (Int_t ieta=1; ieta<=ax->GetNbins(); ieta++) 
+   {
+      eta = ax->GetBinCenter(ieta);
+      for (Int_t iphi=1; iphi<=ay->GetNbins(); iphi++)  
+      {
+         bin = stack->GetBin(ieta, iphi);
+         value = stack->GetBinContent(bin);
+
+         if (value > fMaxValEt ) fMaxValEt = value;
+
+         cos = Cos(2*ATan(Exp( -Abs(eta))));
+         value /= Abs(cos);
+         if (value > fMaxValE) fMaxValE = value;
+      }
+   }
 }
 
 //______________________________________________________________________________
@@ -238,14 +255,6 @@ Int_t TEveCaloDataHist::GetNSlices() const
    return fHStack->GetHists()->GetEntries();
 }
 
-//______________________________________________________________________________
-Float_t TEveCaloDataHist::GetMaxVal() const
-{
-   // Returns the maximum of all added histograms.
-
-   return fHStack->GetMaximum();
-}
-
 //______________________________________________________________________________
 void TEveCaloDataHist::GetEtaLimits(Double_t &min, Double_t &max) const
 {
diff --git a/graf3d/eve/src/TEveCaloLegoEditor.cxx b/graf3d/eve/src/TEveCaloLegoEditor.cxx
index 9e6d9a152a7..45eaba9decf 100644
--- a/graf3d/eve/src/TEveCaloLegoEditor.cxx
+++ b/graf3d/eve/src/TEveCaloLegoEditor.cxx
@@ -51,10 +51,10 @@ TEveCaloLegoEditor::TEveCaloLegoEditor(const TGWindow *p, Int_t width, Int_t hei
       // grid color
       TGHorizontalFrame* f = new TGHorizontalFrame(this);
       TGLabel* lab = new TGLabel(f, "GridColor:");
-      f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 10, 1, 2));
+      f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 10, 1, 1));
 
       fGridColor = new TGColorSelect(f, 0, -1);
-      f->AddFrame(fGridColor, new TGLayoutHints(kLHintsLeft|kLHintsTop, 3, 1, 0, 2));
+      f->AddFrame(fGridColor, new TGLayoutHints(kLHintsLeft|kLHintsTop, 3, 1, 0, 1));
       fGridColor->Connect("ColorSelected(Pixel_t)", "TEveCaloLegoEditor", this, "DoGridColor(Pixel_t)");
 
       AddFrame(f, new TGLayoutHints(kLHintsTop, 1, 1, 1, 0));
@@ -67,7 +67,7 @@ TEveCaloLegoEditor::TEveCaloLegoEditor(const TGWindow *p, Int_t width, Int_t hei
       f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 8, 1, 1));
 
       fFontColor = new TGColorSelect(f, 0, -1);
-      f->AddFrame(fFontColor, new TGLayoutHints(kLHintsLeft|kLHintsTop, 3, 1, 0, 2));
+      f->AddFrame(fFontColor, new TGLayoutHints(kLHintsLeft|kLHintsTop, 3, 1, 0, 1));
       fFontColor->Connect("ColorSelected(Pixel_t)", "TEveCaloLegoEditor", this, "DoFontColor(Pixel_t)");
 
       AddFrame(f, new TGLayoutHints(kLHintsTop, 1, 1, 1, 0));
@@ -79,7 +79,7 @@ TEveCaloLegoEditor::TEveCaloLegoEditor(const TGWindow *p, Int_t width, Int_t hei
       f->AddFrame(lab, new TGLayoutHints(kLHintsLeft|kLHintsBottom, 1, 1, 1, 1));
 
       fPlaneColor = new TGColorSelect(f, 0, -1);
-      f->AddFrame(fPlaneColor, new TGLayoutHints(kLHintsLeft|kLHintsTop, 3, 1, 0, 2));
+      f->AddFrame(fPlaneColor, new TGLayoutHints(kLHintsLeft|kLHintsTop, 3, 1, 0, 1));
       fPlaneColor->Connect("ColorSelected(Pixel_t)", "TEveCaloLegoEditor", this, "DoPlaneColor(Pixel_t)");
 
       fTransparency = new TGNumberEntry(f, 0., 2, -1,
@@ -116,15 +116,6 @@ TEveCaloLegoEditor::TEveCaloLegoEditor(const TGWindow *p, Int_t width, Int_t hei
    fBinWidth->Connect("ValueSet(Double_t)", "TEveCaloLegoEditor", this, "DoBinWidth()");
    AddFrame(fBinWidth, new TGLayoutHints(kLHintsTop, 4, 2, 1, 2));
 
-   {
-      TGHorizontalFrame *title1 = new TGHorizontalFrame(this, 145, 10,
-                                                        kLHintsExpandX | kFixedWidth);
-      title1->AddFrame(new TGLabel(title1, "View"),
-                       new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
-      title1->AddFrame(new TGHorizontal3DLine(title1),
-                       new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
-      AddFrame(title1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
-   }
    fProjection = MakeLabeledCombo("Project:", 1);
    fProjection->AddEntry("Auto", TEveCaloLego::kAuto);
    fProjection->AddEntry("3D", TEveCaloLego::k3D);
diff --git a/graf3d/eve/src/TEveCaloLegoGL.cxx b/graf3d/eve/src/TEveCaloLegoGL.cxx
index dd584245147..bff37d3bd6b 100644
--- a/graf3d/eve/src/TEveCaloLegoGL.cxx
+++ b/graf3d/eve/src/TEveCaloLegoGL.cxx
@@ -232,9 +232,9 @@ void TEveCaloLegoGL::MakeDisplayList() const
          {
             glLoadName(i);
             MakeQuad(cellData.EtaMin(), cellData.PhiMin(), offset,
-                     cellData.EtaDelta(), cellData.PhiDelta(), cellData.Value());
+                     cellData.EtaDelta(), cellData.PhiDelta(), cellData.Value(fM->fPlotEt));
          }
-         offset += cellData.Value();
+         offset += cellData.Value(fM->fPlotEt);
       }
       glEndList();
    }
@@ -331,7 +331,7 @@ void TEveCaloLegoGL::DrawZAxis(TGLRnrCtx &rnrCtx, Float_t azX, Float_t azY) cons
 
    // size of tick-mark 8 pixels
    TGLVertex3 worldRef(0, 0, fZAxisMax*0.5);
-   TGLVector3 off = rnrCtx.RefCamera().ViewportDeltaToWorld(worldRef, -8, 0);
+   TGLVector3 off = rnrCtx.RefCamera().ViewportDeltaToWorld(worldRef, -10, 0);
 
    // primary tick-marks
    Int_t np = TMath::CeilNint(fZAxisMax/fZAxisStep);
@@ -964,12 +964,12 @@ void TEveCaloLegoGL::DrawCells2D(TGLRnrCtx & rnrCtx) const
                glVertex3f(cellData.Eta() +etaW, cellData.Phi()+phiW, sum);
                glVertex3f(cellData.Eta() -etaW, cellData.Phi()+phiW, sum);
             }
-            sum = cellData.Value();
+            sum = cellData.Value(fM->fPlotEt);
             prevTower = (*it).fTower;
          }
          else
          {
-            sum += cellData.Value();
+            sum += cellData.Value(fM->fPlotEt);
          }
          glEnd();
          name++;
@@ -1028,7 +1028,7 @@ void TEveCaloLegoGL::DrawCells2D(TGLRnrCtx & rnrCtx) const
                if (j == (jMax-1))
                   up = cd.PhiMax() -phi0;
 
-               vec[i*nPhi+j]  += cd.Value()*(right-left)*(up-down);
+               vec[i*nPhi+j]  += cd.Value(fM->fPlotEt)*(right-left)*(up-down);
             }
          }
       }
@@ -1096,21 +1096,28 @@ void TEveCaloLegoGL::DirectDraw(TGLRnrCtx & rnrCtx) const
       cells3D = kTRUE;
 
    // init cached variables
-   fDataMax   = fM->fData->GetMaxVal();
+   if (fM->fScaleAbs)
+      fDataMax   = fM->fMaxValAbs;
+   else
+      fDataMax   = fM->fData->GetMaxVal(fM->fPlotEt);
+
+   //   printf("Direct draw max %f\n", fDataMax);
    Int_t ondiv;
    Double_t omin, omax;
    THLimitsFinder::Optimize(0, fDataMax, fM->fNZSteps, omin, omax, ondiv,  fZAxisStep);
-   fZAxisMax = (ondiv+1)*fZAxisStep;
+   fZAxisMax = (ondiv)*fZAxisStep;
+   if (fZAxisMax < fDataMax)
+      fZAxisMax += fZAxisStep;
+
 
    // cache
-   fM->AssertPalette();
    if (fM->fCacheOK == kFALSE)
    {
       fDLCacheOK = kFALSE;
       fM->ResetCache();
       fM->fData->GetCellList(fM->fPalette->GetMinVal(), fM->fPalette->GetMaxVal(),
-                             fM->GetEta(), fM->GetEtaRng()*0.5,
-                             fM->fPhi, fM->fPhiOffset, fM->fCellList);
+                             fM->GetEta(), fM->GetEtaRng(),
+                             fM->GetPhi(), fM->GetPhiRng(), fM->fCellList);
       fM->fCacheOK = kTRUE;
    }
    if (cells3D && fDLCacheOK == kFALSE) MakeDisplayList();
@@ -1119,21 +1126,21 @@ void TEveCaloLegoGL::DirectDraw(TGLRnrCtx & rnrCtx) const
    // modelview matrix
    glPushMatrix();
 
-   // scale from rebinning
-   Float_t sx = (fEtaAxis->GetXmax()-fEtaAxis->GetXmin())/fM->GetEtaRng();
-   Float_t sy = (fPhiAxis->GetXmax()-fPhiAxis->GetXmin())/fM->GetPhiRng();
+   Double_t em, eM, pm, pM;
+   fM->fData->GetEtaLimits(em, eM);
+   fM->fData->GetPhiLimits(pm, pM);
 
-   // scale due to shortest XY axis have same length as  z axis
-   Float_t zf;
-   if (fEtaAxis->GetXmax()-fEtaAxis->GetXmin() < fPhiAxis->GetXmax()-fPhiAxis->GetXmin())
-      zf = fM->GetDefaultCellHeight()/(fEtaAxis->GetXmax()-fEtaAxis->GetXmin());
-   else
-      zf = fM->GetDefaultCellHeight()/(fPhiAxis->GetXmax()-fPhiAxis->GetXmin());
+   // scale due to shortest XY axis
+   Double_t unit = ((eM-em) < (pM-pm)) ? (eM-em):(pM-pm);
 
-   glScalef(sx*zf, sy*zf, fM->fCellZScale*fM->GetDefaultCellHeight()/fZAxisMax);
+   // scale from rebinning
+   Float_t sx = (eM-em)/fM->GetEtaRng();
+   Float_t sy = (pM-pm)/fM->GetPhiRng();
+   glScalef(sx/unit, sy/unit, fM->GetValToHeight());
 
    glTranslatef(-fM->GetEta(), -fM->fPhi, 0);
 
+
    glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT);
    glLineWidth(1);
    glDisable(GL_LIGHTING);
diff --git a/graf3d/eve/src/TEveCaloVizEditor.cxx b/graf3d/eve/src/TEveCaloVizEditor.cxx
index bf2044cd8d8..afdbb58ca97 100644
--- a/graf3d/eve/src/TEveCaloVizEditor.cxx
+++ b/graf3d/eve/src/TEveCaloVizEditor.cxx
@@ -14,11 +14,15 @@
 #include "TEveGValuators.h"
 #include "TEveRGBAPaletteEditor.h"
 
+#include "TGClient.h"
+#include "TGFont.h"
+
 #include "TGLabel.h"
 #include "TGNumberEntry.h"
 #include "TGDoubleSlider.h"
 #include "TGNumberEntry.h"
 #include "TG3DLine.h"
+#include "TGButtonGroup.h"
 
 #include "TMathBase.h"
 #include "TMath.h"
@@ -35,15 +39,81 @@ TEveCaloVizEditor::TEveCaloVizEditor(const TGWindow *p, Int_t width, Int_t heigh
    TGedFrame(p, width, height, options | kVerticalFrame, back),
    fM(0),
 
+   fPlotE(0),
+   fPlotEt(0),
+
+   fScaleAbs(0),
+   fMaxValAbs(0),
+   fMaxTowerH(0),
+
    fEtaRng(0),
    fPhi(0),
    fPhiOffset(0),
    fTower(0),
-   fPalette(0),
-   fCellZScale(0)
+   fPalette(0)
 {
    // Constructor.
 
+   MakeTitle("TEveCaloViz");
+
+   // E/Et Plot
+   {
+      TGHorizontalFrame* group = new   TGHorizontalFrame(this);
+
+      TGCompositeFrame *labfr = new TGHorizontalFrame(group, 28, 20, kFixedSize);
+   
+      TGFont *myfont = gClient->GetFont("-adobe-times-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
+      TGLabel* label = new TGLabel(labfr, "Plot:");
+      label->SetTextFont(myfont);
+      labfr->AddFrame(label, new TGLayoutHints(kLHintsLeft  | kLHintsBottom));
+      group->AddFrame(labfr, new TGLayoutHints(kLHintsLeft));
+
+      fPlotE = new TGRadioButton(group, new TGHotString("E"), 11);
+      fPlotE->Connect("Clicked()", "TEveCaloVizEditor", this, "DoPlot()");
+      group->AddFrame(fPlotE, new TGLayoutHints(kLHintsLeft  | kLHintsBottom, 2, 2, 0, 0));
+
+      fPlotEt = new TGRadioButton(group, new TGHotString("Et"), 22);
+      fPlotEt->Connect("Clicked()", "TEveCaloVizEditor", this, "DoPlot()");
+      group->AddFrame(fPlotEt, new TGLayoutHints(kLHintsLeft  | kLHintsBottom,  2, 2, 0, 0));
+
+      AddFrame(group, new TGLayoutHints(kLHintsTop, 4, 1, 1, 0));
+   }
+   // scaling
+   TGHorizontalFrame* scf = new TGHorizontalFrame(this);
+
+   TGLabel* label = new TGLabel(scf, "ScaleAbsolute:");
+   scf->AddFrame(label, new TGLayoutHints(kLHintsLeft  | kLHintsBottom));
+ 
+   fScaleAbs  = new TGCheckButton(scf);
+   scf->AddFrame(fScaleAbs, new TGLayoutHints(kLHintsLeft, 3, 5, 3, 0));
+   fScaleAbs->Connect("Toggled(Bool_t)", "TEveCaloVizEditor", this, "DoScaleAbs()");
+
+
+   fMaxValAbs = new TEveGValuator(scf, "MaxEVal:", 70, 0);
+   fMaxValAbs->SetLabelWidth(56);
+   fMaxValAbs->SetNELength(5);
+   fMaxValAbs->SetShowSlider(kFALSE);
+   fMaxValAbs->Build();
+   fMaxValAbs->SetLimits(0, 1000);
+   fMaxValAbs->Connect("ValueSet(Double_t)", "TEveCaloVizEditor", this, "DoMaxValAbs()");
+   scf->AddFrame(fMaxValAbs, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1));
+
+   AddFrame(scf, new TGLayoutHints(kLHintsTop, 4, 1, 1, 0));
+
+
+   // tower height
+   fMaxTowerH = new TEveGValuator(this, "MaxTowerH:", 96, 0);
+   fMaxTowerH->SetLabelWidth(71);
+   fMaxTowerH->SetNELength(5);
+   fMaxTowerH->SetShowSlider(kFALSE);
+   fMaxTowerH->Build();
+   fMaxTowerH->SetLimits(0.1, 500, 501, TGNumberFormat::kNESRealOne);
+   fMaxTowerH->Connect("ValueSet(Double_t)", "TEveCaloVizEditor", this, "DoMaxTowerH()");
+   AddFrame(fMaxTowerH, new TGLayoutHints(kLHintsTop, 4, 1, 1, 1));
+
+   
+   //______________________________________________________________________________
+
    fTower = CreateEditorTabSubFrame("Towers");
    Int_t  labelW = 45;
 
@@ -74,14 +144,7 @@ TEveCaloVizEditor::TEveCaloVizEditor(const TGWindow *p, Int_t width, Int_t heigh
    fPhiOffset->Connect("ValueSet(Double_t)", "TEveCaloVizEditor", this, "DoPhi()");
    fTower->AddFrame(fPhiOffset, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1));
 
-   fCellZScale = new TEveGValuator(fTower, "ZScale:", 90, 0);
-   fCellZScale->SetLabelWidth(labelW);
-   fCellZScale->SetNELength(6);
-   fCellZScale->Build();
-   fCellZScale->SetLimits(0, 5, 100, TGNumberFormat::kNESRealTwo);
-   fCellZScale->Connect("ValueSet(Double_t)", "TEveCaloVizEditor", this, "DoCellZScale()");
-   fTower->AddFrame(fCellZScale, new TGLayoutHints(kLHintsTop, 1, 1, 1, 1));
-
+   
    TGHorizontalFrame *title2 = new TGHorizontalFrame(fTower, 145, 10, kLHintsExpandX| kFixedWidth);
    title2->AddFrame(new TGLabel(title2, "Palette Controls"),
                     new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
@@ -100,6 +163,21 @@ void TEveCaloVizEditor::SetModel(TObject* obj)
    // Set model object.
 
    fM = dynamic_cast<TEveCaloViz*>(obj);
+   if(fM->GetPlotEt())
+   {
+      fPlotEt->SetState(kButtonDown, kFALSE);
+      fPlotE->SetState(kButtonUp, kFALSE);
+   }
+   else
+   {
+      fPlotE->SetState(kButtonDown, kFALSE);
+      fPlotEt->SetState(kButtonUp, kFALSE);
+   }
+
+   fScaleAbs->SetState(fM->GetScaleAbs() ? kButtonDown : kButtonUp);
+   fMaxValAbs->SetValue(fM->GetMaxValAbs());
+   fMaxTowerH->SetValue(fM->GetMaxTowerH());
+
 
    Double_t min, max;
    fM->GetData()->GetEtaLimits(min, max);
@@ -110,8 +188,50 @@ void TEveCaloVizEditor::SetModel(TObject* obj)
    fPhiOffset->SetValue(fM->fPhiOffset*TMath::RadToDeg());
 
    fPalette->SetModel(fM->fPalette);
+}
+
+//______________________________________________________________________________
+void TEveCaloVizEditor::DoMaxTowerH()
+{
+   // Slot for setting max tower height.
+
+   fM->SetMaxTowerH(fMaxTowerH->GetValue());
+   Update();
+}
+
+//______________________________________________________________________________
+void TEveCaloVizEditor::DoScaleAbs()
+{
+   // Slot for enabling/disabling absolute scale.
+
+   fM->SetScaleAbs(fScaleAbs->IsOn());
+   Update();
+}
+
+//___________________________________________________________________________
+void TEveCaloVizEditor::DoMaxValAbs()
+{
+   // Slot for setting max E in for absolute scale.
+
+   fM->SetMaxValAbs(fMaxValAbs->GetValue());
+   Update();
+}
+
+//___________________________________________________________________________
+void TEveCaloVizEditor::DoPlot()
+{
+   // Slot for setting E/Et plot.
 
-   fCellZScale->SetValue(fM->fCellZScale);
+   TGButton *btn = (TGButton *) gTQSender;
+   Int_t id = btn->WidgetId();
+
+   if (id == fPlotE->WidgetId()) 
+      fPlotEt->SetState(kButtonUp);
+   else
+      fPlotE->SetState(kButtonUp);
+
+   fM->SetPlotEt(fPlotEt->IsDown());
+   Update();
 }
 
 //______________________________________________________________________________
@@ -132,15 +252,6 @@ void TEveCaloVizEditor::DoPhi()
    Update();
 }
 
-//______________________________________________________________________________
-void TEveCaloVizEditor::DoCellZScale()
-{
-  // Slot for setting tower height.
-
-   fM->SetCellZScale(fCellZScale->GetValue());
-   Update();
-}
-
 //______________________________________________________________________________
 void TEveCaloVizEditor::DoPalette()
 {
diff --git a/graf3d/eve/src/TEveLegoOverlay.cxx b/graf3d/eve/src/TEveLegoOverlay.cxx
index 013b16992e9..77c2389b58d 100644
--- a/graf3d/eve/src/TEveLegoOverlay.cxx
+++ b/graf3d/eve/src/TEveLegoOverlay.cxx
@@ -99,7 +99,7 @@ void TEveLegoOverlay::DrawSlider(TGLRnrCtx& rnrCtx)
    glTranslatef(0, fSliderPosY, 0);
    Int_t nsteps, ndiv;
    Double_t omin, omax, zmax, tickval;
-   THLimitsFinder::Optimize(0, fCalo->GetData()->GetMaxVal(), fCalo->GetNZSteps(), omin, omax, ndiv, tickval);
+   THLimitsFinder::Optimize(0, fCalo->GetData()->GetMaxVal(fCalo->GetPlotEt()), fCalo->GetNZSteps(), omin, omax, ndiv, tickval);
    nsteps = ndiv+1;
    zmax = nsteps*tickval;
    
diff --git a/graf3d/eve/src/TEveUtil.cxx b/graf3d/eve/src/TEveUtil.cxx
index 00d604987b8..7cb75389483 100644
--- a/graf3d/eve/src/TEveUtil.cxx
+++ b/graf3d/eve/src/TEveUtil.cxx
@@ -38,7 +38,7 @@
 //
 // Standard utility functions for Reve.
 
-ClassImp(TEveUtil)
+ClassImp(TEveUtil);
 
 //______________________________________________________________________________
 void TEveUtil::SetupEnvironment()
@@ -270,6 +270,52 @@ const char* TEveUtil::FormAxisValue(Float_t x)
    return "0";
 }
 
+/******************************************************************************/
+// Math utilities
+/******************************************************************************/
+
+//______________________________________________________________________________
+Bool_t TEveUtil::IsU1IntervalContainedByMinMax(Float_t minM, Float_t maxM,
+                                               Float_t minQ, Float_t maxQ)
+{
+   // Return true if interval Q is contained within interval M for U1 variables.
+   // It is assumed that all values are within the [-2pi, 2pi] interval and
+   // minM <= maxM & minQ <= maxQ.
+
+   using namespace TMath;
+
+   if (maxQ < minM)
+   {
+      minQ += TwoPi(); maxQ += TwoPi();
+   }
+   else if (minQ > maxM)
+   {
+      minQ -= TwoPi(); maxQ -= TwoPi();
+   }
+   return minQ >= minM && maxQ <= maxM;
+}
+
+//______________________________________________________________________________
+Bool_t TEveUtil::IsU1IntervalOverlappingByMinMax(Float_t minM, Float_t maxM,
+                                                 Float_t minQ, Float_t maxQ)
+{
+   // Return true if interval Q is overlapping within interval M for U1 variables.
+   // It is assumed that all values are within the [-2pi, 2pi] interval and
+   // minM <= maxM & minQ <= maxQ.
+
+   using namespace TMath;
+
+   if (maxQ < minM)
+   {
+      minQ += TwoPi(); maxQ += TwoPi();
+   }
+   else if (minQ > maxM)
+   {
+      minQ -= TwoPi(); maxQ -= TwoPi();
+   }
+   return maxQ >= minM && minQ <= maxM;
+}
+
 
 /******************************************************************************/
 // TEveException
@@ -279,7 +325,7 @@ const char* TEveUtil::FormAxisValue(Float_t x)
 //
 // Exception class thrown by TEve classes and macros.
 
-ClassImp(TEveException)
+ClassImp(TEveException);
 
 //______________________________________________________________________________
 bool operator==(const TString& t, const std::string& s)
@@ -316,7 +362,7 @@ TEveException operator+(const TEveException &s1,  const char *s2)
 // Exception safe wrapper for setting gPad.
 // Optionally calls gPad->Modified()/Update() in destructor.
 
-ClassImp(TEvePadHolder)
+ClassImp(TEvePadHolder);
 
 //______________________________________________________________________________
 TEvePadHolder::TEvePadHolder(Bool_t modify_update_p, TVirtualPad* new_pad, Int_t subpad) :
@@ -383,7 +429,7 @@ TEveGeoManagerHolder::~TEveGeoManagerHolder()
 // Base-class for reference-counted objects.
 // By default the object is destroyed when zero referece-count is reached.
 
-ClassImp(TEveRefCnt)
+ClassImp(TEveRefCnt);
 
 
 /******************************************************************************/
@@ -395,7 +441,7 @@ ClassImp(TEveRefCnt)
 // Base-class for reference-counted objects with reverse references to
 // TEveElement objects.
 
-ClassImp(TEveRefBackPtr)
+ClassImp(TEveRefBackPtr);
 
 //______________________________________________________________________________
 TEveRefBackPtr::TEveRefBackPtr() :
diff --git a/tutorials/eve/cms_calo.C b/tutorials/eve/cms_calo.C
index 8f94dca5465..b30e50cab18 100644
--- a/tutorials/eve/cms_calo.C
+++ b/tutorials/eve/cms_calo.C
@@ -16,6 +16,9 @@ void cms_calo()
   data->AddHistogram(ecalHist);
   data->AddHistogram(hcalHist);
   
+  // palette
+  gStyle->SetPalette(1, 0);
+
   // different calorimeter presentations
   TEveCalo3D* calo3d = MakeCalo3D(data);
   MakeCalo2D(calo3d);
@@ -27,18 +30,11 @@ void cms_calo()
 //______________________________________________________________________________
 TEveCalo3D* MakeCalo3D(TEveCaloDataHist* data)
 {
-  // palette
-  gStyle->SetPalette(1, 0);
-  TEveRGBAPalette* pal = new TEveRGBAPalette(0, 100);
-  pal->SetLimits(0, TMath::CeilNint(data->GetMaxVal()));
-  pal->SetDefaultColor((Color_t)4);
-  pal->SetShowDefValue(kFALSE);
 
   // 3D towers
   TEveCalo3D* calo3d = new TEveCalo3D(data);
   calo3d->SetBarrelRadius(129);
   calo3d->SetEndCapPos(300);
-  calo3d->SetPalette(pal);
   gEve->AddElement(calo3d);
 
   return calo3d;
@@ -72,15 +68,11 @@ void MakeCaloLego(TEveCaloDataHist* data)
   TGLViewer*  v  = v2->GetGLViewer();
   v->SetCurrentCamera(TGLViewer::kCameraPerspXOY);
   v->SetEventHandler(new TEveLegoEventHandler("Lego", v->GetGLWidget(), v));
-  TEveRGBAPalette* pal = new TEveRGBAPalette(0, 100);
-  pal->SetLimits(0, TMath::CeilNint(data->GetMaxVal()));
-  pal->SetDefaultColor((Color_t)4);
   TEveScene*  s2 = gEve->SpawnNewScene("Lego");
   v2->AddScene(s2);
   
-  // lego1
+  // lego
   TEveCaloLego* lego = new TEveCaloLego(data);
-  lego->SetPalette(pal);
   lego->SetGridColor(kGray+2);
   lego->Set2DMode(TEveCaloLego::kValSize);
   lego->SetName("TwoHistLego");
@@ -94,17 +86,4 @@ void MakeCaloLego(TEveCaloDataHist* data)
   v->AddOverlayElement(overlay);
   gEve->AddElement(overlay, s2);
   gEve->EnableRedraw();
-
-  // lego2
-  TEveCaloDataHist* data2 = new TEveCaloDataHist();
-  data2->AddHistogram(data->GetHistogram(0));
-  TEveCaloLego* lego2 = new TEveCaloLego(data2);
-  lego2->SetName("OneHistLego");
-  lego2->SetPalette(pal);
-  gEve->AddElement(lego2, s2);
-  gEve->AddToListTree(lego2, kTRUE);  
-  lego2->InitMainTrans();
-  lego2->RefMainTrans().Move3PF(0, 0, 15);
-  lego2->SetEta(-3, 3);
-  lego2->SetPhi(TMath::PiOver4());
 }
-- 
GitLab