AliPhysics  ff07904 (ff07904)
AliEmcalCorrectionCellCombineCollections.cxx
Go to the documentation of this file.
1 // AliEmcalCorrectionCellCombineCollections
2 //
3 
4 #include <sstream>
5 
6 #include <AliAODEvent.h>
7 #include <AliVCaloCells.h>
8 #include <AliAODCaloCells.h>
9 #include <AliESDCaloCells.h>
10 
12 #include "AliEmcalContainerUtils.h"
13 
15 
19 
20 // Actually registers the class with the base class
22 
27  AliEmcalCorrectionComponent("AliEmcalCorrectionCellCombineCollections"),
28  fExternalCellsBranchName("emcalCells"),
29  fCreatedCellsBranchName("emcalCellsCombined"),
30  fVerifyCombinedCells(true),
31  fInitializedCombinedCells(false),
32  fCombinedCells(0)
33 {
34  // Default constructor
35  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
36 }
37 
42 {
43  // Destructor
44 }
45 
56 {
57  // Initialization
58  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
60 
61  GetProperty("externalCellsBranchName", fExternalCellsBranchName);
62  GetProperty("combinedCellsBranchName", fCreatedCellsBranchName);
63  GetProperty("verifyCombinedCells", fVerifyCombinedCells);
64 
65  // Check for "usedefault"
66  if (fExternalCellsBranchName == "usedefault") {
68  }
69 
70  // NOTE: "usedefault" doesn't make sense for the combined cell branch name. The name needs to be distinct!
71  // Thus, we only do it for fExternalCellsBranchName.
72 
73  return kTRUE;
74 }
75 
80 {
81  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
83 }
84 
91 {
93 }
94 
104 {
105  if (fEsdMode) {
106  fCombinedCells = new AliESDCaloCells(fCreatedCellsBranchName.c_str(), fCreatedCellsBranchName.c_str(), AliVCaloCells::kEMCALCell);
107  }
108  else {
109  fCombinedCells = new AliAODCaloCells(fCreatedCellsBranchName.c_str(), fCreatedCellsBranchName.c_str(), AliVCaloCells::kEMCALCell);
110  }
111 
112  // Add it to the input event
113  // While the CorrectionTask can handle cells in the external event, it is not well handled by
114  // other classes, so it should stay in the input event to ensure it is easily available.
116 
117  AliDebugStream(2) << "Added combined calo cells \"" << fCombinedCells->GetName() << "\" with " << fCombinedCells->GetNumberOfCells() << " cells to the input event" << std::endl;
118 
120 }
121 
127 {
128  // Run
129  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
131 
133 
134  return kTRUE;
135 }
136 
143 {
144  // Create cells.
145  // In general, the memory allocation process for cells is not very efficient...
146  if (fInitializedCombinedCells == false) {
148  }
149 
150  // Get the external event
152  if (!embedding) {
153  AliFatal("Could not retrieve external event!");
154  }
155 
156  // Get the cells to copy
157  AliVCaloCells * externalCells = dynamic_cast<AliVCaloCells *>(embedding->GetExternalEvent()->FindListObject(fExternalCellsBranchName.c_str()));
158  if (!externalCells) {
159  AliFatal(TString::Format("Could not retrieve cells \"%s\" from external event!", fExternalCellsBranchName.c_str()));
160  }
161 
162  // Delete any previous container
163  fCombinedCells->DeleteContainer();
164  // Create a new container
165  fCombinedCells->CreateContainer(fCaloCells->GetNumberOfCells() + externalCells->GetNumberOfCells());
166  // Add internal and external cells to the combined cells
168  AddCellsToCombinedCellObject(externalCells, fCaloCells->GetNumberOfCells());
169 
170  if (fVerifyCombinedCells) {
171  VerifyCombinedCells({fCaloCells, externalCells});
172  }
173 }
174 
182 void AliEmcalCorrectionCellCombineCollections::AddCellsToCombinedCellObject(AliVCaloCells * inputCells, int indexOffset)
183 {
184  // Cell properties
185  Short_t cellNumber;
186  Double_t amplitude, time, eFrac;
187  Int_t mcLabel;
188  Bool_t cellHighGain;
189  Bool_t getCellResult = kFALSE;
190 
191  AliDebugStream(3) << "Adding caloCells \"" << inputCells->GetName() << "\" of type \"" << inputCells->GetType() << "\" with " << inputCells->GetNumberOfCells() << " cells to the combined cells" << std::endl;
192 
193  // Loop over the input cells and add them to the combined cells
194  for (unsigned int i = 0; i < static_cast<unsigned int>(inputCells->GetNumberOfCells()); i++)
195  {
196  getCellResult = inputCells->GetCell(i, cellNumber, amplitude, time, mcLabel, eFrac);
197  if (!getCellResult) {
198  AliWarning(TString::Format("Could not get cell %i from cell collection %s", i, inputCells->GetName()));
199  }
200  // Get high gain attribute in addition to cell
201  // NOTE: GetCellHighGain() uses the cell position, not cell index, and thus should _NOT_ be used!
202  cellHighGain = inputCells->GetHighGain(i);
203 
204  // Set the properties in the combined cell
205  fCombinedCells->SetCell(i + indexOffset, cellNumber, amplitude, time, mcLabel, eFrac, cellHighGain);
206  }
207 }
208 
216 void AliEmcalCorrectionCellCombineCollections::VerifyCombinedCells(std::vector <AliVCaloCells *> inputCaloCells)
217 {
218  // Input cell arrays properties
219  Short_t cellNumber;
220  Double_t amplitude, time, eFrac;
221  Int_t mcLabel;
222  Bool_t cellHighGain;
223  Bool_t getCellResult = kFALSE;
224  // Combined cell array properties
225  Short_t cellNumberCombined;
226  Double_t amplitudeCombined, timeCombined, eFracCombined;
227  Int_t mcLabelCombined;
228  Bool_t cellHighGainCombined;
229  Bool_t getCellResultCombined = kFALSE;
230 
231  unsigned int combinedCellsIndex = 0;
232  for (auto caloCells : inputCaloCells)
233  {
234  AliDebugStream(2) << "Verifying cells from cell collection " << caloCells->GetName() << "\n";
235  for (unsigned int i = 0; i < static_cast<unsigned int>(caloCells->GetNumberOfCells()); i++)
236  {
237  // Get input calo cell
238  getCellResult = caloCells->GetCell(i, cellNumber, amplitude, time, mcLabel, eFrac);
239  if (!getCellResult) {
240  AliWarning(TString::Format("Could not get cell %i from cell collection %s", i, caloCells->GetName()));
241  }
242  // Get high gain attribute in addition to cell
243  cellHighGain = caloCells->GetHighGain(i);
244  // Get combined calo cell
245  getCellResultCombined = fCombinedCells->GetCell(combinedCellsIndex, cellNumberCombined, amplitudeCombined, timeCombined, mcLabelCombined, eFracCombined);
246  if (!getCellResultCombined) {
247  AliWarning(TString::Format("Could not get cell %i from combined cell collection %s", combinedCellsIndex, fCombinedCells->GetName()));
248  }
249  // Get high gain attribute in addition to cell
250  cellHighGainCombined = fCombinedCells->GetHighGain(combinedCellsIndex);
251 
252  if (cellNumberCombined != cellNumber ||
253  amplitudeCombined != amplitude ||
254  timeCombined != time ||
255  mcLabelCombined != mcLabel ||
256  eFracCombined != eFrac ||
257  cellHighGainCombined != cellHighGain)
258  {
259  std::stringstream errorMessage;
260  errorMessage << std::boolalpha;
261  errorMessage << "Cell mistmatch at index " << i << " of cell collection " << caloCells->GetName() << ", combined cells " << combinedCellsIndex << " of combined cell collection " << fCombinedCells->GetName() << "\n";
262  errorMessage << "Input cell: cell number: " << cellNumber << ", amplitude: " << amplitude << ", time: " << time << ", mcLabel: " << mcLabel << ", eFrac: " << eFrac << ", cellHighGain: " << cellHighGain << "\n";
263  errorMessage << "Combined cell: cell number: " << cellNumberCombined << ", amplitude: " << amplitudeCombined << ", time: " << timeCombined << ", mcLabel: " << mcLabelCombined << ", eFrac: " << eFracCombined << ", cellHighGain: " << cellHighGainCombined << "\n";
264  AliFatal(errorMessage.str().c_str());
265  }
266 
267  combinedCellsIndex++;
268  }
269  }
270 
271  AliDebugStream(1) << "Input cells were successfully combined into the combined cells.\n";
272 }
273 
281 {
282  if (!(event->FindListObject(obj->GetName()))) {
283  event->AddObject(obj);
284  }
285  else {
286  if (!attempt) {
287  AliFatal(Form("Container with name %s already present. Aborting", obj->GetName()));
288  }
289  }
290 }
291 
double Double_t
Definition: External.C:58
static RegisterCorrectionComponent< AliEmcalCorrectionCellCombineCollections > reg
void AddCellsToCombinedCellObject(AliVCaloCells *inputCells, int indexOffset)
std::string fCreatedCellsBranchName
Name of the cell branch which will be created for the combined cells.
Declaration of class AliAnalysisTaskEmcalEmbeddingHelper.
AliVEvent * GetExternalEvent() const
Retrieve the embedded event from the embedding helper.
AliVCaloCells * fCaloCells
! Pointer to CaloCells
Combines two cell collections into one collection.
int Int_t
Definition: External.C:63
std::string fExternalCellsBranchName
Name of the cell branch which will be copied from the external event for the combined cells...
Base class for correction components in the EMCal correction framework.
Implementation of task to embed external events.
void VerifyCombinedCells(std::vector< AliVCaloCells * > inputCaloCells)
short Short_t
Definition: External.C:23
bool fVerifyCombinedCells
True if the task should confirm that the combined cells properly copied the input cells...
void AddObjectToEvent(TObject *obj, AliVEvent *event, Bool_t attempt=kFALSE)
AliEmcalCorrectionEventManager fEventManager
Minimal task which inherits from AliAnalysisTaskSE and manages access to the event.
bool fInitializedCombinedCells
! True if the combined cells object has been initialized
static std::string DetermineUseDefaultName(InputObject_t objType)
bool Bool_t
Definition: External.C:53
AliVCaloCells * fCombinedCells
! Cells combined from the input and external events.
bool GetProperty(std::string propertyName, T &property, bool requiredProperty=true, std::string correctionName="")
Retrieve property.
static const AliAnalysisTaskEmcalEmbeddingHelper * GetInstance()