]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGGA/PHOSTasks/ClusterSelection/AliPHOSClusterSelectionTask.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[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
19 #include "AliVCluster.h"
20
21 // Analysis task to fill histograms with PHOS ESD or AOD clusters and cells
22 // Authors : Henrik Qvigstad
23 // Date    : 28.05.2011
24 /* $Id$ */
25
26 #include "AliPHOSClusterSelectionTask.h"
27 ClassImp(AliPHOSClusterSelectionTask);
28
29 AliPHOSClusterSelectionTask::AliPHOSClusterSelectionTask(const char* name = "AliPHOSClusterSelectionTask")
30   : AliAnalysisTaskSE(name),
31     fClusters(0x0),
32     fSelectionMap(0x0)
33 {
34   return;
35 }
36
37 AliPHOSClusterSelectionTask::~AliPHOSClusterSelectionTask()
38 {
39   delete fClusters;
40 }
41
42 void AliPHOSClusterSelectionTask::UserCreateOutputObjects()
43 {
44   return;
45 }
46
47 void AliPHOSClusterSelectionTask::UserExec(Option_t *option)
48 {
49   AliVEvent* event = InputEvent();
50   if( ! event )
51     AliError("No Event");
52
53   // initilise fClusters, array of PHOS Clusters
54   if( 0x0 == fClusters ) fClusters = new TRefArray;
55   event->GetPHOSClusters( fClusters );
56
57   // Remove Clusters
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
60
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
65         )
66       fClusters->RemoveAt(index);
67   }
68
69   // Compact array after removel of clusters
70   fClusters->Compact();
71
72   // initialize fSelectionMap
73   if( fSelectionMap )
74     fSelectionMap->Clear();
75   else {
76     fSelectionMap = new TMap;
77     fSelectionMap->SetOwnerValue();
78   }
79 }
80
81 TRefArray* AliPHOSClusterSelectionTask::GetPHOSClusters() const
82 {
83   if( ! fClusters )
84     AliError("fCluster not initialized, do not run this function before ::UserExec");
85
86   return fClusters;
87 }
88
89 TRefArray* AliPHOSClusterSelectionTask::GetPHOSClustersSelected(const AliPHOSClusterSelection* selection, bool useMap, bool addMap )
90 {
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.
93
94   if( !fClusters  || !fSelectionMap )
95     AliFatal("fCluster not initialized, do not run this function before ::UserExec");
96
97   if( useMap ) {
98     // Check if Selection is already done
99     TRefArray* array = dynamic_selection<TRefArray*> ( fSelectionMap->GetValue(selection) );
100     if( array )
101       return array;
102   }
103
104   // if selected clusters not allready determined/in-map, determine and add to map:
105   TRefArray* newArray = new TRefArray( * DeterminePHOSClustersSelected(selection) );
106   if(addMap)
107     fSelectionMap->Add(selection, newArray); // key, value
108 }
109
110 TRefArray* AliPHOSClusterSelectionTask::DeterminePHOSClustersSelected(const AliPHOSClusterSelection* selection)
111 {
112   int nClu = fClusters->GetEntriesFast();
113
114   // create/clear array
115   static TRefArray* statRefArr = 0x0;
116   if( statRefArr )
117     statRefArr->Clear();
118   else
119     statRefArr = new TRefArray(nClu);
120   // array should now exist and be empty,
121
122
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
128   }
129
130   return statRefArr;
131 }
132
133
134 AliPHOSClusterSelectionTask* AliPHOSClusterSelectionTask::GetTask(const char* name)
135 {
136   // Get AliPHOSClusterSelectionTask from AliAnalysisManager
137
138   AliAnalysisManager* analysisManager = dynamic_cast<AliAnalysisManager*>(AliAnalysisManager::GetAnalysisManager());
139   if( !analysisManager )
140     AliError("No AnalysisManager");
141   AliAnalysisTask* task = analysisManager->GetTask(name);
142   if( !task )
143     AliError( Form("No task with name: %s", name) );
144
145   AliPHOSClusterSelectionTask* sTask = dynamic_cast<AliAnalysisTask*>(task);
146   if( !sTask)
147     AliError( Form("No AliPHOSClusterSelectionTask with name: %s", name) );
148
149   return sTask;
150 }