LCOV - code coverage report
Current view: top level - PHOS/PHOSsim - AliPHOSvFast.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 1 180 0.6 %
Date: 2016-06-14 17:26:59 Functions: 1 21 4.8 %

          Line data    Source code
       1             :   /**************************************************************************
       2             :  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
       3             :  *                                                                        *
       4             :  * Author: The ALICE Off-line Project.                                    *
       5             :  * Contributors are mentioned in the code where appropriate.              *
       6             :  *                                                                        *
       7             :  * Permission to use, copy, modify and distribute this software and its   *
       8             :  * documentation strictly for non-commercial purposes is hereby granted   *
       9             :  * without fee, provided that the above copyright notice appears in all   *
      10             :  * copies and that both the copyright notice and this permission notice   *
      11             :  * appear in the supporting documentation. The authors make no claims     *
      12             :  * about the suitability of this software for any purpose. It is          *
      13             :  * provided "as is" without express or implied warranty.                  *
      14             :  **************************************************************************/
      15             : 
      16             : /* $Id$ */
      17             : 
      18             : /* History of cvs commits:
      19             :  *
      20             :  * $Log$
      21             :  * Revision 1.30  2006/09/13 07:31:01  kharlov
      22             :  * Effective C++ corrections (T.Pocheptsov)
      23             :  *
      24             :  * Revision 1.29  2005/05/28 14:19:05  schutz
      25             :  * Compilation warnings fixed by T.P.
      26             :  *
      27             :  */
      28             : 
      29             : //_________________________________________________________________________
      30             : // Implementation of the PHOS manager class for fast simulations     
      31             : // Tracks particles until the reach a grossly designed PHOS module
      32             : // Modify the particles property (momentum, energy, type) according to
      33             : //  the PHOS response function. The result is called a virtual reconstructed
      34             : //  particle.                
      35             : //
      36             : //*-- Author: Yves Schutz (SUBATECH)
      37             : 
      38             : // --- ROOT system ---
      39             :  
      40             : #include <TGeometry.h>
      41             : #include <TParticle.h>
      42             : #include <TDatabasePDG.h>
      43             : #include "TClonesArray.h" 
      44             : #include <TVirtualMC.h>
      45             : 
      46             : // --- Standard library ---
      47             : 
      48             : // --- AliRoot header files ---
      49             : #include "AliPHOSFastRecParticle.h"
      50             : #include "AliPHOSGeometry.h"
      51             : #include "AliPHOSLoader.h"
      52             : #include "AliPHOSvFast.h"
      53             : #include "AliRun.h"
      54             : 
      55          20 : ClassImp(AliPHOSvFast)
      56             : 
      57           0 : AliPHOSvFast::AliPHOSvFast() :
      58           0 :   fBigBoxX(0.),
      59           0 :   fBigBoxY(0.),
      60           0 :   fBigBoxZ(0.),
      61           0 :   fFastRecParticles(0),
      62           0 :   fNRecParticles(0),
      63           0 :   fRan(0),
      64           0 :   fResPara1(0.),
      65           0 :   fResPara2(0.),
      66           0 :   fResPara3(0.),
      67           0 :   fPosParaA0(0.),
      68           0 :   fPosParaA1(0.),
      69           0 :   fPosParaB0(0.),
      70           0 :   fPosParaB1(0.),
      71           0 :   fPosParaB2(0.)    
      72           0 : {
      73             :   // default ctor : initialize data member
      74           0 : }
      75             : 
      76             : //____________________________________________________________________________
      77             : AliPHOSvFast::AliPHOSvFast(const char *name, const char *title):
      78           0 :   AliPHOS(name,title),
      79           0 :   fBigBoxX(0.),
      80           0 :   fBigBoxY(0.),
      81           0 :   fBigBoxZ(0.),
      82           0 :   fFastRecParticles(new AliPHOSFastRecParticle::FastRecParticlesList("AliPHOSFastRecParticle", 100)),
      83           0 :   fNRecParticles(0),
      84           0 :   fRan(0),
      85           0 :   fResPara1(0.030), // GeV
      86           0 :   fResPara2(0.00003),
      87           0 :   fResPara3(0.00001),
      88           0 :   fPosParaA0(2.87),    // mm
      89           0 :   fPosParaA1(-0.0975),
      90           0 :   fPosParaB0(0.257),
      91           0 :   fPosParaB1(0.137),
      92           0 :   fPosParaB2(0.00619)
      93           0 : {
      94             :   // ctor
      95             :   // create the Loader 
      96           0 :   SetBigBox(0, GetGeometry()->GetOuterBoxSize(0) ) ;
      97           0 :   SetBigBox(1, GetGeometry()->GetOuterBoxSize(3) + GetGeometry()->GetCPVBoxSize(1) ) ; 
      98           0 :   SetBigBox(2, GetGeometry()->GetOuterBoxSize(2) ); 
      99           0 : }
     100             : 
     101             : //____________________________________________________________________________
     102             : AliPHOSvFast::~AliPHOSvFast()
     103           0 : {
     104             :   // dtor
     105             :  
     106           0 :   fFastRecParticles->Delete() ; 
     107           0 :   delete fFastRecParticles ;
     108           0 :   fFastRecParticles = 0 ; 
     109             : 
     110           0 : }
     111             : 
     112             : //____________________________________________________________________________
     113             : void AliPHOSvFast::AddRecParticle(const AliPHOSFastRecParticle & rp)
     114             : {  
     115             :   // Add a virtually reconstructed particle to the list 
     116             : 
     117           0 :   new( (*fFastRecParticles)[fNRecParticles] ) AliPHOSFastRecParticle(rp) ;
     118           0 :   fNRecParticles++ ; 
     119           0 : }
     120             : 
     121             : //____________________________________________________________________________
     122             : void AliPHOSvFast::CreateGeometry()
     123             : {
     124             :   // Create the geometry for GEANT
     125             :   
     126           0 :   AliPHOSvFast *phostmp = (AliPHOSvFast*)gAlice->GetModule("PHOS") ;
     127             :   
     128           0 :   if ( phostmp == NULL ) {
     129             :     
     130           0 :     fprintf(stderr, "PHOS detector not found!\n") ;
     131           0 :     return ;
     132             :     
     133             :   }
     134             : 
     135             :   // Get pointer to the array containing media indeces
     136           0 :   Int_t *idtmed = fIdtmed->GetArray() - 699 ;
     137             :   
     138           0 :   Float_t bigbox[3] ; 
     139           0 :   bigbox[0] =   GetBigBox(0) / 2.0 ;
     140           0 :   bigbox[1] =   GetBigBox(1) / 2.0 ;
     141           0 :   bigbox[2] =   GetBigBox(2) / 2.0 ;
     142             :   
     143           0 :   TVirtualMC::GetMC()->Gsvolu("PHOS", "BOX ", idtmed[798], bigbox, 3) ;
     144             :   
     145             :   // --- Position  PHOS mdules in ALICE setup ---
     146             :   
     147           0 :   Int_t idrotm[99] ;
     148           0 :   Double_t const kRADDEG = 180.0 / TMath::Pi() ;
     149             :   
     150           0 :   for( Int_t i = 1; i <= GetGeometry()->GetNModules(); i++ ) {
     151             :     
     152           0 :     Float_t angle = GetGeometry()->GetPHOSAngle(i) ;
     153           0 :     AliMatrix(idrotm[i-1], 90.0, angle, 90.0, 90.0+angle, 0.0, 0.0) ;
     154             :  
     155           0 :     Float_t r = GetGeometry()->GetIPtoCrystalSurface() + GetBigBox(1) / 2.0 ;
     156             : 
     157           0 :     Float_t xP1 = r * TMath::Sin( angle / kRADDEG ) ;
     158           0 :     Float_t yP1 = -r * TMath::Cos( angle / kRADDEG ) ;
     159           0 :     TVirtualMC::GetMC()->Gspos("PHOS", i, "ALIC", xP1, yP1, 0.0, idrotm[i-1], "ONLY") ;
     160             :  
     161             :   } // for GetNModules
     162             : 
     163           0 : }
     164             : 
     165             : 
     166             : //____________________________________________________________________________
     167             : void AliPHOSvFast::Init(void)
     168             : {
     169             :   // Prints out an information message
     170             :   
     171             :   Int_t i;
     172             : 
     173           0 :   printf("\n");
     174           0 :   for(i=0;i<35;i++) printf("*");
     175           0 :   printf(" FAST PHOS_INIT ");
     176           0 :   for(i=0;i<35;i++) printf("*");
     177           0 :   printf("\n");
     178             : 
     179             :   // Here the PHOS initialisation code (if any!)
     180             : 
     181           0 :   for(i=0;i<80;i++) printf("*");
     182           0 :   printf("\n");
     183             :   
     184           0 : }
     185             : 
     186             : //___________________________________________________________________________
     187             : Float_t AliPHOSvFast::GetBigBox(Int_t index) const
     188             : {
     189             :   // Get the X, Y or Z dimension of the box describing a PHOS module
     190             :   
     191             :   Float_t rv = 0 ; 
     192             : 
     193           0 :   switch (index) {
     194             :   case 0:
     195           0 :     rv = fBigBoxX ; 
     196           0 :     break ; 
     197             :   case 1:
     198           0 :      rv = fBigBoxY ; 
     199           0 :     break ; 
     200             :   case 2:
     201           0 :      rv = fBigBoxZ ; 
     202           0 :     break ; 
     203             :  }
     204           0 :   return rv ; 
     205             : }
     206             : //___________________________________________________________________________
     207             : 
     208             : void AliPHOSvFast::MakeBranch(Option_t* opt)
     209             : {  
     210             :   // Create new branch in the current reconstructed Root Tree
     211           0 :   AliDetector::MakeBranch(opt);
     212           0 :   const char *cd = strstr(opt,"R");
     213             :   
     214           0 :   if (fFastRecParticles && fLoader->TreeR() && cd) {
     215           0 :     MakeBranchInTree(fLoader->TreeR(), GetName(), &fFastRecParticles, fBufferSize, 0);
     216           0 :   }
     217           0 : }
     218             : //____________________________________________________________________________
     219             : 
     220             : Double_t AliPHOSvFast::MakeEnergy(Double_t energy)
     221             : {  
     222             :   // Smears the energy according to the energy dependent energy resolution.
     223             :   // A gaussian distribution is assumed
     224             : 
     225           0 :   Double_t sigma  = SigmaE(energy) ; 
     226           0 :   return  fRan.Gaus(energy, sigma) ;   
     227             : }
     228             : //____________________________________________________________________________
     229             : 
     230             : TVector3 AliPHOSvFast::MakePosition(Double_t energy, TVector3 pos, Double_t theta, Double_t phi)
     231             : {
     232             :   // Smears the impact position according to the energy dependent position resolution
     233             :   // A gaussian position distribution is assumed
     234             : 
     235           0 :   TVector3 newpos ;
     236           0 :   Double_t sigma = SigmaP( energy, theta*180./TMath::Pi() ) ;
     237           0 :   Double_t x = fRan.Gaus( pos.X(), sigma ) ;
     238           0 :   sigma = SigmaP( energy, phi*180./TMath::Pi() ) ;
     239           0 :   Double_t z = fRan.Gaus( pos.Z(), sigma ) ;
     240           0 :   Double_t y = pos.Y() ; 
     241             :   
     242           0 :   newpos.SetX(x) ; 
     243           0 :   newpos.SetY(y) ; 
     244           0 :   newpos.SetZ(z) ; 
     245             :               
     246             :   return newpos ; 
     247           0 : }
     248             : 
     249             : //____________________________________________________________________________
     250             : void AliPHOSvFast::MakeRecParticle(Int_t modid, TVector3 pos, AliPHOSFastRecParticle & rp)
     251             : {
     252             :   // Modify the primary particle properties according
     253             :   //  1. the response function of PHOS
     254             :   //  2. the performance of the EMC+PPSD setup
     255             :   
     256           0 :   Int_t type = MakeType( rp ) ;
     257           0 :   rp.SetType(type) ;
     258             : 
     259             :   
     260             :   // get the detected energy
     261             : 
     262           0 :   TLorentzVector momentum ;  
     263           0 :   rp.Momentum(momentum) ; 
     264           0 :   Double_t kineticenergy = TMath::Sqrt( TMath::Power(momentum.E(), 2) - TMath::Power(rp.GetMass(), 2) ) ; 
     265           0 :   Double_t modifiedkineticenergy = MakeEnergy(kineticenergy ) ;
     266           0 :   Double_t modifiedenergy = TMath::Sqrt( TMath::Power(modifiedkineticenergy, 2)  
     267           0 :                                          + TMath::Power( rp.GetMass(), 2) ) ;
     268             :  
     269             :   // get the angle of incidence 
     270             :   
     271           0 :   Double_t incidencetheta = 90. * TMath::Pi() /180 - rp.Theta() ; 
     272           0 :   Double_t incidencephi   = ( 270 + GetGeometry()->GetPHOSAngle(modid) ) * TMath::Pi() / 180. - rp.Phi() ;   
     273             : 
     274             :   // get the detected direction
     275             :   
     276           0 :   TVector3 modifiedposition = MakePosition(kineticenergy, pos, incidencetheta, incidencephi) ; 
     277           0 :   modifiedposition *= modifiedkineticenergy / modifiedposition.Mag() ; 
     278             : 
     279             :   // Set the modified 4-momentum of the reconstructed particle
     280             : 
     281           0 :   rp.SetMomentum(modifiedposition.X(), modifiedposition.Y(), modifiedposition.Z(), modifiedenergy) ; 
     282             : 
     283           0 :  }
     284             : 
     285             : //____________________________________________________________________________
     286             : Int_t AliPHOSvFast::MakeType(AliPHOSFastRecParticle & rp )
     287             : {
     288             :   // Generate a particle type using the performance of the EMC+PPSD setup
     289             : 
     290             :   Int_t rv =   AliPHOSFastRecParticle::kUNDEFINED ;
     291           0 :   Int_t charge = (Int_t)rp.GetPDG()->Charge() ;
     292             :   Int_t test ; 
     293             :   Float_t ran ; 
     294           0 :   if ( charge != 0 && ( TMath::Abs(rp.GetPdgCode()) != 11 ) ) 
     295           0 :     test = - 1 ;
     296             :   else
     297           0 :     test = rp.GetPdgCode() ; 
     298             : 
     299           0 :   Fatal("MakeType", "SHOULD NOT BE USED until values of probabilities are properly set ") ;
     300             :    // NB: ALL VALUES SHOULD BE CHECKED !!!!
     301           0 :   switch (test) { 
     302             : 
     303             :   case 22:    // it's a photon              // NB: ALL VALUES SHOLD BE CHECKED !!!!
     304           0 :     ran = fRan.Rndm() ; 
     305           0 :     if( ran <= 0.9498 )
     306           0 :       rv =  AliPHOSFastRecParticle::kNEUTRALHAFAST ; 
     307             :     else
     308             :       rv =  AliPHOSFastRecParticle::kNEUTRALEMFAST ;     
     309             :     break ; 
     310             : 
     311             :   case 2112:  // it's a neutron
     312           0 :     ran = fRan.Rndm() ; 
     313           0 :     if ( ran <= 0.9998 )
     314           0 :       rv =  AliPHOSFastRecParticle::kNEUTRALHASLOW ; 
     315             :     else 
     316             :       rv = AliPHOSFastRecParticle::kNEUTRALEMSLOW ; 
     317             :     break ; 
     318             :     
     319             :   case -2112: // it's a anti-neutron
     320           0 :     ran = fRan.Rndm() ; 
     321           0 :     if ( ran <= 0.9984 )
     322           0 :       rv =  AliPHOSFastRecParticle::kNEUTRALHASLOW ; 
     323             :     else 
     324             :       rv =  AliPHOSFastRecParticle::kNEUTRALEMSLOW ; 
     325             :     break ; 
     326             :     
     327             :   case 11:    // it's a electron
     328           0 :     ran = fRan.Rndm() ; 
     329           0 :     if ( ran <= 0.9996 )
     330           0 :       rv =  AliPHOSFastRecParticle::kCHARGEDEMFAST ; 
     331             :     else 
     332             :       rv =  AliPHOSFastRecParticle::kCHARGEDHAFAST ; 
     333             :     break; 
     334             : 
     335             :   case -11:   // it's a positon
     336           0 :     ran = fRan.Rndm() ; 
     337           0 :     if ( ran <= 0.9996 )
     338           0 :       rv =  AliPHOSFastRecParticle::kCHARGEDEMFAST ; 
     339             :     else 
     340             :       rv =  AliPHOSFastRecParticle::kCHARGEDHAFAST ; 
     341             :     break; 
     342             : 
     343             :   case -1:    // it's a charged
     344           0 :     ran = fRan.Rndm() ; 
     345           0 :     if ( ran <= 0.9996 )
     346           0 :       rv =  AliPHOSFastRecParticle::kCHARGEDHAFAST ; 
     347             :     else 
     348             :       rv =  AliPHOSFastRecParticle::kNEUTRALHAFAST ; 
     349             : 
     350             :     break ; 
     351             :   }
     352             :     
     353             :   
     354           0 :   return rv ;
     355             : }
     356             : 
     357             : //___________________________________________________________________________
     358             : void AliPHOSvFast::ResetPoints()
     359             : {
     360             :   // This overloads the method in AliDetector
     361             :   
     362           0 :   ResetFastRecParticles() ; 
     363           0 : }
     364             : 
     365             : //___________________________________________________________________________
     366             : void AliPHOSvFast::ResetFastRecParticles()
     367             : {
     368             :   // Resets the list of virtual reconstructed particles
     369             :  
     370           0 :   if (fFastRecParticles) 
     371           0 :     fFastRecParticles->Clear() ;
     372           0 :   fNRecParticles = 0 ; 
     373           0 : }
     374             : 
     375             : //___________________________________________________________________________
     376             : void AliPHOSvFast::SetBigBox(Int_t index, Float_t value)
     377             : {
     378             :   // Set the size of the Box describing a PHOS module
     379             :   
     380           0 :   switch (index) {
     381             :   case 0:
     382           0 :     fBigBoxX = value ; 
     383           0 :     break ; 
     384             :   case 1:
     385           0 :     fBigBoxY = value ; 
     386           0 :     break ; 
     387             :   case 2:
     388           0 :     fBigBoxZ = value ; 
     389           0 :     break ; 
     390             :  }
     391             : 
     392           0 : }
     393             : 
     394             : //____________________________________________________________________________
     395             : Double_t AliPHOSvFast::SigmaE(Double_t energy)
     396             : {
     397             :   // Calculates the energy dependent energy resolution
     398             :   
     399             :   Double_t rv = -1 ; 
     400             :   
     401           0 :   rv = TMath::Sqrt( TMath::Power(fResPara1/energy, 2) 
     402           0 :                + TMath::Power(fResPara2/TMath::Sqrt(energy), 2) 
     403           0 :                + TMath::Power(fResPara3, 2) ) ;  
     404             : 
     405           0 :   return rv * energy ; 
     406             : }
     407             : 
     408             : //____________________________________________________________________________
     409             : Double_t AliPHOSvFast::SigmaP(Double_t energy, Double_t incidence)
     410             : {
     411             :   // Calculates the energy dependent position resolution 
     412             : 
     413           0 :   Double_t paraA = fPosParaA0 + fPosParaA1 * incidence ; 
     414           0 :   Double_t paraB = fPosParaB0 + fPosParaB1 * incidence + fPosParaB2 * incidence * incidence ; 
     415             : 
     416           0 :   return ( paraA / TMath::Sqrt(energy) + paraB ) * 0.1   ; // in cm  
     417             : }
     418             : 
     419             : //____________________________________________________________________________
     420             : void AliPHOSvFast::StepManager(void)
     421             : {
     422             :   // Only verifies if the particle reaches PHOS and stops the tracking 
     423             : 
     424           0 :   TLorentzVector lv ; 
     425           0 :   TVirtualMC::GetMC()->TrackPosition(lv) ;
     426           0 :   TVector3 pos = lv.Vect() ; 
     427           0 :   Int_t modid  ; 
     428           0 :   TVirtualMC::GetMC()->CurrentVolID(modid);
     429             :   
     430           0 :   Float_t energy = TVirtualMC::GetMC()->Etot() ; //Total energy of current track
     431             : 
     432             :   //Calculating mass of current particle
     433           0 :   TDatabasePDG * pdg = TDatabasePDG::Instance() ;
     434           0 :   TParticlePDG * partPDG = pdg->GetParticle(TVirtualMC::GetMC()->TrackPid()) ;
     435           0 :   Float_t mass = partPDG->Mass() ;
     436             : 
     437           0 :   if(energy > mass){
     438           0 :     pos.SetMag(TMath::Sqrt(energy*energy-mass*mass)) ;
     439           0 :     TLorentzVector pTrack(pos, energy) ;  
     440             : 
     441           0 :     TParticle * part = new TParticle(TVirtualMC::GetMC()->TrackPid(), 0,-1,-1,-1,-1, pTrack, lv)  ;
     442             :         
     443           0 :     AliPHOSFastRecParticle rp(*part) ;
     444             : 
     445             :     // Adds the response of PHOS to the particle
     446           0 :     MakeRecParticle(modid, pos, rp) ;
     447             :     
     448             :     // add the `track' particle to the FastRecParticles list
     449             :   
     450           0 :     AddRecParticle(rp) ;
     451             : 
     452           0 :     part->Delete() ;
     453           0 :   }
     454             :   // stop the track as soon PHOS is reached
     455             :   
     456           0 :   TVirtualMC::GetMC()->StopTrack() ; 
     457             : 
     458           0 : }
     459             : 

Generated by: LCOV version 1.11