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 ©) :
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 ©)
70 // Assignment operator.
71 // Implemented as requested by C++ standards.
72 // Can be used in PROOF and by plugins.
74 AliAnalysisTaskSE::operator=(copy);
77 fRsnObjects = copy.fRsnObjects;
78 fInputEHMain = copy.fInputEHMain;
79 fInputEHMix = copy.fInputEHMix;
80 fBigOutput = copy.fBigOutput;
85 //__________________________________________________________________________________________________
86 AliRsnAnalysisTask::~AliRsnAnalysisTask()
90 // Clean-up the output list, but not the histograms that are put inside
91 // (the list is owner and will clean-up these histograms). Protect in PROOF case.
94 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
99 //__________________________________________________________________________________________________
100 void AliRsnAnalysisTask::AddLoop(AliRsnLoop *obj)
103 // Add new computation object
106 fRsnObjects.Add(obj);
109 //__________________________________________________________________________________________________
110 void AliRsnAnalysisTask::UserCreateOutputObjects()
113 // Initialization of outputs.
114 // This is called once per worker node.
117 // sets all Inuput Handler pointers
120 // create list and set it as owner of its content (MANDATORY)
121 if (fBigOutput) OpenFile(1);
122 fOutput = new TList();
125 // loop on computators and initialize all their outputs
126 TObjArrayIter next(&fRsnObjects);
127 AliRsnLoop *objLoop = 0x0;
128 while ( (objLoop = (AliRsnLoop *)next()) ) {
129 objLoop->Init(GetName(), fOutput);
133 TObjArrayIter nextIH(fInputEHMain->InputEventHandlers());
135 AliRsnInputHandler *rsnIH;
136 AliRsnDaughterSelector *s;
139 while ( (obj = nextIH()) ) {
140 if (obj->IsA() == AliRsnInputHandler::Class()) {
141 rsnIH = (AliRsnInputHandler *) obj;
142 s = rsnIH->GetSelector();
143 s->InitActions(fOutput);
145 for (Int_t is = 0; is < c->GetEntries(); is++) {
146 cuts = (AliRsnCutSet *)c->At(is);
154 // post data for ALL output slots >0 here, to get at least an empty histogram
155 PostData(1, fOutput);
158 //__________________________________________________________________________________________________
159 void AliRsnAnalysisTask::UserExec(Option_t *)
162 // Main loop for single-event computations.
163 // It is called for each event and executes the 'DoLoop'
164 // function of all AliRsnLoop instances stored here.
167 AliRsnEvent *evMain = 0x0;
168 AliRsnInputHandler *rsnIH = 0x0;
171 TObjArrayIter next(fInputEHMain->InputEventHandlers());
173 while ( (obj = next()) ) {
174 if (obj->IsA() == AliRsnInputHandler::Class()) {
175 rsnIH = (AliRsnInputHandler *)obj;
176 //AliInfo(Form("Found object '%s' which is RSN input handler", obj->GetName()));
177 evMain = rsnIH->GetRsnEvent();
185 TObjArrayIter next(&fRsnObjects);
186 AliRsnLoop *obj = 0x0;
187 while ( (obj = (AliRsnLoop *)next()) ) {
188 if (obj->IsMixed()) continue;
189 obj->DoLoop(evMain, rsnIH->GetSelector());
192 PostData(1, fOutput);
195 //__________________________________________________________________________________________________
196 void AliRsnAnalysisTask::UserExecMix(Option_t *)
199 // Main loop for event-mixing computations
200 // It is called for each pair of matched events
201 // and executes the 'DoLoop' function of all AliRsnLoop instances stored here.
204 AliRsnEvent *evMain = 0x0;
205 AliRsnEvent *evMix = 0x0;
207 AliRsnInputHandler *rsnIH = 0x0, *rsnMixIH = 0x0;
210 TObjArrayIter next(fInputEHMain->InputEventHandlers());
212 while ( (obj = next()) ) {
213 if (obj->IsA() == AliRsnInputHandler::Class()) {
214 rsnIH = (AliRsnInputHandler *)obj;
215 //AliInfo(Form("Found object '%s' which is RSN input handler", obj->GetName()));
216 evMain = rsnIH->GetRsnEvent();
217 id = fInputEHMain->InputEventHandlers()->IndexOf(obj);
225 // gets first input handler form mixing buffer
226 AliMultiInputEventHandler *ihMultiMix = dynamic_cast<AliMultiInputEventHandler *>(fInputEHMix->InputEventHandler(0));
228 rsnMixIH = dynamic_cast<AliRsnInputHandler *>(ihMultiMix->InputEventHandler(id));
230 evMix = rsnMixIH->GetRsnEvent();
233 TObjArrayIter next(&fRsnObjects);
234 AliRsnLoop *obj = 0x0;
235 while ( (obj = (AliRsnLoop *)next()) ) {
236 if (!obj->IsMixed()) continue;
237 obj->DoLoop(evMain, rsnIH->GetSelector(), evMix, rsnMixIH->GetSelector());
242 PostData(1, fOutput);
245 //________________________________________________________________________
246 void AliRsnAnalysisTask::Terminate(Option_t *)
249 // Draw result to screen, or perform fitting, normalizations
250 // Called once at the end of the query
253 fOutput = dynamic_cast<TList *>(GetOutputData(1));
254 if (!fOutput) { AliError("Could not retrieve TList fOutput"); return; }
257 //_____________________________________________________________________________
258 void AliRsnAnalysisTask::InitInputHandlers()
261 // Sets needed input handlers
263 AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
264 fInputEHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
266 fInputEHMix = dynamic_cast<AliMixInputEventHandler *>(fInputEHMain->GetFirstMultiInputHandler());