]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliDetector.cxx
Useful macros for the shifter
[u/mrichter/AliRoot.git] / STEER / AliDetector.cxx
index 59c815bb8501719133231f0cba2c274464968c14..9fd0964e5c37ef1bd95e59f9ec50c1ec2174eef2 100644 (file)
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
 
-#include <assert.h>
-
 #include <TBrowser.h>
-#include <TFile.h>
-#include <TFolder.h>
-#include <TROOT.h>
+#include <TClonesArray.h>
 #include <TTree.h>
-#include <Riostream.h>
 
+#include "AliLog.h"
 #include "AliConfig.h"
 #include "AliDetector.h"
 #include "AliHit.h"
-#include "AliPoints.h"
 #include "AliLoader.h"
 #include "AliRun.h"
-
-
-// Static variables for the hit iterator routines
-static Int_t sMaxIterHit=0;
-static Int_t sCurIterHit=0;
+#include "AliMC.h"
 
 
 ClassImp(AliDetector)
  
 //_______________________________________________________________________
 AliDetector::AliDetector():
+  AliModule(),
   fTimeGate(200.e-9),
   fIshunt(0),
   fNhits(0),
   fNdigits(0),
   fBufferSize(1600),
+  fMaxIterHit(0),
+  fCurIterHit(0),
   fHits(0),
   fDigits(0),
-  fPoints(0),
   fLoader(0x0)
 {
   //
@@ -74,22 +67,6 @@ AliDetector::AliDetector():
   //
 }
  
-//_______________________________________________________________________
-AliDetector::AliDetector(const AliDetector &det):
-  AliModule(det),
-  fTimeGate(200.e-9),
-  fIshunt(0),
-  fNhits(0),
-  fNdigits(0),
-  fBufferSize(1600),
-  fHits(0),
-  fDigits(0),
-  fPoints(0),
-  fLoader(0x0)
-{
-  det.Copy(*this);
-}
-
 //_____________________________________________________________________________
 AliDetector::AliDetector(const char* name,const char *title):
   AliModule(name,title),
@@ -98,9 +75,10 @@ AliDetector::AliDetector(const char* name,const char *title):
   fNhits(0),
   fNdigits(0),
   fBufferSize(1600),
+  fMaxIterHit(0),
+  fCurIterHit(0),
   fHits(0),
   fDigits(0),
-  fPoints(0),
   fLoader(0x0)
 {
   //
@@ -121,12 +99,6 @@ AliDetector::~AliDetector()
   // Destructor
   //
 
-  // Delete space point structure
-  if (fPoints) {
-    fPoints->Delete();
-    delete fPoints;
-    fPoints     = 0;
-  }
   // Delete digits structure
   if (fDigits) {
     fDigits->Delete();
@@ -142,15 +114,21 @@ AliDetector::~AliDetector()
 }
 
 //_______________________________________________________________________
-void AliDetector::Publish(const char *dir, void *address, const char *name)
+void AliDetector::Publish(const char */*dir*/, void */*address*/, const char */*name*/) const
 {
 //
 // Register pointer to detector objects. 
 // 
-//  TFolder *topFolder = (TFolder *)gROOT->FindObjectAny("/Folders");
   MayNotUse("Publish");
 }
 
+//_______________________________________________________________________
+void AliDetector::AddAlignableVolumes() const
+{
+  // 
+  AliWarning(Form("%s still has to implement the AddAlignableVolumes method!",GetName()));
+}
+
 //_______________________________________________________________________
 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, 
                                        void* address, Int_t size,
@@ -163,24 +141,24 @@ TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
 TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name, 
                                        const char *classname, 
                                        void* address,Int_t size, 
-                                       Int_t splitlevel, const char *file)
+                                       Int_t splitlevel, const char */*file*/)
 { 
 //
 // Makes branch in given tree and diverts them to a separate file
 // 
 //
 //
-// if (GetDebug()>1)
if(GetDebug()) Info("MakeBranch","Making Branch %s",name);
+    
AliDebug(2,Form("Making Branch %s",name));
  if (tree == 0x0) 
   {
-   Error("MakeBranch","Making Branch %s Tree is NULL",name);
+   AliError(Form("Making Branch %s Tree is NULL",name));
    return 0x0;
   }
  TBranch *branch = tree->GetBranch(name);
  if (branch) 
   {  
-    if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",name);
+    AliDebug(2,Form("Branch %s is already in tree.",name));
     return branch;
   }
     
@@ -190,9 +168,9 @@ TBranch* AliDetector::MakeBranchInTree(TTree *tree, const char* name,
   } 
  else 
   {
-    branch = tree->Branch(name,address,size);
+    branch = tree->Bronch(name, "TClonesArray", address, size, splitlevel);
   }
if(GetDebug()) Info("MakeBranch","Branch %s returning branch %#x",name,branch);
AliDebug(2,Form("Branch %s returning branch %#x",name,branch));
  return branch;
 }
 
@@ -215,15 +193,6 @@ void AliDetector::Browse(TBrowser *b)
   }
 }
 
-//_______________________________________________________________________
-void AliDetector::Copy(AliDetector &) const
-{
-  //
-  // Copy *this onto det -- not implemented
-  //
-  Fatal("Copy","Not implemented\n");
-}
-
 //_______________________________________________________________________
 void AliDetector::FinishRun()
 {
@@ -243,13 +212,13 @@ AliHit* AliDetector::FirstHit(Int_t track)
   // track is returned
   // 
   if(track>=0) {
-    gAlice->ResetHits(); //stupid = if N detector this method is called N times
-    TreeH()->GetEvent(track); //skowron
+    gAlice->GetMCApp()->ResetHits(); //stupid = if N detector this method is called N times
+    fLoader->TreeH()->GetEvent(track); //skowron
   }
   //
-  sMaxIterHit=fHits->GetEntriesFast();
-  sCurIterHit=0;
-  if(sMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
+  fMaxIterHit=fHits->GetEntriesFast();
+  fCurIterHit=0;
+  if(fMaxIterHit) return dynamic_cast<AliHit*>(fHits->UncheckedAt(0));
   else            return 0;
 }
 
@@ -259,99 +228,17 @@ AliHit* AliDetector::NextHit()
   //
   // Return the next hit for the current track
   //
-  if(sMaxIterHit) {
-    if(++sCurIterHit<sMaxIterHit) 
-      return dynamic_cast<AliHit*>(fHits->UncheckedAt(sCurIterHit));
+  if(fMaxIterHit) {
+    if(++fCurIterHit<fMaxIterHit) 
+      return dynamic_cast<AliHit*>(fHits->UncheckedAt(fCurIterHit));
     else        
       return 0;
   } else {
-    printf("* AliDetector::NextHit * Hit Iterator called without calling FistHit before\n");
+    AliWarning("Hit Iterator called without calling FistHit before");
     return 0;
   }
 }
 
-//_______________________________________________________________________
-void AliDetector::LoadPoints(Int_t)
-{
-  //
-  // Store x, y, z of all hits in memory
-  //
-  if (fHits == 0) 
-   {
-    Error("LoadPoints","fHits == 0. Name is %s",GetName());
-    return;
-   }
-  //
-  Int_t nhits = fHits->GetEntriesFast();
-  if (nhits == 0) 
-   {
-//    Error("LoadPoints","nhits == 0. Name is %s",GetName());
-    return;
-   }
-  Int_t tracks = gAlice->GetNtrack();
-  if (fPoints == 0) fPoints = new TObjArray(tracks);
-  AliHit *ahit;
-  //
-  Int_t *ntrk=new Int_t[tracks];
-  Int_t *limi=new Int_t[tracks];
-  Float_t **coor=new Float_t*[tracks];
-  for(Int_t i=0;i<tracks;i++) {
-    ntrk[i]=0;
-    coor[i]=0;
-    limi[i]=0;
-  }
-  //
-  AliPoints *points = 0;
-  Float_t *fp=0;
-  Int_t trk;
-  Int_t chunk=nhits/4+1;
-  //
-  // Loop over all the hits and store their position
-  for (Int_t hit=0;hit<nhits;hit++) {
-    ahit = dynamic_cast<AliHit*>(fHits->UncheckedAt(hit));
-    trk=ahit->GetTrack();
-    assert(trk<=tracks);
-    if(ntrk[trk]==limi[trk])
-     {
-      //
-      // Initialise a new track
-      fp=new Float_t[3*(limi[trk]+chunk)];
-      if(coor[trk]) 
-       {
-          memcpy(fp,coor[trk],sizeof(Float_t)*3*limi[trk]);
-          delete [] coor[trk];
-       }
-      limi[trk]+=chunk;
-      coor[trk] = fp;
-     } 
-    else 
-     {
-      fp = coor[trk];
-     }
-    fp[3*ntrk[trk]  ] = ahit->X();
-    fp[3*ntrk[trk]+1] = ahit->Y();
-    fp[3*ntrk[trk]+2] = ahit->Z();
-    ntrk[trk]++;
-  }
-  //
-  for(trk=0; trk<tracks; ++trk) {
-    if(ntrk[trk]) {
-      points = new AliPoints();
-      points->SetMarkerColor(GetMarkerColor());
-      points->SetMarkerSize(GetMarkerSize());
-      points->SetDetector(this);
-      points->SetParticle(trk);
-      points->SetPolyMarker(ntrk[trk],coor[trk],GetMarkerStyle());
-      fPoints->AddAt(points,trk);
-      delete [] coor[trk];
-      coor[trk]=0;
-    }
-  }
-  delete [] coor;
-  delete [] ntrk;
-  delete [] limi;
-}
-
 //_______________________________________________________________________
 void AliDetector::MakeBranch(Option_t *option)
 {
@@ -359,12 +246,12 @@ void AliDetector::MakeBranch(Option_t *option)
   // Create a new branch for this detector in its treeH
   //
 
-  if(GetDebug()) Info("MakeBranch"," for %s",GetName());
+  AliDebug(2,Form(" for %s",GetName()));
   const char *cH = strstr(option,"H");
 
-  if (fHits && TreeH() && cH) 
+  if (fHits && fLoader->TreeH() && cH) 
    {
-     MakeBranchInTree(TreeH(), GetName(), &fHits, fBufferSize, 0);
+     MakeBranchInTree(fLoader->TreeH(), GetName(), &fHits, fBufferSize, 0);
    }   
 }
 
@@ -388,19 +275,6 @@ void AliDetector::ResetHits()
   if (fHits) fHits->Clear();
 }
 
-//_______________________________________________________________________
-void AliDetector::ResetPoints()
-{
-  //
-  // Reset array of points
-  //
-  if (fPoints) {
-    fPoints->Delete();
-    delete fPoints;
-    fPoints = 0;
-  }
-}
-
 //_______________________________________________________________________
 void AliDetector::SetTreeAddress()
 {
@@ -411,17 +285,17 @@ void AliDetector::SetTreeAddress()
   //
   // Branch address for hit tree
   
-  TTree *tree = TreeH();
+  TTree* tree = fLoader->TreeH();
   if (tree && fHits) {
     branch = tree->GetBranch(GetName());
     if (branch) 
      {
-       if(GetDebug()) Info("SetTreeAddress","(%s) Setting for Hits",GetName());
+       AliDebug(2,Form("(%s) Setting for Hits",GetName()));
        branch->SetAddress(&fHits);
      }
     else
      { //can be invoked before branch creation
-       if(GetDebug()) Warning("SetTreeAddress","(%s) Failed for Hits. Can not find branch in tree.",GetName());
+       AliDebug(2,Form("(%s) Failed for Hits. Can not find branch in tree.",GetName()));
      }
   }
   
@@ -432,8 +306,6 @@ void AliDetector::SetTreeAddress()
     branch = treeD->GetBranch(GetName());
     if (branch) branch->SetAddress(&fDigits);
   }
-  
-  AliModule::SetTreeAddress();
 }
 
 //_______________________________________________________________________
@@ -448,7 +320,7 @@ void AliDetector::MakeTree(Option_t *option)
     AliLoader* loader = GetLoader();
     if (loader == 0x0)
      {
-       Error("MakeTree","Can not get loader for %s",GetName());
+       AliError(Form("Can not get loader for %s",GetName()));
        return;
      }
     loader->MakeTree(option); //delegate this job to getter
@@ -460,27 +332,11 @@ AliLoader* AliDetector::MakeLoader(const char* topfoldername)
 //builds standard getter (AliLoader type)
 //if detector wants to use castomized getter, it must overload this method
 
- if (GetDebug())
-   Info("MakeLoader",
-        "Creating standard getter for detector %s. Top folder is %s.",
-         GetName(),topfoldername);
+ AliDebug(1,Form("Creating standard getter for detector %s. Top folder is %s.",
+         GetName(),topfoldername));
      
  fLoader = new AliLoader(GetName(),topfoldername);
  return fLoader;
 }
 
-//_______________________________________________________________________
-TTree* AliDetector::TreeH()
-{
-//Get the hits container from the folder
-  if (GetLoader() == 0x0) 
-    {
-    //sunstitude this with make getter when we can obtain the event folder name 
-     Error("TreeH","Can not get the getter");
-     return 0x0;
-    }
-  TTree* tree = (TTree*)GetLoader()->TreeH();
-  return tree;
-}