1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 #include "TRefArray.h"
19 #include "AliAnalysisManager.h"
21 #include "AliVCluster.h"
22 #include "AliPHOSClusterSelection.h"
24 // Analysis task to fill histograms with PHOS ESD or AOD clusters and cells
25 // Authors : Henrik Qvigstad
29 #include "AliPHOSClusterSelectionTask.h"
30 ClassImp(AliPHOSClusterSelectionTask);
32 AliPHOSClusterSelectionTask::AliPHOSClusterSelectionTask(const char* name)
33 : AliAnalysisTaskSE(name),
40 AliPHOSClusterSelectionTask::~AliPHOSClusterSelectionTask()
45 void AliPHOSClusterSelectionTask::UserCreateOutputObjects()
50 void AliPHOSClusterSelectionTask::UserExec(Option_t *option)
52 (void)(option); // To make the compiler not give a warning.
54 AliVEvent* event = InputEvent();
58 // initilise fClusters, array of PHOS Clusters
59 if( 0x0 == fClusters ) fClusters = new TRefArray;
60 event->GetPHOSClusters( fClusters );
63 for(int index = 0; index < fClusters->GetEntriesFast(); ++index) { // TODO: check if array is indexed from 0
64 AliVCluster* cluster = (AliVCluster*) fClusters->At(index); // TODO: check that fClusters is always compressed
67 if( cluster->E() < kMinClusterEnergy // Low Energy Clusters
68 || cluster->GetDistanceToBadChannel() < kMinBCDistance // to close to Bad Channel
69 || cluster->GetNCells() < kMinNCells // to few cells
70 || cluster->GetM02() < kMinM02
72 fClusters->RemoveAt(index);
75 // Remove empty slots from array after removal of clusters
76 fClusters->Compress();
78 // initialize fSelectionMap
80 fSelectionMap->Clear();
82 fSelectionMap = new TMap;
83 fSelectionMap->SetOwnerValue();
88 TRefArray* AliPHOSClusterSelectionTask::GetPHOSClusters() const
91 AliError("fCluster not initialized, do not run this function before ::UserExec");
96 TRefArray* AliPHOSClusterSelectionTask::GetPHOSClustersSelected( AliPHOSClusterSelection* selection, bool useMap, bool addMap )
98 // useMap - Use The Resulting Array of previous selection (stored in map
99 // addMap - Add This Selection to the 'map' for use in future calls of this function.
101 if( !fClusters || !fSelectionMap )
102 AliFatal("fCluster not initialized, do not run this function before ::UserExec");
106 // Check if Selection is already done
107 TRefArray* array = dynamic_cast<TRefArray*> ( fSelectionMap->GetValue(selection) );
112 // if selected clusters not allready determined/in-map, determine and add to map:
113 TRefArray* newArray = new TRefArray( * DeterminePHOSClustersSelected(selection) );
115 fSelectionMap->Add(selection, newArray); // key, value
120 TRefArray* AliPHOSClusterSelectionTask::DeterminePHOSClustersSelected(const AliPHOSClusterSelection* selection)
122 int nClu = fClusters->GetEntriesFast();
124 // create/clear array
125 static TRefArray* statRefArr = 0x0;
129 statRefArr = new TRefArray(nClu);
130 // array should now exist and be empty,
133 // fill array with selection:
134 for(int iClu = 0; iClu < nClu; ++iClu) {
135 AliVCluster* cluster = (AliVCluster*) fClusters->At(iClu);
136 if( selection->IsSelected(cluster) )
137 statRefArr->AddLast(cluster); // add at end of array
144 AliPHOSClusterSelectionTask* AliPHOSClusterSelectionTask::GetTask(const char* name)
146 // Get AliPHOSClusterSelectionTask from AliAnalysisManager
148 AliAnalysisManager* analysisManager = dynamic_cast<AliAnalysisManager*>(AliAnalysisManager::GetAnalysisManager());
149 if( !analysisManager )
150 Printf("ERROR: No AnalysisManager");
151 AliAnalysisTask* task = analysisManager->GetTask(name);
153 Printf( Form("ERROR: No task with name: %s", name) );
155 AliPHOSClusterSelectionTask* sTask = dynamic_cast<AliPHOSClusterSelectionTask*>(task);
157 Printf( Form("ERROR:: No AliPHOSClusterSelectionTask with name: %s", name) );