00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "TEvePointSet.h"
00013
00014 #include "TEveManager.h"
00015 #include "TEveProjectionManager.h"
00016 #include "TEveTrans.h"
00017
00018 #include "TTree.h"
00019 #include "TTreePlayer.h"
00020 #include "TF3.h"
00021
00022 #include "TColor.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 ClassImp(TEvePointSet);
00047
00048
00049 TEvePointSet::TEvePointSet(Int_t n_points, ETreeVarType_e tv_type) :
00050 TEveElement(fMarkerColor),
00051 TPointSet3D(n_points),
00052 TEvePointSelectorConsumer(tv_type),
00053 TEveProjectable(),
00054 TQObject(),
00055
00056 fTitle (),
00057 fIntIds (0),
00058 fIntIdsPerPoint (0)
00059 {
00060
00061
00062 fMarkerStyle = 20;
00063
00064
00065 fPickable = kTRUE;
00066 }
00067
00068
00069 TEvePointSet::TEvePointSet(const char* name, Int_t n_points, ETreeVarType_e tv_type) :
00070 TEveElement(fMarkerColor),
00071 TPointSet3D(n_points),
00072 TEvePointSelectorConsumer(tv_type),
00073 TEveProjectable(),
00074 TQObject(),
00075
00076 fTitle (),
00077 fIntIds (0),
00078 fIntIdsPerPoint (0)
00079 {
00080
00081
00082 fMarkerStyle = 20;
00083 SetName(name);
00084
00085
00086 fPickable = kTRUE;
00087 }
00088
00089
00090 TEvePointSet::TEvePointSet(const TEvePointSet& e) :
00091 TEveElement(e),
00092 TPointSet3D(e),
00093 TEvePointSelectorConsumer(e),
00094 TEveProjectable(),
00095 TQObject(),
00096
00097 fTitle (e.fTitle),
00098 fIntIds (e.fIntIds ? new TArrayI(*e.fIntIds) : 0),
00099 fIntIdsPerPoint (e.fIntIdsPerPoint)
00100 {
00101
00102 }
00103
00104
00105 TEvePointSet::~TEvePointSet()
00106 {
00107
00108
00109 delete fIntIds;
00110 }
00111
00112
00113
00114
00115 void TEvePointSet::ClonePoints(const TEvePointSet& e)
00116 {
00117
00118
00119
00120 delete [] fP;
00121 fN = e.fN;
00122 if (fN > 0)
00123 {
00124 const Int_t nn = 3 * e.fN;
00125 fP = new Float_t [nn];
00126 for (Int_t i = 0; i < nn; i++) fP[i] = e.fP[i];
00127 } else {
00128 fP = 0;
00129 }
00130 fLastPoint = e.fLastPoint;
00131
00132
00133 CopyIds(e);
00134
00135
00136 delete fIntIds;
00137 fIntIds = e.fIntIds ? new TArrayI(*e.fIntIds) : 0;
00138 fIntIdsPerPoint = e.fIntIdsPerPoint;
00139 }
00140
00141
00142
00143
00144 const TGPicture* TEvePointSet::GetListTreeIcon(Bool_t)
00145 {
00146
00147
00148 return TEveElement::fgListTreeIcons[3];
00149 }
00150
00151
00152 void TEvePointSet::Reset(Int_t n_points, Int_t n_int_ids)
00153 {
00154
00155
00156
00157
00158 delete [] fP; fP = 0;
00159 fN = n_points;
00160 if (fN) {
00161 fP = new Float_t [3*fN];
00162 memset(fP, 0, 3*fN*sizeof(Float_t));
00163 }
00164 fLastPoint = -1;
00165 ClearIds();
00166 delete fIntIds; fIntIds = 0;
00167 fIntIdsPerPoint = n_int_ids;
00168 if (fIntIdsPerPoint > 0) fIntIds = new TArrayI(fIntIdsPerPoint*fN);
00169 ResetBBox();
00170 }
00171
00172
00173 Int_t TEvePointSet::GrowFor(Int_t n_points)
00174 {
00175
00176
00177
00178
00179
00180 Int_t old_size = Size();
00181 Int_t new_size = old_size + n_points;
00182 SetPoint(new_size - 1, 0, 0, 0);
00183 if (fIntIds)
00184 fIntIds->Set(fIntIdsPerPoint * new_size);
00185 return old_size;
00186 }
00187
00188
00189
00190
00191 inline void TEvePointSet::AssertIntIdsSize()
00192 {
00193
00194
00195
00196 Int_t exp_size = GetN()*fIntIdsPerPoint;
00197 if (fIntIds->GetSize() < exp_size)
00198 fIntIds->Set(exp_size);
00199 }
00200
00201
00202 Int_t* TEvePointSet::GetPointIntIds(Int_t p) const
00203 {
00204
00205
00206
00207
00208
00209 if (fIntIds)
00210 return fIntIds->GetArray() + p*fIntIdsPerPoint;
00211 return 0;
00212 }
00213
00214
00215 Int_t TEvePointSet::GetPointIntId(Int_t p, Int_t i) const
00216 {
00217
00218
00219
00220
00221
00222 if (fIntIds)
00223 return * (fIntIds->GetArray() + p*fIntIdsPerPoint + i);
00224 return kMinInt;
00225 }
00226
00227
00228 void TEvePointSet::SetPointIntIds(Int_t* ids)
00229 {
00230
00231
00232
00233 SetPointIntIds(fLastPoint, ids);
00234 }
00235
00236
00237 void TEvePointSet::SetPointIntIds(Int_t n, Int_t* ids)
00238 {
00239
00240
00241 if (!fIntIds) return;
00242 AssertIntIdsSize();
00243 Int_t* x = fIntIds->GetArray() + n*fIntIdsPerPoint;
00244 for (Int_t i=0; i<fIntIdsPerPoint; ++i)
00245 x[i] = ids[i];
00246 }
00247
00248
00249
00250
00251 void TEvePointSet::SetMarkerStyle(Style_t mstyle)
00252 {
00253
00254
00255 static const TEveException eh("TEvePointSet::SetMarkerStyle ");
00256
00257 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
00258 while (pi != fProjectedList.end())
00259 {
00260 TEvePointSet* pt = dynamic_cast<TEvePointSet*>(*pi);
00261 if (pt)
00262 {
00263 pt->SetMarkerStyle(mstyle);
00264 pt->StampObjProps();
00265 }
00266 ++pi;
00267 }
00268 TAttMarker::SetMarkerStyle(mstyle);
00269 }
00270
00271
00272 void TEvePointSet::SetMarkerSize(Size_t msize)
00273 {
00274
00275
00276 static const TEveException eh("TEvePointSet::SetMarkerSize ");
00277
00278 std::list<TEveProjected*>::iterator pi = fProjectedList.begin();
00279 while (pi != fProjectedList.end())
00280 {
00281 TEvePointSet* pt = dynamic_cast<TEvePointSet*>(*pi);
00282 if (pt)
00283 {
00284 pt->SetMarkerSize(msize);
00285 pt->StampObjProps();
00286 }
00287 ++pi;
00288 }
00289 TAttMarker::SetMarkerSize(msize);
00290 }
00291
00292
00293
00294
00295 void TEvePointSet::Paint(Option_t*)
00296 {
00297
00298
00299 PaintStandard(this);
00300 }
00301
00302
00303
00304
00305 void TEvePointSet::InitFill(Int_t subIdNum)
00306 {
00307
00308
00309
00310
00311 if (subIdNum > 0) {
00312 fIntIdsPerPoint = subIdNum;
00313 if (!fIntIds)
00314 fIntIds = new TArrayI(fIntIdsPerPoint*GetN());
00315 else
00316 fIntIds->Set(fIntIdsPerPoint*GetN());
00317 } else {
00318 delete fIntIds; fIntIds = 0;
00319 fIntIdsPerPoint = 0;
00320 }
00321 }
00322
00323
00324 void TEvePointSet::TakeAction(TEvePointSelector* sel)
00325 {
00326
00327
00328
00329
00330 static const TEveException eh("TEvePointSet::TakeAction ");
00331
00332 if(sel == 0)
00333 throw(eh + "selector is <null>.");
00334
00335 Int_t n = sel->GetNfill();
00336 Int_t beg = GrowFor(n);
00337
00338
00339
00340
00341 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
00342 Float_t *p = fP + 3*beg;
00343
00344 switch(fSourceCS) {
00345 case kTVT_XYZ:
00346 while(n-- > 0) {
00347 p[0] = *vx; p[1] = *vy; p[2] = *vz;
00348 p += 3;
00349 ++vx; ++vy; ++vz;
00350 }
00351 break;
00352 case kTVT_RPhiZ:
00353 while(n-- > 0) {
00354 p[0] = *vx * TMath::Cos(*vy); p[1] = *vx * TMath::Sin(*vy); p[2] = *vz;
00355 p += 3;
00356 ++vx; ++vy; ++vz;
00357 }
00358 break;
00359 default:
00360 throw(eh + "unknown tree variable type.");
00361 }
00362
00363 if (fIntIds) {
00364 Double_t** subarr = new Double_t* [fIntIdsPerPoint];
00365 for (Int_t i=0; i<fIntIdsPerPoint; ++i) {
00366 subarr[i] = sel->GetVal(sel->GetDimension() - fIntIdsPerPoint + i);
00367 if (subarr[i] == 0)
00368 throw(eh + "sub-id array not available.");
00369 }
00370 Int_t* ids = fIntIds->GetArray() + fIntIdsPerPoint*beg;
00371 n = sel->GetNfill();
00372 while (n-- > 0) {
00373 for (Int_t i=0; i<fIntIdsPerPoint; ++i) {
00374 ids[i] = TMath::Nint(*subarr[i]);
00375 ++subarr[i];
00376 }
00377 ids += fIntIdsPerPoint;
00378 }
00379 delete [] subarr;
00380 }
00381 }
00382
00383
00384
00385
00386 void TEvePointSet::CopyVizParams(const TEveElement* el)
00387 {
00388
00389
00390 const TEvePointSet* m = dynamic_cast<const TEvePointSet*>(el);
00391 if (m)
00392 {
00393 TAttMarker::operator=(*m);
00394 fOption = m->fOption;
00395 }
00396
00397 TEveElement::CopyVizParams(el);
00398 }
00399
00400
00401 void TEvePointSet::WriteVizParams(ostream& out, const TString& var)
00402 {
00403
00404
00405 TEveElement::WriteVizParams(out, var);
00406
00407 TAttMarker::SaveMarkerAttributes(out, var);
00408 }
00409
00410
00411
00412
00413 TClass* TEvePointSet::ProjectedClass(const TEveProjection*) const
00414 {
00415
00416
00417 return TEvePointSetProjected::Class();
00418 }
00419
00420
00421 void TEvePointSet::PointSelected(Int_t id)
00422 {
00423
00424
00425
00426 Emit("PointSelected(Int_t)", id);
00427 TPointSet3D::PointSelected(id);
00428 }
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455 ClassImp(TEvePointSetArray);
00456
00457
00458 TEvePointSetArray::TEvePointSetArray(const char* name,
00459 const char* title) :
00460 TEveElement(fMarkerColor),
00461 TNamed(name, title),
00462
00463 fBins(0), fDefPointSetCapacity(128), fNBins(0), fLastBin(-1),
00464 fMin(0), fCurMin(0), fMax(0), fCurMax(0),
00465 fBinWidth(0),
00466 fQuantName()
00467 {
00468
00469 }
00470
00471
00472 TEvePointSetArray::~TEvePointSetArray()
00473 {
00474
00475
00476
00477
00478 delete [] fBins; fBins = 0;
00479 }
00480
00481
00482 void TEvePointSetArray::RemoveElementLocal(TEveElement* el)
00483 {
00484
00485
00486 for (Int_t i=0; i<fNBins; ++i) {
00487 if (fBins[i] == el) {
00488 fBins[i] = 0;
00489 break;
00490 }
00491 }
00492 }
00493
00494
00495 void TEvePointSetArray::RemoveElementsLocal()
00496 {
00497
00498
00499 delete [] fBins; fBins = 0; fLastBin = -1;
00500 }
00501
00502
00503
00504
00505 void TEvePointSetArray::SetMarkerColor(Color_t tcolor)
00506 {
00507
00508
00509 static const TEveException eh("TEvePointSetArray::SetMarkerColor ");
00510
00511 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
00512 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject(eh));
00513 if (m && m->GetMarkerColor() == fMarkerColor)
00514 m->SetMarkerColor(tcolor);
00515 }
00516 TAttMarker::SetMarkerColor(tcolor);
00517 }
00518
00519
00520 void TEvePointSetArray::SetMarkerStyle(Style_t mstyle)
00521 {
00522
00523
00524 static const TEveException eh("TEvePointSetArray::SetMarkerStyle ");
00525
00526 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
00527 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject(eh));
00528 if (m && m->GetMarkerStyle() == fMarkerStyle)
00529 m->SetMarkerStyle(mstyle);
00530 }
00531 TAttMarker::SetMarkerStyle(mstyle);
00532 }
00533
00534
00535 void TEvePointSetArray::SetMarkerSize(Size_t msize)
00536 {
00537
00538
00539 static const TEveException eh("TEvePointSetArray::SetMarkerSize ");
00540
00541 for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
00542 TAttMarker* m = dynamic_cast<TAttMarker*>((*i)->GetObject(eh));
00543 if (m && m->GetMarkerSize() == fMarkerSize)
00544 m->SetMarkerSize(msize);
00545 }
00546 TAttMarker::SetMarkerSize(msize);
00547 }
00548
00549
00550
00551
00552 void TEvePointSetArray::TakeAction(TEvePointSelector* sel)
00553 {
00554
00555
00556
00557
00558 static const TEveException eh("TEvePointSetArray::TakeAction ");
00559
00560 if (sel == 0)
00561 throw eh + "selector is <null>.";
00562
00563 Int_t n = sel->GetNfill();
00564
00565
00566
00567 Double_t *vx = sel->GetV1(), *vy = sel->GetV2(), *vz = sel->GetV3();
00568 Double_t *qq = sel->GetV4();
00569
00570 if (qq == 0)
00571 throw eh + "requires 4-d varexp.";
00572
00573 switch (fSourceCS)
00574 {
00575 case kTVT_XYZ:
00576 {
00577 while (n-- > 0)
00578 {
00579 Fill(*vx, *vy, *vz, *qq);
00580 ++vx; ++vy; ++vz; ++qq;
00581 }
00582 break;
00583 }
00584 case kTVT_RPhiZ:
00585 {
00586 while (n-- > 0)
00587 {
00588 Fill(*vx * TMath::Cos(*vy), *vx * TMath::Sin(*vy), *vz, *qq);
00589 ++vx; ++vy; ++vz; ++qq;
00590 }
00591 break;
00592 }
00593 default:
00594 {
00595 throw eh + "unknown tree variable type.";
00596 }
00597 }
00598 }
00599
00600
00601
00602
00603 Int_t TEvePointSetArray::Size(Bool_t under, Bool_t over) const
00604 {
00605
00606
00607
00608
00609 Int_t size = 0;
00610 const Int_t min = under ? 0 : 1;
00611 const Int_t max = over ? fNBins : fNBins - 1;
00612 for (Int_t i = min; i < max; ++i)
00613 {
00614 if (fBins[i])
00615 size += fBins[i]->Size();
00616 }
00617 return size;
00618 }
00619
00620
00621 void TEvePointSetArray::InitBins(const char* quant_name,
00622 Int_t nbins, Double_t min, Double_t max)
00623 {
00624
00625
00626
00627
00628 static const TEveException eh("TEvePointSetArray::InitBins ");
00629
00630 if (nbins < 1) throw eh + "nbins < 1.";
00631 if (min > max) throw eh + "min > max.";
00632
00633 RemoveElements();
00634
00635 fQuantName = quant_name;
00636 fNBins = nbins + 2;
00637 fLastBin = -1;
00638 fMin = fCurMin = min;
00639 fMax = fCurMax = max;
00640 fBinWidth = (fMax - fMin)/(fNBins - 2);
00641
00642 fBins = new TEvePointSet* [fNBins];
00643
00644 for (Int_t i = 0; i < fNBins; ++i)
00645 {
00646 fBins[i] = new TEvePointSet
00647 (Form("Slice %d [%4.3lf, %4.3lf]", i, fMin + (i-1)*fBinWidth, fMin + i*fBinWidth),
00648 fDefPointSetCapacity);
00649 fBins[i]->SetMarkerColor(fMarkerColor);
00650 fBins[i]->SetMarkerStyle(fMarkerStyle);
00651 fBins[i]->SetMarkerSize(fMarkerSize);
00652 AddElement(fBins[i]);
00653 }
00654
00655 fBins[0]->SetName("Underflow");
00656 fBins[0]->SetRnrSelf(kFALSE);
00657
00658 fBins[fNBins-1]->SetName("Overflow");
00659 fBins[fNBins-1]->SetRnrSelf(kFALSE);
00660 }
00661
00662
00663 Bool_t TEvePointSetArray::Fill(Double_t x, Double_t y, Double_t z, Double_t quant)
00664 {
00665
00666
00667
00668
00669
00670 fLastBin = TMath::FloorNint((quant - fMin)/fBinWidth) + 1;
00671
00672 if (fLastBin < 0)
00673 {
00674 fLastBin = 0;
00675 }
00676 else if (fLastBin > fNBins - 1)
00677 {
00678 fLastBin = fNBins - 1;
00679 }
00680
00681 if (fBins[fLastBin] != 0)
00682 {
00683 fBins[fLastBin]->SetNextPoint(x, y, z);
00684 return kTRUE;
00685 }
00686 else
00687 {
00688 return kFALSE;
00689 }
00690 }
00691
00692
00693 void TEvePointSetArray::SetPointId(TObject* id)
00694 {
00695
00696
00697 if (fLastBin >= 0)
00698 fBins[fLastBin]->SetPointId(id);
00699 }
00700
00701
00702 void TEvePointSetArray::CloseBins()
00703 {
00704
00705
00706
00707
00708 for (Int_t i=0; i<fNBins; ++i)
00709 {
00710 if (fBins[i] != 0)
00711 {
00712 fBins[i]->SetTitle(Form("N=%d", fBins[i]->Size()));
00713 fBins[i]->ComputeBBox();
00714 }
00715 }
00716 fLastBin = -1;
00717 }
00718
00719
00720
00721
00722 void TEvePointSetArray::SetOwnIds(Bool_t o)
00723 {
00724
00725
00726 for (Int_t i=0; i<fNBins; ++i)
00727 {
00728 if (fBins[i] != 0)
00729 fBins[i]->SetOwnIds(o);
00730 }
00731 }
00732
00733
00734
00735
00736 void TEvePointSetArray::SetRange(Double_t min, Double_t max)
00737 {
00738
00739
00740
00741
00742 using namespace TMath;
00743
00744 fCurMin = min; fCurMax = max;
00745 Int_t low_b = Max(0, FloorNint((min-fMin)/fBinWidth)) + 1;
00746 Int_t high_b = Min(fNBins-2, CeilNint ((max-fMin)/fBinWidth));
00747
00748 for (Int_t i = 1; i < fNBins - 1; ++i)
00749 {
00750 if (fBins[i] != 0)
00751 fBins[i]->SetRnrSelf(i>=low_b && i<=high_b);
00752 }
00753 }
00754
00755
00756
00757
00758
00759
00760
00761
00762
00763
00764
00765 ClassImp(TEvePointSetProjected);
00766
00767
00768 TEvePointSetProjected::TEvePointSetProjected() :
00769 TEvePointSet (),
00770 TEveProjected ()
00771 {
00772
00773 }
00774
00775
00776 void TEvePointSetProjected::SetProjection(TEveProjectionManager* proj,
00777 TEveProjectable* model)
00778 {
00779
00780
00781
00782 TEveProjected::SetProjection(proj, model);
00783 CopyVizParams(dynamic_cast<TEveElement*>(model));
00784 }
00785
00786
00787 void TEvePointSetProjected::SetDepthLocal(Float_t d)
00788 {
00789
00790
00791 SetDepthCommon(d, this, fBBox);
00792
00793 Int_t n = Size();
00794 Float_t *p = GetP() + 2;
00795 for (Int_t i = 0; i < n; ++i, p+=3)
00796 *p = fDepth;
00797 }
00798
00799
00800 void TEvePointSetProjected::UpdateProjection()
00801 {
00802
00803
00804
00805 TEveProjection &proj = * fManager->GetProjection();
00806 TEvePointSet &ps = * dynamic_cast<TEvePointSet*>(fProjectable);
00807 TEveTrans *tr = ps.PtrMainTrans(kFALSE);
00808
00809 Int_t n = ps.Size();
00810 Reset(n);
00811 fLastPoint = n - 1;
00812 Float_t *o = ps.GetP(), *p = GetP();
00813 for (Int_t i = 0; i < n; ++i, o+=3, p+=3)
00814 {
00815 proj.ProjectPointfv(tr, o, p, fDepth);
00816 }
00817 }
00818
00819
00820 void TEvePointSetProjected::PointSelected(Int_t id)
00821 {
00822
00823
00824
00825 TEvePointSet *ps = dynamic_cast<TEvePointSet*>(fProjectable);
00826 ps->PointSelected(id);
00827 }