// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007

/*************************************************************************
 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOT_TEveTrack
#define ROOT_TEveTrack

#include <vector>

#include "TEveVector.h"
#include "TEvePathMark.h"
#include "TEveVSDStructs.h"
#include "TEveElement.h"
#include "TEveLine.h"

#include "TPolyMarker3D.h"
#include "TMarker.h"

class TEveTrackPropagator;
class TEveTrackList;

class TEveMCTrack;
class TParticle;

class TEveTrack : public TEveLine
{
   friend class TEveTrackPropagator;
   friend class TEveTrackList;
   friend class TEveTrackGL;

private:
   TEveTrack& operator=(const TEveTrack&); // Not implemented

public:
   typedef std::vector<TEvePathMarkD>   vPathMark_t;
   typedef vPathMark_t::iterator        vPathMark_i;
   typedef vPathMark_t::const_iterator  vPathMark_ci;

   // Deprecated -- to be removed.
   enum EBreakProjectedTracks_e { kBPTDefault, kBPTAlways, kBPTNever };

protected:
   TEveVectorD        fV;          // Starting vertex
   TEveVectorD        fP;          // Starting momentum
   TEveVectorD        fPEnd;       // Momentum at the last point of extrapolation
   Double_t           fBeta;       // Relativistic beta factor
   Double_t           fDpDs;       // Momentum loss over distance
   Int_t              fPdg;        // PDG code
   Int_t              fCharge;     // Charge in units of e0
   Int_t              fLabel;      // Simulation label
   Int_t              fIndex;      // Reconstruction index
   Int_t              fStatus;     // Status-word, user-defined.
   Bool_t             fLockPoints; // Lock points that are currently in - do nothing in MakeTrack().
   vPathMark_t        fPathMarks;  // TEveVector of known points along the track
   Int_t              fLastPMIdx;  //!Last path-mark index tried in track-propagation.

   TEveTrackPropagator *fPropagator;   // Pointer to shared render-style

public:
   TEveTrack();
   TEveTrack(TParticle* t, Int_t label, TEveTrackPropagator* prop=0);
   TEveTrack(TEveMCTrack*  t, TEveTrackPropagator* prop=0);
   TEveTrack(TEveRecTrack* t, TEveTrackPropagator* prop=0);
   TEveTrack(TEveRecTrackD* t, TEveTrackPropagator* prop=0);
   TEveTrack(const TEveTrack& t);
   virtual ~TEveTrack();

   virtual void ComputeBBox();

   virtual void SetStdTitle();

   virtual void SetTrackParams(const TEveTrack& t);
   virtual void SetPathMarks  (const TEveTrack& t);

   virtual void MakeTrack(Bool_t recurse=kTRUE);

   TEveTrackPropagator* GetPropagator() const  { return fPropagator; }
   Int_t GetLastPMIdx() const { return fLastPMIdx; }
   void  SetPropagator(TEveTrackPropagator* prop);
   void  SetAttLineAttMarker(TEveTrackList* tl);

   const TEveVectorD& GetVertex()      const { return fV;    }
   const TEveVectorD& GetMomentum()    const { return fP;    }
   const TEveVectorD& GetEndMomentum() const { return fPEnd; }

   Double_t GetDpDs()        const { return fDpDs; }
   void     SetDpDs(Double_t dpds) { fDpDs = dpds; }

   Int_t GetPdg()    const    { return fPdg;    }
   void  SetPdg(Int_t pdg)    { fPdg = pdg;     }
   Int_t GetCharge() const    { return fCharge; }
   void  SetCharge(Int_t chg) { fCharge = chg;  }
   Int_t GetLabel()  const    { return fLabel;  }
   void  SetLabel(Int_t lbl)  { fLabel = lbl;   }
   Int_t GetIndex()  const    { return fIndex;  }
   void  SetIndex(Int_t idx)  { fIndex = idx;   }
   Int_t GetStatus()  const   { return fStatus; }
   void  SetStatus(Int_t idx) { fStatus = idx;  }

   void  AddPathMark(const TEvePathMarkD& pm) { fPathMarks.push_back(pm); }
   void  AddPathMark(const TEvePathMark& pm)  { fPathMarks.push_back(pm); }

   void  SortPathMarksByTime();
         vPathMark_t& RefPathMarks()       { return fPathMarks; }
   const vPathMark_t& RefPathMarks() const { return fPathMarks; }

   void  PrintPathMarks(); // *MENU*

   void   SetLockPoints(Bool_t l) { fLockPoints = l;    }
   Bool_t GetLockPoints()   const { return fLockPoints; }

   //-------------------------------------------------------------------

   virtual void SecSelected(TEveTrack*); // *SIGNAL*

   virtual const TGPicture* GetListTreeIcon(Bool_t open=kFALSE);

   virtual void CopyVizParams(const TEveElement* el);
   virtual void WriteVizParams(std::ostream& out, const TString& var);

   virtual TClass* ProjectedClass(const TEveProjection* p) const;

   ClassDef(TEveTrack, 0); // Track with given vertex, momentum and optional referece-points (path-marks) along its path.
};

/******************************************************************************/
// TEveTrackList
/******************************************************************************/

class TEveTrackList : public TEveElementList,
                      public TAttMarker,
                      public TAttLine
{
   friend class TEveTrackListEditor;

private:
   TEveTrackList(const TEveTrackList&);            // Not implemented
   TEveTrackList& operator=(const TEveTrackList&); // Not implemented

protected:
   TEveTrackPropagator* fPropagator;   // Basic track rendering parameters, not enforced to elements.

   Bool_t               fRecurse;    // Recurse when propagating marker/line/etc attributes to tracks.

   Bool_t               fRnrLine;    // Render track as line.
   Bool_t               fRnrPoints;  // Render track as points.

   Double_t             fMinPt;      // Minimum track pTfor display selection.
   Double_t             fMaxPt;      // Maximum track pTfor display selection.
   Double_t             fLimPt;      // Highest track pT in the container.
   Double_t             fMinP;       // Minimum track pfor display selection.
   Double_t             fMaxP;       // Maximum track pfor display selection.
   Double_t             fLimP;       // Highest track p in the container.

   void     FindMomentumLimits(TEveElement* el, Bool_t recurse=kTRUE);
   Double_t RoundMomentumLimit(Double_t x);
   void     SanitizeMinMaxCuts();

public:
   TEveTrackList(TEveTrackPropagator* prop=0);
   TEveTrackList(const char* name, TEveTrackPropagator* prop=0);
   virtual ~TEveTrackList();

   void  MakeTracks(Bool_t recurse=kTRUE);
   void  FindMomentumLimits(Bool_t recurse=kTRUE);

   void  SetPropagator(TEveTrackPropagator* prop);
   TEveTrackPropagator* GetPropagator() { return fPropagator; }

   Bool_t GetRecurse() const   { return fRecurse; }
   void   SetRecurse(Bool_t x) { fRecurse = x; }

   //--------------------------------

   virtual void   SetMainColor(Color_t c);
   virtual void   SetLineColor(Color_t c) { SetMainColor(c); }
   virtual void   SetLineColor(Color_t c, TEveElement* el);
   virtual void   SetLineWidth(Width_t w);
   virtual void   SetLineWidth(Width_t w, TEveElement* el);
   virtual void   SetLineStyle(Style_t s);
   virtual void   SetLineStyle(Style_t s, TEveElement* el);

   virtual void   SetMarkerColor(Color_t c);
   virtual void   SetMarkerColor(Color_t c, TEveElement* el);
   virtual void   SetMarkerSize(Size_t s);
   virtual void   SetMarkerSize(Size_t s, TEveElement* el);
   virtual void   SetMarkerStyle(Style_t s);
   virtual void   SetMarkerStyle(Style_t s, TEveElement* el);

   void   SetRnrLine(Bool_t rnr);
   void   SetRnrLine(Bool_t rnr, TEveElement* el);
   Bool_t GetRnrLine() const { return fRnrLine; }

   void   SetRnrPoints(Bool_t r);
   void   SetRnrPoints(Bool_t r, TEveElement* el);
   Bool_t GetRnrPoints() const { return fRnrPoints; }

   void SelectByPt(Double_t min_pt, Double_t max_pt);
   void SelectByPt(Double_t min_pt, Double_t max_pt, TEveElement* el);
   void SelectByP (Double_t min_p,  Double_t max_p);
   void SelectByP (Double_t min_p,  Double_t max_p,  TEveElement* el);

   Double_t GetMinPt() const { return fMinPt; }
   Double_t GetMaxPt() const { return fMaxPt; }
   Double_t GetLimPt() const { return fLimPt; }
   Double_t GetMinP()  const { return fMinP;  }
   Double_t GetMaxP()  const { return fMaxP;  }
   Double_t GetLimP()  const { return fLimP;  }

   //-------------------------------------------------------------------

   TEveTrack* FindTrackByLabel(Int_t label); // *MENU*
   TEveTrack* FindTrackByIndex(Int_t index); // *MENU*

   virtual void CopyVizParams(const TEveElement* el);
   virtual void WriteVizParams(std::ostream& out, const TString& var);

   virtual TClass* ProjectedClass(const TEveProjection* p) const;

   ClassDef(TEveTrackList, 1); // A list of tracks supporting change of common attributes and selection based on track parameters.
};

#endif
 TEveTrack.h:1
 TEveTrack.h:2
 TEveTrack.h:3
 TEveTrack.h:4
 TEveTrack.h:5
 TEveTrack.h:6
 TEveTrack.h:7
 TEveTrack.h:8
 TEveTrack.h:9
 TEveTrack.h:10
 TEveTrack.h:11
 TEveTrack.h:12
 TEveTrack.h:13
 TEveTrack.h:14
 TEveTrack.h:15
 TEveTrack.h:16
 TEveTrack.h:17
 TEveTrack.h:18
 TEveTrack.h:19
 TEveTrack.h:20
 TEveTrack.h:21
 TEveTrack.h:22
 TEveTrack.h:23
 TEveTrack.h:24
 TEveTrack.h:25
 TEveTrack.h:26
 TEveTrack.h:27
 TEveTrack.h:28
 TEveTrack.h:29
 TEveTrack.h:30
 TEveTrack.h:31
 TEveTrack.h:32
 TEveTrack.h:33
 TEveTrack.h:34
 TEveTrack.h:35
 TEveTrack.h:36
 TEveTrack.h:37
 TEveTrack.h:38
 TEveTrack.h:39
 TEveTrack.h:40
 TEveTrack.h:41
 TEveTrack.h:42
 TEveTrack.h:43
 TEveTrack.h:44
 TEveTrack.h:45
 TEveTrack.h:46
 TEveTrack.h:47
 TEveTrack.h:48
 TEveTrack.h:49
 TEveTrack.h:50
 TEveTrack.h:51
 TEveTrack.h:52
 TEveTrack.h:53
 TEveTrack.h:54
 TEveTrack.h:55
 TEveTrack.h:56
 TEveTrack.h:57
 TEveTrack.h:58
 TEveTrack.h:59
 TEveTrack.h:60
 TEveTrack.h:61
 TEveTrack.h:62
 TEveTrack.h:63
 TEveTrack.h:64
 TEveTrack.h:65
 TEveTrack.h:66
 TEveTrack.h:67
 TEveTrack.h:68
 TEveTrack.h:69
 TEveTrack.h:70
 TEveTrack.h:71
 TEveTrack.h:72
 TEveTrack.h:73
 TEveTrack.h:74
 TEveTrack.h:75
 TEveTrack.h:76
 TEveTrack.h:77
 TEveTrack.h:78
 TEveTrack.h:79
 TEveTrack.h:80
 TEveTrack.h:81
 TEveTrack.h:82
 TEveTrack.h:83
 TEveTrack.h:84
 TEveTrack.h:85
 TEveTrack.h:86
 TEveTrack.h:87
 TEveTrack.h:88
 TEveTrack.h:89
 TEveTrack.h:90
 TEveTrack.h:91
 TEveTrack.h:92
 TEveTrack.h:93
 TEveTrack.h:94
 TEveTrack.h:95
 TEveTrack.h:96
 TEveTrack.h:97
 TEveTrack.h:98
 TEveTrack.h:99
 TEveTrack.h:100
 TEveTrack.h:101
 TEveTrack.h:102
 TEveTrack.h:103
 TEveTrack.h:104
 TEveTrack.h:105
 TEveTrack.h:106
 TEveTrack.h:107
 TEveTrack.h:108
 TEveTrack.h:109
 TEveTrack.h:110
 TEveTrack.h:111
 TEveTrack.h:112
 TEveTrack.h:113
 TEveTrack.h:114
 TEveTrack.h:115
 TEveTrack.h:116
 TEveTrack.h:117
 TEveTrack.h:118
 TEveTrack.h:119
 TEveTrack.h:120
 TEveTrack.h:121
 TEveTrack.h:122
 TEveTrack.h:123
 TEveTrack.h:124
 TEveTrack.h:125
 TEveTrack.h:126
 TEveTrack.h:127
 TEveTrack.h:128
 TEveTrack.h:129
 TEveTrack.h:130
 TEveTrack.h:131
 TEveTrack.h:132
 TEveTrack.h:133
 TEveTrack.h:134
 TEveTrack.h:135
 TEveTrack.h:136
 TEveTrack.h:137
 TEveTrack.h:138
 TEveTrack.h:139
 TEveTrack.h:140
 TEveTrack.h:141
 TEveTrack.h:142
 TEveTrack.h:143
 TEveTrack.h:144
 TEveTrack.h:145
 TEveTrack.h:146
 TEveTrack.h:147
 TEveTrack.h:148
 TEveTrack.h:149
 TEveTrack.h:150
 TEveTrack.h:151
 TEveTrack.h:152
 TEveTrack.h:153
 TEveTrack.h:154
 TEveTrack.h:155
 TEveTrack.h:156
 TEveTrack.h:157
 TEveTrack.h:158
 TEveTrack.h:159
 TEveTrack.h:160
 TEveTrack.h:161
 TEveTrack.h:162
 TEveTrack.h:163
 TEveTrack.h:164
 TEveTrack.h:165
 TEveTrack.h:166
 TEveTrack.h:167
 TEveTrack.h:168
 TEveTrack.h:169
 TEveTrack.h:170
 TEveTrack.h:171
 TEveTrack.h:172
 TEveTrack.h:173
 TEveTrack.h:174
 TEveTrack.h:175
 TEveTrack.h:176
 TEveTrack.h:177
 TEveTrack.h:178
 TEveTrack.h:179
 TEveTrack.h:180
 TEveTrack.h:181
 TEveTrack.h:182
 TEveTrack.h:183
 TEveTrack.h:184
 TEveTrack.h:185
 TEveTrack.h:186
 TEveTrack.h:187
 TEveTrack.h:188
 TEveTrack.h:189
 TEveTrack.h:190
 TEveTrack.h:191
 TEveTrack.h:192
 TEveTrack.h:193
 TEveTrack.h:194
 TEveTrack.h:195
 TEveTrack.h:196
 TEveTrack.h:197
 TEveTrack.h:198
 TEveTrack.h:199
 TEveTrack.h:200
 TEveTrack.h:201
 TEveTrack.h:202
 TEveTrack.h:203
 TEveTrack.h:204
 TEveTrack.h:205
 TEveTrack.h:206
 TEveTrack.h:207
 TEveTrack.h:208
 TEveTrack.h:209
 TEveTrack.h:210
 TEveTrack.h:211
 TEveTrack.h:212
 TEveTrack.h:213
 TEveTrack.h:214
 TEveTrack.h:215
 TEveTrack.h:216
 TEveTrack.h:217
 TEveTrack.h:218
 TEveTrack.h:219
 TEveTrack.h:220
 TEveTrack.h:221
 TEveTrack.h:222
 TEveTrack.h:223
 TEveTrack.h:224
 TEveTrack.h:225
 TEveTrack.h:226
 TEveTrack.h:227
 TEveTrack.h:228
 TEveTrack.h:229
 TEveTrack.h:230