]> git.uio.no Git - u/mrichter/AliRoot.git/blob - STEER/AliAODEvent.cxx
First version of kdtree (Alexander, Marian)
[u/mrichter/AliRoot.git] / STEER / AliAODEvent.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-2007, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16 /* $Id$ */
17
18 //-------------------------------------------------------------------------
19 //     AOD base class
20 //     Author: Markus Oldenburg, CERN
21 //-------------------------------------------------------------------------
22
23 #include <TTree.h>
24
25 #include "AliAODEvent.h"
26 #include "AliAODHeader.h"
27 #include "AliAODTrack.h"
28
29 ClassImp(AliAODEvent)
30
31 //______________________________________________________________________________
32 AliAODEvent::AliAODEvent() :
33   fAODObjects(new TList()),
34   fHeader(0),
35   fTracks(0),
36   fVertices(0),
37   fClusters(0),
38   fJets(0),
39   fTracklets(0)
40 {
41   // default constructor
42 }
43
44 //______________________________________________________________________________
45 AliAODEvent::~AliAODEvent() 
46 {
47 // destructor
48     delete fAODObjects;
49 }
50
51 //______________________________________________________________________________
52 void AliAODEvent::AddObject(TObject* obj) 
53 {
54   // Add an object to the list of object.
55   // Please be aware that in order to increase performance you should
56   // refrain from using TObjArrays (if possible). Use TClonesArrays, instead.
57   
58   fAODObjects->AddLast(obj);
59 }
60
61 //______________________________________________________________________________
62 TObject *AliAODEvent::GetObject(const char *objName) const 
63 {
64   // Return the pointer to the object with the given name.
65
66   return fAODObjects->FindObject(objName);
67 }
68
69 //______________________________________________________________________________
70 void AliAODEvent::CreateStdContent() 
71 {
72   // create the standard AOD content and set pointers
73
74   // create standard objects and add them to the TList of objects
75   AddObject(new AliAODHeader());
76   AddObject(new TClonesArray("AliAODTrack", 0));
77   AddObject(new TClonesArray("AliAODVertex", 0));
78   AddObject(new TClonesArray("AliAODCluster", 0));
79   AddObject(new TClonesArray("AliAODJet", 0));
80   AddObject(new AliAODTracklets());
81
82   // read back pointers
83   GetStdContent();
84
85   // set names
86   fTracks->SetName("tracks");
87   fVertices->SetName("vertices");
88   fClusters->SetName("clusters");
89   fJets->SetName("jets");
90   fTracklets->SetName("tracklets");     
91 }
92
93 //______________________________________________________________________________
94 void AliAODEvent::GetStdContent()
95 {
96   // set pointers for standard content
97
98   fHeader    = (AliAODHeader*)fAODObjects->At(0);
99   fTracks    = (TClonesArray*)fAODObjects->At(1);
100   fVertices  = (TClonesArray*)fAODObjects->At(2);
101   fClusters  = (TClonesArray*)fAODObjects->At(3);
102   fJets      = (TClonesArray*)fAODObjects->At(4);
103   fTracklets = (AliAODTracklets*)fAODObjects->At(5);
104 }
105
106 //______________________________________________________________________________
107 void AliAODEvent::ResetStd(Int_t trkArrSize, Int_t vtxArrSize)
108 {
109   // deletes content of standard arrays and resets size
110   fTracks->Delete();
111   if (trkArrSize > fTracks->GetSize()) 
112     fTracks->Expand(trkArrSize);
113
114   fVertices->Delete();
115   if (vtxArrSize > fVertices->GetSize()) 
116     fVertices->Expand(vtxArrSize);
117 }
118
119 void AliAODEvent::ClearStd()
120 {
121   // clears the standard arrays
122     fTracks   ->Clear();
123     fVertices ->Clear();
124     fClusters ->Clear();
125     fJets     ->Clear();
126     fTracklets->DeleteContainer();
127 }
128
129 //______________________________________________________________________________
130 Int_t AliAODEvent::GetMuonTracks(TRefArray *muonTracks) const
131 {
132   // fills the provided TRefArray with all found muon tracks
133
134   muonTracks->Clear();
135
136   AliAODTrack *track = 0;
137   for (Int_t iTrack = 0; iTrack < GetNTracks(); iTrack++) {
138     if ((track = GetTrack(iTrack))->GetMostProbablePID() == AliAODTrack::kMuon) {
139       muonTracks->Add(track);
140     }
141   }
142   
143   return muonTracks->GetSize();
144 }
145
146
147
148 void AliAODEvent::ReadFromTree(TTree *tree)
149 {
150     // connects aod event to tree
151
152     fAODObjects = (TList*)((AliAODEvent*)tree->GetTree()->GetUserInfo()->FindObject("AliAODEvent"))->GetList(); 
153     TIter next(fAODObjects);
154     TNamed *el;
155     while((el=(TNamed*)next())){
156         TString bname(el->GetName());
157         tree->SetBranchAddress(bname.Data(),fAODObjects->GetObjectRef(el));
158     }
159     GetStdContent();
160 }
161