AliPhysics  8630145 (8630145)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliAnalysisTaskEmcalTriggerBase.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 <functional>
16 #include <iostream>
17 
18 #include <TClonesArray.h>
19 #include <TGrid.h>
20 #include <THistManager.h>
21 #include <TParameter.h>
22 
24 #include "AliAnalysisUtils.h"
25 #include "AliEMCALGeometry.h"
26 #include "AliEMCALTriggerPatchInfo.h"
27 #include "AliEMCALTriggerMapping.h"
28 #include "AliESDEvent.h"
29 #include "AliInputEventHandler.h"
30 #include "AliLog.h"
31 #include "AliOADBContainer.h"
32 #include "AliVVertex.h"
33 
37 
38 namespace EMCalTriggerPtAnalysis {
39 
40 AliAnalysisTaskEmcalTriggerBase::AliAnalysisTaskEmcalTriggerBase():
42  fTriggerSelection(nullptr),
43  fHistos(nullptr),
44  fTriggerStringFromPatches(kFALSE),
45  fSelectedTriggers(),
46  fVertexCut(-10., 10.),
47  fNameDownscaleOADB(""),
48  fDownscaleOADB(nullptr),
49  fDownscaleFactors(nullptr),
50  fNameMaskedFastorOADB(),
51  fMaskedFastorOADB(nullptr),
52  fMaskedFastors(),
53  fOnlineTriggerThresholds(),
54  fSelectNoiseEvents(false),
55  fRejectNoiseEvents(false)
56 {
57  SetNeedEmcalGeom(true);
58  SetCaloTriggerPatchInfoName("EmcalTriggers");
59 }
60 
62  AliAnalysisTaskEmcal(name, true),
63  fTriggerSelection(nullptr),
64  fHistos(nullptr),
65  fTriggerStringFromPatches(kFALSE),
66  fSelectedTriggers(),
67  fVertexCut(-10., 10.),
68  fNameDownscaleOADB(""),
69  fDownscaleOADB(nullptr),
70  fDownscaleFactors(nullptr),
71  fNameMaskedFastorOADB(),
72  fMaskedFastorOADB(nullptr),
73  fMaskedFastors(),
74  fOnlineTriggerThresholds(),
75  fSelectNoiseEvents(false),
76  fRejectNoiseEvents(false)
77 {
78  SetNeedEmcalGeom(true);
79  SetCaloTriggerPatchInfoName("EmcalTriggers");
80 }
81 
84  if(fHistos) delete fHistos;
85  if(fDownscaleOADB) delete fDownscaleOADB;
86 }
87 
90  if(!fAliAnalysisUtils) fAliAnalysisUtils = new AliAnalysisUtils;
91 
92  fHistos = new THistManager(Form("Histos_%s", GetName()));
93 
96 
97  for(auto h : *(fHistos->GetListOfHistograms())) fOutput->Add(h);
98 
99  PostData(1, fOutput);
100 }
101 
103  // Apply trigger selection
105  if(!fSelectedTriggers.size()) return false;
106 
108 
109  const AliVVertex *vtx = fInputEvent->GetPrimaryVertex();
110  //if(!fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5.)) return; // reject pileup event
111  if(vtx->GetNContributors() < 1) return false;
112  if(fInputEvent->IsA() == AliESDEvent::Class() && fAliAnalysisUtils->IsFirstEventInChunk(fInputEvent)) return false;
113  if(fAliAnalysisUtils->IsPileUpEvent(fInputEvent)) return false; // Apply new vertex cut
114 
115  if(!fAliAnalysisUtils->IsVertexSelected2013pA(fInputEvent))return false; // Apply new vertex cut
116  if(!fVertexCut.IsInRange(fVertex[2])) return false;
117  if(!IsUserEventSelected()) return false;
118 
119  // Do MC outlier cut
120  if(fIsPythia){
121  if(!CheckMCOutliers()){
122  AliDebugStream(1) << GetName() << ": Reject MC outliers" << std::endl;
123  return false;
124  }
125  }
126 
128  return true;
129 }
130 
131 
133  fSelectedTriggers.clear();
134 
135  TString triggerstring = "";
138  } else {
139  triggerstring = fInputEvent->GetFiredTriggerClasses();
140  }
141  UInt_t selectionstatus = fInputHandler->IsEventSelected();
142  Bool_t isMinBias = selectionstatus & AliVEvent::kINT7,
144  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ1] = (selectionstatus & AliVEvent::kEMCEJE) && triggerstring.Contains("EJ1");
145  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ2] = (selectionstatus & AliVEvent::kEMCEJE) && triggerstring.Contains("EJ2");
146  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG1] = (selectionstatus & AliVEvent::kEMCEGA) && triggerstring.Contains("EG1"),
147  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG2] = (selectionstatus & AliVEvent::kEMCEGA) && triggerstring.Contains("EG2");
148  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0] = (selectionstatus & AliVEvent::kEMC7) && triggerstring.Contains("CEMC7");
149  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ1] = (selectionstatus & AliVEvent::kEMCEJE) && triggerstring.Contains("DJ1");
150  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ2] = (selectionstatus & AliVEvent::kEMCEJE) && triggerstring.Contains("DJ2");
151  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG1] = (selectionstatus & AliVEvent::kEMCEGA) && triggerstring.Contains("DG1");
152  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG2] = (selectionstatus & AliVEvent::kEMCEGA) && triggerstring.Contains("DG2");
153  emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0] = (selectionstatus & AliVEvent::kEMC7) && triggerstring.Contains("CDMC7");
155  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++)
157  }
158  // Online selection / rejection
160  if(fRejectNoiseEvents){
161  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++){
162  if(emcalTriggers[itrg])
164  }
165  } else {
166  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++){
167  if(emcalTriggers[itrg])
169  }
170  }
171  }
172  if(isMinBias) fSelectedTriggers.push_back("MB");
173  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0]){
174  fSelectedTriggers.push_back("EMC7");
175  if(!isMinBias) fSelectedTriggers.push_back("EMC7excl");
176  }
177  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0]){
178  fSelectedTriggers.push_back("DMC7");
179  if(!isMinBias) fSelectedTriggers.push_back("DMC7excl");
180  }
181  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ2]){
182  fSelectedTriggers.push_back("EJ2");
183  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EJ2excl");
184  }
185  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ1]){
186  fSelectedTriggers.push_back("EJ1");
187  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ2])) fSelectedTriggers.push_back("EJ1excl");
188  }
189  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ2]){
190  fSelectedTriggers.push_back("DJ2");
191  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0])) fSelectedTriggers.push_back("DJ2excl");
192  }
193  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ1]){
194  fSelectedTriggers.push_back("DJ1");
195  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ2])) fSelectedTriggers.push_back("DJ1excl");
196  }
197  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG2]){
198  fSelectedTriggers.push_back("EG2");
199  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EG2excl");
200  }
201  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG1]){
202  fSelectedTriggers.push_back("EG1");
203  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG2])) fSelectedTriggers.push_back("EG1excl");
204  }
205  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG2]){
206  fSelectedTriggers.push_back("DG2");
207  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0])) fSelectedTriggers.push_back("DG2excl");
208  }
209  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG1]){
210  fSelectedTriggers.push_back("DG1");
211  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG2])) fSelectedTriggers.push_back("DG1excl");
212  }
213 }
214 
217 
218  if(!fLocalInitialized){
219  return;
220  }
221 
222  // Handle OADB container with downscaling factors
223  if(fNameDownscaleOADB.Length()){
224  if(fNameDownscaleOADB.Contains("alien://") && ! gGrid) TGrid::Connect("alien://");
225  fDownscaleOADB = new AliOADBContainer("AliEmcalDownscaleFactors");
226  fDownscaleOADB->InitFromFile(fNameDownscaleOADB.Data(), "AliEmcalDownscaleFactors");
227  }
228  // Load OADB container with masked fastors (in case fastor masking is switched on)
230  if(fNameMaskedFastorOADB.Contains("alien://") && ! gGrid) TGrid::Connect("alien://");
231  fMaskedFastorOADB = new AliOADBContainer("AliEmcalMaskedFastors");
232  fMaskedFastorOADB->InitFromFile(fNameMaskedFastorOADB.Data(), "AliEmcalMaskedFastors");
233  }
234 
235  // Setting online threshold for trigger
237  if(fInputEvent->GetRunNumber() >= 15344 && fInputEvent->GetRunNumber() <= 197388){
242  SetOnlineTriggerThreshold("DG1", 0);
243  SetOnlineTriggerThreshold("DG2", 0);
244  SetOnlineTriggerThreshold("DJ1", 0);
245  SetOnlineTriggerThreshold("DJ2", 0);
246  SetOnlineTriggerThreshold("EMC7", 0);
247  SetOnlineTriggerThreshold("DMC7", 0);
248  }
249  }
250 
251  // Load acceptance OADB
253  AliOADBContainer acceptanceCont;
254  acceptanceCont.InitFromFile(fNameAcceptanceOADB.Data(), "AliEmcalTriggerAcceptance");
255  TObjArray *acceptanceMaps = dynamic_cast<TObjArray *>(acceptanceCont.GetObject(fInputEvent->GetRunNumber()));
256  TH2 *map(nullptr);
257  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EG1")))){
258  map->SetDirectory(nullptr);
260  }
261  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EG2")))){
262  map->SetDirectory(nullptr);
264  }
265  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DG1")))){
266  map->SetDirectory(nullptr);
268  }
269  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DG2")))){
270  map->SetDirectory(nullptr);
272  }
273  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EJ1")))){
274  map->SetDirectory(nullptr);
276  }
277  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EJ2")))){
278  map->SetDirectory(nullptr);
280  }
281  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DJ1")))){
282  map->SetDirectory(nullptr);
284  }
285  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DJ2")))){
286  map->SetDirectory(nullptr);
288  }
289  }
290 }
291 
293  if(fDownscaleOADB){
294  fDownscaleFactors = static_cast<TObjArray *>(fDownscaleOADB->GetObject(runnumber));
295  }
296  if(fMaskedFastorOADB){
297  fMaskedFastors.clear();
298  TObjArray *ids = static_cast<TObjArray *>(fMaskedFastorOADB->GetObject(runnumber));
299  for(auto m : *ids){
300  TParameter<int> *id = static_cast<TParameter<int> *>(m);
301  fMaskedFastors.push_back(id->GetVal());
302  }
303  }
304 }
305 
307  // Exclusive means classes without lower trigger classes (which are downscaled) -
308  // in order to make samples statistically independent: MBExcl means MinBias && !EMCAL trigger
309  std::vector<TString> triggers = {
310  "MB", "EMC7", "DMC7",
311  "EJ1", "EJ2", "EG1", "EG2", "DJ1", "DJ2", "DG1", "DG2",
312  "EMC7excl", "DMC7excl", "EG2excl", "EJ2excl", "DG2excl", "DJ2excl",
313  "EJ1excl", "DJ1excl", "EG1excl", "DG1excl"
314  };
315  return triggers;
316 }
317 
319  AliDebugStream(1) << "Using V1 online trigger selector" << std::endl;
321  double onlinethresholds[5] = {140., 89., 260., 127., 0.};
322  int ngood(0);
323  for(auto p : *fTriggerPatchInfo){
324  AliEMCALTriggerPatchInfo *patch = static_cast<AliEMCALTriggerPatchInfo *>(p);
325  if((AliEmcalTriggerOfflineSelection::IsSingleShower(trigger) && patch->IsGammaLowRecalc()) ||
326  (!AliEmcalTriggerOfflineSelection::IsSingleShower(trigger) && patch->IsJetLowRecalc())){
327  if(patch->GetADCAmp() >= GetOnlineTriggerThresholdByIndex(trigger)) ngood++;
328  }
329  }
330  return ngood > 0;
331 }
332 
334  if(fDownscaleFactors){
335  TParameter<double> *result(nullptr);
336  // Downscaling only done on MB, L0 and the low threshold triggers
337  if(triggerclass.Contains("MB")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("INT7"));
338  else if(triggerclass.Contains("EMC7")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EMC7"));
339  else if(triggerclass.Contains("EJ2")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EJ2"));
340  else if(triggerclass.Contains("EG2")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EG2"));
341  if(result) return 1./result->GetVal();
342  }
343  return 1.;
344 }
345 
347  TParameter<int> *threshpar(nullptr);
348  if((threshpar = static_cast<TParameter<int> *>(fOnlineTriggerThresholds.FindObject(triggerclass.Data())))){
349  threshpar->SetVal(threshold);
350  } else {
351  fOnlineTriggerThresholds.Add(new TParameter<int>(triggerclass.Data(), threshold));
352  }
353 }
354 
356  Int_t threshold(0);
357  TParameter<int> *val(nullptr);
358  if((val = static_cast<TParameter<int> *>(fOnlineTriggerThresholds.FindObject(name))))
359  threshold = val->GetVal();
360  return threshold;
361 }
362 
364  const TString triggernames[AliEmcalTriggerOfflineSelection::kTrgn] = {"EMC7", "EG1", "EG2", "EJ1", "EJ2", "DMC7",
365  "DG1", "DG2", "DJ1", "DJ2"};
366  return GetOnlineTriggerThresholdByName(triggernames[trigger]);
367 }
368 
370  const TString triggernames[AliEmcalTriggerOfflineSelection::kTrgn] = {"EMC7", "EG1", "EG2", "EJ1", "EJ2", "DMC7",
371  "DG1", "DG2", "DJ1", "DJ2"};
372  bool isInitialized = true;
373  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++){
374  if(!fOnlineTriggerThresholds.FindObject(triggernames[itrg].Data())) {
375  isInitialized = false;
376  break;
377  }
378  }
379  return isInitialized;
380 }
381 
383  return adc > GetOnlineTriggerThresholdByName(triggerclass);
384 }
385 
387  TString triggerstring = "";
388  Int_t nEJ1 = 0, nEJ2 = 0, nEG1 = 0, nEG2 = 0, nDJ1 = 0, nDJ2 = 0, nDG1 = 0, nDG2 = 0;
389  for(auto patchIter : *triggerpatches){
390  AliEMCALTriggerPatchInfo *patch = dynamic_cast<AliEMCALTriggerPatchInfo *>(patchIter);
391  if(!patch->IsRecalc()) continue;
392  if(patch->IsEMCal()){
393  if(patch->IsGammaLowRecalc() && SelectFiredPatch("EG1", patch->GetADCAmp())) nEG1++;
394  if(patch->IsGammaLowRecalc() && SelectFiredPatch("EG2", patch->GetADCAmp())) nEG2++;
395  if(patch->IsJetLowRecalc() && SelectFiredPatch("EJ1", patch->GetADCAmp())) nEJ1++;
396  if(patch->IsJetLowRecalc() && SelectFiredPatch("EJ2", patch->GetADCAmp())) nEJ2++;
397  } else {
398  if(patch->IsGammaLowRecalc() && SelectFiredPatch("DG1", patch->GetADCAmp())) nDG1++;
399  if(patch->IsGammaLowRecalc() && SelectFiredPatch("DG2", patch->GetADCAmp())) nDG2++;
400  if(patch->IsJetLowRecalc() && SelectFiredPatch("DJ1", patch->GetADCAmp())) nDJ1++;
401  if(patch->IsJetLowRecalc() && SelectFiredPatch("DJ2", patch->GetADCAmp())) nDJ2++;
402  }
403  }
404  if(nEJ1) triggerstring += "EJ1";
405  if(nEJ2){
406  if(triggerstring.Length()) triggerstring += ",";
407  triggerstring += "EJ2";
408  }
409  if(nEG1){
410  if(triggerstring.Length()) triggerstring += ",";
411  triggerstring += "EG1";
412  }
413  if(nEG2){
414  if(triggerstring.Length()) triggerstring += ",";
415  triggerstring += "EG2";
416  }
417  if(nDJ1){
418  if(triggerstring.Length()) triggerstring += ",";
419  triggerstring += "DJ2";
420  }
421  if(nDJ2){
422  if(triggerstring.Length()) triggerstring += ",";
423  triggerstring += "DJ2";
424  }
425  if(nDG1){
426  if(triggerstring.Length()) triggerstring += ",";
427  triggerstring += "DG1";
428  }
429  if(nDG2){
430  if(triggerstring.Length()) triggerstring += ",";
431  triggerstring += "DG2";
432  }
433  return triggerstring;
434 }
435 
436 } /* namespace EMCalTriggerPtAnalysis */
std::vector< TString > fSelectedTriggers
! Triggers selected for given event
Bool_t fIsPythia
trigger, if it is a PYTHIA production
double Double_t
Definition: External.C:58
Int_t GetOnlineTriggerThresholdByIndex(AliEmcalTriggerOfflineSelection::EmcalTriggerClass trg) const
Bool_t fRejectNoiseEvents
Reject events triggered by noisy fastors.
Base task in the EMCAL framework.
void SetOnlineTriggerThreshold(const TString &triggerclass, Int_t threshold)
Bool_t fLocalInitialized
whether or not the task has been already initialized
TString GetFiredTriggerClassesFromPatches(const TClonesArray *triggerpatches) const
AliEmcalTriggerOfflineSelection * fTriggerSelection
Offline trigger selection.
TObjArray fOnlineTriggerThresholds
Trigger thresholds applied at online level.
void SetCaloTriggerPatchInfoName(const char *n)
TString fNameMaskedFastorOADB
Name of the masked fastor OADB container.
bool SelectOnlineTrigger(AliEmcalTriggerOfflineSelection::EmcalTriggerClass trigger) const
void SetAcceptanceMap(EmcalTriggerClass trgcls, const TH2 *accmap)
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
THashList * GetListOfHistograms() const
Definition: THistManager.h:504
EmcalTriggerClass
Definition of the various supported trigger types.
AliAnalysisUtils * fAliAnalysisUtils
!vertex selection (optional)
TString fNameDownscaleOADB
Name of the downscale OADB container.
TString fNameAcceptanceOADB
Name of the OADB container with the trigger acceptance.
AliOADBContainer * fMaskedFastorOADB
! Container with masked fastors
Bool_t fSelectNoiseEvents
Explicitly select events triggered only by noisy fastors.
Bool_t IsOfflineSelected(EmcalTriggerClass trgcls, const TClonesArray *const triggerpatches) const
Bool_t fTriggerStringFromPatches
Do rebuild the trigger string from trigger patches.
AliEmcalList * fOutput
!output list
Definition: External.C:220
AliOADBContainer * fDownscaleOADB
! Container with downscale factors for different triggers
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
Double_t fVertex[3]
!event vertex
TClonesArray * fTriggerPatchInfo
!trigger patch info array
void SetNeedEmcalGeom(Bool_t n)
Container class for histograms for the high- charged particle analysis.
Definition: THistManager.h:43
AliCutValueRange< double > fVertexCut
Cut on the z-position of the primary vertex.
bool Bool_t
Definition: External.C:53
Bool_t SelectFiredPatch(const TString &triggerclass, Int_t adc) const