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() :
27 // Dummy constructor ALWAYS needed for I/O.
31 //__________________________________________________________________________________________________
32 AliRsnAnalysisTask::AliRsnAnalysisTask(const char *name) :
33 AliAnalysisTaskSE(name),
41 // Default constructor.
42 // Define input and output slots here (never in the dummy constructor)
43 // Input slot #0 works with a TChain - it is connected to the default input container
44 // Output slot #1 writes into a TH1 container
47 DefineOutput(1, TList::Class());
50 //__________________________________________________________________________________________________
51 AliRsnAnalysisTask::AliRsnAnalysisTask(const AliRsnAnalysisTask& copy) :
52 AliAnalysisTaskSE(copy),
54 fRsnObjects(copy.fRsnObjects),
55 fInputEHMain(copy.fInputEHMain),
56 fInputEHMix(copy.fInputEHMix),
57 fBigOutput(copy.fBigOutput)
61 // Implemented as requested by C++ standards.
62 // Can be used in PROOF and by plugins.
66 //__________________________________________________________________________________________________
67 AliRsnAnalysisTask& AliRsnAnalysisTask::operator=(const AliRsnAnalysisTask& copy)
70 // Assignment operator.
71 // Implemented as requested by C++ standards.
72 // Can be used in PROOF and by plugins.
74 AliAnalysisTaskSE::operator=(copy);
75 fRsnObjects = copy.fRsnObjects;
76 fInputEHMain = copy.fInputEHMain;
77 fInputEHMix = copy.fInputEHMix;
78 fBigOutput = copy.fBigOutput;
83 //__________________________________________________________________________________________________
84 AliRsnAnalysisTask::~AliRsnAnalysisTask()
88 // Clean-up the output list, but not the histograms that are put inside
89 // (the list is owner and will clean-up these histograms). Protect in PROOF case.
92 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
97 //__________________________________________________________________________________________________
98 void AliRsnAnalysisTask::AddLoop(AliRsnLoop *obj)
101 // Add new computation object
104 fRsnObjects.Add(obj);
107 //__________________________________________________________________________________________________
108 void AliRsnAnalysisTask::UserCreateOutputObjects()
111 // Initialization of outputs.
112 // This is called once per worker node.
115 // sets all Inuput Handler pointers
118 // create list and set it as owner of its content (MANDATORY)
119 if (fBigOutput) OpenFile(1);
120 fOutput = new TList();
123 // loop on computators and initialize all their outputs
124 TObjArrayIter next(&fRsnObjects);
125 AliRsnLoop *obj = 0x0;
126 while ( (obj = (AliRsnLoop*)next()) ) {
127 obj->Init(GetName(), fOutput);
130 // post data for ALL output slots >0 here, to get at least an empty histogram
131 PostData(1, fOutput);
134 //__________________________________________________________________________________________________
135 void AliRsnAnalysisTask::UserExec(Option_t *)
138 // Main loop for single-event computations.
139 // It is called for each event and executes the 'DoLoop'
140 // function of all AliRsnLoop instances stored here.
143 AliRsnEvent *evMain = 0x0;
144 AliRsnInputHandler *rsnIH = 0x0;
147 TObjArrayIter next(fInputEHMain->InputEventHandlers());
149 while ( (obj = next()) ) {
150 if (obj->IsA() == AliRsnInputHandler::Class()) {
151 rsnIH = (AliRsnInputHandler*)obj;
152 //AliInfo(Form("Found object '%s' which is RSN input handler", obj->GetName()));
153 evMain = rsnIH->GetRsnEvent();
161 TObjArrayIter next(&fRsnObjects);
162 AliRsnLoop *obj = 0x0;
163 while ( (obj = (AliRsnLoop*)next()) ) {
164 if (obj->IsMixed()) continue;
165 obj->DoLoop(evMain, rsnIH->GetSelector());
168 PostData(1, fOutput);
171 //__________________________________________________________________________________________________
172 void AliRsnAnalysisTask::UserExecMix(Option_t*)
175 // Main loop for event-mixing computations
176 // It is called for each pair of matched events
177 // and executes the 'DoLoop' function of all AliRsnLoop instances stored here.
180 AliRsnEvent *evMain = 0x0;
181 AliRsnEvent *evMix = 0x0;
183 AliRsnInputHandler *rsnIH = 0x0, *rsnMixIH = 0x0;
186 TObjArrayIter next(fInputEHMain->InputEventHandlers());
188 while ( (obj = next()) ) {
189 if (obj->IsA() == AliRsnInputHandler::Class()) {
190 rsnIH = (AliRsnInputHandler*)obj;
191 //AliInfo(Form("Found object '%s' which is RSN input handler", obj->GetName()));
192 evMain = rsnIH->GetRsnEvent();
193 id = fInputEHMain->InputEventHandlers()->IndexOf(obj);
201 // gets first input handler form mixing buffer
202 AliMultiInputEventHandler *ihMultiMix = dynamic_cast<AliMultiInputEventHandler*>(fInputEHMix->InputEventHandler(0));
204 rsnMixIH = dynamic_cast<AliRsnInputHandler*>(ihMultiMix->InputEventHandler(id));
206 evMix = rsnMixIH->GetRsnEvent();
209 TObjArrayIter next(&fRsnObjects);
210 AliRsnLoop *obj = 0x0;
211 while ( (obj = (AliRsnLoop*)next()) ) {
212 if (!obj->IsMixed()) continue;
213 obj->DoLoop(evMain, rsnIH->GetSelector(), evMix, rsnMixIH->GetSelector());
218 PostData(1, fOutput);
221 //________________________________________________________________________
222 void AliRsnAnalysisTask::Terminate(Option_t *)
225 // Draw result to screen, or perform fitting, normalizations
226 // Called once at the end of the query
229 fOutput = dynamic_cast<TList*>(GetOutputData(1));
230 if (!fOutput) { AliError("Could not retrieve TList fOutput"); return; }
233 //_____________________________________________________________________________
234 void AliRsnAnalysisTask::InitInputHandlers()
237 // Sets needed input handlers
239 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
240 fInputEHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
242 fInputEHMix = dynamic_cast<AliMixInputEventHandler *>(fInputEHMain->GetFirstMultiInputHandler());