bugfix: output of one extra cluster when the last rawcluster was accepted by the...
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTriggerSTU.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
19
20
21Author: R. GUERNANE LPSC Grenoble CNRS/IN2P3
22*/
23
24#include "AliEMCALTriggerSTU.h"
25#include "AliCDBManager.h"
26#include "AliCDBEntry.h"
fff39dd1 27#include "AliEMCALTriggerSTUDCSConfig.h"
916f1e76 28#include "AliVZEROCalibData.h"
29#include "AliVZEROdigit.h"
30#include "AliEMCALTriggerPatch.h"
31#include "AliESDVZERO.h"
32#include "AliLog.h"
33
34#include <TClonesArray.h>
35#include <TSystem.h>
36#include <TH2F.h>
37#include <TFile.h>
38#include <TTree.h>
39
40#include <fstream>
41#include <Riostream.h>
c58cfdff 42#include <cstdlib>
916f1e76 43
44ClassImp(AliEMCALTriggerSTU)
45
46//_______________
47AliEMCALTriggerSTU::AliEMCALTriggerSTU() : AliEMCALTriggerBoard()
fff39dd1 48,fGammaTh(0)
49,fJetTh(0)
50,fDCSConfig(0x0)
916f1e76 51{
79b05051 52 // Ctor
916f1e76 53}
54
55//_______________
fff39dd1 56AliEMCALTriggerSTU::AliEMCALTriggerSTU(AliEMCALTriggerSTUDCSConfig *dcsConf, const TVector2& RS) : AliEMCALTriggerBoard(RS)
57,fGammaTh(0)
58,fJetTh(0)
59,fDCSConfig(dcsConf)
916f1e76 60{
79b05051 61 // Ctor
916f1e76 62}
63
64//_______________
65AliEMCALTriggerSTU::~AliEMCALTriggerSTU()
66{
79b05051 67 // Dtor
916f1e76 68}
69
70//_______________
de39a0ff 71Int_t AliEMCALTriggerSTU::GetRawData() const
916f1e76 72{
79b05051 73 // Get raw data
74
de39a0ff 75 return fDCSConfig->GetRawData();
76}
77
78//_______________
79void AliEMCALTriggerSTU::Build( TString& str, Int_t iTRU, Int_t** M, const TVector2* rSize )
80{
79b05051 81 // Build
82
de39a0ff 83 str.ToLower();
84
85 Int_t ix = (iTRU % 2) ? 24 : 0;
86
87 Int_t iy = iTRU / 2;
916f1e76 88
de39a0ff 89 Int_t** v = 0x0;
916f1e76 90
de39a0ff 91 if (str.Contains("map"))
916f1e76 92 {
de39a0ff 93 v = fMap;
916f1e76 94 }
de39a0ff 95 else if (str.Contains("region"))
916f1e76 96 {
de39a0ff 97 v = fRegion;
98 }
99 else
100 {
101 AliError("Operation not allowed: STU won't be configured properly!");
102 }
a51e676d 103
104 if(v){
105 for (Int_t i=0; i<rSize->X(); i++)
106 for (Int_t j=0; j<rSize->Y(); j++) v[i + ix][j + iy * 4] = M[i][j];
107 }
916f1e76 108}
109
110//_______________
de39a0ff 111void AliEMCALTriggerSTU::L1(TriggerType_t type)
916f1e76 112{
79b05051 113 // L1
114
de39a0ff 115 TVector2 s1, s2, s3, s4;
116 fDCSConfig->GetSegmentation(s1, s2, s3, s4);
117
118 switch (type)
119 {
120 case kL1Gamma:
121 SetSubRegionSize(s1);
122 SetPatchSize(s2);
123 break;
124 case kL1Jet:
125 SetSubRegionSize(s3);
126 SetPatchSize(s4);
127 break;
128 default:
129 AliError("Not supported L1 trigger type");
130 return;
131 break;
132 }
133
134 SlidingWindow(type, GetThreshold(type));
916f1e76 135}
136
137//________________
de39a0ff 138void AliEMCALTriggerSTU::PrintADC( TriggerType_t type, TVector2& pos, TVector2& idx )
916f1e76 139{
79b05051 140 // Dump
141
de39a0ff 142 Int_t ix = (Int_t) (( pos.X() + fPatchSize->X() ) * fSubRegionSize->X());
143
144 Int_t iy = (Int_t) (( pos.Y() + fPatchSize->Y() ) * fSubRegionSize->Y());
916f1e76 145
146 TString subRegionADC[] = {"0->15", "16->31", "32->47", "48->63", "64->79", "80->95"};
147
148 switch ( type )
149 {
de39a0ff 150 case kL1Gamma:
916f1e76 151 {
152 Int_t iTRU = ( (ix-1) < 24 ) ? 31 - int(pos.Y() / 4) : 15 - int(pos.Y() / 4);
153
154 printf("TRU #%d row #%d col #%d fastor: ",iTRU,int(idx.Y()),int(idx.X()));
155
da509d54 156 for (Int_t i=(Int_t)(pos.X() * fSubRegionSize->X());i<ix;i++)
916f1e76 157 {
da509d54 158 for (Int_t j=(Int_t) (pos.Y() * fSubRegionSize->Y());j<iy;j++)
916f1e76 159 {
160 Int_t jtru = ( i < 24 ) ? 31 - j / 4 : 15 - j / 4;
161 printf("TRU#%d_%d ",jtru,fMap[i][j]);
162 }
163 }
164
165 cout << endl;
166 }
167 break;
de39a0ff 168 case kL1Jet:
916f1e76 169 {
170 //Int_t jTRU = ( (ix-1) < 24 ) ? 31 - (iy-1) / 4 : 15 - (iy-1) / 4;
171
172 printf("jet found at row : %d and col : %d",int(idx.X()),int(idx.Y()));
173
de39a0ff 174 Char_t vPair[100];
916f1e76 175 Int_t nSubRegion = 0;
176
da509d54 177 for (Int_t i=(Int_t)(pos.X() * fSubRegionSize->X());i<ix;i++)
916f1e76 178 {
da509d54 179 for (Int_t j=(Int_t)(pos.Y() * fSubRegionSize->Y());j<iy;j++)
916f1e76 180 {
181 Int_t itru = ( i < 24 ) ? 31 - j / 4 : 15 - j / 4;
182
183 Int_t idSR = fMap[i][j]/16;
184
185 Char_t value = ((itru << 3) & 0xF8) | (idSR & 0x7);
186
187 Bool_t isFound = kFALSE;
188
189 for (Int_t k=0;k<nSubRegion && nSubRegion;k++)
190 {
191 if (vPair[k] == value) isFound = kTRUE;
192 }
193
194 if (!isFound)
195 {
196 nSubRegion++;
916f1e76 197
198 vPair[nSubRegion-1] = value;
199 }
200 }
201 }
202
203 cout << " fastor:";
204 for (Int_t i=0;i<nSubRegion;i++)
205 {
206 cout << " TRU#" << ((vPair[i] & 0xF8) >> 3) << "_" << subRegionADC[(vPair[i] & 0x7)];
207 }
208
209 cout << endl;
916f1e76 210 }
211 break;
212 default:
213 AliError("AliEMCALTriggerSTU::PrintADC(): Undefined trigger type, pls check!");
214 }
215}
216
916f1e76 217//___________
218void AliEMCALTriggerSTU::PatchGenerator(const TClonesArray* lpos, Int_t val)
219{
79b05051 220 // Patch generator
221
916f1e76 222 ZeroRegion();
223
224 Int_t vTRU[32][24][4] ;//= {0};
225
226 for (Int_t i = 0; i < 32; i++)
227 for (Int_t j = 0; j < 24; j++)
228 for (Int_t k = 0; k < 4; k++) vTRU[i][j][k]=0;
229
230
231 AliWarning("AliEMCALTriggerSTU::PatchGenerator(): STU region has been reset!");
232
233 // Fill the patch FOR at 'pos' w/ value 'val'
234
235 TIter NextPosition( lpos );
236
237 while ( TVector2 *pos = (TVector2*)NextPosition() )
238 {
239 pos->Print();
da509d54 240 for (Int_t i=(Int_t)(pos->X()*fSubRegionSize->X()); i<int((pos->X()+fPatchSize->X())*fSubRegionSize->X()); i++)
241 for (Int_t j=(Int_t)(pos->Y()*fSubRegionSize->Y()); j<int((pos->Y()+fPatchSize->Y())*fSubRegionSize->Y()); j++)
916f1e76 242 fRegion[i][j] = val;
243 }
244
245 for (Int_t i=0; i<2; i++)
246 {
247 for (Int_t j=0; j<16; j++)
248 {
249 Int_t iTRU = ( !i ) ? 31 - j : 15 - j;
250
251 for (Int_t i1=24*i; i1<24*(i+1); i1++)
252 {
253 for (Int_t j1=4*j; j1<4*(j+1); j1++)
254 {
255 vTRU[iTRU][i1%24][j1%4] = fRegion[i1][j1];
256 }
257 }
258 }
259 }
260
261 gSystem->Exec(Form("mkdir -p GP"));
262
263 for (Int_t i=0; i<32; i++)
264 {
265 std::ofstream outfile(Form("GP/data_TRU%d.txt",i),std::ios::trunc);
266
267 for (Int_t j=0;j<96;j++)
268 {
269 Int_t ietam, iphim;
270
271 if ( int(i / 16) )
272 {
273 ietam = j/4;
274 iphim = 3 - j%4;
275 }
276 else
277 {
278 ietam = 23 - j/4;
279 iphim = j%4;
280 }
281
282 outfile << vTRU[i][ietam][iphim] << endl;
283 }
284
285 outfile.close();
286 }
287}
288
289//___________
de39a0ff 290void AliEMCALTriggerSTU::ComputeThFromV0(const Int_t M[])
fff39dd1 291{
79b05051 292 // Compute threshold from V0
293
de39a0ff 294 if (!(M[0] + M[1])) AliWarning("V0A + V0C is null!"); // 0/1: V0C/V0A
fff39dd1 295
fff39dd1 296
de39a0ff 297 fGammaTh = fDCSConfig->GetGA()*(M[0] + M[1])*(M[0] + M[1]) + fDCSConfig->GetGB()*(M[0] + M[1]) + fDCSConfig->GetGC();
fff39dd1 298
de39a0ff 299 fJetTh = fDCSConfig->GetJA()*(M[0] + M[1])*(M[0] + M[1]) + fDCSConfig->GetJB()*(M[0] + M[1]) + fDCSConfig->GetJC();
300}
301
302//___________
303void AliEMCALTriggerSTU::SetThreshold(TriggerType_t type, Int_t v)
304{
79b05051 305 // Set threshold
306
de39a0ff 307 switch (type)
308 {
309 case kL1Gamma:
310 fGammaTh = v;
311 break;
312 case kL1Jet:
313 fJetTh = v;
314 break;
315 default:
316 AliError("AliEMCALTriggerSTU::SetThreshold(): Undefined trigger type, pls check!");
317 }
fff39dd1 318}
319
320//___________
de39a0ff 321Int_t AliEMCALTriggerSTU::GetThreshold(TriggerType_t type)
916f1e76 322{
323 // Compute threshold FIXME: need an access to the OCDB
324 // to get f(V0) parameters depending on trigger type
325
de39a0ff 326
327 switch (type)
916f1e76 328 {
de39a0ff 329 case kL1Gamma:
fff39dd1 330 return fGammaTh;
916f1e76 331 break;
de39a0ff 332 case kL1Jet:
fff39dd1 333 return fJetTh;
916f1e76 334 break;
335 default:
fff39dd1 336 AliError("AliEMCALTriggerSTU::GetThreshold(): Undefined trigger type, pls check!");
916f1e76 337 }
338
fff39dd1 339 return 0;
916f1e76 340}
341
342//__________
343void AliEMCALTriggerSTU::Reset()
344{
79b05051 345 // Reset
346
916f1e76 347 fPatches->Delete();
348}