]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EVGEN/AliGenExtFile.cxx
Introduce Riostream.h and remove unused variables
[u/mrichter/AliRoot.git] / EVGEN / AliGenExtFile.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.23  2002/10/14 14:55:35  hristov
19 Merging the VirtualMC branch to the main development branch (HEAD)
20
21 Revision 1.20.4.1  2002/06/10 14:57:41  hristov
22 Merged with v3-08-02
23
24 Revision 1.22  2002/05/15 11:59:49  morsch
25 CdEventFile() method added.
26
27 Revision 1.21  2002/04/26 10:39:31  morsch
28 AliGenExtFile derives from AliGenMC. Generate() uses methods from AliGenMC (N. Carrer)
29
30 Revision 1.20  2002/03/22 09:43:28  morsch
31 Don't delete the TParticle.
32
33 Revision 1.19  2002/02/08 16:50:50  morsch
34 Add name and title in constructor.
35
36 Revision 1.18  2001/11/12 14:31:00  morsch
37 Memory leaks fixed. (M. Bondila)
38
39 Revision 1.17  2001/11/09 09:12:58  morsch
40 Generalization by using AliGenReader object to read particles from file.
41
42 Revision 1.16  2001/07/27 17:09:35  morsch
43 Use local SetTrack, KeepTrack and SetHighWaterMark methods
44 to delegate either to local stack or to stack owned by AliRun.
45 (Piotr Skowronski, A.M.)
46
47 Revision 1.15  2001/01/23 13:29:37  morsch
48 Add method SetParticleCode and enum type Code_t to handle both PDG (new ntuples)
49 and GEANT3 codes (old ntuples) in input file.
50
51 Revision 1.14  2000/12/21 16:24:06  morsch
52 Coding convention clean-up
53
54 Revision 1.13  2000/11/30 07:12:50  alibrary
55 Introducing new Rndm and QA classes
56
57 Revision 1.12  2000/10/27 13:54:45  morsch
58 Remove explicite reference to input file from constuctor.
59
60 Revision 1.11  2000/10/02 21:28:06  fca
61 Removal of useless dependecies via forward declarations
62
63 Revision 1.10  2000/07/11 18:24:55  fca
64 Coding convention corrections + few minor bug fixes
65
66 Revision 1.9  2000/06/14 15:20:09  morsch
67 Include clean-up (IH)
68
69 Revision 1.8  2000/06/09 20:36:44  morsch
70 All coding rule violations except RS3 corrected
71
72 Revision 1.7  2000/02/16 14:56:27  morsch
73 Convert geant particle code into pdg code before putting particle on the stack.
74
75 Revision 1.6  1999/11/09 07:38:48  fca
76 Changes for compatibility with version 2.23 of ROOT
77
78 Revision 1.5  1999/09/29 09:24:12  fca
79 Introduction of the Copyright and cvs Log
80
81 */
82
83
84 // Event generator that using an instance of type AliGenReader
85 // reads particles from a file and applies cuts. 
86
87 #include <Riostream.h>
88
89 #include "AliGenExtFile.h"
90 #include "AliRun.h"
91
92 #include <TParticle.h>
93 #include <TFile.h>
94 #include <TTree.h>
95
96
97  ClassImp(AliGenExtFile)
98
99 AliGenExtFile::AliGenExtFile()
100   :AliGenMC()
101 {
102 //  Constructor
103 //
104 //  Read all particles
105     fNpart  =- 1;
106     fReader =  0;
107 }
108
109 AliGenExtFile::AliGenExtFile(Int_t npart)
110     :AliGenMC(npart)
111 {
112 //  Constructor
113     fName   = "ExtFile";
114     fTitle  = "Primaries from ext. File";
115     fReader = 0;
116 }
117
118 AliGenExtFile::AliGenExtFile(const AliGenExtFile & ExtFile)
119 {
120 // copy constructor
121 }
122 //____________________________________________________________
123 AliGenExtFile::~AliGenExtFile()
124 {
125 // Destructor
126     delete fReader;
127 }
128
129 //___________________________________________________________
130 void AliGenExtFile::Init()
131 {
132 // Initialize
133     if (fReader) fReader->Init();
134 }
135
136     
137 void AliGenExtFile::Generate()
138 {
139 // Generate particles
140
141   Float_t polar[3]  = {0,0,0};
142   //
143   Float_t origin[3] = {0,0,0};
144   Float_t p[3];
145   Float_t random[6];
146   Int_t i, j, nt;
147   //
148   for (j=0;j<3;j++) origin[j]=fOrigin[j];
149   if(fVertexSmear == kPerTrack) {
150     Rndm(random,6);
151     for (j = 0; j < 3; j++) {
152         origin[j] += fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
153             TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
154     }
155   }
156
157   while(1) {
158     Int_t nTracks = fReader->NextEvent();       
159     if (nTracks == 0) {
160       // printf("\n No more events !!! !\n");
161       Warning("AliGenExtFile::Generate","\nNo more events in external file!!!\nLast event may be empty or incomplete.\n");
162       return;
163     }
164
165     //
166     // Particle selection loop
167     //
168     // The selction criterium for the external file generator is as follows:
169     //
170     // 1) All tracs are subjects to the cuts defined by AliGenerator, i.e.
171     //    fThetaMin, fThetaMax, fPhiMin, fPhiMax, fPMin, fPMax, fPtMin, fPtMax,
172     //    fYMin, fYMax.
173     //    If the particle does not satisfy these cuts, it is not put on the
174     //    stack.
175     // 2) If fCutOnChild and some specific child is selected (e.g. if
176     //    fForceDecay==kSemiElectronic) the event is rejected if NOT EVEN ONE
177     //    child falls into the child-cuts.
178     if(fCutOnChild) {
179       // Count the selected children
180       Int_t nSelected = 0;
181
182       for (i = 0; i < nTracks; i++) {
183         TParticle* iparticle = fReader->NextParticle();
184         Int_t kf = CheckPDGCode(iparticle->GetPdgCode());
185         kf = TMath::Abs(kf);
186         if (ChildSelected(kf) && KinematicSelection(iparticle, 1)) {
187           nSelected++;
188         }
189       }
190       if (!nSelected) continue;    // No particle selected:  Go to next event
191       fReader->RewindEvent();
192     }
193
194     //
195     // Stack filling loop
196     //
197     for (i = 0; i < nTracks; i++) {
198
199       TParticle* iparticle = fReader->NextParticle();
200       if (!KinematicSelection(iparticle,0)) {
201         Double_t  pz   = iparticle->Pz();
202         Double_t  e    = iparticle->Energy();
203         Double_t  y;
204         if ((e-pz) == 0) {
205           y = 20.;
206         } else if ((e+pz) == 0.) {
207           y = -20.;
208         } else {
209           y = 0.5*TMath::Log((e+pz)/(e-pz));      
210         }
211         printf("\n Not selected %d %f %f %f %f %f", i,
212                iparticle->Theta(),
213                iparticle->Phi(),
214                iparticle->P(),
215                iparticle->Pt(),
216                y);
217         delete iparticle;
218         continue;
219       }
220       p[0] = iparticle->Px();
221       p[1] = iparticle->Py();
222       p[2] = iparticle->Pz();
223       Int_t idpart = iparticle->GetPdgCode();
224       if(fVertexSmear==kPerTrack) {
225           Rndm(random,6);
226           for (j = 0; j < 3; j++) {
227               origin[j]=fOrigin[j]
228                   +fOsigma[j]*TMath::Cos(2*random[2*j]*TMath::Pi())*
229                   TMath::Sqrt(-2*TMath::Log(random[2*j+1]));
230           }
231       }
232       Int_t decayed = iparticle->GetFirstDaughter();
233       Int_t doTracking = fTrackIt && (decayed < 0) &&
234                          (TMath::Abs(idpart) > 10);
235       // printf("*** pdg, first daughter, trk = %d, %d, %d\n",
236       //   idpart,decayed, doTracking);
237       SetTrack(doTracking,-1,idpart,p,origin,polar,0,kPPrimary,nt);
238       KeepTrack(nt);
239     } // track loop
240
241     break;
242
243   } // event loop
244
245   SetHighWaterMark(nt);
246   CdEventFile();
247 }
248
249 void AliGenExtFile::CdEventFile()
250 {
251 // CD back to the event file
252   TFile *pFile=0;
253   if (!gAlice) {
254       gAlice = (AliRun*)pFile->Get("gAlice");
255       if (gAlice) printf("AliRun object found on file\n");
256       if (!gAlice) gAlice = new AliRun("gAlice","Alice test program");
257   }
258   TTree *fAli=gAlice->TreeK();
259   if (fAli) pFile =fAli->GetCurrentFile();
260   pFile->cd();    
261 }
262
263
264 AliGenExtFile& AliGenExtFile::operator=(const  AliGenExtFile& rhs)
265 {
266 // Assignment operator
267     return *this;
268 }
269
270
271
272
273
274
275
276