]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWGGA/PHOSTasks/ClusterSelection/AliPHOSClusterSelectionLogbackTask.cxx
Merge branch 'feature-movesplit'
[u/mrichter/AliRoot.git] / PWGGA / PHOSTasks / ClusterSelection / AliPHOSClusterSelectionLogbackTask.cxx
CommitLineData
50aff95d 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 "TObjArray.h"
e8bd1c25 18#include "TObject.h"
19#include "TMap.h"
50aff95d 20
21#include "AliVCluster.h"
e8bd1c25 22#include "AliPHOSGeometry.h"
23
24#include "AliPHOSClusterSelection.h"
25#include "AliPHOSEventSelection.h"
26#include "AliPHOSLogbackCluster.h"
50aff95d 27
28// Analysis task to fill histograms with PHOS ESD or AOD clusters and cells
29// Authors : Henrik Qvigstad
30// Date : 28.05.2011
31/* $Id$ */
32
33#include "AliPHOSClusterSelectionLogbackTask.h"
34ClassImp(AliPHOSClusterSelectionLogbackTask);
35
36
e8bd1c25 37AliPHOSClusterSelectionLogbackTask::AliPHOSClusterSelectionLogbackTask(const char* name)
50aff95d 38 : AliPHOSClusterSelectionTask(name),
7178af80 39 fMapOfEventLists(0x0)
50aff95d 40{
7178af80 41 fMapOfEventLists = new TMap;
42 fMapOfEventLists->SetOwnerValue();
50aff95d 43}
44
45AliPHOSClusterSelectionLogbackTask::~AliPHOSClusterSelectionLogbackTask()
46{
e8bd1c25 47 delete fMapOfEventLists;
50aff95d 48}
49
50void AliPHOSClusterSelectionLogbackTask::UserCreateOutputObjects()
51{
52 return;
53}
7178af80 54
50aff95d 55void AliPHOSClusterSelectionLogbackTask::UserExec(Option_t *option)
56{
57 AliPHOSClusterSelectionTask::UserExec(option);
50aff95d 58
7178af80 59 // initialize fMapOfEventLists
60 if( !fMapOfEventLists ) {
61 fMapOfEventLists = new TMap;
62 fMapOfEventLists->SetOwnerValue();
50aff95d 63 }
64}
65
7178af80 66TObjArray* AliPHOSClusterSelectionLogbackTask::GetPHOSClustersLogback(const AliPHOSEventSelection* eventSelection, UInt_t eventLogbackIndex, const AliPHOSClusterSelection* clusterSelection) const
50aff95d 67{
68 // Gives an array of clusters for an given event and cluster selection,
69 // provided that such an selection has been logged.
7178af80 70 // eventLogbackIndex - How many logged events to go back in time, must be an positive integer 0,1,2...
71 // , an clusterSelection is optional.
72
73 TObject* objEventList = fMapOfEventLists->GetValue(eventSelection);
74 TList* eventList = dynamic_cast<TList*> ( objEventList );
75 if(!eventList)
76 return 0x0;
50aff95d 77
7178af80 78 // eventList is a list of eventArray
79 TObject* objEventArray = eventList->At(eventLogbackIndex);
80 TObjArray* eventArray = dynamic_cast<TObjArray*> ( objEventArray );
81 if( !eventArray )
82 return 0x0;
83
84 // fMapOfEventLists[eventSelection][eventLogbackIndex][0]
85 TObject* objEventClusters = eventArray->At(kCluArray);
86 TObjArray* eventClusters = dynamic_cast<TObjArray*> ( objEventClusters );
87 if( !eventClusters )
88 AliFatal(Form("eventArray should always contain and TObjArray in index %i", kCluArray));
89
90 // fMapOfEventLists[eventSelection][eventLogbackIndex][1]
91 TObject* objSelectionMap = eventArray->At(kSelMap);
92 TMap* selectionMap = dynamic_cast<TMap*> ( objSelectionMap );
93 if( !selectionMap )
e8bd1c25 94 AliFatal(Form("eventArray should always contain and TMap in index %i", kSelMap));
7178af80 95
96
97 // For the given eventSelection and eventBacklog, we should now have
98 // eventClusters and selectionMap !!!
99 // which TObjArray we return to the user depends on if an clusterSelection is specified
100 if(clusterSelection) {
101 TObject* objSelectionArray = selectionMap->GetValue(clusterSelection);
102 TObjArray* selectionArray = dynamic_cast<TObjArray*> ( objSelectionArray );
103 return selectionArray;
104 }
105 else
106 return eventClusters;
50aff95d 107}
108
109
e8bd1c25 110void AliPHOSClusterSelectionLogbackTask::LogEvent(const AliPHOSEventSelection* eventSelection, UInt_t nEventsToLog)
50aff95d 111{
7178af80 112 if( nEventsToLog < 1) {
113 AliError("nEventsToLog needs to be >0, or logging does not make sense");
114 return;
50aff95d 115 }
116
7178af80 117 // Make a copy of the cluster array
118 TObjArray* newCluArray = new TObjArray(fClusters->GetEntriesFast());
119 newCluArray->SetOwner();
e8bd1c25 120 for(int iclu=0; iclu < fClusters->GetSize(); ++iclu) {
121 AliPHOSLogbackCluster* clu = new AliPHOSLogbackCluster((AliVCluster*)fClusters->At(iclu));
7178af80 122 newCluArray->Add(clu);
50aff95d 123 }
7178af80 124
125 // Make a copy of the selection map
126 // and referance to the new array of clusters
127 TMap* newMap = new TMap;
128 newMap->SetOwnerValue();
129 TMapIter* iter = (TMapIter*) fSelectionMap->MakeIterator();
e8bd1c25 130 TObject* key = 0x0;
131 while((key = iter->Next())){ // Loop over Cluster Selections
7178af80 132 TRefArray* oldSelArray = dynamic_cast<TRefArray*> (fSelectionMap->GetValue(key));
133 TObjArray* newSelArray = new TObjArray(oldSelArray->GetEntriesFast());
134 newSelArray->SetOwner(false);
135 // Referance the new selection array to the new clusters
136 for(int selInd=0; selInd<oldSelArray->GetEntriesFast(); ++selInd){
137 bool matched = false; // false untill mached
138 for(int cluInd=0; cluInd<fClusters->GetEntriesFast(); ++cluInd){
139 TObject* oldSelCluster = oldSelArray->At(selInd);
140 TObject* oldCluster = fClusters->At(cluInd);
141 if(oldSelCluster == oldCluster) { // if old selection matches old cluster,
142 // then new selection should match cluster in the same index as old cluster
143 // at the same old selection index
144 if( newSelArray->At(cluInd) )
145 AliError("should be empty!");
e8bd1c25 146 newSelArray->AddAt(newCluArray->At(cluInd), selInd);
7178af80 147
148 matched = true;
149 break;
150 }
151 }
152 if( ! matched )
153 AliError("Should have found a match!");
154 }
155
156 if( newSelArray->GetEntriesFast() != newSelArray->GetEntries()
157 || newSelArray->GetEntriesFast() != oldSelArray->GetEntriesFast() )
158 AliError("Entries should match!");
159
160 newMap->Add(key, newSelArray);
161 }// endo of creation of new selMap.
162
163 //make an eventArray to hold clusters and maps
164 TObjArray* eventArray = new TObjArray(kSize);
165 eventArray->SetOwner();
166 eventArray->AddAt(newCluArray, kCluArray);
167 eventArray->AddAt(newMap, kSelMap);
168
169 // at to list of events
170 TObject* objEventList = fMapOfEventLists->GetValue(eventSelection);
171 TList* eventList = dynamic_cast<TList*> ( objEventList );
172 if(!eventList) {
173 eventList = new TList;
174 eventList->SetOwner();
175 }
e8bd1c25 176 eventList->AddFirst(eventArray);
7178af80 177
178
179 // remove old events
e8bd1c25 180 while( eventList->At(nEventsToLog) && nEventsToLog )
7178af80 181 eventList->RemoveLast();
50aff95d 182}
183
184
185
186AliPHOSClusterSelectionLogbackTask* GetTask(const char* name)
187{
188 AliPHOSClusterSelectionLogbackTask* task = dynamic_cast<AliPHOSClusterSelectionLogbackTask*>( AliPHOSClusterSelectionTask::GetTask(name) );
189 if( !task )
e8bd1c25 190 Printf( Form("No AliPHOSClusterSelectionLogbackTask with name: %s", name) );
50aff95d 191
192 return task;
193}