AliPhysics  63e47e1 (63e47e1)
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  fEMCALTriggerQA.push_back(new AliEMCALTriggerOnlineQAPP(name));
83  break;
85  fEMCALTriggerQA.push_back(new AliEMCALTriggerOfflineQAPP(name));
86  break;
89  break;
90  default:
91  break;
92  }
93  }
94  else {
95  AliInfo("Setting up the task for PbPb collisions.");
96  // No offline class for PbPb... yet
98  for (Int_t i = 0; i < GetNCentBins(); i++) {
99  fEMCALTriggerQA.push_back(new AliEMCALTriggerOnlineQAPbPb(name));
100  }
101  }
102 }
103 
108 {
109  for (auto triggerQA : fEMCALTriggerQA) delete triggerQA;
110 }
111 
116 {
118 
119  fESDEvent = dynamic_cast<AliESDEvent*>(InputEvent());
120 
121  if (!fESDEvent) {
122  fMinTimeStamp = 0;
123  fMaxTimeStamp = 0;
124  fTimeStampBinWidth = 0;
125  }
126 
127  if (!fLocalInitialized) return;
128 
129  fTriggerPatches = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTriggerPatchesName));
130 
131  if (fTriggerPatches) {
132  TString objname(fTriggerPatches->GetClass()->GetName());
133  TClass cls(objname);
134  if (!cls.InheritsFrom("AliEMCALTriggerPatchInfo")) {
135  AliError(Form("%s: Objects of type %s in %s are not inherited from AliEMCALTriggerPatchInfo!",
136  GetName(), cls.GetName(), fTriggerPatchesName.Data()));
137  fTriggerPatches = 0;
138  }
139  }
140 
141  if (!fTriggerPatches) {
142  fLocalInitialized = kFALSE;
143  AliError(Form("%s: Unable to get trigger patch container with name %s. Aborting", GetName(), fTriggerPatchesName.Data()));
144  return;
145  }
146 
147  for (auto triggerQA : fEMCALTriggerQA) triggerQA->ExecOnce();
148 }
149 
154 {
156 
157  if (fOutput) {
158  for (auto triggerQA : fEMCALTriggerQA) {
159  triggerQA->EnableHistogramsByTimeStamp(fTimeStampBinWidth);
160  triggerQA->SetDebugLevel(DebugLevel());
161  triggerQA->Init();
162  fOutput->Add(triggerQA->GetListOfHistograms());
163 
164  AliEMCALTriggerOfflineQAPP* triggerOffline = dynamic_cast<AliEMCALTriggerOfflineQAPP*>(triggerQA);
165  if (triggerOffline) triggerOffline->EnableDCal(fDCalPlots);
166  }
167 
168  PostData(1, fOutput);
169  }
170 }
171 
177 {
178  return kTRUE;
179 }
180 
181 
187 {
188  AliEMCALTriggerQA* triggerQA = GetTriggerQA(fBeamType == AliEmcalTriggerQATask::kAA ? fCentBin : 0);
189  if (!triggerQA) {
190  return kFALSE;
191  }
192 
193  if (fESDEvent) {
194  if (fESDEvent->GetTimeStamp() < fMinTimeStamp) return kFALSE;
195  if (fMaxTimeStamp > fMinTimeStamp && fESDEvent->GetTimeStamp() > fMaxTimeStamp) return kFALSE;
196  triggerQA->EventTimeStamp(fESDEvent->GetTimeStamp());
197  }
198 
199  if (fTriggerPatches) {
200  Int_t nPatches = fTriggerPatches->GetEntriesFast();
201 
202  AliDebug(2, Form("nPatches = %d", nPatches));
203 
204  for (Int_t i = 0; i < nPatches; i++) {
205  AliDebug(2, Form("Processing bkg patch %d", i));
206 
207  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
208  if (!patch) continue;
209  if (patch->GetADCAmp() < fMinAmplitude) continue;
210 
211  triggerQA->ProcessBkgPatch(patch);
212  }
213 
214  triggerQA->ComputeBackground();
215 
216  for (Int_t i = 0; i < nPatches; i++) {
217  AliDebug(2, Form("Processing patch %d", i));
218 
219  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
220  if (!patch) continue;
221  if (patch->GetADCAmp() < fMinAmplitude) continue;
222 
223  triggerQA->ProcessPatch(patch);
224  }
225  }
226 
227  if (fCaloTriggers) {
228  AliEMCALTriggerFastOR fastor;
229  fCaloTriggers->Reset();
230  Int_t globCol = -1, globRow = -1;
231  Float_t L0amp = -1;
232  Int_t L1amp = -1;
233  while (fCaloTriggers->Next()) {
234  // get position in global 2x2 tower coordinates
235  // A0 left bottom (0,0)
236  fCaloTriggers->GetPosition(globCol, globRow);
237  // for some strange reason some ADC amps are initialized in reconstruction
238  // as -1, neglect those
239  fCaloTriggers->GetL1TimeSum(L1amp);
240  if (L1amp < 0) L1amp = 0;
241  fCaloTriggers->GetAmplitude(L0amp);
242  L0amp *= 4;
243  if (L0amp < 0) L0amp = 0;
244 
245  Int_t time = -1;
246  Int_t nl0times(0);
247  fCaloTriggers->GetNL0Times(nl0times);
248  if(nl0times) {
249  TArrayI l0times(nl0times);
250  fCaloTriggers->GetL0Times(l0times.GetArray());
251  for(int itime = 0; itime < nl0times; itime++){
252  time = l0times[itime];
253  break;
254  }
255  }
256 
257  fastor.Initialize(L0amp, L1amp, globRow, globCol, time, fGeom);
258 
259  triggerQA->ProcessFastor(&fastor, fCaloCells);
260  }
261  }
262 
263  if (fCaloCells) {
264  const Int_t ncells = fCaloCells->GetNumberOfCells();
265  AliEMCALTriggerQA::AliEMCALCellInfo cellInfo;
266  for (Int_t pos = 0; pos < ncells; pos++) {
267  Double_t amp = fCaloCells->GetAmplitude(pos);
268  Int_t absId = fCaloCells->GetCellNumber(pos);
269  cellInfo.Set(absId, amp);
270  triggerQA->ProcessCell(cellInfo);
271  }
272  }
273 
274  triggerQA->EventCompleted();
275 
276  return kTRUE;
277 }
278 
284 {
285  fADCperBin = n;
286 
287  for (auto qa : fEMCALTriggerQA) qa->SetADCperBin(n);
288 }
289 
302 {
303  // Get the pointer to the existing analysis manager via the static access method
304  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
305  if (!mgr) {
306  ::Error("AliEmcalTriggerQATask", "No analysis manager to connect to.");
307  return 0;
308  }
309 
310  // Check the analysis type using the event handlers connected to the analysis manager
311  AliVEventHandler *evhand = mgr->GetInputEventHandler();
312  if (!evhand) {
313  ::Error("AliEmcalTriggerQATask", "This task requires an input event handler");
314  return 0;
315  }
316 
317  // Init the task and do settings
318  TString taskName("AliEmcalTriggerQATask");
319  if (!suffix.IsNull()) {
320  taskName += "_";
321  taskName += suffix;
322  }
323  AliEmcalTriggerQATask* eTask = new AliEmcalTriggerQATask(taskName, beamType, anaType);
324  eTask->SetTriggerPatchesName(triggerPatchesName);
325  if(triggersName.IsNull()) {
326  if (evhand->InheritsFrom("AliESDInputHandler")) {
327  triggersName = "EMCALTrigger";
328  ::Info("AddTaskEmcalTriggerQA", "ESD analysis, triggersName = \"%s\"", triggersName.Data());
329  }
330  else {
331  triggersName = "emcalTrigger";
332  ::Info("AddTaskEmcalTriggerQA", "AOD analysis, triggersName = \"%s\"", triggersName.Data());
333  }
334  }
335  if(cellsName.IsNull()) {
336  if (evhand->InheritsFrom("AliESDInputHandler")) {
337  cellsName = "EMCALCells";
338  ::Info("AddTaskEmcalTriggerQA", "ESD analysis, cellsName = \"%s\"", cellsName.Data());
339  }
340  else {
341  cellsName = "emcalCells";
342  ::Info("AddTaskEmcalTriggerQA", "AOD analysis, cellsName = \"%s\"", cellsName.Data());
343  }
344  }
345  eTask->SetCaloTriggersName(triggersName);
346  eTask->SetCaloCellsName(cellsName);
347 
348  // Final settings, pass to manager and set the containers
349  mgr->AddTask(eTask);
350  // Create containers for input/output
351  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
352  mgr->ConnectInput (eTask, 0, cinput1 );
353 
354  TString commonoutput;
355  if (subdir.IsNull()) {
356  commonoutput = mgr->GetCommonFileName();
357  }
358  else {
359  commonoutput = TString::Format("%s:%s", mgr->GetCommonFileName(), subdir.Data());
360  }
361  TString contOutName(Form("%s_histos", taskName.Data()));
362  mgr->ConnectOutput(eTask, 1, mgr->CreateContainer(contOutName, TList::Class(), AliAnalysisManager::kOutputContainer, commonoutput.Data()));
363 
364  return eTask;
365 }
366 
372 {
373  EBeamType_t beam = BeamTypeFromRunNumber(runnumber);
374  std::vector<std::string> triggerClasses = {"CINT7", "CEMC7", "CDMC7", "EG1", "EG2", "EJ1", "EJ2", "DG1", "DG2", "DJ1", "DJ2" };
375  AliEmcalTriggerQATask* task(nullptr);
376  for (auto triggerClass : triggerClasses) {
377  TString suffix(triggerClass.c_str());
378  suffix.ReplaceAll("-", "_");
379  task = AddTaskEmcalTriggerQA("EmcalTriggers", "", "", beam, kTriggerOfflineLightAnalysis, "CaloQA_default", suffix);
380  task->SetForceBeamType(beam);
381  task->AddAcceptedTriggerClass(triggerClass.c_str());
382  if (runnumber > 197692) {
384  }
385 
386  if (triggerClass.find("CINT7") != std::string::npos) {
387  for (auto triggerQA : task->fEMCALTriggerQA) {
388  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, EMCALTrigger::kTMEMCalLevel0, kTRUE);
389  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, EMCALTrigger::kTMEMCalGammaH, kTRUE);
390  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, EMCALTrigger::kTMEMCalJetH, kTRUE);
391  }
392  }
393  else {
394  EMCALTrigger::EMCalTriggerType_t triggerType = EMCALTrigger::kTMEMCalLevel0;
395  if (triggerClass.find("CEMC7") != std::string::npos || triggerClass.find("CDMC7") != std::string::npos) {
396  triggerType = EMCALTrigger::kTMEMCalLevel0;
397  }
398  else if (triggerClass.find("EG") != std::string::npos || triggerClass.find("DG") != std::string::npos) {
399  triggerType = EMCALTrigger::kTMEMCalGammaH;
400  }
401  else if (triggerClass.find("EJ") != std::string::npos || triggerClass.find("DJ") != std::string::npos) {
402  triggerType = EMCALTrigger::kTMEMCalJetH;
403  }
404  for (auto triggerQA : task->fEMCALTriggerQA) {
405  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, triggerType, kTRUE);
406  }
407  }
408  }
409  return task;
410 }
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
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
Int_t fCentBin
!event centrality bin
const Bool_t anaType
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
static AliEmcalTriggerQATask * AddTaskEmcalTriggerQA_QAtrain(Int_t runnumber)
EBeamType_t
Switch for the beam type.
AliVCaloTrigger * fCaloTriggers
!calo triggers
AliEMCALTriggerQA * GetTriggerQA(Int_t i=0)