TH2Editor.cxx

Go to the documentation of this file.
00001 // @(#)root/ged:$Id: TH2Editor.cxx 35417 2010-09-20 07:16:18Z bellenot $
00002 // Author: Carsten Hof   09/08/04
00003 // Authors mail: Carsten_Hof@web.de
00004 
00005 /*************************************************************************
00006  * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers.               *
00007  * All rights reserved.                                                  *
00008  *                                                                       *
00009  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00010  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00011  *************************************************************************/
00012 
00013 //////////////////////////////////////////////////////////////////////////
00014 //                                                                      //
00015 //  TH2Editor                                                           //
00016 //  Editor for changing TH2 histogram attributes, rebinning & fitting.  //
00017 //  For all possible draw options (there are a few which are not imple- //
00018 //  mentable in a graphical user interface) see THistPainter::Paint in  //
00019 //  root/histpainter/THistPainter.cxx                                   //
00020 //
00021 //Begin_Html
00022 /*
00023 <img src="gif/TH2Editor_1.gif">
00024 */
00025 //End_Html
00026 //Begin_Html
00027 /*
00028 <img src="gif/TH2Editor_2.gif">
00029 */
00030 //End_Html
00031 //  These changes can be made via the TH2Editor:                        //
00032 //    Style Tab:                                                        //
00033 //      'Line'     : change Line attributes (color, thickness)          //
00034 //                   see TAttLineEditor                                 //
00035 //      'Fill'     : change Fill attributes (color, pattern)            //
00036 //                   see TAttFillEditor                                 //
00037 //      'Title'    : TextEntry: set the title of the histogram          //
00038 //      'Histogram': change the draw options of the histogram           //
00039 //      'Plot'     : Radiobutton: draw a 2D or 3D plot of the histogram //
00040 //                   according to the Plot dimension there will be      //
00041 //                   different drawing possibilities (ComboBoxes/       //
00042 //                   CheckBoxes)                                        //
00043 //    2d Plot:                                                          //
00044 //      'Contour' : ComboBox: draw a contour plot (None, Cont0..4)      //
00045 //      'Cont #'  : TGNumberEntry: set the number of Contours           //
00046 //    2d Plot checkboxes:                                               //
00047 //      'Arrow'   : arrow mode. Shows gradient between adjacent cells   //
00048 //      'Col'     : a box is drawn for each cell with a color scale     //
00049 //                  varying with contents                               //
00050 //      'Text'    : Draw bin contents as text                           //
00051 //      'Box'     : a box is drawn for each cell with surface           //
00052 //                  proportional to contents                            //
00053 //      'Scat'    : Draw a scatter-plot (default)                       //
00054 //      'Palette' : the color palette is drawn                          //
00055 //                                                                      //
00056 //    3d Plot:                                                          //
00057 //      'Type'    : ComboBox: set histogram type Lego or Surface-Plot   //
00058 //                  draw(Lego, Lego1.2, Surf, Surf1..5)                 //
00059 //                  see THistPainter::Paint                             //
00060 //      'Coords'  : ComboBox: set the coordinate system (Cartesian, ..  //
00061 //                  Spheric) see THistPainter::Paint                    //
00062 //      'Cont #'  : TGNumberEntry: set the number of Contours (for e.g. //
00063 //                  Lego2 drawoption                                    //
00064 //    3d Plot checkboxes:                                               //
00065 //      'Errors'  : draw errors in a cartesian lego plot                //
00066 //      'Palette' : the color palette is drawn                          //
00067 //      'Front'   : draw the front box of a cartesian lego plot         //
00068 //      'Back'    : draw the back box of a cartesian lego plot          //
00069 //    Available for a 3D lego plot:                                     //
00070 //      'Bar'     : change the bar attributes                           //
00071 //            'W' : change Bar Width                                    //
00072 //            'O' : change Bar Offset                                   //
00073 //   Further Editor:                                                    //
00074 //      'Marker'   : change the Marker attributes (color, appearance,   //
00075 //                   thickness) see TAttMarkerEditor                    //
00076 //                                                                      //
00077 //Begin_Html
00078 /*
00079 <img src="gif/TH2Editor1_1.gif">
00080 */
00081 //End_Html
00082 //Begin_Html
00083 /*
00084 <img src="gif/TH2Editor1_2.gif">
00085 */
00086 //End_Html
00087 //                                                                      //
00088 //   Rebinning Tab:                                                     //
00089 //      This Tab has two different layouts. One is for a histogram which//
00090 //      is not drawn from an ntuple. The other one is available for a   //
00091 //      histogram which is drawn from an ntuple. In this case the rebin //
00092 //      algorithm can create a rebinned histogram from the original data//
00093 //      i.e. the ntuple.                                                //
00094 //      To see te differences do for example:                           //
00095 //         TFile f("hsimple.root");                                     //
00096 //         hpxpy->Draw("Lego2");              // non ntuple histogram   //
00097 //         ntuple->Draw("px:py","","Lego2");  // ntuple histogram       //
00098 //    Non ntuple histogram:                                             //
00099 //       'Rebin': with the Sliders (one for the x, one for the y axis)  //
00100 //                the number of bins (shown in the field below the      //
00101 //                Slider) can be changed to any number which divides    //
00102 //                the number of bins of the original histogram.         //
00103 //                Pushing 'Apply' will delete the origin histogram and  //
00104 //                replace it by the rebinned one on the screen.         //
00105 //                Pushing 'Ignore' the origin histogram will be restored//
00106 //    Histogram drawn from an ntuple:                                   //
00107 //       'Rebin'  with the sliders the number of bins can be enlarged by//
00108 //                a factor of 2,3,4,5 (moving to the right) or reduced  //
00109 //                by a factor of 1/2, 1/3, 1/4, 1/5                     //
00110 //       'BinOffset': with the BinOffset slider the origin of the       //
00111 //                histogram can be changed within one binwidth          //
00112 //                Using this slider the effect of binning the data into //
00113 //                bins can be made visible => statistical fluctuations  //
00114 //       'Axis Range': with the DoubleSlider it is possible to zoom into//
00115 //                the specified axis range. It is also possible to set  //
00116 //                the upper and lower limit in fields below the slider  //
00117 //       'Delayed drawing': all the Binning sliders can be set to delay //
00118 //                draw mode. Then the changes on the histogram are only //
00119 //                updated, when the Slider is released. This should be  //
00120 //                activated if the redrawing of the histogram is too    //
00121 //                time consuming.                                       //
00122 //////////////////////////////////////////////////////////////////////////
00123 
00124 
00125 #include "TH2Editor.h"
00126 #include "TGedEditor.h"
00127 #include "TGComboBox.h"
00128 #include "TGTextEntry.h"
00129 #include "TGToolTip.h"
00130 #include "TGLabel.h"
00131 #include "TVirtualPad.h"
00132 #include "TStyle.h"
00133 #include "TString.h"
00134 #include "TGButtonGroup.h"
00135 #include "TGNumberEntry.h"
00136 #include "TG3DLine.h"
00137 #include "TGDoubleSlider.h"
00138 #include "TGSlider.h"
00139 #include "TView.h"
00140 #include "TCanvas.h"
00141 #include "TGedPatternSelect.h"
00142 #include "TGColorSelect.h"
00143 #include "TColor.h"
00144 #include "TTreePlayer.h"
00145 #include "TSelectorDraw.h"
00146 #include "TGTab.h"
00147 #include "TGMsgBox.h"
00148 #include "TH2.h"
00149 
00150 
00151 ClassImp(TH2Editor)
00152 
00153 enum ETH2Wid {
00154    kTH2_TITLE,
00155    kDIM_SIMPLE, kDIM_COMPLEX, kHIST_TYPE,
00156    kTYPE_LEGO,  kTYPE_LEGO1,  kTYPE_LEGO2,
00157    kTYPE_SURF,  kTYPE_SURF1,  kTYPE_SURF2, kTYPE_SURF3, kTYPE_SURF4, kTYPE_SURF5,
00158    kCOORD_TYPE, kCOORDS_CAR,  kCOORDS_CYL, kCOORDS_POL, kCOORDS_PSR, kCOORDS_SPH,
00159    kCONT_TYPE,  kERROR_ONOFF, kPALETTE_ONOFF, kPALETTE_ONOFF1,
00160    kARROW_ONOFF,kBOX_ONOFF,   kSCAT_ONOFF, kCOL_ONOFF, kTEXT_ONOFF,
00161    kFRONTBOX_ONOFF, kBACKBOX_ONOFF,
00162    kBAR_WIDTH,   kBAR_OFFSET,
00163    kCONT_NONE,   kCONT_0, kCONT_1, kCONT_2, kCONT_3, kCONT_4,
00164    kCONT_LEVELS, kCONT_LEVELS1,
00165    kSLIDERX_MIN, kSLIDERX_MAX, kSLIDERY_MIN, kSLIDERY_MAX,
00166    kDELAYED_DRAWING, kCOLOR,  kPATTERN,
00167    kBINXSLIDER, kBINYSLIDER, kBINXSLIDER1, kBINYSLIDER1,
00168    kXBINOFFSET, kYBINOFFSET
00169 };
00170 
00171 //______________________________________________________________________________
00172 TH2Editor::TH2Editor(const TGWindow *p, Int_t width,
00173                      Int_t height, UInt_t options, Pixel_t back)
00174    : TGedFrame(p, width, height, options | kVerticalFrame, back),
00175      fHist(0),
00176      fBin(0),
00177      fBinHist(0)
00178 {
00179    // Constructor of histogram attribute GUI.
00180 
00181    MakeTitle("Title");
00182 
00183    // Histogram title
00184    fTitlePrec = 2;
00185    fTitle = new TGTextEntry(this, new TGTextBuffer(50), kTH2_TITLE);
00186    fTitle->Resize(135, fTitle->GetDefaultHeight());
00187    fTitle->SetToolTipText("Enter the histogram title string");
00188    AddFrame(fTitle, new TGLayoutHints(kLHintsLeft, 3, 1, 2, 5));
00189 
00190 
00191    // 2D or 3D Plot?
00192    TGCompositeFrame *f2 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00193    fDimGroup = new TGHButtonGroup(f2,"Plot");
00194    fDim = new TGRadioButton(fDimGroup,"2-D",kDIM_SIMPLE);
00195    fDim->SetToolTipText("A 2-d plot of the histogram is dawn");
00196    fDim0 = new TGRadioButton(fDimGroup,"3-D",kDIM_COMPLEX);
00197    fDim0->SetToolTipText("A 3-d plot of the histogram is dawn");
00198    fDimGroup->SetLayoutHints(fDimlh=new TGLayoutHints(kLHintsLeft ,-2,3,3,-7),fDim);
00199    fDimGroup->SetLayoutHints(fDim0lh=new TGLayoutHints(kLHintsLeft ,16,-1,3,-7),fDim0);
00200    fDimGroup->Show();
00201    fDimGroup->ChangeOptions(kFitWidth|kChildFrame|kHorizontalFrame);
00202    f2->AddFrame(fDimGroup, new TGLayoutHints(kLHintsTop, 4, 1, 0, 0));
00203    AddFrame(f2, new TGLayoutHints(kLHintsTop, 1, 1, 2, 5));
00204 
00205    // 2D Plot drawoptions
00206    f6 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00207    AddFrame(f6, new TGLayoutHints(kLHintsTop, 3, 1, 4, 2));
00208 
00209    TGCompositeFrame *f7 = new TGCompositeFrame(f6, 40, 20);
00210    f6->AddFrame(f7, new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00211 
00212    TGLabel *fAddLabel = new TGLabel(f7, "Contour:");
00213    f7->AddFrame(fAddLabel, new TGLayoutHints(kLHintsLeft, 6, 4, 4, 4));
00214 
00215    fColContLbl = new TGLabel(f7, "Cont #:");
00216    f7->AddFrame(fColContLbl, new TGLayoutHints( kLHintsLeft, 6, 4, 4, 4));
00217 
00218    fAddArr = new TGCheckButton(f7, "Arrow", kARROW_ONOFF);
00219    fAddArr ->SetToolTipText("Shows gradient between adjacent cells");
00220    f7->AddFrame(fAddArr, new TGLayoutHints(kLHintsLeft, 6, 1, 2, 0));
00221 
00222    fAddCol = new TGCheckButton(f7, "Col", kCOL_ONOFF);
00223    fAddCol ->SetToolTipText("A box is drawn for each cell with a color scale varying with contents");
00224    f7->AddFrame(fAddCol, new TGLayoutHints(kLHintsLeft, 6, 1, 1, 0));
00225 
00226    fAddText = new TGCheckButton(f7, "Text", kTEXT_ONOFF);
00227    fAddText ->SetToolTipText("Draw bin contents as text");
00228    f7->AddFrame(fAddText, new TGLayoutHints(kLHintsLeft, 6, 1, 1, 3));
00229 
00230    TGCompositeFrame *f8 = new TGCompositeFrame(f6, 40, 20, kVerticalFrame);
00231    f6->AddFrame(f8, new TGLayoutHints(kLHintsLeft, 5, 1, 0, 0));
00232 
00233    fContCombo = BuildHistContComboBox(f8, kCONT_TYPE);
00234    f8->AddFrame(fContCombo, new TGLayoutHints(kLHintsLeft, 6, 1, 2, 1));
00235    fContCombo->Resize(61, 20);
00236    fContCombo->Associate(this);
00237 
00238    fContLevels = new TGNumberEntry(f8, 20, 0, kCONT_LEVELS,
00239                                    TGNumberFormat::kNESInteger,
00240                                    TGNumberFormat::kNEANonNegative,
00241                                    TGNumberFormat::kNELLimitMinMax, 1, 99);
00242    f8->AddFrame(fContLevels, new TGLayoutHints(kLHintsLeft, 6, 1, 3, 1));
00243    fContLevels->GetNumberEntry()->SetToolTipText("Set number of contours (1..99)");
00244    fContLevels->Resize(60,20);
00245 
00246    fAddBox = new TGCheckButton(f8, "Box", kBOX_ONOFF);
00247    fAddBox ->SetToolTipText("A box is drawn for each cell with surface proportional to contents");
00248    f8->AddFrame(fAddBox, new TGLayoutHints(kLHintsLeft, 6, 1, 3, 0));
00249 
00250    fAddScat = new TGCheckButton(f8, "Scat", kSCAT_ONOFF);
00251    fAddScat ->SetToolTipText("Draw a scatter-plot");
00252    f8->AddFrame(fAddScat, new TGLayoutHints(kLHintsLeft, 6, 1, 1, 0));
00253 
00254    fAddPalette = new TGCheckButton(f8, "Palette", kPALETTE_ONOFF);
00255    fAddPalette ->SetToolTipText("Add color palette beside the histogram");
00256    f8->AddFrame(fAddPalette, new TGLayoutHints(kLHintsLeft, 6, 1, 1, 0));
00257 
00258    f9 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00259    AddFrame(f9, new TGLayoutHints(kLHintsTop, 3, 1, 2, 0));
00260 
00261    TGCompositeFrame *f10 = new TGCompositeFrame(f9, 40, 20);
00262    f9->AddFrame(f10, new TGLayoutHints(kLHintsLeft, 0, 0, 3, 0));
00263 
00264    TGLabel *fType = new TGLabel(f10, "Type:");
00265    f10->AddFrame(fType, new TGLayoutHints(kLHintsNormal, 1, 1, 1, 1));
00266 
00267    TGLabel *fCoords = new TGLabel(f10, "Coords:");
00268    f10->AddFrame(fCoords, new TGLayoutHints(kLHintsLeft, 1, 1, 5, 1));
00269 
00270    fColContLbl1 = new TGLabel(f10, "Cont #:");
00271    f10->AddFrame(fColContLbl1, new TGLayoutHints( kLHintsLeft, 1, 1, 5, 3));
00272 
00273    fAddFB = new TGCheckButton(f10, "Front", kFRONTBOX_ONOFF);
00274    fAddFB ->SetToolTipText("Supress the drawing of the front box");
00275    f10->AddFrame(fAddFB, new TGLayoutHints(kLHintsLeft, 0, 1, 6, 0));
00276    fAddBB = new TGCheckButton(f10, "Back", kBACKBOX_ONOFF);
00277    fAddBB ->SetToolTipText("Supress the drawing of the back box");
00278    f10->AddFrame(fAddBB, new TGLayoutHints(kLHintsLeft, 0, 1, 3, 0));
00279 
00280    TGCompositeFrame *f11 = new TGCompositeFrame(f9, 40, 20);
00281    f9->AddFrame(f11, new TGLayoutHints(kLHintsLeft, 5, 1, 0, 0));
00282 
00283    fTypeCombo = BuildHistTypeComboBox(f11, kHIST_TYPE);
00284    f11->AddFrame(fTypeCombo, new TGLayoutHints(kLHintsLeft, 0, 1, 2, 1));
00285    fTypeCombo->Resize(80, 20);
00286    fTypeCombo->Associate(this);
00287 
00288    fCoordsCombo = BuildHistCoordsComboBox(f11, kCOORD_TYPE);
00289    f11->AddFrame(fCoordsCombo, new TGLayoutHints(kLHintsLeft, 0, 1, 2, 1));
00290    fCoordsCombo->Resize(80, 20);
00291    fCoordsCombo->Associate(this);
00292 
00293    fContLevels1 = new TGNumberEntry(f11, 20, 0, kCONT_LEVELS1,
00294                                     TGNumberFormat::kNESInteger,
00295                                     TGNumberFormat::kNEANonNegative,
00296                                     TGNumberFormat::kNELLimitMinMax, 1, 99);
00297    fContLevels1->GetNumberEntry()->SetToolTipText("Set number of contours (1..99)");
00298    fContLevels1->Resize(78,20);
00299    f11->AddFrame(fContLevels1, new TGLayoutHints(kLHintsLeft, 0, 1, 2, 1));
00300 
00301    fAddError = new TGCheckButton(f11, "Errors", kERROR_ONOFF);
00302    fAddError ->SetToolTipText("Add color palette beside the histogram");
00303    f11->AddFrame(fAddError, new TGLayoutHints(kLHintsLeft, 0, 1, 4, 0));
00304    fAddPalette1 = new TGCheckButton(f11, "Palette", kPALETTE_ONOFF1);
00305    fAddPalette1 ->SetToolTipText("Add color palette beside the histogram");
00306    f11->AddFrame(fAddPalette1, new TGLayoutHints(kLHintsLeft, 0, 1, 3, 0));
00307 
00308 
00309    // Bin bar settings
00310    f12 = new TGCompositeFrame(this, 145, 10, kHorizontalFrame |
00311                                              kLHintsExpandX   |
00312                                              kFixedWidth      |
00313                                              kOwnBackground);
00314    f12->AddFrame(new TGLabel(f12,"Bar"),
00315                  new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00316    f12->AddFrame(new TGHorizontal3DLine(f12),
00317                  new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00318    AddFrame(f12, new TGLayoutHints(kLHintsTop,0,0,6,4));
00319 
00320    f13 = new TGCompositeFrame(this, 80, 20, kHorizontalFrame);
00321    TGLabel *fWidthLbl = new TGLabel(f13, "W:");
00322    f13->AddFrame(fWidthLbl, new TGLayoutHints( kLHintsLeft, 1, 3, 4, 1));
00323    fBarWidth = new TGNumberEntry(f13, 1.00, 6, kBAR_WIDTH,
00324                                  TGNumberFormat::kNESRealTwo,
00325                                  TGNumberFormat::kNEANonNegative,
00326                                  TGNumberFormat::kNELLimitMinMax, 0.01, 1.);
00327    fBarWidth->GetNumberEntry()->SetToolTipText("Set bar chart width");
00328    fBarWidth->Resize(45,20);
00329    f13->AddFrame(fBarWidth, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 1));
00330 
00331    TGLabel *fOffsetLbl = new TGLabel(f13, "O:");
00332    f13->AddFrame(fOffsetLbl, new TGLayoutHints(kLHintsLeft, 6,3, 4, 1));
00333    fBarOffset = new TGNumberEntry(f13, 0.00, 5, kBAR_OFFSET,
00334                                   TGNumberFormat::kNESRealTwo,
00335                                   TGNumberFormat::kNEAAnyNumber,
00336                                   TGNumberFormat::kNELLimitMinMax, -1., 1.);
00337    fBarOffset->GetNumberEntry()->SetToolTipText("Set bar chart offset");
00338    fBarOffset->Resize(50,20);
00339    f13->AddFrame(fBarOffset, new TGLayoutHints(kLHintsLeft, 1, 1, 2, 1));
00340    AddFrame(f13, new TGLayoutHints(kLHintsTop, 1, 1, 0, 4));
00341 
00342 
00343    // Set the color and pattern of the Frame (only for Cartesian 3D plot).
00344    f38 = new TGCompositeFrame(this, 80, 20, kVerticalFrame);
00345    TGCompositeFrame *f39 = new TGCompositeFrame(f38, 145, 10, kHorizontalFrame |
00346                                                               kLHintsExpandX   |
00347                                                               kFixedWidth      |
00348                                                               kOwnBackground);
00349    f39->AddFrame(new TGLabel(f39,"Frame Fill"),
00350                  new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00351    f39->AddFrame(new TGHorizontal3DLine(f39),
00352                  new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00353    f38->AddFrame(f39, new TGLayoutHints(kLHintsTop,0,0,6,1));
00354 
00355    TGCompositeFrame *f21 = new TGCompositeFrame(f38, 80, 20, kHorizontalFrame);
00356    fFrameColor = new TGColorSelect(f21, 0, kCOLOR);
00357    f21->AddFrame(fFrameColor, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 0));
00358    fFrameColor->Associate(f38);
00359    fFramePattern = new TGedPatternSelect(f21, 1, kPATTERN);
00360    f21->AddFrame(fFramePattern, new TGLayoutHints(kLHintsLeft, 1, 1, 1, 0));
00361    fFramePattern->Associate(f38);
00362    f38->AddFrame(f21, new TGLayoutHints(kLHintsTop, 1, 1, 0, 0));
00363    AddFrame(f38, new TGLayoutHints(kLHintsTop));
00364 
00365    fCutString = "";
00366 
00367    CreateBinTab();
00368 }
00369 
00370 //______________________________________________________________________________
00371 void TH2Editor::CreateBinTab()
00372 {
00373    // Create the Binning tab.
00374    fBin = CreateEditorTabSubFrame("Binning");
00375 
00376    // Editor for rebinning a histogram which does NOT derive from an Ntuple
00377    fBinXCont = new TGCompositeFrame(fBin, 80, 20, kVerticalFrame);
00378    TGCompositeFrame *title1 = new TGCompositeFrame(fBinXCont, 145, 10,
00379                                                               kHorizontalFrame |
00380                                                               kLHintsExpandX   |
00381                                                               kFixedWidth      |
00382                                                               kOwnBackground);
00383    title1->AddFrame(new TGLabel(title1, "Rebin"),
00384                     new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00385    title1->AddFrame(new TGHorizontal3DLine(title1),
00386                     new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00387    fBinXCont->AddFrame(title1, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
00388 
00389    TGCompositeFrame *f22 = new TGCompositeFrame(fBinXCont, 80, 20,
00390                                                            kHorizontalFrame);
00391    TGLabel *binSliderXLbl = new TGLabel(f22,"x:");
00392    f22->AddFrame(binSliderXLbl,
00393                  new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 4,0, 4, 1));
00394    fBinXSlider  = new TGHSlider(f22, 100, kSlider1 | kScaleBoth);
00395    fBinXSlider->Resize(107,20);
00396    f22->AddFrame(fBinXSlider, new TGLayoutHints(kLHintsLeft, 2,0,0,3));
00397    fBinXCont->AddFrame(f22, new TGLayoutHints(kLHintsTop, 3, 7, 3, 5));
00398 
00399    TGCompositeFrame *f23 = new TGCompositeFrame(fBinXCont, 80, 20,
00400                                                 kHorizontalFrame);
00401    TGLabel *binXLabel1 = new TGLabel(f23, "# of Bins:");
00402    f23->AddFrame(binXLabel1, new TGLayoutHints(kLHintsLeft, 20, 1, 2, 1));
00403    fBinXNumberEntry = new TGNumberEntryField(f23, kBINXSLIDER, 0.0,
00404                                              TGNumberFormat::kNESInteger);
00405    ((TGTextEntry*)fBinXNumberEntry)->SetToolTipText("Set the number of x axis bins in the rebinned histogram");
00406    fBinXNumberEntry->Resize(57,20);
00407    f23->AddFrame(fBinXNumberEntry, new TGLayoutHints(kLHintsRight, 8, 0, 0, 0));
00408    fBinXCont->AddFrame(f23, new TGLayoutHints(kLHintsTop, 0, 7, 3, 4));
00409 
00410    TGCompositeFrame *f37 = new TGCompositeFrame(fBinXCont, 80, 20,
00411                                                            kHorizontalFrame);
00412    TGLabel *binSliderYLbl = new TGLabel(f37,"y:");
00413    f37->AddFrame(binSliderYLbl,
00414                  new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 4,0, 4, 1));
00415    fBinYSlider  = new TGHSlider(f37, 100, kSlider1 | kScaleBoth);
00416    fBinYSlider->Resize(107,20);
00417    f37->AddFrame(fBinYSlider, new TGLayoutHints(kLHintsLeft, 1,0,0,3));
00418    fBinXCont->AddFrame(f37, new TGLayoutHints(kLHintsTop, 3, 7, 3, 5));
00419 
00420    TGCompositeFrame *f36 = new TGCompositeFrame(fBinXCont, 80, 20,
00421                                                            kHorizontalFrame);
00422    TGLabel *binYLabel1 = new TGLabel(f36, "# of Bins:");
00423    f36->AddFrame(binYLabel1, new TGLayoutHints(kLHintsLeft, 20, 1, 2, 1));
00424    fBinYNumberEntry = new TGNumberEntryField(f36, kBINYSLIDER, 0.0,
00425                                              TGNumberFormat::kNESInteger);
00426    ((TGTextEntry*)fBinYNumberEntry)->SetToolTipText("Set the number of y axis bins in the rebinned histogram");
00427    fBinYNumberEntry->Resize(57,20);
00428    f36->AddFrame(fBinYNumberEntry, new TGLayoutHints(kLHintsRight, 8, 0, 0, 0));
00429    fBinXCont->AddFrame(f36, new TGLayoutHints(kLHintsTop, 0, 7, 3, 4));
00430 
00431    // Text buttons Apply & Ignore for rebinned histogram shown on the screen.
00432    TGCompositeFrame *f24 = new TGCompositeFrame(fBinXCont, 118, 20,
00433                                                            kHorizontalFrame |
00434                                                            kFixedWidth);
00435    fApply = new TGTextButton(f24, " &Apply ");
00436    f24->AddFrame(fApply,
00437                  new TGLayoutHints(kLHintsExpandX | kLHintsLeft ,0, 3, 4, 4));
00438    fCancel = new TGTextButton(f24, " &Ignore ");
00439    f24->AddFrame(fCancel,
00440                  new TGLayoutHints(kLHintsExpandX | kLHintsLeft, 3, 0, 4, 4));
00441    fBinXCont->AddFrame(f24, new TGLayoutHints(kLHintsTop, 20, 3, 3, 4));
00442    fBin->AddFrame(fBinXCont,new TGLayoutHints(kLHintsTop));
00443 
00444    // Widgets for rebinning a histogram which derives from an Ntuple
00445 
00446    fBinXCont1 = new TGCompositeFrame(fBin, 80, 20, kVerticalFrame);
00447    TGCompositeFrame *title2 = new TGCompositeFrame(fBinXCont1, 145, 10,
00448                                                                kHorizontalFrame |
00449                                                                kLHintsExpandX   |
00450                                                                kFixedWidth      |
00451                                                                kOwnBackground);
00452    title2->AddFrame(new TGLabel(title2, "X-Axis"),
00453                     new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00454    title2->AddFrame(new TGHorizontal3DLine(title2),
00455                     new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00456    fBinXCont1->AddFrame(title2, new TGLayoutHints(kLHintsTop, 0, 0, 2, 0));
00457 
00458    TGCompositeFrame *f26 = new TGCompositeFrame(fBinXCont1, 80, 20,
00459                                                             kHorizontalFrame);
00460    fBinXSlider1  = new TGHSlider(f26, 100, kSlider1 | kScaleBoth);
00461    fBinXSlider1->Resize(120,20);
00462    fBinXSlider1->SetRange(1,9);
00463    fBinXSlider1->SetScale(14);
00464    fBinXSlider1->SetPosition(5);
00465    f26->AddFrame(fBinXSlider1, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
00466    fBinXCont1->AddFrame(f26, new TGLayoutHints(kLHintsTop, 3, 7, 3, 0));
00467 
00468    // Lettering of the Rebin Slider
00469    TGCompositeFrame *f27 = new TGCompositeFrame(fBinXCont1, 80, 20,
00470                                                             kHorizontalFrame);
00471    TGLabel *l1 = new TGLabel(f27, "-5");
00472    f27->AddFrame(l1, new TGLayoutHints(kLHintsLeft, 5, 1, -1, 0));
00473    TGLabel *l2 = new TGLabel(f27, "-2");
00474    f27->AddFrame(l2, new TGLayoutHints(kLHintsLeft, 31, 2, -1, 0));
00475    TGLabel *l3 = new TGLabel(f27, "2");
00476    f27->AddFrame(l3, new TGLayoutHints(kLHintsLeft, 21, 2, -1, 0));
00477    TGLabel *l4 = new TGLabel(f27, "5");
00478    f27->AddFrame(l4, new TGLayoutHints(kLHintsLeft, 36, 3, -1, 0));
00479    fBinXCont1->AddFrame(f27, new TGLayoutHints(kLHintsTop, 0, 0, 0, 0));
00480 
00481    TGCompositeFrame *f28 = new TGCompositeFrame(fBinXCont1, 140, 20,
00482                                                             kHorizontalFrame);
00483    TGLabel *binXLabel2 = new TGLabel(f28, "# of Bins:");
00484    f28->AddFrame(binXLabel2, new TGLayoutHints(kLHintsLeft, 8, 1, 4, 1));
00485 
00486    fBinXNumberEntry1 = new TGNumberEntryField(f28, kBINXSLIDER1, 0.0,
00487                                               TGNumberFormat::kNESInteger);
00488    ((TGTextEntry*)fBinXNumberEntry1)->SetToolTipText("Set the number of x axis bins in the rebinned histogram");
00489    fBinXNumberEntry1->Resize(57,20);
00490    f28->AddFrame(fBinXNumberEntry1,
00491                  new TGLayoutHints(kLHintsLeft, 21, 0, 2, 0));
00492    fBinXCont1->AddFrame(f28, new TGLayoutHints(kLHintsTop, 0, 7, 2, 4));
00493 
00494    TGCompositeFrame *f29 = new TGCompositeFrame(fBinXCont1, 80, 20,
00495                                                 kHorizontalFrame);
00496    TGLabel *xOffsetLbl = new TGLabel(f29, "BinOffset:");
00497    f29->AddFrame(xOffsetLbl, new TGLayoutHints(kLHintsLeft, 7, 1, 2, 1));
00498    fXOffsetNumberEntry = new TGNumberEntryField(f29, kXBINOFFSET, 0.0,
00499                                                 TGNumberFormat::kNESRealFour,
00500                                                 TGNumberFormat::kNEAAnyNumber,
00501                                                 TGNumberFormat::kNELLimitMinMax,
00502                                                 0., 1.);
00503    ((TGTextEntry*)fXOffsetNumberEntry)->SetToolTipText("Add an x-offset to the origin of the histogram");
00504    fXOffsetNumberEntry->Resize(57,20);
00505    f29->AddFrame(fXOffsetNumberEntry,
00506                  new TGLayoutHints(kLHintsRight, 21, 0, 0, 0));
00507    fBinXCont1->AddFrame(f29, new TGLayoutHints(kLHintsTop, 0, 7, 3, 1));
00508 
00509    TGCompositeFrame *f30 = new TGCompositeFrame(fBinXCont1, 80, 20,
00510                                                             kHorizontalFrame);
00511    fXBinOffsetSld  = new TGHSlider(f30, 100, kSlider1 | kScaleBoth);
00512    fXBinOffsetSld->Resize(120,20);
00513    f30->AddFrame(fXBinOffsetSld, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
00514    fBinXCont1->AddFrame(f30, new TGLayoutHints(kLHintsTop, 3, 7, 3, 3));
00515    fBin->AddFrame(fBinXCont1, new TGLayoutHints(kLHintsTop));
00516 
00517    // Same for Y-Axis:
00518    // Widgets for rebinning a histogram which derives from an Ntuple
00519 
00520    fBinYCont1 = new TGCompositeFrame(fBin, 80, 20, kVerticalFrame);
00521    TGCompositeFrame *title3 = new TGCompositeFrame(fBinYCont1, 145, 10,
00522                                                                kHorizontalFrame |
00523                                                                kLHintsExpandX   |
00524                                                                kFixedWidth      |
00525                                                                kOwnBackground);
00526    title3->AddFrame(new TGLabel(title3, "Y-Axis"),
00527                     new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00528    title3->AddFrame(new TGHorizontal3DLine(title3),
00529                     new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00530    fBinYCont1->AddFrame(title3, new TGLayoutHints(kLHintsTop, 0, 0, 7, 0));
00531 
00532    TGCompositeFrame *f31 = new TGCompositeFrame(fBinYCont1, 80, 20,
00533                                                             kHorizontalFrame);
00534    fBinYSlider1  = new TGHSlider(f31, 100, kSlider1 | kScaleBoth);
00535    fBinYSlider1->Resize(120,20);
00536    fBinYSlider1->SetRange(1,9);
00537    fBinYSlider1->SetScale(14);
00538    fBinYSlider1->SetPosition(5);
00539    f31->AddFrame(fBinYSlider1, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
00540    fBinYCont1->AddFrame(f31, new TGLayoutHints(kLHintsTop, 3, 7, 3, 0));
00541 
00542    //  Lettering of the Rebin Slider
00543    TGCompositeFrame *f32 = new TGCompositeFrame(fBinYCont1, 80, 20,
00544                                                             kHorizontalFrame);
00545    TGLabel *l5 = new TGLabel(f32, "-5");
00546    f32->AddFrame(l5, new TGLayoutHints(kLHintsLeft, 5, 1, -1, 0));
00547    TGLabel *l6 = new TGLabel(f32, "-2");
00548    f32->AddFrame(l6, new TGLayoutHints(kLHintsLeft, 31, 2, -1, 0));
00549    TGLabel *l7 = new TGLabel(f32, "2");
00550    f32->AddFrame(l7, new TGLayoutHints(kLHintsLeft, 21, 2, -1, 0));
00551    TGLabel *l8 = new TGLabel(f32, "5");
00552    f32->AddFrame(l8, new TGLayoutHints(kLHintsLeft, 36, 3, -1, 0));
00553    fBinYCont1->AddFrame(f32, new TGLayoutHints(kLHintsTop, 0, 0, 0, 0));
00554 
00555    TGCompositeFrame *f33 = new TGCompositeFrame(fBinYCont1, 140, 20,
00556                                                             kHorizontalFrame);
00557    TGLabel *binYLabel2 = new TGLabel(f33, "# of Bins:");
00558    f33->AddFrame(binYLabel2, new TGLayoutHints(kLHintsLeft, 8, 1, 4, 1));
00559 
00560    fBinYNumberEntry1 = new TGNumberEntryField(f33, kBINYSLIDER1, 0.0,
00561                                               TGNumberFormat::kNESInteger);
00562    ((TGTextEntry*)fBinYNumberEntry1)->SetToolTipText("Set the number of Y axis bins in the rebinned histogram");
00563    fBinYNumberEntry1->Resize(57,20);
00564    f33->AddFrame(fBinYNumberEntry1,
00565                  new TGLayoutHints(kLHintsLeft, 21, 0, 2, 0));
00566    fBinYCont1->AddFrame(f33, new TGLayoutHints(kLHintsTop, 0, 7, 2, 4));
00567 
00568    TGCompositeFrame *f34 = new TGCompositeFrame(fBinYCont1, 80, 20,
00569                                                             kHorizontalFrame);
00570    TGLabel *yOffsetLbl = new TGLabel(f34, "BinOffset:");
00571    f34->AddFrame(yOffsetLbl, new TGLayoutHints(kLHintsLeft, 7, 1, 2, 1));
00572    fYOffsetNumberEntry = new TGNumberEntryField(f34, kYBINOFFSET, 0.0,
00573                                                 TGNumberFormat::kNESRealFour,
00574                                                 TGNumberFormat::kNEAAnyNumber,
00575                                                 TGNumberFormat::kNELLimitMinMax,
00576                                                 0., 1.);
00577    ((TGTextEntry*)fYOffsetNumberEntry)->SetToolTipText("Add an Y-offset to the origin of the histogram");
00578    fYOffsetNumberEntry->Resize(57,20);
00579    f34->AddFrame(fYOffsetNumberEntry,
00580                  new TGLayoutHints(kLHintsRight, 21, 0, 0, 0));
00581    fBinYCont1->AddFrame(f34, new TGLayoutHints(kLHintsTop, 0, 7, 3, 1));
00582 
00583    TGCompositeFrame *f35 = new TGCompositeFrame(fBinYCont1, 80, 20,
00584                                                             kHorizontalFrame);
00585    fYBinOffsetSld  = new TGHSlider(f35, 100, kSlider1 | kScaleBoth);
00586    fYBinOffsetSld->Resize(120,20);
00587    fYBinOffsetSld->Associate(f35);
00588    f35->AddFrame(fYBinOffsetSld, new TGLayoutHints(kLHintsLeft, 2,0,0,0));
00589    fBinYCont1->AddFrame(f35, new TGLayoutHints(kLHintsTop, 3, 7, 3, 3));
00590    fBin->AddFrame(fBinYCont1, new TGLayoutHints(kLHintsTop));
00591 
00592    // Axis ranges
00593    TGCompositeFrame *title4 = new TGCompositeFrame(fBin, 145, 10,
00594                                                          kHorizontalFrame |
00595                                                          kLHintsExpandX   |
00596                                                          kFixedWidth      |
00597                                                          kOwnBackground);
00598    title4->AddFrame(new TGLabel(title4, "Axis Range"),
00599                     new TGLayoutHints(kLHintsLeft, 1, 1, 0, 0));
00600    title4->AddFrame(new TGHorizontal3DLine(title4),
00601                     new TGLayoutHints(kLHintsExpandX, 5, 5, 7, 7));
00602    fBin->AddFrame(title4, new TGLayoutHints(kLHintsTop, 0, 0, 5, 0));
00603 
00604    TGCompositeFrame *f14 = new TGCompositeFrame(fBin, 80, 20, kHorizontalFrame);
00605    TGLabel *fSliderXLbl = new TGLabel(f14,"x:");
00606    f14->AddFrame(fSliderXLbl,
00607                  new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 4,3, 2, 1));
00608    fSliderX = new TGDoubleHSlider(f14, 1, 2);
00609    fSliderX->Resize(119,20);
00610    f14->AddFrame(fSliderX, new TGLayoutHints(kLHintsLeft));
00611    fBin->AddFrame(f14, new TGLayoutHints(kLHintsTop, 3, 7, 4, 1));
00612 
00613    TGCompositeFrame *f17 = new TGCompositeFrame(fBin, 80, 20, kHorizontalFrame);
00614    fSldXMin = new TGNumberEntryField(f17, kSLIDERX_MIN, 0.0,
00615                                      TGNumberFormat::kNESRealTwo,
00616                                      TGNumberFormat::kNEAAnyNumber);
00617    ((TGTextEntry*)fSldXMin)->SetToolTipText("Set the minimum value of the x-axis");
00618    fSldXMin->Resize(57,20);
00619    f17->AddFrame(fSldXMin, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
00620    fSldXMax = new TGNumberEntryField(f17, kSLIDERX_MAX, 0.0,
00621                                      TGNumberFormat::kNESRealTwo,
00622                                      TGNumberFormat::kNEAAnyNumber);
00623    ((TGTextEntry*)fSldXMax)->SetToolTipText("Set the maximum value of the x-axis");
00624    fSldXMax->Resize(57,20);
00625    f17->AddFrame(fSldXMax, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
00626    fBin->AddFrame(f17, new TGLayoutHints(kLHintsTop, 20, 3, 5, 0));
00627 
00628    TGCompositeFrame *f15 = new TGCompositeFrame(fBin, 80, 20, kHorizontalFrame);
00629    TGLabel *fSliderYLbl = new TGLabel(f15,"y:");
00630    f15->AddFrame(fSliderYLbl,
00631                  new TGLayoutHints(kLHintsCenterY | kLHintsLeft, 4,2, 4, 1));
00632    fSliderY = new TGDoubleHSlider(f15, 1, 2);
00633    fSliderY->Resize(119,20);
00634    f15->AddFrame(fSliderY, new TGLayoutHints(kLHintsLeft));
00635    fBin->AddFrame(f15, new TGLayoutHints(kLHintsTop, 3, 7, 4, 1));
00636 
00637    TGCompositeFrame *f18 = new TGCompositeFrame(fBin, 80, 20, kHorizontalFrame);
00638    fSldYMin = new TGNumberEntryField(f18, kSLIDERY_MIN, 0.0,
00639                                      TGNumberFormat::kNESRealTwo,
00640                                      TGNumberFormat::kNEAAnyNumber);
00641    ((TGTextEntry*)fSldYMin)->SetToolTipText("Set the minimum value of the y-axis");
00642    fSldYMin->Resize(57,20);
00643    f18->AddFrame(fSldYMin, new TGLayoutHints(kLHintsLeft, 0, 0, 0, 0));
00644    fSldYMax = new TGNumberEntryField(f18, kSLIDERY_MAX, 0.0,
00645                                      TGNumberFormat::kNESRealTwo,
00646                                      TGNumberFormat::kNEAAnyNumber);
00647    ((TGTextEntry*)fSldYMax)->SetToolTipText("Set the maximum value of the y-axis");
00648    fSldYMax->Resize(57,20);
00649    f18->AddFrame(fSldYMax, new TGLayoutHints(kLHintsLeft, 4, 0, 0, 0));
00650    fBin->AddFrame(f18, new TGLayoutHints(kLHintsTop, 20, 3, 5, 0));
00651 
00652    TGCompositeFrame *f20 = new TGCompositeFrame(fBin, 80, 20, kVerticalFrame);
00653    fDelaydraw = new TGCheckButton(f20, "Delayed drawing", kDELAYED_DRAWING);
00654    fDelaydraw ->SetToolTipText("Draw the new axis range when the Slider is released");
00655    f20->AddFrame(fDelaydraw, new TGLayoutHints(kLHintsLeft, 6, 1, 1, 0));
00656    fBin->AddFrame(f20, new TGLayoutHints(kLHintsTop, 2, 1, 5, 3));
00657 
00658    fXBinOffsetSld->SetRange(0,100);
00659    fXBinOffsetSld->SetPosition(0);
00660    fXOffsetNumberEntry->SetNumber(0.0000);
00661 
00662    fYBinOffsetSld->SetRange(0,100);
00663    fYBinOffsetSld->SetPosition(0);
00664    fYOffsetNumberEntry->SetNumber(0.0000);
00665 
00666    fCancel->SetState(kButtonDisabled);
00667    fApply->SetState(kButtonDisabled);
00668 
00669 }
00670 
00671 //______________________________________________________________________________
00672 TH2Editor::~TH2Editor()
00673 {
00674    // Destructor.
00675 
00676    // children of TGButonGroup are not deleted
00677    delete fDim;
00678    delete fDim0;
00679    delete fDimlh;
00680    delete fDim0lh;
00681 
00682    if (fBinHist) delete fBinHist;
00683    fBinHist = 0;
00684 }
00685 
00686 //______________________________________________________________________________
00687 void TH2Editor::ConnectSignals2Slots()
00688 {
00689    // Connect signals to slots.
00690 
00691    fTitle->Connect("TextChanged(const char *)", "TH2Editor", this, "DoTitle(const char *)");
00692    fDimGroup->Connect("Clicked(Int_t)","TH2Editor",this,"DoHistView()");
00693    fTypeCombo->Connect("Selected(Int_t)", "TH2Editor", this, "DoHistChanges()");
00694    fCoordsCombo->Connect("Selected(Int_t)", "TH2Editor", this, "DoHistChanges()");
00695    fContCombo->Connect("Selected(Int_t)", "TH2Editor", this, "DoHistChanges()");
00696    fAddArr->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddArr(Bool_t)");
00697    fAddBox->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddBox(Bool_t)");
00698    fAddCol->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddCol(Bool_t)");
00699    fAddScat->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddScat(Bool_t)");
00700    fAddText->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddText(Bool_t)");
00701    fAddError->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddError(Bool_t)");
00702    fAddPalette->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddPalette(Bool_t)");
00703    fAddPalette1->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddPalette(Bool_t)");
00704    fAddFB->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddFB()");
00705    fAddBB->Connect("Toggled(Bool_t)", "TH2Editor", this, "DoAddBB()");
00706    fContLevels->Connect("ValueSet(Long_t)", "TH2Editor", this, "DoContLevel()");
00707    (fContLevels->GetNumberEntry())->Connect("ReturnPressed()", "TH2Editor",
00708                                              this,"DoContLevel()");
00709    fContLevels1->Connect("ValueSet(Long_t)", "TH2Editor", this, "DoContLevel1()");
00710    (fContLevels1->GetNumberEntry())->Connect("ReturnPressed()", "TH2Editor",
00711                                              this,"DoContLevel1()");
00712    fBarWidth->Connect("ValueSet(Long_t)", "TH2Editor", this, "DoBarWidth()");
00713    (fBarWidth->GetNumberEntry())->Connect("ReturnPressed()", "TH2Editor",
00714                                            this, "DoBarWidth()");
00715    fBarOffset->Connect("ValueSet(Long_t)", "TH2Editor", this, "DoBarOffset()");
00716    (fBarOffset->GetNumberEntry())->Connect("ReturnPressed()", "TH2Editor",
00717                                            this, "DoBarOffset()");
00718    fBinXSlider->Connect("PositionChanged(Int_t)","TH2Editor",this, "DoBinMoved()");
00719    fBinXSlider->Connect("Released()","TH2Editor",this, "DoBinReleased()");
00720    fBinXSlider->Connect("Pressed()","TH2Editor",this, "DoBinPressed()");
00721    fBinYSlider->Connect("PositionChanged(Int_t)","TH2Editor",this, "DoBinMoved()");
00722    fBinYSlider->Connect("Released()","TH2Editor",this, "DoBinReleased()");
00723    fBinYSlider->Connect("Pressed()","TH2Editor",this, "DoBinPressed()");
00724    fBinXNumberEntry->Connect("ReturnPressed()", "TH2Editor", this, "DoBinLabel()");
00725    fBinYNumberEntry->Connect("ReturnPressed()", "TH2Editor", this, "DoBinLabel()");
00726    fApply->Connect("Clicked()", "TH2Editor", this, "DoApply()");
00727    fCancel->Connect("Pressed()", "TH2Editor", this, "DoCancel()");
00728    fBinXSlider1->Connect("Released()","TH2Editor",this, "DoBinReleased1()");
00729    fBinXSlider1->Connect("PositionChanged(Int_t)","TH2Editor",this, "DoBinMoved1()");
00730    fBinXNumberEntry1->Connect("ReturnPressed()", "TH2Editor", this, "DoBinLabel1()");
00731    fXBinOffsetSld->Connect("PositionChanged(Int_t)","TH2Editor",this, "DoOffsetMoved()");
00732    fXBinOffsetSld->Connect("Released()","TH2Editor",this, "DoOffsetReleased()");
00733    fXBinOffsetSld->Connect("Pressed()","TH2Editor",this, "DoOffsetPressed()");
00734    fXOffsetNumberEntry->Connect("ReturnPressed()", "TH2Editor", this, "DoBinOffset()");
00735    fBinYSlider1->Connect("Released()","TH2Editor",this, "DoBinReleased1()");
00736    fBinYSlider1->Connect("PositionChanged(Int_t)","TH2Editor",this, "DoBinMoved1()");
00737    fBinYNumberEntry1->Connect("ReturnPressed()", "TH2Editor", this, "DoBinLabel1()");
00738    fYBinOffsetSld->Connect("PositionChanged(Int_t)","TH2Editor",this,"DoOffsetMoved()");
00739    fYBinOffsetSld->Connect("Released()","TH2Editor",this, "DoOffsetReleased()");
00740    fYBinOffsetSld->Connect("Pressed()","TH2Editor",this, "DoOffsetPressed()");
00741    fYOffsetNumberEntry->Connect("ReturnPressed()", "TH2Editor", this,"DoBinOffset()");
00742    fSliderX->Connect("PositionChanged()","TH2Editor",this, "DoSliderXMoved()");
00743    fSliderX->Connect("Pressed()","TH2Editor",this, "DoSliderXPressed()");
00744    fSliderX->Connect("Released()","TH2Editor",this, "DoSliderXReleased()");
00745    fSldXMin->Connect("ReturnPressed()", "TH2Editor", this, "DoXAxisRange()");
00746    fSldXMax->Connect("ReturnPressed()", "TH2Editor", this, "DoXAxisRange()");
00747    fSliderY->Connect("PositionChanged()","TH2Editor",this, "DoSliderYMoved()");
00748    fSliderY->Connect("Pressed()","TH2Editor",this, "DoSliderYPressed()");
00749    fSliderY->Connect("Released()","TH2Editor",this, "DoSliderYReleased()");
00750    fSldYMin->Connect("ReturnPressed()", "TH2Editor", this, "DoYAxisRange()");
00751    fSldYMax->Connect("ReturnPressed()", "TH2Editor", this, "DoYAxisRange()");
00752    fFrameColor->Connect("ColorSelected(Pixel_t)", "TH2Editor", this, "DoFillColor(Pixel_t)");
00753    fFramePattern->Connect("PatternSelected(Style_t)", "TH2Editor", this, "DoFillPattern(Style_t)");
00754 
00755    fInit = kFALSE;
00756 }
00757 
00758 //______________________________________________________________________________
00759 Bool_t TH2Editor::AcceptModel(TObject* obj)
00760 {
00761    // Check if object is able to configure with this editor.
00762 
00763    if (obj == 0 || !obj->InheritsFrom(TH2::Class()) ||
00764        (!strcmp(((TH2 *)obj)->GetName(),"htemp") &&
00765         ((TH2*)obj)->GetEntries() == 0)) {  // htemp is an empty histogram
00766       return kFALSE;
00767    }
00768    return kTRUE;
00769 }
00770 
00771 //______________________________________________________________________________
00772 void TH2Editor::SetModel(TObject* obj)
00773 {
00774    // Pick up the values of current histogram attributes.
00775 
00776    fAvoidSignal = kTRUE;
00777    if (fBinHist && (obj != fHist)) {
00778       //we have probably moved to a different pad.
00779       //let's restore the original histogram
00780       fHist->Reset();
00781       fHist->SetBins(fBinHist->GetXaxis()->GetNbins(),
00782                      fBinHist->GetXaxis()->GetXmin(),
00783                      fBinHist->GetXaxis()->GetXmax(),
00784                      fBinHist->GetYaxis()->GetNbins(),
00785                      fBinHist->GetYaxis()->GetXmin(),
00786                      fBinHist->GetYaxis()->GetXmax());
00787       fHist->Add(fBinHist);
00788       delete fBinHist;
00789       fBinHist = 0;
00790       if (fGedEditor->GetPad()) {
00791          fGedEditor->GetPad()->Modified();
00792          fGedEditor->GetPad()->Update();
00793       }
00794    }
00795 
00796    fHist = (TH2*) obj;
00797 
00798    const char *text = fHist->GetTitle();
00799    fTitle->SetText(text);
00800    TString str = GetDrawOption();
00801    fCutString = GetCutOptionString();
00802    str.ToUpper();
00803 
00804    if (str == "") {
00805       // default options = Scatter-Plot
00806       ShowFrame(f6);
00807       HideFrame(f9);
00808       HideFrame(f12);
00809       HideFrame(f13);
00810       HideFrame(f38);
00811       fDimGroup->SetButton(kDIM_SIMPLE, kTRUE);
00812       fDimGroup->SetButton(kDIM_COMPLEX, kFALSE);
00813       if (fTypeCombo->GetSelected()==-1) fTypeCombo->Select(kTYPE_LEGO);
00814       if (fCoordsCombo->GetSelected()==-1) fCoordsCombo->Select(kCOORDS_CAR);
00815       if (fContCombo->GetSelected()==-1) fContCombo->Select(kCONT_NONE);
00816 
00817       fAddArr->SetState(kButtonUp);
00818       fAddBox->SetState(kButtonUp);
00819       fAddCol->SetState(kButtonUp);
00820       fAddScat->SetState(kButtonDisabled);
00821       fAddText->SetState(kButtonUp);
00822       fAddError->SetState(kButtonUp);
00823       fAddPalette->SetState(kButtonDisabled);
00824       fAddPalette1->SetState(kButtonUp);
00825       fAddFB->SetState(kButtonDown);
00826       fAddBB->SetState(kButtonDown);
00827    } else if (!str.Contains("LEGO") && !str.Contains("SURF")) {
00828       ShowFrame(f6);
00829       HideFrame(f9);
00830       HideFrame(f12);
00831       HideFrame(f13);
00832       HideFrame(f38);
00833       fDimGroup->SetButton(kDIM_SIMPLE, kTRUE);
00834       fDimGroup->SetButton(kDIM_COMPLEX, kFALSE);
00835       if (fTypeCombo->GetSelected()==-1) fTypeCombo->Select(kTYPE_LEGO);
00836       if (fCoordsCombo->GetSelected()==-1) fCoordsCombo->Select(kCOORDS_CAR);
00837       if (str.Contains("CONT")){
00838          if (str.Contains("CONT1")) fContCombo->Select(kCONT_1);
00839          else if (str.Contains("CONT2")) fContCombo->Select(kCONT_2);
00840          else if (str.Contains("CONT3")) fContCombo->Select(kCONT_3);
00841          else if (str.Contains("CONT4")) fContCombo->Select(kCONT_4);
00842          else if (str.Contains("CONT0") || str.Contains("CONT"))
00843             fContCombo->Select(kCONT_0);
00844       } else fContCombo->Select(kCONT_NONE);
00845 
00846       if (str.Contains("ARR")) fAddArr->SetState(kButtonDown);
00847       else fAddArr->SetState(kButtonUp);
00848       if (str.Contains("BOX")) fAddBox->SetState(kButtonDown);
00849       else fAddBox->SetState(kButtonUp);
00850       if (str.Contains("COL")) fAddCol->SetState(kButtonDown);
00851       else fAddCol->SetState(kButtonUp);
00852       if (str.Contains("SCAT")) {
00853          if (str=="SCAT") fAddScat->SetState(kButtonDisabled);
00854          else fAddScat->SetState(kButtonDown);
00855       } else fAddScat->SetState(kButtonUp);
00856       if (str.Contains("TEXT")) fAddText->SetState(kButtonDown);
00857       else fAddText->SetState(kButtonUp);
00858 
00859       fAddError->SetState(kButtonUp);
00860       if (str.Contains("COL") || (str.Contains("CONT") &&
00861           !str.Contains("CONT2") && !str.Contains("CONT3"))) {
00862          if (str.Contains("Z")) fAddPalette->SetState(kButtonDown);
00863          else fAddPalette->SetState(kButtonUp);
00864       } else fAddPalette->SetState(kButtonDisabled);
00865       fAddPalette1->SetState(kButtonUp);
00866       fAddFB->SetState(kButtonDown);
00867       fAddBB->SetState(kButtonDown);
00868 
00869    } else if (str.Contains("LEGO") || str.Contains("SURF")) {
00870       HideFrame(f6);
00871       ShowFrame(f9);
00872       ShowFrame(f12);
00873       ShowFrame(f13);
00874       ShowFrame(f38);
00875       fDimGroup->SetButton(kDIM_COMPLEX, kTRUE);
00876       fDimGroup->SetButton(kDIM_SIMPLE, kFALSE);
00877       if (str.Contains("LEGO2")) fTypeCombo->Select(kTYPE_LEGO2);
00878       else if (str.Contains("LEGO1")) fTypeCombo->Select(kTYPE_LEGO1);
00879       else if (str.Contains("LEGO"))  fTypeCombo->Select(kTYPE_LEGO);
00880       else if (str.Contains("SURF5")) fTypeCombo->Select(kTYPE_SURF5);
00881       else if (str.Contains("SURF4")) fTypeCombo->Select(kTYPE_SURF4);
00882       else if (str.Contains("SURF3")) fTypeCombo->Select(kTYPE_SURF3);
00883       else if (str.Contains("SURF2")) fTypeCombo->Select(kTYPE_SURF2);
00884       else if (str.Contains("SURF1")) fTypeCombo->Select(kTYPE_SURF1);
00885       else if (str.Contains("SURF")) fTypeCombo->Select(kTYPE_SURF);
00886 
00887 
00888       if (str.Contains("CYL")) fCoordsCombo->Select(kCOORDS_CYL);
00889       else if (str.Contains("POL")) fCoordsCombo->Select(kCOORDS_POL);
00890       else if (str.Contains("SPH")) fCoordsCombo->Select(kCOORDS_SPH);
00891       else if (str.Contains("PSR")) fCoordsCombo->Select(kCOORDS_PSR);
00892       else fCoordsCombo->Select(kCOORDS_CAR); //default
00893 
00894       if (fContCombo->GetSelected()==-1) fContCombo->Select(kCONT_NONE);
00895       fAddArr->SetState(kButtonUp);
00896       fAddBox->SetState(kButtonUp);
00897       fAddCol->SetState(kButtonUp);
00898       fAddScat->SetState(kButtonDisabled);
00899       fAddText->SetState(kButtonUp);
00900 
00901       if (fCoordsCombo->GetSelected()!=kCOORDS_CAR) {
00902          if (fAddFB->GetState()!=kButtonDisabled)
00903             fAddFB->SetState(kButtonDisabled);
00904          if (fAddBB->GetState()!=kButtonDisabled)
00905             fAddBB->SetState(kButtonDisabled);
00906          if (fAddError->GetState()!=kButtonDisabled)
00907             fAddError->SetState(kButtonDisabled);
00908       } else {
00909          if (str.Contains("FB")) fAddFB->SetState(kButtonUp);
00910          else fAddFB->SetState(kButtonDown);
00911          if (str.Contains("BB")) fAddBB->SetState(kButtonUp);
00912          else fAddBB->SetState(kButtonDown);
00913          if (str.Contains("E")){
00914             TString dum = str;
00915             if (str.Contains("LEGO"))
00916                dum.Remove(strstr(dum.Data(),"LEGO")-dum.Data(),4);
00917             if (str.Contains("TEXT"))
00918                dum.Remove(strstr(dum.Data(),"TEXT")-dum.Data(),4);
00919             if (dum.Contains("E")) fAddError->SetState(kButtonDown);
00920             else fAddError->SetState(kButtonUp);
00921          } else fAddError->SetState(kButtonUp);
00922       }
00923       if ((fTypeCombo->GetSelected()==kTYPE_LEGO) ||
00924           (fTypeCombo->GetSelected()==kTYPE_LEGO1)||
00925           (fTypeCombo->GetSelected()==kTYPE_SURF) ||
00926           (fTypeCombo->GetSelected()==kTYPE_SURF4))
00927          fAddPalette1->SetState(kButtonDisabled);
00928       else if (str.Contains("Z")) fAddPalette1->SetState(kButtonDown);
00929       else fAddPalette1->SetState(kButtonUp);
00930    }
00931 
00932    fBarWidth->SetNumber(fHist->GetBarWidth());
00933    fBarOffset->SetNumber(fHist->GetBarOffset());
00934 
00935    Int_t nx = fHist -> GetXaxis() -> GetNbins();
00936    Int_t nxbinmin = fHist -> GetXaxis() -> GetFirst();
00937    Int_t nxbinmax = fHist -> GetXaxis() -> GetLast();
00938    fSliderX->SetRange(1,nx);
00939    fSliderX->SetPosition((Double_t)nxbinmin,(Double_t)nxbinmax);
00940    fSldXMin->SetNumber(fHist->GetXaxis()->GetBinLowEdge(nxbinmin));
00941    fSldXMax->SetNumber(fHist->GetXaxis()->GetBinUpEdge(nxbinmax));
00942 
00943    Int_t ny = fHist -> GetYaxis() -> GetNbins();
00944    Int_t nybinmin = fHist -> GetYaxis() -> GetFirst();
00945    Int_t nybinmax = fHist -> GetYaxis() -> GetLast();
00946    fSliderY->SetRange(1,ny);
00947    fSliderY->SetPosition((Double_t)nybinmin,(Double_t)nybinmax);
00948    fSldYMin->SetNumber(fHist->GetYaxis()->GetBinLowEdge(nybinmin));
00949    fSldYMax->SetNumber(fHist->GetYaxis()->GetBinUpEdge(nybinmax));
00950 
00951    if (fDelaydraw->GetState()!=kButtonDown) fDelaydraw->SetState(kButtonUp);
00952 
00953    if (str.Contains("COL") || fContCombo->GetSelected()!= kCONT_NONE)
00954       fColContLbl->Enable() ;
00955    else fColContLbl->Disable();
00956 
00957    if (str.Contains("LEGO2") || str.Contains("SURF1") ||
00958        str.Contains("SURF2") || str.Contains("SURF3") ||
00959        str.Contains("SURF5")) fColContLbl1->Enable();
00960    else fColContLbl1->Disable();
00961 
00962    fContLevels->SetIntNumber(fHist->GetContour());
00963    fContLevels1->SetIntNumber(fHist->GetContour());
00964 
00965    fFrameColor->SetColor(TColor::Number2Pixel(fGedEditor->GetPad()->GetFrameFillColor()));
00966    fFramePattern->SetPattern(fGedEditor->GetPad()->GetFrameFillStyle());
00967 
00968    TTreePlayer *player = (TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer();
00969 
00970    if (!player || player->GetHistogram()!=fHist ) {
00971       Int_t n1 = 0, n2 =0;
00972       Int_t upx =0, upy =0;
00973       if (fBinHist) n1 = fBinHist->GetXaxis()->GetNbins();
00974       else n1 = nx;
00975       if (fBinHist) n2 = fBinHist->GetYaxis()->GetNbins();
00976       else n2 = ny;
00977       fBin->HideFrame(fBinXCont1);
00978       fBin->ShowFrame(fBinXCont);
00979       fBin->HideFrame(fBinYCont1);
00980       if (n1 < 1) n1 = 1;
00981       if (n2 < 1) n2 = 1;
00982       Int_t* divx = Dividers(n1);
00983       Int_t* divy = Dividers(n2);
00984       if (divx[0]-1 <= 1) upx = 2;
00985       else upx = divx[0]-1;
00986       fBinXSlider->SetRange(1,upx);
00987       if (divy[0]-1 <= 1) upy = 2;
00988       else upy = divy[0]-1;
00989       fBinYSlider->SetRange(1,upy);
00990       Int_t i = 1; Int_t j = 1;
00991       if (fBinXSlider->GetMaxPosition()==2 && fBinXSlider->GetPosition()==2)
00992          fBinXSlider->SetPosition(2);
00993       else {
00994          while ( divx[i] != nx) i ++;
00995          fBinXSlider->SetPosition(divx[0] - i + 1);
00996       }
00997       if (fBinYSlider->GetMaxPosition()==2 && fBinYSlider->GetPosition()==2)
00998          fBinYSlider->SetPosition(2);
00999       else {
01000          while ( divy [j] != ny) j ++;
01001          fBinYSlider->SetPosition(divy[0] - j + 1);
01002       }
01003       fBinXNumberEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 2, n1);
01004       fBinXNumberEntry->SetIntNumber(nx);
01005       fBinYNumberEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 2, n2);
01006       fBinYNumberEntry->SetIntNumber(ny);
01007       delete [] divx;
01008       delete [] divy;
01009    }
01010    else if (fHist==player->GetHistogram()) {
01011       fBin->HideFrame(fBinXCont);
01012       fBin->ShowFrame(fBinXCont1);
01013       fBin->ShowFrame(fBinYCont1);
01014       fBinXSlider1->SetPosition(5);
01015       fBinXNumberEntry1->SetLimits(TGNumberFormat::kNELLimitMinMax, 1, 1000);
01016       fBinXNumberEntry1->SetIntNumber(nxbinmax-nxbinmin+1);
01017       fBinYSlider1->SetPosition(5);
01018       fBinYNumberEntry1->SetLimits(TGNumberFormat::kNELLimitMinMax, 1, 1000);
01019       fBinYNumberEntry1->SetIntNumber(nybinmax-nybinmin+1);
01020    }
01021 
01022    fXOffsetNumberEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0,
01023                                   fHist->GetXaxis()->GetBinWidth(1));
01024    fYOffsetNumberEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0,
01025                                   fHist->GetYaxis()->GetBinWidth(1));
01026    if (!fGedEditor->GetTab()->IsEnabled(fGedEditor->GetTab()->GetCurrent())) fGedEditor->GetTab()->SetTab(0);
01027 
01028    if (fInit) ConnectSignals2Slots();
01029    fGedEditor->GetTab()->SetEnabled(1, kTRUE);
01030    fAvoidSignal = kFALSE;
01031 }
01032 
01033 //______________________________________________________________________________
01034 void TH2Editor::DoTitle(const char *text)
01035 {
01036    // Slot connected to the histogram title setting.
01037 
01038    if (fAvoidSignal) return;
01039    fHist->SetTitle(text);
01040    Update();
01041 }
01042 
01043 //______________________________________________________________________________
01044 void TH2Editor::DoHistView()
01045 {
01046    // Slot connected to the 'Plot' button group.
01047 
01048    if (gPad) gPad->GetVirtCanvas()->SetCursor(kWatch);
01049    gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kWatch));
01050 
01051    if (fDim->GetState() == kButtonDown)
01052       DoHistSimple();
01053    else
01054       DoHistComplex();
01055 
01056    if (gPad) gPad->GetVirtCanvas()->SetCursor(kPointer);
01057    gVirtualX->SetCursor(GetId(), gVirtualX->CreateCursor(kPointer));
01058 }
01059 
01060 //______________________________________________________________________________
01061 void TH2Editor::DoHistSimple()
01062 {
01063    // Slot connected to the 2D-Plot radio button.
01064 
01065    if (fAvoidSignal) return;
01066    TString str = "";
01067    ShowFrame(f6);
01068    HideFrame(f9);
01069    HideFrame(f12);
01070    HideFrame(f13);
01071    HideFrame(f38);
01072    if (fContCombo->GetSelected()==-1)
01073       fContCombo->Select(kCONT_NONE);
01074    if ((fContCombo->GetSelected()!= kCONT_NONE) &&
01075         fAddPalette->GetState()==kButtonDisabled)
01076       fAddPalette->SetState(kButtonUp);
01077 
01078    str = GetHistContLabel()+GetHistAdditiveLabel();
01079    if (str=="" || str=="SCAT" || str==fCutString) {
01080       fAddScat->SetState(kButtonDisabled);
01081       fAddPalette->SetState(kButtonDisabled);
01082    } else if (fAddScat->GetState()==kButtonDisabled)
01083       fAddScat->SetState(kButtonUp);
01084    if (str.Contains("COL") || fContCombo->GetSelected()!= kCONT_NONE)
01085       fColContLbl->Enable();
01086    else fColContLbl->Disable();
01087 
01088    ((TGMainFrame*)GetMainFrame())->Layout();
01089 
01090    TString ocut = fCutString;
01091    ocut.ToUpper();
01092    if (!str.Contains(fCutString) && !str.Contains(ocut))
01093       str+=fCutString;
01094    SetDrawOption(str);
01095    Update();
01096 }
01097 
01098 //______________________________________________________________________________
01099 void TH2Editor::DoHistComplex()
01100 {
01101    // Slot connected to the 3D-Plot radio button.
01102 
01103    if (fAvoidSignal) return;
01104    TString str = "";
01105    HideFrame(f6);
01106    ShowFrame(f9);
01107    ShowFrame(f38);
01108    if (GetHistTypeLabel().Contains("LEGO")) {
01109       ShowFrame(f12);
01110       ShowFrame(f13);
01111    } else {
01112       HideFrame(f12);
01113       HideFrame(f13);
01114    }
01115    if (fTypeCombo->GetSelected()==-1) fTypeCombo->Select(kTYPE_LEGO);
01116    if (fCoordsCombo->GetSelected()==-1) fCoordsCombo->Select(kCOORDS_CAR);
01117 
01118    str = GetHistTypeLabel()+GetHistCoordsLabel()+GetHistAdditiveLabel();
01119 
01120    if (str.Contains("LEGO2") || str.Contains("SURF1") ||
01121        str.Contains("SURF2") || str.Contains("SURF3") ||
01122        str.Contains("SURF5")) {
01123       fColContLbl1->Enable();
01124       if (fAddPalette1->GetState()==kButtonDisabled)
01125          fAddPalette1->SetState(kButtonUp);
01126    } else {
01127       fColContLbl1->Disable();
01128       fAddPalette1->SetState(kButtonDisabled);
01129    }
01130 
01131    ((TGMainFrame*)GetMainFrame())->Layout();
01132 
01133    TString ocut = fCutString;
01134    ocut.ToUpper();
01135    if (!str.Contains(fCutString) && !str.Contains(ocut))
01136       str+=fCutString;
01137    SetDrawOption(str);
01138    Update();
01139 }
01140 
01141 //______________________________________________________________________________
01142 void TH2Editor::DoHistChanges()
01143 {
01144    // Slot connected to histogram type, coordinate system, contour combo box.
01145 
01146    if (fAvoidSignal) return;
01147    TString str = "";
01148    if (fDim->GetState() == kButtonDown) {
01149       str = GetHistContLabel()+GetHistAdditiveLabel();
01150       if ((fContCombo->GetSelected()!=kCONT_NONE &&
01151            fContCombo->GetSelected()!=kCONT_2 &&
01152            fContCombo->GetSelected()!=kCONT_3) || str.Contains("COL")) {
01153 
01154          if (str.Contains("Z")) fAddPalette->SetState(kButtonDown);
01155          else fAddPalette->SetState(kButtonUp);
01156       } else fAddPalette->SetState(kButtonDisabled);
01157       if (str=="" || str=="SCAT" || str==fCutString) {
01158          fAddScat->SetState(kButtonDisabled);
01159          fAddPalette->SetState(kButtonDisabled);
01160       } else if (fAddScat->GetState()==kButtonDisabled)
01161          fAddScat->SetState(kButtonUp);
01162       str = GetHistContLabel()+GetHistAdditiveLabel();
01163       if (str.Contains("COL") || fContCombo->GetSelected()!= kCONT_NONE)
01164          fColContLbl->Enable();
01165       else
01166          fColContLbl->Disable();
01167 
01168    } else if (fDim0->GetState() == kButtonDown) {
01169       if (fCoordsCombo->GetSelected()!=kCOORDS_CAR) {
01170          if (fAddFB->GetState()!=kButtonDisabled)
01171             fAddFB->SetState(kButtonDisabled);
01172          if (fAddBB->GetState()!=kButtonDisabled)
01173             fAddBB->SetState(kButtonDisabled);
01174          if (fAddError->GetState()!=kButtonDisabled)
01175             fAddError->SetState(kButtonDisabled);
01176       } else {
01177          if (fAddFB->GetState()==kButtonDisabled)
01178             fAddFB->SetState(kButtonDown);
01179          if (fAddBB->GetState()==kButtonDisabled)
01180             fAddBB->SetState(kButtonDown);
01181          if (fAddError->GetState()==kButtonDisabled)
01182             fAddError->SetState(kButtonUp);
01183       }
01184       if ((fTypeCombo->GetSelected()==kTYPE_LEGO) ||
01185           (fTypeCombo->GetSelected()==kTYPE_LEGO1)||
01186           (fTypeCombo->GetSelected()==kTYPE_SURF) ||
01187           (fTypeCombo->GetSelected()==kTYPE_SURF4))
01188          fAddPalette1->SetState(kButtonDisabled);
01189       else if (fAddPalette1->GetState()==kButtonDisabled)
01190          fAddPalette1->SetState(kButtonUp);
01191       if (GetHistTypeLabel().Contains("LEGO")) {
01192          ShowFrame(f12);
01193          ShowFrame(f13);
01194       } else {
01195          HideFrame(f12);
01196          HideFrame(f13);
01197       }
01198       ((TGMainFrame*)GetMainFrame())->Layout();
01199       str = GetHistTypeLabel()+GetHistCoordsLabel()+GetHistAdditiveLabel();
01200       if (str.Contains("LEGO2") || str.Contains("SURF1") ||
01201           str.Contains("SURF2") || str.Contains("SURF3") ||
01202           str.Contains("SURF5"))
01203          fColContLbl1->Enable();
01204       else
01205          fColContLbl1->Disable() ;
01206    }
01207 
01208    TString ocut = fCutString;
01209    ocut.ToUpper();
01210    if (!str.Contains(fCutString) && !str.Contains(ocut))
01211       str+=fCutString;
01212    SetDrawOption(str);
01213    Update();
01214 }
01215 
01216 //______________________________________________________________________________
01217 void TH2Editor::DoAddArr(Bool_t on)
01218 {
01219    // Slot connected to the "Arrow draw option" check button.
01220 
01221    if (fAvoidSignal) return;
01222    Bool_t make=kFALSE;
01223    TString str = GetDrawOption();
01224    str.ToUpper();
01225 
01226    if (on) {
01227       if (!str.Contains("ARR")) {
01228          str += "ARR";
01229          if (fAddScat->GetState()==kButtonDisabled)
01230             fAddScat->SetState(kButtonUp);
01231          make=kTRUE;
01232       }
01233    } else if (fAddArr->GetState()==kButtonUp) {
01234       if (str.Contains("ARR")) {
01235          str.Remove(strstr(str.Data(),"ARR")-str.Data(),3);
01236          if (str=="" || str=="SCAT" || str==fCutString) {
01237             fAddScat->SetState(kButtonDisabled);
01238             fAddPalette->SetState(kButtonDisabled);
01239          }
01240          make=kTRUE;
01241       }
01242    }
01243    if (make) {
01244       DoHistChanges();
01245    }
01246 }
01247 
01248 //______________________________________________________________________________
01249 void TH2Editor::DoAddBox(Bool_t on)
01250 {
01251    // Slot connected to the "Box draw option" check button.
01252 
01253    if (fAvoidSignal) return;
01254    Bool_t make=kFALSE;
01255    TString str = GetDrawOption();
01256    str.ToUpper();
01257 
01258    if (on) {
01259       if (!str.Contains("BOX")) {
01260          str += "BOX";
01261          if (fAddScat->GetState()==kButtonDisabled)
01262             fAddScat->SetState(kButtonUp);
01263          make=kTRUE;
01264       }
01265    } else if (fAddBox->GetState()==kButtonUp) {
01266       if (str.Contains("BOX")) {
01267          str.Remove(strstr(str.Data(),"BOX")-str.Data(),3);
01268          if (str=="" || str=="SCAT" || str==fCutString) {
01269             fAddScat->SetState(kButtonDisabled);
01270             fAddPalette->SetState(kButtonDisabled);
01271          }
01272          make=kTRUE;
01273       }
01274    }
01275    if (make) {
01276       DoHistChanges();
01277    }
01278 }
01279 
01280 //______________________________________________________________________________
01281 void TH2Editor::DoAddCol(Bool_t on)
01282 {
01283    // Slot connected to the "Col draw option" check button.
01284 
01285    if (fAvoidSignal) return;
01286    Bool_t make=kFALSE;
01287    TString str = GetDrawOption();
01288    str.ToUpper();
01289 
01290    if (on) {
01291       if (!str.Contains("COL")) {
01292          str += "COL";
01293          fColContLbl->Enable() ;
01294          if (fAddScat->GetState()==kButtonDisabled)
01295             fAddScat->SetState(kButtonUp);
01296          if (fAddPalette->GetState()==kButtonDisabled)
01297             fAddPalette->SetState(kButtonUp);
01298          make=kTRUE;
01299       }
01300    } else if (fAddCol->GetState()==kButtonUp) {
01301       if (str.Contains("COL")) {
01302          str.Remove(strstr(str.Data(),"COL")-str.Data(),3);
01303          if (fAddBox->GetState()==kButtonDisabled)
01304             fAddBox->SetState(kButtonUp);
01305          if (fContCombo->GetSelected()==kCONT_NONE) {
01306             fAddPalette->SetState(kButtonDisabled);
01307             if (str.Contains("Z"))
01308                str.Remove(strstr(str.Data(),"Z")-str.Data(),1);
01309          }
01310          if (str=="" || str=="SCAT" || str==fCutString)
01311             fAddScat->SetState(kButtonDisabled);
01312          if (fContCombo->GetSelected()!= kCONT_NONE)
01313             fColContLbl->Enable() ;
01314          else fColContLbl->Disable();
01315          make=kTRUE;
01316       }
01317    }
01318    if (make) {
01319       DoHistChanges();
01320    }
01321 }
01322 
01323 //______________________________________________________________________________
01324 void TH2Editor::DoAddScat(Bool_t on)
01325 {
01326    // Slot connected to the "Scat draw option" check button.
01327 
01328    if (fAvoidSignal) return;
01329    Bool_t make=kFALSE;
01330    TString str = GetDrawOption();
01331    str.ToUpper();
01332 
01333    if (on) {
01334       if (!str.Contains("SCAT")) {
01335          str += "SCAT";
01336          make=kTRUE;
01337       }
01338    } else if (fAddScat->GetState()==kButtonUp) {
01339       if (str.Contains("SCAT")) {
01340          str.Remove(strstr(str.Data(),"SCAT")-str.Data(),4);
01341          make=kTRUE;
01342       }
01343    }
01344    if (make) {
01345       DoHistChanges();
01346    }
01347 }
01348 
01349 //______________________________________________________________________________
01350 void TH2Editor::DoAddText(Bool_t on)
01351 {
01352    // Slot connected to the "Text draw option" check button.
01353 
01354    if (fAvoidSignal) return;
01355    Bool_t make=kFALSE;
01356    TString str = GetDrawOption();
01357    str.ToUpper();
01358 
01359    if (on) {
01360       if (!str.Contains("TEXT")) {
01361          str += "TEXT";
01362          if (fAddScat->GetState()==kButtonDisabled)
01363             fAddScat->SetState(kButtonUp);
01364          make=kTRUE;
01365       }
01366    } else if (fAddText->GetState()==kButtonUp) {
01367       if (str.Contains("TEXT")) {
01368          str.Remove(strstr(str.Data(),"TEXT")-str.Data(),4);
01369          if (str=="" || str=="SCAT" || str==fCutString)
01370             fAddScat->SetState(kButtonDisabled);
01371          make=kTRUE;
01372       }
01373    }
01374    if (make) {
01375       DoHistChanges();
01376       // next line is needed for marker editor refresh
01377       fGedEditor->GetCanvas()->Selected(fGedEditor->GetPad(), fHist, 1);
01378    }
01379 }
01380 
01381 //______________________________________________________________________________
01382 void TH2Editor::DoAddError(Bool_t on)
01383 {
01384    // Slot connected to the "Error" check button.
01385 
01386    if (fAvoidSignal) return;
01387    Bool_t make=kFALSE;
01388    TString str = GetDrawOption();
01389    str.ToUpper();
01390 
01391    TString dum = str;
01392    if (str.Contains("LEGO"))
01393       dum.Remove(strstr(dum.Data(),"LEGO")-dum.Data(),4);
01394    if (str.Contains("TEXT"))
01395       dum.Remove(strstr(dum.Data(),"TEXT")-dum.Data(),4);
01396    if (on) {
01397       if (!dum.Contains("E")) {
01398          str += "E";
01399          make=kTRUE;
01400       }
01401    } else if (fAddError->GetState() == kButtonUp) {
01402       if (str.Contains("E")) {
01403          if (fDim->GetState() == kButtonDown)
01404             str = GetHistContLabel()+GetHistAdditiveLabel();
01405          else
01406             str= GetHistTypeLabel()+GetHistCoordsLabel()+
01407                  GetHistAdditiveLabel();
01408          make=kTRUE;
01409       }
01410    }
01411    if (make) {
01412       DoHistChanges();
01413    }
01414 }
01415 
01416 //______________________________________________________________________________
01417 void TH2Editor::DoAddPalette(Bool_t on)
01418 {
01419    // Slot connected to the color palette check button.
01420 
01421    if (fAvoidSignal) return;
01422    Bool_t make=kFALSE;
01423    TString str = GetDrawOption();
01424    str.ToUpper();
01425 
01426    if (on) {
01427       if (!str.Contains("Z")) {
01428          str += "Z";
01429          make=kTRUE;
01430       }
01431    } else if (fAddPalette->GetState()==kButtonUp ||
01432               fAddPalette1->GetState()==kButtonUp) {
01433       if (str.Contains("Z")) {
01434          str.Remove(strstr(str.Data(),"Z")-str.Data(),1);
01435          make=kTRUE;
01436       }
01437    }
01438    if (make) {
01439       DoHistChanges();
01440    }
01441 }
01442 
01443 //______________________________________________________________________________
01444 void TH2Editor::DoAddFB()
01445 {
01446    // Slot connected to the "FB front-box draw option" check button.
01447 
01448    if (fAvoidSignal) return;
01449    Bool_t make=kFALSE;
01450    TString str = GetDrawOption();
01451    str.ToUpper();
01452 
01453    if (fAddFB->GetState()==kButtonDown) {
01454       if (str.Contains("FB")) {
01455          if (str.Contains("SURF") && !(str.Contains("1") ||
01456              str.Contains("2") || str.Contains("3") ||
01457              str.Contains("4") || str.Contains("5"))) {
01458             TString dum = str;
01459             dum.Remove(strstr(dum.Data(),"SURF")-dum.Data(),4);
01460             if (dum.Contains("FB"))
01461                dum.Remove(strstr(dum.Data(),"FB")-dum.Data(),2);
01462             str = "SURF" + dum;
01463          } else str.Remove(strstr(str.Data(),"FB")-str.Data(),2);
01464          make = kTRUE;
01465       }
01466    } else if (fAddFB->GetState()==kButtonUp){
01467       if (!str.Contains("FB")) {
01468          str += "FB";
01469          make=kTRUE;
01470       }
01471    }
01472    if (make) {
01473       DoHistChanges();
01474    }
01475 }
01476 
01477 //______________________________________________________________________________
01478 void TH2Editor::DoAddBB()
01479 {
01480    // Slot connected to the "BB back-box draw option" check button.
01481 
01482    if (fAvoidSignal) return;
01483    Bool_t make=kFALSE;
01484    TString str = GetDrawOption();
01485    str.ToUpper();
01486 
01487    if (fAddBB->GetState()==kButtonDown) {
01488       if (str.Contains("BB")) {
01489          if (str.Contains("FB")) {
01490             TString dum = str;
01491             dum.Remove(strstr(dum.Data(),"FB")-dum.Data(),2);
01492             dum.Remove(strstr(dum.Data(),"BB")-dum.Data(),2);
01493             str=dum+"FB";
01494          } else str.Remove(strstr(str.Data(),"BB")-str.Data(),2);
01495          make = kTRUE;
01496       }
01497    } else if (fAddBB->GetState()==kButtonUp){
01498       if (!str.Contains("BB")) {
01499          str += "BB";
01500          make=kTRUE;
01501       }
01502    }
01503    if (make) {
01504       DoHistChanges();
01505    }
01506 }
01507 
01508 //______________________________________________________________________________
01509 void TH2Editor::DoContLevel()
01510 {
01511    // Slot connected to the contour level number entry fContLevels.
01512 
01513    if (fAvoidSignal) return;
01514    fHist->SetContour((Int_t)fContLevels->GetNumber());
01515    fContLevels1->SetNumber((Int_t)fContLevels->GetNumber());
01516    Update();
01517 }
01518 
01519 //______________________________________________________________________________
01520 void TH2Editor::DoContLevel1()
01521 {
01522    // Slot connected to the contour level number entry fContLevels1.
01523 
01524    if (fAvoidSignal) return;
01525    fHist->SetContour((Int_t)fContLevels1->GetNumber());
01526    fContLevels->SetNumber((Int_t)fContLevels1->GetNumber());
01527    Update();
01528 }
01529 
01530 //______________________________________________________________________________
01531 void TH2Editor::DoBarWidth()
01532 {
01533    // Slot connected to the bar width of the bar chart.
01534 
01535    if (fAvoidSignal) return;
01536    fHist->SetBarWidth(fBarWidth->GetNumber());
01537    Update();
01538 }
01539 
01540 //______________________________________________________________________________
01541 void TH2Editor::DoBarOffset()
01542 {
01543    // Slot connected to the bar offset of the bar chart.
01544 
01545    if (fAvoidSignal) return;
01546    fHist->SetBarOffset((Float_t)fBarOffset->GetNumber());
01547    Update();
01548 }
01549 
01550 //______________________________________________________________________________
01551 void TH2Editor::DoBinReleased()
01552 {
01553    // Slot connected to the rebin slider in case of no ntuple histogram.
01554    // It updates some other widgets related to the rebin slider.
01555 
01556    // Draw the rebinned histogram in case of the delay draw mode
01557    if (fAvoidSignal) return;
01558    if (fDelaydraw->GetState()==kButtonDown){
01559       if (!fBinHist) {
01560          fBinHist = (TH2*)fHist->Clone("BinHist");
01561       }
01562       Int_t nx = fBinHist->GetXaxis()->GetNbins();
01563       Int_t ny = fBinHist->GetYaxis()->GetNbins();
01564       Int_t numx = fBinXSlider->GetPosition();
01565       Int_t numy = fBinYSlider->GetPosition();
01566       Int_t* divx = Dividers(nx);
01567       Int_t* divy = Dividers(ny);
01568       if (divx[0]==2) fBinXSlider->SetPosition(2);
01569       if (divy[0]==2) fBinYSlider->SetPosition(2);
01570       if (divx[0]==2 && divy[0]==2) {
01571          delete [] divx;
01572          delete [] divy;
01573          return;
01574       }
01575       // delete the histogram which is on the screen
01576       fGedEditor->GetPad()->cd();
01577       fHist->Reset();
01578       fHist->SetBins(nx,fBinHist->GetXaxis()->GetXmin(),
01579                      fBinHist->GetXaxis()->GetXmax(),
01580                      ny,fBinHist->GetYaxis()->GetXmin(),
01581                      fBinHist->GetYaxis()->GetXmax());
01582       fHist->Add(fBinHist);
01583       fHist->ResetBit(TH1::kCanRebin);
01584       fHist->Rebin2D(divx[numx], divy[numy]);
01585 
01586       //fModel=fHist;
01587 
01588       if (divx[0]!=2) {
01589          TAxis* xaxis = fHist->GetXaxis();
01590          Double_t xBinWidth = xaxis->GetBinWidth(1);
01591          xaxis->SetRangeUser(fSldXMin->GetNumber()+xBinWidth/2,
01592                              fSldXMax->GetNumber()-xBinWidth/2);
01593          fSliderX->SetRange(1,(Int_t)nx/divx[numx]);
01594          fSliderX->SetPosition(xaxis->FindBin(fSldXMin->GetNumber()+xBinWidth/2),
01595                                xaxis->FindBin(fSldXMax->GetNumber()-xBinWidth/2));
01596          // the axis range could be changed a little bit by the Rebin algorithm
01597          fSldXMin->SetNumber(xaxis->GetBinLowEdge(xaxis->GetFirst()));
01598          fSldXMax->SetNumber(xaxis->GetBinUpEdge(xaxis->GetLast()));
01599       }
01600       if (divy[0]!=2) {
01601          TAxis* yaxis = fHist->GetYaxis();
01602          Double_t yBinWidth = yaxis->GetBinWidth(1);
01603          yaxis->SetRangeUser(fSldYMin->GetNumber()+yBinWidth/2,
01604                              fSldYMax->GetNumber()-yBinWidth/2);
01605          fSliderY->SetRange(1,(Int_t)ny/divy[numy]);
01606          fSliderY->SetPosition(yaxis->FindBin(fSldYMin->GetNumber()+yBinWidth/2),
01607                                yaxis->FindBin(fSldYMax->GetNumber()-yBinWidth/2));
01608          fSldYMin->SetNumber(yaxis->GetBinLowEdge(yaxis->GetFirst()));
01609          fSldYMax->SetNumber(yaxis->GetBinUpEdge(yaxis->GetLast()));
01610       }
01611       if (fCancel->GetState()==kButtonDisabled) fCancel->SetState(kButtonUp);
01612       if (fApply->GetState()==kButtonDisabled) fApply->SetState(kButtonUp);
01613       Update();
01614       delete [] divx;
01615       delete [] divy;
01616    }
01617 //   fGedEditor->GetPad()->GetCanvas()->Selected(fGedEditor->GetPad(), fHist,  0);
01618    // fModel = fHist;
01619    Refresh(fHist);
01620 }
01621 
01622 //______________________________________________________________________________
01623 void TH2Editor::DoBinPressed()
01624 {
01625    // Slot connected to the rebin slider in case of no ntuple histogram.
01626 
01627    if (fAvoidSignal) return;
01628    Int_t* divx = Dividers(fHist->GetXaxis()->GetNbins());
01629    Int_t* divy = Dividers(fHist->GetYaxis()->GetNbins());
01630    if (divx[0]==2 && divy[0]==2 && !fBinHist)
01631       new TGMsgBox(fClient->GetDefaultRoot(), this->GetMainFrame(),
01632                    "TH2Editor", "It is not possible to rebin the histogram",
01633                    kMBIconExclamation, kMBOk, 0, kVerticalFrame);
01634    // calling the MessageBox again does NOT work!*/
01635    delete [] divx;
01636    delete [] divy;
01637 }
01638 
01639 //______________________________________________________________________________
01640 void TH2Editor::DoBinMoved()
01641 {
01642    // Slot connected to the rebin sliders in case of no ntuple histogram
01643    // does the rebinning of the selected histogram.
01644 
01645    // create a clone in the background, when the slider is moved for 1st time
01646    if (fAvoidSignal) return;
01647    if (!fBinHist /*&& fDelaydraw->GetState()!=kButtonDown*/) {
01648       Int_t* divx = Dividers(fHist->GetXaxis()->GetNbins());
01649       Int_t* divy = Dividers(fHist->GetYaxis()->GetNbins());
01650       // if there is nothing to rebin:
01651       if (divx[0]==2 && divy[0]==2) {
01652          delete [] divx;
01653          delete [] divy;
01654          return;
01655       }
01656       fBinHist = (TH2*)fHist->Clone("BinHist");
01657       delete [] divx;
01658       delete [] divy;
01659    }
01660    // if the slider already has been moved and the clone is saved
01661    Int_t nx = fBinHist->GetXaxis()->GetNbins();
01662    Int_t ny = fBinHist->GetYaxis()->GetNbins();
01663    Int_t numx = fBinXSlider->GetPosition();
01664    Int_t numy = fBinYSlider->GetPosition();
01665    if (nx < 1 || ny < 1) return;
01666    Int_t* divx = Dividers(nx);
01667    Int_t* divy = Dividers(ny);
01668    if (divx[0]==2) {
01669       fBinXSlider->SetPosition(2);
01670       numx=1;
01671    }
01672    if (divy[0]==2) {
01673       fBinYSlider->SetPosition(2);
01674       numy=1;
01675    }
01676    Int_t maxx = (Int_t)nx/divx[numx];
01677    Int_t maxy = (Int_t)ny/divy[numy];
01678    if (maxx==1) maxx=2;
01679    if (maxy==1) maxy=2;
01680    if (fDelaydraw->GetState()==kButtonUp){
01681       // delete the histogram which is on the screen
01682       fGedEditor->GetPad()->cd();
01683       fHist->Reset();
01684       fHist->SetBins(nx,fBinHist->GetXaxis()->GetXmin(),
01685                      fBinHist->GetXaxis()->GetXmax(),
01686                      ny,fBinHist->GetYaxis()->GetXmin(),
01687                      fBinHist->GetYaxis()->GetXmax());
01688       fHist->Add(fBinHist);
01689       fHist->ResetBit(TH1::kCanRebin);
01690       fHist->Rebin2D(divx[numx], divy[numy]);
01691       //fModel=fHist;
01692       if (divx[0]!=2) {
01693          TAxis* xaxis = fHist->GetXaxis();
01694          Double_t xBinWidth = xaxis->GetBinWidth(1);
01695          // if the user has zoomed into a special area the range will be reset:
01696          xaxis->SetRangeUser(fSldXMin->GetNumber()+xBinWidth/2,
01697                              fSldXMax->GetNumber()-xBinWidth/2);
01698          fSliderX->SetRange(1,maxx);
01699          fSliderX->SetPosition(xaxis->FindBin(fSldXMin->GetNumber()+xBinWidth/2),
01700                                xaxis->FindBin(fSldXMax->GetNumber()-xBinWidth/2));
01701          // the axis range could be changed a little bit by the Rebin algorithm
01702          fSldXMin->SetNumber(xaxis->GetBinLowEdge(xaxis->GetFirst()));
01703          fSldXMax->SetNumber(xaxis->GetBinUpEdge(xaxis->GetLast()));
01704          fClient->NeedRedraw(fBinXSlider,kTRUE);
01705       }
01706       if (divy[0]!=2) {
01707          TAxis* yaxis = fHist->GetYaxis();
01708          Double_t yBinWidth = yaxis->GetBinWidth(1);
01709          yaxis->SetRangeUser(fSldYMin->GetNumber()+yBinWidth/2,
01710                              fSldYMax->GetNumber()-yBinWidth/2);
01711          fSliderY->SetRange(1,maxy);
01712          fSliderY->SetPosition(yaxis->FindBin(fSldYMin->GetNumber()+yBinWidth/2),
01713                                yaxis->FindBin(fSldYMax->GetNumber()-yBinWidth/2));
01714          fSldYMin->SetNumber(yaxis->GetBinLowEdge(yaxis->GetFirst()));
01715          fSldYMax->SetNumber(yaxis->GetBinUpEdge(yaxis->GetLast()));
01716          fClient->NeedRedraw(fBinYSlider,kTRUE);
01717       }
01718       Update();
01719    }
01720    // set the according NumberEntries
01721    if (fCancel->GetState()==kButtonDisabled)
01722       fCancel->SetState(kButtonUp);
01723    if (fApply->GetState()==kButtonDisabled)
01724       fApply->SetState(kButtonUp);
01725    fBinXNumberEntry->SetNumber(maxx);
01726    fBinYNumberEntry->SetNumber(maxy);
01727    delete [] divx;
01728    delete [] divy;
01729 }
01730 
01731 //______________________________________________________________________________
01732 void TH2Editor::DoBinLabel()
01733 {
01734    // Slot connected to the Bin Number Entry for the Rebin.
01735 
01736    if (fAvoidSignal) return;
01737    Int_t i;
01738    Int_t numx = (Int_t)(fBinXNumberEntry->GetNumber());
01739    Int_t numy = (Int_t)(fBinYNumberEntry->GetNumber());
01740    Int_t nx = 0;
01741    if (fBinHist) nx = fBinHist->GetXaxis()->GetNbins();
01742    else nx = fHist->GetXaxis()->GetNbins();
01743    Int_t ny = 0;
01744    if (fBinHist) ny = fBinHist->GetYaxis()->GetNbins();
01745    else ny = fHist->GetYaxis()->GetNbins();
01746    if (nx < 2 || ny < 2) return;
01747    // Get the divider of nx/ny which is closest to numx/numy
01748    Int_t *divx = Dividers(nx);
01749    Int_t *divy = Dividers(ny);
01750    Int_t diff = TMath::Abs(numx - divx[1]);
01751    Int_t c = 1; Int_t d = 1;
01752    for (i = 2; i <= divx[0]; i++) {
01753       if ((TMath::Abs(numx - divx[i])) < diff) {
01754          c = i;
01755          diff = TMath::Abs(numx - divx[i]);
01756       }
01757    }
01758    diff = TMath::Abs(numy - divy[1]);
01759    for (i = 2; i <= divy[0]; i++) {
01760       if ((TMath::Abs(numy - divy[i])) < diff) {
01761          d = i;
01762          diff = TMath::Abs(numy - divy[i]);
01763       }
01764    }
01765    if (divx[c]!= fHist->GetXaxis()->GetNbins() ||
01766        divy[d]!= fHist->GetYaxis()->GetNbins()) {
01767       fBinXNumberEntry->SetNumber(divx[c]);
01768       fBinXSlider->SetPosition(divx[0] - c +1);
01769       fBinYNumberEntry->SetNumber(divy[d]);
01770       fBinYSlider->SetPosition(divy[0] - d +1);
01771       if (fDelaydraw->GetState()==kButtonUp) DoBinMoved();
01772       else DoBinReleased();
01773    }
01774 //   fGedEditor->GetPad()->GetCanvas()->Selected(fGedEditor->GetPad(), fHist,  0);
01775 //   fModel = fHist;
01776    Refresh(fHist);
01777    delete [] divx;
01778    delete [] divy;
01779 }
01780 
01781 //______________________________________________________________________________
01782 void TH2Editor::DoApply()
01783 {
01784    // Slot connected to the Apply Button in the Rebinned histogram Window.
01785 
01786    Int_t ret = 0;
01787    new TGMsgBox(fClient->GetDefaultRoot(), this->GetMainFrame(),
01788                 "TH2 Editor", "Replace origin histogram with rebinned one?",
01789                 kMBIconQuestion, kMBYes | kMBNo, &ret, kVerticalFrame);
01790    if (ret==1) {
01791       if (fBinHist) {
01792          delete fBinHist;
01793          fBinHist = 0;
01794       }
01795       Int_t nx = fHist->GetXaxis()->GetNbins();
01796       Int_t ny = fHist->GetYaxis()->GetNbins();
01797       Int_t *divx = Dividers(nx);
01798       Int_t *divy = Dividers(ny);
01799       Int_t upx = 0, upy = 0;
01800       if (divx[0]-1 <= 1) upx = 2;
01801       else upx = divx[0]-1;
01802       if (divy[0]-1 <= 1) upy = 2;
01803       else upy = divy[0]-1;
01804       fBinXSlider->SetRange(1,upx);
01805       fBinYSlider->SetRange(1,upy);
01806       if (fBinXSlider->GetMaxPosition()==2 && divx[0]==2 )
01807          fBinXSlider->SetPosition(2);
01808       else fBinXSlider->SetPosition(1);
01809       if (fBinYSlider->GetMaxPosition()==2 && divy[0]==2 )
01810          fBinYSlider->SetPosition(2);
01811       else fBinYSlider->SetPosition(1);
01812       fCancel->SetState(kButtonDisabled);
01813       fApply->SetState(kButtonDisabled);
01814       Update();
01815       delete [] divx;
01816       delete [] divy;
01817    } else if (ret==2) DoCancel();
01818 }
01819 
01820 //______________________________________________________________________________
01821 void TH2Editor::DoCancel()
01822 {
01823    // Slot connected to the Cancel Button in the Rebinned histogram Window.
01824 
01825    if (fBinHist) {
01826       fGedEditor->GetPad()->cd();
01827       fHist->Reset();
01828       fHist->SetBins(fBinHist->GetXaxis()->GetNbins(),
01829                      fBinHist->GetXaxis()->GetXmin(),
01830                      fBinHist->GetXaxis()->GetXmax(),
01831                      fBinHist->GetYaxis()->GetNbins(),
01832                      fBinHist->GetYaxis()->GetXmin(),
01833                      fBinHist->GetYaxis()->GetXmax());
01834       fHist->Add(fBinHist);
01835       fHist->GetXaxis()->SetRange(fBinHist->GetXaxis()->GetFirst(),
01836                                   fBinHist->GetXaxis()->GetLast());
01837       fHist->GetYaxis()->SetRange(fBinHist->GetYaxis()->GetFirst(),
01838                                   fBinHist->GetYaxis()->GetLast());
01839 
01840       delete fBinHist;
01841       fBinHist = 0;
01842 
01843       fCancel->SetState(kButtonDisabled);
01844       fApply->SetState(kButtonDisabled);
01845       Int_t* divx = Dividers(fHist->GetXaxis()->GetNbins());
01846       Int_t* divy = Dividers(fHist->GetYaxis()->GetNbins());
01847       if (divx[0]!=2) fBinXSlider->SetPosition(1);
01848       if (divy[0]!=2) fBinYSlider->SetPosition(1);
01849       // Consigning the new Histogram to all other Editors
01850 //      fGedEditor->GetPad()->GetCanvas()->Selected(fGedEditor->GetPad(), fHist,  0);
01851       Update();
01852       //  fModel = fHist;
01853       Refresh(fHist);
01854       delete [] divx;
01855       delete [] divy;
01856    }
01857 }
01858 
01859 
01860 //______________________________________________________________________________
01861 void TH2Editor::DoBinReleased1()
01862 {
01863    // Slot connected to the BinNumber Slider in case of a 'ntuple histogram'.
01864    // It does the rebin.
01865 
01866    if (fAvoidSignal) return;
01867    Double_t oldXOffset = fXOffsetNumberEntry->GetNumber();
01868    Int_t xnumber = fBinXSlider1->GetPosition();
01869    Double_t oldYOffset = fYOffsetNumberEntry->GetNumber();
01870    Int_t ynumber = fBinYSlider1->GetPosition();
01871    if (xnumber==5 && ynumber==5) return;
01872    Int_t xfact = 0;
01873    Int_t yfact = 0;
01874    Int_t xBinNumber = 0;
01875    Int_t yBinNumber = 0;
01876    TAxis* xaxis = fHist->GetXaxis();
01877    TAxis* yaxis = fHist->GetYaxis();
01878    //"compute" the scaling factor:
01879    if (xnumber >= 5) xfact = xnumber - 4;
01880    else xfact = xnumber - 6;
01881    if (ynumber >= 5) yfact = ynumber - 4;
01882    else yfact = ynumber - 6;
01883    TTreePlayer *player = (TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer();
01884    if (!player) return;
01885    Int_t nx = xaxis->GetNbins();
01886    Int_t ny = yaxis->GetNbins();
01887    Int_t firstx = xaxis->GetFirst();
01888    Int_t lastx = xaxis->GetLast();
01889    Int_t firsty = yaxis->GetFirst();
01890    Int_t lasty = yaxis->GetLast();
01891    Double_t minx = xaxis->GetBinLowEdge(1);        // overall min in user coords
01892    Double_t maxx = xaxis->GetBinUpEdge(nx);        // overall max in user coords
01893    Double_t miny = yaxis->GetBinLowEdge(1);        // overall min in user coords
01894    Double_t maxy = yaxis->GetBinUpEdge(ny);        // overall max in user coords
01895    Double_t rminx = xaxis->GetBinLowEdge(firstx);  // recent min in user coords
01896    Double_t rmaxx = xaxis->GetBinUpEdge(lastx);    // recent max in user coords
01897    Double_t rminy = yaxis->GetBinLowEdge(firsty);  // recent min in user coords
01898    Double_t rmaxy = yaxis->GetBinUpEdge(lasty);    // recent max in user coords
01899 
01900    ((TH2*)player->GetHistogram())->ResetBit(TH1::kCanRebin);
01901    ((TH2*)player->GetHistogram())->Reset();
01902 
01903    // Get new Number of bins
01904    if (xfact > 0) xBinNumber = xfact*nx;
01905    if (xfact < 0) xBinNumber = (Int_t) ((-1)*nx/xfact+0.5);
01906    if (xBinNumber < 1) xBinNumber = 1;
01907    if (xBinNumber > 1000) xBinNumber= 1000;
01908    if (yfact > 0) yBinNumber = yfact*ny;
01909    if (yfact < 0) yBinNumber = (Int_t) ((-1)*ny/yfact+0.5);
01910    if (yBinNumber < 1) yBinNumber = 1;
01911    if (yBinNumber > 1000) yBinNumber= 1000;
01912    Double_t xOffset = 1.*fXBinOffsetSld->GetPosition()/100*((maxx-minx)/xBinNumber);
01913    Double_t yOffset = 1.*fYBinOffsetSld->GetPosition()/100*((maxy-miny)/yBinNumber);
01914    // create new histogram - the main job is done by sel->TakeAction()
01915 
01916    ((TH2*)player->GetHistogram())->SetBins(xBinNumber, minx-oldXOffset+xOffset,
01917                                            maxx-oldXOffset+xOffset,
01918                                            yBinNumber, miny-oldYOffset+yOffset,
01919                                            maxy-oldYOffset+yOffset);
01920    TSelectorDraw *sel = (TSelectorDraw*)player->GetSelector();
01921    if (!sel) return;
01922    sel->TakeAction();
01923 
01924    // Restore and set all the attributes which were changed by TakeAction()
01925    fHist = (TH2*)((TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer())->GetHistogram();
01926    fSliderX->SetRange(1,xBinNumber);
01927    fSliderY->SetRange(1,yBinNumber);
01928    Double_t xBinWidth = xaxis->GetBinWidth(1);
01929    Double_t yBinWidth = yaxis->GetBinWidth(1);
01930    fSliderX->SetPosition(xaxis->FindBin(rminx+xBinWidth/2),
01931                          xaxis->FindBin(rmaxx-xBinWidth/2));
01932    fSliderY->SetPosition(yaxis->FindBin(rminy+yBinWidth/2),
01933                          yaxis->FindBin(rmaxy-yBinWidth/2));
01934    xOffset = 1.*fXBinOffsetSld->GetPosition()/100*xBinWidth;  // nessesary ??
01935    yOffset = 1.*fYBinOffsetSld->GetPosition()/100*yBinWidth;  // nessesary ??
01936 
01937    // SetRange in BinNumbers along x and y!
01938    xaxis->SetRange(xaxis->FindBin(rminx+xBinWidth/2),
01939                                   xaxis->FindBin(rmaxx-xBinWidth/2));
01940    yaxis->SetRange(yaxis->FindBin(rminy+yBinWidth/2),
01941                                   yaxis->FindBin(rmaxy-yBinWidth/2));
01942    fSldXMin->SetNumber(xaxis->GetBinLowEdge(xaxis->GetFirst()));
01943    fSldXMax->SetNumber(xaxis->GetBinUpEdge(xaxis->GetLast()));
01944    fSldYMin->SetNumber(yaxis->GetBinLowEdge(yaxis->GetFirst()));
01945    fSldYMax->SetNumber(yaxis->GetBinUpEdge(yaxis->GetLast()));
01946    fBinXNumberEntry1->SetNumber(xaxis->GetLast() - xaxis->GetFirst()+1);
01947    fBinYNumberEntry1->SetNumber(yaxis->GetLast() - yaxis->GetFirst()+1);
01948    fBinXSlider1->SetPosition(5);
01949    fBinYSlider1->SetPosition(5);
01950    fXOffsetNumberEntry->SetNumber(xOffset);
01951    fYOffsetNumberEntry->SetNumber(yOffset);
01952    fXOffsetNumberEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0,
01953                                   xaxis->GetBinWidth(1));
01954    fYOffsetNumberEntry->SetLimits(TGNumberFormat::kNELLimitMinMax, 0,
01955                                   yaxis->GetBinWidth(1));
01956    fClient->NeedRedraw(fBinXSlider1, kTRUE);
01957    // when you 2-clicks on a slider, sometimes it gets caught on wrong position! (2 or  -2)
01958    fClient->NeedRedraw(fBinYSlider1, kTRUE);
01959    // when you 2-clicks on a slider, sometimes it gets caught on wrong position! (2 or  -2)
01960    Update();
01961 }
01962 
01963 //______________________________________________________________________________
01964 void TH2Editor::DoBinMoved1()
01965 {
01966    // Slot connected to the rebin slider in case of an ntuple histogram.
01967    // Updates the BinNumberEntryField during the BinSlider movement.
01968 
01969    if (fAvoidSignal) return;
01970    TAxis* xaxis = fHist->GetXaxis();
01971    TAxis* yaxis = fHist->GetYaxis();
01972    Int_t firstx = xaxis->GetFirst();
01973    Int_t lastx = xaxis->GetLast();
01974    Int_t firsty = yaxis->GetFirst();
01975    Int_t lasty = yaxis->GetLast();
01976    Int_t xnumber = fBinXSlider1->GetPosition();
01977    Int_t ynumber = fBinYSlider1->GetPosition();
01978    Int_t numx = lastx-firstx+1;
01979    Int_t numy = lasty-firsty+1;
01980    Int_t xfact = 0;
01981    Int_t yfact = 0;
01982    Int_t xBinNumber = 0;
01983    Int_t yBinNumber = 0;
01984    if (xnumber >= 5) xfact = xnumber - 4;
01985    else xfact = xnumber - 6;
01986    if (xfact > 0) xBinNumber = xfact*numx;
01987    if (xfact < 0) xBinNumber = (Int_t) ((-1)*numx/xfact+0.5);
01988    if (xBinNumber < 1) xBinNumber = 1;
01989    if (xBinNumber > 1000) xBinNumber= 1000;
01990    if (fBinXNumberEntry1->GetNumber()!=xBinNumber)
01991       fBinXNumberEntry1->SetIntNumber(xBinNumber);
01992 
01993    if (ynumber >= 5) yfact = ynumber - 4;
01994    else yfact = ynumber - 6;
01995    if (yfact > 0) yBinNumber = yfact*numy;
01996    if (yfact < 0) yBinNumber = (Int_t) ((-1)*numy/yfact+0.5);
01997    if (yBinNumber < 1) yBinNumber = 1;
01998    if (yBinNumber > 1000) yBinNumber= 1000;
01999    if (fBinYNumberEntry1->GetNumber()!=yBinNumber)
02000       fBinYNumberEntry1->SetIntNumber(yBinNumber);
02001 }
02002 
02003 //______________________________________________________________________________
02004 void TH2Editor::DoBinLabel1()
02005 {
02006    // Slot connected to the Bin Number Entry for the Rebin.
02007 
02008    if (fAvoidSignal) return;
02009    Double_t oldXOffset = fXOffsetNumberEntry->GetNumber();
02010    Int_t numx = (Int_t)fBinXNumberEntry1->GetNumber();
02011    Double_t oldYOffset = fYOffsetNumberEntry->GetNumber();
02012    Int_t numy = (Int_t)fBinYNumberEntry1->GetNumber();
02013    TAxis* xaxis = fHist->GetXaxis();
02014    TAxis* yaxis = fHist->GetYaxis();
02015    TTreePlayer *player = (TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer();
02016    if (!player) return;
02017    Int_t firstx = xaxis->GetFirst();
02018    Int_t lastx = xaxis->GetLast();
02019    Int_t firsty = yaxis->GetFirst();
02020    Int_t lasty = yaxis->GetLast();
02021    Int_t nx = xaxis->GetNbins();
02022    Int_t ny = yaxis->GetNbins();
02023    Double_t minx = xaxis->GetBinLowEdge(1);         // overall min in user coords
02024    Double_t maxx = xaxis->GetBinUpEdge(nx);         // overall max in user coords
02025    Double_t miny = yaxis->GetBinLowEdge(1);         // overall min in user coords
02026    Double_t maxy = yaxis->GetBinUpEdge(ny);         // overall max in user coords
02027    Double_t rminx = xaxis->GetBinLowEdge(firstx);   // recent min in user coords
02028    Double_t rmaxx = xaxis->GetBinUpEdge(lastx);     // recent max in user coords
02029    Double_t rminy = yaxis->GetBinLowEdge(firsty);   // recent min in user coords
02030    Double_t rmaxy = yaxis->GetBinUpEdge(lasty);     // recent max in user coords
02031 
02032    ((TH2*)player->GetHistogram())->ResetBit(TH1::kCanRebin);
02033    ((TH2*)player->GetHistogram())->Reset();
02034 
02035    // Calculate the new number of bins in the complete range
02036    Int_t xBinNumber = (Int_t) ((maxx-minx)/(rmaxx - rminx)*numx + 0.5);
02037    if (xBinNumber < 1) xBinNumber = 1;
02038    if (xBinNumber > 1000) xBinNumber= 1000;
02039    Double_t xOffset = 1.*(fXBinOffsetSld->GetPosition())/100*(maxx-minx)/xBinNumber;
02040    Int_t yBinNumber = (Int_t) ((maxy-miny)/(rmaxy - rminy)*numy + 0.5);
02041    if (yBinNumber < 1) yBinNumber = 1;
02042    if (yBinNumber > 1000) yBinNumber= 1000;
02043    Double_t yOffset = 1.*(fYBinOffsetSld->GetPosition())/100*(maxy-miny)/yBinNumber;
02044    // create new histogram - the main job is done by sel->TakeAction()
02045    ((TH2*)player->GetHistogram())->SetBins(xBinNumber, minx-oldXOffset+xOffset,
02046                                            maxx-oldXOffset+xOffset,
02047                                            yBinNumber, miny-oldYOffset+yOffset,
02048                                            maxy-oldYOffset+yOffset);
02049    TSelectorDraw *sel = (TSelectorDraw*)player->GetSelector();
02050    if (!sel) return;
02051    sel->TakeAction();
02052 
02053    // Restore and set all the attributes which were changed by TakeAction()
02054    fHist = (TH2*)((TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer())->GetHistogram();
02055    fSliderX->SetRange(1,xBinNumber);
02056    fSliderY->SetRange(1,yBinNumber);
02057    Double_t xBinWidth = xaxis->GetBinWidth(1);
02058    Double_t yBinWidth = yaxis->GetBinWidth(1);
02059    fSliderX->SetPosition(xaxis->FindBin(rminx+xBinWidth/2),
02060                          xaxis->FindBin(rmaxx-xBinWidth/2));
02061    fSliderY->SetPosition(yaxis->FindBin(rminy+yBinWidth/2),
02062                          yaxis->FindBin(rmaxy-yBinWidth/2));
02063    xOffset = 1.*fXBinOffsetSld->GetPosition()/100*xBinWidth; //nesessary ??
02064    yOffset = 1.*fYBinOffsetSld->GetPosition()/100*yBinWidth; //nesessary ??
02065 
02066    // SetRange in BinNumbers along x and y!
02067    xaxis->SetRange(xaxis->FindBin(rminx+xBinWidth/2),
02068                    xaxis->FindBin(rmaxx-xBinWidth/2));
02069    yaxis->SetRange(yaxis->FindBin(rminy+yBinWidth/2),
02070                    yaxis->FindBin(rmaxy-yBinWidth/2));
02071    fSldXMin->SetNumber(xaxis->GetBinLowEdge(xaxis->GetFirst()));
02072    fSldXMax->SetNumber(xaxis->GetBinUpEdge(xaxis->GetLast()));
02073    fSldYMin->SetNumber(yaxis->GetBinLowEdge(yaxis->GetFirst()));
02074    fSldYMax->SetNumber(yaxis->GetBinUpEdge(yaxis->GetLast()));
02075    fXOffsetNumberEntry->SetNumber(xOffset);
02076    fXOffsetNumberEntry->SetLimits(TGNumberFormat::kNELLimitMinMax,0,xBinWidth);
02077    fYOffsetNumberEntry->SetNumber(yOffset);
02078    fYOffsetNumberEntry->SetLimits(TGNumberFormat::kNELLimitMinMax,0,yBinWidth);
02079    Update();
02080 }
02081 
02082 //______________________________________________________________________________
02083 void TH2Editor::DoOffsetPressed()
02084 {
02085    // Slot connected to the OffSetSlider. It saves the OldBinOffset
02086    // (nessesary for delay draw mode).
02087 
02088    if (fAvoidSignal) return;
02089    fOldXOffset = fXOffsetNumberEntry->GetNumber();
02090    fOldYOffset = fYOffsetNumberEntry->GetNumber();
02091 }
02092 
02093 //______________________________________________________________________________
02094 void TH2Editor::DoOffsetReleased()
02095 {
02096    // Slot connected to the OffSetSlider that
02097    // changes the origin of the histogram inbetween a binwidth;
02098    // rebin the histogram with the new Offset given by the slider.
02099    // problem: histogram with variable binwidth??
02100 
02101    if (fAvoidSignal) return;
02102    if (fDelaydraw->GetState()==kButtonDown){
02103       Int_t numx = (Int_t)fXBinOffsetSld->GetPosition();
02104       Int_t numy = (Int_t)fYBinOffsetSld->GetPosition();
02105       TAxis* xaxis = fHist->GetXaxis();
02106       TAxis* yaxis = fHist->GetYaxis();
02107       Double_t xBinWidth = xaxis->GetBinWidth(1);
02108       Double_t yBinWidth = yaxis->GetBinWidth(1);
02109       Double_t xOffset =  1.*numx/100*xBinWidth;
02110       Double_t yOffset =  1.*numy/100*yBinWidth;
02111       Double_t oldXOffset = fOldXOffset;
02112       Double_t oldYOffset = fOldYOffset;
02113       Int_t nx = xaxis->GetNbins();
02114       Int_t ny = yaxis->GetNbins();
02115 
02116       TTreePlayer *player = (TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer();
02117       if (!player) return;
02118 
02119       Int_t firstx = xaxis->GetFirst();
02120       Int_t lastx = xaxis->GetLast();
02121       Int_t firsty = yaxis->GetFirst();
02122       Int_t lasty = yaxis->GetLast();
02123       Double_t minx = xaxis->GetBinLowEdge(1);       // overall min in user coords
02124       Double_t maxx = xaxis->GetBinUpEdge(nx);       // overall max in user coords
02125       Double_t miny = yaxis->GetBinLowEdge(1);       // overall min in user coords
02126       Double_t maxy = yaxis->GetBinUpEdge(ny);       // overall max in user coords
02127       Double_t rminx = xaxis->GetBinLowEdge(firstx); // recent min in user coords
02128       Double_t rmaxx = xaxis->GetBinUpEdge(lastx);   // recent max in user coords
02129       Double_t rminy = yaxis->GetBinLowEdge(firsty); // recent min in user coords
02130       Double_t rmaxy = yaxis->GetBinUpEdge(lasty);   // recent max in user coords
02131 
02132       ((TH2*)player->GetHistogram())->ResetBit(TH1::kCanRebin);
02133       ((TH2*)player->GetHistogram())->Reset();
02134 
02135       ((TH2*)player->GetHistogram())->SetBins(nx, minx-oldXOffset+xOffset,
02136                                               maxx-oldXOffset+xOffset,
02137                                               ny, miny-oldYOffset+yOffset,
02138                                               maxy-oldYOffset+yOffset);
02139       TSelectorDraw *sel = (TSelectorDraw*)player->GetSelector();
02140       if (!sel) return;
02141       sel->TakeAction();
02142 
02143       // Restore all the attributes which were changed by TakeAction()
02144       fHist = (TH2*)((TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer())->GetHistogram();
02145 
02146       // SetRange in BinNumbers along x and y!
02147       xaxis->SetRange(xaxis->FindBin(rminx+xOffset-oldXOffset+xBinWidth/2),
02148                       xaxis->FindBin(rmaxx+xOffset-oldXOffset-xBinWidth/2));
02149       yaxis->SetRange(yaxis->FindBin(rminy+yOffset-oldYOffset+yBinWidth/2),
02150                       yaxis->FindBin(rmaxy+yOffset-oldYOffset-yBinWidth/2));
02151       fSldXMin->SetNumber(xaxis->GetBinLowEdge(xaxis->GetFirst()));
02152       fSldXMax->SetNumber(xaxis->GetBinUpEdge(xaxis->GetLast()));
02153       fSldYMin->SetNumber(yaxis->GetBinLowEdge(yaxis->GetFirst()));
02154       fSldYMax->SetNumber(yaxis->GetBinUpEdge(yaxis->GetLast()));
02155       fXOffsetNumberEntry->SetNumber(xOffset);
02156       fYOffsetNumberEntry->SetNumber(yOffset);
02157       Update();
02158    }
02159 }
02160 
02161 //______________________________________________________________________________
02162 void TH2Editor::DoOffsetMoved()
02163 {
02164    // Slot connected to the OffSetSlider.
02165    // It changes the origin of the histogram inbetween a binwidth;
02166    // rebin the histogram with the new offset given by the slider.
02167    // problem: histogram with variable binwidth??
02168 
02169    if (fAvoidSignal) return;
02170    Int_t numx = (Int_t)fXBinOffsetSld->GetPosition();
02171    Int_t numy = (Int_t)fYBinOffsetSld->GetPosition();
02172    TAxis* xaxis = fHist->GetXaxis();
02173    TAxis* yaxis = fHist->GetYaxis();
02174    Double_t xBinWidth = xaxis->GetBinWidth(1);
02175    Double_t yBinWidth = yaxis->GetBinWidth(1);
02176    Double_t xOffset =  1.*numx/100*xBinWidth;
02177    Double_t yOffset =  1.*numy/100*yBinWidth;
02178    if (fDelaydraw->GetState()==kButtonUp){
02179       Double_t oldXOffset = fXOffsetNumberEntry->GetNumber();
02180       Double_t oldYOffset = fYOffsetNumberEntry->GetNumber();
02181       Int_t nx = xaxis->GetNbins();
02182       Int_t ny = yaxis->GetNbins();
02183 
02184       TTreePlayer *player = (TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer();
02185       if (!player) return;
02186 
02187       Int_t firstx = xaxis->GetFirst();
02188       Int_t lastx = xaxis->GetLast();
02189       Int_t firsty = yaxis->GetFirst();
02190       Int_t lasty = yaxis->GetLast();
02191       Double_t minx = xaxis->GetBinLowEdge(1);       // overall min in user coords
02192       Double_t maxx = xaxis->GetBinUpEdge(nx);       // overall max in user coords
02193       Double_t miny = yaxis->GetBinLowEdge(1);       // overall min in user coords
02194       Double_t maxy = yaxis->GetBinUpEdge(ny);       // overall max in user coords
02195       Double_t rminx = xaxis->GetBinLowEdge(firstx); // recent min in user coords
02196       Double_t rmaxx = xaxis->GetBinUpEdge(lastx);   // recent max in user coords
02197       Double_t rminy = yaxis->GetBinLowEdge(firsty); // recent min in user coords
02198       Double_t rmaxy = yaxis->GetBinUpEdge(lasty);   // recent max in user coords
02199 
02200       ((TH2*)player->GetHistogram())->ResetBit(TH1::kCanRebin);
02201       ((TH2*)player->GetHistogram())->Reset();
02202 
02203       ((TH2*)player->GetHistogram())->SetBins(nx,minx-oldXOffset+xOffset,
02204                                               maxx-oldXOffset+xOffset,
02205                                               ny, miny-oldYOffset+yOffset,
02206                                               maxy-oldYOffset+yOffset);
02207       TSelectorDraw *sel = (TSelectorDraw*)player->GetSelector();
02208       if (!sel) return;
02209       sel->TakeAction();
02210 
02211       // Restore all the attributes which were changed by TakeAction()
02212       fHist = (TH2*)((TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer())->GetHistogram();
02213 
02214       // SetRange in BinNumbers along x and y!
02215       xaxis->SetRange(xaxis->FindBin(rminx+xOffset-oldXOffset+xBinWidth/2),
02216                       xaxis->FindBin(rmaxx+xOffset-oldXOffset-xBinWidth/2));
02217       yaxis->SetRange(yaxis->FindBin(rminy+yOffset-oldYOffset+yBinWidth/2),
02218                       yaxis->FindBin(rmaxy+yOffset-oldYOffset-yBinWidth/2));
02219       fSldXMin->SetNumber(xaxis->GetBinLowEdge(xaxis->GetFirst()));
02220       fSldXMax->SetNumber(xaxis->GetBinUpEdge(xaxis->GetLast()));
02221       fSldYMin->SetNumber(yaxis->GetBinLowEdge(yaxis->GetFirst()));
02222       fSldYMax->SetNumber(yaxis->GetBinUpEdge(yaxis->GetLast()));
02223       fClient->NeedRedraw(fXBinOffsetSld, kTRUE);
02224       fClient->NeedRedraw(fYBinOffsetSld, kTRUE);
02225       Update();
02226    }
02227    fXOffsetNumberEntry->SetNumber(xOffset);
02228    fYOffsetNumberEntry->SetNumber(yOffset);
02229    fClient->NeedRedraw(fXOffsetNumberEntry, kTRUE);
02230    fClient->NeedRedraw(fYOffsetNumberEntry, kTRUE);
02231 }
02232 
02233 //______________________________________________________________________________
02234 void TH2Editor::DoBinOffset()
02235 {
02236    // Slot connected to the OffSetNumberEntry, related to the OffSetSlider
02237    // changes the origin of the histogram inbetween a binwidth.
02238 
02239    if (fAvoidSignal) return;
02240    TAxis* xaxis = fHist->GetXaxis();
02241    TAxis* yaxis = fHist->GetYaxis();
02242    Double_t xBinWidth = xaxis->GetBinWidth(1);
02243    Double_t yBinWidth = yaxis->GetBinWidth(1);
02244    Double_t xOffset =  fXOffsetNumberEntry->GetNumber();
02245    Double_t oldXOffset = 1.*fXBinOffsetSld->GetPosition()/100*xBinWidth;
02246    Double_t yOffset =  fYOffsetNumberEntry->GetNumber();
02247    Double_t oldYOffset = 1.*fYBinOffsetSld->GetPosition()/100*yBinWidth;
02248    Int_t nx = xaxis->GetNbins();
02249    Int_t ny = yaxis->GetNbins();
02250    TTreePlayer *player = (TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer();
02251    if (!player) return;
02252    Int_t firstx = xaxis->GetFirst();
02253    Int_t lastx = xaxis->GetLast();
02254    Int_t firsty = yaxis->GetFirst();
02255    Int_t lasty = yaxis->GetLast();
02256    Double_t minx = xaxis->GetBinLowEdge(1);        // overall min in user coords
02257    Double_t maxx = xaxis->GetBinUpEdge(nx);        // overall max in user coords
02258    Double_t miny = yaxis->GetBinLowEdge(1);        // overall min in user coords
02259    Double_t maxy = yaxis->GetBinUpEdge(ny);        // overall max in user coords
02260    Double_t rminx = xaxis->GetBinLowEdge(firstx);  // recent min in user coords
02261    Double_t rmaxx = xaxis->GetBinUpEdge(lastx);    // recent max in user coords
02262    Double_t rminy = yaxis->GetBinLowEdge(firsty);  // recent min in user coords
02263    Double_t rmaxy = yaxis->GetBinUpEdge(lasty);    // recent max in user coords
02264 
02265    ((TH2*)player->GetHistogram())->ResetBit(TH1::kCanRebin);
02266    ((TH2*)player->GetHistogram())->Reset();
02267 
02268    ((TH2*)player->GetHistogram())->SetBins(nx,minx+xOffset-oldXOffset,
02269                                            maxx+xOffset-oldXOffset,
02270                                            ny,miny+yOffset-oldYOffset,
02271                                            maxy+yOffset-oldYOffset);
02272    TSelectorDraw *sel = (TSelectorDraw*)player->GetSelector();
02273    if (!sel) return;
02274    sel->TakeAction();
02275 
02276    // Restore all the attributes which were changed by TakeAction()
02277    fHist = (TH2*)((TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer())->GetHistogram();
02278 
02279    // SetRange in BinNumbers along x and y!
02280    xaxis->SetRange(xaxis->FindBin(rminx+xOffset-oldXOffset+xBinWidth/2),
02281                    xaxis->FindBin(rmaxx+xOffset-oldXOffset-xBinWidth/2));
02282    yaxis->SetRange(yaxis->FindBin(rminy+yOffset-oldYOffset+yBinWidth/2),
02283                    yaxis->FindBin(rmaxy+yOffset-oldYOffset-yBinWidth/2));
02284    fSldXMin->SetNumber(xaxis->GetBinLowEdge(xaxis->GetFirst()));
02285    fSldXMax->SetNumber(xaxis->GetBinUpEdge(xaxis->GetLast()));
02286    fXBinOffsetSld->SetPosition((Int_t)(xOffset/xBinWidth*100));
02287    fSldYMin->SetNumber(yaxis->GetBinLowEdge(yaxis->GetFirst()));
02288    fSldYMax->SetNumber(yaxis->GetBinUpEdge(yaxis->GetLast()));
02289    fYBinOffsetSld->SetPosition((Int_t)(yOffset/yBinWidth*100));
02290    Update();
02291 }
02292 
02293 //______________________________________________________________________________
02294 void TH2Editor::DoSliderXMoved()
02295 {
02296    // Slot connected to the x-Slider that redraws the histogram
02297    // with the new slider range.
02298 
02299    if (fAvoidSignal) return;
02300    TAxis* xaxis = fHist->GetXaxis();
02301    if (fDelaydraw->GetState()==kButtonDown && fDim->GetState()==kButtonDown) {
02302       // 2D plot
02303       Int_t px1,py1,px2,py2;
02304       Float_t ymin,ymax,xleft,xright;
02305       xleft = xaxis->GetBinLowEdge((Int_t)((fSliderX->GetMinPosition())+0.5));
02306       xright =  xaxis->GetBinUpEdge((Int_t)((fSliderX->GetMaxPosition())+0.5));
02307       ymin  = fGedEditor->GetPad()->GetUymin();
02308       ymax  = fGedEditor->GetPad()->GetUymax();
02309       px1   = fGedEditor->GetPad()->XtoAbsPixel(xleft);
02310       py1   = fGedEditor->GetPad()->YtoAbsPixel(ymin);
02311       px2   = fGedEditor->GetPad()->XtoAbsPixel(xright);
02312       py2   = fGedEditor->GetPad()->YtoAbsPixel(ymax);
02313       fGedEditor->GetPad()->GetCanvas()->FeedbackMode(kTRUE);
02314       fGedEditor->GetPad()->cd();
02315       fGedEditor->GetPad()->SetLineWidth(1);
02316       fGedEditor->GetPad()->SetLineColor(2);
02317       gVirtualX->DrawBox(fPx1old, fPy1old, fPx2old, fPy2old, TVirtualX::kHollow);
02318       gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
02319       fPx1old = px1;
02320       fPy1old = py1;
02321       fPx2old = px2 ;
02322       fPy2old = py2;
02323       gVirtualX->Update(0);
02324       fSldXMin->SetNumber(xleft);
02325       fSldXMax->SetNumber(xright);
02326    }  else  if (fDelaydraw->GetState()==kButtonDown &&
02327                 fDim0->GetState()==kButtonDown &&
02328                 fCoordsCombo->GetSelected()==kCOORDS_CAR) {
02329       // 3D plot
02330       Float_t p1[3], p2[3], p3[3], p4[3], p5[3], p6[3], p7[3], p8[3];
02331       fGedEditor->GetPad()->GetCanvas()->FeedbackMode(kTRUE);
02332       fGedEditor->GetPad()->cd();
02333       TView *fView = fGedEditor->GetPad()->GetView();
02334       Double_t *rmin = fView->GetRmin();
02335       Double_t *rmax = fView->GetRmax();
02336       p1[0] = p4[0] = p5[0] = p8[0] =
02337             xaxis->GetBinLowEdge((Int_t)((fSliderX->GetMinPosition())+0.5));
02338       p2[0] = p3[0] = p6[0] = p7[0] =
02339             xaxis->GetBinUpEdge((Int_t)((fSliderX->GetMaxPosition())+0.5));
02340       p1[1] = p2[1] = p3[1] = p4[1] = rmin[1];
02341       p5[1] = p6[1] = p7[1] = p8[1] = rmax[1];
02342       p1[2] = p2[2] = p5[2] = p6[2] = rmin[2];
02343       p3[2] = p4[2] = p7[2] = p8[2] = rmax[2];
02344       fGedEditor->GetPad()->SetLineWidth(1);
02345       fGedEditor->GetPad()->SetLineColor(2);
02346       PaintBox3D(fP2oldx, fP3oldx, fP7oldx, fP6oldx);
02347       PaintBox3D(fP1oldx, fP4oldx, fP8oldx, fP5oldx);
02348       PaintBox3D(p2, p3, p7, p6);
02349       PaintBox3D(p1, p4, p8, p5);
02350       for (Int_t i = 0; i<3; i++){
02351          fP1oldx[i] = p1[i];
02352          fP2oldx[i] = p2[i];
02353          fP3oldx[i] = p3[i];
02354          fP4oldx[i] = p4[i];
02355          fP5oldx[i] = p5[i];
02356          fP6oldx[i] = p6[i];
02357          fP7oldx[i] = p7[i];
02358          fP8oldx[i] = p8[i];
02359       }
02360       fSldXMin->SetNumber(p1[0]);
02361       fSldXMax->SetNumber(p2[0]);
02362    } else  if (fDelaydraw->GetState()==kButtonDown &&
02363                fDim0->GetState()==kButtonDown) {
02364       fSldXMin->SetNumber(xaxis->GetBinLowEdge((Int_t)((fSliderX->GetMinPosition())+0.5)));
02365       fSldXMax->SetNumber(xaxis->GetBinUpEdge((Int_t)((fSliderX->GetMaxPosition())+0.5)));
02366    } else {
02367       fHist->GetXaxis()->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
02368                                   (Int_t)((fSliderX->GetMaxPosition())+0.5));
02369       fSldXMin->SetNumber(xaxis->GetBinLowEdge(xaxis->GetFirst()));
02370       fSldXMax->SetNumber(xaxis->GetBinUpEdge(xaxis->GetLast()));
02371       fClient->NeedRedraw(fSliderX,kTRUE);
02372       Update();
02373    }
02374    fClient->NeedRedraw(fSldXMin,kTRUE);
02375    fClient->NeedRedraw(fSldXMax,kTRUE);
02376 }
02377 
02378 //______________________________________________________________________________
02379 void TH2Editor::DoSliderXPressed()
02380 {
02381    // Slot connected to the x axis range slider that initialises
02382    // the "virtual" box which is drawn in delay draw mode.
02383 
02384    if (fAvoidSignal) return;
02385    TAxis* xaxis = fHist->GetXaxis();
02386    Float_t ymin,ymax,xleft,xright;
02387    if (fDelaydraw->GetState()==kButtonDown && fDim->GetState()==kButtonDown) {
02388       // 2D Plot
02389       if (!fGedEditor->GetPad()) return;
02390       fGedEditor->GetPad()->cd();
02391       fGedEditor->GetPad()->GetCanvas()->FeedbackMode(kFALSE);
02392       fGedEditor->GetPad()->SetLineWidth(1);
02393       fGedEditor->GetPad()->SetLineColor(2);
02394       xleft  = xaxis->GetBinLowEdge((Int_t)((fSliderX->GetMinPosition())+0.5));
02395       xright =  xaxis->GetBinUpEdge((Int_t)((fSliderX->GetMaxPosition())+0.5));
02396       ymin  = fGedEditor->GetPad()->GetUymin();
02397       ymax  = fGedEditor->GetPad()->GetUymax();
02398       fPx1old = fGedEditor->GetPad()->XtoAbsPixel(xleft);
02399       fPy1old = fGedEditor->GetPad()->YtoAbsPixel(ymin);
02400       fPx2old = fGedEditor->GetPad()->XtoAbsPixel(xright);
02401       fPy2old = fGedEditor->GetPad()->YtoAbsPixel(ymax);
02402       gVirtualX->DrawBox(fPx1old, fPy1old, fPx2old, fPy2old, TVirtualX::kHollow);
02403    } else if (fDelaydraw->GetState()==kButtonDown &&
02404               fDim0->GetState()==kButtonDown &&
02405               fCoordsCombo->GetSelected()==kCOORDS_CAR) {
02406       // 3D plot
02407       if (!fGedEditor->GetPad()) return;
02408       fGedEditor->GetPad()->cd();
02409       TView *fView = fGedEditor->GetPad()->GetView();
02410       Double_t *rmin = fView->GetRmin();
02411       Double_t *rmax = fView->GetRmax();
02412       fP1oldx[0] = fP4oldx[0] = fP5oldx[0] = fP8oldx[0] =
02413                  xaxis->GetBinLowEdge((Int_t)((fSliderX->GetMinPosition())+0.5));
02414       fP2oldx[0] = fP3oldx[0] = fP6oldx[0] = fP7oldx[0] =
02415                  xaxis->GetBinUpEdge((Int_t)((fSliderX->GetMaxPosition())+0.5));
02416       fP1oldx[1] = fP2oldx[1] = fP3oldx[1] = fP4oldx[1] = rmin[1];
02417       fP5oldx[1] = fP6oldx[1] = fP7oldx[1] = fP8oldx[1] = rmax[1];
02418       fP1oldx[2] = fP2oldx[2] = fP5oldx[2] = fP6oldx[2] = rmin[2];
02419       fP3oldx[2] = fP4oldx[2] = fP7oldx[2] = fP8oldx[2] = rmax[2];
02420       fGedEditor->GetPad()->GetCanvas()->FeedbackMode(kTRUE);
02421       fGedEditor->GetPad()->SetLineWidth(1);
02422       fGedEditor->GetPad()->SetLineColor(2);
02423       PaintBox3D(fP2oldx, fP3oldx, fP7oldx, fP6oldx);
02424       PaintBox3D(fP1oldx, fP4oldx, fP8oldx, fP5oldx);
02425    }
02426 }
02427 
02428 //______________________________________________________________________________
02429 void TH2Editor::DoSliderXReleased()
02430 {
02431    // Slot connected to the x-axis slider finalizing values after
02432    // the slider movement.
02433 
02434    if (fAvoidSignal) return;
02435    if (fDelaydraw->GetState()==kButtonDown) {
02436       fHist->GetXaxis()->SetRange((Int_t)((fSliderX->GetMinPosition())+0.5),
02437                                   (Int_t)((fSliderX->GetMaxPosition())+0.5));
02438       fSldXMin->SetNumber(fHist->GetXaxis()->GetBinLowEdge(fHist->GetXaxis()->GetFirst()));
02439       fSldXMax->SetNumber(fHist->GetXaxis()->GetBinUpEdge(fHist->GetXaxis()->GetLast()));
02440       Update();
02441    }
02442    TTreePlayer *player = (TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer();
02443    if (player) if (player->GetHistogram() == fHist) {
02444       Int_t last = fHist->GetXaxis()->GetLast();
02445       Int_t first = fHist->GetXaxis()->GetFirst();
02446       fBinXNumberEntry1->SetIntNumber(last-first+1);
02447       Update();
02448    }
02449 }
02450 
02451 //______________________________________________________________________________
02452 void TH2Editor::DoXAxisRange()
02453 {
02454    // Slot connected to the Max/Min number entry fields showing x-axis range.
02455 
02456    TAxis* xaxis = fHist->GetXaxis();
02457    Int_t nx = xaxis->GetNbins();
02458    Double_t width = xaxis->GetBinWidth(1);
02459    if ((fSldXMin->GetNumber()+width/2) < (xaxis->GetBinLowEdge(1)))
02460       fSldXMin->SetNumber(xaxis->GetBinLowEdge(1));
02461    if ((fSldXMax->GetNumber()-width/2) > (xaxis->GetBinUpEdge(nx)))
02462       fSldXMax->SetNumber(xaxis->GetBinUpEdge(nx));
02463    xaxis->SetRangeUser(fSldXMin->GetNumber()+width/2,
02464                        fSldXMax->GetNumber()-width/2);
02465    Int_t nxbinmin = xaxis->GetFirst();
02466    Int_t nxbinmax = xaxis->GetLast();
02467    fSliderX->SetPosition((Double_t)(nxbinmin),(Double_t)(nxbinmax));
02468    Update();
02469 }
02470 
02471 //______________________________________________________________________________
02472 void TH2Editor::DoSliderYMoved()
02473 {
02474    // Slot connected to the x-slider for redrawing the
02475    // histogram with the new slider Range (immediately).
02476 
02477    if (fAvoidSignal) return;
02478    TAxis* yaxis = fHist->GetYaxis();
02479    if (fDelaydraw->GetState()==kButtonDown && fDim->GetState()==kButtonDown) {
02480       Int_t px1,py1,px2,py2;
02481       Float_t xmin,xmax,ybottom,ytop;
02482       ybottom = yaxis->GetBinLowEdge((Int_t)((fSliderY->GetMinPosition())+0.5));
02483       ytop = yaxis->GetBinUpEdge((Int_t)((fSliderY->GetMaxPosition())+0.5));
02484       xmin = fGedEditor->GetPad()->GetUxmin();
02485       xmax = fGedEditor->GetPad()->GetUxmax();
02486       px1  = fGedEditor->GetPad()->XtoAbsPixel(xmin);
02487       py1  = fGedEditor->GetPad()->YtoAbsPixel(ybottom);
02488       px2  = fGedEditor->GetPad()->XtoAbsPixel(xmax);
02489       py2  = fGedEditor->GetPad()->YtoAbsPixel(ytop);
02490       fGedEditor->GetPad()->GetCanvas()->FeedbackMode(kTRUE);
02491       fGedEditor->GetPad()->cd();
02492       fGedEditor->GetPad()->SetLineWidth(1);
02493       fGedEditor->GetPad()->SetLineColor(2);
02494       gVirtualX->DrawBox(fPx1old, fPy1old, fPx2old, fPy2old, TVirtualX::kHollow);
02495       gVirtualX->DrawBox(px1, py1, px2, py2, TVirtualX::kHollow);
02496       fPx1old = px1;
02497       fPy1old = py1;
02498       fPx2old = px2 ;
02499       fPy2old = py2;
02500       gVirtualX->Update(0);
02501       fSldYMin->SetNumber(ybottom);
02502       fSldYMax->SetNumber(ytop);
02503    } else if (fDelaydraw->GetState()==kButtonDown &&
02504               fDim0->GetState()==kButtonDown &&
02505               fCoordsCombo->GetSelected()==kCOORDS_CAR) {
02506       // 3D plot
02507       Float_t p1[3], p2[3], p3[3], p4[3], p5[3], p6[3], p7[3], p8[3];
02508       fGedEditor->GetPad()->GetCanvas()->FeedbackMode(kTRUE);
02509       fGedEditor->GetPad()->cd();
02510       TView *fView = fGedEditor->GetPad()->GetView();
02511       Double_t *rmin = fView->GetRmin();
02512       Double_t *rmax = fView->GetRmax();
02513       p1[0] = p2[0] = p3[0] = p4[0] = rmin[0];
02514       p5[0] = p6[0] = p7[0] = p8[0] = rmax[0];
02515       p1[1] = p4[1] = p5[1] = p8[1] =
02516             yaxis->GetBinLowEdge((Int_t)((fSliderY->GetMinPosition())+0.5));
02517       p2[1] = p3[1] = p6[1] = p7[1] =
02518             yaxis->GetBinUpEdge((Int_t)((fSliderY->GetMaxPosition())+0.5));
02519       p1[2] = p2[2] = p5[2] = p6[2] = rmin[2];
02520       p3[2] = p4[2] = p7[2] = p8[2] = rmax[2];
02521       fGedEditor->GetPad()->SetLineWidth(1);
02522       fGedEditor->GetPad()->SetLineColor(2);
02523       PaintBox3D(fP2oldy, fP3oldy, fP7oldy, fP6oldy);
02524       PaintBox3D(fP1oldy, fP4oldy, fP8oldy, fP5oldy);
02525       PaintBox3D(p2, p3, p7, p6);
02526       PaintBox3D(p1, p4, p8, p5);
02527       for (Int_t i = 0; i<3; i++) {
02528          fP1oldy[i] = p1[i];
02529          fP2oldy[i] = p2[i];
02530          fP3oldy[i] = p3[i];
02531          fP4oldy[i] = p4[i];
02532          fP5oldy[i] = p5[i];
02533          fP6oldy[i] = p6[i];
02534          fP7oldy[i] = p7[i];
02535          fP8oldy[i] = p8[i];
02536       }
02537       fSldYMin->SetNumber(p1[1]);
02538       fSldYMax->SetNumber(p2[1]);
02539    } else if (fDelaydraw->GetState()==kButtonDown &&
02540               fDim0->GetState()==kButtonDown) {
02541       fSldYMin->SetNumber(yaxis->GetBinLowEdge((Int_t)((fSliderY->GetMinPosition())+0.5)));
02542       fSldYMax->SetNumber(yaxis->GetBinUpEdge((Int_t)((fSliderY->GetMaxPosition())+0.5)));
02543    } else {
02544       yaxis->SetRange((Int_t)((fSliderY->GetMinPosition())+0.5),
02545                       (Int_t)((fSliderY->GetMaxPosition())+0.5));
02546       fSldYMin->SetNumber(yaxis->GetBinLowEdge(yaxis->GetFirst()));
02547       fSldYMax->SetNumber(yaxis->GetBinUpEdge(yaxis->GetLast()));
02548       fClient->NeedRedraw(fSliderY,kTRUE);
02549       Update();
02550    }
02551    fClient->NeedRedraw(fSldYMin,kTRUE);
02552    fClient->NeedRedraw(fSldYMax,kTRUE);
02553 }
02554 
02555 //______________________________________________________________________________
02556 void TH2Editor::DoSliderYPressed()
02557 {
02558    // Slot connected to y-axis slider which initialises
02559    // the "virtual" box which is drawn in delay draw mode.
02560 
02561    if (fAvoidSignal) return;
02562    TAxis* yaxis = fHist->GetYaxis();
02563    Float_t xmin,xmax,ytop,ybottom;
02564    if (fDelaydraw->GetState()==kButtonDown && fDim->GetState()==kButtonDown) {
02565       // 2D plot:
02566       if (!fGedEditor->GetPad()) return;
02567       fGedEditor->GetPad()->cd();
02568       fGedEditor->GetPad()->GetCanvas()->FeedbackMode(kFALSE);
02569       fGedEditor->GetPad()->SetLineWidth(1);
02570       fGedEditor->GetPad()->SetLineColor(2);
02571       ybottom = yaxis->GetBinLowEdge((Int_t)((fSliderY->GetMinPosition())+0.5));
02572       ytop =  yaxis->GetBinUpEdge((Int_t)((fSliderY->GetMaxPosition())+0.5));
02573       xmin  = fGedEditor->GetPad()->GetUxmin();
02574       xmax  = fGedEditor->GetPad()->GetUxmax();
02575       fPx1old   = fGedEditor->GetPad()->XtoAbsPixel(xmin);
02576       fPy1old   = fGedEditor->GetPad()->YtoAbsPixel(ybottom);
02577       fPx2old   = fGedEditor->GetPad()->XtoAbsPixel(xmax);
02578       fPy2old   = fGedEditor->GetPad()->YtoAbsPixel(ytop);
02579       gVirtualX->DrawBox(fPx1old, fPy1old, fPx2old, fPy2old, TVirtualX::kHollow);
02580    }  else if (fDelaydraw->GetState()==kButtonDown &&
02581                fDim0->GetState()==kButtonDown &&
02582                fCoordsCombo->GetSelected()==kCOORDS_CAR) {
02583       // 3D plot
02584       if (!fGedEditor->GetPad()) return;
02585       fGedEditor->GetPad()->cd();
02586       TView *fView = gPad->GetView();
02587       Double_t *rmin = fView->GetRmin();
02588       Double_t *rmax = fView->GetRmax();
02589       fP1oldy[0] = fP2oldy[0] = fP3oldy[0] = fP4oldy[0] = rmin[0];
02590       fP5oldy[0] = fP6oldy[0] = fP7oldy[0] = fP8oldy[0] = rmax[0];
02591       fP1oldy[1] = fP4oldy[1] = fP5oldy[1] = fP8oldy[1] =
02592                  yaxis->GetBinLowEdge((Int_t)((fSliderY->GetMinPosition())+0.5));
02593       fP2oldy[1] = fP3oldy[1] = fP6oldy[1] = fP7oldy[1] =
02594                  yaxis->GetBinUpEdge((Int_t)((fSliderY->GetMaxPosition())+0.5));
02595       fP1oldy[2] = fP2oldy[2] = fP5oldy[2] = fP6oldy[2] = rmin[2];
02596       fP3oldy[2] = fP4oldy[2] = fP7oldy[2] = fP8oldy[2] = rmax[2];
02597       fGedEditor->GetPad()->GetCanvas()->FeedbackMode(kTRUE);
02598       fGedEditor->GetPad()->SetLineWidth(1);
02599       fGedEditor->GetPad()->SetLineColor(2);
02600       PaintBox3D(fP2oldy, fP3oldy, fP7oldy, fP6oldy);
02601       PaintBox3D(fP1oldy, fP4oldy, fP8oldy, fP5oldy);
02602    }
02603 }
02604 
02605 //______________________________________________________________________________
02606 void TH2Editor::DoSliderYReleased()
02607 {
02608    // Slot connected to the y-axis slider finalizing values after
02609    // the slider movement.
02610 
02611    if (fAvoidSignal) return;
02612    if (fDelaydraw->GetState()==kButtonDown) {
02613       fHist->GetYaxis()->SetRange((Int_t)((fSliderY->GetMinPosition())+0.5),
02614                                   (Int_t)((fSliderY->GetMaxPosition())+0.5));
02615       fSldYMin->SetNumber(fHist->GetYaxis()->GetBinLowEdge(fHist->GetYaxis()->GetFirst()));
02616       fSldYMax->SetNumber(fHist->GetYaxis()->GetBinUpEdge(fHist->GetYaxis()->GetLast()));
02617       Update();
02618    }
02619 
02620    TTreePlayer *player = (TTreePlayer*)TVirtualTreePlayer::GetCurrentPlayer();
02621    if (player) if (player->GetHistogram() == fHist) {
02622       Int_t last = fHist->GetYaxis()->GetLast();
02623       Int_t first = fHist->GetYaxis()->GetFirst();
02624       fBinYNumberEntry1->SetIntNumber(last-first+1);
02625       Update();
02626    }
02627 }
02628 
02629 //______________________________________________________________________________
02630 void TH2Editor::DoYAxisRange()
02631 {
02632    // Slot connected to the Max/Min number entry fields showing y-axis range.
02633 
02634    if (fAvoidSignal) return;
02635    TAxis* yaxis = fHist->GetYaxis();
02636    Int_t ny = yaxis->GetNbins();
02637    Double_t width = yaxis->GetBinWidth(1);
02638 
02639    if ((fSldYMin->GetNumber()+width/2) < (yaxis->GetBinLowEdge(1)))
02640       fSldYMin->SetNumber(yaxis->GetBinLowEdge(1));
02641    if ((fSldYMax->GetNumber()-width/2) > (yaxis->GetBinUpEdge(ny)))
02642       fSldYMax->SetNumber(yaxis->GetBinUpEdge(ny));
02643 
02644    yaxis->SetRangeUser(fSldYMin->GetNumber()+width/2,
02645                        fSldYMax->GetNumber()-width/2);
02646    Int_t nybinmin = yaxis -> GetFirst();
02647    Int_t nybinmax = yaxis -> GetLast();
02648    fSliderY->SetPosition((Double_t)(nybinmin),(Double_t)(nybinmax));
02649    Update();
02650 }
02651 
02652 //______________________________________________________________________________
02653 void TH2Editor::DoFillColor(Pixel_t color)
02654 {
02655    // Slot connected to the fill area color.
02656 
02657    if (fAvoidSignal || !fGedEditor->GetPad()) return;
02658    fGedEditor->GetPad()->cd();
02659    fGedEditor->GetPad()->SetFrameFillColor(TColor::GetColor(color));
02660    Update();
02661 }
02662 
02663 //______________________________________________________________________________
02664 void TH2Editor::DoFillPattern(Style_t pattern)
02665 {
02666    // Slot connected to the fill area pattern.
02667 
02668    if (fAvoidSignal || !fGedEditor->GetPad()) return;
02669    fGedEditor->GetPad()->cd();
02670    fGedEditor->GetPad()->SetFrameFillStyle(pattern);
02671    Update();
02672 }
02673 
02674 //______________________________________________________________________________
02675 TString TH2Editor::GetHistTypeLabel()
02676 {
02677    // Return the immediate histogram type (HIST, LEGO1-2, SURF1-5).
02678 
02679    TString s="";
02680    switch (fTypeCombo->GetSelected()){
02681       case (-1)         : {s = ""; break;}
02682       case (kTYPE_LEGO ): {s = "LEGO"; break;}
02683       case (kTYPE_LEGO1): {s = "LEGO1"; break;}
02684       case (kTYPE_LEGO2): {s = "LEGO2"; break;}
02685       case (kTYPE_SURF ): {s = "SURF";  break;}
02686       case (kTYPE_SURF1): {s = "SURF1"; break;}
02687       case (kTYPE_SURF2): {s = "SURF2"; break;}
02688       case (kTYPE_SURF3): {s = "SURF3"; break;}
02689       case (kTYPE_SURF4): {s = "SURF4"; break;}
02690       case (kTYPE_SURF5): {s = "SURF5"; break;}
02691       default:  break;
02692    }
02693    return s;
02694 }
02695 
02696 //______________________________________________________________________________
02697 TString TH2Editor::GetHistCoordsLabel()
02698 {
02699    // Return the immediate coordinate system of the histogram.
02700    // (POL, CYL, SPH,PSR)
02701 
02702    TString s="";
02703    switch (fCoordsCombo->GetSelected()){
02704       case (-1)         : {s = ""; break;}
02705       case (kCOORDS_CAR): {s = ""; break;}
02706       case (kCOORDS_POL): {s = "POL"; break;}
02707       case (kCOORDS_CYL): {s = "CYL"; break;}
02708       case (kCOORDS_SPH): {s = "SPH"; break;}
02709       case (kCOORDS_PSR): {s = "PSR"; break;}
02710       default:  break;
02711    }
02712    return s;
02713 }
02714 
02715 //______________________________________________________________________________
02716 TString TH2Editor::GetHistContLabel()
02717 {
02718    // Returns histogram contour option (None,Cont0..5).
02719 
02720    TString s="";
02721    switch (fContCombo->GetSelected()){
02722       case (-1)         : {s = ""; break;}
02723       case (kCONT_NONE) : {s = ""; break;}
02724       case (kCONT_0)    : {s = "CONT0"; break;}
02725       case (kCONT_1)    : {s = "CONT1"; break;}
02726       case (kCONT_2)    : {s = "CONT2"; break;}
02727       case (kCONT_3)    : {s = "CONT3"; break;}
02728       case (kCONT_4)    : {s = "CONT4"; break;}
02729       default:  break;
02730    }
02731    return s;
02732 }
02733 
02734 //______________________________________________________________________________
02735 TString TH2Editor::GetHistAdditiveLabel()
02736 {
02737    // Return histogram additive options (Arr,Box,Col,Scat,Col,Text,E,Z,FB,BB).
02738 
02739    TString s="";
02740    if (fDim->GetState()==kButtonDown) {
02741       if (fAddArr->GetState()==kButtonDown) s+="ARR";
02742       if (fAddBox->GetState()==kButtonDown) s+="BOX";
02743       if (fAddCol->GetState()==kButtonDown) s+="COL";
02744       if (fAddScat->GetState()==kButtonDown) s+="SCAT";
02745       if (fAddText->GetState()==kButtonDown) s+="TEXT";
02746       if (fAddPalette->GetState()==kButtonDown) s+="Z";
02747    } else if (fDim0->GetState()==kButtonDown){
02748       if (fAddPalette1->GetState()==kButtonDown) s+="Z";
02749       if (fAddError->GetState()==kButtonDown) s+="E";
02750       if (fAddFB->GetState()==kButtonUp) s+="FB";
02751       if (fAddBB->GetState()==kButtonUp) s+="BB";
02752    }
02753    return s;
02754 }
02755 
02756 //______________________________________________________________________________
02757 TString TH2Editor::GetCutOptionString()
02758 {
02759    // Return draw option string related to graphical cut in use.
02760 
02761    TString cutopt = " ";
02762    TString opt = GetDrawOption();
02763    Int_t scut = opt.First('[');
02764    if (scut != -1) {
02765       Int_t ecut = opt.First(']');
02766       cutopt += opt(scut,ecut);
02767    }
02768    return cutopt;
02769 }
02770 
02771 //______________________________________________________________________________
02772 TGComboBox* TH2Editor::BuildHistTypeComboBox(TGFrame* parent, Int_t id)
02773 {
02774    // Create histogram type combo box.
02775 
02776    TGComboBox *c = new TGComboBox(parent, id);
02777 
02778    c->AddEntry("Lego" , kTYPE_LEGO);
02779    c->AddEntry("Lego1", kTYPE_LEGO1);
02780    c->AddEntry("Lego2", kTYPE_LEGO2);
02781    c->AddEntry("Surf" , kTYPE_SURF);
02782    c->AddEntry("Surf1", kTYPE_SURF1);
02783    c->AddEntry("Surf2", kTYPE_SURF2);
02784    c->AddEntry("Surf3", kTYPE_SURF3);
02785    c->AddEntry("Surf4", kTYPE_SURF4);
02786    c->AddEntry("Surf5", kTYPE_SURF5);
02787 
02788    return c;
02789 }
02790 
02791 //______________________________________________________________________________
02792 TGComboBox* TH2Editor::BuildHistCoordsComboBox(TGFrame* parent, Int_t id)
02793 {
02794    // Create coordinate system combo box.
02795 
02796    TGComboBox *c = new TGComboBox(parent, id);
02797 
02798    c->AddEntry("Cartesian", kCOORDS_CAR);
02799    c->AddEntry("Cylindric", kCOORDS_CYL);
02800    c->AddEntry("Polar", kCOORDS_POL);
02801    c->AddEntry("Rapidity", kCOORDS_PSR);
02802    c->AddEntry("Spheric", kCOORDS_SPH);
02803    TGListBox* lb = c->GetListBox();
02804    lb->Resize(lb->GetWidth(), 83);
02805 
02806    return c;
02807 }
02808 
02809 //______________________________________________________________________________
02810 TGComboBox* TH2Editor::BuildHistContComboBox(TGFrame* parent, Int_t id)
02811 {
02812    // Create contour combo box.
02813 
02814    TGComboBox *c = new TGComboBox(parent, id);
02815 
02816    c->AddEntry("None" , kCONT_NONE);
02817    c->AddEntry("Cont0", kCONT_0);
02818    c->AddEntry("Cont1", kCONT_1);
02819    c->AddEntry("Cont2", kCONT_2);
02820    c->AddEntry("Cont3", kCONT_3);
02821    c->AddEntry("Cont4", kCONT_4);
02822 
02823    return c;
02824 }
02825 
02826 //______________________________________________________________________________
02827 void TH2Editor::PaintBox3D(Float_t *p1, Float_t *p2,Float_t *p3, Float_t *p4)
02828 {
02829    // Paint a square in 3D.
02830 
02831    fGedEditor->GetPad()->PaintLine3D(p1, p2);
02832    fGedEditor->GetPad()->PaintLine3D(p2, p3);
02833    fGedEditor->GetPad()->PaintLine3D(p3, p4);
02834    fGedEditor->GetPad()->PaintLine3D(p4, p1);
02835 }
02836 //______________________________________________________________________________
02837 Int_t* TH2Editor::Dividers(Int_t n)
02838 {
02839    // Give an array of dividers of n (without the trivial divider n))
02840    // in the first entry the number of dividers is saved.
02841 
02842    Int_t* div;
02843    if (n <= 0) {
02844       div = new Int_t[1];
02845       div[0]=0;
02846    } else if (n == 1) {
02847       div = new Int_t[2];
02848       div[0]=div[1]=1;
02849    } else {
02850       div = new Int_t[(Int_t) n/2+2];
02851       div[0]=0;
02852       div[1]=1;
02853 
02854       Int_t num = 1;
02855       for (Int_t i=2; i <= n/2; i++) {
02856          if (n % i == 0) {
02857             num++;
02858             div[num] = i;
02859          }
02860       }
02861       num++;
02862       div[num]=n;
02863       div[0] = num;
02864    }
02865    return div;
02866 }
02867 
02868 //______________________________________________________________________________
02869 void TH2Editor::ActivateBaseClassEditors(TClass* /*cl*/)
02870 {
02871    // Skip TH1Editor in building list of editors.
02872 
02873    fGedEditor->ActivateEditors(TH1::Class()->GetListOfBases(), kTRUE);
02874 }
02875 

Generated on Tue Jul 5 14:19:48 2011 for ROOT_528-00b_version by  doxygen 1.5.1