]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALTriggerBoard.cxx
move include to header, avoid problems with DA compilations
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerBoard.cxx
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 ClassImp(AliEMCALTriggerBoard)
35
36 //_______________
37 AliEMCALTriggerBoard::AliEMCALTriggerBoard() : TObject(),
38 fRegion(0x0),
39 fMap(0x0),
40 fRegionSize(0x0),
41 fSubRegionSize(0x0),
42 fPatchSize(0x0),
43 fPatches(0x0)
44 {
45         
46 }       
47
48 //_______________
49 AliEMCALTriggerBoard::AliEMCALTriggerBoard(const TVector2& RS) : TObject(),
50 fRegion(0x0),
51 fMap(0x0),
52 fRegionSize(    new TVector2( RS ) ),
53 fSubRegionSize( new TVector2() ),
54 fPatchSize(     new TVector2() ),
55 fPatches( new TClonesArray("AliEMCALTriggerPatch",10) )
56 {
57         // Ctor
58         
59   fRegion = (int**)malloc( (int)fRegionSize->X() * sizeof( int* ) );  
60   
61   if (!fRegion) printf("Error: malloc could not allocate %d bytes for fRegion\n",
62                        int(fRegionSize->X() * sizeof( int* )));
63   
64   fMap = (int**)malloc( (int)fRegionSize->X() * sizeof( int* ) );
65   
66   if (!fMap) printf("Error: malloc could not allocate %d bytes for fMap\n",
67                     int(fRegionSize->X() * sizeof( int* )));
68   
69   for (Int_t i=0;i<fRegionSize->X();i++)
70   {
71     if(fRegion){
72       fRegion[i] = (int*)malloc( (int)fRegionSize->Y() * sizeof( int ) );
73     
74       if (!fRegion[i]) printf("Error: malloc could not allocate %d bytes for fRegion[%d]\n",
75                             i,int(fRegionSize->Y() * sizeof( int )));
76     }
77     if(fMap){
78       fMap[i] = (int*)malloc( (int)fRegionSize->Y() * sizeof( int ) );
79     
80       if (!fMap[i]) printf("Error: malloc could not allocate %d bytes for fMap[%d]\n",
81                            i,int(fRegionSize->Y() * sizeof( int )));
82     }
83   }
84   
85         // Initialize region matrix
86         ZeroRegion();
87         if(fMap){
88         for (int i=0; i<fRegionSize->X(); ++i)
89                 for (int j=0; j<fRegionSize->Y(); ++j) fMap[i][j] = 0;
90   }
91 }
92
93 //_______________
94 AliEMCALTriggerBoard::~AliEMCALTriggerBoard()
95 {
96         // Dtor
97         
98    for (Int_t i=0;i<fRegionSize->X();i++) 
99    {
100       if (fRegion[i]) {free(fRegion[i]); fRegion[i] = 0;}
101       if (   fMap[i]) {free(fMap[i]);    fMap[i] = 0;}
102    }
103    
104    free(fRegion); fRegion = 0x0;
105    free(fMap);    fMap = 0x0;
106    
107    if(fPatches)fPatches->Delete();
108    
109    delete fPatches;
110 }
111
112 //_______________
113 void AliEMCALTriggerBoard::ZeroRegion()
114 {
115         // Initilize fRegion
116   
117   if(fRegion){
118     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   }
120   else {
121     AliFatal("fRegion was not previously initialized");
122   }
123
124 }
125
126 //_______________
127 void AliEMCALTriggerBoard::SlidingWindow(TriggerType_t /*type*/, Int_t thres, Int_t time)
128 {
129         // Sliding window
130         
131         Int_t ipatch = 0;
132         
133         for (Int_t i=0; i<=int(fRegionSize->X()-fPatchSize->X()*fSubRegionSize->X()); i+=int(fSubRegionSize->X()))
134         {
135                 for (Int_t j=0; j<=int(fRegionSize->Y()-fPatchSize->Y()*fSubRegionSize->Y()); j+=int(fSubRegionSize->Y()))
136                 {
137                         ipatch++;
138                         
139                         Int_t sum = 0;
140                         
141                         for (Int_t k=0; k<int(fPatchSize->X()*fSubRegionSize->X()); k++)
142                         {
143                                 for (Int_t l=0; l<int(fPatchSize->Y()*fSubRegionSize->Y()); l++)
144                                 {
145                                         sum += fRegion[i+k][j+l];
146                                 }
147                         }
148
149                         if ( sum > thres ) 
150                         {
151                                 new((*fPatches)[fPatches->GetLast()+1]) 
152                                                 AliEMCALTriggerPatch(int(i/fSubRegionSize->X()), int(j/fSubRegionSize->Y()), int(sum), time);
153                         }
154                 }
155         }
156 }
157
158 //__________
159 void AliEMCALTriggerBoard::Scan()
160 {
161         // Dump
162         
163         cout << "     ";
164         for (Int_t i=0; i<int(fRegionSize->X()); i++) printf("%8d ",i);
165         cout << "\n";
166         for (Int_t i=0; i<int(fRegionSize->X())-5; i++) printf("-------");
167         cout << "\n";
168         
169         for (Int_t i=0; i<int(fRegionSize->Y()); i++)
170         {
171                 if (i && !(i%12))
172                 {
173                         for (Int_t j=0; j<int(fRegionSize->X())-5; j++) printf("-------");
174                         cout << endl;
175                 }
176                 
177                 printf("%3d |",i);
178                 for (Int_t j=0; j<int(fRegionSize->X()); j++) 
179                 {
180                         printf("%2d/%5d ", fMap[j][i], fRegion[j][i]);
181                 }
182                 cout << endl;
183         }
184 }
185
186 //__________
187 void AliEMCALTriggerBoard::Reset()
188 {
189         //
190         fPatches->Delete();
191         ZeroRegion();
192 }
193