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),
32 PointSet::PointSet(const Text_t* name, Int_t n_points, TreeVarType_e tv_type) :
33 RenderElement(fMarkerColor),
34 TPointSet3D(n_points),
35 TPointSelectorConsumer(tv_type),
43 PointSet::PointSet(const Text_t* name, TTree* tree, TreeVarType_e tv_type) :
44 RenderElement(fMarkerColor),
45 TPointSet3D(tree->GetSelectedRows()),
46 TPointSelectorConsumer(tv_type),
50 static const Exc_t eH("PointSet::PointSet ");
55 TTreePlayer* tp = dynamic_cast<TTreePlayer*>(tree->GetPlayer());
56 TakeAction(dynamic_cast<TSelectorDraw*>(tp->GetSelector()));
59 /**************************************************************************/
61 void PointSet::Reset(Int_t n_points)
65 if(fN) fP = new Float_t [3*fN];
66 memset(fP, 0, 3*fN*sizeof(Float_t));
72 Int_t PointSet::GrowFor(Int_t n_points)
74 // Resizes internal array to allow additional n_points to be stored.
75 // Returns the old size which is also the location where one can
76 // start storing new data.
77 // The caller is *obliged* to fill the new point slots.
79 Int_t old_size = Size();
80 Int_t new_size = old_size + n_points;
81 SetPoint(new_size - 1, 0, 0, 0);
85 /**************************************************************************/
87 void PointSet::Paint(Option_t* option)
89 if(fRnrElement == kFALSE) return;
91 TPointSet3D::Paint(option);
94 /**************************************************************************/
96 void PointSet::TakeAction(TSelectorDraw* sel)
98 static const Exc_t eH("PointSet::TakeAction ");
101 throw(eH + "selector is <null>.");
103 Int_t n = sel->GetNfill();
104 Int_t beg = GrowFor(n);
105 Float_t *p = fP + 3*beg;
107 // printf("PointSet::TakeAction beg=%d n=%d size=%d\n", beg, n, Size());
109 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
114 p[0] = *vx; p[1] = *vy; p[2] = *vz;
121 p[0] = *vx * TMath::Cos(*vy); p[1] = *vx * TMath::Sin(*vy); p[2] = *vz;
127 throw(eH + "unknown tree variable type.");
131 /**************************************************************************/
132 /**************************************************************************/
134 //______________________________________________________________________
138 ClassImp(PointSetArray)
140 PointSetArray::PointSetArray(const Text_t* name,
141 const Text_t* title) :
142 RenderElementListBase(fMarkerColor),
145 fBins(0), fDefPointSetCapacity(128), fNBins(0),
146 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
151 PointSetArray::~PointSetArray()
153 // Destructor: deletes the fBins array. Actual removal of
154 // elements done by RenderElementListBase.
156 // printf("PointSetArray::~PointSetArray()\n");
157 delete [] fBins; fBins = 0;
160 void PointSetArray::RemoveElementLocal(RenderElement* el)
162 for(Int_t i=0; i<fNBins; ++i) {
168 RenderElementListBase::RemoveElementLocal(el);
171 void PointSetArray::RemoveElements()
173 delete [] fBins; fBins = 0;
174 RenderElementListBase::RemoveElements();
177 /**************************************************************************/
179 void PointSetArray::SetMarkerColor(Color_t tcolor)
181 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
182 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
183 if(m && m->GetMarkerColor() == fMarkerColor)
184 m->SetMarkerColor(tcolor);
186 TAttMarker::SetMarkerColor(tcolor);
189 void PointSetArray::SetMarkerStyle(Style_t mstyle)
191 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
192 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
193 if(m && m->GetMarkerStyle() == fMarkerStyle)
194 m->SetMarkerStyle(mstyle);
196 TAttMarker::SetMarkerStyle(mstyle);
199 void PointSetArray::SetMarkerSize(Size_t msize)
201 for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
202 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject());
203 if(m && m->GetMarkerSize() == fMarkerSize)
204 m->SetMarkerSize(msize);
206 TAttMarker::SetMarkerSize(msize);
209 /**************************************************************************/
211 void PointSetArray::TakeAction(TSelectorDraw* sel)
213 static const Exc_t eH("PointSetArray::TakeAction ");
216 throw(eH + "selector is <null>.");
218 Int_t n = sel->GetNfill();
220 // printf("PointSetArray::TakeAction n=%d\n", n);
222 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
223 Double_t *qq = sel->GetV4();
226 throw(eH + "requires 4-d varexp.");
231 Fill(*vx, *vy, *vz, *qq);
232 ++vx; ++vy; ++vz; ++qq;
237 Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq);
238 ++vx; ++vy; ++vz; ++qq;
242 throw(eH + "unknown tree variable type.");
246 /**************************************************************************/
248 void PointSetArray::InitBins(const Text_t* quant_name,
249 Int_t nbins, Double_t min, Double_t max,
252 static const Exc_t eH("PointSetArray::InitBins ");
254 if(nbins < 1) throw(eH + "nbins < 1.");
255 if(min > max) throw(eH + "min > max.");
259 fQuantName = quant_name;
261 fMin = fCurMin = min;
262 fMax = fCurMax = max;
263 fBinWidth = (fMax - fMin)/fNBins;
265 fBins = new Reve::PointSet*[fNBins];
266 for(Int_t i=0; i<fNBins; ++i) {
267 fBins[i] = new Reve::PointSet
268 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + i*fBinWidth, fMin + (i+1)*fBinWidth),
269 fDefPointSetCapacity);
270 fBins[i]->SetMarkerColor(fMarkerColor);
271 fBins[i]->SetMarkerStyle(fMarkerStyle);
272 fBins[i]->SetMarkerSize(fMarkerSize);
274 gReve->AddRenderElement(this, fBins[i]);
276 AddElement(fBins[i]);
280 void PointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
282 Int_t bin = Int_t( (quant - fMin)/fBinWidth );
283 if(bin >= 0 && bin < fNBins && fBins[bin] != 0)
284 fBins[bin]->SetNextPoint(x, y, z);
287 void PointSetArray::CloseBins()
289 for(Int_t i=0; i<fNBins; ++i) {
291 // HACK! PolyMarker3D does half-management of array size.
292 // In fact, the error is mine, in pointset3d(gl) i use fN instead of Size().
293 // Fixed in my root, but not elsewhere.
294 fBins[i]->fN = fBins[i]->fLastPoint;
296 fBins[i]->ComputeBBox();
301 /**************************************************************************/
303 void PointSetArray::SetRange(Double_t min, Double_t max)
305 using namespace TMath;
307 fCurMin = min; fCurMax = max;
308 Int_t low_b = (Int_t) Max(Double_t(0), Floor((min-fMin)/fBinWidth));
309 Int_t high_b = (Int_t) Min(Double_t(fNBins-1), Ceil((max-fMin)/fBinWidth));
310 for(Int_t i=0; i<fNBins; ++i) {
312 fBins[i]->SetRnrElement(i>=low_b && i<=high_b);