Cleaning the code and using "const" wherever it is ppossible (Boris)
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisAT.cxx
CommitLineData
06351446 1#include <TSystem.h>
2#include <TFile.h>
3
4#include "AliLog.h"
5
6#include "AliAnalysisManager.h"
7#include "AliRsnPairMgr.h"
8#include "AliRsnEventBuffer.h"
9
10#include "AliMCEventHandler.h"
11
12#include "AliRsnAnalysisAT.h"
13
14ClassImp ( AliRsnAnalysisAT )
15AliRsnAnalysisAT::AliRsnAnalysisAT ( const char * name )
16 : AliRsnBaseAT ( name )
17{
18 InitIOVars ();
19 DefineInput ( 1, AliRsnPairMgr::Class() );
20
21 DefineOutput ( 0, TList::Class() );
22}
23
24AliRsnAnalysisAT::~AliRsnAnalysisAT()
25{
26}
27
28void AliRsnAnalysisAT::InitIOVars()
29{
30 AliDebug ( AliLog::kDebug, "<-" );
31 AliRsnBaseAT::InitIOVars();
32
33 fPairMgr = 0;
34 fRsnMVEventBuffer = 0;
35 fOutList = 0;
36
37 for ( Int_t i=0;i<100 ;i++ )
38 for ( Int_t j=0;j<100 ;j++ )
39 {
40 fHist[i][j] = 0;
41 }
42
43 AliDebug ( AliLog::kDebug, "->" );
44}
45
46void AliRsnAnalysisAT::LocalInit()
47{
48 AliDebug ( AliLog::kDebug, "<-" );
49 fPairMgr = dynamic_cast<AliRsnPairMgr*> ( GetInputData ( 1 ) );
50 fPairMgr->PrintPairs();
51 AliDebug ( AliLog::kDebug, "->" );
52}
53
54Bool_t AliRsnAnalysisAT::Notify()
55{
56 AliDebug ( AliLog::kDebug, "<-" );
57 fChain[0] = ( TChain* ) GetInputData ( 0 );
58 if ( fChain[0] )
59 {
60 TFile *f = fChain[0]->GetCurrentFile();
61 if ( f ) { AliInfo ( Form ( "Processing file %s", f->GetName() ) );}
62 else AliError ( "fTree->GetCurrentFile() is 0" );
63 AliInfo ( Form ( "NumOfEvents %d", fChain[0]->GetTree()->GetEntries() ) );
64 }
65 else
66 {
67 AliError ( "fChain[0] not available" );
68 }
69
70 AliDebug ( AliLog::kDebug, "->" );
71 return AliRsnBaseAT::Notify();
72}
73
74void AliRsnAnalysisAT::CreateOutputObjects()
75{
76 AliDebug ( AliLog::kDebug, "<-" );
77
78 fPairMgr = dynamic_cast<AliRsnPairMgr*> ( GetInputData ( 1 ) );
79 OpenFile ( 0 );
80 fOutList = new TList();
81
82 AliRsnPair *def=0;
83 for ( Int_t i=0;i< fPairMgr->GetPairs()->GetEntriesFast();i++ )
84 {
85 def = ( AliRsnPair * ) fPairMgr->GetPairs()->At ( i );
86 for ( Int_t j=0;j<def->GetCutMgr()->GetEntriesFast() ;j++ )
87 {
88 fHist[i][j] = def->GenerateEffMassHist ( j );
89 fOutList->Add ( fHist[i][j] );
90 }
91 }
92
93 fRsnMVEventBuffer = new AliRsnEventBuffer ( 1000 );
94// fRsnMVEventBuffer = new AliRsnEventBuffer ( 100 ,kFALSE );
95 AliDebug ( AliLog::kDebug, "->" );
96
97}
98
99void AliRsnAnalysisAT::Exec ( Option_t * option )
100{
101 TTree *tree = ( ( TChain* ) GetInputData ( 0 ) )->GetTree();
102 Long64_t ientry = ( Long64_t ) tree->GetReadEntry();
103
104 if ( ientry%100==0 )
105 AliInfo ( Form ( "Event #%d",ientry ) );
106
107// AliRsnEvent *curEvent = GetRsnMVEventFromInputType();
108// if ( !curEvent ) { AliError ( "Could not get AliRsnEvent from GetRsnMVEventFromInputType(). Skipping..." ); return; }
109
110// ProcessEventAnalysis ( curEvent );
111// PostEventProcess();
112
113// if (ientry%10000==0)
114// AliInfo(Form("Event #%d",ientry));
115 PostData ( 0, fOutList );
116}
117
118void AliRsnAnalysisAT::Terminate ( Option_t * )
119{
120 AliDebug ( AliLog::kDebug, "<-" );
121 fOutList = dynamic_cast<TList*> ( GetOutputData ( 0 ) );
122 if ( !fOutList ) { AliError ( " fOutList not available" ); return; }
123 fOutList->Print();
124
125 AliDebug ( AliLog::kDebug, "->" );
126}
127
128void AliRsnAnalysisAT::Cleanup()
129{
130 AliInfo ( Form ( "Cleaning up in worker %s ...",gSystem->HostName() ) );
131// fRsnMVEventBuffer->ClearBuffer();
132// AliRsnPair *def = ( AliRsnPair * ) fPairMgr->GetPairs()->At ( 0 );
133// def->DoCleanUpAfterOneEvent();
134}
135
136void AliRsnAnalysisAT::ProcessEventAnalysis ( AliRsnEvent *curEvent )
137{
138
139
140
141 fRsnMVEventBuffer->AddEvent ( curEvent );
142 AliRsnPair *def=0;
143 AliRsnEvent *event=0;
144 Int_t numOfTracks;
145 for ( Int_t i=0;i< fPairMgr->GetPairs()->GetEntriesFast();i++ )
146 {
147 def = ( AliRsnPair * ) fPairMgr->GetPairs()->At ( i );
148 def->SetRsnMVEventBuffer ( fRsnMVEventBuffer );
149 for ( Int_t j=0;j<def->GetCutMgr()->GetEntriesFast() ;j++ )
150 {
151 event = fRsnMVEventBuffer->GetCurrentEvent();
152 numOfTracks = event->GetMultiplicity();
153// AliInfo ( Form ( "%d",event->GetMultiplicity() ) );
154
155 if ( numOfTracks>0 )
156 def->ProcessPair ( event ,fHist[i][j] ,j );
157 }
158 }
159
160}
161
162
163
164AliRsnEvent * AliRsnAnalysisAT::GetRsnMVEventFromInputType ( const Short_t & index )
165{
166 switch ( fInputType[index] )
167 {
168 case kAOD:
169 {
170 return GetRsnMVFromAOD ( index );
171 break;
172 }
173 case kESD:
174 {
175 AliWarning ( "Not Implemented Yet ..." );
176 return GetRsnMVFromESD ( index );
177 break;
178 }
179 case kESDMC:
180 {
181 AliWarning ( "Not Implemented Yet ..." );
182 return GetRsnMVFromESDMC ( index );
183 break;
184 }
185 case kMC:
186 AliWarning ( "Not Implemented Yet ..." );
187 return ( AliRsnEvent* ) 0x0;
188 break;
189 case kRSN:
190 {
191 return GetRsnMVFromRSN();
192 break;
193 }
194 default:
195 AliError ( "Type not supported ..." );
196 return ( AliRsnEvent* ) 0x0;
197 break;
198 }
199 return ( AliRsnEvent* ) 0x0;
200}
201
202void AliRsnAnalysisAT::PostEventProcess ( const Short_t & index )
203{
204 switch ( fInputType[index] )
205 {
206 case kAOD:
207 break;
208 case kESD:
209 break;
210 case kESDMC:
211 break;
212 case kMC:
213 break;
214 case kRSN:
215 {
216 if ( fRsnMVEventBuffer->GetDeleteBufferWhenReset() == kFALSE )
217 {
218 fRSN[index] = ( AliRsnEvent* ) fRsnMVEventBuffer->GetNextEvent();
219 SetBranchAddress ( 0 , "RsnEvents", &fRSN[index] );
220 }
221 break;
222 }
223 default:
224 break;
225 }
226
227}
228
229AliRsnEvent * AliRsnAnalysisAT::GetRsnMVFromAOD ( const Short_t & index )
230{
231
232 if ( !fAOD[index] ) { AliError ( "fAOD not available." ); return ( AliRsnEvent * ) 0x0; }
233
234
235// fRSN[0] = new AliRsnEvent();
236// fRSN[0]->Init();
237// fRSN[0]->BuildEvent ( fAOD[index] );
238// return fRSN[0];
239
240 return ( AliRsnEvent* ) 0x0;
241
242}
243
244AliRsnEvent * AliRsnAnalysisAT::GetRsnMVFromESD ( const Short_t & index )
245{
246 if ( !fESD[index] ) { AliError ( "fESD not available." ); return ( AliRsnEvent * ) 0x0; }
247
248// fRSN[0] = new AliRsnEvent();
249// fRSN[0]->Init();
250// fRSN[0]->BuildEvent ( fESD[index] );
251// return fRSN[0];
252
253 return ( AliRsnEvent* ) 0x0;
254}
255
256AliRsnEvent * AliRsnAnalysisAT::GetRsnMVFromESDMC ( const Short_t & index )
257{
258
259 if ( !fESD[index] ) { AliError ( "fESD not available." ); return ( AliRsnEvent * ) 0x0; }
260 AliMCEventHandler* mcHandler = dynamic_cast<AliMCEventHandler*> ( AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler() );
261 if ( !mcHandler ) { AliError ( "Could not retrieve MC event handler" ); return ( AliRsnEvent * ) 0x0; }
262
263// fRSN[0] = new AliRsnEvent();
264// fRSN[0]->Init();
265// fRSN[0]->BuildEvent ( fESD[index] ,mcHandler );
266// return fRSN[0];
267
268 return ( AliRsnEvent* ) 0x0;
269}
270
271AliRsnEvent * AliRsnAnalysisAT::GetRsnMVFromRSN ( const Short_t & index )
272{
273 AliRsnEvent *event = fRSN[index];
274 if ( fRsnMVEventBuffer->GetDeleteBufferWhenReset() == kTRUE )
275 {
276 event = ( AliRsnEvent * ) fRSN[index]->Clone();
277 }
278// AliInfo ( Form ( "%p %p",event,fRSN[index] ) );
279 return event;
280}