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