AliPhysics  9538fdd (9538fdd)
 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  SetNCentBins(nCentBins);
77 
78  if (nCentBins == 0) {
79  AliInfo("Setting up the task for pp collisions.");
81  fEMCALTriggerQA.SetLast(0);
82  if (online){
83  fEMCALTriggerQA.AddAt(new AliEMCALTriggerOnlineQAPP(name), 0);
84  }
85  else {
86  fEMCALTriggerQA.AddAt(new AliEMCALTriggerOfflineQAPP(name), 0);
87  }
88  }
89  else {
90  AliInfo("Setting up the task for PbPb collisions.");
91  // No offline class for PbPb... yet
93  fEMCALTriggerQA.SetLast(nCentBins-1);
94  for (Int_t i = 0; i < nCentBins; i++) {
95  fEMCALTriggerQA.AddAt(new AliEMCALTriggerOnlineQAPbPb(name), i);
96  }
97  }
98 
99  fEMCALTriggerQA.SetOwner(kTRUE);
100 }
101 
106 {
107 }
108 
113 {
115 
116  fESDEvent = dynamic_cast<AliESDEvent*>(InputEvent());
117 
118  if (!fESDEvent){
119  fMinTimeStamp = 0;
120  fMaxTimeStamp = 0;
121  fTimeStampBinWidth = 0;
122  }
123 
124  if (!fLocalInitialized) return;
125 
126  fTriggerPatches = dynamic_cast<TClonesArray*>(InputEvent()->FindListObject(fTriggerPatchesName));
127 
128  if (fTriggerPatches) {
129  TString objname(fTriggerPatches->GetClass()->GetName());
130  TClass cls(objname);
131  if (!cls.InheritsFrom("AliEMCALTriggerPatchInfo")) {
132  AliError(Form("%s: Objects of type %s in %s are not inherited from AliEMCALTriggerPatchInfo!",
133  GetName(), cls.GetName(), fTriggerPatchesName.Data()));
134  fTriggerPatches = 0;
135  }
136  }
137 
138  if (!fTriggerPatches) {
139  fLocalInitialized = kFALSE;
140  AliError(Form("%s: Unable to get trigger patch container with name %s. Aborting", GetName(), fTriggerPatchesName.Data()));
141  return;
142  }
143 
144  for (Int_t i = 0; i < fNcentBins; i++) {
145  GetTriggerQA(i)->ExecOnce();
146  }
147 }
148 
153 {
155 
156  if (fOutput) {
157  for (Int_t i = 0; i < fNcentBins; i++) {
158  GetTriggerQA(i)->EnableHistogramsByTimeStamp(fTimeStampBinWidth);
159  GetTriggerQA(i)->SetDebugLevel(DebugLevel());
160  GetTriggerQA(i)->Init();
161  fOutput->Add(GetTriggerQA(i)->GetListOfHistograms());
162 
163  AliEMCALTriggerOfflineQAPP* triggerOffline = dynamic_cast<AliEMCALTriggerOfflineQAPP*>(GetTriggerQA(i));
164  if (triggerOffline) {
165  triggerOffline->EnableDCal(fDCalPlots);
166  }
167  }
168 
169  PostData(1, fOutput);
170  }
171 }
172 
178 {
179  return kTRUE;
180 }
181 
182 
188 {
189  if (fESDEvent) {
190  if (fESDEvent->GetTimeStamp() < fMinTimeStamp) return kFALSE;
191  if (fMaxTimeStamp > fMinTimeStamp && fESDEvent->GetTimeStamp() > fMaxTimeStamp) return kFALSE;
192  GetTriggerQA(fCentBin)->EventTimeStamp(fESDEvent->GetTimeStamp());
193  }
194 
195  if (fTriggerPatches) {
196  Int_t nPatches = fTriggerPatches->GetEntriesFast();
197 
198  AliDebug(2, Form("nPatches = %d", nPatches));
199 
200  for (Int_t i = 0; i < nPatches; i++) {
201  AliDebug(2, Form("Processing bkg patch %d", i));
202 
203  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
204  if (!patch) continue;
205  if (patch->GetADCAmp() < fMinAmplitude) continue;
206 
207  GetTriggerQA(fCentBin)->ProcessBkgPatch(patch);
208  }
209 
210  GetTriggerQA(fCentBin)->ComputeBackground();
211 
212  for (Int_t i = 0; i < nPatches; i++) {
213  AliDebug(2, Form("Processing patch %d", i));
214 
215  AliEMCALTriggerPatchInfo* patch = static_cast<AliEMCALTriggerPatchInfo*>(fTriggerPatches->At(i));
216  if (!patch) continue;
217  if (patch->GetADCAmp() < fMinAmplitude) continue;
218 
219  GetTriggerQA(fCentBin)->ProcessPatch(patch);
220  }
221  }
222 
223  if (fCaloTriggers) {
224  AliEMCALTriggerFastOR fastor;
225  fCaloTriggers->Reset();
226  Int_t globCol = -1, globRow = -1;
227  Float_t L0amp = -1;
228  Int_t L1amp = -1;
229  while (fCaloTriggers->Next()) {
230  // get position in global 2x2 tower coordinates
231  // A0 left bottom (0,0)
232  fCaloTriggers->GetPosition(globCol, globRow);
233  // for some strange reason some ADC amps are initialized in reconstruction
234  // as -1, neglect those
235  fCaloTriggers->GetL1TimeSum(L1amp);
236  if (L1amp < 0) L1amp = 0;
237  fCaloTriggers->GetAmplitude(L0amp);
238  L0amp *= 4;
239  if (L0amp < 0) L0amp = 0;
240 
241  Int_t time = -1;
242  Int_t nl0times(0);
243  fCaloTriggers->GetNL0Times(nl0times);
244  if(nl0times) {
245  TArrayI l0times(nl0times);
246  fCaloTriggers->GetL0Times(l0times.GetArray());
247  for(int itime = 0; itime < nl0times; itime++){
248  time = l0times[itime];
249  break;
250  }
251  }
252 
253  fastor.Initialize(L0amp, L1amp, globRow, globCol, time, fGeom);
254 
255  GetTriggerQA(fCentBin)->ProcessFastor(&fastor, fCaloCells);
256  }
257  }
258 
259  if (fCaloCells) {
260  const Int_t ncells = fCaloCells->GetNumberOfCells();
261  AliEMCALTriggerQA::AliEMCALCellInfo cellInfo;
262  for (Int_t pos = 0; pos < ncells; pos++) {
263  Double_t amp = fCaloCells->GetAmplitude(pos);
264  Int_t absId = fCaloCells->GetCellNumber(pos);
265  cellInfo.Set(absId, amp);
266  GetTriggerQA(fCentBin)->ProcessCell(cellInfo);
267  }
268  }
269 
270  GetTriggerQA(fCentBin)->EventCompleted();
271 
272  return kTRUE;
273 }
274 
280 {
281  fADCperBin = n;
282 
283  TIter next(&fEMCALTriggerQA);
284  AliEMCALTriggerQA* qa = 0;
285  while ((qa = static_cast<AliEMCALTriggerQA*>(next()))) {
286  qa->SetADCperBin(n);
287  }
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, nCentBins, online);
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  Int_t nCentBins = 0;
375  if (beam == kpA || beam == kAA) nCentBins = 4;
376  std::vector<std::string> triggerClasses = {"CINT7", "CEMC7", "CDMC7", "EG1", "EG2", "EJ1", "EJ2", "DG1", "DG2", "DJ1", "DJ2" };
377  for (auto triggerClass : triggerClasses) {
378  TString suffix(triggerClass.c_str());
379  suffix.ReplaceAll("-", "_");
380  AliEmcalTriggerQATask* task = AddTaskEmcalTriggerQA("EmcalTriggers", "", "", nCentBins, kFALSE, "CaloQA_default", suffix);
381  task->AddAcceptedTriggerClass(triggerClass.c_str());
382  task->SetForceBeamType(beam);
383  }
384 }
Int_t fADCperBin
ADC counts per bin.
void SetTriggerPatchesName(const char *name)
Int_t fNcentBins
how many centrality bins
AliEMCALGeometry * fGeom
!emcal geometry
double Double_t
Definition: External.C:58
TClonesArray * fTriggerPatches
! trigger array in
UInt_t fTimeStampBinWidth
Time stamp bin width.
static AliEmcalTriggerQATask * AddTaskEmcalTriggerQA(TString triggerPatchesName="EmcalTriggers", TString cellsName="", TString triggersName="", Int_t nCentBins=0, Bool_t online=kFALSE, TString subdir="", TString suffix="")
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
Int_t nCentBins
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)
unsigned int UInt_t
Definition: External.C:33
float Float_t
Definition: External.C:68
Base task in the EMCAL framework (lighter version of AliAnalysisTaskEmcal)
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)
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
TObjArray fEMCALTriggerQA
produces the QA histograms
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)