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 "AliVCluster.h"
21 // Analysis task to fill histograms with PHOS ESD or AOD clusters and cells
22 // Authors : Henrik Qvigstad
26 #include "AliPHOSClusterSelectionTask.h"
27 ClassImp(AliPHOSClusterSelectionTask);
29 AliPHOSClusterSelectionTask::AliPHOSClusterSelectionTask(const char* name = "AliPHOSClusterSelectionTask")
30 : AliAnalysisTaskSE(name),
37 AliPHOSClusterSelectionTask::~AliPHOSClusterSelectionTask()
42 void AliPHOSClusterSelectionTask::UserCreateOutputObjects()
47 void AliPHOSClusterSelectionTask::UserExec(Option_t *option)
49 AliVEvent* event = InputEvent();
53 // initilise fClusters, array of PHOS Clusters
54 if( 0x0 == fClusters ) fClusters = new TRefArray;
55 event->GetPHOSClusters( fClusters );
58 for(int index = 0; index < fClusters->GetEntriesFast(); ++index) { // TODO: check if array is indexed from 0
59 AliVCluster* cluster = (AliVCluster*) fClusters->At(iClu); // TODO: check that fClusters is always compressed
61 if( cluster->E() < kMinClusterEnergy // Low Energy Clusters
62 || cluster->GetDistanceToBadChannel() < kMinBCDistance // to close to Bad Channel
63 || cluster->GetNCells() < kMinNCells // to few cells
64 || cluster->GetM02() < kMinM02
66 fClusters->RemoveAt(index);
69 // Compact array after removel of clusters
72 // initialize fSelectionMap
74 fSelectionMap->Clear();
76 fSelectionMap = new TMap;
77 fSelectionMap->SetOwnerValue();
81 TRefArray* AliPHOSClusterSelectionTask::GetPHOSClusters() const
84 AliError("fCluster not initialized, do not run this function before ::UserExec");
89 TRefArray* AliPHOSClusterSelectionTask::GetPHOSClustersSelected(const AliPHOSClusterSelection* selection, bool useMap, bool addMap )
91 // useMap - Use The Resulting Array of previous selection (stored in map
92 // addMap - Add This Selection to the 'map' for use in future calls of this function.
94 if( !fClusters || !fSelectionMap )
95 AliFatal("fCluster not initialized, do not run this function before ::UserExec");
98 // Check if Selection is already done
99 TRefArray* array = dynamic_selection<TRefArray*> ( fSelectionMap->GetValue(selection) );
104 // if selected clusters not allready determined/in-map, determine and add to map:
105 TRefArray* newArray = new TRefArray( * DeterminePHOSClustersSelected(selection) );
107 fSelectionMap->Add(selection, newArray); // key, value
110 TRefArray* AliPHOSClusterSelectionTask::DeterminePHOSClustersSelected(const AliPHOSClusterSelection* selection)
112 int nClu = fClusters->GetEntriesFast();
114 // create/clear array
115 static TRefArray* statRefArr = 0x0;
119 statRefArr = new TRefArray(nClu);
120 // array should now exist and be empty,
123 // fill array with selection:
124 for(int iClu = 0; iClu < nClu; ++iClu) {
125 AliVCluster* cluster = (AliVCluster*) fClusters->At(iClu);
126 if( selection->IsSelected(cluster) )
127 statRefArr->AddLast(cluster); // add at end of array
134 AliPHOSClusterSelectionTask* AliPHOSClusterSelectionTask::GetTask(const char* name)
136 // Get AliPHOSClusterSelectionTask from AliAnalysisManager
138 AliAnalysisManager* analysisManager = dynamic_cast<AliAnalysisManager*>(AliAnalysisManager::GetAnalysisManager());
139 if( !analysisManager )
140 AliError("No AnalysisManager");
141 AliAnalysisTask* task = analysisManager->GetTask(name);
143 AliError( Form("No task with name: %s", name) );
145 AliPHOSClusterSelectionTask* sTask = dynamic_cast<AliAnalysisTask*>(task);
147 AliError( Form("No AliPHOSClusterSelectionTask with name: %s", name) );