AliPhysics  ff07904 (ff07904)
AliAnalysisTaskEmcalTriggerSelection.cxx
Go to the documentation of this file.
1 /************************************************************************************
2  * Copyright (C) 2017, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  ************************************************************************************/
27 #include <algorithm>
28 #include <iostream>
29 #include <sstream>
30 #include <unordered_map>
31 #include <TH1.h>
36 #include "AliEMCALTriggerPatchInfo.h"
37 #include "AliYAMLConfiguration.h"
38 
42 
43 namespace PWG {
44 namespace EMCAL {
45 
46 AliAnalysisTaskEmcalTriggerSelection::AliAnalysisTaskEmcalTriggerSelection():
48  fTriggerDecisionContainer(nullptr),
49  fGlobalDecisionContainerName("EmcalTriggerDecision"),
50  fTriggerSelections(),
51  fSelectionQA()
52 {
53  SetCaloTriggerPatchInfoName("EmcalTriggers");
54  fTriggerSelections.SetOwner(kTRUE);
55 }
56 
58  AliAnalysisTaskEmcal(name, kTRUE),
60  fGlobalDecisionContainerName("EmcalTriggerDecision"),
62  fSelectionQA()
63 {
64  SetCaloTriggerPatchInfoName("EmcalTriggers");
66  fTriggerSelections.SetOwner(kTRUE);
67 }
68 
71 
72  for(auto s : fTriggerSelections) InitQA(static_cast<AliEmcalTriggerSelection *>(s));
73  for(auto q : fSelectionQA) static_cast<AliEmcalTriggerSelectionQA *>(q)->GetHistos(fOutput);
74 }
75 
78  fInputEvent->AddObject(fTriggerDecisionContainer);
79 }
80 
82  fTriggerSelections.Add(selection);
83 }
84 
87  AliEmcalTriggerSelection *selection(NULL);
88  TIter selectionIter(&fTriggerSelections);
89  while((selection = dynamic_cast<AliEmcalTriggerSelection *>(selectionIter()))){
91  }
92  return kTRUE;
93 }
94 
97  return kTRUE;
98 }
99 
102  fSelectionQA.Add(qa);
103 }
104 
106  for(auto d : *(cont->GetListOfTriggerDecisions())) {
107  AliEmcalTriggerDecision *myd = static_cast<AliEmcalTriggerDecision *>(d);
108  static_cast<AliEmcalTriggerSelectionQA *>(fSelectionQA.FindObject(myd->GetName()))->Fill(myd);
109  }
110 }
111 
113  if(Is2012PP(period)) ConfigurePP2012();
114  if(Is2016PP(period)) ConfigurePP2016();
115  if(Is2012MCPP(period)) ConfigureMCPP2012();
116  if(Is2016MCPP(period)) ConfigureMCPP2016();
117 }
118 
120  TString datasetstring(dataset);
121  datasetstring.ToLower();
122  if(datasetstring.Length() != 6) return false; // not data period
123  if(datasetstring.Contains("lhc12")){
124  auto subperiod = datasetstring[5];
125  if(subperiod > 'b' && subperiod < 'j') return true;
126  }
127  return false;
128 }
129 
131  TString datasetstring(dataset);
132  datasetstring.ToLower();
133  if(datasetstring.Length() != 6) return false; // not data period
134  if(datasetstring.Contains("lhc16") || datasetstring.Contains("lhc17") || datasetstring.Contains("lhc18")){
135  auto subperiod = datasetstring[5];
136  if(datasetstring.Contains("lhc16")){
137  if(subperiod > 'g' && subperiod < 'q') return true;
138  }
139  if(datasetstring.Contains("lhc17")) {
140  if((subperiod > 'c' && subperiod < 'n') || (subperiod == 'o') || (subperiod < 'r')) return true;
141  }
142  if(datasetstring.Contains("lhc18")) {
143  // 2018 runs will follow when taken
144  return true;
145  }
146  }
147  return false;
148 }
149 
151  std::vector<TString> supportedProductions = {"lhc15h1", "lhc15h2", "lhc16a1", "lhc16c2", "lhc17g5a", "lhc17g5"};
152  return IsSupportedMCSample(dataset, supportedProductions);
153 }
154 
156  std::vector<TString> supportedProductions = {"lhc17f8", "lhc18f5"};
157  return IsSupportedMCSample(dataset, supportedProductions);
158 }
159 
160 Bool_t AliAnalysisTaskEmcalTriggerSelection::IsSupportedMCSample(const char *dataset, std::vector<TString> &supportedProductions) const{
161  TString datasetstring(dataset);
162  datasetstring.ToLower();
163  bool found(false);
164  for(const auto & prod : supportedProductions) {
165  if(datasetstring.Contains(prod)) {
166  found = true;
167  break;
168  }
169  }
170  return found;
171 }
172 
178  eg1cuts->SetUseRecalcPatches(true);
179  eg1cuts->SetThreshold(130);
180  this->AddTriggerSelection(new AliEmcalTriggerSelection("EGA", eg1cuts));
181 
186  ej1cuts->SetUseRecalcPatches(true);
187  ej1cuts->SetThreshold(200);
188  this->AddTriggerSelection(new AliEmcalTriggerSelection("EJE", ej1cuts));
189 }
190 
196  eg1cuts->SetUseSimpleOfflinePatches(true);
197  eg1cuts->SetThreshold(10.);
198  this->AddTriggerSelection(new AliEmcalTriggerSelection("EGA", eg1cuts));
199 
204  ej1cuts->SetUseSimpleOfflinePatches(true);
205  ej1cuts->SetThreshold(15.5);
206  this->AddTriggerSelection(new AliEmcalTriggerSelection("EJE", ej1cuts));
207 }
208 
214  eg1cuts->SetUseRecalcPatches(true);
215  eg1cuts->SetThreshold(115);
216  this->AddTriggerSelection(new AliEmcalTriggerSelection("EG1", eg1cuts));
217 
222  eg2cuts->SetUseRecalcPatches(true);
223  eg2cuts->SetUseSimpleOfflinePatches(true);
224  eg2cuts->SetThreshold(51);
225  this->AddTriggerSelection(new AliEmcalTriggerSelection("EG2", eg2cuts));
226 
231  dg1cuts->SetUseRecalcPatches(true);
232  dg1cuts->SetThreshold(115);
233  this->AddTriggerSelection(new AliEmcalTriggerSelection("DG1", dg1cuts));
234 
239  dg2cuts->SetUseRecalcPatches(true);
240  dg2cuts->SetThreshold(51);
241  this->AddTriggerSelection(new AliEmcalTriggerSelection("DG2", dg2cuts));
242 
247  ej1cuts->SetUseRecalcPatches(true);
248  ej1cuts->SetThreshold(255);
249  this->AddTriggerSelection(new AliEmcalTriggerSelection("EJ1", ej1cuts));
250 
255  ej2cuts->SetUseRecalcPatches(true);
256  ej2cuts->SetThreshold(204);
257  this->AddTriggerSelection(new AliEmcalTriggerSelection("EJ2", ej2cuts));
258 
263  dj1cuts->SetUseRecalcPatches(true);
264  dj1cuts->SetThreshold(255);
265  this->AddTriggerSelection(new AliEmcalTriggerSelection("DJ1", dj1cuts));
266 
271  dj2cuts->SetUseRecalcPatches(true);
272  dj2cuts->SetThreshold(204);
273  this->AddTriggerSelection(new AliEmcalTriggerSelection("DJ2", dj2cuts));
274 
275 }
276 
282  eg1cuts->SetUseSimpleOfflinePatches(true);
283  eg1cuts->SetThreshold(9.);
284  this->AddTriggerSelection(new AliEmcalTriggerSelection("EG1", eg1cuts));
285 
290  eg2cuts->SetUseSimpleOfflinePatches(true);
291  eg2cuts->SetThreshold(4.);
292  this->AddTriggerSelection(new AliEmcalTriggerSelection("EG2", eg2cuts));
293 
298  dg1cuts->SetUseSimpleOfflinePatches(true);
299  dg1cuts->SetThreshold(9.);
300  this->AddTriggerSelection(new AliEmcalTriggerSelection("DG1", dg1cuts));
301 
306  dg2cuts->SetUseSimpleOfflinePatches(true);
307  dg2cuts->SetThreshold(4.);
308  this->AddTriggerSelection(new AliEmcalTriggerSelection("DG2", dg2cuts));
309 
314  ej1cuts->SetUseSimpleOfflinePatches(true);
315  ej1cuts->SetThreshold(19.);
316  this->AddTriggerSelection(new AliEmcalTriggerSelection("EJ1", ej1cuts));
317 
322  ej2cuts->SetUseSimpleOfflinePatches(true);
323  ej2cuts->SetThreshold(14.);
324  this->AddTriggerSelection(new AliEmcalTriggerSelection("EJ2", ej2cuts));
325 
330  dj1cuts->SetUseSimpleOfflinePatches(true);
331  dj1cuts->SetThreshold(19.);
332  this->AddTriggerSelection(new AliEmcalTriggerSelection("DJ1", dj1cuts));
333 
338  dj2cuts->SetUseSimpleOfflinePatches(true);
339  dj2cuts->SetThreshold(14.);
340  this->AddTriggerSelection(new AliEmcalTriggerSelection("DJ2", dj2cuts));
341 }
342 
344  using YAMLhandler = PWG::Tools::AliYAMLConfiguration;
345  YAMLhandler configuration;
346  configuration.AddConfiguration(configfile, "user");
347  configuration.Initialize();
348  std::string namecontainer, acceptance, patchtype, energydef, energysource;
349  std::vector<std::string> triggerclasses;
350  configuration.GetProperty("containername", namecontainer);
351  configuration.GetProperty("energydef", energydef);
352  configuration.GetProperty("energysource", energysource);
353  configuration.GetProperty("triggerclasses", triggerclasses);
354  bool isOfflineSimple = energysource.find("Offline") != std::string::npos,
355  isRecalc = energysource.find("Recalc") != std::string::npos;
356 
357  SetGlobalDecisionContainerName(namecontainer.data());
358 
360  try {
361  selectionmethod = DecodeEnergyDefinition(energydef);
362  } catch(ConfigValueException &e) {
363  AliErrorStream() << e.what() << " - not processing trigger classes" << std::endl;
364  return;
365  }
366  for(auto t : triggerclasses) {
367  double threshold;
368  configuration.GetProperty(Form("%s:acceptance", t.data()), acceptance);
369  configuration.GetProperty(Form("%s:patchtype", t.data()), patchtype);
370  configuration.GetProperty(Form("%s:threshold", t.data()), threshold);
371 
373  try {
374  cuts->SetAcceptanceType(DecodeAcceptanceString(acceptance));
375  cuts->SetPatchType(DecodePatchTypeString(patchtype));
376  } catch(ConfigValueException &e){
377  AliErrorStream() << e.what() << " - not adding trigger class " << t << std::endl;
378  delete cuts;
379  continue;
380  }
381 
382  cuts->SetSelectionMethod(selectionmethod);
383  if(isOfflineSimple) cuts->SetUseSimpleOfflinePatches();
384  if(isRecalc) cuts->SetUseRecalcPatches();
385  cuts->SetThreshold(threshold);
386  this->AddTriggerSelection(new AliEmcalTriggerSelection(t.data(), cuts));
387  }
388 }
389 
391  std::unordered_map<std::string, AliEmcalTriggerSelectionCuts::AcceptanceType_t> mapacceptance = {
394  };
395  auto result = mapacceptance.find(acceptancestring);
396  if(result == mapacceptance.end()) throw ConfigValueException("accpetance", acceptancestring.data());
397  return result->second;
398 }
399 
401  std::unordered_map<std::string, AliEmcalTriggerSelectionCuts::PatchType_t> mappatchtype = {
408  };
409  auto result = mappatchtype.find(patchtypestring);
410  if(result == mappatchtype.end()) throw ConfigValueException("accpetance", patchtypestring.data());
411  return result->second;
412 }
413 
415  std::unordered_map<std::string, AliEmcalTriggerSelectionCuts::SelectionMethod_t> mapenergydef = {
420  };
421  auto result = mapenergydef.find(energydefstring);
422  if(result == mapenergydef.end()) throw ConfigValueException("accpetance", energydefstring.data());
423  return result->second;
424 
425 }
426 
427 void AliAnalysisTaskEmcalTriggerSelection::PrintStream(std::ostream &stream) const {
428  stream << "Task: " << GetName() << ", name of the output container: " << fGlobalDecisionContainerName << std::endl << std::endl;
429  stream << "Trigger classes: " << std::endl;
430  for(const auto c : this->fTriggerSelections){
432  stream << *sel << std::endl;
433  }
434 }
435 
437  TNamed(),
438  fMaxPatchADC(nullptr),
439  fMaxPatchEnergy(nullptr),
440  fMaxPatchEnergySmeared(nullptr)
441 {
442 }
443 
445  TNamed(sel->GetName(), ""),
449 {
450  fMaxPatchADC = new TH1D(Form("hMaxPatchADC%s", GetName()), "Max. patch ADC", 1000, 0., 1000);
451  fMaxPatchEnergy = new TH1D(Form("hMaxPatchEnergy%s", GetName()), "Max. patch energy", 1000, 0., 100);
452  fMaxPatchEnergySmeared = new TH1D(Form("hMaxPatchEnergySmeared%s", GetName()), "Max. patch smeared energy", 1000, 0., 100);
453 }
454 
456  TNamed(ref),
460 {
461 }
462 
464  TNamed::operator=(ref);
465  if(this != &ref) {
469  }
470  return *this;
471 }
472 
474  if(decision->GetMainPatch()){
475  fMaxPatchADC->Fill(decision->GetMainPatch()->GetADCAmp());
476  fMaxPatchEnergy->Fill(decision->GetMainPatch()->GetPatchE());
477  fMaxPatchEnergySmeared->Fill(decision->GetMainPatch()->GetSmearedEnergy());
478  }
479 }
480 
482  targetlist->Add(fMaxPatchADC);
483  targetlist->Add(fMaxPatchEnergy);
484  targetlist->Add(fMaxPatchEnergySmeared);
485 
486 }
487 
489  fKey(key),
490  fValue(value),
491  fMessage()
492 {
493  std::stringstream msgbuilder;
494  msgbuilder << "Improper value for key " << fKey << ": " << fValue;
495  fMessage = msgbuilder.str();
496 }
497 
498 }
499 }
500 
501 std::ostream &operator<<(std::ostream &stream, const PWG::EMCAL::AliAnalysisTaskEmcalTriggerSelection &task) {
502  task.PrintStream(stream);
503  return stream;
504 }
Class for the selection of trigger patches in the EMCAL triggered event selection.
Object performing offline EMCAL trigger selection.
AliEmcalTriggerSelectionCuts::AcceptanceType_t DecodeAcceptanceString(const std::string &acceptancestring)
void ConfigurePP2016()
Trigger configuration for run2 pp (2016 - 2018) - data mode.
Container for trigger decision.
void MakeQA(const AliEmcalTriggerDecisionContainer *cont)
Fill QA histograms for the event.
virtual void UserExecOnce()
Initializations performed when the first event is created.
void SetGlobalDecisionContainerName(const char *name)
Set the name of the global trigger decision container.
void SetSelectionMethod(SelectionMethod_t selectionMethod)
void AutoConfigure(const char *period)
Automatically configure trigger decision handler for different periods.
TString fGlobalDecisionContainerName
Name of the global trigger selection.
Base task in the EMCAL framework.
virtual Bool_t FillHistograms()
Filling basic QA Histograms of the trigger selection task.
void ConfigurePP2012()
Trigger configuration for run1 pp (2012) - data mode.
virtual void UserCreateOutputObjects()
Initialization of output container.
void ConfigureMCPP2012()
Trigger configuration for MC anchored to run1 pp (2012)
TCanvas * c
Definition: TestFitELoss.C:172
void InitQA(const AliEmcalTriggerSelection *const sel)
Initialize QA histograms for trigger selection.
Bool_t IsSupportedMCSample(const char *period, std::vector< TString > &supportedProductions) const
void SetCaloTriggerPatchInfoName(const char *n)
Namespace for EMCAL framework classes and task.
const AliEMCALTriggerPatchInfo * GetMainPatch() const
Get the highest energetic trigger patch of the event firing the trigger.
AliEmcalTriggerDecisionContainer * GetGlobalTriggerDecisionContainer() const
Find the main trigger container in the input event.
void GetHistos(Double_t lowLim, Double_t highLim, Dir *resp, Dir *data, TDirectory *out)
Definition: UnfoldMult.C:261
const TList * GetListOfTriggerDecisions() const
Get container with trigger decision results.
void PrintStream(std::ostream &stream) const
Print information about the trigger decision container to the output stream.
AliEmcalTriggerSelectionQA & operator=(const AliEmcalTriggerSelectionQA &ref)
Assignment operator.
Definition: External.C:212
void GetHistos(TList *targetlist) const
Fill histograms of this QA component into the targetlist.
AliEmcalTriggerSelectionCuts::SelectionMethod_t DecodeEnergyDefinition(const std::string &energydefstring)
Namespace for PWG framework classes.
void Reset()
Clear container with trigger decisions.
AliEmcalTriggerDecision * MakeDecison(const TClonesArray *const reconstructedPatches) const
ConfigValueException(const char *key, const char *value)
Construct a new ConfigValueException object.
AliEmcalList * fOutput
!output list
Task providing an event selection for EMCAL-triggered events based on the reconstructed EMCAL trigger...
YAML configuration class for AliPhysics.
void SetMakeGeneralHistograms(Bool_t g)
TClonesArray * fTriggerPatchInfo
!trigger patch info array
void SetAcceptanceType(AcceptanceType_t acceptance)
void ConfigureFromYAML(const char *yamlconfig)
Configure task using YAML configuration file.
void ConfigureMCPP2016()
Trigger configuration for MC anchored to run2 pp (2016-2018)
AliEmcalTriggerSelectionCuts::PatchType_t DecodePatchTypeString(const std::string &patchtypestring)
AliEmcalTriggerDecisionContainer * fTriggerDecisionContainer
Trigger decision container objects.
int AddConfiguration(std::string configurationFilename, std::string configurationName="")
void UserCreateOutputObjects()
Main initialization function on the worker.
bool Bool_t
Definition: External.C:53
friend std::ostream & operator<<(std::ostream &stream, const AliAnalysisTaskEmcalTriggerSelection &task)
Output stream operator.
void AddTriggerSelection(AliEmcalTriggerSelection *const selection)
Add trigger selection to the trigger selection task.
TString prod[]
productions to be compared, directory name
void AddTriggerDecision(AliEmcalTriggerDecision *const decision)
Add trigger decision to the container.