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