]> git.uio.no Git - u/mrichter/AliRoot.git/blob - EPOS/TEpos.cxx
Coverity 16763 Out-of-bounds access corrected.
[u/mrichter/AliRoot.git] / EPOS / TEpos.cxx
1 //
2 //###################################################################
3 //#        EPOS 1.67     K. WERNER, T. PIEROG, S. PORTEBOEUF.       #
4 //#                      Contact: werner@subatech.in2p3.fr          #
5 //###################################################################
6 //
7 // TEpos.cxx
8 // 
9 // Wraper class for interfacing EPOS model, derived from ROOT's TGenerator.
10 // It generates temporary input file for the model, providing user with
11 // ability to add his/hers own lines to the input.
12 // Output is read directly from common blocks.
13 //
14 //      Author: Piotr Ostrowski, postrow@if.pw.edu.pl
15 //
16
17
18 #include <TClonesArray.h>
19 #include <TDatabasePDG.h>
20 #include <TObjArray.h>
21 #include <TParticle.h>
22 #include <TROOT.h>
23 #include <TRandom.h>
24 #include <TMath.h>
25 #include <iostream>
26 #include <fstream>
27 #include <string>
28 #include <vector>
29 #include "eposproc.h"
30 #include "EPOScommon.h"
31 #include "AliGenEposIsajetToPdgConverter.h"
32 #include "TEpos.h"
33
34 using namespace std;
35
36 ClassImp(TEpos)
37
38 TEpos::TEpos()  : TGenerator("EPOS", "Epos event generator"),
39                 fLaproj(0),
40                 fMaproj(0),
41                 fLatarg(0),
42                 fMatarg(0),
43                 fBminim(0.0),
44                 fBmaxim(10000.0),
45                 fPhimin(0.0),
46                 fPhimax(TMath::TwoPi()),
47                 fEcms(-1),
48                 fSplitting(kFALSE),
49                 fNoDecays(),
50                 fExtraInputLines(),
51                 fIdConverter()
52 {
53         fIdConverter=new AliGenEposIsajetToPdgConverter();
54 }
55
56 TEpos::TEpos(const TEpos&)  : TGenerator("EPOS", "Epos event generator"),
57                 fLaproj(0),
58                 fMaproj(0),
59                 fLatarg(0),
60                 fMatarg(0),
61                 fBminim(0.0),
62                 fBmaxim(10000.0),
63                 fPhimin(0.0),
64                 fPhimax(TMath::TwoPi()),
65                 fEcms(-1),
66                 fSplitting(kFALSE),
67                 fNoDecays(),
68                 fExtraInputLines(),
69                 fIdConverter()
70 {
71         fIdConverter = new AliGenEposIsajetToPdgConverter();
72 }
73
74 TEpos::~TEpos() {
75         delete fIdConverter;
76 }
77
78 TEpos& TEpos::operator=(const TEpos&) {
79   //operator=
80         if (!fIdConverter) {
81                 fIdConverter = new AliGenEposIsajetToPdgConverter();
82         }
83         return *this;
84 }
85
86 void TEpos::Initialize() {
87   // Generates input file and prepares EPOS to read from it.
88         Int_t nopeno = 0;
89         GenerateInputFile();
90         aaset(0);
91         atitle();
92         xiniall();
93
94         const char *inputFileName = GetInputFileName();
95         Int_t nameLength = strlen(inputFileName);
96         setinp(inputFileName, nameLength, nameLength);
97         aread();
98         while(copen.nopen == -1) {
99                 copen.nopen=nopeno;
100             prnt1.iecho=1;
101                 xiniall();
102             aread();
103         }
104         Int_t ishini;
105         utpri("aamain",prnt1.ish,ishini,4,6);
106         if(appli.model != 1)
107                 IniModel(appli.model);
108         ebin.nrebin = 1;
109         ainit();
110         aseed(2);
111 }
112
113 void TEpos::GenerateEvent() {
114 //      cseed.seedj = gRandom->Rndm() * 1e10;
115         Int_t n = 1;
116         evgen(n);
117 }
118
119 Int_t TEpos::ImportParticles(TClonesArray *particles, Option_t *) {
120   //Fills provided ClonesArray with generated particles
121         particles->Clear();
122         if (!cevt.nevt) return 0;
123         Int_t numpart = cptl.nptl;
124         printf("%d particles generated\n", numpart);
125         for (Int_t iPart=0; iPart<numpart; iPart++) {
126                 Int_t tFather = cptl.iorptl[iPart] - 1;
127                 tFather = tFather < -1 ? -1 : tFather;
128                 if (tFather> -1) {
129                         TParticle *mother = (TParticle*) (particles->UncheckedAt(tFather));
130                         mother->SetLastDaughter(iPart);
131                         if (mother->GetFirstDaughter()==-1)
132                                 mother->SetFirstDaughter(iPart);
133                 }
134                 Int_t status = cptl.istptl[iPart] + 1;
135                 Int_t pdg = fIdConverter->ConvertIsajetToPdg(cptl.idptl[iPart]);
136                 new((*particles)[iPart]) TParticle(pdg, status,
137                                  tFather, -1, -1, -1,
138                                  cptl.pptl[iPart][0], cptl.pptl[iPart][1],cptl.pptl[iPart][2],cptl.pptl[iPart][3],
139                                  cptl.xorptl[iPart][0]*1.e-12, cptl.xorptl[iPart][1]*1.e-12, cptl.xorptl[iPart][2]*1.e-12, cptl.xorptl[iPart][3]*1e-12);
140                 (*particles)[iPart]->SetUniqueID(iPart);
141         }
142
143         return numpart;
144 }
145
146 TObjArray*  TEpos::ImportParticles(Option_t *) {
147   //Creates new particle array
148         fParticles->Clear();
149         if (!cevt.nevt) return NULL;
150         Int_t numpart = cptl.nptl;
151         printf("%d particles generated\n", numpart);
152         for (Int_t iPart=0; iPart<numpart; iPart++) {
153                 Int_t tFather = cptl.iorptl[iPart] - 1;
154                 tFather = tFather < -1 ? -1 : tFather;
155                 if (tFather> -1) {
156                         TParticle *mother = (TParticle*) (fParticles->UncheckedAt(tFather));
157                         mother->SetLastDaughter(iPart);
158                         if (mother->GetFirstDaughter()==-1)
159                                 mother->SetFirstDaughter(iPart);
160                 }
161                 Int_t status = cptl.istptl[iPart] + 1;
162                 Int_t pdg = fIdConverter->ConvertIsajetToPdg(cptl.idptl[iPart]);
163                 TParticle* p = new TParticle(pdg, status,
164                                  tFather, -1, -1, -1,
165                                  cptl.pptl[iPart][0], cptl.pptl[iPart][1],cptl.pptl[iPart][2],cptl.pptl[iPart][3],
166                                  cptl.xorptl[iPart][0]*1.e-12, cptl.xorptl[iPart][1]*1.e-12, cptl.xorptl[iPart][2]*1.e-12, cptl.xorptl[iPart][3]*1e-12);
167                 p->SetUniqueID(iPart);
168                 fParticles->Add(p);
169         }
170
171         return fParticles;
172 }
173
174 void TEpos::AddNoDecay(Int_t nodecay) {
175         fNoDecays.push_back(nodecay);
176 }
177
178 void TEpos::AddExtraInputLine(const char *line) {
179         fExtraInputLines.push_back(line);
180 }
181
182 void TEpos::GenerateInputFile() {
183   // Generate input file in EPOS format
184         ofstream file(GetInputFileName(), ios_base::out | ios_base::trunc);
185         char epo[256];
186         char *epoEnv = getenv("EPO");
187         if (epoEnv) {
188                 strncpy(epo, epoEnv, 255);
189         } else {
190                 strncpy(epo, getenv("ALICE_ROOT"), 255);
191         }
192         strncat(epo, "/EPOS/epos167", 255);
193
194         file << "fname pathnx " << epo << "/" << endl;
195         file << "fname histo none" << endl;
196         file << "fname copy none" << endl;
197         file << "fname log none" << endl;
198         file << "fname check none" << endl;
199 //      file << "fname data /tmp/epos.out" << endl;
200         file << "fname initl " << epo << "/epos.initl" << endl;
201         file << "fname inidi " << epo << "/epos.inidi" << endl;
202         file << "fname inidr " << epo << "/epos.inidr" << endl;
203         file << "fname iniev " << epo << "/epos.iniev" << endl;
204         file << "fname inirj " << epo << "/epos.inirj" << endl;
205         file << "fname inics " << epo << "/epos.inics" << endl;
206         file << "fname inigrv " << epo << "/epos.inigrv" << endl;
207         file << "fqgsjet dat " << epo << "/qgsjet/qgsjet.dat" << endl;
208         file << "fqgsjet ncs " << epo << "/qgsjet/qgsjet.ncs" << endl;
209         file << "fqgsjetII dat " << epo << "/qgsjetII/qgsdat-II-03" << endl;
210         file << "fqgsjetII ncs " << epo << "/qgsjetII/sectnu-II-03" << endl;
211         file << "nodecay 120" << endl;
212         file << "nodecay -120" << endl;
213         file << "nodecay 130" << endl;
214         file << "nodecay -130" << endl;
215         file << "nodecay -20" << endl;
216         file << "nodecay 20" << endl;
217         file << "nodecay 14" << endl;
218         file << "nodecay -14" << endl;
219         file << "set ndecay 1111110" << endl;
220         file << "echo on" << endl;
221
222 //      .optns file
223         int precision = file.precision();
224         file.precision(15);
225         file << "set seedj " << (gRandom->Rndm() * 1e14) << endl;
226         file.precision(precision);
227         file << "application hadron" << endl;
228         file << "set laproj " << fLaproj << endl;
229         file << "set maproj " << fMaproj << endl;
230         file << "set latarg " << fLatarg << endl;
231         file << "set matarg " << fMatarg << endl;
232         file << "set bminim " << fBminim << endl;
233         file << "set bmaxim " << fBmaxim << endl;
234         file << "set phimin " << fPhimin << endl;
235         file << "set phimax " << fPhimax << endl;
236         file << "set ecms " << fEcms << endl;
237
238         for(unsigned int i = 0; i < fNoDecays.size(); ++i) {
239                 file << "nodecay " << fNoDecays[i] << endl;
240         }
241
242         file << "switch splitting " << (fSplitting ? "on" : "off") << endl;
243
244         file << "frame nucleon-nucleon" << endl;
245
246         for(unsigned int i = 0; i < fExtraInputLines.size(); ++i) {
247                 file << fExtraInputLines[i] << endl;
248         }
249
250 //    file << "output epos" << endl;
251 //    file << "record event nevt nptl b endrecord" << endl;
252 //    file << "record particle i id fa mo c1 c2 st endrecord" << endl;
253
254         file << "input " << epo << "/epos.param" << endl;
255         file << "runprogram" << endl;
256         file.close();
257 }
258
259 Float_t TEpos::GetBimevt() const { return cevt.bimevt; }
260 Float_t TEpos::GetPhievt() const { return cevt.phievt; }
261 Int_t TEpos::GetKolevt() const { return cevt.kolevt; }
262 Int_t TEpos::GetKoievt() const { return cevt.koievt; }
263 Float_t TEpos::GetPmxevt() const { return cevt.pmxevt; }
264 Float_t TEpos::GetEgyevt() const { return cevt.egyevt; }
265 Int_t TEpos::GetNpjevt() const { return cevt.npjevt; }
266 Int_t TEpos::GetNtgevt() const { return cevt.ntgevt; }
267 Int_t TEpos::GetNpnevt() const { return cevt.npnevt; }
268 Int_t TEpos::GetNppevt() const { return cevt.nppevt; }
269 Int_t TEpos::GetNtnevt() const { return cevt.ntnevt; }
270 Int_t TEpos::GetNtpevt() const { return cevt.ntpevt; }
271 Int_t TEpos::GetJpnevt() const { return cevt.jpnevt; }
272 Int_t TEpos::GetJppevt() const { return cevt.jppevt; }
273 Int_t TEpos::GetJtnevt() const { return cevt.jtnevt; }
274 Int_t TEpos::GetJtpevt() const { return cevt.jtpevt; }
275 Float_t TEpos::GetXbjevt() const { return cevt.xbjevt; }
276 Float_t TEpos::GetQsqevt() const { return cevt.qsqevt; }
277 Int_t TEpos::GetNglevt() const { return cevt.nglevt; }
278 Float_t TEpos::GetZppevt() const { return cevt.zppevt; }
279 Float_t TEpos::GetZptevt() const { return cevt.zptevt; }
280