]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliModule.cxx
fForceDecay initialized to kAll in constructors
[u/mrichter/AliRoot.git] / STEER / AliModule.cxx
index 8028594ea1e5179e86fb1913e5b6632394da1e01..43b99bcb36ee57ae9dd12688a76bfd679228c03d 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-/*
-$Log$
-Revision 1.9  2000/05/16 08:45:08  fca
-Correct dtor, thanks to J.Belikov
-
-Revision 1.8  2000/02/23 16:25:22  fca
-AliVMC and AliGeant3 classes introduced
-ReadEuclid moved from AliRun to AliModule
-
-Revision 1.7  1999/09/29 09:24:29  fca
-Introduction of the Copyright and cvs Log
-
-*/
+/* $Id$ */
 
 ///////////////////////////////////////////////////////////////////////////////
 //                                                                           //
@@ -44,43 +32,70 @@ Introduction of the Copyright and cvs Log
 //End_Html
 //                                                                           //
 ///////////////////////////////////////////////////////////////////////////////
+
+#include <TNode.h>
+#include <TObjArray.h>
+#include <TClonesArray.h>
+#include <TTree.h>
+#include <TSystem.h>
+#include <TDirectory.h>
+#include <TVirtualMC.h>
+
+#include "AliConfig.h"
+#include "AliLoader.h"
+#include "AliMagF.h"
 #include "AliModule.h"
 #include "AliRun.h"
-#include "AliHit.h"
-#include "AliPoints.h"
-#include <TClass.h>
-#include <TNode.h>
-#include <TRandom.h>
+#include "AliTrackReference.h"
+#include "AliMC.h"
 
 ClassImp(AliModule)
  
-//_____________________________________________________________________________
-AliModule::AliModule()
+//_______________________________________________________________________
+AliModule::AliModule():
+  fEuclidMaterial(""),
+  fEuclidGeometry(""),
+  fIdtmed(0),
+  fIdmate(0),
+  fLoMedium(0),
+  fHiMedium(0),
+  fActive(0),
+  fHistograms(0),
+  fNodes(0),
+  fDebug(0),
+  fEnable(1),
+  fTrackReferences(0),
+  fMaxIterTrackRef(0),
+  fCurrentIterTrackRef(0)
 {
   //
   // Default constructor for the AliModule class
   //
-  fHistograms = 0;
-  fNodes      = 0;
-  fIdtmed     = 0;
-  fIdmate     = 0;
 }
  
-//_____________________________________________________________________________
-AliModule::AliModule(const char* name,const char *title):TNamed(name,title)
+//_______________________________________________________________________
+AliModule::AliModule(const char* name,const char *title):
+  TNamed(name,title),
+  fEuclidMaterial(""),
+  fEuclidGeometry(""),
+  fIdtmed(new TArrayI(100)),
+  fIdmate(new TArrayI(100)),
+  fLoMedium(65536),
+  fHiMedium(0),
+  fActive(0),
+  fHistograms(new TList()),
+  fNodes(new TList()),
+  fDebug(0),
+  fEnable(1),
+  fTrackReferences(new TClonesArray("AliTrackReference", 100)),
+  fMaxIterTrackRef(0),
+  fCurrentIterTrackRef(0)
 {
   //
   // Normal constructor invoked by all Modules.
   // Create the list for Module specific histograms
   // Add this Module to the global list of Modules in Run.
   //
-  //
-  // Initialises the histogram list
-  fHistograms = new TList();
-  //
-  // Initialises the list of ROOT TNodes
-  fNodes      = new TList();
-  //  
   // Get the Module numeric ID
   Int_t id = gAlice->GetModuleID(name);
   if (id>=0) {
@@ -90,51 +105,84 @@ AliModule::AliModule(const char* name,const char *title):TNamed(name,title)
   }
   //
   // Add this Module to the list of Modules
-  gAlice->Modules()->Add(this);
-  //
-  //
+
+  gAlice->AddModule(this);
+
   SetMarkerColor(3);
   //
-  // Allocate space for tracking media and material indexes
-  fIdtmed = new TArrayI(100);
-  fIdmate  = new TArrayI(100);
+  // Clear space for tracking media and material indexes
+
   for(Int_t i=0;i<100;i++) (*fIdmate)[i]=(*fIdtmed)[i]=0;
-  //
-  // Prepare to find the tracking media range
-  fLoMedium = 65536;
-  fHiMedium = 0;
+
+    
+  SetDebug(gAlice->GetDebug());
 }
  
-//_____________________________________________________________________________
-AliModule::AliModule(const AliModule &mod)
+//_______________________________________________________________________
+AliModule::AliModule(const AliModule &mod):
+  TNamed(mod),
+  TAttLine(mod),
+  TAttMarker(mod),
+  AliRndm(mod),
+  fEuclidMaterial(""),
+  fEuclidGeometry(""),
+  fIdtmed(0),
+  fIdmate(0),
+  fLoMedium(0),
+  fHiMedium(0),
+  fActive(0),
+  fHistograms(0),
+  fNodes(0),
+  fDebug(0),
+  fEnable(0),
+  fTrackReferences(0),
+  fMaxIterTrackRef(0),
+  fCurrentIterTrackRef(0)
 {
   //
   // Copy constructor
   //
-  Copy(*this);
+  mod.Copy(*this);
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 AliModule::~AliModule()
 {
   //
   // Destructor
   //
-  fHistograms = 0;
-  //
+
+  // Remove this Module from the list of Modules
+  if (gAlice) {
+    TObjArray * modules = gAlice->Modules();
+    if (modules) modules->Remove(this);
+  }
   // Delete ROOT geometry
   if(fNodes) {
     fNodes->Clear();
     delete fNodes;
+    fNodes = 0;
+  }
+  // Delete histograms
+  if(fHistograms) {
+    fHistograms->Clear();
+    delete fHistograms;
+    fHistograms = 0;
+  }
+  // Delete track references
+  if (fTrackReferences) {
+    fTrackReferences->Delete();
+    delete fTrackReferences;
+    fTrackReferences     = 0;
   }
-  //
   // Delete TArray objects
   delete fIdtmed;
   delete fIdmate;
+
 }
  
-//_____________________________________________________________________________
-void AliModule::Copy(AliModule &mod) const
+//_______________________________________________________________________
+void AliModule::Copy(TObject & /* mod */) const
 {
   //
   // Copy *this onto mod, not implemented for AliModule
@@ -142,7 +190,7 @@ void AliModule::Copy(AliModule &mod) const
   Fatal("Copy","Not implemented!\n");
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::Disable()
 {
   //
@@ -154,22 +202,12 @@ void AliModule::Disable()
   //
   // Loop through geometry to disable all
   // nodes for this Module
-  while((node = (TNode*)next())) {
-    node->SetVisibility(0);
+  while((node = dynamic_cast<TNode*>(next()))) {
+    node->SetVisibility(-1);
   }   
 }
 
-//_____________________________________________________________________________
-Int_t AliModule::DistancetoPrimitive(Int_t, Int_t)
-{
-  //
-  // Return distance from mouse pointer to object
-  // Dummy routine for the moment
-  //
-  return 9999;
-}
-
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::Enable()
 {
   //
@@ -181,15 +219,15 @@ void AliModule::Enable()
   //
   // Loop through geometry to enable all
   // nodes for this Module
-  while((node = (TNode*)next())) {
-    node->SetVisibility(1);
+  while((node = dynamic_cast<TNode*>(next()))) {
+    node->SetVisibility(3);
   }   
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a, 
-                             Float_t z, Float_t dens, Float_t radl,
-                             Float_t absl, Float_t *buf, Int_t nwbuf) const
+                            Float_t z, Float_t dens, Float_t radl,
+                            Float_t absl, Float_t *buf, Int_t nwbuf) const
 {
   //
   // Store the parameters for a material
@@ -209,10 +247,10 @@ void AliModule::AliMaterial(Int_t imat, const char* name, Float_t a,
   (*fIdmate)[imat]=kmat;
 }
   
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a, 
-                             Float_t &z, Float_t &dens, Float_t &radl,
-                             Float_t &absl)
+                               Float_t &z, Float_t &dens, Float_t &radl,
+                               Float_t &absl) const
 {
   //
   // Store the parameters for a material
@@ -235,10 +273,10 @@ void AliModule::AliGetMaterial(Int_t imat, char* name, Float_t &a,
 }
   
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
-                            Float_t *z, Float_t dens, Int_t nlmat,
-                            Float_t *wmat) const
+                           Float_t *z, Float_t dens, Int_t nlmat,
+                           Float_t *wmat) const
 { 
   //
   // Defines mixture or compound imat as composed by 
@@ -264,12 +302,12 @@ void AliModule::AliMixture(Int_t imat, const char *name, Float_t *a,
   (*fIdmate)[imat]=kmat;
 } 
  
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
-                           Int_t isvol, Int_t ifield, Float_t fieldm,
-                           Float_t tmaxfd, Float_t stemax, Float_t deemax,
-                           Float_t epsil, Float_t stmin, Float_t *ubuf,
-                           Int_t nbuf) const
+                          Int_t isvol, Int_t ifield, Float_t fieldm,
+                          Float_t tmaxfd, Float_t stemax, Float_t deemax,
+                          Float_t epsil, Float_t stmin, Float_t *ubuf,
+                          Int_t nbuf) const
 { 
   //
   // Store the parameters of a tracking medium
@@ -298,10 +336,10 @@ void AliModule::AliMedium(Int_t numed, const char *name, Int_t nmat,
   (*fIdtmed)[numed]=kmed;
 } 
  
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
-                           Float_t theta2, Float_t phi2, Float_t theta3,
-                           Float_t phi3) const
+                          Float_t theta2, Float_t phi2, Float_t theta3,
+                          Float_t phi3) const
 {
   // 
   // Define a rotation matrix. Angles are in degrees.
@@ -317,14 +355,19 @@ void AliModule::AliMatrix(Int_t &nmat, Float_t theta1, Float_t phi1,
   gMC->Matrix(nmat, theta1, phi1, theta2, phi2, theta3, phi3); 
 } 
 
-//_____________________________________________________________________________
-AliModule& AliModule::operator=(const AliModule &mod)
+//_______________________________________________________________________
+Float_t AliModule::ZMin() const
 {
-  mod.Copy(*this);
-  return (*this);
+  return -500;
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
+Float_t AliModule::ZMax() const
+{
+  return 500;
+}
+
+//_______________________________________________________________________
 void AliModule::SetEuclidFile(char* material, char* geometry)
 {
   //
@@ -342,7 +385,7 @@ void AliModule::SetEuclidFile(char* material, char* geometry)
   }
 }
  
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::ReadEuclid(const char* filnam, char* topvol)
 {
   //                                                                     
@@ -368,7 +411,7 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
   char key[5], card[77], natmed[21];
   char name[5], mother[5], shape[5], konly[5], volst[7000][5];
   char *filtmp;
-  Float_t par[50];
+  Float_t par[100];
   Float_t teta1, phi1, teta2, phi2, teta3, phi3, orig, step;
   Float_t xo, yo, zo;
   const Int_t kMaxRot=5000;
@@ -497,7 +540,7 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
     }
     if (istop[i] && !flag) {
       strcpy(topvol,volst[i]);
-      printf(" *** GREUCL *** volume %s taken as a top volume\n",topvol);
+      if(fDebug) printf("%s::ReadEuclid: volume %s taken as a top volume\n",ClassName(),topvol);
       flag=1;
     }
   }
@@ -507,7 +550,7 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
   fclose (lun);
   //*
   //*     commented out only for the not cernlib version
-  printf(" *** GREUCL *** file: %s is now read in\n",filnam);
+  if(fDebug) printf("%s::ReadEuclid: file: %s is now read in\n",ClassName(),filnam);
   //
   return;
   //*
@@ -515,7 +558,7 @@ void AliModule::ReadEuclid(const char* filnam, char* topvol)
   Error("ReadEuclid","reading error or premature end of file\n");
 }
 
-//_____________________________________________________________________________
+//_______________________________________________________________________
 void AliModule::ReadEuclidMedia(const char* filnam)
 {
   //                                                                     
@@ -545,7 +588,7 @@ void AliModule::ReadEuclidMedia(const char* filnam)
   }
   //
   // *** The input filnam name will be with extension '.euc'
-  printf("The file name is %s\n",filnam); //Debug
+  if(fDebug) printf("%s::ReadEuclid: The file name is %s\n",ClassName(),filnam); //Debug
   filtmp=gSystem->ExpandPathName(filnam);
   lun=fopen(filtmp,"r");
   delete [] filtmp;
@@ -600,44 +643,187 @@ void AliModule::ReadEuclidMedia(const char* filnam)
   fclose (lun);
   //*
   //*     commented out only for the not cernlib version
-  Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
+  if(fDebug) printf("%s::ReadEuclidMedia: file %s is now read in\n",
+       ClassName(),filnam);
   //*
   return;
   //*
  L20:
   Warning("ReadEuclidMedia","reading error or premature end of file\n");
 } 
-//_____________________________________________________________________________
-void AliModule::Streamer(TBuffer &R__b)
+
+//_______________________________________________________________________
+void AliModule::RemapTrackReferencesIDs(Int_t *map)
+{
+  // 
+  // Remapping track reference
+  // Called at finish primary
+  //
+  if (!fTrackReferences) return;
+  for (Int_t i=0;i<fTrackReferences->GetEntries();i++){
+    AliTrackReference * ref = dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(i));
+    if (ref) {
+      Int_t newID = map[ref->GetTrack()];
+      if (newID>=0) ref->SetTrack(newID);
+      else {
+        //ref->SetTrack(-1);
+        ref->SetBit(kNotDeleted,kFALSE);
+        fTrackReferences->RemoveAt(i);  
+      }      
+    }
+  }
+  fTrackReferences->Compress();
+
+}
+
+
+//_______________________________________________________________________
+AliTrackReference* AliModule::FirstTrackReference(Int_t track)
 {
   //
-  // Stream an object of class Module.
-  //
-  if (R__b.IsReading()) {
-    Version_t R__v = R__b.ReadVersion(); if (R__v) { }
-    TNamed::Streamer(R__b);
-    TAttLine::Streamer(R__b);
-    TAttMarker::Streamer(R__b);
-    fEuclidMaterial.Streamer(R__b);
-    fEuclidGeometry.Streamer(R__b);
-    R__b >> fActive;
-    R__b >> fHistograms;
-    //
-    // Stream the pointers but not the TClonesArrays
-    R__b >> fNodes; // diff
+  // 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) 
+   {
+     AliRunLoader* rl = AliRunLoader::GetRunLoader();
+
+     rl->GetAliRun()->GetMCApp()->ResetTrackReferences();
+     rl->TreeTR()->GetEvent(track);
+     if (rl == 0x0)
+       Fatal("FirstTrackReference","AliRunLoader not initialized. Can not proceed");
+   }
+  //
+  fMaxIterTrackRef     = fTrackReferences->GetEntriesFast();
+  fCurrentIterTrackRef = 0;
+  if(fMaxIterTrackRef) return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(0));
+  else            return 0;
+}
+
+//_______________________________________________________________________
+AliTrackReference* AliModule::NextTrackReference()
+{
+  //
+  // Return the next hit for the current track
+  //
+  if(fMaxIterTrackRef) {
+    if(++fCurrentIterTrackRef<fMaxIterTrackRef) 
+      return dynamic_cast<AliTrackReference*>(fTrackReferences->UncheckedAt(fCurrentIterTrackRef));
+    else        
+      return 0;
   } else {
-    R__b.WriteVersion(AliModule::IsA());
-    TNamed::Streamer(R__b);
-    TAttLine::Streamer(R__b);
-    TAttMarker::Streamer(R__b);
-    fEuclidMaterial.Streamer(R__b);
-    fEuclidGeometry.Streamer(R__b);
-    R__b << fActive;
-    R__b << fHistograms;
-    //
-    // Stream the pointers but not the TClonesArrays
-    R__b << fNodes; // diff
+    printf("* AliModule::NextTrackReference * TrackReference  Iterator called without calling FistTrackReference before\n");
+    return 0;
   }
 }
+
+
+//_______________________________________________________________________
+void AliModule::ResetTrackReferences()
+{
+  //
+  // Reset number of hits and the hits array
+  //
+  fMaxIterTrackRef   = 0;
+  if (fTrackReferences)   fTrackReferences->Clear();
+}
  
+//_____________________________________________________________________________
+
+AliLoader*  AliModule::MakeLoader(const char* /*topfoldername*/) 
+ {
+   return 0x0;
+ }//skowron   
+//PH Merged with v3-09-08 |
+//                        V
+//_____________________________________________________________________________
+
+void AliModule::SetTreeAddress()
+{
+  //
+  // Set branch address for track reference Tree
+  //
+
+  TBranch *branch;
+
+  // Branch address for track reference tree
+  TTree *treeTR = TreeTR();
+
+  if (treeTR && fTrackReferences) {
+     branch = treeTR->GetBranch(GetName());
+    if (branch) 
+     {
+       if(GetDebug()) 
+         Info("SetTreeAddress","(%s) Setting for TrackRefs",GetName());
+       branch->SetAddress(&fTrackReferences);
+     }
+    else
+     { 
+     //can be called before MakeBranch and than does not make sense to issue the warning
+       if(GetDebug()) 
+         Warning("SetTreeAddress",
+                 "(%s) Failed for Track References. Can not find branch in tree.",
+                 GetName());
+     }
+  }
+}
+
+//_____________________________________________________________________________
+void  AliModule::AddTrackReference(Int_t label){
+  //
+  // add a trackrefernce to the list
+  if (!fTrackReferences) {
+    cerr<<"Container trackrefernce not active\n";
+    return;
+  }
+  Int_t nref = fTrackReferences->GetEntriesFast();
+  TClonesArray &lref = *fTrackReferences;
+  new(lref[nref]) AliTrackReference(label);
+}
+
+
+//_____________________________________________________________________________
+void AliModule::MakeBranchTR(Option_t */*option*/)
+{ 
+    //
+    // Makes branch in treeTR
+    //  
+  if(GetDebug()) Info("MakeBranchTR","Making Track Refs. Branch for %s",GetName());
+  TTree * tree = TreeTR();
+  if (fTrackReferences && tree) 
+   {
+      TBranch *branch = tree->GetBranch(GetName());
+     if (branch) 
+       {  
+        if(GetDebug()) Info("MakeBranch","Branch %s is already in tree.",GetName());
+        return;
+       }
+  
+     branch = tree->Branch(GetName(),&fTrackReferences);
+   }
+  else
+    {
+      if(GetDebug()) 
+       Info("MakeBranchTR","FAILED for %s: tree=%#x fTrackReferences=%#x",
+            GetName(),tree,fTrackReferences);
+    }
+}
+
+//_____________________________________________________________________________
+TTree* AliModule::TreeTR()
+{
+  AliRunLoader* rl = AliRunLoader::GetRunLoader();
+
+  if ( rl == 0x0)
+   {
+     Error("TreeTR","Can not get the run loader");
+     return 0x0;
+   }
+
+  TTree* tree = rl->TreeTR();
+  return tree;
+}