AliPhysics  5364b50 (5364b50)
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 <algorithm>
16 #include <array>
17 #include <cfloat>
18 #include <functional>
19 #include <iostream>
20 #include <memory>
21 
22 #include <TClonesArray.h>
23 #include <TGrid.h>
24 #include <THistManager.h>
25 #include <TObjArray.h>
26 #include <TObjString.h>
27 #include <TParameter.h>
28 
30 #include "AliAnalysisUtils.h"
31 #include "AliAODEvent.h"
32 #include "AliAODInputHandler.h"
35 #include "AliEMCALGeometry.h"
36 #include "AliEMCALTriggerPatchInfo.h"
37 #include "AliEMCALTriggerMapping.h"
38 #include "AliESDEvent.h"
39 #include "AliInputEventHandler.h"
40 #include "AliLog.h"
41 #include "AliOADBContainer.h"
42 #include "AliVVertex.h"
43 
47 
48 namespace EMCalTriggerPtAnalysis {
49 
50 AliAnalysisTaskEmcalTriggerBase::AliAnalysisTaskEmcalTriggerBase():
52  fTriggerSelection(nullptr),
53  fUseTriggerBits(kTRUE),
54  fRequireBunchCrossing(kTRUE),
55  fUseDownscaleCorrectionFormOCDB(kFALSE),
56  fHistos(nullptr),
57  fTriggerStringFromPatches(kFALSE),
58  fSelectedTriggers(),
59  fNameClusterContainer(""),
60  fRequireAnalysisUtils(kTRUE),
61  fVertexCut(-10., 10.),
62  fNameDownscaleOADB(""),
63  fDownscaleOADB(nullptr),
64  fDownscaleFactors(nullptr),
65  fNameMaskedFastorOADB(),
66  fMaskedFastorOADB(nullptr),
67  fMaskedFastors(),
68  fOnlineTriggerThresholds(),
69  fNameAcceptanceOADB(),
70  fSelectNoiseEvents(false),
71  fRejectNoiseEvents(false),
72  fEnableDCALTriggers(true),
73  fEnableCentralityTriggers(false),
74  fEnableT0Triggers(false),
75  fRequireL0forL1(false),
76  fExclusiveMinBias(false)
77 {
78  SetNeedEmcalGeom(true);
80  SetCaloTriggerPatchInfoName("EmcalTriggers");
81 }
82 
84  AliAnalysisTaskEmcal(name, true),
86  fUseTriggerBits(kTRUE),
87  fRequireBunchCrossing(kTRUE),
93  fRequireAnalysisUtils(kTRUE),
94  fVertexCut(-10., 10.),
100  fMaskedFastors(),
103  fSelectNoiseEvents(false),
104  fRejectNoiseEvents(false),
105  fEnableDCALTriggers(true),
107  fEnableT0Triggers(false),
108  fRequireL0forL1(false),
109  fExclusiveMinBias(false)
110 {
111  SetNeedEmcalGeom(true);
113  SetCaloTriggerPatchInfoName("EmcalTriggers");
114 }
115 
118  if(fHistos) delete fHistos;
119  if(fDownscaleOADB) delete fDownscaleOADB;
122 }
123 
126  if(fRequireAnalysisUtils && !fAliAnalysisUtils) fAliAnalysisUtils = new AliAnalysisUtils;
127 
128  if((!fNameClusterContainer.Length()) || fNameClusterContainer == "usedefault") fNameClusterContainer = AliEmcalAnalysisFactory::ClusterContainerNameFactory(fInputHandler->IsA() == AliAODInputHandler::Class());
131  }
132 
133  fHistos = new THistManager(Form("Histos_%s", GetName()));
134 
135  // Create trigger correlation histogram
136  fHistos->CreateTH2("hTriggerCorrelation", "Correlation selected trigger classes", 6, -0.5, 5.5, 6, -0.5, 5.5);
137  std::array<TString, 6> binlabels = {"MB", "EMC7", "EG1", "EG2", "EJ1", "EJ2"};
138  TH1 *correlationHist = static_cast<TH1 *>(fHistos->FindObject("hTriggerCorrelation"));
139  for(int ib = 0; ib < 6; ib++){
140  correlationHist->GetXaxis()->SetBinLabel(ib+1, binlabels[ib]);
141  correlationHist->GetYaxis()->SetBinLabel(ib+1, binlabels[ib]);
142  }
143 
146 
147  for(auto h : *(fHistos->GetListOfHistograms())) fOutput->Add(h);
148  fHistos->GetListOfHistograms()->SetOwner(false);
149 
150  PostData(1, fOutput);
151 }
152 
154  // Apply trigger selection
156  if(!fSelectedTriggers.size()) return false;
157 
159 
160  const AliVVertex *vtx = fInputEvent->GetPrimaryVertex();
161  //if(!fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5.)) return; // reject pileup event
162  if(vtx->GetNContributors() < 1) return false;
163 
165  if(fInputEvent->IsA() == AliESDEvent::Class() && fAliAnalysisUtils->IsFirstEventInChunk(fInputEvent)) return false;
166  if(fAliAnalysisUtils->IsPileUpEvent(fInputEvent)) return false; // Apply new vertex cut
167  if(!fAliAnalysisUtils->IsVertexSelected2013pA(fInputEvent))return false; // Apply new vertex cut
168  }
169 
170  if(!fVertexCut.IsInRange(fVertex[2])) return false;
171  if(!IsUserEventSelected()) return false;
172 
173  // Do MC outlier cut
174  if(fIsPythia){
175  if(!CheckMCOutliers()){
176  AliDebugStream(1) << GetName() << ": Reject MC outliers" << std::endl;
177  return false;
178  }
179  }
180 
181  // Fill histogram with trigger correlation
182  // self-correlations included
183  std::array<TString, 6> kAbsTriggers = {"MB", "EMC7", "EG1", "EG2", "EJ1", "EJ2"};
184  for(int itrg = 0; itrg < 6; itrg++){
185  bool hasTriggerA = (std::find(fSelectedTriggers.begin(), fSelectedTriggers.end(), kAbsTriggers[itrg]) != fSelectedTriggers.end());
186  if(hasTriggerA) {
187  for(int jtrg = 0; jtrg < 6; jtrg++){
188  bool hasTriggerB = (std::find(fSelectedTriggers.begin(), fSelectedTriggers.end(), kAbsTriggers[jtrg]) != fSelectedTriggers.end());
189  if(hasTriggerB)
190  fHistos->FillTH2("hTriggerCorrelation", kAbsTriggers[itrg], kAbsTriggers[jtrg]);
191  }
192  }
193  }
194 
196  return true;
197 }
198 
199 
201  fSelectedTriggers.clear();
202  Bool_t isMC = MCEvent() != nullptr;
203 
204  TString triggerstring = "";
207  } else {
208  triggerstring = fInputEvent->GetFiredTriggerClasses();
209  }
210 
211 
212  UInt_t selectionstatus = fInputHandler->IsEventSelected();
213  Bool_t isMinBias = selectionstatus & AliVEvent::kINT7,
214  isMinBiasT0 = selectionstatus & AliVEvent::kINT8,
215  isCENT = selectionstatus & AliVEvent::kCentral,
216  isSemiCENT = selectionstatus & AliVEvent::kSemiCentral,
219 
220  if(fExclusiveMinBias){
221  // do not perform EMCAL trigger selection in case only
222  // min. bias trigger is requested:w
223  if(isMinBias) fSelectedTriggers.push_back("MB");
224  if(isMinBiasT0 && fEnableT0Triggers) fSelectedTriggers.push_back("MBT0");
226  if(isCENT) fSelectedTriggers.push_back("CENT");
227  if(isSemiCENT) fSelectedTriggers.push_back("SEMICENT");
228  }
229  return;
230  }
231 
232  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++) emcalTriggers[itrg] = true;
233  if(fEnableT0Triggers) for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++) emc8Triggers[itrg] = true;
234  if(!isMC){
235  // In case of data select events as bunch-bunch (-B-) events.
236  // Cut not applied in simulations
237  if(fRequireBunchCrossing && ! (triggerstring.Contains("-B-") || triggerstring.Contains("-S-"))) return;
238 
239  // In case of data use information from the physics selection and event record
240  // Further cleanup of trigger events can be performed depending on the presence
241  // of recalc patches (after masking hot fastors in the trigger maker) above
242  // threshold
243  if(fUseTriggerBits){
244  const std::array<ULong_t, AliEmcalTriggerOfflineSelection::kTrgn> kSelectTriggerBits = {
245  AliVEvent::kEMC7|AliVEvent::kEMC8, AliVEvent::kEMCEGA, AliVEvent::kEMCEGA, AliVEvent::kEMCEJE, AliVEvent::kEMCEJE,
246  AliVEvent::kEMC7|AliVEvent::kEMC8, AliVEvent::kEMCEGA, AliVEvent::kEMCEGA, AliVEvent::kEMCEJE, AliVEvent::kEMCEJE
247  };
248  for(int iclass = 0; iclass < AliEmcalTriggerOfflineSelection::kTrgn; iclass++){
249  emcalTriggers[iclass] &= bool(selectionstatus & kSelectTriggerBits[iclass]);
250  emc8Triggers[iclass] &= bool(selectionstatus & kSelectTriggerBits[iclass]);
251  if(fRequireL0forL1 && !bool(selectionstatus & (AliVEvent::kEMC7|AliVEvent::kEMC8))) {
252  emcalTriggers[iclass] = false;
253  emc8Triggers[iclass] = false;
254  }
255  }
256  }
257 
258  // Apply cut on the trigger string - this basically discriminates high- and low-threshold
259  // triggers
260  const std::array<TString, AliEmcalTriggerOfflineSelection::kTrgn> kSelectTriggerStrings = {
261  "CEMC7-|CEMC8-", "EG1|EGA", "EG2", "EJ1|EJE", "EJ2", "CDMC7-|CDMC8-", "DG1", "DG2", "DJ1", "DJ2"
262  };
263  if(triggerstring.Contains("EMC")) AliDebugStream(1) << GetName() << ": Trigger string " << triggerstring << std::endl;
264  bool isT0trigger = triggerstring.Contains("INT8") || triggerstring.Contains("EMC8");
265  for(int iclass = 0; iclass < AliEmcalTriggerOfflineSelection::kTrgn; iclass++){
266  bool selectionStatus = false;
267  if(kSelectTriggerStrings[iclass].Contains("|")){
268  std::unique_ptr<TObjArray> options(kSelectTriggerStrings[iclass].Tokenize("|"));
269  for(auto o : *options){
270  TObjString *optstring = static_cast<TObjString *>(o);
271  if(triggerstring.Contains(optstring->String())) selectionStatus = true;
272  }
273  } else {
274  selectionStatus = triggerstring.Contains(kSelectTriggerStrings[iclass]);
275  }
276  if(isT0trigger) {
277  emc8Triggers[iclass] &= selectionStatus;
278  emcalTriggers[iclass] = false;
279  } else {
280  emcalTriggers[iclass] &= selectionStatus;
281  emc8Triggers[iclass] = false;
282  }
283  if(emcalTriggers[iclass])
284  AliDebugStream(1) << GetName() << ": Event selected as trigger " << kSelectTriggerStrings[iclass] << " (INT7 suite)" << std::endl;
285  if(emc8Triggers[iclass])
286  AliDebugStream(1) << GetName() << ": Event selected as trigger " << kSelectTriggerStrings[iclass] << " (INT8 suite)" << std::endl;
287  }
288 
289  // Online selection / rejection
291  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++){
292  if(emcalTriggers[itrg] || emc8Triggers[itrg]){
294  if(fRejectNoiseEvents){
295  if(emcalTriggers[itrg]) emcalTriggers[itrg] &= onlinestatus;
296  if(emc8Triggers[itrg]) emc8Triggers[itrg] &= onlinestatus;
297  } else {
298  if(emcalTriggers[itrg]) emcalTriggers[itrg] &= !onlinestatus;
299  if(emc8Triggers[itrg]) emc8Triggers[itrg] &= !onlinestatus;
300  }
301  }
302  }
303  }
304  }
305  // Apply offline trigger selection: In this case cuts are performed on the
306  // patch energy from EMCAL cells after calibration. This method is most relevant
307  // for simulations. It can have a special use case in data in case a stronger
308  // offline selection is applied in addition to the online selection.
310  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++)
312  }
313  if(isMinBias) fSelectedTriggers.push_back("MB");
315  if(isCENT) fSelectedTriggers.push_back("CENT");
316  if(isSemiCENT) fSelectedTriggers.push_back("SEMICENT");
317  }
318  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0]){
319  fSelectedTriggers.push_back("EMC7");
320  if(!isMinBias) fSelectedTriggers.push_back("EMC7excl");
321  }
322  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ2]){
323  fSelectedTriggers.push_back("EJ2");
324  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EJ2excl");
325  }
326  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ1]){
327  fSelectedTriggers.push_back("EJ1");
328  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ2])) fSelectedTriggers.push_back("EJ1excl");
329  }
330  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG2]){
331  fSelectedTriggers.push_back("EG2");
332  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EG2excl");
333  }
334  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG1]){
335  fSelectedTriggers.push_back("EG1");
336  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG2])) fSelectedTriggers.push_back("EG1excl");
337  }
338 
340  // Handle DCAL triggers only in case DCAL triggers are enabled,
341  // otherwise ignore results of the online/offline trigger selection
342  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0]){
343  fSelectedTriggers.push_back("DMC7");
344  if(!isMinBias) fSelectedTriggers.push_back("DMC7excl");
345  }
346  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ2]){
347  fSelectedTriggers.push_back("DJ2");
348  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0])) fSelectedTriggers.push_back("DJ2excl");
349  }
350  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ1]){
351  fSelectedTriggers.push_back("DJ1");
352  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ2])) fSelectedTriggers.push_back("DJ1excl");
353  }
354  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG2]){
355  fSelectedTriggers.push_back("DG2");
356  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0])) fSelectedTriggers.push_back("DG2excl");
357  }
358  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG1]){
359  fSelectedTriggers.push_back("DG1");
360  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG2])) fSelectedTriggers.push_back("DG1excl");
361  }
362  }
363 
364  if(fEnableT0Triggers) {
365  if(isMinBiasT0) fSelectedTriggers.push_back("MBT0");
366  if(emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEL0]) {
367  // EMC8 trigger
368  fSelectedTriggers.push_back("EMC8");
369  if(!isMinBiasT0) fSelectedTriggers.push_back("EMC8excl");
370  }
371  if(emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEG1]){
372  // EMC8EGA trigger
373  fSelectedTriggers.push_back("EMC8EGA");
374  if(!(isMinBiasT0 || emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EMC8EGAexcl");
375  }
376  if(emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEJ1]){
377  // EMC8EJE trigger
378  fSelectedTriggers.push_back("EMC8EJE");
379  if(!(isMinBiasT0 || emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EMC8EJEexcl");
380  }
381  }
382 }
383 
386 
387  if(!fLocalInitialized){
388  return;
389  }
390 
391  // Handle OADB container with downscaling factors
392  if(fNameDownscaleOADB.Length()){
393  if(fNameDownscaleOADB.Contains("alien://") && ! gGrid) TGrid::Connect("alien://");
394  fDownscaleOADB = new AliOADBContainer("AliEmcalDownscaleFactors");
395  fDownscaleOADB->InitFromFile(fNameDownscaleOADB.Data(), "AliEmcalDownscaleFactors");
396  }
397 
398  if(!fExclusiveMinBias){
399  // Load EMCAL trigger OADB in case EMCAL triggers
400  // are enabled
401 
402  // Load OADB container with masked fastors (in case fastor masking is switched on)
404  if(fNameMaskedFastorOADB.Contains("alien://") && ! gGrid) TGrid::Connect("alien://");
405  fMaskedFastorOADB = new AliOADBContainer("AliEmcalMaskedFastors");
406  fMaskedFastorOADB->InitFromFile(fNameMaskedFastorOADB.Data(), "AliEmcalMaskedFastors");
407  }
408 
409  // Setting online threshold for trigger
411  if(fInputEvent->GetRunNumber() >= 15344 && fInputEvent->GetRunNumber() <= 197388){
416  SetOnlineTriggerThreshold("DG1", 0);
417  SetOnlineTriggerThreshold("DG2", 0);
418  SetOnlineTriggerThreshold("DJ1", 0);
419  SetOnlineTriggerThreshold("DJ2", 0);
420  SetOnlineTriggerThreshold("EMC7", 0);
421  SetOnlineTriggerThreshold("DMC7", 0);
422  }
423  }
424 
425  // Load acceptance OADB
426  if(fNameAcceptanceOADB.Length() && fTriggerSelection){
427  AliDebugStream(1) << GetName() << ": Loading acceptance map from OADB file " << fNameAcceptanceOADB << std::endl;
428  AliOADBContainer acceptanceCont("AliEmcalTriggerAcceptance");
429  acceptanceCont.InitFromFile(fNameAcceptanceOADB.Data(), "AliEmcalTriggerAcceptance");
430  TObjArray *acceptanceMaps = dynamic_cast<TObjArray *>(acceptanceCont.GetObject(fInputEvent->GetRunNumber()));
431  TH2 *map(nullptr);
432  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EG1")))){
433  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger EG1" << std::endl;
434  map->SetDirectory(nullptr);
436  }
437  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EG2")))){
438  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger EG2" << std::endl;
439  map->SetDirectory(nullptr);
441  }
442  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DG1")))){
443  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger DG1" << std::endl;
444  map->SetDirectory(nullptr);
446  }
447  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DG2")))){
448  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger DG2" << std::endl;
449  map->SetDirectory(nullptr);
451  }
452  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EJ1")))){
453  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger EJ1" << std::endl;
454  map->SetDirectory(nullptr);
456  }
457  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EJ2")))){
458  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger EJ2" << std::endl;
459  map->SetDirectory(nullptr);
461  }
462  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DJ1")))){
463  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger DJ1" << std::endl;
464  map->SetDirectory(nullptr);
466  }
467  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DJ2")))){
468  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger DJ2" << std::endl;
469  map->SetDirectory(nullptr);
471  }
472  }
473  }
474 }
475 
477  if(fDownscaleOADB){
478  fDownscaleFactors = static_cast<TObjArray *>(fDownscaleOADB->GetObject(runnumber));
479  }
481 
482  // Log info for downscale factors
483  if(!fDownscaleFactors || !fDownscaleFactors->GetEntries()){
484  AliInfoStream() << GetName() << ": No downscale factors provided for run " << runnumber << std::endl;
485  } else {
486  AliInfoStream() << GetName() << ": Downscale factors used for run " << runnumber << std::endl;
487  for(auto e : *fDownscaleFactors){
488  TParameter<double> *dfactor = static_cast<TParameter<double> *>(e);
489  AliInfoStream() << GetName() << ": Trigger " << dfactor->GetName() << ", downscale factor " << dfactor->GetVal() << std::endl;
490  }
491  }
492 
493  if(!fExclusiveMinBias){
494  if(fMaskedFastorOADB){
495  fMaskedFastors.clear();
496  TObjArray *ids = static_cast<TObjArray *>(fMaskedFastorOADB->GetObject(runnumber));
497  for(auto m : *ids){
498  TParameter<int> *id = static_cast<TParameter<int> *>(m);
499  fMaskedFastors.push_back(id->GetVal());
500  }
501  }
502  }
503 }
504 
506  // Exclusive means classes without lower trigger classes (which are downscaled) -
507  // in order to make samples statistically independent: MBExcl means MinBias && !EMCAL trigger
508  std::vector<TString> triggers = {"MB"}; // Min. Bias always enabled
509  const std::array<TString, 10> emcaltriggers = {{"EMC7", "EJ1", "EJ2", "EG1", "EG2", "EMC7excl", "EG2excl", "EJ2excl", "EJ1excl", "EG1excl"}},
510  dcaltriggers = {{"DMC7", "DJ1", "DJ2", "DG1", "DG2", "DMC7excl", "DG2excl", "DJ2excl", "DJ1excl", "DG1excl"}};
511  const std::array<TString, 7> t0triggers = {{"MBT0", "EMC8", "EMC8EGA", "EMC8EJE", "EMC8excl", "EMC8EGAexcl", "EMC8EJEexcl"}};
512  const std::array<TString, 2> centralitytriggers = {{"CENT", "SEMICENT"}};
513  if(!fExclusiveMinBias){
514  for(const auto &t : emcaltriggers) triggers.push_back(t);
515  }
517  for(const auto &t : dcaltriggers) triggers.push_back(t);
518  }
519  if(fEnableT0Triggers){
520  for(const auto &t: t0triggers) triggers.push_back(t);
521  }
523  for(const auto &t : centralitytriggers) triggers.push_back(t);
524  }
525  return triggers;
526 }
527 
529  AliDebugStream(1) << "Using V1 online trigger selector" << std::endl;
531  int ngood(0);
532  for(auto p : *fTriggerPatchInfo){
533  AliEMCALTriggerPatchInfo *patch = static_cast<AliEMCALTriggerPatchInfo *>(p);
534  if((AliEmcalTriggerOfflineSelection::IsSingleShower(trigger) && patch->IsGammaLowRecalc()) ||
535  (!AliEmcalTriggerOfflineSelection::IsSingleShower(trigger) && patch->IsJetLowRecalc())){
536  if(patch->GetADCAmp() >= GetOnlineTriggerThresholdByIndex(trigger)) ngood++;
537  }
538  }
539  return ngood > 0;
540 }
541 
543  if(fDownscaleFactors){
544  TParameter<double> *result(nullptr);
545  // Downscaling only done on MB, L0 and the low threshold triggers
546  if(triggerclass.Contains("MB")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("INT7"));
547  else if(triggerclass.Contains("EMC7")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EMC7"));
548  else if(triggerclass.Contains("DMC7")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("DMC7"));
549  else if(triggerclass.Contains("EJ2")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EJ2"));
550  else if(triggerclass.Contains("EJ1")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EJ1"));
551  else if(triggerclass.Contains("EG2")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EG2"));
552  else if(triggerclass.Contains("EG1")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EG1"));
553  else if(triggerclass.Contains("DG2")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("DG2"));
554  else if(triggerclass.Contains("DG1")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("DG1"));
555  double triggerweight = 1.;
556  if(result) triggerweight = 1./result->GetVal();
557  AliDebugStream(1) << "Using trigger weight " << triggerweight << " for trigger " << triggerclass << std::endl;
558  return triggerweight;
559  } else {
560  AliDebugStream(1) << "No downscale factors loaded - using trigger weight 1" << std::endl;
561  }
562  return 1.;
563 }
564 
566  AliInfoStream() << "Reading downscale factors from OCDB for run " << fInputEvent->GetRunNumber() << std::endl;
567  if(!fDownscaleFactors){
569  fDownscaleFactors->SetOwner(true);
570  }
571  fDownscaleFactors->Clear();
573  if(downscaleOCDB->GetCurrentRun() != fInputEvent->GetRunNumber()) downscaleOCDB->SetRun(fInputEvent->GetRunNumber());
574  const std::array<TString, 11> khwtriggers = {"INT7", "EMC7", "DMC7", "EJ1", "EJ2", "DJ1", "DJ2", "EG1", "EG2", "DG1", "DG2"};
575  std::vector<TString> runtriggers = downscaleOCDB->GetTriggerClasses();
576  for(const auto &t : khwtriggers){
577  std::function<bool (TString)> triggerfinder = [t](const TString &test) -> bool {
578  if(!test.Contains(t + "-B-")) return false;
579  return true;
580  };
581  auto entry = std::find_if(runtriggers.begin(), runtriggers.end(), triggerfinder);
582  if(entry != runtriggers.end()){
583  TString triggername = *entry;
584  double downscalefactor = downscaleOCDB->GetDownscaleFactorForTriggerClass(triggername);
585  AliInfoStream() << "Applying downscale factor " << downscalefactor << " for trigger " << t << " (" << triggername << ") for run " << fInputEvent->GetRunNumber() << std::endl;
586  fDownscaleFactors->Add(new TParameter<double>(t, TMath::Abs(downscalefactor) < DBL_EPSILON ? 1 : downscalefactor));
587  } else {
588  AliErrorStream() << "No downscale factor found for trigger " << t << " for run " << fInputEvent->GetRunNumber() << std::endl;
589  }
590  }
591 }
592 
594  TParameter<int> *threshpar(nullptr);
595  if((threshpar = static_cast<TParameter<int> *>(fOnlineTriggerThresholds.FindObject(triggerclass.Data())))){
596  threshpar->SetVal(threshold);
597  } else {
598  fOnlineTriggerThresholds.Add(new TParameter<int>(triggerclass.Data(), threshold));
599  }
600 }
601 
603  Int_t threshold(0);
604  TParameter<int> *val(nullptr);
605  if((val = static_cast<TParameter<int> *>(fOnlineTriggerThresholds.FindObject(name))))
606  threshold = val->GetVal();
607  return threshold;
608 }
609 
611  const TString triggernames[AliEmcalTriggerOfflineSelection::kTrgn] = {"EMC7", "EG1", "EG2", "EJ1", "EJ2", "DMC7",
612  "DG1", "DG2", "DJ1", "DJ2"};
613  return GetOnlineTriggerThresholdByName(triggernames[trigger]);
614 }
615 
617  const TString triggernames[AliEmcalTriggerOfflineSelection::kTrgn] = {"EMC7", "EG1", "EG2", "EJ1", "EJ2", "DMC7",
618  "DG1", "DG2", "DJ1", "DJ2"};
619  bool isInitialized = true;
620  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++){
621  if(!fOnlineTriggerThresholds.FindObject(triggernames[itrg].Data())) {
622  isInitialized = false;
623  break;
624  }
625  }
626  return isInitialized;
627 }
628 
630  return adc > GetOnlineTriggerThresholdByName(triggerclass);
631 }
632 
634  TString triggerstring = "";
635  Int_t nEJ1 = 0, nEJ2 = 0, nEG1 = 0, nEG2 = 0, nDJ1 = 0, nDJ2 = 0, nDG1 = 0, nDG2 = 0;
636  for(auto patchIter : *triggerpatches){
637  AliEMCALTriggerPatchInfo *patch = dynamic_cast<AliEMCALTriggerPatchInfo *>(patchIter);
638  if(!patch->IsRecalc()) continue;
639  if(patch->IsEMCal()){
640  if(patch->IsGammaLowRecalc() && SelectFiredPatch("EG1", patch->GetADCAmp())) nEG1++;
641  if(patch->IsGammaLowRecalc() && SelectFiredPatch("EG2", patch->GetADCAmp())) nEG2++;
642  if(patch->IsJetLowRecalc() && SelectFiredPatch("EJ1", patch->GetADCAmp())) nEJ1++;
643  if(patch->IsJetLowRecalc() && SelectFiredPatch("EJ2", patch->GetADCAmp())) nEJ2++;
644  } else {
645  if(patch->IsGammaLowRecalc() && SelectFiredPatch("DG1", patch->GetADCAmp())) nDG1++;
646  if(patch->IsGammaLowRecalc() && SelectFiredPatch("DG2", patch->GetADCAmp())) nDG2++;
647  if(patch->IsJetLowRecalc() && SelectFiredPatch("DJ1", patch->GetADCAmp())) nDJ1++;
648  if(patch->IsJetLowRecalc() && SelectFiredPatch("DJ2", patch->GetADCAmp())) nDJ2++;
649  }
650  }
651  if(nEJ1) triggerstring += "EJ1";
652  if(nEJ2){
653  if(triggerstring.Length()) triggerstring += ",";
654  triggerstring += "EJ2";
655  }
656  if(nEG1){
657  if(triggerstring.Length()) triggerstring += ",";
658  triggerstring += "EG1";
659  }
660  if(nEG2){
661  if(triggerstring.Length()) triggerstring += ",";
662  triggerstring += "EG2";
663  }
664  if(nDJ1){
665  if(triggerstring.Length()) triggerstring += ",";
666  triggerstring += "DJ2";
667  }
668  if(nDJ2){
669  if(triggerstring.Length()) triggerstring += ",";
670  triggerstring += "DJ2";
671  }
672  if(nDG1){
673  if(triggerstring.Length()) triggerstring += ",";
674  triggerstring += "DG1";
675  }
676  if(nDG2){
677  if(triggerstring.Length()) triggerstring += ",";
678  triggerstring += "DG2";
679  }
680  return triggerstring;
681 }
682 
683 } /* namespace EMCalTriggerPtAnalysis */
std::vector< TString > fSelectedTriggers
! Triggers selected for given event
Bool_t IsOfflineSelected(EmcalTriggerClass trgcls, const AliVEvent *const data) const
Select event as triggered 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)
Setting trigger threshold for online trigger selection.
Bool_t fLocalInitialized
whether or not the task has been already initialized
TString GetFiredTriggerClassesFromPatches(const TClonesArray *triggerpatches) const
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
static AliEmcalDownscaleFactorsOCDB * Instance()
AliEmcalTriggerOfflineSelection * fTriggerSelection
Offline trigger selection.
void PrepareDownscaleFactorsFormOCDB()
Read the downscale factors from the OCDB.
TObjArray fOnlineTriggerThresholds
Trigger thresholds applied at online level.
Bool_t fEnableDCALTriggers
Enable / Disable event selection for DCAL trigger classes.
void SetCaloTriggerPatchInfoName(const char *n)
TString fNameMaskedFastorOADB
Name of the masked fastor OADB container.
Bool_t fRequireAnalysisUtils
Switch whether to require event selection in AliAnalysisUtils.
bool SelectOnlineTrigger(AliEmcalTriggerOfflineSelection::EmcalTriggerClass trigger) const
Bool_t CheckMCOutliers()
Filter the mc tails in pt-hard distributions.
Bool_t fRequireBunchCrossing
Require bunch-bunch events (tag -B- in trigger string)
void SetAcceptanceMap(EmcalTriggerClass trgcls, const TH2 *accmap)
Set acceptance map for a given trigger class.
TH2 * CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
Create a new TH2 within the container.
TObject * FindObject(const char *name) const
Find an object inside the container.
int Int_t
Definition: External.C:63
TString fNameClusterContainer
Name of the cluster container in the event.
unsigned int UInt_t
Definition: External.C:33
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
EmcalTriggerClass
Definition of the various supported trigger types.
AliAnalysisUtils * fAliAnalysisUtils
!vertex selection (optional)
TString fNameDownscaleOADB
Name of the downscale OADB container.
static Bool_t IsSingleShower(EmcalTriggerClass cls)
Checks if the trigger class is a single shower patch trigger class.
Bool_t fEnableT0Triggers
Enable triggers depending on T0 (INT8, EMC8, EMC8EGA, EMC8EJE)
TString fNameAcceptanceOADB
Name of the OADB container with the trigger acceptance.
const TString & GetNameClusterContainer() const
Get the name of the cluster container.
AliOADBContainer * fMaskedFastorOADB
! Container with masked fastors
Bool_t fSelectNoiseEvents
Explicitly select events triggered only by noisy fastors.
Bool_t fEnableCentralityTriggers
Enable central / semi-central trigger.
Bool_t fUseTriggerBits
Switch whether using trigger bits (relies on physics selection)
Bool_t fTriggerStringFromPatches
Do rebuild the trigger string from trigger patches.
Bool_t isMC
AliEmcalList * fOutput
!output list
Definition: External.C:220
AliOADBContainer * fDownscaleOADB
! Container with downscale factors for different triggers
Analysis of high- tracks in triggered events.
Double_t fVertex[3]
!event vertex
void SetMakeGeneralHistograms(Bool_t g)
TClonesArray * fTriggerPatchInfo
!trigger patch info array
void SetNeedEmcalGeom(Bool_t n)
Container class for histograms.
Definition: THistManager.h:99
virtual void ExecOnce()
Perform steps needed to initialize the analysis.
void test(int runnumber=195345)
void UserCreateOutputObjects()
Main initialization function on the worker.
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
Definition: External.C:196
static TString ClusterContainerNameFactory(Bool_t isAOD)
Get name of the default cluster container.