]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenReaderTreeK.cxx
New class used for primary vertex finding (AliITSVertexerTracks)
[u/mrichter/AliRoot.git] / EVGEN / AliGenReaderTreeK.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, 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 /*
17 $Log$
18 Revision 1.4.4.1  2002/06/10 14:57:41  hristov
19 Merged with v3-08-02
20
21 Revision 1.5  2002/04/26 10:37:23  morsch
22 Method RewindEvent() added. (N. Carrer)
23
24 Revision 1.4  2002/03/22 08:25:33  morsch
25 TreeE connected correctly.
26
27 Revision 1.3  2001/12/12 11:21:37  morsch
28 Dummy copy constructor added.
29
30 Revision 1.2  2001/11/12 14:31:00  morsch
31 Memory leaks fixed. (M. Bondila)
32
33 Revision 1.1  2001/11/09 09:11:24  morsch
34 Realisation of AliGenReader that reads the kine tree (TreeK).
35
36 */
37 #include <TFile.h>
38 #include <TTree.h>
39 #include <TParticle.h>
40
41 #include "AliGenReaderTreeK.h"
42 #include "AliStack.h"
43 #include "AliHeader.h"
44 #include "AliRun.h"
45
46 ClassImp(AliGenReaderTreeK);
47
48
49 AliGenReaderTreeK::AliGenReaderTreeK():AliGenReader() 
50 {
51 //  Default constructor
52     fFileName       = NULL;
53     fStack          = 0;
54     fHeader         = 0;
55     fNcurrent       = 0;
56     fNparticle      = 0;
57     fFile           = 0;
58     fBaseFile       = 0;
59     fTreeE          = 0;
60 }
61
62 AliGenReaderTreeK::AliGenReaderTreeK(const AliGenReaderTreeK &reader)
63 {
64     ;
65 }
66
67
68 AliGenReaderTreeK::~AliGenReaderTreeK() 
69 {
70 // Destructor
71     delete fTreeE;
72 }
73
74 void AliGenReaderTreeK::Init() 
75 {
76 // Initialization
77 // Connect base file and file to read from
78
79     TTree *ali = gAlice->TreeE();
80     if (ali) {
81         fBaseFile = ali->GetCurrentFile();
82     } else {
83         printf("\n Warning: Basefile cannot be found !\n");
84     }
85     if (!fFile) fFile  = new TFile(fFileName);
86 }
87
88 Int_t AliGenReaderTreeK::NextEvent() 
89 {
90 //  Read the next event  
91 //  cd to file with old kine tree    
92     if (!fBaseFile) Init();
93     fFile->cd();
94 //  Connect header tree
95     if (!fTreeE) fTreeE = (TTree*)gDirectory->Get("TE");
96     if (fHeader) delete fHeader;
97     fHeader = 0;
98     fTreeE->SetBranchAddress("Header", &fHeader);
99 //  Get next event
100     fTreeE->GetEntry(fNcurrent);
101 //  Connect Stack
102     if (fStack) delete fStack;
103     fStack = fHeader->Stack();
104     fStack->GetEvent(fNcurrent);
105 //  cd back to base file
106     fBaseFile->cd();
107 //
108     fNcurrent++;
109     fNparticle = 0;
110     Int_t ntrack =  fStack->GetNtrack();
111     printf("\n Next event contains %d particles", ntrack);
112 //    
113     return  ntrack;
114 }
115
116 TParticle* AliGenReaderTreeK::NextParticle() 
117 {
118 //  Return next particle
119     TParticle* part = fStack->Particle(fNparticle);
120     fNparticle++;
121     return part;
122 }
123
124 void AliGenReaderTreeK::RewindEvent()
125 {
126   // Go back to the first particle of the event
127   fNparticle = 0;
128 }
129
130
131 AliGenReaderTreeK& AliGenReaderTreeK::operator=(const  AliGenReaderTreeK& rhs)
132 {
133 // Assignment operator
134     return *this;
135 }
136
137
138