LCOV - code coverage report
Current view: top level - STEER/ESD - AliESDCaloCells.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 117 186 62.9 %
Date: 2016-06-14 17:26:59 Functions: 12 18 66.7 %

          Line data    Source code
       1             : /**************************************************************************
       2             :  * Copyright(c) 1998-2007, 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             : #include "AliESDCaloCells.h"
      17             : 
      18             : /// \cond CLASSIMP
      19         172 : ClassImp(AliESDCaloCells) ;
      20             : /// \endcond
      21             : 
      22             : ///
      23             : /// Default constructor.
      24             : ///
      25             : //_____________________________________________________
      26             : AliESDCaloCells::AliESDCaloCells() : 
      27          72 :   AliVCaloCells(), fNCells(0), fHGLG(0),fCellNumber(0), 
      28          36 :   fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0), 
      29          36 :   fIsSorted(kTRUE), fType(kUndef)
      30         180 : {
      31          72 : }
      32             : 
      33             : ///
      34             : /// Constructor.
      35             : ///
      36             : //______________________________________________________________________________________
      37             :  AliESDCaloCells::AliESDCaloCells(const char* name, const char* title, VCells_t ttype) : 
      38           0 :    AliVCaloCells(name, title), fNCells(0),  fHGLG(0),fCellNumber(0), 
      39           0 :    fAmplitude(0),  fTime(0), fEFraction(0), fMCLabel(0),
      40           0 :    fIsSorted(kTRUE), fType(ttype)
      41           0 : {
      42           0 : }
      43             : 
      44             : ///
      45             : /// Copy constructor.
      46             : ///
      47             : //__________________________________________________________
      48             : AliESDCaloCells::AliESDCaloCells(const AliESDCaloCells& c) : 
      49           0 :   AliVCaloCells(c), fNCells(c.fNCells),  fHGLG(0), fCellNumber(0), 
      50           0 :   fAmplitude(0), fTime(0), fEFraction(0), fMCLabel(0),
      51           0 :   fIsSorted(c.fIsSorted), fType(c.fType)
      52           0 : {
      53           0 :   fHGLG       = new Bool_t[fNCells] ;
      54           0 :   fCellNumber = new Short_t[fNCells];
      55           0 :   fAmplitude  = new Double32_t[fNCells];
      56           0 :   fTime       = new Double32_t[fNCells];
      57           0 :   fMCLabel    = new Int_t[fNCells];
      58           0 :   fEFraction  = new Double32_t[fNCells];
      59             : 
      60           0 :   for(Int_t i = 0; i < fNCells; i++)
      61             :   {
      62           0 :     fCellNumber[i]    = c.fCellNumber[i];
      63           0 :     fAmplitude[i]     = c.fAmplitude[i];
      64           0 :     fTime[i]          = c.fTime[i];
      65           0 :     if(c.fMCLabel)  fMCLabel[i]   = c.fMCLabel[i];
      66           0 :     if(c.fEFraction)fEFraction[i] = c.fEFraction[i];
      67             :   }
      68             :   
      69           0 :   if(c.fHGLG)
      70             :   {
      71           0 :     for(Int_t i = 0; i < fNCells; i++)
      72             :     {
      73           0 :       fHGLG[i]          = c.fHGLG[i];   
      74             :     }
      75           0 :   }
      76           0 : }
      77             : 
      78             : ///
      79             : /// Assignment operator.
      80             : ///
      81             : //__________________________________________________________________________
      82             : AliESDCaloCells & AliESDCaloCells::operator =(const AliESDCaloCells& source)  
      83             : {
      84           8 :   if(this != &source)
      85             :   {
      86           4 :     AliVCaloCells::operator=(source);
      87             :     
      88           4 :     if(fNCells != source.fNCells) 
      89             :     {
      90           0 :       if(fHGLG)
      91           0 :         delete [] fHGLG ;
      92           0 :       delete [] fCellNumber;
      93           0 :       delete [] fAmplitude;
      94           0 :       delete [] fTime;
      95           0 :       delete [] fMCLabel;
      96           0 :       delete [] fEFraction;
      97             :       
      98           0 :       fNCells = source.fNCells;
      99             :   
     100           0 :       if(source.fHGLG)
     101           0 :         fHGLG       = new Bool_t[fNCells] ;
     102           0 :       fCellNumber = new Short_t[fNCells];
     103           0 :       fAmplitude  = new Double32_t[fNCells];
     104           0 :       fTime       = new Double32_t[fNCells];
     105           0 :       fMCLabel    = new Int_t[fNCells];
     106           0 :       fEFraction  = new Double32_t[fNCells];
     107           0 :     }
     108             :     
     109           4 :     if(source.fHGLG)
     110           0 :       memcpy(fCellNumber,source.fHGLG,fNCells*sizeof(Bool_t));
     111           4 :     memcpy(fCellNumber,source.fCellNumber,fNCells*sizeof(Short_t));
     112           4 :     memcpy(fAmplitude, source.fAmplitude, fNCells*sizeof(Double32_t));
     113           4 :     memcpy(fTime,      source.fTime,      fNCells*sizeof(Double32_t));
     114           4 :     if(source.fMCLabel   && fMCLabel)   memcpy(fMCLabel,   source.fMCLabel,   fNCells*sizeof(Int_t));
     115           4 :     if(source.fEFraction && fEFraction) memcpy(fEFraction, source.fEFraction, fNCells*sizeof(Double32_t));
     116             : 
     117           4 :     fIsSorted = source.fIsSorted;
     118           4 :     fType = source.fType;
     119             :     
     120           4 :   }
     121             : 
     122           4 :   return *this;
     123             : }
     124             : 
     125             : ///
     126             : /// This overwrites the virtual TObject::Copy()
     127             : /// to allow run time copying without casting
     128             : /// in AliESDEvent
     129             : ///
     130             : //____________________________________________
     131             : void AliESDCaloCells::Copy(TObject &obj) const 
     132             : {
     133           8 :   if(this==&obj)return;
     134          12 :   AliESDCaloCells *robj = dynamic_cast<AliESDCaloCells*>(&obj);
     135           4 :   if(!robj)return; // not an AliESDCaloCells
     136           4 :   *robj = *this;
     137           8 : }
     138             : 
     139             : ///
     140             : /// Copy the calo cells into a new object. If option all=FALSE, just the object type, 
     141             : /// for mixing.
     142             : ///
     143             : //______________________________________________________________________
     144             : AliVCaloCells* AliESDCaloCells::CopyCaloCells(Bool_t all = kTRUE) const
     145             : {  
     146           0 :   AliVCaloCells *obj = new AliESDCaloCells();
     147             :   
     148           0 :   if(all){
     149           0 :     obj->SetName (GetName()) ; 
     150           0 :     obj->SetTitle(GetTitle()) ; 
     151           0 :     obj->SetType (GetType()) ; 
     152             :     
     153           0 :     obj->SetNumberOfCells(fNCells);
     154           0 :     for (Short_t i = 0; i < fNCells; i++) 
     155             :     {
     156             :       Int_t mclabel = -1;
     157           0 :       if(fMCLabel) mclabel = fMCLabel[i];
     158             :       
     159             :       Float_t efrac = 0.;
     160           0 :       if(fEFraction) efrac = fEFraction[i];
     161             :       
     162           0 :       obj->SetCell(i,fCellNumber[i],fAmplitude[i],fTime[i],mclabel,efrac);
     163             :     }
     164           0 :   }
     165             : 
     166           0 :   return obj;
     167           0 : }
     168             : 
     169             : ///
     170             : /// Destructor.
     171             : ///
     172             : //_________________________________
     173             : AliESDCaloCells::~AliESDCaloCells()
     174         120 : {
     175          20 :   DeleteContainer();
     176          60 : }
     177             : 
     178             : ///
     179             : /// Clear arrays.
     180             : ///
     181             : //__________________________________________
     182             : void AliESDCaloCells::Clear(const Option_t*)
     183             : {  
     184           0 :   DeleteContainer();
     185           0 : }
     186             : 
     187             : ///
     188             : /// Function that creates container to store calorimeter cell data.
     189             : ///
     190             : //___________________________________________________
     191             : void AliESDCaloCells::CreateContainer(Short_t nCells)
     192             : {
     193          32 :   DeleteContainer();
     194             :   
     195          16 :   if (nCells <= 0) 
     196             :   {
     197           0 :     fNCells = 0;
     198           0 :     return;
     199             :   }
     200             : 
     201          16 :   fNCells = nCells;
     202             : 
     203          16 :   fHGLG       = new Bool_t[fNCells];
     204          16 :   fCellNumber = new Short_t[fNCells];
     205          16 :   fAmplitude  = new Double32_t[fNCells];
     206          16 :   fTime       = new Double32_t[fNCells];
     207          16 :   fMCLabel    = new Int_t[fNCells];
     208          16 :   fEFraction  = new Double32_t[fNCells];
     209             : 
     210             :   // set to zero
     211         726 :   for(int i = 0;i<fNCells;++i)
     212             :   {
     213         347 :     fHGLG[i]=kFALSE ;
     214         347 :     fAmplitude [i] =  0.; 
     215         347 :     fCellNumber[i] = -1 ; 
     216         347 :     fEFraction [i] =  0.;
     217         347 :     fTime      [i] = -1.;
     218         347 :     fMCLabel   [i] = -1 ;
     219             :   }
     220          16 : }
     221             : 
     222             : ///
     223             : /// Deletes allocated memory
     224             : ///
     225             : //_____________________________________
     226             : void AliESDCaloCells::DeleteContainer()
     227             : {
     228         204 :   if(fHGLG)
     229             :   {
     230          72 :     delete[] fHGLG;
     231          36 :     fHGLG = 0 ;
     232          36 :   }
     233             :   
     234         102 :   if (fCellNumber)
     235             :   {
     236          72 :     delete[] fCellNumber;
     237          36 :     fCellNumber = 0;
     238          36 :   }
     239             : 
     240         102 :   if (fAmplitude)
     241             :   {
     242          72 :     delete[] fAmplitude;
     243          36 :     fAmplitude = NULL;
     244          36 :   }
     245             : 
     246         102 :   if (fTime)
     247             :   {
     248          72 :     delete[] fTime;
     249          36 :     fTime = NULL;
     250          36 :   }
     251             :   
     252         102 :   if (fMCLabel)
     253             :   {
     254          72 :     delete[] fMCLabel;
     255          36 :     fMCLabel = NULL;
     256          36 :   }
     257             :   
     258         102 :   if (fEFraction)
     259             :   {
     260          72 :     delete[] fEFraction;
     261          36 :     fEFraction = NULL;
     262          36 :   }
     263             :   
     264         102 :   fNCells = 0;
     265         102 :   fIsSorted = kFALSE;
     266             :   
     267         102 : }
     268             : 
     269             : ///
     270             : /// Sort the cell array by cell number.
     271             : ///
     272             : //__________________________
     273             : void AliESDCaloCells::Sort() 
     274             : {  
     275          32 :   Int_t *idxArray = new Int_t[fNCells];
     276          16 :   TMath::Sort(fNCells,fCellNumber,idxArray,kFALSE);
     277             :   
     278          16 :   Short_t    *newIndex     = new Short_t[fNCells];
     279          16 :   Double32_t *newAmplitude = new Double32_t[fNCells];
     280          16 :   Double32_t *newTime      = new Double32_t[fNCells];
     281             :   
     282             :   Int_t      *newMCLabel   = 0 ;
     283             :   Double32_t *newEFraction = 0 ; 
     284          32 :   if(fMCLabel)   newMCLabel   = new Int_t[fNCells];
     285          32 :   if(fEFraction) newEFraction = new Double32_t[fNCells];
     286             :     
     287         670 :   for (Int_t i=0; i < fNCells; i++) 
     288             :   {
     289         319 :     newIndex[i]     = fCellNumber[idxArray[i]];
     290         319 :     newAmplitude[i] = fAmplitude [idxArray[i]];
     291         319 :     newTime[i]      = fTime      [idxArray[i]];
     292         638 :     if(fMCLabel)   newMCLabel[i]   = fMCLabel  [idxArray[i]];
     293         638 :     if(fEFraction) newEFraction[i] = fEFraction[idxArray[i]];
     294             :   }
     295          16 :   if(fHGLG){
     296          16 :     Bool_t     *newHGLG      = new Bool_t[fNCells];
     297         670 :     for (Int_t i=0; i < fNCells; i++) {
     298         319 :       newHGLG[i]      = fHGLG[idxArray[i]];
     299             :     }
     300          32 :     delete [] fHGLG;  
     301          16 :     fHGLG = newHGLG;
     302          16 :   }
     303             :   
     304          32 :   delete [] fCellNumber;
     305          32 :   delete [] fAmplitude;
     306          32 :   delete [] fTime;
     307          32 :   delete [] fMCLabel;
     308          32 :   delete [] fEFraction;
     309             : 
     310          16 :   fCellNumber = newIndex;
     311          16 :   fAmplitude  = newAmplitude;
     312          16 :   fTime       = newTime;
     313          16 :   fMCLabel    = newMCLabel;
     314          16 :   fEFraction  = newEFraction;
     315             : 
     316          32 :   delete [] idxArray;
     317             :   
     318          16 :   fIsSorted = kTRUE;
     319          16 : } 
     320             : 
     321             : ///
     322             : /// Sets a cell at the given position.
     323             : /// \param pos: cell position in array.
     324             : /// \param cellNumber: Cell absolute Id. number.
     325             : /// \param amplitude: Cell signal (GeV).
     326             : /// \param time: Cell time (s).
     327             : /// \param mclabel: MC particle index in kine array.
     328             : /// \param efrac: Fraction of energy from embedding.
     329             : /// \param isHG: bool true if cell is from high gain.
     330             : ///
     331             : //________________________________________________________________________________________
     332             : Bool_t AliESDCaloCells::SetCell(Short_t pos,     Short_t cellNumber, Double32_t amplitude,  
     333             :                                 Double32_t time, Int_t mclabel,    Double32_t efrac, Bool_t isHG)
     334             : {
     335         638 :   if (pos>=0 && pos < fNCells) 
     336             :   {
     337         319 :     if(fHGLG)
     338         319 :       fHGLG[pos]=isHG ;
     339         319 :     fCellNumber[pos] = cellNumber;
     340         319 :     fAmplitude[pos]  = amplitude;
     341         319 :     fTime[pos]       = time;
     342             :     
     343             :     // note: initialize (can't use memset for non-0 values)
     344             :     //       plus sizeof(Double32_t) is 0
     345         319 :     if(!fMCLabel){
     346           0 :       fMCLabel   = new Int_t[fNCells];
     347             : 
     348           0 :       for( Int_t i = 0; i < fNCells; i++ )
     349           0 :         fMCLabel[i] = -1;
     350           0 :     }
     351         319 :     if(!fEFraction){
     352           0 :       fEFraction = new Double32_t[fNCells];
     353             : 
     354           0 :       for( Int_t i = 0; i < fNCells; i++ )
     355           0 :         fEFraction[i] = 0;
     356           0 :     }
     357             : 
     358         319 :     fMCLabel[pos]    = mclabel;
     359         319 :     fEFraction[pos]  = efrac;
     360             :     
     361         319 :     fIsSorted = kFALSE;
     362             :     
     363         319 :     return kTRUE;
     364             :     
     365             :   } else {
     366           0 :     return kFALSE;
     367             :   }
     368         319 : }

Generated by: LCOV version 1.11