pointset.C

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: pointset.C 32410 2010-02-25 18:51:45Z matevz $
00002 // Author: Matevz Tadel
00003 
00004 // Demonstrates usage of class TEvePointSet.
00005 
00006 #ifndef __CINT__
00007 
00008 #include <TEveManager.h>
00009 #include <TEvePointSet.h>
00010 #include <TEveRGBAPalette.h>
00011 #include <TColor.h>
00012 #include <TRandom.h>
00013 #include <TMath.h>
00014 
00015 #endif
00016 
00017 TEvePointSet* pointset(Int_t npoints = 512, TEveElement* parent=0)
00018 {
00019    TEveManager::Create();
00020 
00021    if (!gRandom)
00022       gRandom = new TRandom(0);
00023    TRandom& r= *gRandom;
00024 
00025    Float_t s = 100;
00026 
00027    TEvePointSet* ps = new TEvePointSet();
00028    ps->SetOwnIds(kTRUE);
00029 
00030    for(Int_t i = 0; i<npoints; i++)
00031    {
00032       ps->SetNextPoint(r.Uniform(-s,s), r.Uniform(-s,s), r.Uniform(-s,s));
00033       ps->SetPointId(new TNamed(Form("Point %d", i), ""));
00034    }
00035 
00036    ps->SetMarkerColor(TMath::Nint(r.Uniform(2, 9)));
00037    ps->SetMarkerSize(r.Uniform(1, 2));
00038    ps->SetMarkerStyle(4);
00039 
00040    if (parent)
00041    {
00042       parent->AddElement(ps);
00043    }
00044    else
00045    {
00046       gEve->AddElement(ps);
00047       gEve->Redraw3D();
00048    }
00049 
00050    return ps;
00051 }
00052 
00053 TEvePointSet*
00054 pointset_hierarchy(Int_t level=3, Int_t nps=1, Int_t fac=2,
00055                         Int_t npoints=512, TEveElement* parent=0)
00056 {
00057    // This only works in compiled mode!
00058 
00059    TEvePointSet* ps = 0;
00060    --level;
00061    for (Int_t i=0; i<nps; ++i)
00062    {
00063       printf("level=%d nps=%d i=%d\n", level, nps, i);
00064       ps = pointset(npoints, parent);
00065       if (level)
00066       {
00067          pointset_hierarchy(level, nps*fac, fac, npoints/fac, ps);
00068       }
00069    }
00070    return ps;
00071 }
00072 
00073 TEvePointSetArray* pointsetarray()
00074 {
00075    TEveManager::Create();
00076 
00077    TRandom r(0);
00078 
00079    TEvePointSetArray* l = new TEvePointSetArray("TPC hits - Charge Slices", "");
00080    l->SetSourceCS(TEvePointSelectorConsumer::kTVT_RPhiZ);
00081    l->SetMarkerColor(3);
00082    l->SetMarkerStyle(4); // antialiased circle
00083    l->SetMarkerSize(0.8);
00084 
00085    gEve->AddElement(l);
00086    l->InitBins("Charge", 9, 10, 100);
00087 
00088    TColor::SetPalette(1, 0); // Spectrum palette
00089    const Int_t nCol = TColor::GetNumberOfColors();
00090    for (Int_t i = 1; i <= 9; ++i)
00091       l->GetBin(i)->SetMainColor(TColor::GetColorPalette(i * nCol / 10));
00092 
00093    l->GetBin(0) ->SetMainColor(kGray);
00094    l->GetBin(10)->SetMainColor(kWhite);
00095 
00096    Double_t rad, phi, z;
00097    for (Int_t i = 0; i < 10000; ++i)
00098    {
00099       rad = r.Uniform(60, 180);
00100       phi = r.Uniform(0, TMath::TwoPi());
00101       z   = r.Uniform(-250, 250);
00102       l->Fill(rad*TMath::Cos(phi), rad*TMath::Sin(phi), z,
00103               r.Uniform(0, 110));
00104    }
00105 
00106    l->CloseBins();
00107 
00108    gEve->Redraw3D();
00109 
00110    return l;
00111 }

Generated on Tue Jul 5 15:43:51 2011 for ROOT_528-00b_version by  doxygen 1.5.1