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

Last change on this file since 8846 was 8376, checked in by tbretz, 18 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(Option_t *o="") { }
34 void Delete(Int_t i) { delete fStars.RemoveAt(i); }
35 void Delete(MStar *obj) { delete fStars.Remove(obj); }
36
37 Int_t GetMax() const { return fStars.GetLast()+1; }
38 Int_t GetRealEntries() const { return fStars.GetEntries(); }
39
40 void RemoveTwins(Double_t radius);
41
42 void Sort() { fStars.Sort(); }
43
44 void Expand(int n) { fStars.Expand(n); }
45};
46
47class MStarListIter
48{
49private:
50 MStarList *fList;
51
52 Int_t fNumPos; // actual position in list
53
54 Bool_t fAll; // iterate over all stars
55
56 MStar fReference; // iterate only over stars not more than
57 Float_t fRadius; // fRadius away from the reference
58
59public:
60 MStarListIter(MStarList *list) : fList(list), fNumPos(0), fAll(kTRUE) {}
61 MStarListIter(MStarList *list, const MStar &s, Float_t r) : fList(list), fNumPos(0), fAll(kFALSE), fReference(s), fRadius(r) {}
62
63 MStar *Next()
64 {
65 const Double_t r2 = fRadius*fRadius;
66
67 for (int i=fNumPos; i<fList->GetMax(); i++)
68 {
69 MStar *p = (*fList)[i];
70
71 if (!p)
72 continue;
73
74 if (!fAll)
75 {
76 Double_t dx = p->GetX()-fReference.GetX();
77 Double_t dy = p->GetY()-fReference.GetY();
78
79 if (dx*dx + dy*dy > r2)
80 continue;
81 }
82
83 fNumPos = i+1;
84 return p;
85 }
86 return NULL;
87 }
88
89 MStar *operator()() { return Next(); }
90
91 void Reset() { fNumPos=0; }
92};
93
94#endif
Note: See TracBrowser for help on using the repository browser.