7e33f31668482f6d5123800cdf36c0a413b161f3
[u/mrichter/AliRoot.git] / JETAN / AliAnalysisTaskFastEmbedding.cxx
1 /*************************************************************************
2  *                                                                       *
3  * Task for fast embedding                                               *
4  * read extra input from AOD                                             *
5  *                                                                       *
6  *************************************************************************/
7
8
9 /**************************************************************************
10  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
11  *                                                                        *
12  * Author: The ALICE Off-line Project.                                    *
13  * Contributors are mentioned in the code where appropriate.              *
14  *                                                                        *
15  * Permission to use, copy, modify and distribute this software and its   *
16  * documentation strictly for non-commercial purposes is hereby granted   *
17  * without fee, provided that the above copyright notice appears in all   *
18  * copies and that both the copyright notice and this permission notice   *
19  * appear in the supporting documentation. The authors make no claims     *
20  * about the suitability of this software for any purpose. It is          *
21  * provided "as is" without express or implied warranty.                  *
22  **************************************************************************/
23
24 /* $Id: */
25
26 #include <TFile.h>
27 #include <TTree.h>
28 #include <TChain.h>
29 #include <TClonesArray.h>
30 #include <TDirectory.h>
31 #include <TSystem.h>
32 #include <TRef.h>
33 #include <TRandom3.h>
34 #include <TH1F.h>
35 #include <TH2F.h>
36
37
38 #include "AliAnalysisTaskFastEmbedding.h"
39 #include "AliAnalysisManager.h"
40 #include "AliAODEvent.h"
41 #include "AliAODTrack.h"
42 #include "AliAODJet.h"
43 #include "AliAODMCParticle.h"
44
45 #include "AliLog.h"
46
47 ClassImp(AliAnalysisTaskFastEmbedding)
48
49 //__________________________________________________________________________
50 AliAnalysisTaskFastEmbedding::AliAnalysisTaskFastEmbedding()
51     : AliAnalysisTaskSE()
52       ,fAODout(0)
53       ,fAODevent(0)
54       ,fAODtree(0)
55       ,fAODfile(0)
56       ,rndm(0)
57       ,fAODPathArray(0)
58       ,fAODPath("AliAOD.root")
59       ,fTrackBranch("aodExtraTracks")
60       ,fMCparticlesBranch("aodExtraMCparticles")
61       ,fJetBranch("")
62       ,fEntry(0)
63       ,fEmbedMode(0)
64       ,fEvtSelecMode(0)
65       ,fEvtSelMinJetPt(-1)
66       ,fEvtSelMaxJetPt(-1)
67       ,fToyMinNbOfTracks(1)
68       ,fToyMaxNbOfTracks(1)
69       ,fToyMinTrackPt(50.)
70       ,fToyMaxTrackPt(50.)
71       ,fToyDistributionTrackPt(0.)
72       ,fToyMinTrackEta(-.5)
73       ,fToyMaxTrackEta(.5)
74       ,fToyMinTrackPhi(0.)
75       ,fToyMaxTrackPhi(2*TMath::Pi())
76       ,fToyFilterMap(0)
77       ,fHistList(0)
78       ,fh1TrackPt(0)
79       ,fh2TrackEtaPhi(0)
80       ,fh1TrackN(0)
81       ,fh1MCTrackPt(0)
82       ,fh2MCTrackEtaPhi(0)
83       ,fh1MCTrackN(0)
84
85
86 {
87     // default constructor
88
89 }
90
91
92 //__________________________________________________________________________
93 AliAnalysisTaskFastEmbedding::AliAnalysisTaskFastEmbedding(const char *name)
94     : AliAnalysisTaskSE(name)
95       ,fAODout(0)
96       ,fAODevent(0)
97       ,fAODtree(0)
98       ,fAODfile(0)
99       ,rndm(0)
100       ,fAODPathArray(0)
101       ,fAODPath("AliAOD.root")
102       ,fTrackBranch("aodExtraTracks")
103       ,fMCparticlesBranch("aodExtraMCparticles")
104       ,fJetBranch("")
105       ,fEntry(0)
106       ,fEmbedMode(0)
107       ,fEvtSelecMode(0)
108       ,fEvtSelMinJetPt(-1)
109       ,fEvtSelMaxJetPt(-1)
110       ,fToyMinNbOfTracks(1)
111       ,fToyMaxNbOfTracks(1)
112       ,fToyMinTrackPt(50.)
113       ,fToyMaxTrackPt(50.)
114       ,fToyDistributionTrackPt(0.)
115       ,fToyMinTrackEta(-.5)
116       ,fToyMaxTrackEta(.5)
117       ,fToyMinTrackPhi(0.)
118       ,fToyMaxTrackPhi(2*TMath::Pi())
119       ,fToyFilterMap(0)
120       ,fHistList(0)
121       ,fh1TrackPt(0)
122       ,fh2TrackEtaPhi(0)
123       ,fh1TrackN(0)
124       ,fh1MCTrackPt(0)
125       ,fh2MCTrackEtaPhi(0)
126       ,fh1MCTrackN(0)
127 {
128     // constructor
129     DefineOutput(1, TList::Class());
130 }
131
132
133 //__________________________________________________________________________
134 AliAnalysisTaskFastEmbedding::AliAnalysisTaskFastEmbedding(const AliAnalysisTaskFastEmbedding &copy)
135     : AliAnalysisTaskSE()
136       ,fAODout(copy.fAODout)
137       ,fAODevent(copy.fAODevent)
138       ,fAODtree(copy.fAODtree)
139       ,fAODfile(copy.fAODfile)
140       ,rndm(copy.rndm)
141       ,fAODPathArray(copy.fAODPathArray)
142       ,fAODPath(copy.fAODPath)
143       ,fTrackBranch(copy.fTrackBranch)
144       ,fMCparticlesBranch(copy.fMCparticlesBranch)
145       ,fJetBranch(copy.fJetBranch)
146       ,fEntry(copy.fEntry)
147       ,fEmbedMode(copy.fEmbedMode)
148       ,fEvtSelecMode(copy.fEvtSelecMode)
149       ,fEvtSelMinJetPt(copy.fEvtSelMinJetPt)
150       ,fEvtSelMaxJetPt(copy.fEvtSelMaxJetPt)
151       ,fToyMinNbOfTracks(copy.fToyMinNbOfTracks)
152       ,fToyMaxNbOfTracks(copy.fToyMaxNbOfTracks)
153       ,fToyMinTrackPt(copy.fToyMinTrackPt)
154       ,fToyMaxTrackPt(copy.fToyMaxTrackPt)
155       ,fToyDistributionTrackPt(copy.fToyDistributionTrackPt)
156       ,fToyMinTrackEta(copy.fToyMinTrackEta)
157       ,fToyMaxTrackEta(copy.fToyMaxTrackEta)
158       ,fToyMinTrackPhi(copy.fToyMinTrackPhi)
159       ,fToyMaxTrackPhi(copy.fToyMaxTrackPhi)
160       ,fToyFilterMap(copy.fToyFilterMap)
161       ,fHistList(copy.fHistList)
162       ,fh1TrackPt(copy.fh1TrackPt)
163       ,fh2TrackEtaPhi(copy.fh2TrackEtaPhi)
164       ,fh1TrackN(copy.fh1TrackN)
165       ,fh1MCTrackPt(copy.fh1MCTrackPt)
166       ,fh2MCTrackEtaPhi(copy.fh2MCTrackEtaPhi)
167       ,fh1MCTrackN(copy.fh1MCTrackN)
168 {
169     // copy constructor
170 }
171
172
173 //__________________________________________________________________________
174 AliAnalysisTaskFastEmbedding& AliAnalysisTaskFastEmbedding::operator=(const AliAnalysisTaskFastEmbedding& o)
175 {
176     // assignment
177
178     if(this!=&o){
179         AliAnalysisTaskSE::operator=(o);
180         fAODout            = o.fAODout;
181         fAODevent          = o.fAODevent;
182         fAODtree           = o.fAODtree;
183         fAODfile           = o.fAODfile;
184         rndm               = o.rndm;
185         fAODPathArray       = o.fAODPathArray;
186         fAODPath           = o.fAODPath;
187         fTrackBranch       = o.fTrackBranch;
188         fMCparticlesBranch = o.fMCparticlesBranch;
189         fJetBranch         = o.fJetBranch;
190         fEntry             = o.fEntry;
191         fEmbedMode         = o.fEmbedMode;
192         fEvtSelecMode      = o.fEvtSelecMode;
193         fEvtSelMinJetPt    = o.fEvtSelMinJetPt;
194         fEvtSelMaxJetPt    = o.fEvtSelMaxJetPt;
195         fToyMinNbOfTracks  = o.fToyMinNbOfTracks;
196         fToyMaxNbOfTracks  = o.fToyMaxNbOfTracks;
197         fToyMinTrackPt     = o.fToyMinTrackPt;
198         fToyMaxTrackPt     = o.fToyMaxTrackPt;
199         fToyDistributionTrackPt = o.fToyDistributionTrackPt;
200         fToyMinTrackEta    = o.fToyMinTrackEta;
201         fToyMaxTrackEta    = o.fToyMaxTrackEta;
202         fToyMinTrackPhi    = o.fToyMinTrackPhi;
203         fToyMaxTrackPhi    = o.fToyMaxTrackPhi;
204         fToyFilterMap      = o.fToyFilterMap;
205         fHistList          = o.fHistList;
206         fh1TrackPt         = o.fh1TrackPt;
207         fh2TrackEtaPhi     = o.fh2TrackEtaPhi;
208         fh1TrackN          = o.fh1TrackN;
209         fh1MCTrackPt       = o.fh1MCTrackPt;
210         fh2MCTrackEtaPhi   = o.fh2MCTrackEtaPhi;
211         fh1MCTrackN        = o.fh1MCTrackN;
212     }
213
214     return *this;
215 }
216
217
218 //__________________________________________________________________________
219 AliAnalysisTaskFastEmbedding::~AliAnalysisTaskFastEmbedding()
220 {
221     // destructor
222     delete rndm;
223 }
224
225
226 //__________________________________________________________________________
227 void AliAnalysisTaskFastEmbedding::UserCreateOutputObjects()
228 {
229     // create output objects
230     if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::UserCreateOutputObjects()");
231
232     rndm = new TRandom3();
233     Int_t id = GetJobID();
234     if(id>-1) rndm->SetSeed(id);
235     else      rndm->SetSeed();   // a TTUID is generated and used for seed
236     AliInfo(Form("TRandom3 seed: %d", rndm->GetSeed()));
237
238
239     // embed mode with AOD
240     if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks || fEmbedMode==kAODJet4Mom){
241
242        // open input AOD
243        if(fAODPathArray){
244            Int_t rc = SelectAODfile();
245            if(rc<0) return;
246        }
247
248        Int_t rc = OpenAODfile();
249        if(rc<0) return;
250
251     } //end: embed mode with AOD
252
253
254     // connect output aod
255     // create a new branch for extra tracks
256     fAODout = AODEvent();
257     if(!fAODout){
258         AliError("Output AOD not found.");
259         return;
260     }
261     if(!fAODout->FindListObject(fTrackBranch.Data()) && strlen(fTrackBranch.Data())){
262         AliInfo(Form("Add AOD branch %s", fTrackBranch.Data()));
263         TClonesArray *tracks = new TClonesArray("AliAODTrack",0);
264         tracks->SetName(fTrackBranch.Data());
265         AddAODBranch("TClonesArray", &tracks);
266     }
267     // create new branch for extra mcparticle if available as input
268     if(fAODevent && fAODevent->FindListObject("mcparticles") && strlen(fMCparticlesBranch.Data())){
269        AliInfo(Form("Add AOD branch %s", fMCparticlesBranch.Data()));
270        TClonesArray *mcparticles = new TClonesArray("AliAODMCParticle",0);
271        mcparticles->SetName(fMCparticlesBranch.Data());
272        AddAODBranch("TClonesArray", &mcparticles);
273     }
274
275
276
277
278     //qa histograms
279
280     OpenFile(1);
281     fHistList = new TList();
282
283     Bool_t oldStatus = TH1::AddDirectoryStatus();
284     TH1::AddDirectory(kFALSE);
285
286     fh1TrackPt      =  new TH1F("fh1TrackPt","pT of extra tracks;p_{T};entries", 300, 0., 300.);
287     fh2TrackEtaPhi  =  new TH2F("fh2TrackEtaPhi","eta-phi distribution of extra tracks;#eta;#phi", 20, -1., 1., 60, 0., 2*TMath::Pi());
288     fh1TrackN       =  new TH1F("fh1TrackN", "nb. of extra tracks per event;nb. of tracks;entries",300, 0., 3000.);
289
290     fHistList->Add(fh1TrackPt);
291     fHistList->Add(fh2TrackEtaPhi);
292     fHistList->Add(fh1TrackN);
293
294  
295     if(fAODevent && fAODevent->FindListObject("mcparticles") && strlen(fMCparticlesBranch.Data())){ 
296
297        fh1MCTrackPt      =  new TH1F("fh1MCTrackPt","pT of MC extra tracks;p_{T};entries", 300, 0., 300.);
298        fh2MCTrackEtaPhi  =  new TH2F("fh2MCTrackEtaPhi","eta-phi distribution of MC extra tracks;#eta;#phi", 20, -1., 1., 60, 0., 2*TMath::Pi());
299        fh1MCTrackN       =  new TH1F("fh1MCTrackN", "nb. of MC extra tracks per event;nb. of tracks;entries",300, 0., 3000.);
300
301        fHistList->Add(fh1MCTrackPt);
302        fHistList->Add(fh2MCTrackEtaPhi);
303        fHistList->Add(fh1MCTrackN);
304
305     }
306
307     TH1::AddDirectory(oldStatus);
308
309 }
310
311
312 //__________________________________________________________________________
313 void AliAnalysisTaskFastEmbedding::Init()
314 {
315     // Initialization
316     if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::Init()");
317
318 }
319
320
321 //__________________________________________________________________________
322 void AliAnalysisTaskFastEmbedding::UserExec(Option_t *)
323 {
324     if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::UserExec()");
325
326     if(!fAODout){
327        AliError("Need output AOD, but is not connected."); 
328        return;
329     }
330
331     // connect aod out
332     TClonesArray *tracks = (TClonesArray*)(fAODout->FindListObject(fTrackBranch.Data()));
333     if(!tracks){
334         AliError("Extra track branch not found in output.");
335         return;
336     }
337     tracks->Delete();
338     Int_t nAODtracks=0;
339
340
341     TRef dummy;
342
343     // === embed mode with AOD ===
344     if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks || fEmbedMode==kAODJet4Mom){
345        if(!fAODevent){
346           AliError("Need input AOD, but is not connected."); 
347           return;
348        }
349
350        // fetch jets
351        TClonesArray *aodJets = 0;
352        if(fJetBranch.Length()) aodJets = dynamic_cast<TClonesArray*>(fAODevent->FindListObject(fJetBranch.Data()));
353        else                    aodJets = fAODevent->GetJets();
354        if(!aodJets){
355           AliError("Could not find jets in AOD. Check jet branch when indicated.");
356           return;
357        }
358         
359
360        Int_t nEvents = fAODtree->GetEntries();
361
362        Bool_t useEntry = kFALSE;
363        while(!useEntry){  // protection need, if no event fulfills requierment
364           if(fEntry>nEvents){
365               fEntry=0;
366               if(!fAODPathArray){
367                  AliDebug(AliLog::kDebug, "Last event in AOD reached, start from entry 0 again.");
368               } 
369               else {
370                  AliDebug(AliLog::kDebug, "Last event in AOD reached, select new AOD file ...");
371                  Int_t rc = SelectAODfile();
372                  if(rc<0) return;
373
374                  rc = OpenAODfile();
375                  if(rc<0) return;
376               }
377           }
378     
379           fAODtree->GetEvent(fEntry);
380
381           // jet pt selection
382           if(fEvtSelecMode==kEventsJetPt){
383              Int_t nJets = aodJets->GetEntries();
384              for(Int_t ij=0; ij<nJets; ++ij){
385                  AliAODJet *jet = dynamic_cast<AliAODJet*>(aodJets->At(ij));
386                  if(!jet) continue;
387
388                  if(   (fEvtSelMinJetPt==-1. || jet->Pt()>=fEvtSelMinJetPt)
389                     && (fEvtSelMaxJetPt==-1. || jet->Pt()<=fEvtSelMaxJetPt)){
390                     useEntry = kTRUE;
391                     break;
392                  } 
393              }
394           }
395
396           // no selection
397           if(fEvtSelecMode==kEventsAll){
398              useEntry = kTRUE;
399           }
400
401           fEntry++;
402        }
403        AliInfo(Form("Use entry %d from extra AOD.", fEntry-1));
404
405
406        TClonesArray *mcpartIN  = (TClonesArray*)(fAODevent->FindListObject("mcparticles"));
407        TClonesArray *mcpartOUT = 0x0;
408        if(mcpartIN){
409            mcpartOUT = (TClonesArray*)(fAODout->FindListObject(fMCparticlesBranch.Data()));
410            mcpartOUT->Delete();
411        } else {
412            AliInfo("No extra MC particles found.");
413        }
414     
415
416        if(fEmbedMode==kAODFull || fEmbedMode==kAODJetTracks){ // take all tracks or jet tracks
417            // loop over input tracks
418            // add to output aod
419            Int_t nTracks = fAODevent->GetNumberOfTracks();
420            fh1TrackN->Fill((Float_t)nTracks);
421
422            for(Int_t it=0; it<nTracks; ++it){
423                AliAODTrack *tmpTr = fAODevent->GetTrack(it);
424                // ?? test filter bit, or something else??
425
426                if(fEmbedMode==kAODJetTracks){
427                   // jet track? else continue
428                   // not implemented yet
429                   continue;
430                } 
431
432                new ((*tracks)[nAODtracks++]) AliAODTrack(*tmpTr); 
433                dummy = (*tracks)[nAODtracks-1];
434
435                fh1TrackPt->Fill(tmpTr->Pt());
436                fh2TrackEtaPhi->Fill(tmpTr->Eta(), tmpTr->Phi());
437            }
438
439            if(mcpartIN){
440                Int_t nMCpart = mcpartIN->GetEntriesFast();
441
442                Int_t nPhysicalPrimary=0;
443                Int_t nAODmcpart=0;
444                for(Int_t ip=0; ip<nMCpart; ++ip){
445                    AliAODMCParticle *tmpPart = (AliAODMCParticle*) mcpartIN->At(ip);
446
447                    if(fEmbedMode==kAODJetTracks){
448                       // jet track? else continue
449                       // not implemented yet
450                       continue;
451                    } 
452
453                    new((*mcpartOUT)[nAODmcpart++]) AliAODMCParticle(*tmpPart);
454                    dummy = (*mcpartOUT)[nAODmcpart-1];
455
456                    if(tmpPart->IsPhysicalPrimary() && tmpPart->Charge()!=0. && tmpPart->Charge()!=-99. ){
457                       fh1MCTrackPt->Fill(tmpPart->Pt());
458                       fh2MCTrackEtaPhi->Fill(tmpPart->Eta(), tmpPart->Phi());
459                       nPhysicalPrimary++;
460                    }
461                }
462                fh1MCTrackN->Fill((Float_t)nPhysicalPrimary);
463                
464            }
465        } // end: embed all tracks or jet tracks
466
467
468        if(fEmbedMode==kAODJet4Mom){
469
470            // loop over jets
471            Int_t nJets = aodJets->GetEntries();
472            fh1TrackN->Fill((Float_t)nJets);
473            for(Int_t ij=0; ij<nJets; ++ij){
474                AliAODJet *jet = dynamic_cast<AliAODJet*>(aodJets->At(ij));
475                if(!jet) continue;
476                AliAODTrack *tmpTr = (AliAODTrack*)jet;
477
478                new ((*tracks)[nAODtracks++]) AliAODTrack(*tmpTr);
479                dummy = (*tracks)[nAODtracks-1]; 
480
481                fh1TrackPt->Fill(tmpTr->Pt());
482                fh2TrackEtaPhi->Fill(tmpTr->Eta(), tmpTr->Phi());
483            }
484
485        } // end: embed jets as 4-momenta
486
487
488     } //end: embed mode with AOD
489
490
491     // === embed mode with toy ===
492     if(fEmbedMode==kToyTracks){
493         Int_t nT = (Int_t)(rndm->Uniform(fToyMinNbOfTracks, fToyMaxNbOfTracks)+0.5);
494
495         fh1TrackN->Fill((Float_t)nT);
496
497         for(Int_t i=0; i<nT; ++i){
498
499            Double_t pt = -1.;
500            if(fToyMinTrackPt!=fToyMaxTrackPt){
501               if(fToyDistributionTrackPt==0){
502                  pt = rndm->Uniform(fToyMinTrackPt, fToyMaxTrackPt);
503               } else {
504                  while(pt<fToyMinTrackPt||pt>fToyMaxTrackPt){
505                     pt = rndm->Exp(fToyDistributionTrackPt);   // no power law yet!!
506                     pt += fToyMinTrackPt;
507                  }
508               }
509            } else {
510               pt = fToyMinTrackPt;
511            }
512            Double_t eta = rndm->Uniform(fToyMinTrackEta,fToyMaxTrackEta);
513            Double_t phi = rndm->Uniform(fToyMinTrackPhi,fToyMaxTrackPhi);
514            phi = TVector2::Phi_0_2pi(phi);
515
516            Printf("Add track #%d: pt %.2f, eta %.2f, phi %.2f", i, pt, eta, phi);
517
518            Double_t theta = 2*TMath::ATan(1/TMath::Exp(eta));
519            Float_t mom[3];
520            mom[0] = pt;
521            mom[1] = phi;
522            mom[2] = theta;
523
524            Float_t xyz[3];
525            xyz[0] = -999.;
526            xyz[1] = -999.;
527            xyz[2] = -999.;
528         
529            AliAODTrack *tmpTr = new AliAODTrack( -999,   // id
530                                               -999,   // label
531                                               mom,    // momentum[3]
532                                               kFALSE, // cartesian
533                                               xyz,    // position
534                                               kFALSE, // DCA
535                                               NULL,   // covMatrix,
536                                               -99,    // charge
537                                               0,      // itsClusMap
538                                               NULL,   // pid 
539                                               NULL,   // prodVertex
540                                               kFALSE, // used for vertex fit
541                                               kFALSE, // used for prim vtx fit
542                                               AliAODTrack::kUndef, // type
543                                               fToyFilterMap,  // select info
544                                               -999.    // chi2 per NDF
545                                             );
546            tmpTr->SetFlags(1<<27);
547
548            new((*tracks)[nAODtracks++]) AliAODTrack(*tmpTr);
549            dummy = (*tracks)[nAODtracks-1];
550
551            fh1TrackPt->Fill(pt);
552            fh2TrackEtaPhi->Fill(eta,phi);
553
554            delete tmpTr;
555         }
556     } //end: embed mode with toy
557
558
559     PostData(1, fHistList);
560 }
561
562
563 //__________________________________________________________________________
564 void AliAnalysisTaskFastEmbedding::Terminate(Option_t *)
565 {
566     if(fDebug > 1) Printf("AliAnalysisTaskFastEmbedding::Terminate()");
567
568     if(fAODfile && fAODfile->IsOpen())
569     fAODfile->Close();  
570
571 }
572
573 //__________________________________________________________________________
574 Int_t AliAnalysisTaskFastEmbedding::GetJobID()
575 {
576    Int_t id=-1;
577
578    const char* env = gSystem->Getenv("ALIEN_PROC_ID"); // GRID
579    //if(!env || !strlen(env)) env = gSystem->Getenv("LSB_JOBINDEX"); // GSI
580
581    if(env && strlen(env)){
582        id= atoi(env);
583        AliInfo(Form("Job index %d", id));
584    }
585    else{
586        AliInfo("Job index not found. Okay if running locally.");
587    }
588
589    return id;
590 }
591
592 //__________________________________________________________________________
593
594 Int_t AliAnalysisTaskFastEmbedding::SelectAODfile(){
595
596      Int_t nFiles = fAODPathArray->GetEntries();
597      Int_t n = rndm->Integer(nFiles);
598      AliInfo(Form("Select AOD file %d", n));
599      TObjString *objStr = (TObjString*) fAODPathArray->At(n);
600      if(!objStr){
601           AliError("Could not get path of aod file.");
602           return -1;
603      }
604      fAODPath = objStr->GetString();
605
606      return n;
607 }
608
609 Int_t AliAnalysisTaskFastEmbedding::OpenAODfile(){
610
611     TDirectory *owd = gDirectory;
612     fAODfile = TFile::Open(fAODPath.Data());
613     owd->cd();
614     if(!fAODfile){
615        AliError("Could not open AOD file.");
616        return -1;
617     }
618
619     fAODtree = (TTree*)fAODfile->Get("aodTree");
620
621     if(!fAODtree){
622        AliError("AOD tree not found.");
623        return -1;
624     }
625
626     fAODevent = new AliAODEvent();
627     fAODevent->ReadFromTree(fAODtree);
628     if(!fAODevent){
629        AliError("AOD event not found.");
630        return -1;
631     }
632
633     return 1;
634 }
635