Added method SortPathMarksByTime().
[u/mrichter/AliRoot.git] / EVE / Reve / Track.cxx
index 36b6ee05a132ca26050cf0da18b0fc5ac11c2676..2cf96d9baee28ba1657ad958bc9d55e96de32638 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "Track.h"
 #include "MCHelixLine.hi"
+#include "PointSet.h"
 
 #include <TPolyLine3D.h>
 #include <TPolyMarker3D.h>
@@ -28,7 +29,8 @@ Track::Track() :
   fP(),
   fBeta(0),
   fCharge(0),
-  fLabel(0),
+  fLabel(-1),
+  fIndex(-1),
   fPathMarks(),
 
   fRnrStyle(0)
@@ -42,6 +44,7 @@ Track::Track(TParticle* t, Int_t label, TrackRnrStyle* rs):
   fBeta(t->P()/t->Energy()),
   fCharge(0),
   fLabel(label),
+  fIndex(-1),
   fPathMarks(),
 
   fRnrStyle(rs)
@@ -117,11 +120,10 @@ void Track::Reset(Int_t n_points)
 }
 */
 
-/**************************************************************************/
+ /**************************************************************************/
 
-void Track::MakeTrack()
+void Track::MakeTrack( Bool_t recurse)
 {
-  
   TrackRnrStyle& RS((fRnrStyle != 0) ? *fRnrStyle : TrackRnrStyle::fgDefStyle);
 
   Float_t px = fP.x, py = fP.y, pz = fP.z;  
@@ -147,34 +149,49 @@ void Track::MakeTrack()
     MCHelix helix(fRnrStyle, &mc_v0, TMath::C()*fBeta, &track_points, a); //m->cm
     helix.Init(TMath::Sqrt(px*px+py*py), pz);
    
-    if(!fPathMarks.empty()){
-      for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i) {
+    if(!fPathMarks.empty())
+    {
+      for(std::vector<Reve::PathMark*>::iterator i=fPathMarks.begin(); i!=fPathMarks.end(); ++i)
+      {
        Reve::PathMark* pm = *i;
         
-       if(RS.fFitDaughters &&  pm->type == Reve::PathMark::Daughter){
+       if (RS.fFitReferences && pm->type == Reve::PathMark::Reference)
+       {
          if(TMath::Abs(pm->V.z) > RS.fMaxZ 
             || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
            goto helix_bounds;
 
-          //printf("%s fit daughter  \n", fName.Data()); 
-         helix.LoopToVertex(fP.x, fP.y, fP.z, pm->V.x, pm->V.y, pm->V.z);
-         fP.x -=  pm->P.x;
-         fP.y -=  pm->P.y;
-         fP.z -=  pm->P.z;
+         // printf("%s fit reference  \n", fName.Data()); 
+         helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
+         px =  pm->P.x;
+         py =  pm->P.y;
+         pz =  pm->P.z;
        }
-       if(RS.fFitDecay &&  pm->type == Reve::PathMark::Decay){
-         
+       else if(RS.fFitDaughters &&  pm->type == Reve::PathMark::Daughter)
+       {
+         if(TMath::Abs(pm->V.z) > RS.fMaxZ 
+            || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
+           goto helix_bounds;
+
+          // printf("%s fit daughter  \n", fName.Data()); 
+         helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
+         px -=  pm->P.x;
+         py -=  pm->P.y;
+         pz -=  pm->P.z;
+       }
+       else if(RS.fFitDecay &&  pm->type == Reve::PathMark::Decay)
+       {
          if(TMath::Abs(pm->V.z) > RS.fMaxZ 
             || TMath::Sqrt(pm->V.x*pm->V.x + pm->V.y*pm->V.y) > RS.fMaxR )
            goto helix_bounds;
-         helix.LoopToVertex(fP.x, fP.y, fP.z, pm->V.x, pm->V.y, pm->V.z);
+         helix.LoopToVertex(px, py, pz, pm->V.x, pm->V.y, pm->V.z);
           decay = true;
           break;
        }
       }
     }
   helix_bounds:
-    //go to bounds
+    // go to bounds
     if(!decay || RS.fFitDecay == kFALSE){
       helix.LoopToBounds(px,py,pz);
       // printf("%s loop to bounds  \n",fName.Data() );
@@ -220,34 +237,117 @@ make_polyline:
   Reset(track_points.size());
   for(std::vector<MCVertex>::iterator i=track_points.begin(); i!=track_points.end(); ++i)
     SetNextPoint(i->x, i->y, i->z);
+
+  if(recurse) {
+    Track* t;
+    for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
+      t = dynamic_cast<Track*>(*i);
+      if(t)t->MakeTrack(recurse); 
+    }
+  }
 }
 
+/**************************************************************************/
+namespace {
+struct cmp_pathmark {
+  bool operator()(PathMark* const & a, PathMark* const & b)
+  { return a->time < b->time; }
+};
+}
+
+void Track::SortPathMarksByTime()
+{
+ sort(fPathMarks.begin(), fPathMarks.end(), cmp_pathmark());
+}
+
+
 /**************************************************************************/
 
 void Track::ImportHits()
 {
   Reve::LoadMacro("hits_from_label.C");
-  gROOT->ProcessLine(Form("hits_from_label(%d);", fLabel));
+  gROOT->ProcessLine(Form("hits_from_label(%d, (Reve::RenderElement*)%p);", 
+                         fLabel, this));
 }
 
 void Track::ImportClusters()
 {
   Reve::LoadMacro("clusters_from_label.C");
-  gROOT->ProcessLine(Form("clusters_from_label(%d);", fLabel));
+  gROOT->ProcessLine(Form("clusters_from_label(%d, (Reve::RenderElement*)%p);", 
+                         fLabel, this));
 }
 
 void Track::ImportClustersFromIndex()
 {
+  static const Exc_t eH("Track::ImportClustersFromIndex ");
+
+  if (fIndex < 0)
+    throw(eH + "index not set.");
+
   Reve::LoadMacro("clusters_from_index.C");
-  gROOT->ProcessLine(Form("clusters_from_index(%d);", fIndex));
+  gROOT->ProcessLine(Form("clusters_from_index(%d, (Reve::RenderElement*)%p);", 
+                         fIndex, this));
+}
+
+/**************************************************************************/
+
+void Track::ImportKine()
+{
+  static const Exc_t eH("Track::ImportKine ");
+
+  if (fLabel < 0)
+    throw(eH + "label not set.");
+
+  Reve::LoadMacro("kine_tracks.C");
+  gROOT->ProcessLine(Form("kine_track(%d, kFALSE, kTRUE, (Reve::RenderElement*)%p);", 
+                         fLabel, this));
+
+}
+
+void Track::ImportKineWithArgs(Bool_t importMother, Bool_t importDaugters)
+{
+  static const Exc_t eH("Track::ImportKineWithArgs ");
+
+  if (fLabel < 0)
+    throw(eH + "label not set.");
+
+  Reve::LoadMacro("kine_tracks.C");
+  gROOT->ProcessLine(Form("kine_track(%d, %d, %d, (Reve::RenderElement*)%p);", 
+                          fLabel, importMother, importDaugters, this));
+
 }
 
+/**************************************************************************/
+
 void Track::PrintKineStack()
 {
   Reve::LoadMacro("print_kine_from_label.C");
   gROOT->ProcessLine(Form("print_kine_from_label(%d);", fLabel));
 }
 
+
+void Track::PrintPathMarks()
+{
+  static const Exc_t eH("Track::PrintPathMarks ");
+
+  if (fLabel < 0)
+    throw(eH + "label not set.");
+
+  printf("Number of path marks %d label %d\n",
+        fPathMarks.size(), fLabel);
+
+  PathMark* pm;
+  for(vpPathMark_i i=fPathMarks.begin(); i!=fPathMarks.end(); i++) 
+  {
+    pm = *i;
+    printf("Reve::PathMark: %-9s  p: %8f %8f %8f Vertex: %8e %8e %8e %g \n",
+          pm->type_name(),
+          pm->P.x,  pm->P.y, pm->P.z,
+          pm->V.x,  pm->V.y, pm->V.z,
+          pm->time);
+  }
+}
+
 /**************************************************************************/
 
 void Track::CtrlClicked(Reve::Track* track)
@@ -283,10 +383,17 @@ TrackRnrStyle::TrackRnrStyle() :
   fMinAng  (45),
   fDelta   (0.1),
 
-  fFitDaughters(kTRUE),
-  fFitDecay    (kTRUE)
-{}
+  fMinPt   (0.1),
+  fMaxPt   (10),
 
+  fFitDaughters  (kTRUE),
+  fFitReferences (kTRUE),
+  fFitDecay      (kTRUE),
+
+  fRnrDaughters  (kTRUE),
+  fRnrReferences (kTRUE),
+  fRnrDecay      (kTRUE)
+{}
 /**************************************************************************/
 /**************************************************************************/
 
@@ -298,36 +405,36 @@ ClassImp(Reve::TrackList)
 
 void TrackList::Init()
 {
-  fMarkerStyle = 6;
-  fMarkerColor = 5;
-  // fMarker->SetMarkerSize(0.05);
+  fMarkerStyle = 2;
+  fMarkerColor = 4;
+  fMarkerSize  = 0.6;
 
   if (fRnrStyle== 0) fRnrStyle = new TrackRnrStyle;
   SetMainColorPtr(&fRnrStyle->fColor);
 }
 
 TrackList::TrackList(Int_t n_tracks, TrackRnrStyle* rs) :
-  RenderElementListBase(),
+  RenderElement(),
   TPolyMarker3D(n_tracks),
 
   fTitle(),
 
-  fRnrStyle   (rs),
-  fRnrMarkers (kTRUE),
-  fRnrTracks  (kTRUE)
+  fRnrStyle      (rs),
+  fRnrTracks     (kTRUE),
+  fEditPathMarks (kFALSE)
 {
   Init();
 }
 
 TrackList::TrackList(const Text_t* name, Int_t n_tracks, TrackRnrStyle* rs) :
-  RenderElementListBase(),
+  RenderElement(),
   TPolyMarker3D(n_tracks),
   
   fTitle(),
 
-  fRnrStyle   (rs),
-  fRnrMarkers (kTRUE),
-  fRnrTracks  (kTRUE)
+  fRnrStyle      (rs),
+  fRnrTracks     (kTRUE),
+  fEditPathMarks (kFALSE)
 {
   Init();
   SetName(name);
@@ -346,13 +453,13 @@ void TrackList::Reset(Int_t n_tracks)
 
 void TrackList::Paint(Option_t* option)
 {
-  if(fRnrElement) {
+  if(fRnrSelf) {
     if(fRnrMarkers) {
       TPolyMarker3D::Paint(option);
     }
-    if(fRnrTracks) {
+    if(fRnrTracks && fRnrChildren) {
       for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
-       if((*i)->GetRnrElement())
+       if((*i)->GetRnrSelf())
          (*i)->GetObject()->Paint(option);
       }
     }
@@ -366,22 +473,7 @@ void TrackList::AddElement(RenderElement* el)
   static const Exc_t eH("TrackList::AddElement ");
   if (dynamic_cast<Track*>(el)  == 0)
     throw(eH + "new element not a Track.");
-  RenderElementListBase::AddElement(el);
-}
-
-/**************************************************************************/
-
-void TrackList::SetRnrMarkers(Bool_t rnr)
-{
-  fRnrMarkers = rnr;
-  gReve->Redraw3D();
-}
-
-void TrackList::SetRnrTracks(Bool_t rnr)
-{
-
-  fRnrTracks = rnr;
-  gReve->Redraw3D();
+  RenderElement::AddElement(el);
 }
 
 /**************************************************************************/
@@ -458,24 +550,64 @@ void TrackList::SetFitDaughters(Bool_t x)
   MakeTracks();
 }
 
+void TrackList::SetFitReferences(Bool_t x)
+{
+  fRnrStyle->fFitReferences = x;
+  MakeTracks();
+}
+
 void TrackList::SetFitDecay(Bool_t x)
 {
   fRnrStyle->fFitDecay = x;
   MakeTracks();
 }
 
+void TrackList::SetRnrDecay(Bool_t rnr)
+{
+  fRnrStyle->fRnrDecay = rnr;
+  MakeTracks();
+}
+
+void TrackList::SetRnrDaughters(Bool_t rnr)
+{
+  fRnrStyle->fRnrDaughters = rnr;
+  MakeTracks();
+}
+
+void TrackList::SetRnrReferences(Bool_t rnr)
+{
+  fRnrStyle->fRnrReferences = rnr;
+  MakeTracks();
+}
+void TrackList::SetRnrMarkers(Bool_t rnr)
+{
+  fRnrMarkers = rnr;
+  gReve->Redraw3D();
+}
+
+void TrackList::SetRnrTracks(Bool_t rnr)
+{
+
+  fRnrTracks = rnr;
+  gReve->Redraw3D();
+}
+
 /**************************************************************************/
 /**************************************************************************/
 
 void TrackList::SelectByPt(Float_t min_pt, Float_t max_pt)
 {
+  fRnrStyle->fMinPt = min_pt;
+  fRnrStyle->fMaxPt = max_pt;
+
   Float_t minptsq = min_pt*min_pt;
   Float_t maxptsq = max_pt*max_pt;
   Float_t ptsq;
 
   for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
     ptsq = ((Track*)(*i))->fP.Perp2();
-    (*i)->SetRnrElement(ptsq >= minptsq && ptsq <= maxptsq);
+    (*i)->SetRnrSelf(ptsq >= minptsq && ptsq <= maxptsq);
   }
 }
 
@@ -642,6 +774,5 @@ void TrackCounter::OutputEventTracks(FILE* out)
       }
       ++i;
     }
-
   }
 }