]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliDetector.cxx
FirsTrackReference updated (M.Ivanov)
[u/mrichter/AliRoot.git] / STEER / AliDetector.cxx
index 84402dbe7fc371bfe250d263fec92096a95c3a61..14c7a07433e625d36c9b6fa44d0bc5dbcfc44ef6 100644 (file)
 
 /*
 $Log$
+Revision 1.18  2002/08/26 13:51:17  hristov
+Remaping of track references at the end of each primary particle (M.Ivanov)
+
+Revision 1.17  2002/05/24 13:29:58  hristov
+AliTrackReference added, AliDisplay modified
+
+Revision 1.16  2001/10/04 15:30:56  hristov
+Changes to accommodate the set of PHOS folders and tasks (Y.Schutz)
+
+Revision 1.15  2001/07/27 13:03:13  hristov
+Default Branch split level set to 99
+
+Revision 1.14  2001/05/21 17:22:51  buncic
+Fixed problem with missing AliConfig while reading galice.root
+
+Revision 1.13  2001/05/16 14:57:22  alibrary
+New files for folders and Stack
+
+Revision 1.12  2001/03/12 17:47:03  hristov
+Changes needed on Sun with CC 5.0
+
+Revision 1.11  2001/01/26 19:58:46  hristov
+Major upgrade of AliRoot code
+
 Revision 1.10  2001/01/17 10:50:50  hristov
 Corrections to destructors
 
@@ -54,19 +78,27 @@ Introduction of the Copyright and cvs Log
 ///////////////////////////////////////////////////////////////////////////////
 
 #include <assert.h>
+#include <iostream.h>
 
 #include <TTree.h>
 #include <TBrowser.h>
 #include <TFile.h>
+#include <TROOT.h>
+#include <TFolder.h>
 
+#include "AliConfig.h"
 #include "AliDetector.h"
 #include "AliRun.h"
 #include "AliHit.h"
 #include "AliPoints.h"
+#include "AliTrackReference.h"
+
+
 // Static variables for the hit iterator routines
 static Int_t sMaxIterHit=0;
 static Int_t sCurIterHit=0;
 
+
 ClassImp(AliDetector)
  
 //_____________________________________________________________________________
@@ -79,6 +111,7 @@ AliDetector::AliDetector()
   fNdigits    = 0;
   fPoints     = 0;
   fHits       = 0;
+  fTrackReferences =0;
   fDigits     = 0;
   fTimeGate   = 200.e-9;
   fBufferSize = 16000;
@@ -98,11 +131,18 @@ AliDetector::AliDetector(const char* name,const char *title):AliModule(name,titl
   fActive     = kTRUE;
   fNhits      = 0;
   fHits       = 0;
+  fTrackReferences =0;
   fDigits     = 0;
   fNdigits    = 0;
   fPoints     = 0;
   fBufferSize = 16000;
   fDigitsFile = 0;
+
+  AliConfig::Instance()->Add(this);
+
+  fTrackReferences        = new TClonesArray("AliTrackReference", 100);
+  //if detector to want to create another track reference - than let's be free 
+  
 }
  
 //_____________________________________________________________________________
@@ -128,7 +168,108 @@ AliDetector::~AliDetector()
   }
   if (fDigitsFile) delete [] fDigitsFile;
 }
+
+//_____________________________________________________________________________
+void AliDetector::Publish(const char *dir, void *address, const char *name)
+{
+  //
+  // Register pointer to detector objects. 
+  // 
+  TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
+  if  (topFolder) { 
+    TFolder *folder = (TFolder *)topFolder->FindObjectAny(dir);
+    // TFolder *folder = (TFolder *)gROOT->FindObjectAny(dir);
+    if (!folder)  {
+      cerr << "Cannot register: Missing folder: " << dir << endl;
+    } else {
+      TFolder *subfolder = (TFolder *) folder->FindObjectAny(this->GetName()); 
+
+      if(!subfolder)
+         subfolder = folder->AddFolder(this->GetName(),this->GetTitle());
+      if (address) {
+        TObject **obj = (TObject **) address;
+        if ((*obj)->InheritsFrom(TCollection::Class())) {
+           TCollection *collection = (TCollection *) (*obj); 
+           if (name)
+             collection->SetName(name);
+        } 
+        subfolder->Add(*obj);
+      } 
+    }  
+  }
+}
+
+//_____________________________________________________________________________
+TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, void* address, Int_t size,const char *file)
+{ 
+    return(MakeBranchInTree(tree,name,0,address,size,99,file));
+}
+
+//_____________________________________________________________________________
+TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, const char *classname, void* address,Int_t size, Int_t splitlevel, const char *file)
+{ 
+    //
+    // Makes branch in given tree and diverts them to a separate file
+    //  
+    if (GetDebug()>1)
+      printf("* MakeBranch * Making Branch %s \n",name);
+      
+    TDirectory *cwd = gDirectory;
+    TBranch *branch = 0;
+    
+    if (classname) {
+      branch = tree->Branch(name,classname,address,size,splitlevel);
+    } else {
+      branch = tree->Branch(name,address,size);
+    }
+       
+    if (file) {
+        char * outFile = new char[strlen(gAlice->GetBaseFile())+strlen(file)+2];
+        sprintf(outFile,"%s/%s",gAlice->GetBaseFile(),file);
+        branch->SetFile(outFile);
+        TIter next( branch->GetListOfBranches());
+        while ((branch=(TBranch*)next())) {
+           branch->SetFile(outFile);
+        } 
+       delete outFile;
+        
+       cwd->cd();
+        
+       if (GetDebug()>1)
+           printf("* MakeBranch * Diverting Branch %s to file %s\n",name,file);
+    }
+    char *folder = 0;
+    TString folderName(name);  
+    
+    if (!strncmp(tree->GetName(),"TreeE",5)) folder = "RunMC/Event/Data";
+    if (!strncmp(tree->GetName(),"TreeK",5)) folder = "RunMC/Event/Data";
+    if (!strncmp(tree->GetName(),"TreeH",5)) {
+      folder     = "RunMC/Event/Data/Hits";
+      folderName = "Hits" ; 
+    }
+    if (!strncmp(tree->GetName(),"TreeTrackReferences",5)) {
+      folder     = "RunMC/Event/Data/TrackReferences";
+      folderName = "TrackReferences" ; 
+    }
+
+    if (!strncmp(tree->GetName(),"TreeD",5)) {
+      folder     = "Run/Event/Data";
+      folderName = "Digits" ; 
+    }
+    if (!strncmp(tree->GetName(),"TreeS",5)) {
+      folder     = "RunMC/Event/Data/SDigits";
+      folderName = "SDigits" ; 
+    }
+    if (!strncmp(tree->GetName(),"TreeR",5)) folder = "Run/Event/RecData";
+
+    if (folder) {
+      if (GetDebug())
+          printf("%15s: Publishing %s to %s\n",ClassName(),name,folder);
+      Publish(folder,address, folderName.Data());
+    }  
+    return branch;
+}
+
 //_____________________________________________________________________________
 void AliDetector::Browse(TBrowser *b)
 {
@@ -165,6 +306,25 @@ void AliDetector::FinishRun()
   //
 }
 
+
+
+void AliDetector::RemapTrackReferencesIDs(Int_t *map)
+{
+  // 
+  //remaping track reference
+  //called at finish primary
+  if (!fTrackReferences) return;
+  for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
+    AliTrackReference * ref = (AliTrackReference*) fTrackReferences->UncheckedAt(i);
+    if (ref) {
+      Int_t newID = map[ref->GetTrack()];
+      if (newID>=0) ref->SetTrack(newID);
+      else ref->SetTrack(-1);
+      
+    }
+  }
+}
+
 //_____________________________________________________________________________
 AliHit* AliDetector::FirstHit(Int_t track)
 {
@@ -186,6 +346,30 @@ AliHit* AliDetector::FirstHit(Int_t track)
   else            return 0;
 }
 
+
+//_____________________________________________________________________________
+AliTrackReference* AliDetector::FirstTrackReference(Int_t track)
+{
+  //
+  // Initialise the hit iterator
+  // Return the address of the first hit for track
+  // If track>=0 the track is read from disk
+  // while if track<0 the first hit of the current
+  // track is returned
+  // 
+  if(track>=0) {
+    gAlice->ResetTrackReferences();
+    gAlice->TreeTR()->GetEvent(track);
+  }
+  //
+  fMaxIterTrackRef     = fTrackReferences->GetEntriesFast();
+  fCurrentIterTrackRef = 0;
+  if(fMaxIterTrackRef) return (AliTrackReference*) fTrackReferences->UncheckedAt(0);
+  else            return 0;
+}
+
+
+
 //_____________________________________________________________________________
 AliHit* AliDetector::NextHit()
 {
@@ -202,6 +386,22 @@ AliHit* AliDetector::NextHit()
     return 0;
   }
 }
+//_____________________________________________________________________________
+AliTrackReference* AliDetector::NextTrackReference()
+{
+  //
+  // Return the next hit for the current track
+  //
+  if(fMaxIterTrackRef) {
+    if(++fCurrentIterTrackRef<fMaxIterTrackRef) 
+      return (AliTrackReference*) fTrackReferences->UncheckedAt(fCurrentIterTrackRef);
+    else        
+      return 0;
+  } else {
+    printf("* AliDetector::NextTrackReference * TrackReference  Iterator called without calling FistTrackReference before\n");
+    return 0;
+  }
+}
 
 //_____________________________________________________________________________
 void AliDetector::LoadPoints(Int_t)
@@ -274,7 +474,7 @@ void AliDetector::LoadPoints(Int_t)
 }
 
 //_____________________________________________________________________________
-void AliDetector::MakeBranch(Option_t *option, char *file)
+void AliDetector::MakeBranch(Option_t *option, const char *file)
 {
   //
   // Create a new branch in the current Root Tree
@@ -285,14 +485,14 @@ void AliDetector::MakeBranch(Option_t *option, char *file)
   sprintf(branchname,"%s",GetName());
   //
   // Get the pointer to the header
-  char *cH = strstr(option,"H");
+  const char *cH = strstr(option,"H");
   //
   if (fHits && gAlice->TreeH() && cH) {
-    gAlice->MakeBranchInTree(gAlice->TreeH(), 
-                             branchname, &fHits, fBufferSize, file) ;
+    MakeBranchInTree(gAlice->TreeH(), 
+                     branchname, &fHits, fBufferSize, file) ;              
   }    
   
-  char *cD = strstr(option,"D");
+  const char *cD = strstr(option,"D");
 
   if (cD) {
     if (file) {
@@ -301,6 +501,25 @@ void AliDetector::MakeBranch(Option_t *option, char *file)
     }
   }
 }
+//_____________________________________________________________________________
+void AliDetector::MakeBranchTR(Option_t *option, const char *file)
+{
+  //
+  // Create a new branch in the current Root Tree
+  // The branch of fHits is automatically split
+  //
+  char branchname[10];
+  sprintf(branchname,"%s",GetName());
+  //
+  // Get the pointer to the header
+  const char *cTR = strstr(option,"T");
+  //
+  if (fTrackReferences && gAlice->TreeTR() && cTR) {
+    MakeBranchInTree(gAlice->TreeTR(), 
+                     branchname, &fTrackReferences, fBufferSize, file) ;              
+  }      
+}
 
 //_____________________________________________________________________________
 void AliDetector::ResetDigits()
@@ -322,6 +541,20 @@ void AliDetector::ResetHits()
   if (fHits)   fHits->Clear();
 }
 
+
+
+//_____________________________________________________________________________
+void AliDetector::ResetTrackReferences()
+{
+  //
+  // Reset number of hits and the hits array
+  //
+  fMaxIterTrackRef   = 0;
+  if (fTrackReferences)   fTrackReferences->Clear();
+}
+
+
+
 //_____________________________________________________________________________
 void AliDetector::ResetPoints()
 {
@@ -358,6 +591,15 @@ void AliDetector::SetTreeAddress()
     branch = treeD->GetBranch(branchname);
     if (branch) branch->SetAddress(&fDigits);
   }
+
+  // Branch address for tr  tree
+  TTree *treeTR = gAlice->TreeTR();
+  if (treeTR && fTrackReferences) {
+    branch = treeTR->GetBranch(branchname);
+    if (branch) branch->SetAddress(&fTrackReferences);
+  }
+
+
 }