]> git.uio.no Git - u/mrichter/AliRoot.git/blame - STARLIGHT/starlight/src/.svn/text-base/starlightpythia.cpp.svn-base
STARLIGHT code and interface
[u/mrichter/AliRoot.git] / STARLIGHT / starlight / src / .svn / text-base / starlightpythia.cpp.svn-base
CommitLineData
da32329d
AM
1/*
2 <one line to give the library's name and an idea of what it does.>
3 Copyright (C) 2011 Oystein Djuvsland <oystein.djuvsland@gmail.com>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18*/
19
20#include <cstdio>
21#include <iostream>
22#include "starlightpythia.h"
23#include "pythiaInterface.h"
24#include "spectrumprotonnucleus.h"
25#include <cmath>
26#include <sstream>
27
28starlightPythia::starlightPythia(beamBeamSystem& bbsystem) : eventChannel(bbsystem)
29 ,_spectrum(0)
30 ,_doDoubleEvent(false)
31 ,_minGammaEnergy(inputParametersInstance.minGammaEnergy())
32 ,_maxGammaEnergy(inputParametersInstance.maxGammaEnergy())
33 ,_fullEventRecord(false)
34{
35}
36
37starlightPythia::~starlightPythia()
38{
39
40}
41
42int starlightPythia::init(std::string pythiaParams, bool fullEventRecord)
43{
44 _fullEventRecord = fullEventRecord;
45 _spectrum = new spectrumProtonNucleus(&_bbs);
46 //_spectrum = new Spectrum(&bbs);
47
48 _spectrum->setMinGammaEnergy(_minGammaEnergy);
49 _spectrum->setMaxGammaEnergy(_maxGammaEnergy);
50
51 if(!_doDoubleEvent)
52 {
53 _spectrum->generateKsingle();
54 }
55 else
56 {
57 _spectrum->generateKdouble();
58 }
59
60 // Set to run with varying energies
61 pythiaInterface::pygive("mstp(171)=1"); // Varying energies
62 pythiaInterface::pygive("mstp(172)=1"); // Set the energy before generation
63
64 std::stringstream ss(pythiaParams);
65 std::string p;
66 while(std::getline(ss, p, ';'))
67 {
68 if(p.size()>1)
69 {
70 pythiaInterface::pygive(p.c_str());
71 }
72 }
73 //pythiaInterface::pygive("mstp(12)=0");
74 //pythiaInterface::pygive("mstj(21)=0"); // Disable decays of particles
75
76 //pythiaInterface::pygive("parp(2)=1.0"); // Cut off c.m. energy (GeV)
77
78 pythiaInterface::pyinit("FIXT", "gamma", "p", _maxGammaEnergy); // Fixed target, beam, target, beam momentum (GeV/c)
79
80 return 0;
81}
82
83upcEvent starlightPythia::produceEvent()
84{
85 upcEvent event;
86
87
88
89 if (!_doDoubleEvent)
90 {
91 //int zdirection = (Randy.Rndom()) < 0.5 ? -1 : 1;
92 double gammaE = 0;
93 do
94 {
95 gammaE = _spectrum->drawKsingle();
96 } while(isnan(gammaE));
97 event.addGamma(gammaE);
98
99 char opt[32];
100 std::sprintf(opt, "parp(171)=%f", gammaE/_maxGammaEnergy);
101 pythiaInterface::pygive(opt); // Set the energy of the photon beam (gammaE/1000 * 1000.0);
102 pythiaInterface::pyevnt(); // Generate event
103// pythiaInterface::pyfram(2); // go to CMS
104
105 int zdirection = (_bbs.beam1().Z()==1 ? 1 : -1);
106 double boost = acosh(_bbs.beamLorentzGamma())*zdirection;
107
108 vector3 boostVector(0, 0, tanh(boost));
109
110 for(int idx = 0; idx < pyjets_.n; idx++)
111 {
112// if(std::abs(pyjets_.k[1][idx]) <= 6) std::cout << "Quark: " << pyjets_.k[1][idx] << ", status: " << pyjets_.k[0][idx] << std::endl;
113 if(pyjets_.k[0][idx] > 10 && _fullEventRecord==false) continue;
114 int pdgCode = pyjets_.k[1][idx];
115 int charge = 0;
116 if( pdgCode == 12 || pdgCode == 14 || pdgCode == 16 || pdgCode == 22 || pdgCode == 111 || pdgCode == 130 || pdgCode == 321 || pdgCode == 2112)
117 {
118 charge = 0;
119 }
120 else
121 {
122 charge = (pdgCode > 0) - (pdgCode < 0);
123 }
124
125 starlightParticle particle(pyjets_.p[0][idx], pyjets_.p[1][idx], -zdirection*pyjets_.p[2][idx], pyjets_.p[3][idx], pyjets_.p[4][idx], pyjets_.k[1][idx], charge);
126 if(_fullEventRecord)
127 {
128// particle.setParent(pyjets_.k[2][idx]);
129 particle.setFirstDaughter(pyjets_.k[3][idx]);
130 particle.setLastDaughter(pyjets_.k[4][idx]);
131 particle.setStatus(pyjets_.k[0][idx]);
132 }
133 particle.Boost(boostVector);
134 event.addParticle(particle);
135 }
136
137 }
138 return event;
139}