]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisTask.cxx
Added an experimental class for single-track monitors.
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisTask.cxx
1 #include <TEntryList.h>
2
3 #include "AliLog.h"
4 #include "AliAnalysisManager.h"
5 #include "AliMultiInputEventHandler.h"
6 #include "AliMixInputEventHandler.h"
7 #include "AliMCEventHandler.h"
8
9 #include "AliRsnEvent.h"
10 #include "AliRsnLoop.h"
11 #include "AliRsnInputHandler.h"
12
13 #include "AliRsnAnalysisTask.h"
14
15 ClassImp(AliRsnAnalysisTask)
16
17 //__________________________________________________________________________________________________
18 AliRsnAnalysisTask::AliRsnAnalysisTask() :
19    AliAnalysisTaskSE(),
20    fOutput(0),
21    fRsnObjects(0),
22    fInputEHMain(0),
23    fInputEHMix(0)
24 {
25 //
26 // Dummy constructor ALWAYS needed for I/O.
27 //
28 }
29
30 //__________________________________________________________________________________________________
31 AliRsnAnalysisTask::AliRsnAnalysisTask(const char *name) :
32    AliAnalysisTaskSE(name),
33    fOutput(0),
34    fRsnObjects(0),
35    fInputEHMain(0),
36    fInputEHMix(0)
37 {
38 //
39 // Default constructor.
40 // Define input and output slots here (never in the dummy constructor)
41 // Input slot #0 works with a TChain - it is connected to the default input container
42 // Output slot #1 writes into a TH1 container
43 //
44
45    DefineOutput(1, TList::Class());
46 }
47
48 //__________________________________________________________________________________________________
49 AliRsnAnalysisTask::AliRsnAnalysisTask(const AliRsnAnalysisTask& copy) :
50    AliAnalysisTaskSE(copy),
51    fOutput(0),
52    fRsnObjects(copy.fRsnObjects),
53    fInputEHMain(copy.fInputEHMain),
54    fInputEHMix(copy.fInputEHMix)
55 {
56 //
57 // Copy constructor.
58 // Implemented as requested by C++ standards.
59 // Can be used in PROOF and by plugins.
60 //
61 }
62
63 //__________________________________________________________________________________________________
64 AliRsnAnalysisTask& AliRsnAnalysisTask::operator=(const AliRsnAnalysisTask& copy)
65 {
66 //
67 // Assignment operator.
68 // Implemented as requested by C++ standards.
69 // Can be used in PROOF and by plugins.
70 //
71    AliAnalysisTaskSE::operator=(copy);
72    fRsnObjects = copy.fRsnObjects;
73    fInputEHMain = copy.fInputEHMain;
74    fInputEHMix = copy.fInputEHMix;
75    
76    return (*this);
77 }
78
79 //__________________________________________________________________________________________________
80 AliRsnAnalysisTask::~AliRsnAnalysisTask()
81 {
82 //
83 // Destructor. 
84 // Clean-up the output list, but not the histograms that are put inside
85 // (the list is owner and will clean-up these histograms). Protect in PROOF case.
86 //
87
88    if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
89       delete fOutput;
90    }
91 }
92
93 //__________________________________________________________________________________________________
94 void AliRsnAnalysisTask::AddLoop(AliRsnLoop *obj)
95 {
96 //
97 // Add new computation object
98 //
99
100    fRsnObjects.Add(obj);
101 }
102
103 //__________________________________________________________________________________________________
104 void AliRsnAnalysisTask::UserCreateOutputObjects()
105 {
106 //
107 // Initialization of outputs.
108 // This is called once per worker node.
109 //
110
111    // sets all Inuput Handler pointers
112    InitInputHandlers();
113
114    // create list and set it as owner of its content (MANDATORY)
115    fOutput = new TList();
116    fOutput->SetOwner();
117    
118    // loop on computators and initialize all their outputs
119    TObjArrayIter next(&fRsnObjects);
120    AliRsnLoop *obj = 0x0;
121    while ( (obj = (AliRsnLoop*)next()) ) {
122       obj->Init(GetName(), fOutput);
123    }
124
125    // post data for ALL output slots >0 here, to get at least an empty histogram
126    PostData(1, fOutput);
127 }
128
129 //__________________________________________________________________________________________________
130 void AliRsnAnalysisTask::UserExec(Option_t *)
131 {
132 //
133 // Main loop for single-event computations.
134 // It is called for each event and executes the 'DoLoop'
135 // function of all AliRsnLoop instances stored here.
136 //
137
138    AliRsnEvent *evMain = 0x0;
139    AliRsnInputHandler *rsnIH = 0x0;
140
141    if (fInputEHMain) {
142       TObjArrayIter next(fInputEHMain->InputEventHandlers());
143       TObject *obj = 0x0;
144       while ( (obj = next()) ) {
145          if (obj->IsA() == AliRsnInputHandler::Class()) {
146             rsnIH = (AliRsnInputHandler*)obj;
147             //AliInfo(Form("Found object '%s' which is RSN input handler", obj->GetName()));
148             evMain = rsnIH->GetRsnEvent();
149             break;
150          }
151       }
152    }
153    
154    if (!evMain) return;
155
156    TObjArrayIter next(&fRsnObjects);
157    AliRsnLoop *obj = 0x0;
158    while ( (obj = (AliRsnLoop*)next()) ) {
159       if (obj->IsMixed()) continue;
160       obj->DoLoop(evMain, rsnIH->GetSelector());
161    }
162    
163    PostData(1, fOutput);
164 }
165
166 //__________________________________________________________________________________________________
167 void AliRsnAnalysisTask::UserExecMix(Option_t*)
168 {
169 //
170 // Main loop for event-mixing computations
171 // It is called for each pair of matched events
172 // and executes the 'DoLoop' function of all AliRsnLoop instances stored here.
173 //
174
175    AliRsnEvent *evMain = 0x0;
176    AliRsnEvent *evMix  = 0x0;
177    Int_t        id     = -1;
178    AliRsnInputHandler *rsnIH = 0x0, *rsnMixIH = 0x0;
179
180    if (fInputEHMain) {
181       TObjArrayIter next(fInputEHMain->InputEventHandlers());
182       TObject *obj = 0x0;
183       while ( (obj = next()) ) {
184          if (obj->IsA() == AliRsnInputHandler::Class()) {
185             rsnIH = (AliRsnInputHandler*)obj;
186             //AliInfo(Form("Found object '%s' which is RSN input handler", obj->GetName()));
187             evMain = rsnIH->GetRsnEvent();
188             id = fInputEHMain->InputEventHandlers()->IndexOf(obj);
189             break;
190          }
191       }
192    }
193    
194    if (!evMain) return;
195
196    // gets first input handler form mixing buffer
197    AliMultiInputEventHandler *ihMultiMix = dynamic_cast<AliMultiInputEventHandler*>(fInputEHMix->InputEventHandler(0));
198    if (ihMultiMix) {
199       rsnMixIH = dynamic_cast<AliRsnInputHandler*>(ihMultiMix->InputEventHandler(id));
200       if (rsnMixIH) {
201          evMix = rsnMixIH->GetRsnEvent();
202          if (!evMix) return;
203
204          TObjArrayIter next(&fRsnObjects);
205          AliRsnLoop *obj = 0x0;
206          while ( (obj = (AliRsnLoop*)next()) ) {
207             if (!obj->IsMixed()) continue;
208             obj->DoLoop(evMain, rsnIH->GetSelector(), evMix, rsnMixIH->GetSelector());
209          }
210       }
211    }
212    
213    PostData(1, fOutput);
214 }
215
216 //________________________________________________________________________
217 void AliRsnAnalysisTask::Terminate(Option_t *)
218 {
219 //
220 // Draw result to screen, or perform fitting, normalizations
221 // Called once at the end of the query
222 //
223
224    fOutput = dynamic_cast<TList*>(GetOutputData(1));
225    if (!fOutput) { AliError("Could not retrieve TList fOutput"); return; }
226 }
227
228 //_____________________________________________________________________________
229 void AliRsnAnalysisTask::InitInputHandlers()
230 {
231 //
232 // Sets needed input handlers
233 //
234    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
235    fInputEHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
236    if (fInputEHMain) {
237       fInputEHMix = dynamic_cast<AliMixInputEventHandler *>(fInputEHMain->GetFirstMultiInputHandler());
238    }
239 }