LCOV - code coverage report
Current view: top level - PHOS/PHOSbase - AliPHOSDigit.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 97 205 47.3 %
Date: 2016-06-14 17:26:59 Functions: 15 24 62.5 %

          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.39  2006/04/22 15:04:24  hristov
      22             :  * Effective C++ initialization of data members in the default constructor
      23             :  *
      24             :  * Revision 1.38  2006/04/22 10:30:17  hristov
      25             :  * Add fEnergy to AliPHOSDigit and operate with EMC amplitude in energy units (Yu.Kharlov)
      26             :  *
      27             :  * Revision 1.37  2005/05/28 14:19:04  schutz
      28             :  * Compilation warnings fixed by T.P.
      29             :  *
      30             :  */
      31             : 
      32             : //_________________________________________________________________________
      33             : //  PHOS digit: Id
      34             : //              energy
      35             : //              3 identifiers for the primary particle(s) at the origine of the digit
      36             : //  The digits are made in FinishEvent() by summing all the hits in a single PHOS crystal or PPSD gas cell
      37             : //
      38             : //*-- Author: Laurent Aphecetche & Yves Schutz (SUBATECH) & Dmitri Peressounko (RRC KI & SUBATECH)
      39             : 
      40             : 
      41             : // --- ROOT system ---
      42             : 
      43             : #include "TMath.h"
      44             : 
      45             : // --- Standard library ---
      46             : 
      47             : // --- AliRoot header files ---
      48             : 
      49             : #include "AliPHOSDigit.h"
      50             : #include "AliLog.h"
      51             : 
      52             : 
      53             : 
      54          22 : ClassImp(AliPHOSDigit)
      55             : 
      56             : //____________________________________________________________________________
      57             : AliPHOSDigit::AliPHOSDigit() :
      58         637 :   AliDigitNew(),
      59         637 :   fIsLG(0),
      60         637 :   fNprimary(0),  
      61         637 :   fPrimary(0x0),
      62         637 :   fEnergy(0.),
      63         637 :   fTime(0.),
      64         637 :   fTimeR(0.),
      65         637 :   fNSamplesHG(0),
      66         637 :   fNSamplesLG(0),
      67         637 :   fSamplesHG(0),
      68         637 :   fSamplesLG(0)
      69        3185 : {
      70             :   // default ctor 
      71        1274 : }
      72             : 
      73             : //____________________________________________________________________________
      74           0 : AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Int_t digEnergy, Float_t time, Int_t index) :
      75           0 :   fIsLG(0),
      76           0 :   fNprimary(0),
      77           0 :   fPrimary(0),
      78           0 :   fEnergy(0.f),
      79           0 :   fTime(0.f),
      80           0 :   fTimeR(0.f),
      81           0 :   fNSamplesHG(0),
      82           0 :   fNSamplesLG(0),
      83           0 :   fSamplesHG(0),
      84           0 :   fSamplesLG(0)
      85           0 : {  
      86             :   // ctor with all data 
      87             : 
      88           0 :   fAmp         = digEnergy ;
      89           0 :   fEnergy      = 0 ;
      90           0 :   fTime        = time ;
      91           0 :   fTimeR       = fTime ;
      92           0 :   fId          = id ;
      93           0 :   fIndexInList = index ; 
      94             : 
      95           0 :   if( primary != -1){
      96           0 :     fNprimary    = 1 ; 
      97           0 :     fPrimary = new Int_t[fNprimary] ;
      98           0 :     fPrimary[0]  = primary ;
      99           0 :   }
     100             :   else{  //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
     101           0 :     fNprimary = 0 ; 
     102           0 :     fPrimary  = 0 ;
     103             :   }
     104           0 : }
     105             : 
     106             : //____________________________________________________________________________
     107       43500 : AliPHOSDigit::AliPHOSDigit(Int_t primary, Int_t id, Float_t energy, Float_t time, Int_t index) :
     108       43500 :   fIsLG(0),
     109       43500 :   fNprimary(0),
     110       43500 :   fPrimary(0),
     111       43500 :   fEnergy(0.f),
     112       43500 :   fTime(0.f),
     113       43500 :   fTimeR(0.f),
     114       43500 :   fNSamplesHG(0),
     115       43500 :   fNSamplesLG(0),
     116       43500 :   fSamplesHG(0),
     117       43500 :   fSamplesLG(0)
     118      217500 : {  
     119             :   // ctor with all data 
     120             : 
     121       43500 :   fAmp         = 0 ;
     122       43500 :   fEnergy      = energy ;
     123       43500 :   fTime        = time ;
     124       43500 :   fTimeR       = fTime ;
     125       43500 :   fId          = id ;
     126       43500 :   fIndexInList = index ; 
     127       43500 :   if( primary != -1){
     128         109 :     fNprimary    = 1 ; 
     129         218 :     fPrimary = new Int_t[fNprimary] ;
     130         109 :     fPrimary[0]  = primary ;
     131         109 :   }
     132             :   else{  //If the contribution of this primary smaller than fDigitThreshold (AliPHOSv1)
     133       43391 :     fNprimary = 0 ; 
     134       43391 :     fPrimary  = 0 ;
     135             :   }
     136       87000 : }
     137             : 
     138             : //____________________________________________________________________________
     139             : AliPHOSDigit::AliPHOSDigit(const AliPHOSDigit & digit) : 
     140           0 :   AliDigitNew(digit),
     141           0 :   fIsLG(digit.fIsLG),
     142           0 :   fNprimary(digit.fNprimary),
     143           0 :   fPrimary(0),
     144           0 :   fEnergy(digit.fEnergy),
     145           0 :   fTime(digit.fTime),
     146           0 :   fTimeR(digit.fTimeR),
     147           0 :   fNSamplesHG(0),
     148           0 :   fNSamplesLG(0),
     149           0 :   fSamplesHG(0),
     150           0 :   fSamplesLG(0)
     151           0 : {
     152             :   // copy ctor
     153           0 :   if(fNprimary){
     154           0 :     fPrimary = new Int_t[fNprimary] ;
     155           0 :     for (Int_t i = 0; i < fNprimary ; i++)
     156           0 :        fPrimary[i]  = digit.fPrimary[i] ;
     157           0 :   }
     158             :   else
     159           0 :     fPrimary = 0 ;
     160           0 :   fAmp         = digit.fAmp ;
     161           0 :   fId          = digit.fId;
     162           0 :   fIndexInList = digit.fIndexInList ; 
     163           0 : }
     164             : 
     165             : //____________________________________________________________________________
     166             : AliPHOSDigit & AliPHOSDigit::operator = (const AliPHOSDigit &)
     167             : {
     168           0 :   Fatal("operator =", "not implemented");
     169           0 :   return *this;
     170             : }
     171             : //____________________________________________________________________________
     172             : AliPHOSDigit::~AliPHOSDigit() 
     173      262548 : {
     174             :   // Delete array of primaries if any
     175       44384 :   if (fPrimary)   delete [] fPrimary  ;
     176             :   // Delete arrays of ALTRO samples if any
     177       44402 :   if (fSamplesHG) delete [] fSamplesHG;
     178       44144 :   if (fSamplesLG) delete [] fSamplesLG;
     179      131274 : }
     180             : 
     181             : //____________________________________________________________________________
     182             : void AliPHOSDigit::Clear(const Option_t*) 
     183             : {
     184             :   // Delete array of primaries if any
     185        1612 :   delete[] fSamplesHG; fSamplesHG = NULL ;
     186        1021 :   delete[] fSamplesLG; fSamplesLG = NULL ;
     187         964 :   delete[] fPrimary;   fPrimary   = NULL ;
     188             : 
     189         403 : }
     190             : 
     191             : //____________________________________________________________________________
     192             : Int_t AliPHOSDigit::Compare(const TObject * obj) const
     193             : {
     194             :   // Compares two digits with respect to its Id
     195             :   // to sort according increasing Id
     196             : 
     197             :   Int_t rv ;
     198             : 
     199       15296 :   AliPHOSDigit * digit = (AliPHOSDigit *)obj ; 
     200             : 
     201        7648 :   Int_t iddiff = fId - digit->GetId() ; 
     202             : 
     203        7648 :   if ( iddiff > 0 ) 
     204        5699 :     rv = 1 ;
     205        1949 :   else if ( iddiff < 0 )
     206        1949 :     rv = -1 ; 
     207             :   else
     208             :     rv = 0 ;
     209             :   
     210        7648 :   return rv ; 
     211             : 
     212             : }
     213             : 
     214             : //____________________________________________________________________________
     215             : Int_t AliPHOSDigit::GetPrimary(Int_t index) const
     216             : {
     217             :   // retrieves the primary particle number given its index in the list 
     218             :   Int_t rv = -1 ;
     219         582 :   if ( index <= fNprimary && index > 0){
     220         177 :     rv = fPrimary[index-1] ;
     221         177 :   } 
     222             : 
     223         291 :   return rv ; 
     224             :   
     225             : }
     226             : 
     227             : //____________________________________________________________________________
     228             : void AliPHOSDigit::SetALTROSamplesHG(Int_t nSamplesHG, Int_t *samplesHG)
     229             : {
     230         464 :   fNSamplesHG = nSamplesHG;
     231         232 :   if (fSamplesHG) delete [] fSamplesHG;
     232         232 :   fSamplesHG = new UShort_t[fNSamplesHG];
     233             :   UShort_t i;
     234       39182 :   for (i=0; i<fNSamplesHG; i++) {
     235       19359 :     fSamplesHG[i] = samplesHG[i];
     236             :   }
     237         232 : }
     238             : //____________________________________________________________________________
     239             : void AliPHOSDigit::SetALTROSamplesLG(Int_t nSamplesLG, Int_t *samplesLG)
     240             : {
     241         286 :   fNSamplesLG = nSamplesLG;
     242         143 :   if (fSamplesLG) delete [] fSamplesLG;
     243         143 :   fSamplesLG = new UShort_t[fNSamplesLG];
     244             :   UShort_t i;
     245       27652 :   for (i=0; i<fNSamplesLG; i++) {
     246       13683 :     fSamplesLG[i] = samplesLG[i];
     247             :   }
     248         143 : }
     249             : //____________________________________________________________________________
     250             : void AliPHOSDigit::Print(const Option_t *) const
     251             : {
     252             :   // Print the digit together with list of primaries
     253           0 :   TString line = Form("PHOS digit: E=%.3f, Id=%d, Time=%.3e, TimeR=%.3e, NPrim=%d, nHG=%d, nLG=%d \n",
     254           0 :                       fEnergy,fId,fTime,fTimeR,fNprimary,fNSamplesHG,fNSamplesLG);
     255           0 :   line += "\tList of primaries: ";
     256           0 :   for (Int_t index = 0; index <fNprimary; index ++ )
     257           0 :     line += Form(" %d ",fPrimary[index]); 
     258           0 :   line += "\n";
     259           0 :   line += "\tSamples HG: ";
     260           0 :   for (Int_t i = 0; i <fNSamplesHG; i++)
     261           0 :     line += Form(" %d ",fSamplesHG[i]); 
     262           0 :   line += "\n";
     263           0 :   line += "\tSamples LG: ";
     264           0 :   for (Int_t i = 0; i <fNSamplesLG; i++)
     265           0 :     line += Form(" %d ",fSamplesLG[i]); 
     266           0 :   line += "\n";
     267           0 :   AliDebug(2,line);
     268           0 : }
     269             : //____________________________________________________________________________
     270             : void AliPHOSDigit::ShiftPrimary(Int_t shift)
     271             : {
     272             :   //shifts primary number to BIG offset, to separate primary in different TreeK
     273        1313 :   for(Int_t index = 0; index <fNprimary; index ++ ){
     274         109 :     fPrimary[index]+= shift ;
     275             :   } 
     276         365 : }
     277             : //____________________________________________________________________________
     278             : Bool_t AliPHOSDigit::operator==(AliPHOSDigit const & digit) const 
     279             : {
     280             :   // Two digits are equal if they have the same Id
     281             :   
     282           0 :   if ( fId == digit.fId ) 
     283           0 :     return kTRUE ;
     284             :   else 
     285           0 :     return kFALSE ;
     286           0 : }
     287             :  
     288             : //____________________________________________________________________________
     289             : AliPHOSDigit& AliPHOSDigit::operator+=(AliPHOSDigit const & digit) 
     290             : {
     291             : 
     292             :   // Adds the amplitude of digits and completes the list of primary particles
     293         730 :   if(digit.fNprimary>0){
     294         109 :      Int_t *tmp = new Int_t[fNprimary+digit.fNprimary] ;
     295         218 :      if(fAmp < digit.fAmp || fEnergy < digit.fEnergy){//most energetic primary in second digit => first primaries in list from second digit
     296         436 :         for (Int_t index = 0 ; index < digit.fNprimary ; index++)
     297         109 :            tmp[index]=(digit.fPrimary)[index] ;
     298         218 :         for (Int_t index = 0 ; index < fNprimary ; index++)
     299           0 :            tmp[index+digit.fNprimary]=fPrimary[index] ;
     300         109 :      }
     301             :      else{ //add new primaries to the end
     302           0 :         for (Int_t index = 0 ; index < fNprimary ; index++)
     303           0 :            tmp[index]=fPrimary[index] ;
     304           0 :         for (Int_t index = 0 ; index < digit.fNprimary ; index++)
     305           0 :            tmp[index+fNprimary]=(digit.fPrimary)[index] ;
     306             :      }
     307         109 :      if(fPrimary)
     308           0 :        delete []fPrimary ;
     309         109 :      fPrimary = tmp ;
     310         109 :    }
     311         365 :    fNprimary+=digit.fNprimary ;
     312         365 :    fAmp     += digit.fAmp ;
     313         365 :    fEnergy  += digit.fEnergy ;
     314         365 :    if(fTime > digit.fTime)
     315         363 :       fTime = digit.fTime ;
     316         365 :    fTimeR = fTime ; 
     317             : 
     318             :    // Add high-gain ALTRO samples
     319             :    UShort_t i;
     320         365 :    if (digit.fNSamplesHG > fNSamplesHG) {
     321           0 :      UShort_t newNSamplesHG = digit.fNSamplesHG;
     322           0 :      UShort_t *newSamplesHG = new UShort_t[newNSamplesHG];
     323           0 :      for (i=0; i<newNSamplesHG; i++) {
     324           0 :        if (i<fNSamplesHG)
     325           0 :          newSamplesHG[i] = TMath::Max(1023,fSamplesHG[i] + (digit.fSamplesHG)[i]);
     326             :        else
     327           0 :          newSamplesHG[i] = (digit.fSamplesHG)[i];
     328             :      }
     329           0 :      delete [] fSamplesHG;
     330           0 :      fSamplesHG = new UShort_t[newNSamplesHG];
     331           0 :      for (i=0; i<newNSamplesHG; i++) {
     332           0 :        fSamplesHG[i] = newSamplesHG[i];
     333             :      }
     334           0 :      delete [] newSamplesHG;
     335           0 :    }
     336             :    else {
     337         730 :      for (i=0; i<fNSamplesHG; i++)
     338           0 :        fSamplesHG[i] = TMath::Max(1023,fSamplesHG[i] + (digit.fSamplesHG)[i]);
     339             :    }
     340             : 
     341             :    // Add low-gain ALTRO samples
     342         365 :    if (digit.fNSamplesLG > fNSamplesLG) {
     343           0 :      UShort_t newNSamplesLG = digit.fNSamplesLG;
     344           0 :      UShort_t *newSamplesLG = new UShort_t[newNSamplesLG];
     345           0 :      for (i=0; i<newNSamplesLG; i++) {
     346           0 :        if (i<fNSamplesLG)
     347           0 :          newSamplesLG[i] = TMath::Max(1023,fSamplesLG[i] + (digit.fSamplesLG)[i]);
     348             :        else
     349           0 :          newSamplesLG[i] = (digit.fSamplesLG)[i];
     350             :      }
     351           0 :      delete [] fSamplesLG;
     352           0 :      fSamplesLG = new UShort_t[newNSamplesLG];
     353           0 :      for (i=0; i<newNSamplesLG; i++) {
     354           0 :        fSamplesLG[i] = newSamplesLG[i];
     355             :      }
     356           0 :      delete [] newSamplesLG;
     357           0 :    }
     358             :    else {
     359         730 :      for (i=0; i<fNSamplesLG; i++)
     360           0 :        fSamplesLG[i] = TMath::Max(1023,fSamplesLG[i] + (digit.fSamplesLG)[i]);
     361             :    }
     362             :    
     363             :    //If at least one digit in LG, then sum also
     364        1095 :    fIsLG=fIsLG||digit.fIsLG ;
     365             : 
     366         365 :    return *this ;
     367             : }
     368             : //____________________________________________________________________________
     369             : AliPHOSDigit& AliPHOSDigit::operator *= (Float_t factor) 
     370             : {
     371             :   // Multiplies the amplitude by a factor
     372             :   
     373           0 :   Float_t tempo = static_cast<Float_t>(fAmp) ; 
     374           0 :   tempo *= factor ; 
     375           0 :   fAmp = static_cast<Int_t>(TMath::Ceil(tempo)) ; 
     376           0 :   return *this ;
     377             : }
     378             : 
     379             : //____________________________________________________________________________
     380             : ostream& operator << ( ostream& out , const AliPHOSDigit & digit)
     381             : {
     382             :   // Prints the data of the digit
     383             :   
     384             : //   out << "ID " << digit.fId << " Energy = " << digit.fAmp << " Time = " << digit.fTime << endl ; 
     385             : //   Int_t i ;
     386             : //   for(i=0;i<digit.fNprimary;i++)
     387             : //     out << "Primary " << i+1 << " = " << digit.fPrimary[i] << endl ;
     388             : //   out << "Position in list = " << digit.fIndexInList << endl ; 
     389           0 :   digit.Warning("operator <<", "Implement differently") ; 
     390           0 :   return out ;
     391             : }
     392             : 
     393             : 

Generated by: LCOV version 1.11