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