AliPhysics  80ccde44 (80ccde44)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"),
64  fEMCALTriggerQA(),
65  fADCperBin(16),
66  fMinAmplitude(0),
67  fDCalPlots(kTRUE),
68  fMinTimeStamp(0),
69  fMaxTimeStamp(0),
70  fTimeStampBinWidth(0),
71  fESDEvent(0),
72  fTriggerPatches(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(fCentBin);
189  if (!triggerQA) return kFALSE;
190 
191  if (fESDEvent) {
192  if (fESDEvent->GetTimeStamp() < fMinTimeStamp) return kFALSE;
193  if (fMaxTimeStamp > fMinTimeStamp && fESDEvent->GetTimeStamp() > fMaxTimeStamp) return kFALSE;
194  triggerQA->EventTimeStamp(fESDEvent->GetTimeStamp());
195  }
196 
197  if (fTriggerPatches) {
198  Int_t nPatches = fTriggerPatches->GetEntriesFast();
199 
200  AliDebug(2, Form("nPatches = %d", nPatches));
201 
202  for (Int_t i = 0; i < nPatches; i++) {
203  AliDebug(2, Form("Processing bkg patch %d", i));
204 
205  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
206  if (!patch) continue;
207  if (patch->GetADCAmp() < fMinAmplitude) continue;
208 
209  triggerQA->ProcessBkgPatch(patch);
210  }
211 
212  triggerQA->ComputeBackground();
213 
214  for (Int_t i = 0; i < nPatches; i++) {
215  AliDebug(2, Form("Processing patch %d", i));
216 
217  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
218  if (!patch) continue;
219  if (patch->GetADCAmp() < fMinAmplitude) continue;
220 
221  triggerQA->ProcessPatch(patch);
222  }
223  }
224 
225  if (fCaloTriggers) {
226  AliEMCALTriggerFastOR fastor;
227  fCaloTriggers->Reset();
228  Int_t globCol = -1, globRow = -1;
229  Float_t L0amp = -1;
230  Int_t L1amp = -1;
231  while (fCaloTriggers->Next()) {
232  // get position in global 2x2 tower coordinates
233  // A0 left bottom (0,0)
234  fCaloTriggers->GetPosition(globCol, globRow);
235  // for some strange reason some ADC amps are initialized in reconstruction
236  // as -1, neglect those
237  fCaloTriggers->GetL1TimeSum(L1amp);
238  if (L1amp < 0) L1amp = 0;
239  fCaloTriggers->GetAmplitude(L0amp);
240  L0amp *= 4;
241  if (L0amp < 0) L0amp = 0;
242 
243  Int_t time = -1;
244  Int_t nl0times(0);
245  fCaloTriggers->GetNL0Times(nl0times);
246  if(nl0times) {
247  TArrayI l0times(nl0times);
248  fCaloTriggers->GetL0Times(l0times.GetArray());
249  for(int itime = 0; itime < nl0times; itime++){
250  time = l0times[itime];
251  break;
252  }
253  }
254 
255  fastor.Initialize(L0amp, L1amp, globRow, globCol, time, fGeom);
256 
257  triggerQA->ProcessFastor(&fastor, fCaloCells);
258  }
259  }
260 
261  if (fCaloCells) {
262  const Int_t ncells = fCaloCells->GetNumberOfCells();
263  AliEMCALTriggerQA::AliEMCALCellInfo cellInfo;
264  for (Int_t pos = 0; pos < ncells; pos++) {
265  Double_t amp = fCaloCells->GetAmplitude(pos);
266  Int_t absId = fCaloCells->GetCellNumber(pos);
267  cellInfo.Set(absId, amp);
268  triggerQA->ProcessCell(cellInfo);
269  }
270  }
271 
272  triggerQA->EventCompleted();
273 
274  return kTRUE;
275 }
276 
282 {
283  fADCperBin = n;
284 
285  for (auto qa : fEMCALTriggerQA) qa->SetADCperBin(n);
286 }
287 
300 {
301  // Get the pointer to the existing analysis manager via the static access method
302  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
303  if (!mgr) {
304  ::Error("AliEmcalTriggerQATask", "No analysis manager to connect to.");
305  return 0;
306  }
307 
308  // Check the analysis type using the event handlers connected to the analysis manager
309  AliVEventHandler *evhand = mgr->GetInputEventHandler();
310  if (!evhand) {
311  ::Error("AliEmcalTriggerQATask", "This task requires an input event handler");
312  return 0;
313  }
314 
315  // Init the task and do settings
316  TString taskName("AliEmcalTriggerQATask");
317  if (!suffix.IsNull()) {
318  taskName += "_";
319  taskName += suffix;
320  }
321  AliEmcalTriggerQATask* eTask = new AliEmcalTriggerQATask(taskName, beamType, anaType);
322  eTask->SetTriggerPatchesName(triggerPatchesName);
323  if(triggersName.IsNull()) {
324  if (evhand->InheritsFrom("AliESDInputHandler")) {
325  triggersName = "EMCALTrigger";
326  ::Info("AddTaskEmcalTriggerQA", "ESD analysis, triggersName = \"%s\"", triggersName.Data());
327  }
328  else {
329  triggersName = "emcalTrigger";
330  ::Info("AddTaskEmcalTriggerQA", "AOD analysis, triggersName = \"%s\"", triggersName.Data());
331  }
332  }
333  if(cellsName.IsNull()) {
334  if (evhand->InheritsFrom("AliESDInputHandler")) {
335  cellsName = "EMCALCells";
336  ::Info("AddTaskEmcalTriggerQA", "ESD analysis, cellsName = \"%s\"", cellsName.Data());
337  }
338  else {
339  cellsName = "emcalCells";
340  ::Info("AddTaskEmcalTriggerQA", "AOD analysis, cellsName = \"%s\"", cellsName.Data());
341  }
342  }
343  eTask->SetCaloTriggersName(triggersName);
344  eTask->SetCaloCellsName(cellsName);
345 
346  // Final settings, pass to manager and set the containers
347  mgr->AddTask(eTask);
348  // Create containers for input/output
349  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
350  mgr->ConnectInput (eTask, 0, cinput1 );
351 
352  TString commonoutput;
353  if (subdir.IsNull()) {
354  commonoutput = mgr->GetCommonFileName();
355  }
356  else {
357  commonoutput = TString::Format("%s:%s", mgr->GetCommonFileName(), subdir.Data());
358  }
359  TString contOutName(Form("%s_histos", taskName.Data()));
360  mgr->ConnectOutput(eTask, 1, mgr->CreateContainer(contOutName, TList::Class(), AliAnalysisManager::kOutputContainer, commonoutput.Data()));
361 
362  return eTask;
363 }
364 
370 {
371  EBeamType_t beam = BeamTypeFromRunNumber(runnumber);
372  std::vector<std::string> triggerClasses = {"CINT7", "CEMC7", "CDMC7", "EG1", "EG2", "EJ1", "EJ2", "DG1", "DG2", "DJ1", "DJ2" };
373  for (auto triggerClass : triggerClasses) {
374  TString suffix(triggerClass.c_str());
375  suffix.ReplaceAll("-", "_");
376  AliEmcalTriggerQATask* task = AddTaskEmcalTriggerQA("EmcalTriggers", "", "", beam, kTriggerOfflineLightAnalysis, "CaloQA_default", suffix);
377  task->SetForceBeamType(beam);
378  task->AddAcceptedTriggerClass(triggerClass.c_str());
379  if (runnumber > 197692) {
381  }
382 
383  if (triggerClass.find("CINT7") != std::string::npos) {
384  for (auto triggerQA : task->fEMCALTriggerQA) {
385  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, EMCALTrigger::kTMEMCalLevel0, kTRUE);
386  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, EMCALTrigger::kTMEMCalGammaH, kTRUE);
387  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, EMCALTrigger::kTMEMCalJetH, kTRUE);
388  }
389  }
390  else {
391  EMCALTrigger::EMCalTriggerType_t triggerType = EMCALTrigger::kTMEMCalLevel0;
392  if (triggerClass.find("CEMC7") != std::string::npos || triggerClass.find("CDMC7") != std::string::npos) {
393  triggerType = EMCALTrigger::kTMEMCalLevel0;
394  }
395  else if (triggerClass.find("EG") != std::string::npos || triggerClass.find("DG") != std::string::npos) {
396  triggerType = EMCALTrigger::kTMEMCalGammaH;
397  }
398  else if (triggerClass.find("EJ") != std::string::npos || triggerClass.find("DJ") != std::string::npos) {
399  triggerType = EMCALTrigger::kTMEMCalJetH;
400  }
401  for (auto triggerQA : task->fEMCALTriggerQA) {
402  triggerQA->EnablePatchType(AliEMCALTriggerQA::kRecalcPatch, triggerType, kTRUE);
403  }
404  }
405  }
406 }
Int_t fADCperBin
ADC counts per bin.
void SetTriggerPatchesName(const char *name)
AliEMCALGeometry * fGeom
!emcal geometry
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.
static void AddTaskEmcalTriggerQA_QAtrain(Int_t runnumber)
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
EBeamType_t
Switch for the beam type.
AliVCaloTrigger * fCaloTriggers
!calo triggers
AliEMCALTriggerQA * GetTriggerQA(Int_t i=0)