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