]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EMCAL/AliEMCALTriggerSTU.cxx
speed up with binary search
[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 ,fDCSConfig(0x0)
49 {
50         // Ctor
51         fGammaTh[0] = fGammaTh[1] = 0;
52         fJetTh[0] = fJetTh[1] = 0;
53 }
54
55 //_______________
56 AliEMCALTriggerSTU::AliEMCALTriggerSTU(AliEMCALTriggerSTUDCSConfig *dcsConf, const TVector2& RS) : AliEMCALTriggerBoard(RS)
57 ,fDCSConfig(dcsConf)
58 {
59         // Ctor
60         fGammaTh[0] = fGammaTh[1] = 0;
61         fJetTh[0] = fJetTh[1] = 0;      
62 }
63
64 //_______________
65 AliEMCALTriggerSTU::~AliEMCALTriggerSTU()
66 {
67         // Dtor
68 }
69
70 //_______________
71 void AliEMCALTriggerSTU::Build( TString& str, Int_t iTRU, Int_t** M, const TVector2* rSize )
72 {
73         // Build
74         
75         str.ToLower();
76         
77         Int_t ix = (iTRU % 2) ? 24 : 0;
78
79         Int_t iy =  iTRU / 2;
80         
81         Int_t** v = 0x0;
82         
83         if (str.Contains("map"))
84         {
85                 v = fMap;
86         }
87         else if (str.Contains("region"))
88         {
89                 v = fRegion;
90         }
91         else
92         {
93                 AliError("Operation not allowed: STU won't be configured properly!");
94         }
95   
96   if(v){        
97     for (Int_t i=0; i<rSize->X(); i++)
98       for (Int_t j=0; j<rSize->Y(); j++) v[i + ix][j + iy * 4] = M[i][j];
99   }
100 }
101
102 //_______________
103 void AliEMCALTriggerSTU::L1(int type)
104 {
105         // L1
106         
107         TVector2 s1, s2, s3, s4;
108         fDCSConfig->GetSegmentation(s1, s2, s3, s4);
109         
110         switch (type)
111         {
112                 case kL1GammaHigh:
113                 case kL1GammaLow:
114                         SetSubRegionSize(s1); 
115                         SetPatchSize(s2);
116                         break;
117                 case kL1JetHigh:
118                 case kL1JetLow:
119                         SetSubRegionSize(s3);
120                         SetPatchSize(s4);
121                         break;
122                 default:
123                         AliError("Not supported L1 trigger type");
124                         return;
125                         break;
126         }
127         
128         SlidingWindow(GetThreshold(type));      
129         AliDebug(999, Form("STU type %d sliding window w/ thr %d found %d patches", type, GetThreshold(type), fPatches->GetEntriesFast()));
130 }
131
132 //___________
133 void AliEMCALTriggerSTU::ComputeThFromV0(int type, const Int_t M[])
134 {
135         // Compute threshold from V0
136         
137         Short_t P[3] = {0};
138         
139         switch (type)
140         {
141                 case kL1GammaHigh:
142                         P[0] = fDCSConfig->GetG(0, 0);
143                         P[1] = fDCSConfig->GetG(1, 0);
144                         P[2] = fDCSConfig->GetG(2, 0);                  
145                         break;
146                 case kL1GammaLow:
147                         P[0] = fDCSConfig->GetG(0, 1);
148                         P[1] = fDCSConfig->GetG(1, 1);
149                         P[2] = fDCSConfig->GetG(2, 1);                  
150                         break;
151                 case kL1JetHigh:
152                         P[0] = fDCSConfig->GetJ(0, 0);
153                         P[1] = fDCSConfig->GetJ(1, 0);
154                         P[2] = fDCSConfig->GetJ(2, 0);                  
155                         break;
156                 case kL1JetLow:
157                         P[0] = fDCSConfig->GetJ(0, 1);
158                         P[1] = fDCSConfig->GetJ(1, 1);
159                         P[2] = fDCSConfig->GetJ(2, 1);                  
160                         break;
161                 default:
162                         AliError("AliEMCALTriggerSTU::ComputeThFromV0(): Undefined trigger type, pls check!");
163                         return;
164         }
165         
166         ULong64_t v0sum = M[0] + M[1];
167         
168         ULong64_t sqrV0 = v0sum * v0sum;
169         
170         sqrV0 *= P[0];  
171         
172         sqrV0 >>= 32;
173         
174         v0sum *= P[1];
175         
176         v0sum >>= 16;
177         
178         SetThreshold(type, (UShort_t)(sqrV0 + v0sum + P[2]));
179 }
180
181 //___________
182 void AliEMCALTriggerSTU::SetThreshold(int type, Int_t v)
183 {
184         // Set threshold
185         
186         switch (type)
187         {
188                 case kL1GammaHigh:
189                         fGammaTh[0] = v;
190                         break;
191                 case kL1GammaLow:
192                         fGammaTh[1] = v;
193                         break;
194                 case kL1JetHigh:
195                         fJetTh[0] = v;          
196                         break;
197                 case kL1JetLow:
198                         fJetTh[1] = v;          
199                         break;
200                 default:
201                         AliError("AliEMCALTriggerSTU::SetThreshold(): Undefined trigger type, pls check!");
202         }
203 }
204
205 //___________
206 Int_t AliEMCALTriggerSTU::GetThreshold(int type)
207 {       
208         // Compute threshold FIXME: need an access to the OCDB
209         // to get f(V0) parameters depending on trigger type
210         
211         switch (type)
212         {
213                 case kL1GammaHigh:
214                         return fGammaTh[0];
215                         break;
216                 case kL1GammaLow:
217                         return fGammaTh[1];
218                         break;
219                 case kL1JetHigh:
220                         return fJetTh[0];               
221                         break;
222                 case kL1JetLow:
223                         return fJetTh[1];               
224                         break;
225                 default:
226                         AliError("AliEMCALTriggerSTU::GetThreshold(): Undefined trigger type, pls check!");
227         }
228         
229         return 0;
230 }
231
232 //__________
233 void AliEMCALTriggerSTU::Reset()
234 {
235         // Reset
236         
237         fPatches->Delete();
238 }