AliPhysics  608b256 (608b256)
AliEmcalContainerUtils.cxx
Go to the documentation of this file.
1 //
2 // Containers EMCal container utility functions
3 //
4 
6 
7 #include <iostream>
8 
9 #include <AliVEvent.h>
10 #include <AliLog.h>
11 #include <AliAnalysisManager.h>
12 #include <AliVEventHandler.h>
13 
15 
16 // string to enum map for use with the %YAML config
17 const std::map <std::string, AliVEvent::EOfflineTriggerTypes> AliEmcalContainerUtils::fgkPhysicsSelectionMap = {
18  {"kMB", AliVEvent::kMB},
19  {"kINT1", AliVEvent::kINT1},
20  {"kINT7", AliVEvent::kINT7},
21  {"kMUON", AliVEvent::kMUON},
22  {"kHighMult", AliVEvent::kHighMult},
23  {"kHighMultSPD", AliVEvent::kHighMultSPD},
24  {"kEMC1", AliVEvent::kEMC1},
25  {"kCINT5", AliVEvent::kCINT5},
26  {"kINT5", AliVEvent::kINT5},
27  {"kCMUS5", AliVEvent::kCMUS5},
28  {"kMUSPB", AliVEvent::kMUSPB},
29  {"kINT7inMUON", AliVEvent::kINT7inMUON},
30  {"kMuonSingleHighPt7", AliVEvent::kMuonSingleHighPt7},
31  {"kMUSH7", AliVEvent::kMUSH7},
32  {"kMUSHPB", AliVEvent::kMUSHPB},
33  {"kMuonLikeLowPt7", AliVEvent::kMuonLikeLowPt7},
34  {"kMUL7", AliVEvent::kMUL7},
35  {"kMuonLikePB", AliVEvent::kMuonLikePB},
36  {"kMuonUnlikeLowPt7", AliVEvent::kMuonUnlikeLowPt7},
37  {"kMUU7", AliVEvent::kMUU7},
38  {"kMuonUnlikePB", AliVEvent::kMuonUnlikePB},
39  {"kEMC7", AliVEvent::kEMC7},
40  {"kEMC8", AliVEvent::kEMC8},
41  {"kMUS7", AliVEvent::kMUS7},
42  {"kMuonSingleLowPt7", AliVEvent::kMuonSingleLowPt7},
43  {"kPHI1", AliVEvent::kPHI1},
44  {"kPHI7", AliVEvent::kPHI7},
45  {"kPHI8", AliVEvent::kPHI8},
46  {"kPHOSPb", AliVEvent::kPHOSPb},
47  {"kEMCEJE", AliVEvent::kEMCEJE},
48  {"kEMCEGA", AliVEvent::kEMCEGA},
49  {"kHighMultV0", AliVEvent::kHighMultV0},
50  {"kCentral", AliVEvent::kCentral},
51  {"kSemiCentral", AliVEvent::kSemiCentral},
52  {"kDG", AliVEvent::kDG},
53  {"kDG5", AliVEvent::kDG5},
54  {"kZED", AliVEvent::kZED},
55  {"kSPI7", AliVEvent::kSPI7},
56  {"kSPI", AliVEvent::kSPI},
57  {"kINT8", AliVEvent::kINT8},
58  {"kMuonSingleLowPt8", AliVEvent::kMuonSingleLowPt8},
59  {"kMuonSingleHighPt8", AliVEvent::kMuonSingleHighPt8},
60  {"kMuonLikeLowPt8", AliVEvent::kMuonLikeLowPt8},
61  {"kMuonUnlikeLowPt8", AliVEvent::kMuonUnlikeLowPt8},
62  {"kMuonUnlikeLowPt0", AliVEvent::kMuonUnlikeLowPt0},
63  {"kUserDefined", AliVEvent::kUserDefined},
64  {"kTRD", AliVEvent::kTRD},
65  {"kMuonCalo", AliVEvent::kMuonCalo},
66  {"kFastOnly", AliVEvent::kFastOnly},
67  {"kAny", AliVEvent::kAny},
68  {"kAnyINT", AliVEvent::kAnyINT}
69 };
70 
77 UInt_t AliEmcalContainerUtils::DeterminePhysicsSelectionFromYAML(const std::vector<std::string> & selections)
78 {
79  UInt_t physicsSelection = 0;
80  for (auto selection : selections) {
81  auto sel = fgkPhysicsSelectionMap.find(selection);
82  AliDebugGeneralStream("AliEmcalContainerUtils", 3) << "Adding physics selection: " << selection << "\n";
83  if (sel != fgkPhysicsSelectionMap.end()) {
84  physicsSelection |= sel->second;
85  }
86  else {
87  AliFatalGeneralF("AliEmcalContainerUtils", "Could not find physics selection with key \"%s\"", selection.c_str());
88  }
89  }
90  return physicsSelection;
91 }
92 
103 {
104  // Get the pointer to the existing analysis manager via the static access method.
105  //==============================================================================
106  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
107  if (!mgr)
108  {
109  ::Error("AddTaskEmcalSample", "No analysis manager to connect to.");
110  return 0;
111  }
112 
113  // Check the analysis type using the event handlers connected to the analysis manager.
114  //==============================================================================
115  AliVEventHandler* handler = mgr->GetInputEventHandler();
116  if (!handler)
117  {
118  ::Error("AddTaskEmcalSample", "This task requires an input event handler");
119  return 0;
120  }
121 
122  enum EDataType_t {
123  kUnknown,
124  kESD,
125  kAOD
126  };
127 
128  EDataType_t dataType = kUnknown;
129 
130  if (handler->InheritsFrom("AliESDInputHandler")) {
131  dataType = kESD;
132  }
133  else if (handler->InheritsFrom("AliAODInputHandler")) {
134  dataType = kAOD;
135  }
136 
137  return DetermineUseDefaultName(objType, dataType == kESD, false);
138 }
139 
155 std::string AliEmcalContainerUtils::DetermineUseDefaultName(InputObject_t objType, bool esdMode, bool returnObjectType)
156 {
157  std::string returnValue = "";
158  if (objType == kCluster) {
159  if (esdMode == true) {
160  if (returnObjectType == true) {
161  returnValue = "AliESDCaloCluster";
162  }
163  else {
164  returnValue = "CaloClusters";
165  }
166  }
167  else {
168  if (returnObjectType == true) {
169  returnValue = "AliAODCaloCluster";
170  }
171  else {
172  returnValue = "caloClusters";
173  }
174  }
175  }
176  else if (objType == kTrack) {
177  if (esdMode == true) {
178  if (returnObjectType == true) {
179  returnValue = "AliESDtrack";
180  }
181  else {
182  returnValue = "Tracks";
183  }
184  }
185  else {
186  if (returnObjectType == true) {
187  returnValue = "AliAODTrack";
188  }
189  else {
190  returnValue = "tracks";
191  }
192  }
193  }
194  else if (objType == kCaloCells) {
195  if (esdMode == true) {
196  if (returnObjectType == true) {
197  returnValue = "AliESDCaloCells";
198  }
199  else {
200  returnValue = "EMCALCells";
201  }
202  }
203  else {
204  if (returnObjectType == true) {
205  returnValue = "AliAODCaloCells";
206  }
207  else {
208  returnValue = "emcalCells";
209  }
210  }
211  }
212  else {
213  // Default to empty if we are given an unrecognized type with "usedefault"
214  returnValue = "";
215  AliWarningGeneralStream("AliEmcalContainerUtils") << "Unrecognized combination of inputs! Passed values of input object: " << objType << ", esdMode: " << std::boolalpha << esdMode << ", returnObjectType " << returnObjectType << std::endl;
216  }
217 
218  return returnValue;
219 }
220 
231 const AliVEvent * AliEmcalContainerUtils::GetEvent(const AliVEvent * inputEvent, bool isEmbedding)
232 {
233  const AliVEvent * event = nullptr;
234  if (isEmbedding) {
236  if (!embedding) return nullptr;
237 
238  // Need the const cast as GetExternalEvent() returns a non-const event
239  event = const_cast<const AliVEvent *>(embedding->GetExternalEvent());
240  }
241  else {
242  event = inputEvent;
243  }
244 
245  return event;
246 }
247 
258 AliVEvent * AliEmcalContainerUtils::GetEvent(AliVEvent * inputEvent, bool isEmbedding)
259 {
260  return const_cast<AliVEvent *>(GetEvent(const_cast<const AliVEvent *>(inputEvent), isEmbedding));
261 }
262 
static const AliVEvent * GetEvent(const AliVEvent *inputEvent, bool isEmbedding=false)
Declaration of class AliAnalysisTaskEmcalEmbeddingHelper.
AliVEvent * GetExternalEvent() const
Retrieve the embedded event from the embedding helper.
static UInt_t DeterminePhysicsSelectionFromYAML(const std::vector< std::string > &selections)
InputObject_t
Type of input object to be created
unsigned int UInt_t
Definition: External.C:33
Implementation of task to embed external events.
static const std::map< std::string, AliVEvent::EOfflineTriggerTypes > fgkPhysicsSelectionMap
Relates string to the physics selection enumeration for YAML configuration.
static std::string DetermineUseDefaultName(InputObject_t objType)
static const AliAnalysisTaskEmcalEmbeddingHelper * GetInstance()