]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PHOS/AliPHOSvFast.cxx
Added Copy method
[u/mrichter/AliRoot.git] / PHOS / AliPHOSvFast.cxx
index ea753fe481ac95b2e70f3c1a7cc71c6b80f0beb4..895e4cab0f556090ddfe18c30e219465f07c87f1 100644 (file)
@@ -1,4 +1,4 @@
-/**************************************************************************
+  /**************************************************************************
  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
  *                                                                        *
  * Author: The ALICE Off-line Project.                                    *
 //*-- Author: Yves Schutz (SUBATECH)
 
 // --- ROOT system ---
-
-#include "TBRIK.h"
-#include "TNode.h"
-#include "TParticle.h"
+#include <TBRIK.h>
+#include <TGeometry.h>
+#include <TNode.h>
+#include <TParticle.h>
+#include "TClonesArray.h" 
+#include <TVirtualMC.h>
 
 // --- Standard library ---
 
-#include <stdio.h>
-
 // --- AliRoot header files ---
-
+#include "AliPHOSFastRecParticle.h"
+#include "AliPHOSGeometry.h"
+#include "AliPHOSLoader.h"
 #include "AliPHOSvFast.h"
 #include "AliRun.h"
-#include "AliConst.h"
 
 ClassImp(AliPHOSvFast)
 
 //____________________________________________________________________________
-AliPHOSvFast::AliPHOSvFast()
+AliPHOSvFast::AliPHOSvFast() : AliPHOS()
 {
-  // ctor
+  // default ctor : initialize data member
+   fBigBoxX = 0. ;                      
+   fBigBoxY = 0. ;                      
+   fBigBoxZ = 0. ;                       
+   fFastRecParticles = 0 ;        
+   fNRecParticles = 0 ;                
+   fRan = 0 ;                            
+   fResPara1 = 0. ;                       
+   fResPara2 = 0. ;                        
+   fResPara3 = 0. ;                      
+   fPosParaA0 = 0. ;                      
+   fPosParaA1 = 0. ;
+   fPosParaB0 = 0. ;     
+   fPosParaB1 = 0. ;    
+   fPosParaB2 = 0. ;    
 
-  fFastRecParticles = 0 ; 
-  fNRecParticles = 0 ; 
 }
 
 //____________________________________________________________________________
@@ -57,26 +71,20 @@ AliPHOSvFast::AliPHOSvFast(const char *name, const char *title):
 {
   // ctor
 
-  // gets an instance of the geometry parameters class  
-   
-  fGeom =  AliPHOSGeometry::GetInstance(title, "") ; 
-
-  if (fGeom->IsInitialized() ) 
-    cout << "AliPHOSvFast : PHOS geometry intialized for " << fGeom->GetName() << endl ;
-  else
-    cout << "AliPHOSvFast : PHOS geometry initialization failed !" << endl ;   
   
-  SetBigBox(0, fGeom->GetOuterBoxSize(0) ) ;
-  SetBigBox(1, fGeom->GetOuterBoxSize(1) + fGeom->GetPPSDBoxSize(1) ) ; 
-  SetBigBox(2, fGeom->GetOuterBoxSize(0) ); 
-
+  // create the Loader 
+  
+  SetBigBox(0, GetGeometry()->GetOuterBoxSize(0) ) ;
+  SetBigBox(1, GetGeometry()->GetOuterBoxSize(3) + GetGeometry()->GetCPVBoxSize(1) ) ; 
+  SetBigBox(2, GetGeometry()->GetOuterBoxSize(2) ); 
+  
   fNRecParticles = 0 ; 
-  fFastRecParticles = new FastRecParticlesList("AliPHOSFastRecParticle", 100) ;
-
+  fFastRecParticles = new AliPHOSFastRecParticle::FastRecParticlesList("AliPHOSFastRecParticle", 100) ;
+  
   fResPara1 = 0.030 ;    // GeV
   fResPara2 = 0.00003 ; 
   fResPara3 = 0.00001 ; 
-
+  
   fPosParaA0 = 2.87 ;    // mm
   fPosParaA1 = -0.0975 ;  
   fPosParaB0 = 0.257 ;   
@@ -95,6 +103,29 @@ AliPHOSvFast::~AliPHOSvFast()
 
 }
 
+//____________________________________________________________________________
+void AliPHOSvFast::Copy(AliPHOSvFast & fast)
+{
+  TObject::Copy(fast) ; 
+  AliPHOS::Copy(fast) ; 
+  fast.fBigBoxX = fBigBoxX ; 
+  fast.fBigBoxY = fBigBoxY ; 
+  fast.fBigBoxZ = fBigBoxZ ;
+  fast.fNRecParticles = fNRecParticles ;
+  fast.fRan = fRan ; 
+  fast.fResPara1 = fResPara1 ; 
+  fast.fResPara2 = fResPara2 ; 
+  fast.fResPara3 = fResPara3 ;
+  fast.fPosParaA0 = fPosParaA0 ;
+  fast.fPosParaA1 = fPosParaA1 ; 
+  fast.fPosParaB0 = fPosParaB0 ;
+  fast.fPosParaB1 = fPosParaB1 ;
+  fast.fFastRecParticles = new TClonesArray(fFastRecParticles->GetClass()->GetName(), 100) ; 
+  Int_t index ; 
+  for (index = 0 ; index < fFastRecParticles->GetEntries(); index++) 
+    (fast.fFastRecParticles)->AddAt(fFastRecParticles->At(index), index) ;
+}
+
 //____________________________________________________________________________
 void AliPHOSvFast::AddRecParticle(const AliPHOSFastRecParticle & rp)
 {  
@@ -128,7 +159,7 @@ void AliPHOSvFast::BuildGeometry()
  
   const Int_t kColorPHOS = kRed ;
   
-  Double_t const kRADDEG = 180.0 / kPI ;
+  Double_t const kRADDEG = 180.0 / TMath::Pi() ;
   
   new TBRIK( "BigBox", "PHOS box", "void", GetBigBox(0)/2, 
             GetBigBox(1)/2, 
@@ -136,17 +167,17 @@ void AliPHOSvFast::BuildGeometry()
   
   // position PHOS into ALICE
 
-  Float_t r = fGeom->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
+  Float_t r = GetGeometry()->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
   Int_t number = 988 ; 
-  Float_t pphi =  TMath::ATan( GetBigBox(0)  / ( 2.0 * fGeom->GetIPtoCrystalSurface() ) ) ;
+  Float_t pphi =  TMath::ATan( GetBigBox(0)  / ( 2.0 * GetGeometry()->GetIPtoCrystalSurface() ) ) ;
   pphi *= kRADDEG ;
   TNode * top = gAlice->GetGeometry()->GetNode("alice") ;
  
   char * nodename = new char[20] ;  
   char * rotname  = new char[20] ; 
 
-  for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) { 
-   Float_t angle = pphi * 2 * ( i - fGeom->GetNModules() / 2.0 - 0.5 ) ;
+  for( Int_t i = 1; i <= GetGeometry()->GetNModules(); i++ ) { 
+   Float_t angle = pphi * 2 * ( i - GetGeometry()->GetNModules() / 2.0 - 0.5 ) ;
    sprintf(rotname, "%s%d", "rot", number++) ;
    new TRotMatrix(rotname, rotname, 90, angle, 90, 90 + angle, 0, 0);
    top->cd();
@@ -188,14 +219,14 @@ void AliPHOSvFast::CreateGeometry()
   // --- Position  PHOS mdules in ALICE setup ---
   
   Int_t idrotm[99] ;
-  Double_t const kRADDEG = 180.0 / kPI ;
+  Double_t const kRADDEG = 180.0 / TMath::Pi() ;
   
-  for( Int_t i = 1; i <= fGeom->GetNModules(); i++ ) {
+  for( Int_t i = 1; i <= GetGeometry()->GetNModules(); i++ ) {
     
-    Float_t angle = fGeom->GetPHOSAngle(i) ;
+    Float_t angle = GetGeometry()->GetPHOSAngle(i) ;
     AliMatrix(idrotm[i-1], 90.0, angle, 90.0, 90.0+angle, 0.0, 0.0) ;
  
-    Float_t r = fGeom->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
+    Float_t r = GetGeometry()->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
 
     Float_t xP1 = r * TMath::Sin( angle / kRADDEG ) ;
     Float_t yP1 = -r * TMath::Cos( angle / kRADDEG ) ;
@@ -227,7 +258,7 @@ void AliPHOSvFast::Init(void)
 }
 
 //___________________________________________________________________________
-Float_t AliPHOSvFast::GetBigBox(Int_t index)
+Float_t AliPHOSvFast::GetBigBox(Int_t index) const
 {
   // Get the X, Y or Z dimension of the box describing a PHOS module
   
@@ -246,24 +277,20 @@ Float_t AliPHOSvFast::GetBigBox(Int_t index)
  }
   return rv ; 
 }
-
 //___________________________________________________________________________
+
 void AliPHOSvFast::MakeBranch(Option_t* opt)
 {  
   // Create new branch in the current reconstructed Root Tree
-  AliDetector::MakeBranch(opt) ;
+  AliDetector::MakeBranch(opt);
+  const char *cd = strstr(opt,"R");
   
-  char branchname[10];
-  sprintf(branchname,"%s",GetName());
-  char *cd = strstr(opt,"R");
-  
-  if (fFastRecParticles && gAlice->TreeR() && cd) {
-    gAlice->TreeR()->Branch(branchname, &fFastRecParticles, fBufferSize);
+  if (fFastRecParticles && fLoader->TreeR() && cd) {
+    MakeBranchInTree(fLoader->TreeR(), GetName(), &fFastRecParticles, fBufferSize, 0);
   }
 }
-
 //____________________________________________________________________________
+
 Double_t AliPHOSvFast::MakeEnergy(const Double_t energy)
 {  
   // Smears the energy according to the energy dependent energy resolution.
@@ -272,8 +299,8 @@ Double_t AliPHOSvFast::MakeEnergy(const Double_t energy)
   Double_t sigma  = SigmaE(energy) ; 
   return  fRan.Gaus(energy, sigma) ;   
 }
-
 //____________________________________________________________________________
+
 TVector3 AliPHOSvFast::MakePosition(const Double_t energy, const TVector3 pos, const Double_t theta, const Double_t phi)
 {
   // Smears the impact position according to the energy dependent position resolution
@@ -316,7 +343,7 @@ void AliPHOSvFast::MakeRecParticle(const Int_t modid, const TVector3 pos, AliPHO
   // get the angle of incidence 
   
   Double_t incidencetheta = 90. * TMath::Pi() /180 - rp.Theta() ; 
-  Double_t incidencephi   = ( 270 + fGeom->GetPHOSAngle(modid) ) * TMath::Pi() / 180. - rp.Phi() ;   
+  Double_t incidencephi   = ( 270 + GetGeometry()->GetPHOSAngle(modid) ) * TMath::Pi() / 180. - rp.Phi() ;   
 
   // get the detected direction
   
@@ -334,7 +361,7 @@ Int_t AliPHOSvFast::MakeType(AliPHOSFastRecParticle & rp )
 {
   // Generate a particle type using the performance of the EMC+PPSD setup
 
-  Int_t rv =  kUNDEFINED ;
+  Int_t rv =   AliPHOSFastRecParticle::kUNDEFINED ;
   Int_t charge = (Int_t)rp.GetPDG()->Charge() ;
   Int_t test ; 
   Float_t ran ; 
@@ -343,59 +370,56 @@ Int_t AliPHOSvFast::MakeType(AliPHOSFastRecParticle & rp )
   else
     test = rp.GetPdgCode() ; 
 
+  Fatal("MakeType", "SHOULD NOT BE USED until values of probabilities are properly set ") ;
+   // NB: ALL VALUES SHOULD BE CHECKED !!!!
   switch (test) { 
 
-  case 22:    // it's a photon
+  case 22:    // it's a photon              // NB: ALL VALUES SHOLD BE CHECKED !!!!
     ran = fRan.Rndm() ; 
-    if ( ran <= 0.5 )  // 50 % 
-      rv = kGAMMA ; 
-    else {
-      ran = fRan.Rndm() ; 
-      if( ran <= 0.9498 )
-       rv = kNEUTRAL_EM ; 
-      else
-       rv = kNEUTRAL_HA ; 
-    }     
+    if( ran <= 0.9498 )
+      rv =  AliPHOSFastRecParticle::kNEUTRALHAFAST ; 
+    else
+      rv =  AliPHOSFastRecParticle::kNEUTRALEMFAST ;     
     break ; 
 
   case 2112:  // it's a neutron
     ran = fRan.Rndm() ; 
     if ( ran <= 0.9998 )
-      rv = kNEUTRAL_HA ; 
+      rv =  AliPHOSFastRecParticle::kNEUTRALHASLOW ; 
     else 
-      rv = kNEUTRAL_EM ; 
+      rv = AliPHOSFastRecParticle::kNEUTRALEMSLOW ; 
     break ; 
-
+    
   case -2112: // it's a anti-neutron
     ran = fRan.Rndm() ; 
     if ( ran <= 0.9984 )
-      rv = kNEUTRAL_HA ; 
+      rv =  AliPHOSFastRecParticle::kNEUTRALHASLOW ; 
     else 
-      rv = kNEUTRAL_EM ; 
+      rv =  AliPHOSFastRecParticle::kNEUTRALEMSLOW ; 
     break ; 
     
   case 11:    // it's a electron
     ran = fRan.Rndm() ; 
     if ( ran <= 0.9996 )
-      rv = kELECTRON ; 
+      rv =  AliPHOSFastRecParticle::kCHARGEDEMFAST ; 
     else 
-      rv = kCHARGED_HA ; 
+      rv =  AliPHOSFastRecParticle::kCHARGEDHAFAST ; 
     break; 
 
   case -11:   // it's a positon
     ran = fRan.Rndm() ; 
     if ( ran <= 0.9996 )
-      rv = kELECTRON ; 
+      rv =  AliPHOSFastRecParticle::kCHARGEDEMFAST ; 
     else 
-      rv = kCHARGED_HA ; 
+      rv =  AliPHOSFastRecParticle::kCHARGEDHAFAST ; 
     break; 
 
   case -1:    // it's a charged
     ran = fRan.Rndm() ; 
     if ( ran <= 0.9996 )
-      rv = kCHARGED_HA ; 
+      rv =  AliPHOSFastRecParticle::kCHARGEDHAFAST ; 
     else 
-      rv = kGAMMA ; 
+      rv =  AliPHOSFastRecParticle::kNEUTRALHAFAST ; 
 
     break ; 
   }
@@ -456,7 +480,7 @@ Double_t AliPHOSvFast::SigmaE(Double_t energy)
 }
 
 //____________________________________________________________________________
-Double_t AliPHOSvFast::SigmaP(Double_t energy, Int_t incidence)
+Double_t AliPHOSvFast::SigmaP(Double_t energy, Double_t incidence)
 {
   // Calculates the energy dependent position resolution 
 
@@ -470,30 +494,37 @@ Double_t AliPHOSvFast::SigmaP(Double_t energy, Int_t incidence)
 void AliPHOSvFast::StepManager(void)
 {
   // Only verifies if the particle reaches PHOS and stops the tracking 
-  
-  Int_t primary =  gAlice->GetPrimary( gAlice->CurrentTrack() ); 
+
   TLorentzVector lv ; 
   gMC->TrackPosition(lv) ;
   TVector3 pos = lv.Vect() ; 
   Int_t modid  ; 
   gMC->CurrentVolID(modid);
   
-  // Makes a reconstructed particle from the primary particle
+  Float_t energy = gMC->Etot() ; //Total energy of current track
 
-  TClonesArray * particlelist = gAlice->Particles() ;
-  TParticle * part = (TParticle *)particlelist->At(primary) ;  
+  //Calculating mass of current particle
+  TDatabasePDG * pdg = TDatabasePDG::Instance() ;
+  TParticlePDG * partPDG = pdg->GetParticle(gMC->TrackPid()) ;
+  Float_t mass = partPDG->Mass() ;
 
-  AliPHOSFastRecParticle rp(*part) ;
-  rp.SetPrimary(primary) ; 
+  if(energy > mass){
+    pos.SetMag(TMath::Sqrt(energy*energy-mass*mass)) ;
+    TLorentzVector pTrack(pos, energy) ;  
 
-  // Adds the response of PHOS to the particle
+    TParticle * part = new TParticle(gMC->TrackPid(), 0,-1,-1,-1,-1, pTrack, lv)  ;
+        
+    AliPHOSFastRecParticle rp(*part) ;
 
-  MakeRecParticle(modid, pos, rp) ;
-  
-  // add the primary particle to the FastRecParticles list
+    // Adds the response of PHOS to the particle
+    MakeRecParticle(modid, pos, rp) ;
+    
+    // add the `track' particle to the FastRecParticles list
   
-  AddRecParticle(rp) ;
+    AddRecParticle(rp) ;
 
+    part->Delete() ;
+  }
   // stop the track as soon PHOS is reached
   
   gMC->StopTrack() ;