Coding conventions
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerBoard.cxx
CommitLineData
916f1e76 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
19EMCal trigger board super class
20run the sliding window algorithm
21Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
22*/
23
24#include "AliEMCALTriggerBoard.h"
25#include "AliEMCALTriggerPatch.h"
26
27#include <TClonesArray.h>
28
dc483a03 29#include <iostream>
30#include <cstdlib>
31
32using namespace std;
916f1e76 33
34ClassImp(AliEMCALTriggerBoard)
35
36//_______________
37AliEMCALTriggerBoard::AliEMCALTriggerBoard() : TObject(),
38fRegion(0x0),
39fMap(0x0),
40fRegionSize(0x0),
41fSubRegionSize(0x0),
42fPatchSize(0x0),
43fPatches( new TClonesArray("AliEMCALTriggerPatch",10) )
44{
45
46}
47
48//_______________
49AliEMCALTriggerBoard::AliEMCALTriggerBoard(const AliEMCALCalibData */*calibData*/, const TVector2& RS) : TObject(),
50fRegion(0x0),
51fMap(0x0),
52fRegionSize( new TVector2( RS ) ),
53fSubRegionSize( new TVector2() ),
54fPatchSize( new TVector2() ),
55fPatches( new TClonesArray("AliEMCALTriggerPatch",10) )
56{
57 fRegion = (int**)malloc( (int)fRegionSize->X() * sizeof( int* ) );
58
59 if (!fRegion) printf("Error: malloc could not allocate %d bytes for fRegion\n",
60 int(fRegionSize->X() * sizeof( int* )));
61
62 fMap = (int**)malloc( (int)fRegionSize->X() * sizeof( int* ) );
63
64 if (!fMap) printf("Error: malloc could not allocate %d bytes for fMap\n",
65 int(fRegionSize->X() * sizeof( int* )));
66
67 for (Int_t i=0;i<fRegionSize->X();i++)
68 {
69 fRegion[i] = (int*)malloc( (int)fRegionSize->Y() * sizeof( int ) );
70
71 if (!fRegion[i]) printf("Error: malloc could not allocate %d bytes for fRegion[%d]\n",
72 i,int(fRegionSize->Y() * sizeof( int )));
73
74 fMap[i] = (int*)malloc( (int)fRegionSize->Y() * sizeof( int ) );
75
76 if (!fMap[i]) printf("Error: malloc could not allocate %d bytes for fMap[%d]\n",
77 i,int(fRegionSize->Y() * sizeof( int )));
78 }
79
80 // Initialize region matrix
81 ZeroRegion();
82
83 for (int i=0; i<fRegionSize->X(); ++i)
84 for (int j=0; j<fRegionSize->Y(); ++j) fMap[i][j] = 0;
85}
86
87//_______________
88AliEMCALTriggerBoard::~AliEMCALTriggerBoard()
89{
90 for (Int_t i=0;i<fRegionSize->X();i++)
91 {
92 if (fRegion[i]) {delete fRegion[i]; fRegion[i] = 0;}
93 if ( fMap[i]) {delete fMap[i]; fMap[i] = 0;}
94 }
95
96 delete [] fRegion; fRegion = 0x0;
97 delete [] fMap; fMap = 0x0;
98
0341167b 99 if(fPatches)fPatches->Delete();
100 delete fPatches;
916f1e76 101}
102
103//_______________
104void AliEMCALTriggerBoard::ZeroRegion()
105{
106 //
107 for (Int_t i=0;i<int(fRegionSize->X());i++) for (Int_t j=0;j<int(fRegionSize->Y());j++) fRegion[i][j] = 0;
108}
109
110//_______________
111void AliEMCALTriggerBoard::SlidingWindow( L1TriggerType_t /*type*/, Int_t thres )
112{
113 //
114 Int_t ipatch = 0;
115
116 for (Int_t i=0; i<=int(fRegionSize->X()-fPatchSize->X()*fSubRegionSize->X()); i+=int(fSubRegionSize->X()))
117 {
118 for (Int_t j=0; j<=int(fRegionSize->Y()-fPatchSize->Y()*fSubRegionSize->Y()); j+=int(fSubRegionSize->Y()))
119 {
120 ipatch++;
121
122 Int_t sum = 0;
123
124 for (Int_t k=0; k<int(fPatchSize->X()*fSubRegionSize->X()); k++)
125 {
126 for (Int_t l=0; l<int(fPatchSize->Y()*fSubRegionSize->Y()); l++)
127 {
128 sum += fRegion[i+k][j+l];
129 }
130 }
131
132 if ( sum > thres )
133 {
134 //if ( type == kJet ) sum /= 4; // truncate patch sum for jet case
135
136 new((*fPatches)[fPatches->GetLast()+1])
137 AliEMCALTriggerPatch( int(i/fSubRegionSize->X()), int(j/fSubRegionSize->Y()), int(sum) );
138 }
139 }
140 }
141}
142
143//__________
144void AliEMCALTriggerBoard::Scan()
145{
146 //
147 cout << " ";
148 for (Int_t i=0; i<int(fRegionSize->X()); i++) printf("%8d ",i);
149 cout << "\n";
150 for (Int_t i=0; i<int(fRegionSize->X())-5; i++) printf("-------");
151 cout << "\n";
152
153 for (Int_t i=0; i<int(fRegionSize->Y()); i++)
154 {
155 if (i && !(i%12))
156 {
157 for (Int_t j=0; j<int(fRegionSize->X())-5; j++) printf("-------");
158 cout << endl;
159 }
160
161 printf("%3d |",i);
162 for (Int_t j=0; j<int(fRegionSize->X()); j++)
163 {
164 printf("%2d/%5d ", fMap[j][i], fRegion[j][i]);
165 }
166 cout << endl;
167 }
168}
169
170//__________
171void AliEMCALTriggerBoard::Reset()
172{
173 //
174 fPatches->Delete();
175 ZeroRegion();
176}
177