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