/home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/io/include/RAT/TrackCursor.hh Source File

Ratpac-two: /home/docs/checkouts/readthedocs.org/user_builds/ratpac/checkouts/latest/src/io/include/RAT/TrackCursor.hh Source File
Ratpac-two
TrackCursor.hh
1 #ifndef __RAT_TrackCursor__
2 #define __RAT_TrackCursor__
3 
4 #include <RAT/TrackNode.hh>
5 #include <functional>
6 #include <string>
7 
8 namespace RAT {
9 
10 class TrackTest {
11  public:
12  virtual bool operator()(TrackNode *) = 0;
13 }; // Common predicates at the end
14 
15 class TrackCursor {
16  public:
17  TrackCursor(TrackNode *node, bool verbose = false) {
18  fVerbose = verbose;
19  Go(node);
20  };
21 
22  bool GetVerbose() { return fVerbose; };
23  void SetVerbose(bool verbose = true) { fVerbose = verbose; };
24 
25  // Node peeking (does not change current position)
26  TrackNode *TrackStart() const;
27  TrackNode *Prev() const { return fCur->GetPrev(); };
28  TrackNode *Here() const { return fCur; };
29  TrackNode *Next() const { return fCur->GetNext(); };
30  TrackNode *TrackEnd() const;
31 
32  int StepCount() const { return TrackEnd()->GetStepID() + 1; };
33  TrackNode *Step(int i) const;
34  int ChildCount() const { return fCur->child.size(); };
35  TrackNode *Child(int i = 0) const;
36  int TrackChildCount() const;
37  TrackNode *TrackChild(int i) const;
38  TrackNode *Parent() const;
39 
40  // Information
41  double TrackLength() const;
42  bool IsTrackStart() const { return fCur->IsTrackStart(); };
43  bool IsTrackEnd() const { return fCur->IsTrackEnd(); };
44 
45  // Navigation (returns node at new location as well as updating current pos)
46  void Go(TrackNode *node);
47  TrackNode *GoTrackStart();
48  TrackNode *GoPrev();
49  TrackNode *GoNext();
50  TrackNode *GoTrackEnd();
51 
52  TrackNode *GoStep(int i);
53  TrackNode *GoChild(int i = 0);
54  TrackNode *GoTrackChild(int i);
55  TrackNode *GoParent(); // Go to the step in the parent particle where
56  // this track was made
57 
58  // Output
59  void Print() const;
60  void PrintTrack() const;
61 
62  static std::string PrintTrackIDs(TrackNode *node);
63  static std::string Print(TrackNode *node);
64  static std::string PrintTrack(TrackNode *node);
65 
66  // Generic Search
67  TrackNode *FindNextTrack();
68  TrackNode *FindNextTrackNoDescend();
69 
70  TrackNode *FindNextTrack(TrackTest *predicate);
71 
72  // Specialized Search
73  TrackNode *FindNextParticle(const std::string &particleName);
74  // TrackNode *FindNextProcess(std::string process);
75 
76  protected:
77  TrackNode *fCur;
78  bool fVerbose;
79 };
80 
81 // Useful predicates
82 
83 class TrackTest_Particle : public TrackTest {
84  std::string fParticleName;
85 
86  public:
87  TrackTest_Particle(const std::string &particleName) : fParticleName(particleName){};
88  virtual bool operator()(TrackNode *c) { return fParticleName == c->GetParticleName(); };
89 };
90 
91 } // namespace RAT
92 
93 #endif
Definition: TrackCursor.hh:15
Definition: TrackNode.hh:8
virtual int GetStepID() const
Definition: TrackNode.hh:36
virtual const std::string & GetParticleName() const
Definition: TrackNode.hh:47
virtual bool IsTrackStart() const
Definition: TrackNode.hh:21
virtual bool IsTrackEnd() const
Definition: TrackNode.hh:25
Definition: TrackCursor.hh:83
Definition: TrackCursor.hh:10
Definition: CCCrossSecMessenger.hh:29