]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - EVE/EveBase/AliEveKineTools.cxx
With Jochen: new class for arbitrarily shaped jet-cone. Will go to ROOT for the next...
[u/mrichter/AliRoot.git] / EVE / EveBase / AliEveKineTools.cxx
index 7e16b7f5045d278b203049b45bf399f99432a7e8..9d22447464a569394294a9a3b0c06948e9175d60 100644 (file)
 //______________________________________________________________________________
 // AliEveKineTools
 //
-// Tools for import of kinematics. Preliminary version.
+// Tools for import of kinematics.
 //
 
 ClassImp(AliEveKineTools)
 
 namespace {
 
-  typedef std::map<Int_t, TEveTrack*> TrackMap_t;
+  // Map to store label-to-track association.
+  //
+  // multimap is used as there are cases when initial particles (in
+  // particular resonances) are not assigned proper status-codes
+  // and can thus be found several times in the eve-track-list.
+
+  typedef std::multimap<Int_t, TEveTrack*>                 TrackMap_t;
+  typedef std::multimap<Int_t, TEveTrack*>::const_iterator TrackMap_ci;
 
   void MapTracks(TrackMap_t& map, TEveElement* cont, Bool_t recurse)
   {
     TEveElement::List_i i = cont->BeginChildren();
     while (i != cont->EndChildren()) {
       TEveTrack* track = dynamic_cast<TEveTrack*>(*i);
-      map[track->GetLabel()] = track;
+      map.insert(std::make_pair(track->GetLabel(), track));
       if (recurse)
         MapTracks(map, track, recurse);
       ++i;
@@ -68,7 +75,20 @@ void AliEveKineTools::SetDaughterPathMarks(TEveElement* cont, AliStack* stack, B
                                         TEveVector(dp->Vx(), dp->Vy(), dp->Vz()),
                                         TEveVector(dp->Px(), dp->Py(), dp->Pz()),
                                         dp->T()));
+        // printf("Daughter path-mark for %d, %d, t=%e, r=%f,%f,%f\n",
+        //        track->GetLabel(), d, dp->T(), dp->Vx(), dp->Vy(), dp->Vz());
+      }
+
+      // Check last process, set decay if needed.
+      Int_t lp = stack->Particle(d1)->GetUniqueID();
+      if (lp != kPBrem && lp != kPDeltaRay && lp < kPCerenkov)
+      {
+        TParticle* dp = stack->Particle(d1);
+        track->AddPathMark(TEvePathMark(TEvePathMark::kDecay,
+                                        TEveVector(dp->Vx(), dp->Vy(), dp->Vz()),
+                                        TEveVector(0, 0,0),  dp->T()));
       }
+
       if (recurse)
        SetDaughterPathMarks(track, stack, recurse);
     }
@@ -87,70 +107,68 @@ void AliEveKineTools::SetTrackReferences(TEveElement* cont, TTree* treeTR, Bool_
   TrackMap_t map;
   MapTracks(map, cont, recurse);
 
-  Int_t nPrimaries = (Int_t) treeTR->GetEntries();
-  TIter next(treeTR->GetListOfBranches());
-  TBranchElement* el;
-  Bool_t isRef = kTRUE;
+  TClonesArray* arr = 0;
+  treeTR->SetBranchAddress("TrackReferences", &arr);
+
+  Int_t nTreeEntries = (Int_t) treeTR->GetEntries();
 
-  while ((el = (TBranchElement*) next()))
+  for (Int_t te = 0; te < nTreeEntries; ++te)
   {
-    if (strcmp("AliRun",el->GetName()) == 0)
-      isRef = kFALSE;
+    treeTR->GetEntry(te);
+
+    Int_t last_label = -1;
+    std::pair<TrackMap_ci, TrackMap_ci> range;
+    Int_t nArrEntries = arr->GetEntriesFast();
+
+    // printf("tree-entry %d, n-arr-entries %d\n", te, nArrEntries);
 
-    TClonesArray* arr = 0;
-    el->SetAddress(&arr);
-    for (Int_t iPrimPart = 0; iPrimPart<nPrimaries; iPrimPart++)
+    for (Int_t ae = 0; ae < nArrEntries; ++ae)
     {
-      el->GetEntry(iPrimPart);
+      AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(ae);
+      Bool_t isRef = (atr->DetectorId() != -1);
+      Int_t  label = atr->GetTrack();
 
-      Int_t last_label = -1;
-      TrackMap_t::iterator iter = map.end();
-      Int_t Nent =  arr->GetEntriesFast();
-      for (Int_t iTrackRef = 0; iTrackRef < Nent; iTrackRef++)
+      // printf("    arr-entry %d, label %d, detid %d, len=%f, t=%e r=%f,%f,%f\n",
+      //        ae, label, atr->DetectorId(), 
+      //        atr->GetLength(), atr->GetTime(), atr->X(), atr->Y(), atr->Z());
+
+      if (label < 0)
+        throw(kEH + Form("negative label for array-entry %d in tree-entry %d.",
+                         ae, te));
+
+      if (label != last_label)
+      {
+        range      = map.equal_range(label);
+        last_label = label;
+      }
+
+      for (TrackMap_ci i = range.first; i != range.second; ++i)
       {
-       AliTrackReference* atr = (AliTrackReference*)arr->UncheckedAt(iTrackRef);
-
-       Int_t label = atr->GetTrack();
-       if (label < 0)
-         throw(kEH + Form("negative label for entry %d in branch %s.",
-                         iTrackRef, el->GetName()));
-
-        if (label != last_label)
-        {
-         iter       = map.find(label);
-         last_label = label;
-       }
-
-       if (iter != map.end())
-        {
-          iter->second->AddPathMark
-            (TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay,
-                          TEveVector(atr->X(),  atr->Y(),  atr->Z()),
-                          TEveVector(atr->Px(), atr->Py(), atr->Pz()),
-                          atr->GetTime()));
-       }
-      } // loop track refs
-    } // loop primaries in clones arrays
-    delete arr;
-  } // end loop through top branches
+       i->second->AddPathMark
+          (TEvePathMark(isRef ? TEvePathMark::kReference : TEvePathMark::kDecay,
+                        TEveVector(atr->X(),  atr->Y(),  atr->Z()),
+                        TEveVector(atr->Px(), atr->Py(), atr->Pz()),
+                        atr->GetTime()));
+      }
+    }
+  }
+  delete arr;
 }
 
 /**************************************************************************/
 
 void AliEveKineTools::SortPathMarks(TEveElement* el, Bool_t recurse)
 {
-  // Sort path-marks for all tracks by time.
-
-  // !!!!! MT ... this is one level deep only!
+  // Sort path-marks for track by time.
+  // If recurse is true, descends down all track children.
 
   TEveTrack* track = dynamic_cast<TEveTrack*>(el);
-  if (track) track->SortPathMarksByTime();
+  if (track)
+    track->SortPathMarksByTime();
 
-  TEveElement::List_i i = el->BeginChildren();
-  while (i != el->EndChildren() && recurse)
+  if (recurse)
   {
-    track = dynamic_cast<TEveTrack*>(el);
-    if (track) track->SortPathMarksByTime();
-    ++i;
+    for (TEveElement::List_i i = el->BeginChildren(); i != el->EndChildren(); ++i)
+      SortPathMarks(*i, kTRUE);
   }
 }