LCOV - code coverage report
Current view: top level - EMCAL/EMCALsim - AliEMCALTriggerBoard.cxx (source / functions) Hit Total Coverage
Test: coverage.info Lines: 50 82 61.0 %
Date: 2016-06-14 17:26:59 Functions: 5 12 41.7 %

          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             :  
      18             : 
      19             : EMCal trigger board super class
      20             : run the sliding window algorithm
      21             : Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
      22             : */
      23             : 
      24             : #include "AliEMCALTriggerBoard.h"
      25             : #include "AliEMCALTriggerPatch.h"
      26             : #include "AliLog.h"
      27             : 
      28             : #include <TClonesArray.h>
      29             : #include <iostream>
      30             : #include <cstdlib>
      31             : 
      32             : using namespace std;
      33             : 
      34          42 : ClassImp(AliEMCALTriggerBoard)
      35             : 
      36             : //_______________
      37           0 : AliEMCALTriggerBoard::AliEMCALTriggerBoard() : TObject(),
      38           0 : fRegion(0x0),
      39           0 : fMap(0x0),
      40           0 : fRegionSize(0x0),
      41           0 : fSubRegionSize(0x0),
      42           0 : fPatchSize(0x0),
      43           0 : fPatches(0x0)
      44           0 : {
      45             :         
      46           0 : }       
      47             : 
      48             : //_______________
      49          62 : AliEMCALTriggerBoard::AliEMCALTriggerBoard(const TVector2& RS) : TObject(),
      50          62 : fRegion(0x0),
      51          62 : fMap(0x0),
      52         186 : fRegionSize(    new TVector2( RS ) ),
      53         186 : fSubRegionSize( new TVector2() ),
      54         186 : fPatchSize(     new TVector2() ),
      55         186 : fPatches( new TClonesArray("AliEMCALTriggerPatch",10) )
      56         186 : {
      57             :         // Ctor
      58             :         
      59         124 :   fRegion = (int**)malloc( (int)fRegionSize->X() * sizeof( int* ) );  
      60             :   
      61          62 :   if (!fRegion) printf("Error: malloc could not allocate %d bytes for fRegion\n",
      62           0 :                        int(fRegionSize->X() * sizeof( int* )));
      63             :   
      64         124 :   fMap = (int**)malloc( (int)fRegionSize->X() * sizeof( int* ) );
      65             :   
      66          62 :   if (!fMap) printf("Error: malloc could not allocate %d bytes for fMap\n",
      67           0 :                     int(fRegionSize->X() * sizeof( int* )));
      68             :   
      69        3196 :   for (Int_t i=0;i<fRegionSize->X();i++)
      70             :   {
      71        1536 :     if(fRegion){
      72        3072 :       fRegion[i] = (int*)malloc( (int)fRegionSize->Y() * sizeof( int ) );
      73             :     
      74        1536 :       if (!fRegion[i]) printf("Error: malloc could not allocate %d bytes for fRegion[%d]\n",
      75           0 :                             i,int(fRegionSize->Y() * sizeof( int )));
      76             :     }
      77        1536 :     if(fMap){
      78        3072 :       fMap[i] = (int*)malloc( (int)fRegionSize->Y() * sizeof( int ) );
      79             :     
      80        1536 :       if (!fMap[i]) printf("Error: malloc could not allocate %d bytes for fMap[%d]\n",
      81           0 :                            i,int(fRegionSize->Y() * sizeof( int )));
      82             :     }
      83             :   }
      84             :   
      85             :         // Initialize region matrix
      86          62 :         ZeroRegion();
      87          62 :         if(fMap){
      88        3196 :         for (int i=0; i<fRegionSize->X(); ++i)
      89       26880 :                 for (int j=0; j<fRegionSize->Y(); ++j) fMap[i][j] = 0;
      90          62 :   }
      91          62 : }
      92             : 
      93             : //_______________
      94             : AliEMCALTriggerBoard::~AliEMCALTriggerBoard()
      95         124 : {
      96             :         // Dtor
      97             :         
      98        3196 :    for (Int_t i=0;i<fRegionSize->X();i++) 
      99             :    {
     100        4608 :       if (fRegion[i]) {free(fRegion[i]); fRegion[i] = 0;}
     101        4608 :       if (   fMap[i]) {free(fMap[i]);    fMap[i] = 0;}
     102             :    }
     103             :    
     104         124 :    free(fRegion); fRegion = 0x0;
     105         124 :    free(fMap);    fMap = 0x0;
     106             :    
     107         124 :    if(fPatches)fPatches->Delete();
     108             :    
     109         124 :    delete fPatches;
     110          62 : }
     111             : 
     112             : //_______________
     113             : void AliEMCALTriggerBoard::ZeroRegion()
     114             : {
     115             :         // Initilize fRegion
     116             :   
     117         604 :   if(fRegion){
     118       99676 :     for (Int_t i=0;i<int(fRegionSize->X());i++) for (Int_t j=0;j<int(fRegionSize->Y());j++) fRegion[i][j] = 0;
     119         302 :   }
     120             :   else {
     121           0 :     AliFatal("fRegion was not previously initialized");
     122             :   }
     123             : 
     124         302 : }
     125             : 
     126             : //_______________
     127             : void AliEMCALTriggerBoard::SlidingWindow(Int_t thres)
     128             : {
     129             :         // Sliding window       
     130        1952 :         for (int i = 0; i <= int(fRegionSize->X() - fPatchSize->X() * fSubRegionSize->X()); i += int(fSubRegionSize->X())) {
     131      101888 :                 for (int j = 0; j <= int(fRegionSize->Y() - fPatchSize->Y() * fSubRegionSize->Y()); j += int(fSubRegionSize->Y())) {
     132             :                         //
     133      150048 :                         AliDebug(999, Form("--- Current window at (%2d,%2d) ---",i,j));
     134             :                         int sum = 0;
     135             :                         
     136      331776 :                         for (int k = 0; k < int(fPatchSize->X() * fSubRegionSize->X()); k++) {
     137      948672 :                                 for (int l = 0; l < int(fPatchSize->Y() * fSubRegionSize->Y()); l++) {
     138             :                                         //
     139      358464 :                                         sum += fRegion[i + k][j + l]; 
     140     1075392 :                                         AliDebug(999, Form("Adding fRegion[%2d + %2d][%2d + %2d]: %d and sum is %d",i,k,j,l,fRegion[i + k][j + l],sum));
     141             :                                 }
     142             :                         }
     143             :                         
     144       50016 :                         if (sum > thres) {
     145         504 :                           AliDebug(999, Form("Adding new patch at (%2d,%2d) w/ amplitude %d", i, j, sum));
     146       23548 :                                 new((*fPatches)[fPatches->GetEntriesFast()]) AliEMCALTriggerPatch(i, j, sum);
     147             :                         }
     148             :                 }
     149             :         }
     150          32 : }
     151             : 
     152             : //__________
     153             : void AliEMCALTriggerBoard::Scan()
     154             : {
     155             :         // Dump
     156             :         
     157           0 :         cout << "     ";
     158           0 :         for (Int_t i=0; i<int(fRegionSize->X()); i++) printf("%8d ",i);
     159           0 :         cout << "\n";
     160           0 :         for (Int_t i=0; i<int(fRegionSize->X())-5; i++) printf("-------");
     161           0 :         cout << "\n";
     162             :         
     163           0 :         for (Int_t i=0; i<int(fRegionSize->Y()); i++)
     164             :         {
     165           0 :                 if (i && !(i%12))
     166             :                 {
     167           0 :                         for (Int_t j=0; j<int(fRegionSize->X())-5; j++) printf("-------");
     168           0 :                         cout << endl;
     169           0 :                 }
     170             :                 
     171           0 :                 printf("%3d |",i);
     172           0 :                 for (Int_t j=0; j<int(fRegionSize->X()); j++) 
     173             :                 {
     174           0 :                         printf("%2d/%5d ", fMap[j][i], fRegion[j][i]);
     175             :                 }
     176           0 :                 cout << endl;
     177             :         }
     178           0 : }
     179             : 
     180             : //__________
     181             : void AliEMCALTriggerBoard::Reset()
     182             : {
     183             :         //
     184           0 :         fPatches->Delete();
     185           0 :         ZeroRegion();
     186           0 : }
     187             : 

Generated by: LCOV version 1.11