LCOV - code coverage report
Current view: top level - TPC/TPCbase - AliSimDigits.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 130 207 62.8 %
Date: 2016-06-14 17:26:59 Functions: 13 22 59.1 %

          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             : 
      17             : /// \class AliSimDigits
      18             : ///
      19             : ///  Alice segment manager object
      20             : ///  AliSimDigits object   (derived from AliDigits)
      21             : ///  provide additional track information to digit
      22             : /// \author Marian Ivanov  GSI Darmstadt
      23             : 
      24             : #include "TClass.h"
      25             : #include <Riostream.h>
      26             : #include "TError.h"
      27             : #include "AliSegmentID.h"
      28             : #include "AliH2F.h"
      29             : #include "TArrayI.h"
      30             : #include "AliDigits.h"
      31             : #include "AliSimDigits.h"
      32             : #include <TClonesArray.h>
      33             : #include <stdlib.h>
      34             : 
      35             : 
      36             : //_____________________________________________________________________________
      37             : //_____________________________________________________________________________
      38             : //_____________________________________________________________________________
      39             : /// \cond CLASSIMP
      40          24 : ClassImp(AliSimDigits)
      41             : /// \endcond
      42             : 
      43             : AliSimDigits::AliSimDigits()
      44       22913 :              :AliDigits(),
      45       22913 :               fTracks(0),
      46       22913 :               fTrIndex(0),
      47       22913 :               fNlevel(0),
      48       22913 :               fTrBufType(0)  
      49      114565 : {
      50             :   //  AliDigits::Invalite();
      51             :  
      52       22913 :   InvalidateTrack();
      53       45826 : }
      54             : //
      55             : AliSimDigits::AliSimDigits(const AliSimDigits &param)
      56           0 :              :AliDigits(),
      57           0 :               fTracks(0),
      58           0 :               fTrIndex(0),
      59           0 :               fNlevel(0),
      60           0 :               fTrBufType(0) 
      61           0 : {
      62             :   /// dummy
      63             : 
      64           0 :   fTrIndex = param.fTrIndex;
      65           0 : }
      66             : //
      67             : AliSimDigits::~AliSimDigits()
      68      137414 : {
      69             : 
      70       22905 :   if (fTracks != 0) {
      71       45810 :     delete fTracks;
      72             :   }
      73       22905 :   if (fTrIndex != 0) { 
      74       45810 :     delete fTrIndex;
      75             :   } 
      76             : 
      77       68707 : }
      78             : AliSimDigits & AliSimDigits::operator =(const AliSimDigits & param)
      79             : {
      80             :   /// assignment operator - dummy
      81             : 
      82           0 :   if(this!=&param){
      83           0 :     fTrIndex=param.fTrIndex;
      84           0 :   }
      85           0 :   return (*this);
      86             : }
      87             : 
      88             : //__________________________________________________________________
      89             : void AliSimDigits::InvalidateTrack() 
      90             : { 
      91             :   /// set default (invalid parameters)
      92             : 
      93      137410 :   if ( fTracks != 0) delete fTracks;
      94       91618 :   fTracks = new TArrayI;
      95       91601 :   if ( fTrIndex  != 0) delete fTrIndex;
      96       91618 :   fTrIndex = new TArrayI;
      97             : 
      98      366472 :   for (Int_t i = 0; i<3; i++){
      99      137427 :     fTracks->Set(0);
     100      137427 :     fTrIndex->Set(0);
     101             :   }
     102       45809 : }
     103             : 
     104             : void  AliSimDigits::AllocateTrack(Int_t length)
     105             : {
     106             :   /// construct empty buffer fElements and fTracks with size fNrows x fNcols x
     107             :   /// length
     108             : 
     109       45792 :   InvalidateTrack();
     110       22896 :   fNlevel = length;
     111       22896 :   fTracks->Set(fNcols*fNrows*fNlevel);
     112       22896 :   fTrIndex->Set(0); 
     113       22896 :   fTrBufType =0;
     114       22896 : }
     115             : 
     116             : Int_t AliSimDigits::GetTrackID(Int_t row, Int_t column, Int_t level) 
     117             : {
     118             :   /// Get track ID
     119             : 
     120           0 :   if (fTrBufType == 0) return  GetTrackIDFast(row, column,level);
     121           0 :   if (fTrBufType == 1) return  GetTrackID1(row, column,level); 
     122           0 :   if (fTrBufType == 2) return  GetTrackID2(row, column,level); 
     123           0 :   return 0;
     124           0 : }
     125             : 
     126             : void AliSimDigits::ExpandTrackBuffer()
     127             : {  
     128             :   /// expand buffer to two dimensional array
     129             : 
     130       45792 :   if (fTrBufType<0)  {
     131           0 :     Error("ExpandBuffer", "buffer doesn't exist");
     132           0 :     return;
     133             :   }
     134       22896 :   if (fTrBufType==0)      return;  //buffer expanded
     135       45792 :   if (fTrBufType==1)  {ExpandTrackBuffer1(); return;}
     136           0 :   if (fTrBufType==2)  ExpandTrackBuffer2();
     137             :  
     138       22896 : }
     139             : 
     140             : void AliSimDigits::CompresTrackBuffer(Int_t bufType)
     141             : {
     142             :   /// compres buffer according buffertype algorithm
     143             : 
     144       45792 :   if (fTrBufType<0)  {
     145           0 :     Error("CompressBuffer", "buffer doesn't exist");
     146           0 :     return;
     147             :   }
     148       22896 :   if (fTrBufType == bufType) return;
     149             :   //
     150       22896 :   if (fTrBufType>0) ExpandTrackBuffer();
     151       22896 :   if (fTrBufType !=0)  {
     152           0 :     Error("CompressBuffer", "buffer doesn't exist");
     153           0 :     return;
     154             :   }
     155             :   //compress buffer of type 1
     156             :   
     157       45792 :   if (bufType==1)      {CompresTrackBuffer1();return;}
     158           0 :   if (bufType==2)      CompresTrackBuffer2();
     159             :    
     160       22896 : }
     161             : 
     162             : Int_t  AliSimDigits::GetTrackID1(Int_t row, Int_t column, Int_t level)
     163             : {
     164             :   /// return  track ID of digits - for buffer compresion 2
     165             : 
     166             :   Int_t i,n1,n2;
     167           0 :   i = level*fNcols+column;
     168           0 :   if ( (i+1)>=fTrIndex->fN) n2 = fTracks->fN;
     169             :   else 
     170           0 :     n2 = fTrIndex->At(i+1);
     171           0 :   n1 = fTrIndex->At(i);
     172             :   Int_t rownew = 0;
     173             :   Int_t rowold=0;
     174             :   Int_t id;
     175           0 :   for (i = n1;(i<n2);i++){
     176             :     id = 0;
     177           0 :     Int_t num = fTracks->At(i);
     178           0 :     if (num<0) {
     179           0 :       rownew-=num;  
     180             :       rowold = rownew;
     181           0 :       i++;
     182           0 :       if (i<n2){
     183           0 :         num = fTracks->At(i);
     184           0 :         rownew+=num;
     185           0 :         i++;
     186           0 :         id = fTracks->At(i);
     187           0 :       }
     188             :     }
     189             :     else {
     190             :       rowold = rownew;
     191           0 :       rownew+=num;
     192           0 :       i++;
     193           0 :       id = fTracks->At(i);
     194             :     }
     195           0 :     id-=2;
     196           0 :     if ( (row>=rowold) && (row<rownew) ) return id;
     197           0 :     if (row < rownew ) return -2; //empty track
     198           0 :   }
     199           0 :   return -2;
     200           0 : }
     201             : 
     202             : void  AliSimDigits::ExpandTrackBuffer1()
     203             : {
     204             :   /// expand  track compressed according algorithm 1 (track id comression independent to the digit compression)
     205             :   /// !!in expanded tracks we don't use fTrIndex array
     206             : 
     207       45792 :   fTrBufType = 0;
     208             :   Int_t i,j;
     209       22896 :   Int_t all   = fNrows*fNcols;  //total number of digits
     210       22896 :   Int_t elems = all*fNlevel;  //length of the buffer
     211             : 
     212       22896 :   TArrayI * buf = new TArrayI;
     213       22896 :   Int_t *bufData = (Int_t *) calloc(elems, sizeof(Int_t));
     214       22896 :   buf->Adopt(elems, bufData);
     215       22896 :   fTrIndex->Set(0);
     216             :   //
     217             :   Int_t level = 0;
     218             :   Int_t col=0;
     219             :   Int_t row = 0;
     220       22896 :   Int_t n=fTracks->fN;
     221             :   //
     222    14100744 :   for (i=0;i<n;i++){
     223             :     //oposite signa means how many unwrited (under threshold) values
     224     7027476 :     Int_t num = fTracks->At(i);
     225    13882359 :     if (num<0) row-=num;   //negative number mean number of zeroes (no tracks of gibven level no need to write to array) 
     226             :     else {
     227      172593 :       num %= 10000000; //PH: take into account the case of underlying events
     228      172593 :       i++;
     229      172593 :       Int_t id =  fTracks->At(i);
     230     1924110 :       for (j = 0; j<num; j++,row++) {
     231     1578924 :         if (level*all+col*fNrows+row<elems) (*buf)[level*all+col*fNrows+row]=id;       
     232             :       }
     233             :     }
     234     7027476 :     if (row>=fNrows) {
     235             :       row=0;
     236     6690816 :       col++;
     237     6690816 :     }
     238     7027476 :     if (col>=fNcols) {
     239             :       col=0;
     240       68688 :       level++;
     241       68688 :     }    
     242             :   }//end of loop over digits
     243       45792 :   delete fTracks;
     244       22896 :   fTracks = buf;
     245       22896 : }
     246             : 
     247             : void  AliSimDigits::CompresTrackBuffer1()
     248             : {
     249             :   /// comress track according algorithm 1 (track id comression independent to the digit compression)
     250             : 
     251       45792 :   fTrBufType = 1;  
     252             : 
     253       22896 :   TArrayI *  buf = new TArrayI;   //create  new buffer 
     254       22896 :   buf->Set(fNrows*fNcols*fNlevel); //lets have the nearly the "worst case"
     255       22896 :   TArrayI *  index = new TArrayI;
     256       22896 :   index->Set(fNcols*fNlevel);
     257             :   //  Int_t * pindex = 
     258             : 
     259             :   
     260             :   Int_t icurrent=-1;  //current index
     261             :   Int_t izero;      //number of zero
     262             :   Int_t inum;      //number of digits  with the same current track id  
     263             :   Int_t lastID =0;  //last track id  
     264             :   
     265       22896 :   Int_t *cbuff=fTracks->GetArray(); //MI change
     266             : 
     267      183168 :   for (Int_t lev =0; lev<fNlevel; lev++){    //loop over levels 
     268    13519008 :     for (Int_t col = 0; col<fNcols; col++){    //loop over columns
     269             :       izero = 0;
     270             :       inum =  0;
     271             :       lastID = 0;
     272     6690816 :       (*index)[lev*fNcols+col]=icurrent+1;//set collumn pointer
     273             :       Int_t id=0;  //current id
     274 13395013632 :       for (Int_t row = 0; row< fNrows;row++){ //loop over rows        
     275  6690816000 :         id = *cbuff;  //MI change
     276             :         //      id = GetTrackIDFast(row,col,lev);
     277  6690816000 :         if (id <= 0) {
     278  6690026538 :           if ( inum> 0 ) { //if we have some tracks in buffer
     279      164067 :             icurrent++;
     280      164067 :             if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1); //MI change - allocate +1
     281      164067 :             (*buf)[icurrent] = inum;
     282             :             icurrent++;
     283      164067 :             (*buf)[icurrent] = lastID;  
     284             :             inum = 0;      
     285             :             lastID = 0;
     286      164067 :           }
     287  6690026538 :           izero++;
     288  6690026538 :         }
     289             :         else
     290      789462 :           if (id != lastID) 
     291      345186 :             if ( izero > 0 ) { 
     292             :               //if we have currently izero count of non tracks digits
     293      172593 :               icurrent++;         
     294      164067 :               if (icurrent>=buf->fN) buf->Set(icurrent*2+1);
     295      164067 :               (*buf)[icurrent]= -izero;  //write how many under zero
     296      164067 :               inum++;
     297             :               izero = 0;             
     298             :               lastID = id;
     299      164067 :             }
     300             :             else{ 
     301             :               //if we change track id from another track id         
     302             :               icurrent++;         
     303        8526 :               if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2+1);
     304        8526 :               (*buf)[icurrent] = inum;
     305             :               icurrent++;
     306        8526 :               (*buf)[icurrent] = lastID;        
     307             :               lastID = id;
     308             :               inum = 1;      
     309             :               izero = 0;
     310             :             }   
     311             :           else {          
     312      616869 :             inum++;
     313             :           }
     314  6690816000 :         cbuff++;  //MI change
     315             :       }//end of loop over row
     316     6690816 :       if ( izero > 0 ) { 
     317             :         //if we have currently izero count of non tracks digits
     318     6690816 :         icurrent++;       
     319     6690816 :         if (icurrent>=buf->fN) buf->Set(icurrent*2);
     320     6690816 :         (*buf)[icurrent]= -izero;  //write how many under zero  
     321     6690816 :       }
     322     6690816 :       if ( inum> 0 ) { //if we have some tracks in buffer
     323           0 :         icurrent++;
     324           0 :         if ((icurrent+1)>=buf->fN) buf->Set(icurrent*2);
     325           0 :         (*buf)[icurrent] = inum;
     326             :         icurrent++;
     327           0 :         (*buf)[icurrent] = id;  
     328           0 :       }      
     329             :     }//end of loop over columns
     330             :   }//end of loop over differnet track level  
     331       22896 :   buf->Set(icurrent+1);
     332       45792 :   delete fTracks;
     333       22896 :   fTracks = buf;
     334       45792 :   delete fTrIndex;
     335       22896 :   fTrIndex = index;
     336       22896 : }
     337             : 
     338             : 
     339             : 
     340             : void  AliSimDigits::ExpandTrackBuffer2()
     341             : {
     342             :   /// comress track according algorithm 2 (track id comression according  digit compression)
     343             : 
     344           0 :   fTrBufType = 0;
     345           0 : }
     346             : 
     347             : void  AliSimDigits::CompresTrackBuffer2()
     348             : {
     349             :   /// comress track according algorithm 2 (track id comression according  digit compression)
     350             : 
     351           0 :   fTrBufType = 2;
     352           0 : }
     353             : 
     354             : 
     355             : Int_t  AliSimDigits::GetTrackID2(Int_t /*row*/, Int_t /*column*/, Int_t /*level*/)
     356             : {
     357             :   /// returnb track id of digits - for buffer compresion 2
     358             : 
     359           0 :   return -2;
     360             : }
     361             : 
     362             : 
     363             : 
     364             : AliH2F *  AliSimDigits::DrawTracks( const char *option,Int_t level, 
     365             :                               Float_t x1, Float_t x2, Float_t y1, Float_t y2)
     366             : {
     367             :   /// draw digits in given array
     368             :   ///
     369             :   /// make digits histo
     370             : 
     371           0 :   char ch[30];
     372             :   //sprintf(ch,"Track Segment_%d level %d ",GetID(),level );
     373           0 :   snprintf(ch,30,"Track Segment_%d level %d ",GetID(),level );
     374           0 :   if ( (fNrows<1)|| (fNcols<1)) {
     375           0 :     return 0;
     376             :   }
     377           0 :   AliH2F * his  = new AliH2F("Track histo",ch,fNrows,0,fNrows,fNcols,0,fNcols);
     378           0 :   ExpandTrackBuffer();
     379             :   //set histogram  values
     380           0 :   for (Int_t i = 0; i<fNrows;i++)    
     381           0 :     for (Int_t j = 0; j<fNcols;j++)
     382           0 :         his->Fill(i,j,GetTrackIDFast(i,j,level));
     383           0 :   if (x1>=0) {
     384           0 :       AliH2F *h2fsub = his->GetSubrange2d(x1,x2,y1,y2);
     385           0 :       delete his;
     386             :       his=h2fsub;
     387           0 :   }
     388           0 :   if (his==0) return 0;
     389           0 :   if (option!=0) his->Draw(option);
     390           0 :   else his->Draw();
     391           0 :   return his;  
     392           0 : }
     393             : 
     394             : void AliSimDigits::GlitchFilter(){
     395             :   ///  glitch filter, optionally
     396             : 
     397     4529232 :   for (Int_t i=0;i<fNcols;i++){ //pads
     398  4456083456 :     for(Int_t j=1;j<fNrows-1;j++){ //time bins
     399             :       // first and last time bins are checked separately
     400  2225811456 :       if(GetDigitFast(j,i)){// nonzero digit
     401     3977302 :         if (!GetDigitFast(j-1,i) && !GetDigitFast(j+1,i)) {
     402     1714595 :           SetDigitFast(0,j,i);
     403     1714595 :           SetTrackIDFast(-2,j,i,0);
     404     1714595 :           SetTrackIDFast(-2,j,i,1);
     405     1714595 :           SetTrackIDFast(-2,j,i,2);
     406     1714595 :         }
     407             :       }
     408             :     }//time
     409             :    
     410     2232074 :     if(GetDigitFast(0,i) && !GetDigitFast(1,i)) {
     411        1705 :         SetDigitFast(0,0,i);
     412        1705 :         SetTrackIDFast(-2,0,i,0);
     413        1705 :         SetTrackIDFast(-2,0,i,1);
     414        1705 :         SetTrackIDFast(-2,0,i,2);
     415        1705 :     }
     416     2231989 :     if(GetDigitFast(fNrows-1,i) && !GetDigitFast(fNrows-2,i)){ 
     417        1626 :        SetDigitFast(0,fNrows-1,i);
     418        1626 :        SetTrackIDFast(-2,fNrows-1,i,0);
     419        1626 :        SetTrackIDFast(-2,fNrows-1,i,1);
     420        1626 :        SetTrackIDFast(-2,fNrows-1,i,2);    
     421        1626 :     }
     422             :   }//pads
     423             :  
     424       22896 : }
     425             : 

Generated by: LCOV version 1.11