AliPhysics  f9b5d69 (f9b5d69)
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;
120 }
121 
124  if(fRequireAnalysisUtils && !fAliAnalysisUtils) fAliAnalysisUtils = new AliAnalysisUtils;
125 
126  if((!fNameClusterContainer.Length()) || fNameClusterContainer == "usedefault") fNameClusterContainer = AliEmcalAnalysisFactory::ClusterContainerNameFactory(fInputHandler->IsA() == AliAODInputHandler::Class());
129  }
130 
131  fHistos = new THistManager(Form("Histos_%s", GetName()));
132 
133  // Create trigger correlation histogram
134  fHistos->CreateTH2("hTriggerCorrelation", "Correlation selected trigger classes", 6, -0.5, 5.5, 6, -0.5, 5.5);
135  std::array<TString, 6> binlabels = {"MB", "EMC7", "EG1", "EG2", "EJ1", "EJ2"};
136  TH1 *correlationHist = static_cast<TH1 *>(fHistos->FindObject("hTriggerCorrelation"));
137  for(int ib = 0; ib < 6; ib++){
138  correlationHist->GetXaxis()->SetBinLabel(ib+1, binlabels[ib]);
139  correlationHist->GetYaxis()->SetBinLabel(ib+1, binlabels[ib]);
140  }
141 
144 
145  for(auto h : *(fHistos->GetListOfHistograms())) fOutput->Add(h);
146 
147  PostData(1, fOutput);
148 }
149 
151  // Apply trigger selection
153  if(!fSelectedTriggers.size()) return false;
154 
156 
157  const AliVVertex *vtx = fInputEvent->GetPrimaryVertex();
158  //if(!fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5.)) return; // reject pileup event
159  if(vtx->GetNContributors() < 1) return false;
160 
162  if(fInputEvent->IsA() == AliESDEvent::Class() && fAliAnalysisUtils->IsFirstEventInChunk(fInputEvent)) return false;
163  if(fAliAnalysisUtils->IsPileUpEvent(fInputEvent)) return false; // Apply new vertex cut
164  if(!fAliAnalysisUtils->IsVertexSelected2013pA(fInputEvent))return false; // Apply new vertex cut
165  }
166 
167  if(!fVertexCut.IsInRange(fVertex[2])) return false;
168  if(!IsUserEventSelected()) return false;
169 
170  // Do MC outlier cut
171  if(fIsPythia){
172  if(!CheckMCOutliers()){
173  AliDebugStream(1) << GetName() << ": Reject MC outliers" << std::endl;
174  return false;
175  }
176  }
177 
178  // Fill histogram with trigger correlation
179  // self-correlations included
180  std::array<TString, 6> kAbsTriggers = {"MB", "EMC7", "EG1", "EG2", "EJ1", "EJ2"};
181  for(int itrg = 0; itrg < 6; itrg++){
182  bool hasTriggerA = (std::find(fSelectedTriggers.begin(), fSelectedTriggers.end(), kAbsTriggers[itrg]) != fSelectedTriggers.end());
183  if(hasTriggerA) {
184  for(int jtrg = 0; jtrg < 6; jtrg++){
185  bool hasTriggerB = (std::find(fSelectedTriggers.begin(), fSelectedTriggers.end(), kAbsTriggers[jtrg]) != fSelectedTriggers.end());
186  if(hasTriggerB)
187  fHistos->FillTH2("hTriggerCorrelation", kAbsTriggers[itrg], kAbsTriggers[jtrg]);
188  }
189  }
190  }
191 
193  return true;
194 }
195 
196 
198  fSelectedTriggers.clear();
199  Bool_t isMC = MCEvent() != nullptr;
200 
201  TString triggerstring = "";
204  } else {
205  triggerstring = fInputEvent->GetFiredTriggerClasses();
206  }
207 
208 
209  UInt_t selectionstatus = fInputHandler->IsEventSelected();
210  Bool_t isMinBias = selectionstatus & AliVEvent::kINT7,
211  isMinBiasT0 = selectionstatus & AliVEvent::kINT8,
212  isCENT = selectionstatus & AliVEvent::kCentral,
213  isSemiCENT = selectionstatus & AliVEvent::kSemiCentral,
216 
217  if(fExclusiveMinBias){
218  // do not perform EMCAL trigger selection in case only
219  // min. bias trigger is requested:w
220  if(isMinBias) fSelectedTriggers.push_back("MB");
221  if(isMinBiasT0 && fEnableT0Triggers) fSelectedTriggers.push_back("MBT0");
223  if(isCENT) fSelectedTriggers.push_back("CENT");
224  if(isSemiCENT) fSelectedTriggers.push_back("SEMICENT");
225  }
226  return;
227  }
228 
229  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++) emcalTriggers[itrg] = true;
230  if(fEnableT0Triggers) for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++) emc8Triggers[itrg] = true;
231  if(!isMC){
232  // In case of data select events as bunch-bunch (-B-) events.
233  // Cut not applied in simulations
234  if(fRequireBunchCrossing && ! (triggerstring.Contains("-B-") || triggerstring.Contains("-S-"))) return;
235 
236  // In case of data use information from the physics selection and event record
237  // Further cleanup of trigger events can be performed depending on the presence
238  // of recalc patches (after masking hot fastors in the trigger maker) above
239  // threshold
240  if(fUseTriggerBits){
241  const std::array<ULong_t, AliEmcalTriggerOfflineSelection::kTrgn> kSelectTriggerBits = {
242  AliVEvent::kEMC7|AliVEvent::kEMC8, AliVEvent::kEMCEGA, AliVEvent::kEMCEGA, AliVEvent::kEMCEJE, AliVEvent::kEMCEJE,
243  AliVEvent::kEMC7|AliVEvent::kEMC8, AliVEvent::kEMCEGA, AliVEvent::kEMCEGA, AliVEvent::kEMCEJE, AliVEvent::kEMCEJE
244  };
245  for(int iclass = 0; iclass < AliEmcalTriggerOfflineSelection::kTrgn; iclass++){
246  emcalTriggers[iclass] &= bool(selectionstatus & kSelectTriggerBits[iclass]);
247  emc8Triggers[iclass] &= bool(selectionstatus & kSelectTriggerBits[iclass]);
248  if(fRequireL0forL1 && !bool(selectionstatus & (AliVEvent::kEMC7|AliVEvent::kEMC8))) {
249  emcalTriggers[iclass] = false;
250  emc8Triggers[iclass] = false;
251  }
252  }
253  }
254 
255  // Apply cut on the trigger string - this basically discriminates high- and low-threshold
256  // triggers
257  const std::array<TString, AliEmcalTriggerOfflineSelection::kTrgn> kSelectTriggerStrings = {
258  "CEMC7-|CEMC8-", "EG1|EGA", "EG2", "EJ1|EJE", "EJ2", "CDMC7-|CDMC8-", "DG1", "DG2", "DJ1", "DJ2"
259  };
260  if(triggerstring.Contains("EMC")) AliDebugStream(1) << GetName() << ": Trigger string " << triggerstring << std::endl;
261  bool isT0trigger = triggerstring.Contains("INT8") || triggerstring.Contains("EMC8");
262  for(int iclass = 0; iclass < AliEmcalTriggerOfflineSelection::kTrgn; iclass++){
263  bool selectionStatus = false;
264  if(kSelectTriggerStrings[iclass].Contains("|")){
265  std::unique_ptr<TObjArray> options(kSelectTriggerStrings[iclass].Tokenize("|"));
266  for(auto o : *options){
267  TObjString *optstring = static_cast<TObjString *>(o);
268  if(triggerstring.Contains(optstring->String())) selectionStatus = true;
269  }
270  } else {
271  selectionStatus = triggerstring.Contains(kSelectTriggerStrings[iclass]);
272  }
273  if(isT0trigger) {
274  emc8Triggers[iclass] &= selectionStatus;
275  emcalTriggers[iclass] = false;
276  } else {
277  emcalTriggers[iclass] &= selectionStatus;
278  emc8Triggers[iclass] = false;
279  }
280  if(emcalTriggers[iclass])
281  AliDebugStream(1) << GetName() << ": Event selected as trigger " << kSelectTriggerStrings[iclass] << " (INT7 suite)" << std::endl;
282  if(emc8Triggers[iclass])
283  AliDebugStream(1) << GetName() << ": Event selected as trigger " << kSelectTriggerStrings[iclass] << " (INT8 suite)" << std::endl;
284  }
285 
286  // Online selection / rejection
288  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++){
289  if(emcalTriggers[itrg] || emc8Triggers[itrg]){
291  if(fRejectNoiseEvents){
292  if(emcalTriggers[itrg]) emcalTriggers[itrg] &= onlinestatus;
293  if(emc8Triggers[itrg]) emc8Triggers[itrg] &= onlinestatus;
294  } else {
295  if(emcalTriggers[itrg]) emcalTriggers[itrg] &= !onlinestatus;
296  if(emc8Triggers[itrg]) emc8Triggers[itrg] &= !onlinestatus;
297  }
298  }
299  }
300  }
301  }
302  // Apply offline trigger selection: In this case cuts are performed on the
303  // patch energy from EMCAL cells after calibration. This method is most relevant
304  // for simulations. It can have a special use case in data in case a stronger
305  // offline selection is applied in addition to the online selection.
307  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++)
309  }
310  if(isMinBias) fSelectedTriggers.push_back("MB");
312  if(isCENT) fSelectedTriggers.push_back("CENT");
313  if(isSemiCENT) fSelectedTriggers.push_back("SEMICENT");
314  }
315  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0]){
316  fSelectedTriggers.push_back("EMC7");
317  if(!isMinBias) fSelectedTriggers.push_back("EMC7excl");
318  }
319  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ2]){
320  fSelectedTriggers.push_back("EJ2");
321  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EJ2excl");
322  }
323  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ1]){
324  fSelectedTriggers.push_back("EJ1");
325  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEJ2])) fSelectedTriggers.push_back("EJ1excl");
326  }
327  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG2]){
328  fSelectedTriggers.push_back("EG2");
329  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EG2excl");
330  }
331  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG1]){
332  fSelectedTriggers.push_back("EG1");
333  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgEG2])) fSelectedTriggers.push_back("EG1excl");
334  }
335 
337  // Handle DCAL triggers only in case DCAL triggers are enabled,
338  // otherwise ignore results of the online/offline trigger selection
339  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0]){
340  fSelectedTriggers.push_back("DMC7");
341  if(!isMinBias) fSelectedTriggers.push_back("DMC7excl");
342  }
343  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ2]){
344  fSelectedTriggers.push_back("DJ2");
345  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0])) fSelectedTriggers.push_back("DJ2excl");
346  }
347  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ1]){
348  fSelectedTriggers.push_back("DJ1");
349  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDJ2])) fSelectedTriggers.push_back("DJ1excl");
350  }
351  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG2]){
352  fSelectedTriggers.push_back("DG2");
353  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0])) fSelectedTriggers.push_back("DG2excl");
354  }
355  if(emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG1]){
356  fSelectedTriggers.push_back("DG1");
357  if(!(isMinBias || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDL0] || emcalTriggers[AliEmcalTriggerOfflineSelection::kTrgDG2])) fSelectedTriggers.push_back("DG1excl");
358  }
359  }
360 
361  if(fEnableT0Triggers) {
362  if(isMinBiasT0) fSelectedTriggers.push_back("MBT0");
363  if(emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEL0]) {
364  // EMC8 trigger
365  fSelectedTriggers.push_back("EMC8");
366  if(!isMinBiasT0) fSelectedTriggers.push_back("EMC8excl");
367  }
368  if(emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEG1]){
369  // EMC8EGA trigger
370  fSelectedTriggers.push_back("EMC8EGA");
371  if(!(isMinBiasT0 || emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EMC8EGAexcl");
372  }
373  if(emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEJ1]){
374  // EMC8EJE trigger
375  fSelectedTriggers.push_back("EMC8EJE");
376  if(!(isMinBiasT0 || emc8Triggers[AliEmcalTriggerOfflineSelection::kTrgEL0])) fSelectedTriggers.push_back("EMC8EJEexcl");
377  }
378  }
379 }
380 
383 
384  if(!fLocalInitialized){
385  return;
386  }
387 
388  // Handle OADB container with downscaling factors
389  if(fNameDownscaleOADB.Length()){
390  if(fNameDownscaleOADB.Contains("alien://") && ! gGrid) TGrid::Connect("alien://");
391  fDownscaleOADB = new AliOADBContainer("AliEmcalDownscaleFactors");
392  fDownscaleOADB->InitFromFile(fNameDownscaleOADB.Data(), "AliEmcalDownscaleFactors");
393  }
394 
395  if(!fExclusiveMinBias){
396  // Load EMCAL trigger OADB in case EMCAL triggers
397  // are enabled
398 
399  // Load OADB container with masked fastors (in case fastor masking is switched on)
401  if(fNameMaskedFastorOADB.Contains("alien://") && ! gGrid) TGrid::Connect("alien://");
402  fMaskedFastorOADB = new AliOADBContainer("AliEmcalMaskedFastors");
403  fMaskedFastorOADB->InitFromFile(fNameMaskedFastorOADB.Data(), "AliEmcalMaskedFastors");
404  }
405 
406  // Setting online threshold for trigger
408  if(fInputEvent->GetRunNumber() >= 15344 && fInputEvent->GetRunNumber() <= 197388){
413  SetOnlineTriggerThreshold("DG1", 0);
414  SetOnlineTriggerThreshold("DG2", 0);
415  SetOnlineTriggerThreshold("DJ1", 0);
416  SetOnlineTriggerThreshold("DJ2", 0);
417  SetOnlineTriggerThreshold("EMC7", 0);
418  SetOnlineTriggerThreshold("DMC7", 0);
419  }
420  }
421 
422  // Load acceptance OADB
423  if(fNameAcceptanceOADB.Length() && fTriggerSelection){
424  AliDebugStream(1) << GetName() << ": Loading acceptance map from OADB file " << fNameAcceptanceOADB << std::endl;
425  AliOADBContainer acceptanceCont("AliEmcalTriggerAcceptance");
426  acceptanceCont.InitFromFile(fNameAcceptanceOADB.Data(), "AliEmcalTriggerAcceptance");
427  TObjArray *acceptanceMaps = dynamic_cast<TObjArray *>(acceptanceCont.GetObject(fInputEvent->GetRunNumber()));
428  TH2 *map(nullptr);
429  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EG1")))){
430  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger EG1" << std::endl;
431  map->SetDirectory(nullptr);
433  }
434  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EG2")))){
435  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger EG2" << std::endl;
436  map->SetDirectory(nullptr);
438  }
439  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DG1")))){
440  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger DG1" << std::endl;
441  map->SetDirectory(nullptr);
443  }
444  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DG2")))){
445  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger DG2" << std::endl;
446  map->SetDirectory(nullptr);
448  }
449  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EJ1")))){
450  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger EJ1" << std::endl;
451  map->SetDirectory(nullptr);
453  }
454  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("EJ2")))){
455  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger EJ2" << std::endl;
456  map->SetDirectory(nullptr);
458  }
459  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DJ1")))){
460  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger DJ1" << std::endl;
461  map->SetDirectory(nullptr);
463  }
464  if((map = dynamic_cast<TH2 *>(acceptanceMaps->FindObject("DJ2")))){
465  AliDebugStream(1) << GetName() << ": Found acceptance map for trigger DJ2" << std::endl;
466  map->SetDirectory(nullptr);
468  }
469  }
470  }
471 }
472 
474  if(fDownscaleOADB){
475  fDownscaleFactors = static_cast<TObjArray *>(fDownscaleOADB->GetObject(runnumber));
476  }
478 
479  // Log info for downscale factors
480  if(!fDownscaleFactors || !fDownscaleFactors->GetEntries()){
481  AliInfoStream() << GetName() << ": No downscale factors provided for run " << runnumber << std::endl;
482  } else {
483  AliInfoStream() << GetName() << ": Downscale factors used for run " << runnumber << std::endl;
484  for(auto e : *fDownscaleFactors){
485  TParameter<double> *dfactor = static_cast<TParameter<double> *>(e);
486  AliInfoStream() << GetName() << ": Trigger " << dfactor->GetName() << ", downscale factor " << dfactor->GetVal() << std::endl;
487  }
488  }
489 
490  if(!fExclusiveMinBias){
491  if(fMaskedFastorOADB){
492  fMaskedFastors.clear();
493  TObjArray *ids = static_cast<TObjArray *>(fMaskedFastorOADB->GetObject(runnumber));
494  for(auto m : *ids){
495  TParameter<int> *id = static_cast<TParameter<int> *>(m);
496  fMaskedFastors.push_back(id->GetVal());
497  }
498  }
499  }
500 }
501 
503  // Exclusive means classes without lower trigger classes (which are downscaled) -
504  // in order to make samples statistically independent: MBExcl means MinBias && !EMCAL trigger
505  std::vector<TString> triggers = {"MB"}; // Min. Bias always enabled
506  const std::array<TString, 10> emcaltriggers = {{"EMC7", "EJ1", "EJ2", "EG1", "EG2", "EMC7excl", "EG2excl", "EJ2excl", "EJ1excl", "EG1excl"}},
507  dcaltriggers = {{"DMC7", "DJ1", "DJ2", "DG1", "DG2", "DMC7excl", "DG2excl", "DJ2excl", "DJ1excl", "DG1excl"}};
508  const std::array<TString, 7> t0triggers = {{"MBT0", "EMC8", "EMC8EGA", "EMC8EJE", "EMC8excl", "EMC8EGAexcl", "EMC8EJEexcl"}};
509  const std::array<TString, 2> centralitytriggers = {{"CENT", "SEMICENT"}};
510  if(!fExclusiveMinBias){
511  for(const auto &t : emcaltriggers) triggers.push_back(t);
512  }
514  for(const auto &t : dcaltriggers) triggers.push_back(t);
515  }
516  if(fEnableT0Triggers){
517  for(const auto &t: t0triggers) triggers.push_back(t);
518  }
520  for(const auto &t : centralitytriggers) triggers.push_back(t);
521  }
522  return triggers;
523 }
524 
526  AliDebugStream(1) << "Using V1 online trigger selector" << std::endl;
528  int ngood(0);
529  for(auto p : *fTriggerPatchInfo){
530  AliEMCALTriggerPatchInfo *patch = static_cast<AliEMCALTriggerPatchInfo *>(p);
531  if((AliEmcalTriggerOfflineSelection::IsSingleShower(trigger) && patch->IsGammaLowRecalc()) ||
532  (!AliEmcalTriggerOfflineSelection::IsSingleShower(trigger) && patch->IsJetLowRecalc())){
533  if(patch->GetADCAmp() >= GetOnlineTriggerThresholdByIndex(trigger)) ngood++;
534  }
535  }
536  return ngood > 0;
537 }
538 
540  if(fDownscaleFactors){
541  TParameter<double> *result(nullptr);
542  // Downscaling only done on MB, L0 and the low threshold triggers
543  if(triggerclass.Contains("MB")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("INT7"));
544  else if(triggerclass.Contains("EMC7")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EMC7"));
545  else if(triggerclass.Contains("DMC7")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("DMC7"));
546  else if(triggerclass.Contains("EJ2")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EJ2"));
547  else if(triggerclass.Contains("EJ1")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EJ1"));
548  else if(triggerclass.Contains("EG2")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EG2"));
549  else if(triggerclass.Contains("EG1")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("EG1"));
550  else if(triggerclass.Contains("DG2")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("DG2"));
551  else if(triggerclass.Contains("DG1")) result = static_cast<TParameter<double> *>(fDownscaleFactors->FindObject("DG1"));
552  double triggerweight = 1.;
553  if(result) triggerweight = 1./result->GetVal();
554  AliDebugStream(1) << "Using trigger weight " << triggerweight << " for trigger " << triggerclass << std::endl;
555  return triggerweight;
556  } else {
557  AliDebugStream(1) << "No downscale factors loaded - using trigger weight 1" << std::endl;
558  }
559  return 1.;
560 }
561 
563  AliInfoStream() << "Reading downscale factors from OCDB for run " << fInputEvent->GetRunNumber() << std::endl;
564  if(!fDownscaleFactors){
566  fDownscaleFactors->SetOwner(true);
567  }
568  fDownscaleFactors->Clear();
570  if(downscaleOCDB->GetCurrentRun() != fInputEvent->GetRunNumber()) downscaleOCDB->SetRun(fInputEvent->GetRunNumber());
571  const std::array<TString, 11> khwtriggers = {"INT7", "EMC7", "DMC7", "EJ1", "EJ2", "DJ1", "DJ2", "EG1", "EG2", "DG1", "DG2"};
572  std::vector<TString> runtriggers = downscaleOCDB->GetTriggerClasses();
573  for(const auto &t : khwtriggers){
574  std::function<bool (TString)> triggerfinder = [t](const TString &test) -> bool {
575  if(!test.Contains(t + "-B-")) return false;
576  return true;
577  };
578  auto entry = std::find_if(runtriggers.begin(), runtriggers.end(), triggerfinder);
579  if(entry != runtriggers.end()){
580  TString triggername = *entry;
581  double downscalefactor = downscaleOCDB->GetDownscaleFactorForTriggerClass(triggername);
582  AliInfoStream() << "Applying downscale factor " << downscalefactor << " for trigger " << t << " (" << triggername << ") for run " << fInputEvent->GetRunNumber() << std::endl;
583  fDownscaleFactors->Add(new TParameter<double>(t, TMath::Abs(downscalefactor) < DBL_EPSILON ? 1 : downscalefactor));
584  } else {
585  AliErrorStream() << "No downscale factor found for trigger " << t << " for run " << fInputEvent->GetRunNumber() << std::endl;
586  }
587  }
588 }
589 
591  TParameter<int> *threshpar(nullptr);
592  if((threshpar = static_cast<TParameter<int> *>(fOnlineTriggerThresholds.FindObject(triggerclass.Data())))){
593  threshpar->SetVal(threshold);
594  } else {
595  fOnlineTriggerThresholds.Add(new TParameter<int>(triggerclass.Data(), threshold));
596  }
597 }
598 
600  Int_t threshold(0);
601  TParameter<int> *val(nullptr);
602  if((val = static_cast<TParameter<int> *>(fOnlineTriggerThresholds.FindObject(name))))
603  threshold = val->GetVal();
604  return threshold;
605 }
606 
608  const TString triggernames[AliEmcalTriggerOfflineSelection::kTrgn] = {"EMC7", "EG1", "EG2", "EJ1", "EJ2", "DMC7",
609  "DG1", "DG2", "DJ1", "DJ2"};
610  return GetOnlineTriggerThresholdByName(triggernames[trigger]);
611 }
612 
614  const TString triggernames[AliEmcalTriggerOfflineSelection::kTrgn] = {"EMC7", "EG1", "EG2", "EJ1", "EJ2", "DMC7",
615  "DG1", "DG2", "DJ1", "DJ2"};
616  bool isInitialized = true;
617  for(int itrg = 0; itrg < AliEmcalTriggerOfflineSelection::kTrgn; itrg++){
618  if(!fOnlineTriggerThresholds.FindObject(triggernames[itrg].Data())) {
619  isInitialized = false;
620  break;
621  }
622  }
623  return isInitialized;
624 }
625 
627  return adc > GetOnlineTriggerThresholdByName(triggerclass);
628 }
629 
631  TString triggerstring = "";
632  Int_t nEJ1 = 0, nEJ2 = 0, nEG1 = 0, nEG2 = 0, nDJ1 = 0, nDJ2 = 0, nDG1 = 0, nDG2 = 0;
633  for(auto patchIter : *triggerpatches){
634  AliEMCALTriggerPatchInfo *patch = dynamic_cast<AliEMCALTriggerPatchInfo *>(patchIter);
635  if(!patch->IsRecalc()) continue;
636  if(patch->IsEMCal()){
637  if(patch->IsGammaLowRecalc() && SelectFiredPatch("EG1", patch->GetADCAmp())) nEG1++;
638  if(patch->IsGammaLowRecalc() && SelectFiredPatch("EG2", patch->GetADCAmp())) nEG2++;
639  if(patch->IsJetLowRecalc() && SelectFiredPatch("EJ1", patch->GetADCAmp())) nEJ1++;
640  if(patch->IsJetLowRecalc() && SelectFiredPatch("EJ2", patch->GetADCAmp())) nEJ2++;
641  } else {
642  if(patch->IsGammaLowRecalc() && SelectFiredPatch("DG1", patch->GetADCAmp())) nDG1++;
643  if(patch->IsGammaLowRecalc() && SelectFiredPatch("DG2", patch->GetADCAmp())) nDG2++;
644  if(patch->IsJetLowRecalc() && SelectFiredPatch("DJ1", patch->GetADCAmp())) nDJ1++;
645  if(patch->IsJetLowRecalc() && SelectFiredPatch("DJ2", patch->GetADCAmp())) nDJ2++;
646  }
647  }
648  if(nEJ1) triggerstring += "EJ1";
649  if(nEJ2){
650  if(triggerstring.Length()) triggerstring += ",";
651  triggerstring += "EJ2";
652  }
653  if(nEG1){
654  if(triggerstring.Length()) triggerstring += ",";
655  triggerstring += "EG1";
656  }
657  if(nEG2){
658  if(triggerstring.Length()) triggerstring += ",";
659  triggerstring += "EG2";
660  }
661  if(nDJ1){
662  if(triggerstring.Length()) triggerstring += ",";
663  triggerstring += "DJ2";
664  }
665  if(nDJ2){
666  if(triggerstring.Length()) triggerstring += ",";
667  triggerstring += "DJ2";
668  }
669  if(nDG1){
670  if(triggerstring.Length()) triggerstring += ",";
671  triggerstring += "DG1";
672  }
673  if(nDG2){
674  if(triggerstring.Length()) triggerstring += ",";
675  triggerstring += "DG2";
676  }
677  return triggerstring;
678 }
679 
680 } /* 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.
static AliEmcalDownscaleFactorsOCDB * Instance()
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.
AliEmcalTriggerOfflineSelection * fTriggerSelection
Offline trigger selection.
void PrepareDownscaleFactorsFormOCDB()
Read the downscale factors from the OCDB.
Double_t GetDownscaleFactorForTriggerClass(const TString &trigger) const
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.
std::vector< TString > GetTriggerClasses() const
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
Handler for downscale factors for various triggers obtained from the OCDB.
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.