AliPhysics  71e3bc7 (71e3bc7)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliEmcalCorrectionCellCombineCollections.cxx
Go to the documentation of this file.
1 // AliEmcalCorrectionCellCombineCollections
2 //
3 
4 #include <AliAODEvent.h>
5 #include <AliVCaloCells.h>
6 #include <AliAODCaloCells.h>
7 #include <AliESDCaloCells.h>
8 
10 #include "AliEmcalContainerUtils.h"
11 
13 
17 
18 // Actually registers the class with the base class
20 
25  AliEmcalCorrectionComponent("AliEmcalCorrectionCellCombineCollections"),
26  fExternalCellsBranchName("emcalCells"),
27  fCreatedCellsBranchName("emcalCellsCombined"),
28  fInitializedCombinedCells(false),
29  fCombinedCells(0)
30 {
31  // Default constructor
32  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
33 }
34 
39 {
40  // Destructor
41 }
42 
53 {
54  // Initialization
55  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
57 
58  GetProperty("externalCellsBranchName", fExternalCellsBranchName);
59  GetProperty("combinedCellsBranchName", fCreatedCellsBranchName);
60 
61  // Check for "usedefault"
62  if (fExternalCellsBranchName == "usedefault") {
64  }
65 
66  // NOTE: "usedefault" doesn't make sense for the combined cell branch name. The name needs to be distinct!
67  // Thus, we only do it for fExternalCellsBranchName.
68 
69  return kTRUE;
70 }
71 
76 {
77  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
79 }
80 
87 {
89 }
90 
100 {
101  if (fEsdMode) {
102  fCombinedCells = new AliESDCaloCells(fCreatedCellsBranchName.c_str(), fCreatedCellsBranchName.c_str(), AliVCaloCells::kEMCALCell);
103  }
104  else {
105  fCombinedCells = new AliAODCaloCells(fCreatedCellsBranchName.c_str(), fCreatedCellsBranchName.c_str(), AliVCaloCells::kEMCALCell);
106  }
107 
108  // Add it to the input event
109  // While the CorrectionTask can handle cells in the external event, it is not well handled by
110  // other classes, so it should stay in the input event to ensure it is easily available.
112 
113  AliDebugStream(2) << "Added combined calo cells \"" << fCombinedCells->GetName() << "\" with " << fCombinedCells->GetNumberOfCells() << " cells to the input event" << std::endl;
114 
116 }
117 
123 {
124  // Run
125  AliDebug(3, Form("%s", __PRETTY_FUNCTION__));
127 
129 
130  return kTRUE;
131 }
132 
139 {
140  // Create cells.
141  // In general, the memory allocation process for cells is not very efficient...
142  if (fInitializedCombinedCells == false) {
144  }
145 
146  // Get the external event
148  if (!embedding) {
149  AliFatal("Could not retrieve external event!");
150  }
151 
152  // Get the cells to copy
153  AliVCaloCells * externalCells = dynamic_cast<AliVCaloCells *>(embedding->GetExternalEvent()->FindListObject(fExternalCellsBranchName.c_str()));
154  if (!externalCells) {
155  AliFatal(TString::Format("Could not retrieve cells \"%s\" from external event!", fExternalCellsBranchName.c_str()));
156  }
157 
158  // Delete any previous container
159  fCombinedCells->DeleteContainer();
160  // Create a new container
161  fCombinedCells->CreateContainer(fCaloCells->GetNumberOfCells() + externalCells->GetNumberOfCells());
162  // Add internal and external cells to the combined cells
164  AddCellsToCombinedCellObject(externalCells);
165 }
166 
174 {
175  // Cell properties
176  Short_t cellNumber;
177  Double_t ampltidue, time, eFrac;
178  Int_t mcLabel;
179  Bool_t cellHighGain;
180  Bool_t getCellResult = kFALSE;
181 
182  AliDebugStream(3) << "Adding caloCells \"" << inputCells->GetName() << "\" with " << inputCells->GetNumberOfCells() << " cells to the combined cells" << std::endl;
183 
184  // Loop over the input cells and add them to the combined cells
185  for (unsigned int i = 0; i < inputCells->GetNumberOfCells(); i++)
186  {
187  getCellResult = inputCells->GetCell(i, cellNumber, ampltidue, time, mcLabel, eFrac);
188  if (!getCellResult) {
189  AliWarning(TString::Format("Could not get cell %i from cell collection %s", i, inputCells->GetName()));
190  }
191  // Get high gain attribute in addition to cell
192  cellHighGain = inputCells->GetCellHighGain(i);
193 
194  // Set the properties in the combined cell
195  fCombinedCells->SetCell(i, cellNumber, ampltidue, time, mcLabel, eFrac, cellHighGain);
196  }
197 }
198 
205 {
206  if (!(event->FindListObject(obj->GetName()))) {
207  event->AddObject(obj);
208  }
209  else {
210  if (!attempt) {
211  AliFatal(Form("Container with name %s already present. Aborting", obj->GetName()));
212  }
213  }
214 }
215 
double Double_t
Definition: External.C:58
static RegisterCorrectionComponent< AliEmcalCorrectionCellCombineCollections > reg
std::string fCreatedCellsBranchName
Name of the cell branch which will be created for the combined cells.
static std::string DetermineUseDefaultName(InputObject_t objType, bool esdMode, bool returnObjectType=false)
Declaration of class AliAnalysisTaskEmcalEmbeddingHelper.
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.
AliVEvent * fEvent
! Pointer to event
short Short_t
Definition: External.C:23
void AddObjectToEvent(TObject *obj, AliVEvent *event, Bool_t attempt=kFALSE)
ClassImp(AliAnalysisTaskCRC) AliAnalysisTaskCRC
bool fInitializedCombinedCells
! True if the combined cells object has been initialized
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()