7 #include <TClonesArray.h> 10 #include "AliAnalysisManager.h" 11 #include "AliVEventHandler.h" 12 #include "AliVCaloCells.h" 13 #include "AliESDCaloCells.h" 14 #include "AliAODCaloCells.h" 15 #include "AliAODCaloCluster.h" 16 #include "AliESDCaloCluster.h" 17 #include "AliAODTrack.h" 18 #include "AliESDtrack.h" 27 fCollectionToCopyName(
""),
28 fNewCollectionName(
""),
30 fEventInitialized(false),
56 AliVEventHandler *evhand = mgr->GetInputEventHandler();
58 if (evhand->InheritsFrom(
"AliESDInputHandler")) {
66 AliError(
"Event handler not found!");
70 AliError(
"Analysis manager not found!");
100 AliError(
"Could not retrieve event! Returning!");
106 AliFatal(
"Collection to copy name is empty! Please set a valid name!");
110 AliFatal(
"New collection name is empty! Please set a valid name!");
125 AliFatal(TString::Format(
"Unrecognized input object type %d",
fInputObjectType));
145 if (existingObject) {
146 AliFatal(TString::Format(
"Attempted to create a new %d branch, \"%s\", with the same name as an existing branch! Check your configuration! Perhaps \"usedefault\" was used incorrectly?",
fInputObjectType,
fNewCollectionName.c_str()));
154 AliVCaloCells * newCells = 0;
163 fEvent->AddObject(newCells);
173 TClonesArray * newArray =
new TClonesArray(newObjectTypeName.c_str());
175 fEvent->AddObject(newArray);
179 AliFatal(TString::Format(
"Unrecognized input object type %d",
fInputObjectType));
196 AliDebug(3, Form(
"Number of old cells: %d", cellsToCopy->GetNumberOfCells()));
198 cellsToCopy->Copy(*newCells);
203 AliDebug(3, Form(
"Number of old cells: %d \tNumber of new cells: %d", cellsToCopy->GetNumberOfCells(), newCells->GetNumberOfCells() ));
204 if (cellsToCopy->GetNumberOfCells() != newCells->GetNumberOfCells()) {
205 AliFatal(Form(
"Number of old cell: %d != number of new cells %d", cellsToCopy->GetNumberOfCells(), newCells->GetNumberOfCells()));
212 TClonesArray * newClusters =
dynamic_cast<TClonesArray *
>(InputEvent()->FindListObject(
fNewCollectionName.c_str()));
213 TClonesArray * currentClusters =
dynamic_cast<TClonesArray *
>(InputEvent()->FindListObject(
fCollectionToCopyName.c_str()));
214 AliDebug(3, Form(
"before copy:\t currentClusters->GetEntries(): %d \t newClusters->GetEntries(): %d", currentClusters->GetEntries(), newClusters->GetEntries()));
216 AliDebug(3, Form(
"after copy:\t currentClusters->GetEntries(): %d \t newClusters->GetEntries(): %d", currentClusters->GetEntries(), newClusters->GetEntries()));
222 TClonesArray * newTracks =
dynamic_cast<TClonesArray *
>(InputEvent()->FindListObject(
fNewCollectionName.c_str()));
223 TClonesArray * currentTracks =
dynamic_cast<TClonesArray *
>(InputEvent()->FindListObject(
fCollectionToCopyName.c_str()));
224 AliDebug(3, Form(
"before copy:\t currentTracks->GetEntries(): %d \t newTracks->GetEntries(): %d", currentTracks->GetEntries(), newTracks->GetEntries()));
225 for (
Int_t i = 0; i < currentTracks->GetEntriesFast(); i++)
229 AliESDtrack *currentTrack =
dynamic_cast<AliESDtrack *
>(currentTracks->At(i));
231 AliESDtrack *newTrack =
dynamic_cast<AliESDtrack *
>(
new ((*newTracks)[i]) AliESDtrack(*currentTrack));
236 newTrack->SetUniqueID(0);
237 newTrack->ResetBit(TObject::kHasUUID);
238 newTrack->ResetBit(TObject::kIsReferenced);
242 AliAODTrack *currentTrack =
dynamic_cast<AliAODTrack *
>(currentTracks->At(i));
244 AliAODTrack *newTrack =
dynamic_cast<AliAODTrack *
>(
new ((*newTracks)[i]) AliAODTrack(*currentTrack));
249 newTrack->SetUniqueID(0);
250 newTrack->ResetBit(TObject::kHasUUID);
251 newTrack->ResetBit(TObject::kIsReferenced);
254 AliDebug(3, Form(
"after copy:\t currentTracks->GetEntries(): %d \t newTracks->GetEntries(): %d", currentTracks->GetEntries(), newTracks->GetEntries()));
266 const Int_t Ncls = orig->GetEntries();
268 for(
Int_t i=0; i < Ncls; ++i) {
269 AliVCluster *oc =
static_cast<AliVCluster*
>(orig->At(i));
278 AliVCluster *dc =
static_cast<AliVCluster*
>(dest->New(i));
280 dc->SetType(oc->GetType());
283 oc->GetPosition(pos);
284 dc->SetPosition(pos);
285 dc->SetNCells(oc->GetNCells());
286 dc->SetCellsAbsId(oc->GetCellsAbsId());
287 dc->SetCellsAmplitudeFraction(oc->GetCellsAmplitudeFraction());
288 dc->SetID(oc->GetID());
289 dc->SetDispersion(oc->GetDispersion());
290 dc->SetEmcCpvDistance(-1);
292 dc->SetTOF(oc->GetTOF());
293 dc->SetNExMax(oc->GetNExMax());
294 dc->SetM02(oc->GetM02());
295 dc->SetM20(oc->GetM20());
296 dc->SetDistanceToBadChannel(oc->GetDistanceToBadChannel());
297 dc->SetMCEnergyFraction(oc->GetMCEnergyFraction());
300 UInt_t nlabels = oc->GetNLabels();
301 Int_t *labels = oc->GetLabels();
303 if (nlabels == 0 || !labels)
306 AliESDCaloCluster *esdClus =
dynamic_cast<AliESDCaloCluster*
>(dc);
308 TArrayI parents(nlabels, labels);
309 esdClus->AddLabels(parents);
312 AliAODCaloCluster *aodClus =
dynamic_cast<AliAODCaloCluster*
>(dc);
314 aodClus->SetLabel(labels, nlabels);
320 const char * collectionToCopyName,
321 const char * newCollectionName,
330 ::Error(
"AddTaskEmcalCopyCollection",
"No analysis manager to connect to.");
336 AliVEventHandler* handler = mgr->GetInputEventHandler();
339 ::Error(
"AddTaskEmcalCopyCollection",
"This task requires an input event handler");
343 TString name =
"AliEmcalCopyCollection";
344 name += TString::Format(
"_%s_%s", collectionToCopyName, newCollectionName);
350 if (mgrTask)
return mgrTask;
355 collectionToCopyName,
363 mgr->AddTask(copyCollection);
366 AliAnalysisDataContainer* cInput = mgr->GetCommonInputContainer();
367 mgr->ConnectInput(copyCollection, 0, cInput);
369 return copyCollection;
static const AliVEvent * GetEvent(const AliVEvent *inputEvent, bool isEmbedding=false)
void UserExec(Option_t *option)
Copies cell, cluster, or track collections for use in the EMCal framework.Often, it is necessary to c...
AliVEvent * fEvent
! Points to the event to copy from and store the new bracnh in
Helper functions related to AliEmcalContainer derived objects.
bool fIsEmbedding
Denotes whether the collection is embedded (and therefore should be copied and stored in the external...
InputObject_t
Type of input object to be created
AliEmcalContainerUtils::InputObject_t fInputObjectType
Type of collection to copy.
void UserCreateOutputObjects()
void CopyClusters(TClonesArray *orig, TClonesArray *dest)
void CreateNewObjectBranch()
static AliEmcalCopyCollection * AddTaskEmcalCopyCollection(AliEmcalContainerUtils::InputObject_t inputObjectType=AliEmcalContainerUtils::kNoDefinedInputObject, const char *collectionToCopyName="", const char *newCollectionName="", bool isEmbedding=false)
bool fIsEsd
! Denotes whether the input is ESD
static std::string DetermineUseDefaultName(InputObject_t objType)
std::string fNewCollectionName
Name of the collection bracnh where it will be copied.
void CopyBranchToNewObject()
bool fEventInitialized
! Denotes whether the event is initialized
std::string fCollectionToCopyName
Name of the collection branch to copy.