1 #include <TEntryList.h>
4 #include "AliAnalysisManager.h"
5 #include "AliMultiInputEventHandler.h"
6 #include "AliMixInputEventHandler.h"
7 #include "AliMCEventHandler.h"
9 #include "AliRsnEvent.h"
10 #include "AliRsnLoop.h"
11 #include "AliRsnInputHandler.h"
13 #include "AliRsnAnalysisTask.h"
15 ClassImp(AliRsnAnalysisTask)
17 //__________________________________________________________________________________________________
18 AliRsnAnalysisTask::AliRsnAnalysisTask() :
26 // Dummy constructor ALWAYS needed for I/O.
30 //__________________________________________________________________________________________________
31 AliRsnAnalysisTask::AliRsnAnalysisTask(const char *name) :
32 AliAnalysisTaskSE(name),
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
45 DefineOutput(1, TList::Class());
48 //__________________________________________________________________________________________________
49 AliRsnAnalysisTask::AliRsnAnalysisTask(const AliRsnAnalysisTask& copy) :
50 AliAnalysisTaskSE(copy),
52 fRsnObjects(copy.fRsnObjects),
53 fInputEHMain(copy.fInputEHMain),
54 fInputEHMix(copy.fInputEHMix)
58 // Implemented as requested by C++ standards.
59 // Can be used in PROOF and by plugins.
63 //__________________________________________________________________________________________________
64 AliRsnAnalysisTask& AliRsnAnalysisTask::operator=(const AliRsnAnalysisTask& copy)
67 // Assignment operator.
68 // Implemented as requested by C++ standards.
69 // Can be used in PROOF and by plugins.
71 AliAnalysisTaskSE::operator=(copy);
72 fRsnObjects = copy.fRsnObjects;
73 fInputEHMain = copy.fInputEHMain;
74 fInputEHMix = copy.fInputEHMix;
79 //__________________________________________________________________________________________________
80 AliRsnAnalysisTask::~AliRsnAnalysisTask()
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.
88 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
93 //__________________________________________________________________________________________________
94 void AliRsnAnalysisTask::AddLoop(AliRsnLoop *obj)
97 // Add new computation object
100 fRsnObjects.Add(obj);
103 //__________________________________________________________________________________________________
104 void AliRsnAnalysisTask::UserCreateOutputObjects()
107 // Initialization of outputs.
108 // This is called once per worker node.
111 // sets all Inuput Handler pointers
114 // create list and set it as owner of its content (MANDATORY)
115 fOutput = new TList();
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);
125 // post data for ALL output slots >0 here, to get at least an empty histogram
126 PostData(1, fOutput);
129 //__________________________________________________________________________________________________
130 void AliRsnAnalysisTask::UserExec(Option_t *)
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.
138 AliRsnEvent *evMain = 0x0;
139 AliRsnInputHandler *rsnIH = 0x0;
142 TObjArrayIter next(fInputEHMain->InputEventHandlers());
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();
156 TObjArrayIter next(&fRsnObjects);
157 AliRsnLoop *obj = 0x0;
158 while ( (obj = (AliRsnLoop*)next()) ) {
159 if (obj->IsMixed()) continue;
160 obj->DoLoop(evMain, rsnIH->GetSelector());
163 PostData(1, fOutput);
166 //__________________________________________________________________________________________________
167 void AliRsnAnalysisTask::UserExecMix(Option_t*)
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.
175 AliRsnEvent *evMain = 0x0;
176 AliRsnEvent *evMix = 0x0;
178 AliRsnInputHandler *rsnIH = 0x0, *rsnMixIH = 0x0;
181 TObjArrayIter next(fInputEHMain->InputEventHandlers());
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);
196 // gets first input handler form mixing buffer
197 AliMultiInputEventHandler *ihMultiMix = dynamic_cast<AliMultiInputEventHandler*>(fInputEHMix->InputEventHandler(0));
199 rsnMixIH = dynamic_cast<AliRsnInputHandler*>(ihMultiMix->InputEventHandler(id));
201 evMix = rsnMixIH->GetRsnEvent();
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());
213 PostData(1, fOutput);
216 //________________________________________________________________________
217 void AliRsnAnalysisTask::Terminate(Option_t *)
220 // Draw result to screen, or perform fitting, normalizations
221 // Called once at the end of the query
224 fOutput = dynamic_cast<TList*>(GetOutputData(1));
225 if (!fOutput) { AliError("Could not retrieve TList fOutput"); return; }
228 //_____________________________________________________________________________
229 void AliRsnAnalysisTask::InitInputHandlers()
232 // Sets needed input handlers
234 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
235 fInputEHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
237 fInputEHMix = dynamic_cast<AliMixInputEventHandler *>(fInputEHMain->GetFirstMultiInputHandler());