AliRoot Core  3dc7879 (3dc7879)
AliEMCALTriggerSTU.cxx
Go to the documentation of this file.
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 #include "AliEMCALTriggerSTU.h"
17 #include "AliCDBManager.h"
18 #include "AliCDBEntry.h"
20 #include "AliVZEROCalibData.h"
21 #include "AliVZEROdigit.h"
22 #include "AliEMCALTriggerPatch.h"
23 #include "AliESDVZERO.h"
24 #include "AliLog.h"
25 
26 #include <TClonesArray.h>
27 #include <TSystem.h>
28 #include <TH2F.h>
29 #include <TFile.h>
30 #include <TTree.h>
31 
32 #include <fstream>
33 #include <Riostream.h>
34 #include <cstdlib>
35 
37 ClassImp(AliEMCALTriggerSTU) ;
39 
42 //_______________
44 ,fDCSConfig(0x0)
45 ,fActive(true)
46 {
47  fGammaTh[0] = fGammaTh[1] = 0;
48  fJetTh[0] = fJetTh[1] = 0;
49  fBkgRho = 0;
50 }
51 
54 //_______________
56 ,fDCSConfig(dcsConf)
57 ,fActive(true)
58 {
59  fGammaTh[0] = fGammaTh[1] = 0;
60  fJetTh[0] = fJetTh[1] = 0;
61  fBkgRho = 0;
62 }
63 
66 //_______________
68 {
69  fBkgRho = 0;
70 }
71 
74 //_______________
75 void AliEMCALTriggerSTU::Build( TString& str, Int_t iTRU, Int_t** M, const TVector2* rSize, Int_t triggerMapping = 1)
76 {
77  str.ToLower();
78 
79  Int_t ix,iy;
80 
81  switch (triggerMapping + 3*(iTRU >= 32)) {
82  case 1:
83  // Run 1 Geometry
84  ix = iTRU / 2; // Round down to even.
85  ix = 4 * ix; // Every two TRUs add 4 modules
86  iy = (iTRU % 2) ? 24 : 0; // if odd, start at iEta = 24
87  break;
88  case 2:
89  // Run 2 EMCAL Geometry
90  ix = iTRU / 6; // ix = number of rows above.
91  ix = 12 * ix; // Each row adds 12 modules
92  iy = 8 * (iTRU % 6);
93  if ((iTRU == 30) || (iTRU == 31)) iy = 24 * (iTRU % 2); // EMCAL 1/3 SM TRUs
94  break;
95  case 4:
96  AliFatal("EMCAL STU object tried to use run 1 trigger mapping with a DCAL TRU");
97  case 5:
98  iTRU -= 32;
99  // Run2 DCAL Geometry
100  // If using iTRU corresponding to virtual TRU index:
101  ix = iTRU / 6; // ix = number of rows above
102  ix = ix * 12; // Each row adds 12 modules
103  iy = iTRU % 6; // iy = 0,1,2,3,4,5
104  iy = iy * 8 ; // each TRU adds 8.
105 
106  if ((iTRU == 18) || (iTRU == 19)) iy = (iTRU % 2) * 24; // DCAL 1/3 SM TRUs
107  break;
108  default:
109  AliFatal("EMCAL STU object tried an unknown combination of Trigger Mapping and TRU index");
110  }
111 
112 
113  Int_t** v = 0x0;
114 
115  if (str.Contains("map"))
116  {
117  v = fMap;
118  }
119  else if (str.Contains("region"))
120  {
121  v = fRegion;
122  }
123  else
124  {
125  AliError("Operation not allowed: STU won't be configured properly!");
126  }
127 
128  if(v){
129  for (Int_t i=0; i<rSize->X(); i++)
130  for (Int_t j=0; j<rSize->Y(); j++) {
131  v[i + ix][j + iy] = M[i][j];
132  }
133  }
134 }
135 
138 //_______________
140 {
141  if(!fActive) return; // Don't simulate L1 for inactive STUs
142  TVector2 s1, s2, s3, s4;
143  fDCSConfig->GetSegmentation(s1, s2, s3, s4);
144  Int_t fBkg = 0;
145  switch (type)
146  {
147  case kL1GammaHigh:
148  case kL1GammaLow:
149  SetSubRegionSize(s1);
150  SetPatchSize(s2);
151  break;
152  case kL1JetHigh:
153  case kL1JetLow:
154  SetSubRegionSize(s3);
155  SetPatchSize(s4);
156  fBkg = fBkgRho * (PatchSize()->X() * PatchSize()->Y() / 4);
157  break;
158  default:
159  AliError("Not supported L1 trigger type");
160  return;
161  break;
162  }
163  AliDebug(999,Form("STU L1 (type %d) using subregion size (%d,%d), patch size (%d,%d)\n",type,int(SubRegionSize()->X()),int(SubRegionSize()->Y()),int(PatchSize()->X()),int(PatchSize()->Y())));
164  AliDebug(999,Form("STU L1 subtracting Bkg = %d\n",fBkg));
165 
166  if (GetThreshold(type) == 0) {
167  AliDebug(999,Form("STU has 0 threshold for type %d. Skipping this trigger calculation. Check OCDB!!!",type));
168  return; // Don't execute trigger with 0 threshold.
169  }
170 
171  SlidingWindow(GetThreshold(type) + fBkg);
172  AliDebug(999, Form("STU type %d sliding window w/ thr %d found %d patches", type, GetThreshold(type)+ fBkgRho * int(PatchSize()->X() * PatchSize()->Y() / 4.), fPatches->GetEntriesFast()));
173 }
174 
177 //___________
178 void AliEMCALTriggerSTU::ComputeThFromV0(int type, const Int_t M[])
179 {
180  Short_t P[3] = {0};
181 
182  switch (type)
183  {
184  case kL1GammaHigh:
185  P[0] = fDCSConfig->GetG(0, 0);
186  P[1] = fDCSConfig->GetG(1, 0);
187  P[2] = fDCSConfig->GetG(2, 0);
188  break;
189  case kL1GammaLow:
190  P[0] = fDCSConfig->GetG(0, 1);
191  P[1] = fDCSConfig->GetG(1, 1);
192  P[2] = fDCSConfig->GetG(2, 1);
193  break;
194  case kL1JetHigh:
195  P[0] = fDCSConfig->GetJ(0, 0);
196  P[1] = fDCSConfig->GetJ(1, 0);
197  P[2] = fDCSConfig->GetJ(2, 0);
198  break;
199  case kL1JetLow:
200  P[0] = fDCSConfig->GetJ(0, 1);
201  P[1] = fDCSConfig->GetJ(1, 1);
202  P[2] = fDCSConfig->GetJ(2, 1);
203  break;
204  default:
205  AliError("AliEMCALTriggerSTU::ComputeThFromV0(): Undefined trigger type, pls check!");
206  return;
207  }
208 
209  ULong64_t v0sum = M[0] + M[1];
210 
211  ULong64_t sqrV0 = v0sum * v0sum;
212 
213  sqrV0 *= P[0];
214 
215  sqrV0 >>= 32;
216 
217  v0sum *= P[1];
218 
219  v0sum >>= 16;
220 
221  SetThreshold(type, (UShort_t)(sqrV0 + v0sum + P[2]));
222 }
223 
226 //___________
227 void AliEMCALTriggerSTU::SetThreshold(int type, Int_t v)
228 {
229  switch (type)
230  {
231  case kL1GammaHigh:
232  fGammaTh[0] = v;
233  break;
234  case kL1GammaLow:
235  fGammaTh[1] = v;
236  break;
237  case kL1JetHigh:
238  fJetTh[0] = v;
239  break;
240  case kL1JetLow:
241  fJetTh[1] = v;
242  break;
243  default:
244  AliError("AliEMCALTriggerSTU::SetThreshold(): Undefined trigger type, pls check!");
245  }
246 }
247 
252 //___________
254 {
255  switch (type)
256  {
257  case kL1GammaHigh:
258  return fGammaTh[0];
259  break;
260  case kL1GammaLow:
261  return fGammaTh[1];
262  break;
263  case kL1JetHigh:
264  return fJetTh[0];
265  break;
266  case kL1JetLow:
267  return fJetTh[1];
268  break;
269  default:
270  AliError("AliEMCALTriggerSTU::GetThreshold(): Undefined trigger type, pls check!");
271  }
272 
273  return 0;
274 }
275 
278 //___________
280 
281  // iterate over non-overlaping set of (8x8 tower) subregions
282  // 4x4 FastOR units
283  const int kPatchXSize = 8; // How many FastOR units in X
284  const int kPatchYSize = 8; // How many FastOR units in Y
285 
286  std::vector<int> fPatchEnergies ;
287  // How many columns and rows in energy patches.
288  int nX = (int) fRegionSize->X()/kPatchXSize;
289  int nY = (int) fRegionSize->Y()/kPatchYSize;
290 
291  Bool_t fZeroPHOS = (fDCSConfig->GetFw() & 0xffff) == 0xd007; // Whether to ignore PHOS patches
292 
293  for (int i = 0; i < nX; i++) {
294  for (int j = 0; j < nY; j++) {
295  if (fZeroPHOS && (j == 2 || j == 3)) continue; // Skip middle 10 patches
296  int fLocalSum = 0;
297  int fXAnchor = i * kPatchXSize;
298  int fYAnchor = j * kPatchYSize;
299  for (int k = 0; k < kPatchXSize; k++) {
300  for (int l = 0; l < kPatchYSize; l++) {
301  fLocalSum += fRegion[fXAnchor+k][fYAnchor+l];
302  }
303  }
304  fPatchEnergies.push_back(fLocalSum);
305  }
306  }
307  sort(fPatchEnergies.begin(),fPatchEnergies.end());
308  // If EMCAL, use 24th.
309  // If DCAL, use 15th. If DCAL without PHOS, use 10th.
310 
311  // Note: this is proper only for an even number of patches
312  // Technically, this is the median excluding the highest patch
313  return fPatchEnergies.at(fPatchEnergies.size()/2-1);
314 }
315 
318 //__________
320 {
321  fPatches->Delete();
322 }
Int_t ** fRegion
! add comment
Int_t fGammaTh[2]
Gamma threshold.
virtual ~AliEMCALTriggerSTU()
Destructor.
virtual TVector2 * PatchSize() const
virtual TVector2 * SubRegionSize() const
TClonesArray * fPatches
! add comment
Int_t GetJ(int vzpar, int ithresh) const
Bool_t fActive
Active status for STU, if inactive the L1 trigger will not be simulated.
AliEMCALTriggerSTUDCSConfig * fDCSConfig
Int_t fJetTh[2]
Jet threshold.
Int_t GetG(int vzpar, int ithresh) const
EMCal trigger board super class.
#define M(PID)
Definition: AliPID.cxx:49
virtual void Build(TString &str, Int_t i, Int_t **Map, const TVector2 *rSize, Int_t triggerMapping)
Build.
AliEMCALTriggerSTU()
Default constructor.
void GetSegmentation(TVector2 &v1, TVector2 &v2, TVector2 &v3, TVector2 &v4) const
Get Segmentation.
EMCal trigger STU handling.
virtual Int_t GetMedianEnergy()
Calculate median energy of patches.
EMCal trigger STU DCS Config.
Int_t fBkgRho
BkgRho for L1 calculation. Calculated from the other STU.
virtual void SetSubRegionSize(const TVector2 &Size)
#define AliFatal(message)
Definition: AliLog.h:640
virtual void SetPatchSize(const TVector2 &Size)
virtual void ComputeThFromV0(int type, const Int_t M[])
Compute threshold from V0.
#define AliDebug(logLevel, message)
Definition: AliLog.h:300
virtual Int_t GetThreshold(int type)
virtual void Reset()
Reset.
Int_t ** fMap
! Map the position to digit index (which eq. to ADC channel)
#define AliError(message)
Definition: AliLog.h:591
virtual void SetThreshold(int type, Int_t v)
Set threshold.
TVector2 * fRegionSize
! in FastOR unit
virtual void L1(int type)
L1.
virtual void SlidingWindow(Int_t Threshold)
Sliding window algo.