5 #include <Reve/RGTopFrame.h>
8 #include <TTreePlayer.h>
16 //______________________________________________________________________
22 PointSet::PointSet(Int_t n_points, TreeVarType_e tv_type) :
23 RenderElement(fMarkerColor),
24 TPointSet3D(n_points),
25 TPointSelectorConsumer(tv_type)
30 PointSet::PointSet(const Text_t* name, Int_t n_points, TreeVarType_e tv_type) :
31 RenderElement(fMarkerColor),
32 TPointSet3D(n_points),
33 TPointSelectorConsumer(tv_type)
39 PointSet::PointSet(const Text_t* name, TTree* tree, TreeVarType_e tv_type) :
40 RenderElement(fMarkerColor),
41 TPointSet3D(tree->GetSelectedRows()),
42 TPointSelectorConsumer(tv_type)
44 static const Exc_t eH("PointSet::PointSet ");
49 TTreePlayer* tp = dynamic_cast<TTreePlayer*>(tree->GetPlayer());
50 TakeAction(dynamic_cast<TSelectorDraw*>(tp->GetSelector()));
53 /**************************************************************************/
55 void PointSet::Reset(Int_t n_points)
59 if(fN) fP = new Float_t [3*fN];
60 memset(fP, 0, 3*fN*sizeof(Float_t));
65 Int_t PointSet::GrowFor(Int_t n_points)
67 // Resizes internal array to allow additional n_points to be stored.
68 // Returns the old size which is also the location where one can
69 // start storing new data.
70 // The caller is *obliged* to fill the new point slots.
72 Int_t old_size = Size();
73 Int_t new_size = old_size + n_points;
74 SetPoint(new_size - 1, 0, 0, 0);
78 /**************************************************************************/
80 void PointSet::Paint(Option_t* option)
82 if(fRnrElement == kFALSE) return;
84 TPointSet3D::Paint(option);
87 /**************************************************************************/
89 void PointSet::TakeAction(TSelectorDraw* sel)
91 static const Exc_t eH("PointSet::TakeAction ");
94 throw(eH + "selector is <null>.");
96 Int_t n = sel->GetNfill();
97 Int_t beg = GrowFor(n);
98 Float_t *p = fP + 3*beg;
100 // printf("PointSet::TakeAction beg=%d n=%d size=%d\n", beg, n, Size());
102 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
107 p[0] = *vx; p[1] = *vy; p[2] = *vz;
114 p[0] = *vx * TMath::Cos(*vy); p[1] = *vx * TMath::Sin(*vy); p[2] = *vz;
120 throw(eH + "unknown tree variable type.");
124 /**************************************************************************/
125 /**************************************************************************/
127 //______________________________________________________________________
131 ClassImp(PointSetArray)
133 PointSetArray::PointSetArray(const Text_t* name,
134 const Text_t* title) :
135 RenderElementListBase(fMarkerColor),
137 fBins(0), fDefPointSetCapacity(128), fNBins(0)
140 PointSetArray::~PointSetArray()
142 printf("PointSetArray::~PointSetArray()\n");
143 delete [] fBins; fBins = 0;
146 void PointSetArray::RemoveElementLocal(RenderElement* el)
148 for(Int_t i=0; i<fNBins; ++i) {
154 RenderElementListBase::RemoveElementLocal(el);
157 void PointSetArray::RemoveElements()
159 delete [] fBins; fBins = 0;
160 RenderElementListBase::RemoveElements();
163 /**************************************************************************/
165 void PointSetArray::SetMarkerColor(Color_t tcolor)
167 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
168 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
169 if(m && m->GetMarkerColor() == fMarkerColor)
170 m->SetMarkerColor(tcolor);
172 TAttMarker::SetMarkerColor(tcolor);
175 void PointSetArray::SetMarkerStyle(Style_t mstyle)
177 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
178 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
179 if(m && m->GetMarkerStyle() == fMarkerStyle)
180 m->SetMarkerStyle(mstyle);
182 TAttMarker::SetMarkerStyle(mstyle);
185 void PointSetArray::SetMarkerSize(Size_t msize)
187 for(lpRE_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
188 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
189 if(m && m->GetMarkerSize() == fMarkerSize)
190 m->SetMarkerSize(msize);
192 TAttMarker::SetMarkerSize(msize);
195 /**************************************************************************/
197 void PointSetArray::TakeAction(TSelectorDraw* sel)
199 static const Exc_t eH("PointSetArray::TakeAction ");
202 throw(eH + "selector is <null>.");
204 Int_t n = sel->GetNfill();
206 // printf("PointSetArray::TakeAction n=%d\n", n);
208 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
209 Double_t *qq = sel->GetV4();
212 throw(eH + "requires 4-d varexp.");
217 Fill(*vx, *vy, *vz, *qq);
218 ++vx; ++vy; ++vz; ++qq;
223 Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq);
224 ++vx; ++vy; ++vz; ++qq;
228 throw(eH + "unknown tree variable type.");
232 /**************************************************************************/
234 void PointSetArray::InitBins(const Text_t* quant_name,
235 Int_t nbins, Double_t min, Double_t max,
238 static const Exc_t eH("PointSetArray::InitBins ");
240 if(nbins < 1) throw(eH + "nbins < 1.");
241 if(min > max) throw(eH + "min > max.");
245 fQuantName = quant_name;
247 fMin = fCurMin = min;
248 fMax = fCurMax = max;
249 fBinWidth = (fMax - fMin)/fNBins;
251 fBins = new Reve::PointSet*[fNBins];
252 for(Int_t i=0; i<fNBins; ++i) {
253 fBins[i] = new Reve::PointSet
254 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + i*fBinWidth, fMin + (i+1)*fBinWidth),
255 fDefPointSetCapacity);
256 fBins[i]->SetMarkerColor(fMarkerColor);
257 fBins[i]->SetMarkerStyle(fMarkerStyle);
258 fBins[i]->SetMarkerSize(fMarkerSize);
260 gReve->AddRenderElement(this, fBins[i]);
262 AddElement(fBins[i]);
266 void PointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
268 Int_t bin = Int_t( (quant - fMin)/fBinWidth );
269 if(bin >= 0 && bin < fNBins && fBins[bin] != 0)
270 fBins[bin]->SetNextPoint(x, y, z);
273 void PointSetArray::CloseBins()
275 for(Int_t i=0; i<fNBins; ++i) {
277 // HACK! PolyMarker3D does half-management of array size.
278 // In fact, the error is mine, in pointset3d(gl) i use fN instead of Size().
279 // Fixed in my root, but not elsewhere.
280 fBins[i]->fN = fBins[i]->fLastPoint;
282 fBins[i]->ComputeBBox();
287 /**************************************************************************/
289 void PointSetArray::SetRange(Double_t min, Double_t max)
291 using namespace TMath;
293 fCurMin = min; fCurMax = max;
294 Int_t low_b = (Int_t) Max(Double_t(0), Floor((min-fMin)/fBinWidth));
295 Int_t high_b = (Int_t) Min(Double_t(fNBins-1), Ceil((max-fMin)/fBinWidth));
296 for(Int_t i=0; i<fNBins; ++i) {
298 fBins[i]->SetRnrElement(i>=low_b && i<=high_b);