]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnAnalysisTask.cxx
Include variable jet patch size handling in decoding
[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    fRsnObjects = copy.fRsnObjects;
76    fInputEHMain = copy.fInputEHMain;
77    fInputEHMix = copy.fInputEHMix;
78    fBigOutput = copy.fBigOutput;
79    
80    return (*this);
81 }
82
83 //__________________________________________________________________________________________________
84 AliRsnAnalysisTask::~AliRsnAnalysisTask()
85 {
86 //
87 // Destructor. 
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.
90 //
91
92    if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
93       delete fOutput;
94    }
95 }
96
97 //__________________________________________________________________________________________________
98 void AliRsnAnalysisTask::AddLoop(AliRsnLoop *obj)
99 {
100 //
101 // Add new computation object
102 //
103
104    fRsnObjects.Add(obj);
105 }
106
107 //__________________________________________________________________________________________________
108 void AliRsnAnalysisTask::UserCreateOutputObjects()
109 {
110 //
111 // Initialization of outputs.
112 // This is called once per worker node.
113 //
114
115    // sets all Inuput Handler pointers
116    InitInputHandlers();
117
118    // create list and set it as owner of its content (MANDATORY)
119    if (fBigOutput) OpenFile(1);
120    fOutput = new TList();
121    fOutput->SetOwner();
122    
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);
128    }
129
130    // post data for ALL output slots >0 here, to get at least an empty histogram
131    PostData(1, fOutput);
132 }
133
134 //__________________________________________________________________________________________________
135 void AliRsnAnalysisTask::UserExec(Option_t *)
136 {
137 //
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.
141 //
142
143    AliRsnEvent *evMain = 0x0;
144    AliRsnInputHandler *rsnIH = 0x0;
145
146    if (fInputEHMain) {
147       TObjArrayIter next(fInputEHMain->InputEventHandlers());
148       TObject *obj = 0x0;
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();
154             break;
155          }
156       }
157    }
158    
159    if (!evMain) return;
160
161    TObjArrayIter next(&fRsnObjects);
162    AliRsnLoop *obj = 0x0;
163    while ( (obj = (AliRsnLoop*)next()) ) {
164       if (obj->IsMixed()) continue;
165       obj->DoLoop(evMain, rsnIH->GetSelector());
166    }
167    
168    PostData(1, fOutput);
169 }
170
171 //__________________________________________________________________________________________________
172 void AliRsnAnalysisTask::UserExecMix(Option_t*)
173 {
174 //
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.
178 //
179
180    AliRsnEvent *evMain = 0x0;
181    AliRsnEvent *evMix  = 0x0;
182    Int_t        id     = -1;
183    AliRsnInputHandler *rsnIH = 0x0, *rsnMixIH = 0x0;
184
185    if (fInputEHMain) {
186       TObjArrayIter next(fInputEHMain->InputEventHandlers());
187       TObject *obj = 0x0;
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);
194             break;
195          }
196       }
197    }
198    
199    if (!evMain) return;
200
201    // gets first input handler form mixing buffer
202    AliMultiInputEventHandler *ihMultiMix = dynamic_cast<AliMultiInputEventHandler*>(fInputEHMix->InputEventHandler(0));
203    if (ihMultiMix) {
204       rsnMixIH = dynamic_cast<AliRsnInputHandler*>(ihMultiMix->InputEventHandler(id));
205       if (rsnMixIH) {
206          evMix = rsnMixIH->GetRsnEvent();
207          if (!evMix) return;
208
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());
214          }
215       }
216    }
217    
218    PostData(1, fOutput);
219 }
220
221 //________________________________________________________________________
222 void AliRsnAnalysisTask::Terminate(Option_t *)
223 {
224 //
225 // Draw result to screen, or perform fitting, normalizations
226 // Called once at the end of the query
227 //
228
229    fOutput = dynamic_cast<TList*>(GetOutputData(1));
230    if (!fOutput) { AliError("Could not retrieve TList fOutput"); return; }
231 }
232
233 //_____________________________________________________________________________
234 void AliRsnAnalysisTask::InitInputHandlers()
235 {
236 //
237 // Sets needed input handlers
238 //
239    AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
240    fInputEHMain = dynamic_cast<AliMultiInputEventHandler *>(mgr->GetInputEventHandler());
241    if (fInputEHMain) {
242       fInputEHMix = dynamic_cast<AliMixInputEventHandler *>(fInputEHMain->GetFirstMultiInputHandler());
243    }
244 }
245