ReaderESDtree, MUON analysis, reading MUON data froESD in ReaderESD (Christian FINCK)
[u/mrichter/AliRoot.git] / ANALYSIS / AliReaderAOD.cxx
1 #include "AliReaderAOD.h"
2
3 ClassImp(AliReaderAOD)
4
5 #include <TError.h>
6 #include <TFile.h>
7 #include <TTree.h>
8 #include "AliAOD.h"
9
10 Int_t AliReaderAOD::WriteAOD(AliReader* reader, const char* outfilename, const char* pclassname,  Bool_t /*multcheck*/)
11 {
12 //reads tracks from runs and writes them to file
13   ::Info("AliReaderAOD::Write","________________________________________________________");
14   ::Info("AliReaderAOD::Write","________________________________________________________");
15   ::Info("AliReaderAOD::Write","________________________________________________________");
16   
17   if (reader == 0x0)
18    {
19      ::Error("AliReaderAOD::Write","Input Reader is NULL");
20      return -1;
21    }
22   TFile *outfile = TFile::Open(outfilename,"recreate");
23   if (outfile == 0x0)
24    {
25      ::Error("AliReaderAOD::Write","Can not open output file %s",outfilename);
26      return -1;
27    }
28
29   TTree *tree = new TTree("TAOD","Tree with tracks");
30   
31   TBranch *recbranch = 0x0, *simbranch = 0x0;
32   
33   
34   AliAOD* eventrec = new AliAOD();//must be created before Branch is called. Otherwise clones array is not splitted
35   AliAOD* eventsim = new AliAOD();//AOD together with fParticles clones array knowing exact type of particles
36   
37   eventrec->SetParticleClassName(pclassname);
38   eventsim->SetParticleClassName(pclassname);
39   
40   if (reader->ReadsRec()) recbranch = tree->Branch("reconstructed","AliAOD",&eventrec,32000,99);
41   if (reader->ReadsSim()) simbranch = tree->Branch("simulated","AliAOD",&eventsim,32000,99);
42
43   delete eventsim;
44   delete eventrec;
45   
46   reader->Rewind();
47   while (reader->Next() == kFALSE)
48    {
49      
50      if (reader->ReadsRec())
51       {
52         eventrec = reader->GetEventRec();
53         recbranch->SetAddress(&eventrec);
54       }
55
56      if (reader->ReadsSim())
57       {
58         eventsim = reader->GetEventSim();
59         simbranch->SetAddress(&eventsim);
60       }
61      eventrec->GetParticle(0)->Print();
62      eventsim->GetParticle(0)->Print();
63      tree->Fill();
64    }
65   
66   ::Info("AliReaderAOD::Write","Written %d events",tree->GetEntries());
67   outfile->cd();
68   tree->Write();
69   delete tree;
70   delete outfile;
71   return 0; 
72 }
73