Example macros (Markus, Federico)
[u/mrichter/AliRoot.git] / STEER / ReadAOD.C
CommitLineData
e2a21448 1void ReadAOD(const char *fileName = "AliAOD.root") {
2
3 // open input file and get the TTree
4 TFile inFile(fileName, "READ");
5 TTree *aodTree = (TTree*)inFile.Get("AOD");
6
7 AliAODEvent *aod = aodTree->GetUserInfo()->FindObject("AliAODEvent");
8 TIter next(aod->GetList());
9 TNamed *el;
10 while(el=(TNamed*)next())
11 aodTree->SetBranchAddress(el->GetName(),aod->GetList()->GetObjectRef(el));
12
13 // loop over events
14 Int_t nEvents = aodTree->GetEntries();
15 for (Int_t nEv = 0; nEv < nEvents; nEv++) {
16 cout << "Event: " << nEv+1 << "/" << nEvents << endl;
17
18 // read events
19 aodTree->GetEvent(nEv);
20
21 // set pointers
22 aod->GetStdContent();
23
24 //print event info
25 aod->GetHeader()->Print();
26
27 // loop over tracks
28 Int_t nTracks = aod->GetNTracks();
29 for (Int_t nTr = 0; nTr < nTracks; nTr++) {
30
31 // print track info
32 cout << nTr+1 << "/" << nTracks << ": track pt: " << aod->GetTrack(nTr)->Pt() << ", vertex x of this track: " << aod->GetTrack(nTr)->GetProdVertex()->GetX() << endl;
33 }
34
35 // loop over vertices
36 Int_t nVtxs = aod->GetNVertices();
37 for (Int_t nVtx = 0; nVtx < nVtxs; nVtx++) {
38
39 // print track info
40 cout << nVtx+1 << "/" << nVtxs << ": vertex z position: " << aod->GetVertex(nVtx)->GetZ() << endl;
41 }
42 }
43
44 return;
45}