AliPhysics  608b256 (608b256)
AliEmcalTriggerQATask.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2016, 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 <TClonesArray.h>
16 #include <THashList.h>
17 #include <THnSparse.h>
18 
19 #include <AliESDEvent.h>
20 #include <AliEMCALTriggerOnlineQAPbPb.h>
21 #include <AliEMCALTriggerQA.h>
22 #include <AliEMCALTriggerPatchInfo.h>
23 #include <AliEMCALTriggerFastOR.h>
24 #include <AliEMCALTriggerConstants.h>
25 #include <AliEMCALTriggerOnlineQAPP.h>
26 #include <AliVEventHandler.h>
27 #include <AliAnalysisManager.h>
28 
31 #include "AliEmcalTriggerQATask.h"
32 
33 using namespace EMCALTrigger;
34 
36 ClassImp(AliEmcalTriggerQATask);
38 
44  fTriggerPatchesName("EmcalTriggers"),
45  fEMCALTriggerQA(),
46  fADCperBin(16),
47  fMinAmplitude(0),
48  fDCalPlots(kTRUE),
49  fMinTimeStamp(0),
50  fMaxTimeStamp(0),
51  fTimeStampBinWidth(0),
52  fESDEvent(0),
53  fTriggerPatches(0)
54 {
55 }
56 
62  AliAnalysisTaskEmcalLight(name,kTRUE),
63  fTriggerPatchesName("EmcalTriggers"),
65  fADCperBin(16),
66  fMinAmplitude(0),
67  fDCalPlots(kTRUE),
68  fMinTimeStamp(0),
69  fMaxTimeStamp(0),
71  fESDEvent(0),
73 {
74  // Constructor.
76 
77  if (beamType == kpp || beamType == kpA) {
78  AliInfo("Setting up the task for pp collisions.");
80  switch (anaType) {
82  AliInfo("Using online QA component for pp");
83  fEMCALTriggerQA.push_back(new AliEMCALTriggerOnlineQAPP(name));
84  break;
86  AliInfo("Using offline QA component for pp");
87  fEMCALTriggerQA.push_back(new AliEMCALTriggerOfflineQAPP(name));
88  break;
90  AliInfo("Using light offline QA component for pp");
92  break;
93  default:
94  break;
95  }
96  }
97  else {
98  AliInfo("Setting up the task for PbPb collisions.");
99  // No offline class for PbPb... yet
101  for (Int_t i = 0; i < GetNCentBins(); i++) {
102  fEMCALTriggerQA.push_back(new AliEMCALTriggerOnlineQAPbPb(name));
103  }
104  }
105 }
106 
111 {
112  for (auto triggerQA : fEMCALTriggerQA) delete triggerQA;
113 }
114 
119 {
121 
122  fESDEvent = dynamic_cast<AliESDEvent*>(InputEvent());
123 
124  if (!fESDEvent) {
125  fMinTimeStamp = 0;
126  fMaxTimeStamp = 0;
127  fTimeStampBinWidth = 0;
128  }
129 
130  if (!fLocalInitialized) return;
131 
132  fTriggerPatches = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTriggerPatchesName));
133 
134  if (fTriggerPatches) {
135  TString objname(fTriggerPatches->GetClass()->GetName());
136  TClass cls(objname);
137  if (!cls.InheritsFrom("AliEMCALTriggerPatchInfo")) {
138  AliError(Form("%s: Objects of type %s in %s are not inherited from AliEMCALTriggerPatchInfo!",
139  GetName(), cls.GetName(), fTriggerPatchesName.Data()));
140  fTriggerPatches = 0;
141  }
142  }
143 
144  if (!fTriggerPatches) {
145  fLocalInitialized = kFALSE;
146  AliError(Form("%s: Unable to get trigger patch container with name %s. Aborting", GetName(), fTriggerPatchesName.Data()));
147  return;
148  }
149 
150  for (auto triggerQA : fEMCALTriggerQA) triggerQA->ExecOnce();
151 }
152 
157 {
159 
160  if (fOutput) {
161  for (auto triggerQA : fEMCALTriggerQA) {
162  triggerQA->EnableHistogramsByTimeStamp(fTimeStampBinWidth);
163  triggerQA->SetDebugLevel(DebugLevel());
164  triggerQA->Init();
165  fOutput->Add(triggerQA->GetListOfHistograms());
166 
167  AliEMCALTriggerOfflineQAPP* triggerOffline = dynamic_cast<AliEMCALTriggerOfflineQAPP*>(triggerQA);
168  if (triggerOffline) triggerOffline->EnableDCal(fDCalPlots);
169  }
170 
171  PostData(1, fOutput);
172  }
173 }
174 
180 {
181  return kTRUE;
182 }
183 
184 
190 {
191  AliEMCALTriggerQA* triggerQA = GetTriggerQA(fBeamType == AliEmcalTriggerQATask::kAA ? fCentBin : 0);
192  if (!triggerQA) {
193  return kFALSE;
194  }
195 
196  if (fESDEvent) {
197  if (fESDEvent->GetTimeStamp() < fMinTimeStamp) return kFALSE;
198  if (fMaxTimeStamp > fMinTimeStamp && fESDEvent->GetTimeStamp() > fMaxTimeStamp) return kFALSE;
199  triggerQA->EventTimeStamp(fESDEvent->GetTimeStamp());
200  }
201 
202  if (fTriggerPatches) {
203  Int_t nPatches = fTriggerPatches->GetEntriesFast();
204 
205  AliDebug(2, Form("nPatches = %d", nPatches));
206 
207  for (Int_t i = 0; i < nPatches; i++) {
208  AliDebug(2, Form("Processing bkg patch %d", i));
209 
210  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
211  if (!patch) continue;
212  if (patch->GetADCAmp() < fMinAmplitude) continue;
213 
214  triggerQA->ProcessBkgPatch(patch);
215  }
216 
217  triggerQA->ComputeBackground();
218 
219  for (Int_t i = 0; i < nPatches; i++) {
220  AliDebug(2, Form("Processing patch %d", i));
221 
222  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
223  if (!patch) continue;
224  if (patch->GetADCAmp() < fMinAmplitude) continue;
225 
226  triggerQA->ProcessPatch(patch);
227  }
228  }
229 
230  if (fCaloTriggers) {
231  AliEMCALTriggerFastOR fastor;
232  fCaloTriggers->Reset();
233  Int_t globCol = -1, globRow = -1;
234  Float_t L0amp = -1;
235  Int_t L1amp = -1;
236  while (fCaloTriggers->Next()) {
237  // get position in global 2x2 tower coordinates
238  // A0 left bottom (0,0)
239  fCaloTriggers->GetPosition(globCol, globRow);
240  // for some strange reason some ADC amps are initialized in reconstruction
241  // as -1, neglect those
242  fCaloTriggers->GetL1TimeSum(L1amp);
243  if (L1amp < 0) L1amp = 0;
244  fCaloTriggers->GetAmplitude(L0amp);
245  L0amp *= 4;
246  if (L0amp < 0) L0amp = 0;
247 
248  Int_t time = -1;
249  Int_t nl0times(0);
250  fCaloTriggers->GetNL0Times(nl0times);
251  if(nl0times) {
252  TArrayI l0times(nl0times);
253  fCaloTriggers->GetL0Times(l0times.GetArray());
254  for(int itime = 0; itime < nl0times; itime++){
255  time = l0times[itime];
256  break;
257  }
258  }
259 
260  fastor.Initialize(L0amp, L1amp, globRow, globCol, time, fGeom);
261 
262  triggerQA->ProcessFastor(&fastor, fCaloCells);
263  }
264  }
265 
266  if (fCaloCells) {
267  const Int_t ncells = fCaloCells->GetNumberOfCells();
268  AliEMCALTriggerQA::AliEMCALCellInfo cellInfo;
269  for (Int_t pos = 0; pos < ncells; pos++) {
270  Double_t amp = fCaloCells->GetAmplitude(pos);
271  Int_t absId = fCaloCells->GetCellNumber(pos);
272  cellInfo.Set(absId, amp);
273  triggerQA->ProcessCell(cellInfo);
274  }
275  }
276 
277  triggerQA->EventCompleted();
278 
279  return kTRUE;
280 }
281 
287 {
288  fADCperBin = n;
289 
290  for (auto qa : fEMCALTriggerQA) qa->SetADCperBin(n);
291 }
292 
305 {
306  // Get the pointer to the existing analysis manager via the static access method
307  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
308  if (!mgr) {
309  ::Error("AliEmcalTriggerQATask", "No analysis manager to connect to.");
310  return 0;
311  }
312 
313  // Check the analysis type using the event handlers connected to the analysis manager
314  AliVEventHandler *evhand = mgr->GetInputEventHandler();
315  if (!evhand) {
316  ::Error("AliEmcalTriggerQATask", "This task requires an input event handler");
317  return 0;
318  }
319 
320  // Init the task and do settings
321  TString taskName("AliEmcalTriggerQATask");
322  if (!suffix.IsNull()) {
323  taskName += "_";
324  taskName += suffix;
325  }
326  AliEmcalTriggerQATask* eTask = new AliEmcalTriggerQATask(taskName, beamType, anaType);
327  eTask->SetTriggerPatchesName(triggerPatchesName);
328  if(triggersName.IsNull()) {
329  if (evhand->InheritsFrom("AliESDInputHandler")) {
330  triggersName = "EMCALTrigger";
331  ::Info("AddTaskEmcalTriggerQA", "ESD analysis, triggersName = \"%s\"", triggersName.Data());
332  }
333  else {
334  triggersName = "emcalTrigger";
335  ::Info("AddTaskEmcalTriggerQA", "AOD analysis, triggersName = \"%s\"", triggersName.Data());
336  }
337  }
338  if(cellsName.IsNull()) {
339  if (evhand->InheritsFrom("AliESDInputHandler")) {
340  cellsName = "EMCALCells";
341  ::Info("AddTaskEmcalTriggerQA", "ESD analysis, cellsName = \"%s\"", cellsName.Data());
342  }
343  else {
344  cellsName = "emcalCells";
345  ::Info("AddTaskEmcalTriggerQA", "AOD analysis, cellsName = \"%s\"", cellsName.Data());
346  }
347  }
348  eTask->SetCaloTriggersName(triggersName);
349  eTask->SetCaloCellsName(cellsName);
350 
351  // Final settings, pass to manager and set the containers
352  mgr->AddTask(eTask);
353  // Create containers for input/output
354  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
355  mgr->ConnectInput (eTask, 0, cinput1 );
356 
357  TString commonoutput;
358  if (subdir.IsNull()) {
359  commonoutput = mgr->GetCommonFileName();
360  }
361  else {
362  commonoutput = TString::Format("%s:%s", mgr->GetCommonFileName(), subdir.Data());
363  }
364  TString contOutName(Form("%s_histos", taskName.Data()));
365  mgr->ConnectOutput(eTask, 1, mgr->CreateContainer(contOutName, TList::Class(), AliAnalysisManager::kOutputContainer, commonoutput.Data()));
366 
367  return eTask;
368 }
369 
375 {
376  EBeamType_t beam = BeamTypeFromRunNumber(runnumber);
377  std::vector<std::string> triggerClasses = {"CINT7", "CEMC7", "CDMC7", "EG1", "EG2", "EJ1", "EJ2", "DG1", "DG2", "DJ1", "DJ2" };
378  AliEmcalTriggerQATask* task(nullptr);
379  TObjArray tasks;
380  for (auto triggerClass : triggerClasses) {
381  TString suffix(triggerClass.c_str());
382  suffix.ReplaceAll("-", "_");
383  task = AddTaskEmcalTriggerQA("EmcalTriggers", "", "", beam, kTriggerOfflineLightAnalysis, "CaloQA_default", suffix);
384  tasks.Add(task);
385  task->SetForceBeamType(beam);
386  task->AddAcceptedTriggerClass(triggerClass.c_str());
387  if (runnumber > 197692) {
389  }
390 
391  if (triggerClass.find("CINT7") != std::string::npos) {
392  for (auto triggerQA : task->fEMCALTriggerQA) {
393  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, EMCALTrigger::kTMEMCalLevel0, kTRUE);
394  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, EMCALTrigger::kTMEMCalGammaH, kTRUE);
395  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, EMCALTrigger::kTMEMCalJetH, kTRUE);
396  }
397  }
398  else {
399  EMCALTrigger::EMCalTriggerType_t triggerType = EMCALTrigger::kTMEMCalLevel0;
400  if (triggerClass.find("CEMC7") != std::string::npos || triggerClass.find("CDMC7") != std::string::npos) {
401  triggerType = EMCALTrigger::kTMEMCalLevel0;
402  }
403  else if (triggerClass.find("EG") != std::string::npos || triggerClass.find("DG") != std::string::npos) {
404  triggerType = EMCALTrigger::kTMEMCalGammaH;
405  }
406  else if (triggerClass.find("EJ") != std::string::npos || triggerClass.find("DJ") != std::string::npos) {
407  triggerType = EMCALTrigger::kTMEMCalJetH;
408  }
409  for (auto triggerQA : task->fEMCALTriggerQA) {
410  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, triggerType, kTRUE);
411  }
412  }
413  }
414  return tasks;
415 }
Int_t fADCperBin
ADC counts per bin.
void SetTriggerPatchesName(const char *name)
AliEMCALGeometry * fGeom
!emcal geometry
EBeamType_t fBeamType
!event beam type
double Double_t
Definition: External.C:58
TClonesArray * fTriggerPatches
! trigger array in
UInt_t fTimeStampBinWidth
Time stamp bin width.
Class to do some fast QA of the EMCal trigger. Useful also to tune trigger thresholds.
AliESDEvent * fESDEvent
! current ESD event
New centrality estimation (AliMultSelection, see https://twiki.cern.ch/twiki/bin/viewauth/ALICE/AliMu...
Bool_t fDCalPlots
Whether to add DCal QA plots.
TString fTriggerPatchesName
name of input trigger array
Class to generate EMCal trigger QA plots in pp collisions.
UInt_t fMinTimeStamp
Minimum event time stamp (only ESD)
Int_t fMinAmplitude
Minimum trigger patch amplitude.
int Int_t
Definition: External.C:63
void AddAcceptedTriggerClass(const char *trigClass)
float Float_t
Definition: External.C:68
static TObjArray AddTaskEmcalTriggerQA_QAtrain(Int_t runnumber)
Base task in the EMCAL framework (lighter version of AliAnalysisTaskEmcal)
static AliEmcalTriggerQATask * AddTaskEmcalTriggerQA(TString triggerPatchesName="EmcalTriggers", TString cellsName="", TString triggersName="", EBeamType_t beamType=kpp, ETriggerAnalysisType_t anaType=kTriggerOfflineExpertAnalysis, TString subdir="", TString suffix="")
void SetCentralityEstimation(ECentralityEstimation_t b)
std::vector< AliEMCALTriggerQA * > fEMCALTriggerQA
produces the QA histograms
const Bool_t anaType
Int_t fCentBin
!event centrality bin
Bool_t fLocalInitialized
!whether or not the task has been already initialized
static EBeamType_t BeamTypeFromRunNumber(Int_t runnumber)
UInt_t fMaxTimeStamp
Maximum event time stamp (only ESD)
bool Bool_t
Definition: External.C:53
EBeamType_t
Switch for the beam type.
AliVCaloTrigger * fCaloTriggers
!calo triggers
AliEMCALTriggerQA * GetTriggerQA(Int_t i=0)