]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - STEER/AliRun.cxx
Variable number of modules introduced. Also corrections to the tree resetting
[u/mrichter/AliRoot.git] / STEER / AliRun.cxx
index 42710a962f11570a7b8658ccbdc1a2d74ac9b3fb..0ccf52a94fb7ba22fb0e2bf1129fd759a2775eb5 100644 (file)
 //   -Supports the event display.                                            //
 //Begin_Html
 /*
-<img src="gif/AliRunClass.gif">
+<img src="picts/AliRunClass.gif">
 */
 //End_Html
 //Begin_Html
 /*
-<img src="gif/alirun.gif">
+<img src="picts/alirun.gif">
 */
 //End_Html
 //                                                                           //
 #include <TRandom.h>
 #include <TBRIK.h> 
 #include <TNode.h> 
-#include <AliMC.h> 
 #include <TCint.h> 
 #include <TSystem.h>
 
-#include "GParticle.h"
+#include "TParticle.h"
 #include "AliRun.h"
-#include "AliModule.h"
 #include "AliDisplay.h"
 
 #include "AliCallf77.h" 
@@ -52,22 +50,18 @@ static AliHeader *header;
 # define rxstrak rxstrak_
 # define rxkeep  rxkeep_ 
 # define rxouth  rxouth_
-# define sxpart  sxpart_
 #else
 
 # define rxgtrak RXGTRAK 
 # define rxstrak RXSTRAK 
 # define rxkeep  RXKEEP  
 # define rxouth  RXOUTH
-# define sxpart  SXPART
 #endif
 
 static TArrayF sEventEnergy;
 static TArrayF sSummEnergy;
 static TArrayF sSum2Energy;
 
-extern "C" void type_of_call sxpart();
-
 ClassImp(AliRun)
 
 //_____________________________________________________________________________
@@ -96,9 +90,9 @@ AliRun::AliRun()
   fImedia    = 0;
   fTrRmax    = 1.e10;
   fTrZmax    = 1.e10;
-  fIdtmed    = 0;
   fInitDone  = kFALSE;
   fLego      = 0;
+  fPDGDB     = 0;        //Particle factory object!
 }
 
 //_____________________________________________________________________________
@@ -121,6 +115,7 @@ AliRun::AliRun(const char *name, const char *title)
   fTreeR     = 0;
   fTrRmax    = 1.e10;
   fTrZmax    = 1.e10;
+  fGenerator = 0;
   fInitDone  = kFALSE;
   fLego      = 0;
   fField     = 0;
@@ -143,7 +138,7 @@ AliRun::AliRun(const char *name, const char *title)
   fEvent     = 0;
   //
   // Create the particle stack
-  fParticles = new TClonesArray("GParticle",100);
+  fParticles = new TClonesArray("TParticle",100);
   
   fDisplay = 0;
   //
@@ -154,7 +149,7 @@ AliRun::AliRun(const char *name, const char *title)
   //
   //---------------Load detector names
   
-  fNdets=21;
+  /*  fNdets=21;
   strcpy(fDnames[0],"BODY");
   strcpy(fDnames[1],"NULL");
   strcpy(fDnames[2],"ITS");
@@ -176,13 +171,14 @@ AliRun::AliRun(const char *name, const char *title)
   strcpy(fDnames[18],"DIPO");
   strcpy(fDnames[19],"HALL");
   strcpy(fDnames[20],"PIPE");
-  
+  */
   //
   // Prepare the tracking medium lists
   fImedia = new TArrayI(1000);
   for(i=0;i<1000;i++) (*fImedia)[i]=-99;
-  fIdtmed = new Int_t[fNdets*100];
-  for(i=0;i<fNdets*100;i++) fIdtmed[i]=0;
+  //
+  // Make particles
+  fPDGDB     = TDatabasePDG::Instance();        //Particle factory object!
 }
 
 //_____________________________________________________________________________
@@ -191,7 +187,6 @@ AliRun::~AliRun()
   //
   // Defaullt AliRun destructor
   //
-  delete [] fIdtmed;
   delete fImedia;
   delete fField;
   delete fMC;
@@ -297,16 +292,16 @@ void AliRun::CleanParents()
 {
   //
   // Clean Particles stack.
-  // Set parent/child relations
+  // Set parent/daughter relations
   //
   TClonesArray &particles = *(gAlice->Particles());
-  GParticle *part;
+  TParticle *part;
   int i;
   for(i=0; i<fNtrack; i++) {
-    part = (GParticle *)particles.UncheckedAt(i);
-    if(!part->TestBit(Children_Bit)) {
-      part->SetFirstChild(-1);
-      part->SetLastChild(-1);
+    part = (TParticle *)particles.UncheckedAt(i);
+    if(!part->TestBit(Daughters_Bit)) {
+      part->SetFirstDaughter(-1);
+      part->SetLastDaughter(-1);
     }
   }
 }
@@ -328,7 +323,7 @@ void AliRun::DumpPart (Int_t i)
   // Dumps particle i in the stack
   //
   TClonesArray &particles = *fParticles;
-  ((GParticle*) particles[i])->Dump();
+  ((TParticle*) particles[i])->Print();
 }
 
 //_____________________________________________________________________________
@@ -342,7 +337,7 @@ void AliRun::DumpPStack ()
         "\n\n=======================================================================\n");
   for (Int_t i=0;i<fNtrack;i++) 
     {
-      printf("-> %d ",i); ((GParticle*) particles[i])->Dump();
+      printf("-> %d ",i); ((TParticle*) particles[i])->Print();
       printf("--------------------------------------------------------------\n");
     }
   printf(
@@ -363,7 +358,8 @@ void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
   //
   // --- Sanity check on mag field flags
   if(type<0 || type > 2) {
-    printf(" Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
+    Warning("SetField",
+           "Invalid magnetic field flag: %5d; Helix tracking chosen instead\n"
           ,type);
     type=2;
   }
@@ -374,7 +370,7 @@ void AliRun::SetField(Int_t type, Int_t version, Float_t scale,
     fField = new AliMagFCM("Map2-3",filename,type,version,scale,maxField);
     fField->ReadField();
   } else {
-    printf("Invalid map %d\n",version);
+    Warning("SetField","Invalid map %d\n",version);
   }
 }
 
@@ -515,11 +511,11 @@ void AliRun::FlagTrack(Int_t track)
   // Flags a track and all its family tree to be kept
   //
   int curr;
-  GParticle *particle;
+  TParticle *particle;
 
   curr=track;
   while(1) {
-    particle=(GParticle*)fParticles->UncheckedAt(curr);
+    particle=(TParticle*)fParticles->UncheckedAt(curr);
     
     // If the particle is flagged the three from here upward is saved already
     if(particle->TestBit(Keep_Bit)) return;
@@ -528,7 +524,7 @@ void AliRun::FlagTrack(Int_t track)
     particle->SetBit(Keep_Bit);
     
     // Move to father if any
-    if((curr=particle->GetParent())==-1) return;
+    if((curr=particle->GetFirstMother())==-1) return;
   }
 }
  
@@ -609,18 +605,25 @@ AliModule *AliRun::GetModule(const char *name)
   return (AliModule*)fModules->FindObject(name);
 }
  
+//_____________________________________________________________________________
+AliDetector *AliRun::GetDetector(const char *name)
+{
+  //
+  // Return pointer to detector from name
+  //
+  return (AliDetector*)fModules->FindObject(name);
+}
 //_____________________________________________________________________________
 Int_t AliRun::GetModuleID(const char *name)
 {
   //
   // Return galice internal detector identifier from name
   //
-  Int_t i;
-  for(i=0;i<fNdets;i++) if(!strcmp(fDnames[i],name)) {
-    return i;
-  }
-  printf(" * GetDetectorID * Detector %s not found: returning -1\n",name);
-  return -1;
+  Int_t i=-1;
+  TObject *mod=fModules->FindObject(name);
+  if(mod) i=fModules->IndexOf(mod);
+  return i;
 }
  
 //_____________________________________________________________________________
@@ -648,14 +651,13 @@ Int_t AliRun::GetEvent(Int_t event)
   sprintf(treeName,"TreeK%d",event);
   fTreeK = (TTree*)gDirectory->Get(treeName);
   if (fTreeK) fTreeK->SetBranchAddress("Particles", &fParticles);
-  else        printf("ERROR: cannot find Kine Tree for event:%d\n",event);
+  else    Error("GetEvent","cannot find Kine Tree for event:%d\n",event);
   
   // Get Hits Tree header from file
   sprintf(treeName,"TreeH%d",event);
   fTreeH = (TTree*)gDirectory->Get(treeName);
   if (!fTreeH) {
-    printf("ERROR: cannot find Hits Tree for event:%d\n",event);
-    return 0;
+    Error("GetEvent","cannot find Hits Tree for event:%d\n",event);
   }
   
   // Get Digits Tree header from file
@@ -726,26 +728,28 @@ void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
   //
   // Return next track from stack of particles
   //
+  const TVector3 *pol;
   fCurrent=-1;
-  GParticle *track;
+  TParticle *track;
   for(Int_t i=fNtrack-1; i>=0; i--) {
-    track=(GParticle*) fParticles->UncheckedAt(i);
+    track=(TParticle*) fParticles->UncheckedAt(i);
     if(!track->TestBit(Done_Bit)) {
       //
       // The track has not yet been processed
       fCurrent=i;
-      ipart=track->GetKF();
-      pmom[0]=track->GetPx();
-      pmom[1]=track->GetPy(); 
-      pmom[2]=track->GetPz();
-      e     =track->GetEnergy();
-      vpos[0]=track->GetVx();
-      vpos[1]=track->GetVy();
-      vpos[2]=track->GetVz();
-      polar[0]=track->GetPolx();
-      polar[1]=track->GetPoly();
-      polar[2]=track->GetPolz();
-      tof=track->GetTime();
+      ipart=track->GetPdgCode();
+      pmom[0]=track->Px();
+      pmom[1]=track->Py(); 
+      pmom[2]=track->Pz();
+      e     =track->Energy();
+      vpos[0]=track->Vx();
+      vpos[1]=track->Vy();
+      vpos[2]=track->Vz();
+      pol = track->GetPolarisation();
+      polar[0]=pol->X();
+      polar[1]=pol->Y();
+      polar[2]=pol->Z();
+      tof=track->T();
       track->SetBit(Done_Bit);
       break;
     }
@@ -757,8 +761,8 @@ void AliRun::GetNextTrack(Int_t &mtrack, Int_t &ipart, Float_t *pmom,
   if (fCurrent >= nprimaries) return;
   if (fCurrent < nprimaries-1) {
     fTimer.Stop();
-    track=(GParticle*) fParticles->UncheckedAt(fCurrent+1);
-    track->SetProcessTime(fTimer.CpuTime());
+    track=(TParticle*) fParticles->UncheckedAt(fCurrent+1);
+    //    track->SetProcessTime(fTimer.CpuTime());
   }
   fTimer.Start();
 }
@@ -770,13 +774,13 @@ Int_t AliRun::GetPrimary(Int_t track)
   // return number of primary that has generated track
   //
   int current, parent;
-  GParticle *part;
+  TParticle *part;
   //
   parent=track;
   while (1) {
     current=parent;
-    part = (GParticle *)fParticles->UncheckedAt(current);
-    parent=part->GetParent();
+    part = (TParticle *)fParticles->UncheckedAt(current);
+    parent=part->GetFirstMother();
     if(parent<0) return current;
   }
 }
@@ -793,11 +797,12 @@ void AliRun::Init(const char *setup)
 
   AliMC* pMC = AliMC::GetMC();
 
-  pMC->Gpart();  //Create standard Geant particles
-  sxpart();        //Define additional particles
+  pMC->DefineParticles();  //Create standard MC particles
 
   TObject *objfirst, *objlast;
 
+  fNdets = fModules->GetLast()+1;
+
   //
   //=================Create Materials, geometry, histograms, etc
    TIter next(fModules);
@@ -828,9 +833,9 @@ void AliRun::Init(const char *setup)
    pMC->Ggclos();
    
    //Initialise geometry deposition table
-   sEventEnergy.Set(pMC->Nvolumes()+1);
-   sSummEnergy.Set(pMC->Nvolumes()+1);
-   sSum2Energy.Set(pMC->Nvolumes()+1);
+   sEventEnergy.Set(pMC->NofVolumes()+1);
+   sSummEnergy.Set(pMC->NofVolumes()+1);
+   sSum2Energy.Set(pMC->NofVolumes()+1);
    
    //Create the color table
    pMC->SetColors();
@@ -851,7 +856,8 @@ void AliRun::MediaTable()
   // Built media table to get from the media number to
   // the detector id
   //
-  Int_t kz, ibeg, nz, idt, lz, i, k, ind;
+  Int_t kz, nz, idt, lz, i, k, ind;
+  //  Int_t ibeg;
   TObjArray &dets = *gAlice->Detectors();
   AliModule *det;
   //
@@ -859,10 +865,10 @@ void AliRun::MediaTable()
   for (kz=0;kz<fNdets;kz++) {
     // If detector is defined
     if((det=(AliModule*) dets[kz])) {
-      ibeg=100*kz-1;
-      for(nz=ibeg==-1?1:0;nz<100;nz++) {
+        TArrayI &idtmed = *(det->GetIdtmed()); 
+        for(nz=0;nz<100;nz++) {
        // Find max and min material number
-       if((idt=fIdtmed[ibeg+nz])) {
+       if((idt=idtmed[nz])) {
          det->LoMedium() = det->LoMedium() < idt ? det->LoMedium() : idt;
          det->HiMedium() = det->HiMedium() > idt ? det->HiMedium() : idt;
        }
@@ -872,7 +878,8 @@ void AliRun::MediaTable()
        det->HiMedium() = 0;
       } else {
        if(det->HiMedium() > fImedia->GetSize()) {
-         Error("MediaTable","Increase fImedia");
+         Error("MediaTable","Increase fImedia from %d to %d",
+               fImedia->GetSize(),det->HiMedium());
          return;
        }
        // Tag all materials in rage as belonging to detector kz
@@ -915,8 +922,8 @@ void AliRun::SetTransPar(char* filename)
   // Read filename to set the transport parameters
   //
 
-  AliMC* pMC = AliMC::GetMC();
 
+  AliMC* pMC = AliMC::GetMC();
   const Int_t ncuts=10;
   const Int_t nflags=11;
   const Int_t npars=ncuts+nflags;
@@ -925,6 +932,7 @@ void AliRun::SetTransPar(char* filename)
                               "BREM","COMP","DCAY","DRAY","HADR","LOSS",
                               "MULS","PAIR","PHOT","RAYL"};
   char line[256];
+  char detName[7];
   char* filtmp;
   Float_t cut[ncuts];
   Int_t flag[nflags];
@@ -936,7 +944,7 @@ void AliRun::SetTransPar(char* filename)
   lun=fopen(filtmp,"r");
   delete [] filtmp;
   if(!lun) {
-    printf(" * AliRun::SetTransPar * file %s does not exist!\n",filename);
+    Warning("SetTransPar","File %s does not exist!\n",filename);
     return;
   }
   //
@@ -965,39 +973,50 @@ void AliRun::SetTransPar(char* filename)
     if(!iret) continue;
     if(line[0]=='*') continue;
     // Read the numbers
-    iret=sscanf(line,"%d %f %f %f %f %f %f %f %f %f %f %d %d %d %d %d %d %d %d %d %d %d",
-               &itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],&cut[9],
-               &flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],&flag[8],
-               &flag[9],&flag[10]);
+    iret=sscanf(line,"%s %d %f %f %f %f %f %f %f %f %f %f %d %d %d %d %d %d %d %d %d %d %d",
+               detName,&itmed,&cut[0],&cut[1],&cut[2],&cut[3],&cut[4],&cut[5],&cut[6],&cut[7],&cut[8],
+               &cut[9],&flag[0],&flag[1],&flag[2],&flag[3],&flag[4],&flag[5],&flag[6],&flag[7],
+               &flag[8],&flag[9],&flag[10]);
     if(!iret) continue;
     if(iret<0) {
       //reading error
-      printf(" *   Error reading file %s\n",filename);
+      Warning("SetTransPar","Error reading file %s\n",filename);
       continue;
     }
-    // Check that the tracking medium code is valid
-    if(0<itmed && itmed < 100*fNdets) {
-      ktmed=fIdtmed[itmed-1];
-      if(!ktmed) {
-       printf(" *     Invalid tracking medium code %d *\n",itmed);
-       continue;
-      }
-      // Set energy thresholds
-      for(kz=0;kz<ncuts;kz++) {
-       if(cut[kz]>=0) {
-         printf(" *  %-6s set to %10.3E for tracking medium code %4d  *\n",pars[kz],cut[kz],itmed);
-         pMC->Gstpar(ktmed,pars[kz],cut[kz]);
+    // Check that the module exist
+    AliModule *mod = GetModule(detName);
+    if(mod) {
+      // Get the array of media numbers
+      TArrayI &idtmed = *mod->GetIdtmed();
+      // Check that the tracking medium code is valid
+      if(0<=itmed && itmed < 100) {
+       ktmed=idtmed[itmed];
+       if(!ktmed) {
+         Warning("SetTransPar","Invalid tracking medium code %d for %s\n",itmed,mod->GetName());
+         continue;
        }
-      }
-      // Set transport mechanisms
-      for(kz=0;kz<nflags;kz++) {
-       if(flag[kz]>=0) {
-         printf(" *  %-6s set to %10d for tracking medium code %4d  *\n",pars[ncuts+kz],flag[kz],itmed);
-         pMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
+       // Set energy thresholds
+       for(kz=0;kz<ncuts;kz++) {
+         if(cut[kz]>=0) {
+           printf(" *  %-6s set to %10.3E for tracking medium code %4d for %s\n",
+                  pars[kz],cut[kz],itmed,mod->GetName());
+           pMC->Gstpar(ktmed,pars[kz],cut[kz]);
+         }
+       }
+       // Set transport mechanisms
+       for(kz=0;kz<nflags;kz++) {
+         if(flag[kz]>=0) {
+           printf(" *  %-6s set to %10d for tracking medium code %4d for %s\n",
+                  pars[ncuts+kz],flag[kz],itmed,mod->GetName());
+           pMC->Gstpar(ktmed,pars[ncuts+kz],Float_t(flag[kz]));
+         }
        }
+      } else {
+       Warning("SetTransPar","Invalid medium code %d *\n",itmed);
+       continue;
       }
     } else {
-      printf(" *     Invalid tracking medium code %d *\n",itmed);
+      Warning("SetTransPar","Module %s not present\n",detName);
       continue;
     }
   }
@@ -1062,7 +1081,7 @@ void AliRun::PurifyKine()
   //
   TClonesArray &particles = *fParticles;
   int nkeep=fHgwmk+1, parent, i;
-  GParticle *part, *partnew, *father;
+  TParticle *part, *partnew, *father;
   AliHit *OneHit;
   int *map = new int[particles.GetEntries()];
 
@@ -1074,7 +1093,7 @@ void AliRun::PurifyKine()
     if(i<=fHgwmk) map[i]=i ; else map[i] = -99 ;}
   // Second pass, build map between old and new numbering
   for(i=fHgwmk+1; i<fNtrack; i++) {
-    part = (GParticle *)particles.UncheckedAt(i);
+    part = (TParticle *)particles.UncheckedAt(i);
     if(part->TestBit(Keep_Bit)) {
       
       // This particle has to be kept
@@ -1082,35 +1101,35 @@ void AliRun::PurifyKine()
       if(i!=nkeep) {
        
        // Old and new are different, have to copy
-       partnew = (GParticle *)particles.UncheckedAt(nkeep);
+       partnew = (TParticle *)particles.UncheckedAt(nkeep);
        *partnew = *part;
       } else partnew = part;
       
       // as the parent is always *before*, it must be already
       // in place. This is what we are checking anyway!
-      if((parent=partnew->GetParent())>fHgwmk) {
+      if((parent=partnew->GetFirstMother())>fHgwmk) {
        if(map[parent]==-99) printf("map[%d] = -99!\n",parent);
-       partnew->SetParent(map[parent]);
+       partnew->SetFirstMother(map[parent]);
       }
       nkeep++;
     }
   }
   fNtrack=nkeep;
   
-  // Fix children information
+  // Fix daughters information
   for (i=fHgwmk+1; i<fNtrack; i++) {
-    part = (GParticle *)particles.UncheckedAt(i);
-    parent = part->GetParent();
-    father = (GParticle *)particles.UncheckedAt(parent);
-    if(father->TestBit(Children_Bit)) {
+    part = (TParticle *)particles.UncheckedAt(i);
+    parent = part->GetFirstMother();
+    father = (TParticle *)particles.UncheckedAt(parent);
+    if(father->TestBit(Daughters_Bit)) {
       
-      if(i<father->GetFirstChild()) father->SetFirstChild(i);
-      if(i>father->GetLastChild())  father->SetLastChild(i);
+      if(i<father->GetFirstDaughter()) father->SetFirstDaughter(i);
+      if(i>father->GetLastDaughter())  father->SetLastDaughter(i);
     } else {
-      // Iitialise children info for first pass
-      father->SetFirstChild(i);
-      father->SetLastChild(i);
-      father->SetBit(Children_Bit);
+      // Iitialise daughters info for first pass
+      father->SetFirstDaughter(i);
+      father->SetLastDaughter(i);
+      father->SetBit(Daughters_Bit);
     }
   }
   
@@ -1150,6 +1169,7 @@ void AliRun::Reset(Int_t run, Int_t idevent)
   if(fTreeK) fTreeK->Reset();
   if(fTreeH) fTreeH->Reset();
   if(fTreeD) fTreeD->Reset();
+  if(fTreeR) fTreeR->Reset();
 }
 
 //_____________________________________________________________________________
@@ -1256,17 +1276,17 @@ void AliRun::RunLego(const char *setup,Int_t ntheta,Float_t themin,
   //  Use macro "lego.C" to visualize the 3 lego plots in spherical coordinates
   //Begin_Html
   /*
-    <img src="gif/AliRunLego1.gif">
+    <img src="picts/AliRunLego1.gif">
   */
   //End_Html
   //Begin_Html
   /*
-    <img src="gif/AliRunLego2.gif">
+    <img src="picts/AliRunLego2.gif">
   */
   //End_Html
   //Begin_Html
   /*
-    <img src="gif/AliRunLego3.gif">
+    <img src="picts/AliRunLego3.gif">
   */
   //End_Html
   //
@@ -1295,7 +1315,7 @@ void AliRun::SetCurrentTrack(Int_t track)
 }
  
 //_____________________________________________________________________________
-void AliRun::SetTrack(Int_t done, Int_t parent, Int_t ipart, Float_t *pmom,
+void AliRun::SetTrack(Int_t done, Int_t parent, Int_t pdg, Float_t *pmom,
                      Float_t *vpos, Float_t *polar, Float_t tof,
                      const char *mecha, Int_t &ntr, Float_t weight)
 { 
@@ -1305,7 +1325,7 @@ void AliRun::SetTrack(Int_t done, Int_t parent, Int_t ipart, Float_t *pmom,
   // done     0 if the track has to be transported
   //          1 if not
   // parent   identifier of the parent track. -1 for a primary
-  // ipart    particle code
+  // pdg    particle code
   // pmom     momentum GeV/c
   // vpos     position 
   // polar    polarisation 
@@ -1314,32 +1334,40 @@ void AliRun::SetTrack(Int_t done, Int_t parent, Int_t ipart, Float_t *pmom,
   // ntr      on output the number of the track stored
   //
   TClonesArray &particles = *fParticles;
-  GParticle *particle;
+  TParticle *particle;
   Float_t mass;
-  char pname[21];
-  const Int_t firstchild=-1;
-  const Int_t lastchild=-1;
+  const Int_t firstdaughter=-1;
+  const Int_t lastdaughter=-1;
   const Int_t KS=0;
-  const Float_t tlife=0;
+  //  const Float_t tlife=0;
   
-  AliMC::GetMC()->GetParticle(ipart,pname,mass);
+  //
+  // Here we get the static mass
+  // For MC is ok, but a more sophisticated method could be necessary
+  // if the calculated mass is required
+  // also, this method is potentially dangerous if the mass
+  // used in the MC is not the same of the PDG database
+  //
+  mass = TDatabasePDG::Instance()->GetParticle(pdg)->Mass();
   Float_t e=TMath::Sqrt(mass*mass+pmom[0]*pmom[0]+
                        pmom[1]*pmom[1]+pmom[2]*pmom[2]);
   
   //printf("Loading particle %s mass %f ene %f No %d ip %d pos %f %f %f mom %f %f %f KS %d m %s\n",
-  //pname,mass,e,fNtrack,ipart,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
+  //pname,mass,e,fNtrack,pdg,vpos[0],vpos[1],vpos[2],pmom[0],pmom[1],pmom[2],KS,mecha);
   
-  particle=new(particles[fNtrack]) GParticle(KS,ipart,parent,firstchild,
-                                            lastchild,pmom[0],pmom[1],pmom[2],
-                                            e,mass,vpos[0],vpos[1],vpos[2],
-                                            polar[0],polar[1],polar[2],tof,
-                                            tlife,mecha,weight);
+  particle=new(particles[fNtrack]) TParticle(pdg,KS,parent,-1,firstdaughter,
+                                            lastdaughter,pmom[0],pmom[1],pmom[2],
+                                            e,vpos[0],vpos[1],vpos[2],tof);
+  //                                        polar[0],polar[1],polar[2],tof,
+  //                                        mecha,weight);
+  ((TParticle*)particles[fNtrack])->SetPolarisation(TVector3(polar[0],polar[1],polar[2]));
+  ((TParticle*)particles[fNtrack])->SetWeight(weight);
   if(!done) particle->SetBit(Done_Bit);
   
   if(parent>=0) {
-    particle=(GParticle*) fParticles->UncheckedAt(parent);
-    particle->SetLastChild(fNtrack);
-    if(particle->GetFirstChild()<0) particle->SetFirstChild(fNtrack);
+    particle=(TParticle*) fParticles->UncheckedAt(parent);
+    particle->SetLastDaughter(fNtrack);
+    if(particle->GetFirstDaughter()<0) particle->SetFirstDaughter(fNtrack);
   } else { 
     //
     // This is a primary track. Set high water mark for this event
@@ -1359,7 +1387,7 @@ void AliRun::KeepTrack(const Int_t track)
   // flags a track to be kept
   //
   TClonesArray &particles = *fParticles;
-  ((GParticle*)particles[track])->SetBit(Keep_Bit);
+  ((TParticle*)particles[track])->SetBit(Keep_Bit);
 }
  
 //_____________________________________________________________________________
@@ -1387,7 +1415,7 @@ void AliRun::StepManager(Int_t id) const
 }
 
 //_____________________________________________________________________________
-void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
+void AliRun::ReadEuclid(const char* filnam, const AliModule *det, const char* topvol)
 {
   //                                                                     
   //       read in the geometry of the detector in euclid file format    
@@ -1408,7 +1436,6 @@ void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
   //
 
   AliMC* pMC = AliMC::GetMC();
-
   Int_t i, nvol, iret, itmed, irot, numed, npar, ndiv, iaxe;
   Int_t ndvmx, nr, flag;
   char key[5], card[77], natmed[21];
@@ -1419,15 +1446,6 @@ void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
   Float_t xo, yo, zo;
   Int_t idrot[5000],istop[7000];
   FILE *lun;
-  AliModule *det;
-  //
-  TObjArray &dets = *fModules;
-  if(!dets[id_det]) {
-    printf(" *** GREUTMED *** Detector %d not defined\n",id_det);
-    return;
-  } else {
-    det = (AliModule*) dets[id_det];
-  }
   //
   // *** The input filnam name will be with extension '.euc'
   filtmp=gSystem->ExpandPathName(filnam);
@@ -1437,7 +1455,8 @@ void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
     printf(" *** GREUCL *** Could not open file %s\n",filnam);
     return;
   }
-  //* --- definition of rotation matrix 0 ---
+  //* --- definition of rotation matrix 0 ---  
+  TArrayI &idtmed = *(det->GetIdtmed());
   idrot[0]=0;
   nvol=0;
  L10:
@@ -1456,7 +1475,7 @@ void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
     while(i<20) natmed[i++]=' ';
     natmed[i]='\0';
     //
-    pMC->Gckmat(fIdtmed[itmed+id_det*100-1],natmed);
+    pMC->Gckmat(idtmed[itmed],natmed);
     //*
   } else if (!strcmp(key,"ROTM")) {
     sscanf(&card[4],"%d %f %f %f %f %f %f",&irot,&teta1,&phi1,&teta2,&phi2,&teta3,&phi3);
@@ -1468,7 +1487,7 @@ void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
       for(i=0;i<npar;i++) fscanf(lun,"%f",&par[i]);
       fscanf(lun,"%*c");
     }
-    pMC->Gsvolu( name, shape, fIdtmed[numed+id_det*100-1], par, npar);
+    pMC->Gsvolu( name, shape, idtmed[numed], par, npar);
     //*     save the defined volumes
     strcpy(volst[++nvol],name);
     istop[nvol]=1;
@@ -1479,15 +1498,15 @@ void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
     //*
   } else if (!strcmp(key,"DVN2")) {
     sscanf(&card[5],"'%[^']' '%[^']' %d %d %f %d",name, mother, &ndiv, &iaxe, &orig, &numed);
-    pMC->Gsdvn2( name, mother, ndiv, iaxe, orig,fIdtmed[numed+id_det*100-1]);
+    pMC->Gsdvn2( name, mother, ndiv, iaxe, orig,idtmed[numed]);
     //*
   } else if (!strcmp(key,"DIVT")) {
     sscanf(&card[5],"'%[^']' '%[^']' %f %d %d %d", name, mother, &step, &iaxe, &numed, &ndvmx);
-    pMC->Gsdvt ( name, mother, step, iaxe, fIdtmed[numed+id_det*100-1], ndvmx);
+    pMC->Gsdvt ( name, mother, step, iaxe, idtmed[numed], ndvmx);
     //*
   } else if (!strcmp(key,"DVT2")) {
     sscanf(&card[5],"'%[^']' '%[^']' %f %d %f %d %d", name, mother, &step, &iaxe, &orig, &numed, &ndvmx);
-    pMC->Gsdvt2 ( name, mother, step, iaxe, orig, fIdtmed[numed+id_det*100-1], ndvmx );
+    pMC->Gsdvt2 ( name, mother, step, iaxe, orig, idtmed[numed], ndvmx );
     //*
   } else if (!strcmp(key,"POSI")) {
     sscanf(&card[5],"'%[^']' %d '%[^']' %f %f %f %d '%[^']'", name, &nr, mother, &xo, &yo, &zo, &irot, konly);
@@ -1540,7 +1559,7 @@ void AliRun::ReadEuclid(const char* filnam, Int_t id_det, const char* topvol)
 }
 
 //_____________________________________________________________________________
-void AliRun::ReadEuclidMedia(const char* filnam, Int_t id_det)
+void AliRun::ReadEuclidMedia(const char* filnam, const AliModule *det)
 {
   //                                                                     
   //       read in the materials and tracking media for the detector     
@@ -1561,15 +1580,7 @@ void AliRun::ReadEuclidMedia(const char* filnam, Int_t id_det)
   Int_t imate;
   Int_t nwbuf, isvol, ifield, nmat;
   Float_t a, z, dens, radl, absl, fieldm, tmaxfd, stemax, deemax, epsil, stmin;
-  AliModule* det;
-//
-  TObjArray &dets = *fModules;
-  if(!dets[id_det]) {
-    printf(" *** GREUTMED *** Detector %d not defined\n",id_det);
-    return;
-  } else {
-    det = (AliModule*) dets[id_det];
-  }
+  //
   end=strlen(filnam);
   for(i=0;i<end;i++) if(filnam[i]=='.') {
     end=i;
@@ -1582,13 +1593,14 @@ void AliRun::ReadEuclidMedia(const char* filnam, Int_t id_det)
   lun=fopen(filtmp,"r");
   delete [] filtmp;
   if(!lun) {
-    printf(" *** GREUTMED *** Could not open file %s\n",filnam);
+    Warning("ReadEuclidMedia","Could not open file %s\n",filnam);
     return;
   }
   //
   // Retrieve Mag Field parameters
   Int_t ISXFLD=gAlice->Field()->Integ();
   Float_t SXMGMX=gAlice->Field()->Max();
+  //  TArrayI &idtmed = *(det->GetIdtmed());
   //
  L10:
   for(i=0;i<130;i++) card[i]=0;
@@ -1621,9 +1633,9 @@ void AliRun::ReadEuclidMedia(const char* filnam, Int_t id_det)
     while(i<20) natmed[i++]=' ';
     natmed[i]='\0';
     //
-    det->AliMedium(itmed+id_det*100,natmed,nmat,isvol,ISXFLD,SXMGMX,tmaxfd,
+    det->AliMedium(itmed,natmed,nmat,isvol,ISXFLD,SXMGMX,tmaxfd,
                   stemax,deemax,epsil,stmin,ubuf,nwbuf);
-    (*fImedia)[fIdtmed[itmed+id_det*100-1]-1]=id_det;
+    //    (*fImedia)[idtmed[itmed]-1]=id_det;
     //*
   }
   //*
@@ -1631,12 +1643,12 @@ void AliRun::ReadEuclidMedia(const char* filnam, Int_t id_det)
   fclose (lun);
   //*
   //*     commented out only for the not cernlib version
-  printf(" *** GREUTMED *** file: %s is now read in\n",filnam);
+  Warning("ReadEuclidMedia","file: %s is now read in\n",filnam);
   //*
   return;
   //*
  L20:
-  printf(" *** GREUTMED *** reading error or premature end of file\n");
+  Warning("ReadEuclidMedia","reading error or premature end of file\n");
 } 
  
 //_____________________________________________________________________________
@@ -1662,6 +1674,7 @@ void AliRun::Streamer(TBuffer &R__b)
     R__b >> fTrRmax;
     R__b >> fTrZmax;
     R__b >> fGenerator;
+    R__b >> fPDGDB;        //Particle factory object!
   } else {
     R__b.WriteVersion(AliRun::IsA());
     TNamed::Streamer(R__b);
@@ -1677,6 +1690,7 @@ void AliRun::Streamer(TBuffer &R__b)
     R__b << fTrRmax;
     R__b << fTrZmax;
     R__b << fGenerator;
+    R__b << fPDGDB;        //Particle factory object!
   }
 } 
 
@@ -1704,7 +1718,9 @@ extern "C" void type_of_call  rxgtrak (Int_t &mtrack, Int_t &ipart, Float_t *pmo
   //      tof     Particle time of flight in seconds
   //
   Float_t polar[3];
-  gAlice->GetNextTrack(mtrack, ipart, pmom, e, vpos, polar, tof);
+  Int_t pdg;
+  gAlice->GetNextTrack(mtrack, pdg, pmom, e, vpos, polar, tof);
+  ipart = gMC->IdFromPDG(pdg);
   mtrack++;
 }
 
@@ -1743,7 +1759,8 @@ rxstrak (Int_t &keep, Int_t &parent, Int_t &ipart, Float_t *pmom,
   Float_t polar[3]={0.,0.,0.};
   for(int i=0; i<10 && i<cmlen; i++) mecha[i]=cmech[i];
   mecha[10]=0;
-  gAlice->SetTrack(keep, parent-1, ipart, pmom, vpos, polar, tof, mecha, ntr);
+  Int_t pdg=gMC->PDGFromId(ipart);
+  gAlice->SetTrack(keep, parent-1, pdg, pmom, vpos, polar, tof, mecha, ntr);
   ntr++;
 }
 
@@ -1759,7 +1776,7 @@ extern "C" void type_of_call  rxkeep(const Int_t &n)
       exit(1);
     }
   
-  ((GParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
+  ((TParticle*)(gAlice->Particles()->UncheckedAt(n-1)))->SetBit(Keep_Bit);
 }
 
 //_____________________________________________________________________________