EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
starlightpythia.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file starlightpythia.cpp
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 "eXevent.h"
26 #include <cmath>
27 #include <sstream>
28 
29 starlightPythia::starlightPythia(const inputParameters& inputParametersInstance, beamBeamSystem& bbsystem) : eventChannel(inputParametersInstance, bbsystem)
30  ,_spectrum(0)
31  ,_doDoubleEvent(false)
32  ,_minGammaEnergy(inputParametersInstance.minGammaEnergy())
33  ,_maxGammaEnergy(inputParametersInstance.maxGammaEnergy())
34  ,_fullEventRecord(false)
35 {
36 }
37 
39 {
40 
41 }
42 
43 int starlightPythia::init(std::string pythiaParams, bool fullEventRecord)
44 {
45  _fullEventRecord = fullEventRecord;
47 
50 
51  if(!_doDoubleEvent)
52  {
54  }
55  else
56  {
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 
74  pythiaInterface::pyinit("FIXT", "gamma", "p", _maxGammaEnergy); // Fixed target, beam, target, beam momentum (GeV/c)
75 
76  return 0;
77 }
78 
80 {
81  eXEvent event;
82 
83  if (!_doDoubleEvent)
84  {
85  double gammaE = 0;
86  do
87  {
88  gammaE = _spectrum->drawKsingle();
89  } while(isnan(gammaE));
90  event.addGamma(gammaE);
91 
92  char opt[32];
93  std::sprintf(opt, "parp(171)=%f", gammaE/_maxGammaEnergy);
94  pythiaInterface::pygive(opt); // Set the energy of the photon beam (gammaE/1000 * 1000.0);
95  pythiaInterface::pyevnt(); // Generate event
96 
97  int zdirection = (_bbs.beam1().Z()==1 ? 1 : -1);
98  double boost = acosh(_bbs.beamLorentzGamma())*zdirection;
99 
100  vector3 boostVector(0, 0, tanh(boost));
101 
102  for(int idx = 0; idx < pyjets_.n; idx++)
103  {
104  if(pyjets_.k[0][idx] > 10 && _fullEventRecord==false) continue;
105  int pdgCode = pyjets_.k[1][idx];
106  int charge = 0;
107  if( pdgCode == 12 || pdgCode == 14 || pdgCode == 16 || pdgCode == 22 || pdgCode == 111 || pdgCode == 130 || pdgCode == 321 || pdgCode == 2112)
108  {
109  charge = 0;
110  }
111  else
112  {
113  charge = (pdgCode > 0) - (pdgCode < 0);
114  }
115 
116  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);
117  if(_fullEventRecord)
118  {
119  particle.setFirstDaughter(pyjets_.k[3][idx]);
120  particle.setLastDaughter(pyjets_.k[4][idx]);
121  particle.setStatus(pyjets_.k[0][idx]);
122  }
123  particle.Boost(boostVector);
124  event.addParticle(particle);
125  }
126  }
127  return event;
128 }