StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StarLightUser.cc
1 #include <iostream>
2 #include <fstream>
3 #include <string>
4 
5 #include "inputParameters.h"
6 #include "starlight.h"
7 #include "upcevent.h"
8 
9 #include <math.h>
10 #include <assert.h>
11 #include <stdlib.h>
12 
13 inputParameters *_parameters = 0;
14 starlight *_starlight = 0;
15 
16 extern "C" {
17 
18  void starlightinterface_();
19 
20  int ku_npar();
21  char *ku_path();
22  char *ku_gete();
23 
24  void pushtrack_( int *pdg, int *charge, float *mass, float *px, float *py, float *pz, float *e );
25  void pushTrack( int pdg, int charge, float mass, float px, float py, float pz, float e )
26  {
27  pushtrack_( &pdg, &charge, &mass, &px, &py, &pz, &e );
28  }
29  void pushtrackreset_();
30 #define pushTrackReset pushtrackreset_
31  void inithepevtd_();
32 #define initHepevtd inithepevtd_
33 
35  //
36  // On library load, establish the KUIP interface
37  //
38  void starlight_(){
39  starlightinterface_();
40  };
41 
43  //
44  // Handle KUIP commands
45  //
46 
47  static std::ofstream par_out;
48  void starlightuser_()
49  {
50 
51  static bool first = true;
52  if ( first )
53  {
54  par_out.open("starlight.in");
55  first = false;
56  }
57 
58 // int npar = ku_npar(); // number of kuip parameters
59  std::string path = ku_path(); // Command path
60 
61  //
62  // StarLight configuration commands are of the form KEYWORD = VALUE. We
63  // setup the StarLightInterface.cdf such that the starlight command
64  // corresponds to the expected keyword.
65  //
66  size_t found = path.find_last_of("/");
67  std::string command = path.substr(found+1);
68  // Add the expected equal sign
69  command += " = ";
70  // And finish the command
71  command += ku_gete();
72  command += "\n";
73  par_out << command.c_str();
74 
75  }
76 
77 #if 0 /* agusread is implemented in the StarGenerator framework */
78  void agusread_()
79  {
80  static bool first = true;
81 
82  //
83  // Initialization on the first event
84  //
85  if ( first ) {
86 
87  par_out << "RND_SEED = 1234 # Dummy (using starsim RNG)" << std::endl; // dummy
88  par_out << "OUTPUT_FORMAT = 1" << std::endl; // ???
89  par_out.close(); // close output file
90  first = false;
91 
92  // Read in input parameters from the temporary input file
93  _parameters = new inputParameters();
94  _parameters->init( "./starlight.in" );
95  // And create a new instance of the starlight object
96  _starlight = new starlight();
97  _starlight -> setInputParameters( _parameters );
98  _starlight -> init();
99  // And some useful info into the event generator
100  initHepevtd();
101 
102  }
103 
104 
105  // Generate one event
106  upcEvent event = _starlight->produceEvent();
107 
108  // Rset hepevt
109  pushTrackReset();
110 
111  const std::vector<starlightParticle> &particles = *(event.getParticles());
112  for ( int i=0;i<particles.size();i++ )
113  {
114  float px = particles[i].GetPx();
115  float py = particles[i].GetPy();
116  float pz = particles[i].GetPz();
117  float e = particles[i].GetE();
118  float m = particles[i].M();
119  int q = particles[i].getCharge();
120  int pdg = particles[i].getPdgCode();
121 
122  // std::cout << "pdg id = " << pdg << " charge=" << q << std::endl;
123  //
124  // StarLight does not follow the PDG naming convention. They drop the sign of
125  // antiparticles.
126  //
127  assert( pdg > 0 );// If this fails, starlight group has changed something
128  pdg *= q / abs(q);
129 
130  pushTrack( pdg, q, m, px, py, pz, e );
131 
132  }
133 
134 
135 
136  }
137 #endif
138 
139 }
140 
141