TGL5D.cxx

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGL5D.cxx 29602 2009-07-28 10:23:20Z brun $
00002 // Author: Timur Pocheptsov  2009
00003 /*************************************************************************
00004  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
00005  * All rights reserved.                                                  *
00006  *                                                                       *
00007  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00008  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00009  *************************************************************************/
00010 #include <stdexcept>
00011 
00012 #include "TTreeFormula.h"
00013 #include "TTree.h"
00014 #include "TMath.h"
00015 #include "TH3.h"
00016 
00017 #include "TGLPlotCamera.h"
00018 #include "TGL5DPainter.h"
00019 #include "TGL5D.h"
00020 
00021 ClassImp(TGL5DDataSet)
00022 
00023 namespace {
00024 
00025 void FindRange(Long64_t size, const Double_t *src, Rgl::Range_t &range);
00026 
00027 }
00028 
00029 //______________________________________________________________________________
00030 TGL5DDataSet::TGL5DDataSet(TTree *tree)
00031                : TNamed("TGL5DataSet", "TGL5DataSet"),
00032                  fNP(0),
00033                  fV1(0), fV2(0), fV3(0), fV4(0), fV5(0),
00034                  fV1Range(1.), fV2Range(1.), fV3Range(1.),
00035                  fV4IsString(kFALSE)
00036 {
00037    //Constructor. Reads data from TTree,
00038    //estimates ranges, creates a painter.
00039    if (!tree) {
00040       Error("TGL5Data", "Null pointer tree.");
00041       throw std::runtime_error("");
00042    }
00043    
00044    fNP = tree->GetSelectedRows();
00045 
00046    Info("TGL5DDataSet", "Number of selected rows: %d", Int_t(fNP))   ;
00047    //Now, let's access the data and find ranges.
00048    fV1 = tree->GetVal(0);
00049    fV2 = tree->GetVal(1);
00050    fV3 = tree->GetVal(2);
00051    fV4 = tree->GetVal(3);
00052    fV5 = tree->GetVal(4);
00053    //
00054    fV4IsString = tree->GetVar(3)->IsString();
00055    //
00056    if (!fV1 || !fV2 || !fV3 || !fV4 || !fV5) {
00057       Error("TGL5DDataSet", "One or all of vN is a null pointer.");
00058       throw std::runtime_error("");
00059    }
00060    //   
00061    FindRange(fNP, fV1, fV1MinMax);
00062    FindRange(fNP, fV2, fV2MinMax);
00063    FindRange(fNP, fV3, fV3MinMax);
00064    FindRange(fNP, fV4, fV4MinMax);
00065    FindRange(fNP, fV5, fV5MinMax);
00066    //
00067    const Double_t v1Add = 0.1 * (fV1MinMax.second - fV1MinMax.first);
00068    const Double_t v2Add = 0.1 * (fV2MinMax.second - fV2MinMax.first);
00069    const Double_t v3Add = 0.1 * (fV3MinMax.second - fV3MinMax.first);
00070    //Adjust ranges.   
00071    fV1MinMax.first  -= v1Add, fV1MinMax.second += v1Add;
00072    fV1Range = fV1MinMax.second - fV1MinMax.first;
00073    fV2MinMax.first  -= v2Add, fV2MinMax.second += v2Add;
00074    fV2Range = fV2MinMax.second - fV2MinMax.first;
00075    fV3MinMax.first  -= v3Add, fV3MinMax.second += v3Add;
00076    fV3Range = fV3MinMax.second - fV3MinMax.first;
00077    //Set axes.
00078    TH3F hist("tmp", "tmp", 2, -1., 1., 2, -1., 1., 2, -1., 1.);
00079    //TAxis has a lot of attributes, defaults, set by ctor,
00080    //are not enough to be correctly painted by TGaxis object.
00081    //To simplify their initialization - I use temporary histogram.
00082    hist.GetXaxis()->Copy(fXAxis);
00083    hist.GetYaxis()->Copy(fYAxis);
00084    hist.GetZaxis()->Copy(fZAxis);
00085    
00086    fXAxis.Set(kDefaultNB, fV1MinMax.first, fV1MinMax.second);
00087    fYAxis.Set(kDefaultNB, fV2MinMax.first, fV2MinMax.second);
00088    fZAxis.Set(kDefaultNB, fV3MinMax.first, fV3MinMax.second);
00089 
00090    fPainter.reset(new TGLHistPainter(this));
00091    SetBit(kCanDelete);//TPad will delete this object when closed.
00092 }
00093 
00094 //______________________________________________________________________________
00095 Int_t TGL5DDataSet::DistancetoPrimitive(Int_t px, Int_t py)
00096 {
00097    //Check, if the object is under cursor.
00098    return fPainter->DistancetoPrimitive(px, py);
00099 }
00100 
00101 //______________________________________________________________________________
00102 void TGL5DDataSet::ExecuteEvent(Int_t event, Int_t px, Int_t py)
00103 {
00104    //Action.
00105    return fPainter->ExecuteEvent(event, px, py);
00106 }
00107 
00108 //______________________________________________________________________________
00109 char *TGL5DDataSet::GetObjectInfo(Int_t /*px*/, Int_t /*py*/) const
00110 {
00111    //Info for status bar.
00112    static char mess[] = {"5d data set"};
00113    return mess;
00114 }
00115 
00116 //______________________________________________________________________________
00117 void TGL5DDataSet::Paint(Option_t * /*option*/)
00118 {
00119    //Paint.
00120    fPainter->Paint("dummyoption");
00121 }
00122 
00123 //______________________________________________________________________________
00124 TGL5DPainter *TGL5DDataSet::GetRealPainter()const
00125 {
00126    //Get access to painter (for GUI-editor).
00127    return static_cast<TGL5DPainter *>(fPainter->GetRealPainter());
00128 }
00129 
00130 //______________________________________________________________________________
00131 void TGL5DDataSet::SelectPoints(Double_t v4Level, Double_t range)
00132 {
00133    //"Select" sub-range from source data
00134    //- remember indices of "good" points.
00135    fIndices.clear();
00136 
00137    for (Int_t i = 0; i < fNP; ++i)
00138       if (TMath::Abs(fV4[i] - v4Level) < range)
00139          fIndices.push_back(i);
00140 }
00141 
00142 //______________________________________________________________________________
00143 UInt_t TGL5DDataSet::SelectedSize()const
00144 {
00145    //Size of selected sub-range.
00146    return UInt_t(fIndices.size());
00147 }
00148 
00149 //______________________________________________________________________________
00150 Double_t TGL5DDataSet::V1(UInt_t ind)const
00151 {
00152    //V1 from sub-range, converted to unit cube.
00153    return V1ToUnitCube(fV1[fIndices[ind]]);
00154 }
00155 
00156 //______________________________________________________________________________
00157 Double_t TGL5DDataSet::V2(UInt_t ind)const
00158 {
00159    //V2 from sub-range, converted to unit cube.
00160    return V2ToUnitCube(fV2[fIndices[ind]]);
00161 }
00162 
00163 //______________________________________________________________________________
00164 Double_t TGL5DDataSet::V3(UInt_t ind)const
00165 {
00166    //V3 from sub-range, converted to unit cube.
00167    return V3ToUnitCube(fV3[fIndices[ind]]);
00168 }
00169 
00170 //______________________________________________________________________________
00171 TAxis *TGL5DDataSet::GetXAxis()const
00172 {
00173    //X axis for plot.
00174    return &fXAxis;
00175 }
00176 
00177 //______________________________________________________________________________
00178 TAxis *TGL5DDataSet::GetYAxis()const
00179 {
00180    //Y axis for plot.
00181    return &fYAxis;
00182 }
00183 
00184 //______________________________________________________________________________
00185 TAxis *TGL5DDataSet::GetZAxis()const
00186 {
00187    //Z axis for plot.
00188    return &fZAxis;
00189 }
00190 
00191 //______________________________________________________________________________
00192 const Rgl::Range_t &TGL5DDataSet::GetXRange()const
00193 {
00194    //V1 range (X).
00195    return fV1MinMax;
00196 }
00197 
00198 //______________________________________________________________________________
00199 const Rgl::Range_t &TGL5DDataSet::GetYRange()const
00200 {
00201    //V2 range (Y).
00202    return fV2MinMax;
00203 }
00204 
00205 //______________________________________________________________________________
00206 const Rgl::Range_t &TGL5DDataSet::GetZRange()const
00207 {
00208    //V3 range (Z).
00209    return fV3MinMax;
00210 }
00211 
00212 //______________________________________________________________________________
00213 const Rgl::Range_t &TGL5DDataSet::GetV4Range()const
00214 {
00215    //V4 range.
00216    return fV4MinMax;
00217 }
00218 
00219 //______________________________________________________________________________
00220 Double_t TGL5DDataSet::V1ToUnitCube(Double_t v1)const
00221 {
00222    //V1 to unit cube.
00223    return (v1 - fV1MinMax.first) / fV1Range;
00224 }
00225 
00226 //______________________________________________________________________________
00227 Double_t TGL5DDataSet::V2ToUnitCube(Double_t v2)const
00228 {
00229    //V2 to unit cube.
00230    return (v2 - fV2MinMax.first) / fV2Range;
00231 }
00232 
00233 //______________________________________________________________________________
00234 Double_t TGL5DDataSet::V3ToUnitCube(Double_t v3)const
00235 {
00236    //V3 to unit cube.
00237    return (v3 - fV3MinMax.first) / fV3Range;
00238 }
00239 
00240 namespace {
00241 
00242 //______________________________________________________________________________
00243 void FindRange(Long64_t size, const Double_t *src, Rgl::Range_t &range)
00244 {
00245    //Find both min and max on a range in one pass through sequence.
00246    range.first  = src[0];
00247    range.second = src[0];
00248    
00249    for (Long64_t i = 1; i < size; ++i) {
00250       range.first  = TMath::Min(range.first,  src[i]);
00251       range.second = TMath::Max(range.second, src[i]);
00252    }
00253 }
00254 
00255 }

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