Line data Source code
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 : /* $Id$ */
18 :
19 : // Read the old ALICE event format based on CW-ntuples
20 : // http://consult.cern.ch/alice/Internal_Notes/1995/32/abstract
21 : // .cwn file have to be converted to .root using h2root
22 : // Use SetFileName(file) to read from "file"
23 : // Author: andreas.morsch@cern.ch
24 :
25 : #include <TFile.h>
26 : #include <TParticle.h>
27 : #include <TDatabasePDG.h>
28 : #include <TTree.h>
29 : #include <TVirtualMC.h>
30 :
31 : #include "AliGenReaderCwn.h"
32 :
33 6 : ClassImp(AliGenReaderCwn)
34 :
35 0 : AliGenReaderCwn::AliGenReaderCwn():
36 0 : fNcurrent(0),
37 0 : fNparticle(0),
38 0 : fNparticleMax(0),
39 0 : fTreeNtuple(0),
40 0 : fNihead(0),
41 0 : fNrhead(0),
42 0 : fIdpart(0),
43 0 : fTheta(0.),
44 0 : fPhi(0.),
45 0 : fP(0.),
46 0 : fE(0.)
47 0 : {
48 : // Default constructor
49 : Int_t i;
50 0 : for (i = 0; i < 6; i++) fRhead[i] = 0.;
51 0 : for (i = 0; i < 12; i++) fIhead[i] = 0;
52 0 : }
53 :
54 :
55 : AliGenReaderCwn::AliGenReaderCwn(const AliGenReaderCwn &reader):
56 0 : AliGenReader(reader),
57 0 : fNcurrent(0),
58 0 : fNparticle(0),
59 0 : fNparticleMax(0),
60 0 : fTreeNtuple(0),
61 0 : fNihead(0),
62 0 : fNrhead(0),
63 0 : fIdpart(0),
64 0 : fTheta(0.),
65 0 : fPhi(0.),
66 0 : fP(0.),
67 0 : fE(0.)
68 0 : {
69 : // Copy constructor
70 : Int_t i;
71 0 : for (i = 0; i < 6; i++) fRhead[i] = 0.;
72 0 : for (i = 0; i < 12; i++) fIhead[i] = 0;
73 0 : reader.Copy(*this);
74 0 : }
75 :
76 :
77 : AliGenReaderCwn::~AliGenReaderCwn()
78 0 : {
79 0 : delete fTreeNtuple;
80 0 : }
81 :
82 : void AliGenReaderCwn::Init()
83 : {
84 : //
85 : // reset the existing file environment and open a new root file if
86 : // the pointer to the Fluka tree is null
87 :
88 : TFile *pFile=0;
89 0 : if (!pFile) {
90 0 : pFile = new TFile(fFileName);
91 0 : pFile->cd();
92 0 : printf("\n I have opened %s file \n", fFileName);
93 0 : }
94 : // get the tree address in the Fluka boundary source file
95 0 : fTreeNtuple = (TTree*)gDirectory->Get("h888");
96 :
97 : TTree *h2=fTreeNtuple;
98 : //Set branch addresses
99 0 : h2->SetBranchAddress("Nihead",&fNihead);
100 0 : h2->SetBranchAddress("Ihead",fIhead);
101 0 : h2->SetBranchAddress("Nrhead",&fNrhead);
102 0 : h2->SetBranchAddress("Rhead",fRhead);
103 0 : h2->SetBranchAddress("Idpart",&fIdpart);
104 0 : h2->SetBranchAddress("Theta",&fTheta);
105 0 : h2->SetBranchAddress("Phi",&fPhi);
106 0 : h2->SetBranchAddress("P",&fP);
107 0 : h2->SetBranchAddress("E",&fE);
108 0 : }
109 :
110 : Int_t AliGenReaderCwn::NextEvent()
111 : {
112 : // Read the next event
113 : Int_t nTracks;
114 0 : fNparticle = 0;
115 0 : TFile* pFile = fTreeNtuple->GetCurrentFile();
116 0 : pFile->cd();
117 :
118 0 : Int_t nentries = (Int_t) fTreeNtuple->GetEntries();
119 0 : if (fNcurrent < nentries) {
120 0 : fNcurrent++;
121 :
122 0 : Int_t i5=fIhead[4];
123 0 : Int_t i6=fIhead[5];
124 0 : if (i5==0) {
125 0 : printf("\n This should never happen !\n");
126 : nTracks = 0;
127 0 : } else {
128 0 : printf("\n Next event contains %d tracks! \n", i6);
129 : nTracks = i6;
130 : }
131 0 : fNparticleMax = nTracks;
132 : return nTracks;
133 : }
134 :
135 0 : return 0;
136 0 : }
137 :
138 : TParticle* AliGenReaderCwn::NextParticle()
139 : {
140 : // Read next particle
141 : //
142 : Float_t prwn;
143 : Float_t p[4];
144 : // Read the next particle
145 0 : if (fCode == kGEANT3) fIdpart=TVirtualMC::GetMC()->PDGFromId(fIdpart);
146 0 : Double_t amass = TDatabasePDG::Instance()->GetParticle(fIdpart)->Mass();
147 0 : if(fE<=amass) {
148 0 : Warning("Generate","Particle %d E = %f mass = %f %f %f \n",
149 0 : fIdpart,fE,amass, fPhi, fTheta);
150 : prwn=0;
151 0 : } else {
152 0 : prwn=sqrt((fE+amass)*(fE-amass));
153 : }
154 :
155 0 : fTheta *= TMath::Pi()/180.;
156 0 : fPhi = (fPhi-180)*TMath::Pi()/180.;
157 0 : p[0] = prwn*TMath::Sin(fTheta)*TMath::Cos(fPhi);
158 0 : p[1] = prwn*TMath::Sin(fTheta)*TMath::Sin(fPhi);
159 0 : p[2] = prwn*TMath::Cos(fTheta);
160 0 : p[3] = fE;
161 0 : TParticle* particle = new TParticle(fIdpart, 0, -1, -1, -1, -1, p[0], p[1], p[2], p[3], 0., 0., 0., 0.);
162 0 : fNcurrent++;
163 0 : fNparticle++;
164 0 : return particle;
165 0 : }
166 :
167 :
168 :
169 : AliGenReaderCwn& AliGenReaderCwn::operator=(const AliGenReaderCwn& rhs)
170 : {
171 : // Assignment operator
172 0 : rhs.Copy(*this);
173 0 : return *this;
174 : }
175 :
176 : void AliGenReaderCwn::Copy(TObject&) const
177 : {
178 : //
179 : // Copy
180 : //
181 0 : Fatal("Copy","Not implemented!\n");
182 0 : }
183 :
184 :
185 :
186 :
|