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