source: trunk/MagicSoft/Cosy/base/MStarList.h@ 5138

Last change on this file since 5138 was 1810, checked in by tbretz, 22 years ago
*** empty log message ***
File size: 2.1 KB
Line 
1#ifndef COSY_MStarList
2#define COSY_MStarList
3
4#include <TClonesArray.h>
5
6#include "MStar.h"
7
8class MStarListIter;
9
10class MStarList : public TObject
11{
12private:
13 TClonesArray fStars;
14
15public:
16 MStarList() : fStars("MStar", 1000) {}
17
18 void AddAt(Int_t idx, Double_t meanx, Double_t meany, Double_t mag)
19 {
20 new (fStars[idx]) MStar(meanx, meany, mag);
21 }
22 void Add(Double_t meanx, Double_t meany, Double_t mag=0)
23 {
24 AddAt(fStars.GetLast()+1, meanx, meany, mag);
25 }
26 MStar *operator[](Int_t i) { return (MStar*)fStars[i]; }
27
28 void Reset()
29 {
30 fStars.Delete();
31 }
32
33 void Delete(Int_t i) { delete fStars.RemoveAt(i); }
34 void Delete(MStar *obj) { delete fStars.Remove(obj); }
35
36 Int_t GetMax() const { return fStars.GetLast()+1; }
37 Int_t GetRealEntries() const { return fStars.GetEntries(); }
38
39 void RemoveTwins(Double_t radius);
40
41 void Sort() { fStars.Sort(); }
42
43 void Expand(int n) { fStars.Expand(n); }
44};
45
46class MStarListIter
47{
48private:
49 MStarList *fList;
50
51 Int_t fNumPos; // actual position in list
52
53 Bool_t fAll; // iterate over all stars
54
55 MStar fReference; // iterate only over stars not more than
56 Float_t fRadius; // fRadius away from the reference
57
58public:
59 MStarListIter(MStarList *list) : fList(list), fNumPos(0), fAll(kTRUE) {}
60 MStarListIter(MStarList *list, const MStar &s, Float_t r) : fList(list), fNumPos(0), fAll(kFALSE), fReference(s), fRadius(r) {}
61
62 MStar *Next()
63 {
64 const Double_t r2 = fRadius*fRadius;
65
66 for (int i=fNumPos; i<fList->GetMax(); i++)
67 {
68 MStar *p = (*fList)[i];
69
70 if (!p)
71 continue;
72
73 if (!fAll)
74 {
75 Double_t dx = p->GetX()-fReference.GetX();
76 Double_t dy = p->GetY()-fReference.GetY();
77
78 if (dx*dx + dy*dy > r2)
79 continue;
80 }
81
82 fNumPos = i+1;
83 return p;
84 }
85 return NULL;
86 }
87
88 MStar *operator()() { return Next(); }
89
90 void Reset() { fNumPos=0; }
91};
92
93#endif
Note: See TracBrowser for help on using the repository browser.