]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisTask.cxx
Added first version of cut monitoring + style format applied
[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    fBigOutput(kFALSE)
25 {
26 //
27 // Dummy constructor ALWAYS needed for I/O.
28 //
29 }
30
31 //__________________________________________________________________________________________________
32 AliRsnAnalysisTask::AliRsnAnalysisTask(const char *name) :
33    AliAnalysisTaskSE(name),
34    fOutput(0),
35    fRsnObjects(0),
36    fInputEHMain(0),
37    fInputEHMix(0),
38    fBigOutput(kFALSE)
39 {
40 //
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
45 //
46
47    DefineOutput(1, TList::Class());
48 }
49
50 //__________________________________________________________________________________________________
51 AliRsnAnalysisTask::AliRsnAnalysisTask(const AliRsnAnalysisTask &copy) :
52    AliAnalysisTaskSE(copy),
53    fOutput(0),
54    fRsnObjects(copy.fRsnObjects),
55    fInputEHMain(copy.fInputEHMain),
56    fInputEHMix(copy.fInputEHMix),
57    fBigOutput(copy.fBigOutput)
58 {
59 //
60 // Copy constructor.
61 // Implemented as requested by C++ standards.
62 // Can be used in PROOF and by plugins.
63 //
64 }
65
66 //__________________________________________________________________________________________________
67 AliRsnAnalysisTask &AliRsnAnalysisTask::operator=(const AliRsnAnalysisTask &copy)
68 {
69 //
70 // Assignment operator.
71 // Implemented as requested by C++ standards.
72 // Can be used in PROOF and by plugins.
73 //
74    AliAnalysisTaskSE::operator=(copy);
75    if (this == &copy)
76       return *this;
77    fRsnObjects = copy.fRsnObjects;
78    fInputEHMain = copy.fInputEHMain;
79    fInputEHMix = copy.fInputEHMix;
80    fBigOutput = copy.fBigOutput;
81
82    return (*this);
83 }
84
85 //__________________________________________________________________________________________________
86 AliRsnAnalysisTask::~AliRsnAnalysisTask()
87 {
88 //
89 // Destructor.
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.
92 //
93
94    if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
95       delete fOutput;
96    }
97 }
98
99 //__________________________________________________________________________________________________
100 void AliRsnAnalysisTask::AddLoop(AliRsnLoop *obj)
101 {
102 //
103 // Add new computation object
104 //
105
106    fRsnObjects.Add(obj);
107 }
108
109 //__________________________________________________________________________________________________
110 void AliRsnAnalysisTask::UserCreateOutputObjects()
111 {
112 //
113 // Initialization of outputs.
114 // This is called once per worker node.
115 //
116
117    // sets all Inuput Handler pointers
118    InitInputHandlers();
119
120    // create list and set it as owner of its content (MANDATORY)
121    if (fBigOutput) OpenFile(1);
122    fOutput = new TList();
123    fOutput->SetOwner();
124
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);
130    }
131
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
149    // post data for ALL output slots >0 here, to get at least an empty histogram
150    PostData(1, fOutput);
151 }
152
153 //__________________________________________________________________________________________________
154 void AliRsnAnalysisTask::UserExec(Option_t *)
155 {
156 //
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.
160 //
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()) {
170             rsnIH = (AliRsnInputHandler *)obj;
171             //AliInfo(Form("Found object '%s' which is RSN input handler", obj->GetName()));
172             evMain = rsnIH->GetRsnEvent();
173             break;
174          }
175       }
176    }
177
178    if (!evMain) return;
179
180    TObjArrayIter next(&fRsnObjects);
181    AliRsnLoop *obj = 0x0;
182    while ( (obj = (AliRsnLoop *)next()) ) {
183       if (obj->IsMixed()) continue;
184       obj->DoLoop(evMain, rsnIH->GetSelector());
185    }
186
187    PostData(1, fOutput);
188 }
189
190 //__________________________________________________________________________________________________
191 void AliRsnAnalysisTask::UserExecMix(Option_t *)
192 {
193 //
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()) {
209             rsnIH = (AliRsnInputHandler *)obj;
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;
214          }
215       }
216    }
217
218    if (!evMain) return;
219
220    // gets first input handler form mixing buffer
221    AliMultiInputEventHandler *ihMultiMix = dynamic_cast<AliMultiInputEventHandler *>(fInputEHMix->InputEventHandler(0));
222    if (ihMultiMix) {
223       rsnMixIH = dynamic_cast<AliRsnInputHandler *>(ihMultiMix->InputEventHandler(id));
224       if (rsnMixIH) {
225          evMix = rsnMixIH->GetRsnEvent();
226          if (!evMix) return;
227
228          TObjArrayIter next(&fRsnObjects);
229          AliRsnLoop *obj = 0x0;
230          while ( (obj = (AliRsnLoop *)next()) ) {
231             if (!obj->IsMixed()) continue;
232             obj->DoLoop(evMain, rsnIH->GetSelector(), evMix, rsnMixIH->GetSelector());
233          }
234       }
235    }
236
237    PostData(1, fOutput);
238 }
239
240 //________________________________________________________________________
241 void 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 //
247
248    fOutput = dynamic_cast<TList *>(GetOutputData(1));
249    if (!fOutput) { AliError("Could not retrieve TList fOutput"); return; }
250 }
251
252 //_____________________________________________________________________________
253 void 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    }
263 }
264