AliPhysics  2c6b7ad (2c6b7ad)
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"
29 #include "AliEMCALTriggerPatchInfo.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  fScaleShift(0.),
69  fDoBackgroundSubtraction(false),
70  fGeometry(nullptr),
71  fPatchAmplitudes(nullptr),
72  fPatchADCSimple(nullptr),
73  fPatchADC(nullptr),
74  fPatchEnergySimpleSmeared(nullptr),
75  fLevel0TimeMap(nullptr),
76  fTriggerBitMap(nullptr),
77  fADCtoGeV(1.)
78 {
79  memset(fThresholdConstants, 0, sizeof(Int_t) * 12);
80  memset(fL1ThresholdsOffline, 0, sizeof(ULong64_t) * 4);
81  fCellTimeLimits[0] = -10000.;
82  fCellTimeLimits[1] = 10000.;
83  memset(fRhoValues, 0, sizeof(Double_t) * kNIndRho);
84 }
85 
87  delete fPatchAmplitudes;
88  delete fPatchADCSimple;
89  delete fPatchADC;
91  delete fLevel0TimeMap;
92  delete fTriggerBitMap;
93  delete fPatchFinder;
94  delete fLevel0PatchFinder;
96 }
97 
99  if (!fTriggerBitConfig) {
100  AliWarning("Trigger bit configuration was not provided! Assuming new bit configuration (>= 2013).");
101  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigNew();
102  SetTriggerBitConfig(triggerBitConfig);
103  }
104 
110 
111  // Allocate containers for the ADC values
112  int nrows = fGeometry->GetNTotalTRU() * 2;
113  std::cout << "Allocating channel grid with 48 columns in eta and " << nrows << " rows in phi" << std::endl;
114  fPatchAmplitudes->Allocate(48, nrows);
115  fPatchADC->Allocate(48, nrows);
116  fPatchADCSimple->Allocate(48, nrows);
117  fLevel0TimeMap->Allocate(48, nrows);
118  fTriggerBitMap->Allocate(48, nrows);
119 
121  // Allocate container for energy smearing (if enabled)
123  fPatchEnergySimpleSmeared->Allocate(48, nrows);
124  }
125 }
126 
127 void AliEmcalTriggerMakerKernel::AddL1TriggerAlgorithm(Int_t rowmin, Int_t rowmax, UInt_t bitmask, Int_t patchSize, Int_t subregionSize)
128 {
130  AliEMCALTriggerAlgorithm<double> *trigger = new AliEMCALTriggerAlgorithm<double>(rowmin, rowmax, bitmask);
131  trigger->SetPatchSize(patchSize);
132  trigger->SetSubregionSize(subregionSize);
133  fPatchFinder->AddTriggerAlgorithm(trigger);
134 }
135 
136 void AliEmcalTriggerMakerKernel::SetL0TriggerAlgorithm(Int_t rowmin, Int_t rowmax, UInt_t bitmask, Int_t patchSize, Int_t subregionSize)
137 {
139  fLevel0PatchFinder = new AliEMCALTriggerAlgorithm<double>(rowmin, rowmax, bitmask);
140  fLevel0PatchFinder->SetPatchSize(patchSize);
141  fLevel0PatchFinder->SetSubregionSize(subregionSize);
142 }
143 
145 {
146  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigNew();
147  SetTriggerBitConfig(triggerBitConfig);
148 
149  // Initialize patch finder
150  if (fPatchFinder) delete fPatchFinder;
152 
153  SetL0TriggerAlgorithm(0, 103, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
154  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
155  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
156  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit() | 1<<fTriggerBitConfig->GetBkgBit(), 8, 4);
157  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit() | 1<<fTriggerBitConfig->GetBkgBit(), 8, 4);
158  fConfigured = true;
159 }
160 
162 {
163  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigNew();
164  SetTriggerBitConfig(triggerBitConfig);
165 
166  // Initialize patch finder
167  if (fPatchFinder) delete fPatchFinder;
169 
170  SetL0TriggerAlgorithm(0, 103, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
171  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
172  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
173  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit(), 16, 4);
174  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit(), 8, 4);
175  SetOnlineBackgroundSubtraction(true); // Subtract background energy from online ADC values
176  fConfigured = true;
177 }
178 
180 {
181  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigNew();
182  SetTriggerBitConfig(triggerBitConfig);
183 
184  // Initialize patch finder
185  if (fPatchFinder) delete fPatchFinder;
187 
188  SetL0TriggerAlgorithm(0, 103, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
189  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
190  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
191  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit(), 8, 4);
192  AddL1TriggerAlgorithm(64, 103, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit(), 8, 4);
193  fConfigured = true;
194 }
195 
197 {
198  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigNew();
199  SetTriggerBitConfig(triggerBitConfig);
200 
201  // Initialize patch finder
202  if (fPatchFinder) delete fPatchFinder;
204 
205  SetL0TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
206  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit() | 1<<fTriggerBitConfig->GetGammaLowBit(), 2, 1);
207  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit() | 1<<fTriggerBitConfig->GetJetLowBit(), 16, 4);
208  fConfigured = true;
209 }
210 
212 {
213  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigOld();
214  SetTriggerBitConfig(triggerBitConfig);
215 
216  // Initialize patch finder
217  if (fPatchFinder) delete fPatchFinder;
219 
220  SetL0TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
221  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit(), 2, 1);
222  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit(), 16, 4);
223  fConfigured = true;
224 }
225 
227 {
228  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigOld();
229  SetTriggerBitConfig(triggerBitConfig);
230 
231  // Initialize patch finder
232  if (fPatchFinder) delete fPatchFinder;
234 
235  SetL0TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
236  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetGammaHighBit(), 2, 1);
237  AddL1TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetJetHighBit(), 16, 4);
238  fConfigured = true;
239 }
240 
242 {
243  AliEMCALTriggerBitConfig* triggerBitConfig = new AliEMCALTriggerBitConfigOld();
244  SetTriggerBitConfig(triggerBitConfig);
245 
246  // Initialize patch finder
247  if (fPatchFinder) delete fPatchFinder;
249 
250  SetL0TriggerAlgorithm(0, 63, 1<<fTriggerBitConfig->GetLevel0Bit(), 2, 1);
251  fConfigured = true;
252 }
253 
255 {
256  Short_t absId = 0;
257 
258  while (stream.good()) {
259  stream >> absId;
260  AddOfflineBadChannel(absId);
261  }
262 }
263 
265 {
266  std::ifstream file(fname);
268 }
269 
271 {
272  Short_t absId = -1;
273 
274  while (stream.good()) {
275  stream >> absId;
276  AddFastORBadChannel(absId);
277  }
278 }
279 
281 {
282  std::ifstream file(fname);
284 }
285 
287 {
288  if (absId < 0 || absId >= fFastORPedestal.GetSize()) {
289  AliWarning(Form("Abs. ID %d out of range (0,5000)", absId));
290  return;
291  }
292  fFastORPedestal[absId] = ped;
293 }
294 
296 {
297  Short_t absId = 0;
298  Float_t ped = 0;
299  while (stream.good()) {
300  stream >> ped;
301  SetFastORPedestal(absId, ped);
302  absId++;
303  }
304 }
305 
307 {
308  std::ifstream file(fname);
310 }
311 
313  fPatchAmplitudes->Reset();
314  fPatchADC->Reset();
315  fPatchADCSimple->Reset();
316  fLevel0TimeMap->Reset();
317  fTriggerBitMap->Reset();
319  memset(fL1ThresholdsOffline, 0, sizeof(ULong64_t) * 4);
320 }
321 
322 void AliEmcalTriggerMakerKernel::ReadTriggerData(AliVCaloTrigger *trigger){
323  trigger->Reset();
324  Int_t globCol=-1, globRow=-1;
325  Int_t adcAmp=-1, bitmap = 0;
326  while(trigger->Next()){
327  // get position in global 2x2 tower coordinates
328  // A0 left bottom (0,0)
329  trigger->GetPosition(globCol, globRow);
330  Int_t absId = -1;
331  fGeometry->GetAbsFastORIndexFromPositionInEMCAL(globCol, globRow, absId);
332 
333  // trigger bits can also occur on online masked fastors. Therefore trigger
334  // bits are handled before ADC values, and independently whether fastor is
335  // masked or not
336  trigger->GetTriggerBits(bitmap);
337  try {
338  (*fTriggerBitMap)(globCol, globRow) = bitmap;
339  }
341  std::string dirstring = e.GetDirection() == AliEMCALTriggerDataGrid<int>::OutOfBoundsException::kColDir ? "Col" : "Row";
342  AliErrorStream() << "Trigger maker task - filling trigger bit grid - index out-of-bounds in " << dirstring << ": " << e.GetIndex() << std::endl;
343  }
344 
345  // also Level0 times need to be handled without masking of the fastor ...
346  // @TODO cross check
347  Int_t nl0times(0);
348  trigger->GetNL0Times(nl0times);
349  if(nl0times){
350  TArrayI l0times(nl0times);
351  trigger->GetL0Times(l0times.GetArray());
352  for(int itime = 0; itime < nl0times; itime++){
353  try{
354  (*fLevel0TimeMap)(globCol,globRow) = static_cast<Char_t>(l0times[itime]);
355  break;
356  }
358  std::string dirstring = e.GetDirection() == AliEMCALTriggerDataGrid<char>::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 
364  // exclude channel completely if it is masked as hot channel
365  if (fBadChannels.find(absId) != fBadChannels.end()){
366  AliDebugStream(1) << "Found ADC for masked fastor " << absId << ", rejecting" << std::endl;
367  continue;
368  }
369  // for some strange reason some ADC amps are initialized in reconstruction
370  // as -1, neglect those
371  trigger->GetL1TimeSum(adcAmp);
372  if (adcAmp < 0) adcAmp = 0;
373 
374  if (adcAmp >= fMinL1FastORAmp) {
375  try {
376  (*fPatchADC)(globCol,globRow) = adcAmp;
377  }
379  std::string dirstring = e.GetDirection() == AliEMCALTriggerDataGrid<double>::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  // Handling for L0 triggers
385  // For the ADC value we use fCaloTriggers->GetAmplitude()
386  // In data, all patches which have 4 TRUs with proper level0 times are
387  // valid trigger patches. Therefore we need to check all neighbors for
388  // the level0 times, not only the bottom left. In order to obtain this
389  // information, a lookup table with the L0 times for each TRU is created
390  Float_t amplitude(0);
391  trigger->GetAmplitude(amplitude);
392  amplitude *= 4; // values are shifted by 2 bits to fit in a 10 bit word (on the hardware side)
393  amplitude -= fFastORPedestal[absId];
394  if(amplitude < 0) amplitude = 0;
395  if (amplitude >= fMinL0FastORAmp) {
396  try{
397  (*fPatchAmplitudes)(globCol,globRow) = amplitude;
398  }
400  std::string dirstring = e.GetDirection() == AliEMCALTriggerDataGrid<int>::OutOfBoundsException::kColDir ? "Col" : "Row";
401  AliErrorStream() << "Trigger maker task - filling trigger bit grid - index out-of-bounds in " << dirstring << ": " << e.GetIndex() << std::endl;
402  }
403  }
404  }
405 
406  // Reading of the rho values (only PbPb)
408  fRhoValues[kIndRhoEMCAL] = trigger->GetMedian(0); // EMCAL STU at position 0
409  fRhoValues[kIndRhoDCAL] = trigger->GetMedian(1); // DCAL STU at position 1
410  }
411 }
412 
413 void AliEmcalTriggerMakerKernel::ReadCellData(AliVCaloCells *cells){
414  // fill the patch ADCs from cells
415  Int_t nCell = cells->GetNumberOfCells();
416  for(Int_t iCell = 0; iCell < nCell; ++iCell) {
417  // get the cell info, based in index in array
418  Short_t cellId = cells->GetCellNumber(iCell);
419 
420  // Check bad channel map
421  if (fOfflineBadChannels.find(cellId) != fOfflineBadChannels.end()) {
422  AliDebugStream(1) << "Cell " << cellId << " masked as bad channel, rejecting." << std::endl;
423  continue;
424  }
425 
426  Double_t amp = cells->GetAmplitude(iCell),
427  celltime = cells->GetTime(iCell);
428  if(celltime < fCellTimeLimits[0] || celltime > fCellTimeLimits[1]) continue;
429  if(amp < fMinCellAmplitude) continue;
430  if(fScaleShift) amp += fScaleShift;
431  amp = TMath::Max(amp, 0.); // never go negative in energy
432  // get position
433  Int_t absId=-1;
434  fGeometry->GetFastORIndexFromCellIndex(cellId, absId);
436  // Exclude FEE amplitudes from cells which are within a TRU which is masked at
437  // online level. Using this the online acceptance can be applied to offline
438  // patches as well.
439  if(fBadChannels.find(absId) != fBadChannels.end()){
440  AliDebugStream(1) << "Cell " << cellId << " corresponding to masked fastor " << absId << ", rejecting." << std::endl;
441  continue;
442  }
443  }
444  Int_t globCol=-1, globRow=-1;
445  fGeometry->GetPositionInEMCALFromAbsFastORIndex(absId, globCol, globRow);
446  // add
447  amp /= fADCtoGeV;
448  try {
449  if (amp >= fMinCellAmp) (*fPatchADCSimple)(globCol,globRow) += amp;
450  }
452  }
453  }
454 
455  // Apply energy smearing (if enabled)
457  AliDebugStream(1) << "Trigger Maker: Apply energy smearing" << std::endl;
458  for(int icol = 0; icol < fPatchADCSimple->GetNumberOfCols(); icol++){
459  for(int irow = 0; irow < fPatchADCSimple->GetNumberOfRows(); irow++){
460  double energyorig = (*fPatchADCSimple)(icol, irow) * fADCtoGeV; // Apply smearing in GeV
461  double energysmear = energyorig;
462  if(energyorig > fSmearThreshold){
463  double mean = fSmearModelMean->Eval(energyorig), sigma = fSmearModelSigma->Eval(energyorig);
464  energysmear = gRandom->Gaus(mean, sigma);
465  if(energysmear < 0) energysmear = 0; // only accept positive or 0 energy values
466  AliDebugStream(1) << "Original energy " << energyorig << ", mean " << mean << ", sigma " << sigma << ", smeared " << energysmear << std::endl;
467  }
468  (*fPatchEnergySimpleSmeared)(icol, irow) = energysmear;
469  }
470  }
471  AliDebugStream(1) << "Smearing done" << std::endl;
472  }
473 }
474 
476  // get the V0 value and compute and set the offline thresholds
477  // get V0, compute thresholds and save them as global parameters
478  ULong64_t v0S = vzerodata->GetTriggerChargeA() + vzerodata->GetTriggerChargeC();
479  for (Int_t i = 0; i < 4; ++i) {
480  // A*V0^2/2^32+B*V0/2^16+C
481  fL1ThresholdsOffline[i]= ( ((ULong64_t)fThresholdConstants[i][0]) * v0S * v0S ) >> 32;
482  fL1ThresholdsOffline[i] += ( ((ULong64_t)fThresholdConstants[i][1]) * v0S ) >> 16;
483  fL1ThresholdsOffline[i] += ((ULong64_t)fThresholdConstants[i][2]);
484  }
485 }
486 
487 void AliEmcalTriggerMakerKernel::CreateTriggerPatches(const AliVEvent *inputevent, std::vector<AliEMCALTriggerPatchInfo> &outputcont, Bool_t useL0amp){
488  //std::cout << "Finding trigger patches" << std::endl;
489  //AliEMCALTriggerPatchInfo *trigger, *triggerMainJet, *triggerMainGamma, *triggerMainLevel0;
490  //AliEMCALTriggerPatchInfo *triggerMainJetSimple, *triggerMainGammaSimple;
491 
492  if (useL0amp) {
494  }
495  else {
496  fADCtoGeV = EMCALTrigger::kEMCL1ADCtoGeV;
497  }
498 
499  Double_t vertexpos[3];
500  inputevent->GetPrimaryVertex()->GetXYZ(vertexpos);
501  TVector3 vertexvec(vertexpos);
502 
503  Int_t isMC = fIsMC ? 1 : 0;
504  Int_t offset = (1 - isMC) * fTriggerBitConfig->GetTriggerTypesEnd();
505 
506  // Create trigger bit masks. They are needed later to remove
507  // trigger bits from the trigger bit mask for non-matching patch types
508  Int_t jetPatchMask = 1 << fTriggerBitConfig->GetJetHighBit()
509  | 1 << fTriggerBitConfig->GetJetLowBit()
510  | 1 << (fTriggerBitConfig->GetJetHighBit() + fTriggerBitConfig->GetTriggerTypesEnd())
511  | 1 << (fTriggerBitConfig->GetJetLowBit() + fTriggerBitConfig->GetTriggerTypesEnd()),
512  gammaPatchMask = 1 << fTriggerBitConfig->GetGammaHighBit()
513  | 1 << fTriggerBitConfig->GetGammaLowBit()
514  | 1 << (fTriggerBitConfig->GetGammaHighBit() + fTriggerBitConfig->GetTriggerTypesEnd())
515  | 1 << (fTriggerBitConfig->GetGammaLowBit() + fTriggerBitConfig->GetTriggerTypesEnd()),
516  bkgPatchMask = 1 << fTriggerBitConfig->GetBkgBit();
517  //l0PatchMask = 1 << fTriggerBitConfig->GetLevel0Bit();
518 
519  std::vector<AliEMCALTriggerRawPatch> patches;
520  if (fPatchFinder) {
521  if (useL0amp) {
522  patches = fPatchFinder->FindPatches(*fPatchAmplitudes, *fPatchADCSimple);
523  }
524  else {
525  patches = fPatchFinder->FindPatches(*fPatchADC, *fPatchADCSimple);
526  }
527  }
528  outputcont.clear();
529  for(std::vector<AliEMCALTriggerRawPatch>::iterator patchit = patches.begin(); patchit != patches.end(); ++patchit){
530  // Apply offline and recalc selection
531  // Remove unwanted bits from the online bits (gamma bits from jet patches and vice versa)
532  Int_t offlinebits = 0, onlinebits = (*fTriggerBitMap)(patchit->GetColStart(), patchit->GetRowStart());
533  if(HasPHOSOverlap(*patchit)) continue;
534  if(IsGammaPatch(*patchit)){
535  if(patchit->GetADC() > fL1ThresholdsOffline[1]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetGammaHighBit());
536  if(patchit->GetOfflineADC() > fL1ThresholdsOffline[1]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetGammaHighBit());
537  if(patchit->GetADC() > fL1ThresholdsOffline[3]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetGammaLowBit());
538  if(patchit->GetOfflineADC() > fL1ThresholdsOffline[3]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetGammaLowBit());
539  onlinebits &= gammaPatchMask;
540  }
541  if (IsJetPatch(*patchit)){
542  if(patchit->GetADC() > fL1ThresholdsOffline[0]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetJetHighBit());
543  if(patchit->GetOfflineADC() > fL1ThresholdsOffline[0]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetJetHighBit());
544  if(patchit->GetADC() > fL1ThresholdsOffline[2]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetJetLowBit());
545  if(patchit->GetOfflineADC() > fL1ThresholdsOffline[2]) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetJetLowBit());
546  onlinebits &= jetPatchMask;
547  }
548  if (IsBkgPatch(*patchit)){
549  if(patchit->GetADC() > fBkgThreshold) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetBkgBit());
550  if(patchit->GetOfflineADC() > fBkgThreshold) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetBkgBit());
551  onlinebits &= bkgPatchMask;
552  }
554  double area = TMath::Power(static_cast<double>(patchit->GetPatchSize())/4., 2);
555  double rhoval = (patchit->GetRowStart() >= 64) ? fRhoValues[kIndRhoDCAL] : fRhoValues[kIndRhoEMCAL];
556  patchit->SetADC(patchit->GetADC() - area * rhoval);
557  }
558  // convert
559  AliEMCALTriggerPatchInfo fullpatch;
560  fullpatch.Initialize(patchit->GetColStart(), patchit->GetRowStart(),
561  patchit->GetPatchSize(), patchit->GetADC(), patchit->GetOfflineADC(), patchit->GetOfflineADC() * fADCtoGeV,
562  onlinebits | offlinebits, vertexvec, fGeometry);
563  fullpatch.SetTriggerBitConfig(fTriggerBitConfig);
564  fullpatch.SetOffSet(offset);
566  // Add smeared energy
567  double energysmear = 0;
568  for(int icol = 0; icol < fullpatch.GetPatchSize(); icol++){
569  for(int irow = 0; irow < fullpatch.GetPatchSize(); irow++){
570  energysmear += (*fPatchEnergySimpleSmeared)(fullpatch.GetColStart() + icol, fullpatch.GetRowStart() + irow);
571  }
572  }
573  AliDebugStream(1) << "Patch size(" << fullpatch.GetPatchSize() <<") energy " << fullpatch.GetPatchE() << " smeared " << energysmear << std::endl;
574  fullpatch.SetSmearedEnergy(energysmear);
575  }
576  outputcont.push_back(fullpatch);
577  }
578 
579  // Find Level0 patches
580  std::vector<AliEMCALTriggerRawPatch> l0patches;
581  if (fLevel0PatchFinder) l0patches = fLevel0PatchFinder->FindPatches(*fPatchAmplitudes, *fPatchADCSimple);
582  for(std::vector<AliEMCALTriggerRawPatch>::iterator patchit = l0patches.begin(); patchit != l0patches.end(); ++patchit){
583  Int_t offlinebits = 0, onlinebits = 0;
584  if(HasPHOSOverlap(*patchit)) continue;
585  ELevel0TriggerStatus_t L0status = CheckForL0(patchit->GetColStart(), patchit->GetRowStart());
586  if (L0status == kNotLevel0) continue;
587  if (L0status == kLevel0Fired) SETBIT(onlinebits, fTriggerBitConfig->GetLevel0Bit());
588  if (patchit->GetADC() > fL0Threshold) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kRecalcOffset + fTriggerBitConfig->GetLevel0Bit());
589  if (patchit->GetOfflineADC() > fL0Threshold) SETBIT(offlinebits, AliEMCALTriggerPatchInfo::kOfflineOffset + fTriggerBitConfig->GetLevel0Bit());
590 
591  AliEMCALTriggerPatchInfo fullpatch;
592  fullpatch.Initialize(patchit->GetColStart(), patchit->GetRowStart(),
593  patchit->GetPatchSize(), patchit->GetADC(), patchit->GetOfflineADC(), patchit->GetOfflineADC() * fADCtoGeV,
594  onlinebits | offlinebits, vertexvec, fGeometry);
595  fullpatch.SetTriggerBitConfig(fTriggerBitConfig);
597  // Add smeared energy
598  double energysmear = 0;
599  for(int icol = 0; icol < fullpatch.GetPatchSize(); icol++){
600  for(int irow = 0; irow < fullpatch.GetPatchSize(); irow++){
601  energysmear += (*fPatchEnergySimpleSmeared)(fullpatch.GetColStart() + icol, fullpatch.GetRowStart() + irow);
602  }
603  }
604  fullpatch.SetSmearedEnergy(energysmear);
605  }
606  outputcont.push_back(fullpatch);
607  }
608  // std::cout << "Finished finding trigger patches" << std::endl;
609 }
610 
612  double amp = 0;
613  try {
614  amp = (*fPatchAmplitudes)(col, row);
616 
617  }
618  return amp;
619 }
620 
622  double adc = 0;
623  try {
624  adc = (*fPatchADC)(col, row);
626 
627  }
628  return adc;
629 }
630 
632  double adc = 0;
633  try {
634  adc = (*fPatchADC)(col, row) * EMCALTrigger::kEMCL1ADCtoGeV;
636 
637  }
638  return adc;
639 }
640 
642  double adc = 0;
643  try {
644  adc = (*fPatchADCSimple)(col, row);
646 
647  }
648  return adc;
649 }
650 
652  double adc = 0;
653  try {
654  adc = (*fPatchADCSimple)(col, row) * fADCtoGeV;
656 
657  }
658  return adc;
659 }
660 
662  double adc = 0;
664  try {
665  adc = (*fPatchEnergySimpleSmeared)(col, row);
667 
668  }
669  }
670  return adc;
671 }
672 
674  return fPatchADC->GetNumberOfRows();
675 }
676 
679 
680  if(col < 0 || row < 0){
681  AliError(Form("Patch outside range [col %d, row %d]", col, row));
682  return kNotLevel0;
683  }
684  Int_t truref(-1), trumod(-1), absFastor(-1), adc(-1);
685  fGeometry->GetAbsFastORIndexFromPositionInEMCAL(col, row, absFastor);
686  fGeometry->GetTRUFromAbsFastORIndex(absFastor, truref, adc);
687  int nvalid(0);
688  const int kNRowsPhi = fGeometry->GetNTotalTRU() * 2;
689  for(int ipos = 0; ipos < 2; ipos++){
690  if(row + ipos >= kNRowsPhi) continue; // boundary check
691  for(int jpos = 0; jpos < 2; jpos++){
692  if(col + jpos >= kColsEta) continue; // boundary check
693  // Check whether we are in the same TRU
694  trumod = -1;
695  fGeometry->GetAbsFastORIndexFromPositionInEMCAL(col+jpos, row+ipos, absFastor);
696  fGeometry->GetTRUFromAbsFastORIndex(absFastor, trumod, adc);
697  if(trumod != truref) {
698  result = kNotLevel0;
699  return result;
700  }
701  if(col + jpos >= kColsEta) AliError(Form("Boundary error in col [%d, %d + %d]", col + jpos, col, jpos));
702  if(row + ipos >= kNRowsPhi) AliError(Form("Boundary error in row [%d, %d + %d]", row + ipos, row, ipos));
703  Char_t l0times = (*fLevel0TimeMap)(col + jpos,row + ipos);
704  if(l0times > fL0MinTime && l0times < fL0MaxTime) nvalid++;
705  }
706  }
707  if (nvalid == 4) result = kLevel0Fired;
708  return result;
709 }
710 
712  fBadChannels.clear();
713 }
714 
716  fOfflineBadChannels.clear();
717 }
718 
719 Bool_t AliEmcalTriggerMakerKernel::IsGammaPatch(const AliEMCALTriggerRawPatch &patch) const {
720  ULong_t bitmask = patch.GetBitmask(), testmask = 1 << fTriggerBitConfig->GetGammaHighBit() | 1 << fTriggerBitConfig->GetGammaLowBit();
721  return bitmask & testmask;
722 }
723 
724 Bool_t AliEmcalTriggerMakerKernel::IsJetPatch(const AliEMCALTriggerRawPatch &patch) const {
725  ULong_t bitmask = patch.GetBitmask(), testmask = 1 << fTriggerBitConfig->GetJetHighBit() | 1 << fTriggerBitConfig->GetJetLowBit();
726  return bitmask & testmask;
727 }
728 
729 Bool_t AliEmcalTriggerMakerKernel::IsBkgPatch(const AliEMCALTriggerRawPatch &patch) const {
730  ULong_t bitmask = patch.GetBitmask(), testmask = 1 << fTriggerBitConfig->GetBkgBit();
731  return bitmask & testmask;
732 }
733 
734 void AliEmcalTriggerMakerKernel::SetTriggerBitConfig(const AliEMCALTriggerBitConfig *const config) {
735  if (config == fTriggerBitConfig) return;
737  fTriggerBitConfig = config;
738 }
739 
740 bool AliEmcalTriggerMakerKernel::HasPHOSOverlap(const AliEMCALTriggerRawPatch &patch) const {
741  const int kEtaMinPhos = 16, kEtaMaxPhos = 31, kPhiMinPhos = 64, kPhiMaxPhos = 99;
742  if(patch.GetRowStart() + patch.GetPatchSize() -1 < kPhiMinPhos) return false; // EMCAL Patch
743  if(patch.GetRowStart() > kPhiMaxPhos) return false; // DCAL 1/3 supermodule
744  if(patch.GetColStart() + patch.GetPatchSize() -1 < kEtaMinPhos) return false;
745  if(patch.GetColStart() > kEtaMaxPhos) return false;
746  return true;
747 }
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
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 CreateTriggerPatches(const AliVEvent *inputevent, std::vector< AliEMCALTriggerPatchInfo > &outputcont, Bool_t useL0amp=kFALSE)
Run patch finders on input data.
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
void ConfigureForPP20158x8()
Configure the class for 2015 pp.
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.
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.
Bool_t fDoBackgroundSubtraction
Swtich for background subtraction (only online ADC)
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.
Double_t fRhoValues[kNIndRho]
! Rho values for background subtraction (only online ADC)
void SetOnlineBackgroundSubtraction(Bool_t doSubtraction)
Switch on median subtraction of the online ADC value.
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
TList with histograms for a given trigger.
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.
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
Double_t fScaleShift
Scale shift simulation.
double GetL0TriggerChannelAmplitude(Int_t col, Int_t row) const
Get L0 amplitude of a given trigger channel (in col-row space)
TF1 * fSmearModelSigma
Smearing parameterization for the width.
const Double_t kEMCL0ADCtoGeV_AP