]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenReaderEcalJets.cxx
Handle missing rec-point tree in a uniform way: return null pointer to TEvePointSet.
[u/mrichter/AliRoot.git] / EVGEN / AliGenReaderEcalJets.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 /* $Id$ */
17 //
18 // Realisation of AliGenReader to be used with AliGenExtFile
19 // It reads Pythia Jet events from a ntuple like event structure.
20 // The event format is defined in Init()
21 // NextEvent() is used to loop over events and NextParticle() to loop over particles.  
22 // Author: andreas.morsch@cern.ch
23 //
24 #include <TFile.h>
25 #include <TParticle.h>
26 #include <TTree.h>
27
28 #include "AliGenReaderEcalJets.h"
29
30 ClassImp(AliGenReaderEcalJets)
31
32
33 AliGenReaderEcalJets::AliGenReaderEcalJets():
34     fNcurrent(0),
35     fNparticle(0),
36     fNev(0),
37     fNpart(0),
38     fNjet(0),     
39     fNsjet(0),
40     fNpjet(0),
41     fTreeNtuple(0) 
42 {
43 // Default constructor
44 }
45
46  AliGenReaderEcalJets::AliGenReaderEcalJets(const AliGenReaderEcalJets &reader)
47      :AliGenReader(reader),
48       fNcurrent(0),
49       fNparticle(0),
50       fNev(0),
51       fNpart(0),
52       fNjet(0),     
53       fNsjet(0),
54       fNpjet(0),
55       fTreeNtuple(0) 
56 {
57     // Copy Constructor
58     reader.Copy(*this);
59 }
60
61 void AliGenReaderEcalJets::Init() 
62 {
63 //
64 // reset the existing file environment and open a new root file if
65 // the pointer to the Fluka tree is null
66     
67     TFile *pFile=0;
68     if (!pFile) {
69         pFile = new TFile(fFileName);
70         pFile->cd();
71         printf("\n I have opened %s file \n", fFileName);
72     }
73 // get the tree address in the Fluka boundary source file
74     fTreeNtuple = (TTree*)gDirectory->Get("h1");
75     TTree *h1=fTreeNtuple;
76     h1->SetMakeClass(1);
77 //Set branch addresses
78     h1->SetBranchAddress("nev",   &fNev);
79     h1->SetBranchAddress("x",      fX);
80     h1->SetBranchAddress("xtyp",   fXtyp);
81     h1->SetBranchAddress("npart", &fNpart);
82     h1->SetBranchAddress("xpt",    fXpt);
83     h1->SetBranchAddress("xeta",   fXeta);
84     h1->SetBranchAddress("xphi",   fXphi);
85     h1->SetBranchAddress("xid",    fXid);
86     h1->SetBranchAddress("njet",  &fNjet);
87     h1->SetBranchAddress("jet",    fJet);
88     h1->SetBranchAddress("jeta",   fJeta);
89     h1->SetBranchAddress("jphi",   fJphi);
90     h1->SetBranchAddress("nsjet", &fNsjet);
91     h1->SetBranchAddress("jset",   fJset);
92     h1->SetBranchAddress("jseta",  fJseta);
93     h1->SetBranchAddress("jsphi",  fJsphi);
94     h1->SetBranchAddress("npjet", &fNpjet);
95     h1->SetBranchAddress("jpet",   fJpet);
96     h1->SetBranchAddress("jpeta",  fJpeta);
97     h1->SetBranchAddress("jpphi",  fJpphi);
98 }
99
100 Int_t AliGenReaderEcalJets::NextEvent() 
101 {
102 // Read the next event  
103     Int_t nTracks=0, nread=0;
104     
105     TFile* pFile = fTreeNtuple->GetCurrentFile();
106     pFile->cd();
107
108     Int_t nentries = (Int_t) fTreeNtuple->GetEntries();
109     if (fNcurrent < nentries) {
110         Int_t nb = (Int_t)fTreeNtuple->GetEvent(fNcurrent);
111         nread += nb;
112         fNcurrent++;
113         printf("\n Next event contains %d tracks! \n", fNpjet);
114         nTracks    = fNpjet;
115         fNparticle = 0;
116         return nTracks;
117     }
118     return 0;
119 }
120
121 TParticle* AliGenReaderEcalJets::NextParticle() 
122 {
123 // Read the next particle
124
125     Float_t p[4];
126     Int_t    ipart  = fXid[fNparticle];
127     Float_t  pt     = fXpt[fNparticle];
128     Float_t  eta    = fXeta[fNparticle];
129     Float_t  phi    = fXphi[fNparticle];
130     Float_t  theta  = 2.*TMath::ATan(TMath::Exp(-eta));
131     Double_t amass  = TDatabasePDG::Instance()->GetParticle(ipart)->Mass();
132
133     p[0] = pt*TMath::Sin(phi);
134     p[1] = pt*TMath::Cos(phi);      
135     p[2] = pt/TMath::Cos(theta);
136     p[3] = TMath::Sqrt(pt*pt+p[2]*p[2]+amass*amass);
137     
138
139     TParticle* particle = 
140         new TParticle(ipart, 0, -1, -1, -1, -1, p[0], p[1], p[2], p[3], 
141                       0., 0., 0., 0.);
142     fNparticle++;
143     return particle;
144 }
145
146
147
148 AliGenReaderEcalJets& AliGenReaderEcalJets::operator=(const  AliGenReaderEcalJets& rhs)
149 {
150 // Assignment operator
151     rhs.Copy(*this);
152     return (*this);
153 }
154
155 void AliGenReaderEcalJets::Copy(TObject&) const
156 {
157     //
158     // Copy 
159     //
160     Fatal("Copy","Not implemented!\n");
161 }
162
163
164
165
166
167
168