AliPhysics  97344c9 (97344c9)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalTriggerMakerKernel.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2015, 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 #include <iostream>
16 #include <vector>
17 #include <cstring>
18 #include <fstream>
19 
20 #include <TArrayI.h>
21 #include <TF1.h>
22 #include <TObjArray.h>
23 #include <TRandom.h>
24 
25 #include "AliAODCaloTrigger.h"
26 #include "AliEMCALGeometry.h"
27 #include "AliEMCALTriggerConstants.h"
28 #include "AliEMCALTriggerDataGrid.h"
30 #include "AliEMCALTriggerPatchFinder.h"
31 #include "AliEMCALTriggerAlgorithm.h"
32 #include "AliEMCALTriggerRawPatch.h"
35 #include "AliLog.h"
36 #include "AliVCaloCells.h"
37 #include "AliVCaloTrigger.h"
38 #include "AliVEvent.h"
39 #include "AliVVZERO.h"
40 
44 
46  TObject(),
47  fBadChannels(),
48  fOfflineBadChannels(),
49  fFastORPedestal(5000),
50  fTriggerBitConfig(nullptr),
51  fPatchFinder(nullptr),
52  fLevel0PatchFinder(nullptr),
53  fL0MinTime(7),
54  fL0MaxTime(10),
55  fMinCellAmp(0),
56  fMinL0FastORAmp(0),
57  fMinL1FastORAmp(0),
58  fBkgThreshold(-1),
59  fL0Threshold(0),
60  fIsMC(kFALSE),
61  fDebugLevel(0),
62  fMinCellAmplitude(0.),
63  fApplyOnlineBadChannelsToOffline(kFALSE),
64  fConfigured(kFALSE),
65  fSmearModelMean(nullptr),
66  fSmearModelSigma(nullptr),
67  fSmearThreshold(0.1),
68  fGeometry(nullptr),
69  fPatchAmplitudes(nullptr),
70  fPatchADCSimple(nullptr),
71  fPatchADC(nullptr),
72  fPatchEnergySimpleSmeared(nullptr),
73  fLevel0TimeMap(nullptr),
74  fTriggerBitMap(nullptr),
75  fADCtoGeV(1.)
76 {
77  memset(fThresholdConstants, 0, sizeof(Int_t) * 12);
78  memset(fL1ThresholdsOffline, 0, sizeof(ULong64_t) * 4);
79  fCellTimeLimits[0] = -10000.;
80  fCellTimeLimits[1] = 10000.;
81 }
82 
84  delete fPatchAmplitudes;
85  delete fPatchADCSimple;
86  delete fPatchADC;
88  delete fLevel0TimeMap;
89  delete fTriggerBitMap;
90  delete fPatchFinder;
91  delete fLevel0PatchFinder;
93 }
94 
96  if (!fTriggerBitConfig) {
97  AliWarning("Trigger bit configuration was not provided! Assuming new bit configuration (>= 2013).");
98  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigNew();
99  SetTriggerBitConfig(triggerBitConfig);
100  }
101 
107 
108  // Allocate containers for the ADC values
109  int nrows = fGeometry->GetNTotalTRU() * 2;
110  std::cout << "Allocating channel grid with 48 columns in eta and " << nrows << " rows in phi" << std::endl;
111  fPatchAmplitudes->Allocate(48, nrows);
112  fPatchADC->Allocate(48, nrows);
113  fPatchADCSimple->Allocate(48, nrows);
114  fLevel0TimeMap->Allocate(48, nrows);
115  fTriggerBitMap->Allocate(48, nrows);
116 
118  // Allocate container for energy smearing (if enabled)
120  fPatchEnergySimpleSmeared->Allocate(48, nrows);
121  }
122 }
123 
124 void AliEmcalTriggerMakerKernel::AddL1TriggerAlgorithm(Int_t rowmin, Int_t rowmax, UInt_t bitmask, Int_t patchSize, Int_t subregionSize)
125 {
127  AliEMCALTriggerAlgorithm<double> *trigger = new AliEMCALTriggerAlgorithm<double>(rowmin, rowmax, bitmask);
128  trigger->SetPatchSize(patchSize);
129  trigger->SetSubregionSize(subregionSize);
130  fPatchFinder->AddTriggerAlgorithm(trigger);
131 }
132 
133 void AliEmcalTriggerMakerKernel::SetL0TriggerAlgorithm(Int_t rowmin, Int_t rowmax, UInt_t bitmask, Int_t patchSize, Int_t subregionSize)
134 {
136  fLevel0PatchFinder = new AliEMCALTriggerAlgorithm<double>(rowmin, rowmax, bitmask);
137  fLevel0PatchFinder->SetPatchSize(patchSize);
138  fLevel0PatchFinder->SetSubregionSize(subregionSize);
139 }
140 
142 {
143  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigNew();
144  SetTriggerBitConfig(triggerBitConfig);
145 
146  // Initialize patch finder
147  if (fPatchFinder) delete fPatchFinder;
149 
150  SetL0TriggerAlgorithm(0, 103, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
151  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
152  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
153  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit() | 1<<fTriggerBitConfig->GetBkgBit(), 8, 4);
154  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit() | 1<<fTriggerBitConfig->GetBkgBit(), 8, 4);
155  fConfigured = true;
156 }
157 
159 {
160  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigNew();
161  SetTriggerBitConfig(triggerBitConfig);
162 
163  // Initialize patch finder
164  if (fPatchFinder) delete fPatchFinder;
166 
167  SetL0TriggerAlgorithm(0, 103, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
168  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
169  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
170  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit(), 16, 4);
171  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit(), 16, 4);
172  fConfigured = true;
173 }
174 
176 {
177  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigNew();
178  SetTriggerBitConfig(triggerBitConfig);
179 
180  // Initialize patch finder
181  if (fPatchFinder) delete fPatchFinder;
183 
184  SetL0TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
185  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
186  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit(), 16, 4);
187  fConfigured = true;
188 }
189 
191 {
192  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigOld();
193  SetTriggerBitConfig(triggerBitConfig);
194 
195  // Initialize patch finder
196  if (fPatchFinder) delete fPatchFinder;
198 
199  SetL0TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
200  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit(), 2, 1);
201  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit(), 16, 4);
202  fConfigured = true;
203 }
204 
206 {
207  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigOld();
208  SetTriggerBitConfig(triggerBitConfig);
209 
210  // Initialize patch finder
211  if (fPatchFinder) delete fPatchFinder;
213 
214  SetL0TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
215  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit(), 2, 1);
216  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit(), 16, 4);
217  fConfigured = true;
218 }
219 
221 {
222  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigOld();
223  SetTriggerBitConfig(triggerBitConfig);
224 
225  // Initialize patch finder
226  if (fPatchFinder) delete fPatchFinder;
228 
229  SetL0TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
230  fConfigured = true;
231 }
232 
234 {
235  Short_t absId = 0;
236 
237  while (stream.good()) {
238  stream >> absId;
239  AddOfflineBadChannel(absId);
240  }
241 }
242 
244 {
245  std::ifstream file(fname);
247 }
248 
250 {
251  Short_t absId = -1;
252 
253  while (stream.good()) {
254  stream >> absId;
255  AddFastORBadChannel(absId);
256  }
257 }
258 
260 {
261  std::ifstream file(fname);
263 }
264 
266 {
267  if (absId < 0 || absId >= fFastORPedestal.GetSize()) {
268  AliWarning(Form("Abs. ID %d out of range (0,5000)", absId));
269  return;
270  }
271  fFastORPedestal[absId] = ped;
272 }
273 
275 {
276  Short_t absId = 0;
277  Float_t ped = 0;
278  while (stream.good()) {
279  stream >> ped;
280  SetFastORPedestal(absId, ped);
281  absId++;
282  }
283 }
284 
286 {
287  std::ifstream file(fname);
289 }
290 
292  fPatchAmplitudes->Reset();
293  fPatchADC->Reset();
294  fPatchADCSimple->Reset();
295  fLevel0TimeMap->Reset();
296  fTriggerBitMap->Reset();
298  memset(fL1ThresholdsOffline, 0, sizeof(ULong64_t) * 4);
299 }
300 
301 void AliEmcalTriggerMakerKernel::ReadTriggerData(AliVCaloTrigger *trigger){
302  trigger->Reset();
303  Int_t globCol=-1, globRow=-1;
304  Int_t adcAmp=-1, bitmap = 0;
305  while(trigger->Next()){
306  // get position in global 2x2 tower coordinates
307  // A0 left bottom (0,0)
308  trigger->GetPosition(globCol, globRow);
309  Int_t absId = -1;
310  fGeometry->GetAbsFastORIndexFromPositionInEMCAL(globCol, globRow, absId);
311 
312  // trigger bits can also occur on online masked fastors. Therefore trigger
313  // bits are handled before ADC values, and independently whether fastor is
314  // masked or not
315  trigger->GetTriggerBits(bitmap);
316  try {
317  (*fTriggerBitMap)(globCol, globRow) = bitmap;
318  }
320  std::string dirstring = e.GetDirection() == AliEMCALTriggerDataGrid<int>::OutOfBoundsException::kColDir ? "Col" : "Row";
321  AliErrorStream() << "Trigger maker task - filling trigger bit grid - index out-of-bounds in " << dirstring << ": " << e.GetIndex() << std::endl;
322  }
323 
324  // also Level0 times need to be handled without masking of the fastor ...
325  // @TODO cross check
326  Int_t nl0times(0);
327  trigger->GetNL0Times(nl0times);
328  if(nl0times){
329  TArrayI l0times(nl0times);
330  trigger->GetL0Times(l0times.GetArray());
331  for(int itime = 0; itime < nl0times; itime++){
332  try{
333  (*fLevel0TimeMap)(globCol,globRow) = static_cast<Char_t>(l0times[itime]);
334  break;
335  }
337  std::string dirstring = e.GetDirection() == AliEMCALTriggerDataGrid<char>::OutOfBoundsException::kColDir ? "Col" : "Row";
338  AliErrorStream() << "Trigger maker task - filling trigger bit grid - index out-of-bounds in " << dirstring << ": " << e.GetIndex() << std::endl;
339  }
340  }
341  }
342 
343  // exclude channel completely if it is masked as hot channel
344  if (fBadChannels.find(absId) != fBadChannels.end()){
345  AliDebugStream(1) << "Found ADC for masked fastor " << absId << ", rejecting" << std::endl;
346  continue;
347  }
348  // for some strange reason some ADC amps are initialized in reconstruction
349  // as -1, neglect those
350  trigger->GetL1TimeSum(adcAmp);
351  if (adcAmp < 0) adcAmp = 0;
352 
353  if (adcAmp >= fMinL1FastORAmp) {
354  try {
355  (*fPatchADC)(globCol,globRow) = adcAmp;
356  }
358  std::string dirstring = e.GetDirection() == AliEMCALTriggerDataGrid<double>::OutOfBoundsException::kColDir ? "Col" : "Row";
359  AliErrorStream() << "Trigger maker task - filling trigger bit grid - index out-of-bounds in " << dirstring << ": " << e.GetIndex() << std::endl;
360  }
361  }
362 
363  // Handling for L0 triggers
364  // For the ADC value we use fCaloTriggers->GetAmplitude()
365  // In data, all patches which have 4 TRUs with proper level0 times are
366  // valid trigger patches. Therefore we need to check all neighbors for
367  // the level0 times, not only the bottom left. In order to obtain this
368  // information, a lookup table with the L0 times for each TRU is created
369  Float_t amplitude(0);
370  trigger->GetAmplitude(amplitude);
371  amplitude *= 4; // values are shifted by 2 bits to fit in a 10 bit word (on the hardware side)
372  amplitude -= fFastORPedestal[absId];
373  if(amplitude < 0) amplitude = 0;
374  if (amplitude >= fMinL0FastORAmp) {
375  try{
376  (*fPatchAmplitudes)(globCol,globRow) = amplitude;
377  }
379  std::string dirstring = e.GetDirection() == AliEMCALTriggerDataGrid<int>::OutOfBoundsException::kColDir ? "Col" : "Row";
380  AliErrorStream() << "Trigger maker task - filling trigger bit grid - index out-of-bounds in " << dirstring << ": " << e.GetIndex() << std::endl;
381  }
382  }
383  }
384 }
385 
386 void AliEmcalTriggerMakerKernel::ReadCellData(AliVCaloCells *cells){
387  // fill the patch ADCs from cells
388  Int_t nCell = cells->GetNumberOfCells();
389  for(Int_t iCell = 0; iCell < nCell; ++iCell) {
390  // get the cell info, based in index in array
391  Short_t cellId = cells->GetCellNumber(iCell);
392 
393  // Check bad channel map
394  if (fOfflineBadChannels.find(cellId) != fOfflineBadChannels.end()) {
395  AliDebugStream(1) << "Cell " << cellId << " masked as bad channel, rejecting." << std::endl;
396  continue;
397  }
398 
399  Double_t amp = cells->GetAmplitude(iCell),
400  celltime = cells->GetTime(iCell);
401  if(celltime < fCellTimeLimits[0] || celltime > fCellTimeLimits[1]) continue;
402  if(amp < fMinCellAmplitude) continue;
403  // get position
404  Int_t absId=-1;
405  fGeometry->GetFastORIndexFromCellIndex(cellId, absId);
407  // Exclude FEE amplitudes from cells which are within a TRU which is masked at
408  // online level. Using this the online acceptance can be applied to offline
409  // patches as well.
410  if(fBadChannels.find(absId) != fBadChannels.end()){
411  AliDebugStream(1) << "Cell " << cellId << " corresponding to masked fastor " << absId << ", rejecting." << std::endl;
412  continue;
413  }
414  }
415  Int_t globCol=-1, globRow=-1;
416  fGeometry->GetPositionInEMCALFromAbsFastORIndex(absId, globCol, globRow);
417  // add
418  amp /= fADCtoGeV;
419  try {
420  if (amp >= fMinCellAmp) (*fPatchADCSimple)(globCol,globRow) += amp;
421  }
423  }
424  }
425 
426  // Apply energy smearing (if enabled)
428  AliDebugStream(1) << "Trigger Maker: Apply energy smearing" << std::endl;
429  for(int icol = 0; icol < fPatchADCSimple->GetNumberOfCols(); icol++){
430  for(int irow = 0; irow < fPatchADCSimple->GetNumberOfRows(); irow++){
431  double energyorig = (*fPatchADCSimple)(icol, irow) * fADCtoGeV; // Apply smearing in GeV
432  double energysmear = energyorig;
433  if(energyorig > fSmearThreshold){
434  double mean = fSmearModelMean->Eval(energyorig), sigma = fSmearModelSigma->Eval(energyorig);
435  energysmear = gRandom->Gaus(mean, sigma);
436  if(energysmear < 0) energysmear = 0; // only accept positive or 0 energy values
437  AliDebugStream(1) << "Original energy " << energyorig << ", mean " << mean << ", sigma " << sigma << ", smeared " << energysmear << std::endl;
438  }
439  (*fPatchEnergySimpleSmeared)(icol, irow) = energysmear;
440  }
441  }
442  AliDebugStream(1) << "Smearing done" << std::endl;
443  }
444 }
445 
447  // get the V0 value and compute and set the offline thresholds
448  // get V0, compute thresholds and save them as global parameters
449  ULong64_t v0S = vzerodata->GetTriggerChargeA() + vzerodata->GetTriggerChargeC();
450  for (Int_t i = 0; i < 4; ++i) {
451  // A*V0^2/2^32+B*V0/2^16+C
452  fL1ThresholdsOffline[i]= ( ((ULong64_t)fThresholdConstants[i][0]) * v0S * v0S ) >> 32;
453  fL1ThresholdsOffline[i] += ( ((ULong64_t)fThresholdConstants[i][1]) * v0S ) >> 16;
454  fL1ThresholdsOffline[i] += ((ULong64_t)fThresholdConstants[i][2]);
455  }
456 }
457 
458 TObjArray *AliEmcalTriggerMakerKernel::CreateTriggerPatches(const AliVEvent *inputevent, Bool_t useL0amp){
459  //std::cout << "Finding trigger patches" << std::endl;
460  //AliEMCALTriggerPatchInfo *trigger, *triggerMainJet, *triggerMainGamma, *triggerMainLevel0;
461  //AliEMCALTriggerPatchInfo *triggerMainJetSimple, *triggerMainGammaSimple;
462 
463  if (useL0amp) {
465  }
466  else {
467  fADCtoGeV = EMCALTrigger::kEMCL1ADCtoGeV;
468  }
469 
470  Double_t vertexpos[3];
471  inputevent->GetPrimaryVertex()->GetXYZ(vertexpos);
472  TVector3 vertexvec(vertexpos);
473 
474  Int_t isMC = fIsMC ? 1 : 0;
475  Int_t offset = (1 - isMC) * fTriggerBitConfig->GetTriggerTypesEnd();
476 
477  // Create trigger bit masks. They are needed later to remove
478  // trigger bits from the trigger bit mask for non-matching patch types
479  Int_t jetPatchMask = 1 << fTriggerBitConfig->GetJetHighBit()
480  | 1 << fTriggerBitConfig->GetJetLowBit()
481  | 1 << (fTriggerBitConfig->GetJetHighBit() + fTriggerBitConfig->GetTriggerTypesEnd())
482  | 1 << (fTriggerBitConfig->GetJetLowBit() + fTriggerBitConfig->GetTriggerTypesEnd()),
483  gammaPatchMask = 1 << fTriggerBitConfig->GetGammaHighBit()
484  | 1 << fTriggerBitConfig->GetGammaLowBit()
485  | 1 << (fTriggerBitConfig->GetGammaHighBit() + fTriggerBitConfig->GetTriggerTypesEnd())
486  | 1 << (fTriggerBitConfig->GetGammaLowBit() + fTriggerBitConfig->GetTriggerTypesEnd()),
487  bkgPatchMask = 1 << fTriggerBitConfig->GetBkgBit();
488  //l0PatchMask = 1 << fTriggerBitConfig->GetLevel0Bit();
489 
490  std::vector<AliEMCALTriggerRawPatch> patches;
491  if (fPatchFinder) {
492  if (useL0amp) {
493  patches = fPatchFinder->FindPatches(*fPatchAmplitudes, *fPatchADCSimple);
494  }
495  else {
496  patches = fPatchFinder->FindPatches(*fPatchADC, *fPatchADCSimple);
497  }
498  }
499  TObjArray *result = new TObjArray(1000);
500  result->SetOwner(kTRUE);
501  for(std::vector<AliEMCALTriggerRawPatch>::iterator patchit = patches.begin(); patchit != patches.end(); ++patchit){
502  // Apply offline and recalc selection
503  // Remove unwanted bits from the online bits (gamma bits from jet patches and vice versa)
504  Int_t offlinebits = 0, onlinebits = (*fTriggerBitMap)(patchit->GetColStart(), patchit->GetRowStart());
505  if(HasPHOSOverlap(*patchit)) continue;
506  if(IsGammaPatch(*patchit)){
507  if(patchit->GetADC() > fL1ThresholdsOffline[1]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetGammaHighBit());
508  if(patchit->GetOfflineADC() > fL1ThresholdsOffline[1]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetGammaHighBit());
509  if(patchit->GetADC() > fL1ThresholdsOffline[3]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetGammaLowBit());
510  if(patchit->GetOfflineADC() > fL1ThresholdsOffline[3]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetGammaLowBit());
511  onlinebits &= gammaPatchMask;
512  }
513  if (IsJetPatch(*patchit)){
514  if(patchit->GetADC() > fL1ThresholdsOffline[0]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetJetHighBit());
515  if(patchit->GetOfflineADC() > fL1ThresholdsOffline[0]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetJetHighBit());
516  if(patchit->GetADC() > fL1ThresholdsOffline[2]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetJetLowBit());
517  if(patchit->GetOfflineADC() > fL1ThresholdsOffline[2]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetJetLowBit());
518  onlinebits &= jetPatchMask;
519  }
520  if (IsBkgPatch(*patchit)){
521  if(patchit->GetADC() > fBkgThreshold) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetBkgBit());
522  if(patchit->GetOfflineADC() > fBkgThreshold) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetBkgBit());
523  onlinebits &= bkgPatchMask;
524  }
525  // convert
526  AliEMCALTriggerPatchInfoV1 *fullpatch = AliEMCALTriggerPatchInfoV1::CreateAndInitializeV1(patchit->GetColStart(), patchit->GetRowStart(),
527  patchit->GetPatchSize(), patchit->GetADC(), patchit->GetOfflineADC(), patchit->GetOfflineADC() * fADCtoGeV,
528  onlinebits | offlinebits, vertexvec, fGeometry);
529  fullpatch->SetTriggerBitConfig(fTriggerBitConfig);
530  fullpatch->SetOffSet(offset);
532  // Add smeared energy
533  double energysmear = 0;
534  for(int icol = 0; icol < fullpatch->GetPatchSize(); icol++){
535  for(int irow = 0; irow < fullpatch->GetPatchSize(); irow++){
536  energysmear += (*fPatchEnergySimpleSmeared)(fullpatch->GetColStart() + icol, fullpatch->GetRowStart() + irow);
537  }
538  }
539  AliDebugStream(1) << "Patch size(" << fullpatch->GetPatchSize() <<") energy " << fullpatch->GetPatchE() << " smeared " << energysmear << std::endl;
540  fullpatch->SetSmearedEnergyV1(energysmear);
541  }
542  result->Add(fullpatch);
543  }
544 
545  // Find Level0 patches
546  std::vector<AliEMCALTriggerRawPatch> l0patches;
547  if (fLevel0PatchFinder) l0patches = fLevel0PatchFinder->FindPatches(*fPatchAmplitudes, *fPatchADCSimple);
548  for(std::vector<AliEMCALTriggerRawPatch>::iterator patchit = l0patches.begin(); patchit != l0patches.end(); ++patchit){
549  Int_t offlinebits = 0, onlinebits = 0;
550  if(HasPHOSOverlap(*patchit)) continue;
551  ELevel0TriggerStatus_t L0status = CheckForL0(patchit->GetColStart(), patchit->GetRowStart());
552  if (L0status == kNotLevel0) continue;
553  if (L0status == kLevel0Fired) SETBIT(onlinebits, fTriggerBitConfig->GetLevel0Bit());
554  if (patchit->GetADC() > fL0Threshold) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetLevel0Bit());
555  if (patchit->GetOfflineADC() > fL0Threshold) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetLevel0Bit());
556 
557  AliEMCALTriggerPatchInfoV1 *fullpatch = AliEMCALTriggerPatchInfoV1::CreateAndInitializeV1(patchit->GetColStart(), patchit->GetRowStart(),
558  patchit->GetPatchSize(), patchit->GetADC(), patchit->GetOfflineADC(), patchit->GetOfflineADC() * fADCtoGeV,
559  onlinebits | offlinebits, vertexvec, fGeometry);
560  fullpatch->SetTriggerBitConfig(fTriggerBitConfig);
562  // Add smeared energy
563  double energysmear = 0;
564  for(int icol = 0; icol < fullpatch->GetPatchSize(); icol++){
565  for(int irow = 0; irow < fullpatch->GetPatchSize(); irow++){
566  energysmear += (*fPatchEnergySimpleSmeared)(fullpatch->GetColStart() + icol, fullpatch->GetRowStart() + irow);
567  }
568  }
569  fullpatch->SetSmearedEnergyV1(energysmear);
570  }
571  result->Add(fullpatch);
572  }
573  // std::cout << "Finished finding trigger patches" << std::endl;
574  return result;
575 }
576 
577 
579  double adc = 0;
580  try {
581  adc = (*fPatchADC)(col, row);
583 
584  }
585  return adc;
586 }
587 
589  double adc = 0;
590  try {
591  adc = (*fPatchADC)(col, row) * EMCALTrigger::kEMCL1ADCtoGeV;
593 
594  }
595  return adc;
596 }
597 
599  double adc = 0;
600  try {
601  adc = (*fPatchADCSimple)(col, row);
603 
604  }
605  return adc;
606 }
607 
609  double adc = 0;
610  try {
611  adc = (*fPatchADCSimple)(col, row) * fADCtoGeV;
613 
614  }
615  return adc;
616 }
617 
619  double adc = 0;
621  try {
622  adc = (*fPatchEnergySimpleSmeared)(col, row);
624 
625  }
626  }
627  return adc;
628 }
629 
631  return fPatchADC->GetNumberOfRows();
632 }
633 
636 
637  if(col < 0 || row < 0){
638  AliError(Form("Patch outside range [col %d, row %d]", col, row));
639  return kNotLevel0;
640  }
641  Int_t truref(-1), trumod(-1), absFastor(-1), adc(-1);
642  fGeometry->GetAbsFastORIndexFromPositionInEMCAL(col, row, absFastor);
643  fGeometry->GetTRUFromAbsFastORIndex(absFastor, truref, adc);
644  int nvalid(0);
645  const int kNRowsPhi = fGeometry->GetNTotalTRU() * 2;
646  for(int ipos = 0; ipos < 2; ipos++){
647  if(row + ipos >= kNRowsPhi) continue; // boundary check
648  for(int jpos = 0; jpos < 2; jpos++){
649  if(col + jpos >= kColsEta) continue; // boundary check
650  // Check whether we are in the same TRU
651  trumod = -1;
652  fGeometry->GetAbsFastORIndexFromPositionInEMCAL(col+jpos, row+ipos, absFastor);
653  fGeometry->GetTRUFromAbsFastORIndex(absFastor, trumod, adc);
654  if(trumod != truref) {
655  result = kNotLevel0;
656  return result;
657  }
658  if(col + jpos >= kColsEta) AliError(Form("Boundary error in col [%d, %d + %d]", col + jpos, col, jpos));
659  if(row + ipos >= kNRowsPhi) AliError(Form("Boundary error in row [%d, %d + %d]", row + ipos, row, ipos));
660  Char_t l0times = (*fLevel0TimeMap)(col + jpos,row + ipos);
661  if(l0times > fL0MinTime && l0times < fL0MaxTime) nvalid++;
662  }
663  }
664  if (nvalid == 4) result = kLevel0Fired;
665  return result;
666 }
667 
669  fBadChannels.clear();
670 }
671 
673  fOfflineBadChannels.clear();
674 }
675 
676 Bool_t AliEmcalTriggerMakerKernel::IsGammaPatch(const AliEMCALTriggerRawPatch &patch) const {
677  ULong_t bitmask = patch.GetBitmask(), testmask = 1 << fTriggerBitConfig->GetGammaHighBit() | 1 << fTriggerBitConfig->GetGammaLowBit();
678  return bitmask & testmask;
679 }
680 
681 Bool_t AliEmcalTriggerMakerKernel::IsJetPatch(const AliEMCALTriggerRawPatch &patch) const {
682  ULong_t bitmask = patch.GetBitmask(), testmask = 1 << fTriggerBitConfig->GetJetHighBit() | 1 << fTriggerBitConfig->GetJetLowBit();
683  return bitmask & testmask;
684 }
685 
686 Bool_t AliEmcalTriggerMakerKernel::IsBkgPatch(const AliEMCALTriggerRawPatch &patch) const {
687  ULong_t bitmask = patch.GetBitmask(), testmask = 1 << fTriggerBitConfig->GetBkgBit();
688  return bitmask & testmask;
689 }
690 
691 void AliEmcalTriggerMakerKernel::SetTriggerBitConfig(const AliEMCALTriggerBitConfig *const config) {
692  if (config == fTriggerBitConfig) return;
694  fTriggerBitConfig = config;
695 }
696 
697 bool AliEmcalTriggerMakerKernel::HasPHOSOverlap(const AliEMCALTriggerRawPatch &patch) const {
698  const int kEtaMinPhos = 16, kEtaMaxPhos = 31, kPhiMinPhos = 64, kPhiMaxPhos = 99;
699  if(patch.GetRowStart() + patch.GetPatchSize() -1 < kPhiMinPhos) return false; // EMCAL Patch
700  if(patch.GetRowStart() > kPhiMaxPhos) return false; // DCAL 1/3 supermodule
701  if(patch.GetColStart() + patch.GetPatchSize() -1 < kEtaMinPhos) return false;
702  if(patch.GetColStart() > kEtaMaxPhos) return false;
703  return true;
704 }
void Reset()
Reset all data grids and VZERO-dependent L1 thresholds.
Int_t fBkgThreshold
threshold for the background patches (8x8)
ELevel0TriggerStatus_t CheckForL0(Int_t col, Int_t row) const
Accept trigger patch as Level0 patch.
double Double_t
Definition: External.C:58
Double_t fCellTimeLimits[2]
Maximum allowed abs cell time (default [0] = - 10000, [1] = 10000)
Double_t fMinCellAmplitude
Minimum amplitude in cell required to be considered for filling the data grid.
Bool_t IsGammaPatch(const AliEMCALTriggerRawPatch &patch) const
Check from the bitmask whether the patch is a gamma patch.
void ConfigureForPbPb2015()
Configure the class for 2015 PbPb.
void ConfigureForPP2015()
Configure the class for 2015 pp.
Bool_t IsBkgPatch(const AliEMCALTriggerRawPatch &patch) const
Check from the bitmask whether the patch is a background patch.
char Char_t
Definition: External.C:18
TObjArray * CreateTriggerPatches(const AliVEvent *inputevent, Bool_t useL0amp=kFALSE)
Run patch finders on input data.
bool HasPHOSOverlap(const AliEMCALTriggerRawPatch &patch) const
AliEMCALTriggerDataGrid< int > * fTriggerBitMap
! Map of trigger bits
void ReadFastORBadChannelFromStream(std::istream &stream)
Read the FastOR bad channel map from a standard stream.
TArrayF fFastORPedestal
FastOR pedestal.
void AddFastORBadChannel(Short_t absId)
Add a FastOR bad channel to the list.
void SetTriggerBitConfig(const AliEMCALTriggerBitConfig *const config)
Set the trigger bit configuration applied for the given data set.
void ConfigureForPbPb2011()
Configure the class for 2011 PbPb.
Bool_t fConfigured
Switch specifying whether the trigger maker kernel has been configured for a given data set...
void Init()
Initialize the trigger maker Kernel.
Int_t fMinCellAmp
Minimum offline amplitude of the cells used to generate the patches.
void ClearFastORBadChannels()
Clear FastOR bad channel list.
TRandom * gRandom
void ConfigureForPP2011()
Configure the class for 2011 pp.
void ReadFastORBadChannelFromFile(const char *fname)
Read the FastOR bad channel map from a text file.
Bool_t fApplyOnlineBadChannelsToOffline
Apply online bad channels to offline ADC values.
void ReadTriggerData(AliVCaloTrigger *trigger)
Read the calo trigger data.
Int_t fMinL1FastORAmp
Minimum L1 amplitude of the FastORs used to generate the patches.
const AliEMCALTriggerBitConfig * fTriggerBitConfig
Trigger bit configuration, aliroot-dependent.
const AliEMCALGeometry * fGeometry
! Underlying EMCAL geometry
Double_t * sigma
ULong64_t fL1ThresholdsOffline[4]
container for V0-dependent offline thresholds
int Int_t
Definition: External.C:63
void ReadOfflineBadChannelFromFile(const char *fname)
Read the offline bad channel map from a text file.
unsigned int UInt_t
Definition: External.C:33
void ConfigureForPP2012()
Configure the class for 2012 pp.
Int_t fThresholdConstants[4][3]
simple offline trigger thresholds constants
float Float_t
Definition: External.C:68
virtual ~AliEmcalTriggerMakerKernel()
Destructor.
double GetTriggerChannelADC(Int_t col, Int_t row) const
Get ADC value of a given trigger channel (in col-row space)
Double_t fSmearThreshold
Smear threshold: Only cell energies above threshold are smeared.
Temporary class handling.
Double_t fADCtoGeV
! Conversion factor from ADC to GeV
void AddL1TriggerAlgorithm(Int_t rowmin, Int_t rowmax, UInt_t bitmask, Int_t patchSize, Int_t subregionSize)
void SetL0TriggerAlgorithm(Int_t rowmin, Int_t rowmax, UInt_t bitmask, Int_t patchSize, Int_t subregionSize)
Set the L0 algorithm.
void ReadOfflineBadChannelFromStream(std::istream &stream)
Read the offline bad channel map from a standard stream.
void SetFastORPedestal(Short_t absId, Float_t ped)
Set the pedestal value for a FastOR.
unsigned long ULong_t
Definition: External.C:38
void AddOfflineBadChannel(Short_t absId)
Add an offline bad channel to the set.
double GetTriggerChannelEnergy(Int_t col, Int_t row) const
Get energy of the trigger channel estimated from cells (in col-row space)
std::set< Short_t > fBadChannels
Container of bad channels.
Int_t fDebugLevel
Int_t fL0Threshold
threshold for the L0 patches (2x2)
AliEMCALTriggerDataGrid< double > * fPatchAmplitudes
! TRU Amplitudes (for L0)
Manager for constants used in the trigger maker.
short Short_t
Definition: External.C:23
void BuildL1ThresholdsOffline(const AliVVZERO *vzdata)
Build VZERO-dependent thresholds for the offline trigger.
AliEMCALTriggerDataGrid< double > * fPatchADC
! ADC values map
Bool_t isMC
Int_t fMinL0FastORAmp
Minimum L0 amplitude of the FastORs used to generate the patches.
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
std::set< Short_t > fOfflineBadChannels
Abd ID of offline bad channels.
AliEMCALTriggerPatchFinder< double > * fPatchFinder
The actual patch finder.
void ClearOfflineBadChannels()
Clear offline bad channel list.
TFile * file
double GetTriggerChannelADCSimple(Int_t col, Int_t row) const
Get ADC value of trigger channel estimated from cell energies.
double GetTriggerChannelEnergyRough(Int_t col, Int_t row) const
Get estimated energy of the trigger channel based on ADC measurement (in col-row space) ...
double GetTriggerChannelEnergySmeared(Int_t col, Int_t row) const
Get (simulated) smeared energy of a trigger channel estimated based on the measured energy from cells...
AliEMCALTriggerDataGrid< double > * fPatchADCSimple
! patch map for simple offline trigger
Kernel of the EMCAL trigger patch maker.
void ReadFastORPedestalFromFile(const char *fname)
Read the FastOR pedestals from a text file.
AliEMCALTriggerDataGrid< char > * fLevel0TimeMap
! Map needed to store the level0 times
AliEMCALTriggerAlgorithm< double > * fLevel0PatchFinder
Patch finder for Level0 patches.
Bool_t IsJetPatch(const AliEMCALTriggerRawPatch &patch) const
Check from the bitmask whether the patch is a jet patch.
bool Bool_t
Definition: External.C:53
TF1 * fSmearModelMean
Smearing parameterization for the mean.
static AliEMCALTriggerPatchInfoV1 * CreateAndInitializeV1(UChar_t col0, UChar_t row0, UChar_t size, UInt_t adc, UInt_t offlineAdc, Double_t patchE, UInt_t bitmask, const TVector3 &vertex, const AliEMCALGeometry *geom)
double GetDataGridDimensionRows() const
Get the dimension of the underlying data grids in row direction.
void ReadFastORPedestalFromStream(std::istream &stream)
Read the FastOR pedestals from a standard stream.
void ReadCellData(AliVCaloCells *cells)
Read the EMCAL cell data.
void ConfigureForPPb2013()
Configure the class for 2013 pPb.
AliEMCALTriggerDataGrid< double > * fPatchEnergySimpleSmeared
! Data grid for smeared energy values from cell energies
TF1 * fSmearModelSigma
Smearing parameterization for the width.
const Double_t kEMCL0ADCtoGeV_AP