AliPhysics  ec7afe5 (ec7afe5)
 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 
30 #include "AliEmcalTriggerQATask.h"
31 
32 using namespace EMCALTrigger;
33 
37 
43  fTriggerPatchesName("EmcalTriggers"),
44  fEMCALTriggerQA(),
45  fADCperBin(16),
46  fMinAmplitude(0),
47  fDCalPlots(kTRUE),
48  fMinTimeStamp(0),
49  fMaxTimeStamp(0),
50  fTimeStampBinWidth(0),
51  fTriggerPatches(0),
52  fESDEvent(0)
53 {
54 }
55 
61  AliAnalysisTaskEmcalLight(name,kTRUE),
62  fTriggerPatchesName("EmcalTriggers"),
63  fEMCALTriggerQA(),
64  fADCperBin(16),
65  fMinAmplitude(0),
66  fDCalPlots(kTRUE),
67  fMinTimeStamp(0),
68  fMaxTimeStamp(0),
69  fTimeStampBinWidth(0),
70  fTriggerPatches(0),
71  fESDEvent(0)
72 {
73  // Constructor.
75 
76  if (beamType == kpp) {
77  AliInfo("Setting up the task for pp collisions.");
79  if (online){
80  fEMCALTriggerQA.push_back(new AliEMCALTriggerOnlineQAPP(name));
81  }
82  else {
83  fEMCALTriggerQA.push_back(new AliEMCALTriggerOfflineQAPP(name));
84  }
85  }
86  else {
87  AliInfo("Setting up the task for PbPb collisions.");
88  // No offline class for PbPb... yet
90  for (Int_t i = 0; i < GetNCentBins(); i++) {
91  fEMCALTriggerQA.push_back(new AliEMCALTriggerOnlineQAPbPb(name));
92  }
93  }
94 }
95 
100 {
101  for (auto triggerQA : fEMCALTriggerQA) delete triggerQA;
102 }
103 
108 {
110 
111  fESDEvent = dynamic_cast<AliESDEvent*>(InputEvent());
112 
113  if (!fESDEvent) {
114  fMinTimeStamp = 0;
115  fMaxTimeStamp = 0;
116  fTimeStampBinWidth = 0;
117  }
118 
119  if (!fLocalInitialized) return;
120 
121  fTriggerPatches = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTriggerPatchesName));
122 
123  if (fTriggerPatches) {
124  TString objname(fTriggerPatches->GetClass()->GetName());
125  TClass cls(objname);
126  if (!cls.InheritsFrom("AliEMCALTriggerPatchInfo")) {
127  AliError(Form("%s: Objects of type %s in %s are not inherited from AliEMCALTriggerPatchInfo!",
128  GetName(), cls.GetName(), fTriggerPatchesName.Data()));
129  fTriggerPatches = 0;
130  }
131  }
132 
133  if (!fTriggerPatches) {
134  fLocalInitialized = kFALSE;
135  AliError(Form("%s: Unable to get trigger patch container with name %s. Aborting", GetName(), fTriggerPatchesName.Data()));
136  return;
137  }
138 
139  for (auto triggerQA : fEMCALTriggerQA) triggerQA->ExecOnce();
140 }
141 
146 {
148 
149  if (fOutput) {
150  for (auto triggerQA : fEMCALTriggerQA) {
151  triggerQA->EnableHistogramsByTimeStamp(fTimeStampBinWidth);
152  triggerQA->SetDebugLevel(DebugLevel());
153  triggerQA->Init();
154  fOutput->Add(triggerQA->GetListOfHistograms());
155 
156  AliEMCALTriggerOfflineQAPP* triggerOffline = dynamic_cast<AliEMCALTriggerOfflineQAPP*>(triggerQA);
157  if (triggerOffline) triggerOffline->EnableDCal(fDCalPlots);
158  }
159 
160  PostData(1, fOutput);
161  }
162 }
163 
169 {
170  return kTRUE;
171 }
172 
173 
179 {
180  AliEMCALTriggerQA* triggerQA = GetTriggerQA(fCentBin);
181  if (!triggerQA) return kFALSE;
182 
183  if (fESDEvent) {
184  if (fESDEvent->GetTimeStamp() < fMinTimeStamp) return kFALSE;
185  if (fMaxTimeStamp > fMinTimeStamp && fESDEvent->GetTimeStamp() > fMaxTimeStamp) return kFALSE;
186  triggerQA->EventTimeStamp(fESDEvent->GetTimeStamp());
187  }
188 
189  if (fTriggerPatches) {
190  Int_t nPatches = fTriggerPatches->GetEntriesFast();
191 
192  AliDebug(2, Form("nPatches = %d", nPatches));
193 
194  for (Int_t i = 0; i < nPatches; i++) {
195  AliDebug(2, Form("Processing bkg patch %d", i));
196 
197  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
198  if (!patch) continue;
199  if (patch->GetADCAmp() < fMinAmplitude) continue;
200 
201  triggerQA->ProcessBkgPatch(patch);
202  }
203 
204  triggerQA->ComputeBackground();
205 
206  for (Int_t i = 0; i < nPatches; i++) {
207  AliDebug(2, Form("Processing patch %d", i));
208 
209  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
210  if (!patch) continue;
211  if (patch->GetADCAmp() < fMinAmplitude) continue;
212 
213  triggerQA->ProcessPatch(patch);
214  }
215  }
216 
217  if (fCaloTriggers) {
218  AliEMCALTriggerFastOR fastor;
219  fCaloTriggers->Reset();
220  Int_t globCol = -1, globRow = -1;
221  Float_t L0amp = -1;
222  Int_t L1amp = -1;
223  while (fCaloTriggers->Next()) {
224  // get position in global 2x2 tower coordinates
225  // A0 left bottom (0,0)
226  fCaloTriggers->GetPosition(globCol, globRow);
227  // for some strange reason some ADC amps are initialized in reconstruction
228  // as -1, neglect those
229  fCaloTriggers->GetL1TimeSum(L1amp);
230  if (L1amp < 0) L1amp = 0;
231  fCaloTriggers->GetAmplitude(L0amp);
232  L0amp *= 4;
233  if (L0amp < 0) L0amp = 0;
234 
235  Int_t time = -1;
236  Int_t nl0times(0);
237  fCaloTriggers->GetNL0Times(nl0times);
238  if(nl0times) {
239  TArrayI l0times(nl0times);
240  fCaloTriggers->GetL0Times(l0times.GetArray());
241  for(int itime = 0; itime < nl0times; itime++){
242  time = l0times[itime];
243  break;
244  }
245  }
246 
247  fastor.Initialize(L0amp, L1amp, globRow, globCol, time, fGeom);
248 
249  triggerQA->ProcessFastor(&fastor, fCaloCells);
250  }
251  }
252 
253  if (fCaloCells) {
254  const Int_t ncells = fCaloCells->GetNumberOfCells();
255  AliEMCALTriggerQA::AliEMCALCellInfo cellInfo;
256  for (Int_t pos = 0; pos < ncells; pos++) {
257  Double_t amp = fCaloCells->GetAmplitude(pos);
258  Int_t absId = fCaloCells->GetCellNumber(pos);
259  cellInfo.Set(absId, amp);
260  triggerQA->ProcessCell(cellInfo);
261  }
262  }
263 
264  triggerQA->EventCompleted();
265 
266  return kTRUE;
267 }
268 
274 {
275  fADCperBin = n;
276 
277  for (auto qa : fEMCALTriggerQA) qa->SetADCperBin(n);
278 }
279 
292 {
293  // Get the pointer to the existing analysis manager via the static access method
294  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
295  if (!mgr) {
296  ::Error("AliEmcalTriggerQATask", "No analysis manager to connect to.");
297  return 0;
298  }
299 
300  // Check the analysis type using the event handlers connected to the analysis manager
301  AliVEventHandler *evhand = mgr->GetInputEventHandler();
302  if (!evhand) {
303  ::Error("AliEmcalTriggerQATask", "This task requires an input event handler");
304  return 0;
305  }
306 
307  // Init the task and do settings
308  TString taskName("AliEmcalTriggerQATask");
309  if (!suffix.IsNull()) {
310  taskName += "_";
311  taskName += suffix;
312  }
313  AliEmcalTriggerQATask* eTask = new AliEmcalTriggerQATask(taskName, beamType, online);
314  eTask->SetTriggerPatchesName(triggerPatchesName);
315  if(triggersName.IsNull()) {
316  if (evhand->InheritsFrom("AliESDInputHandler")) {
317  triggersName = "EMCALTrigger";
318  ::Info("AddTaskEmcalTriggerQA", "ESD analysis, triggersName = \"%s\"", triggersName.Data());
319  }
320  else {
321  triggersName = "emcalTrigger";
322  ::Info("AddTaskEmcalTriggerQA", "AOD analysis, triggersName = \"%s\"", triggersName.Data());
323  }
324  }
325  if(cellsName.IsNull()) {
326  if (evhand->InheritsFrom("AliESDInputHandler")) {
327  cellsName = "EMCALCells";
328  ::Info("AddTaskEmcalTriggerQA", "ESD analysis, cellsName = \"%s\"", cellsName.Data());
329  }
330  else {
331  cellsName = "emcalCells";
332  ::Info("AddTaskEmcalTriggerQA", "AOD analysis, cellsName = \"%s\"", cellsName.Data());
333  }
334  }
335  eTask->SetCaloTriggersName(triggersName);
336  eTask->SetCaloCellsName(cellsName);
337 
338  // Final settings, pass to manager and set the containers
339  mgr->AddTask(eTask);
340  // Create containers for input/output
341  AliAnalysisDataContainer *cinput1 = mgr->GetCommonInputContainer();
342  mgr->ConnectInput (eTask, 0, cinput1 );
343 
344  TString commonoutput;
345  if (subdir.IsNull()) {
346  commonoutput = mgr->GetCommonFileName();
347  }
348  else {
349  commonoutput = TString::Format("%s:%s", mgr->GetCommonFileName(), subdir.Data());
350  }
351  TString contOutName(Form("%s_histos", taskName.Data()));
352  mgr->ConnectOutput(eTask, 1, mgr->CreateContainer(contOutName, TList::Class(), AliAnalysisManager::kOutputContainer, commonoutput.Data()));
353 
354  return eTask;
355 }
356 
362 {
363  EBeamType_t beam = BeamTypeFromRunNumber(runnumber);
364  std::vector<std::string> triggerClasses = {"CINT7", "CEMC7", "CDMC7", "EG1", "EG2", "EJ1", "EJ2", "DG1", "DG2", "DJ1", "DJ2" };
365  for (auto triggerClass : triggerClasses) {
366  TString suffix(triggerClass.c_str());
367  suffix.ReplaceAll("-", "_");
368  AliEmcalTriggerQATask* task = AddTaskEmcalTriggerQA("EmcalTriggers", "", "", beam, kFALSE, "CaloQA_default", suffix);
369  task->AddAcceptedTriggerClass(triggerClass.c_str());
370  task->SetForceBeamType(beam);
371  }
372 }
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
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)
std::vector< AliEMCALTriggerQA * > fEMCALTriggerQA
produces the QA histograms
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)
static AliEmcalTriggerQATask * AddTaskEmcalTriggerQA(TString triggerPatchesName="EmcalTriggers", TString cellsName="", TString triggersName="", EBeamType_t beamType=kpp, Bool_t online=kFALSE, TString subdir="", TString suffix="")
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
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)