]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/PHOSTasks/ClusterSelection/AliPHOSClusterSelectionTask.cxx
Merge branch 'TPCdev' of https://git.cern.ch/reps/AliRoot into TPCdev
[u/mrichter/AliRoot.git] / PWGGA / PHOSTasks / ClusterSelection / AliPHOSClusterSelectionTask.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 #include "TBits.h"
17 #include "TRefArray.h"
18 #include "TMap.h"
19 #include "AliAnalysisManager.h"
20
21 #include "AliVCluster.h"
22 #include "AliPHOSClusterSelection.h"
23
24 // Analysis task to fill histograms with PHOS ESD or AOD clusters and cells
25 // Authors : Henrik Qvigstad
26 // Date    : 28.05.2011
27 /* $Id$ */
28
29 #include "AliPHOSClusterSelectionTask.h"
30 ClassImp(AliPHOSClusterSelectionTask);
31
32 AliPHOSClusterSelectionTask::AliPHOSClusterSelectionTask(const char* name)
33   : AliAnalysisTaskSE(name),
34     fClusters(0x0),
35     fSelectionMap(0x0)
36 {
37   return;
38 }
39
40 AliPHOSClusterSelectionTask::~AliPHOSClusterSelectionTask()
41 {
42   delete fClusters;
43 }
44
45 void AliPHOSClusterSelectionTask::UserCreateOutputObjects()
46 {
47   return;
48 }
49
50 void AliPHOSClusterSelectionTask::UserExec(Option_t *option)
51 {
52   (void)(option); // To make the compiler not give a warning.
53   
54   AliVEvent* event = InputEvent();
55   if( ! event )
56     AliError("No Event");
57
58   // initilise fClusters, array of PHOS Clusters
59   if( 0x0 == fClusters ) fClusters = new TRefArray;
60   event->GetPHOSClusters( fClusters );
61
62   // Remove Clusters
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
65
66
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
71         )
72       fClusters->RemoveAt(index);
73   }
74
75   // Remove empty slots from array after removal of clusters
76   fClusters->Compress();
77
78   // initialize fSelectionMap
79   if( fSelectionMap )
80     fSelectionMap->Clear();
81   else {
82     fSelectionMap = new TMap;
83     fSelectionMap->SetOwnerValue();
84   }
85
86 }
87
88 TRefArray* AliPHOSClusterSelectionTask::GetPHOSClusters() const
89 {
90   if( ! fClusters )
91     AliError("fCluster not initialized, do not run this function before ::UserExec");
92
93   return fClusters;
94 }
95
96 TRefArray* AliPHOSClusterSelectionTask::GetPHOSClustersSelected( AliPHOSClusterSelection* selection, bool useMap, bool addMap )
97 {
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.
100
101   if( !fClusters  || !fSelectionMap )
102     AliFatal("fCluster not initialized, do not run this function before ::UserExec");
103
104
105   if( useMap ) {
106     // Check if Selection is already done
107     TRefArray* array = dynamic_cast<TRefArray*> ( fSelectionMap->GetValue(selection) );
108     if( array )
109       return array;
110   }
111
112   // if selected clusters not allready determined/in-map, determine and add to map:
113   TRefArray* newArray = new TRefArray( * DeterminePHOSClustersSelected(selection) );
114   if(addMap)
115     fSelectionMap->Add(selection, newArray); // key, value
116
117   return newArray;
118 }
119
120 TRefArray* AliPHOSClusterSelectionTask::DeterminePHOSClustersSelected(const AliPHOSClusterSelection* selection)
121 {
122   int nClu = fClusters->GetEntriesFast();
123
124   // create/clear array
125   static TRefArray* statRefArr = 0x0;
126   if( statRefArr )
127     statRefArr->Clear();
128   else
129     statRefArr = new TRefArray(nClu);
130   // array should now exist and be empty,
131
132
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
138   }
139
140   return statRefArr;
141 }
142
143
144 AliPHOSClusterSelectionTask* AliPHOSClusterSelectionTask::GetTask(const char* name)
145 {
146   // Get AliPHOSClusterSelectionTask from AliAnalysisManager
147
148   AliAnalysisManager* analysisManager = dynamic_cast<AliAnalysisManager*>(AliAnalysisManager::GetAnalysisManager());
149   if( !analysisManager )
150     Printf("ERROR: No AnalysisManager");
151   AliAnalysisTask* task = analysisManager->GetTask(name);
152   if( !task )
153     Printf( Form("ERROR: No task with name: %s", name) );
154
155   AliPHOSClusterSelectionTask* sTask = dynamic_cast<AliPHOSClusterSelectionTask*>(task);
156   if( !sTask)
157     Printf( Form("ERROR:: No AliPHOSClusterSelectionTask with name: %s", name) );
158
159   return sTask;
160 }