33#include <TServerSocket.h>
40#include "EVGCore/EventRecord.h"
41#include "EVGDrivers/GEVGDriver.h"
42#include "EVGDrivers/GEVGPool.h"
43#include "EVGDrivers/GMCJMonitor.h"
50#include "PDG/PDGCodeList.h"
57using std::ostringstream;
95const string kErrNoEvent =
"*** NULL OR UNPHYSICAL EVENT! ***";
96const string kErr =
"FAILED";
110int main(
int argc,
char ** argv)
119 TServerSocket * serv_sock =
new TServerSocket(
gOptPortNum, kTRUE);
122 gSock = serv_sock->Accept();
128 int delay_ok =
gSock->SetOption(kNoDelay,1);
129 LOG(
"gevserv",
pNOTICE) <<
"TCP_NODELAY > " << delay_ok;
142 if(mesg->What() != kMESS_STRING)
continue;
144 char mesg_content[2048];
145 mesg->ReadString(mesg_content, 2048);
147 LOG(
"gevserv",
pNOTICE) <<
"Processing mesg > " << mesg_content;
189 <<
"GENIE was pinged by a client (lamp was rubbed)! Responding...";
193 LOG(
"gevserv",
pINFO) <<
"...done!";
216 LOG(
"gevserv",
pNOTICE) <<
"Configuring GENIE event server";
222 LOG(
"gevserv",
pNOTICE) <<
"Configure options: " << mesg;
237 bool allowdup =
false;
241 vector<string> conf_opt_v =
str::Split(mesg,
" ");
242 vector<string>::iterator conf_opt_iter = conf_opt_v.begin();
244 for( ; conf_opt_iter != conf_opt_v.end(); ++conf_opt_iter) {
245 string conf_opt = *conf_opt_iter;
247 <<
"Processing config option: " << conf_opt;
249 vector<string> sv =
str::Split(conf_opt,
"=");
250 assert(sv.size()==2);
251 string list_name = sv[0];
252 string particle_list = sv[1];
254 vector<string> particles =
str::Split(particle_list,
",");
255 vector<string>::iterator particle_iter = particles.begin();
257 for( ; particle_iter != particles.end(); ++particle_iter) {
258 string particle_code_str = *particle_iter;
259 int particle_code = atoi(particle_code_str.c_str());
273 <<
"Specified neutrino list: " << neutrinos;
275 <<
"Specified target list: " << targets;
281 PDGCodeList::const_iterator nuiter;
282 PDGCodeList::const_iterator tgtiter;
284 for(nuiter = neutrinos.begin(); nuiter != neutrinos.end(); ++nuiter) {
285 for(tgtiter = targets.begin(); tgtiter != targets.end(); ++tgtiter) {
287 int target_code = *tgtiter;
288 int neutrino_code = *nuiter;
293 <<
"\n\n ---- Creating a GEVGDriver object configured for init-state: "
294 << init_state.
AsString() <<
" ----\n\n";
300 gGPool.insert( GEVGPool::value_type(init_state.
AsString(), evgdriver) );
306 <<
"All necessary GEVGDriver object were pushed into GEVGPool\n";
312 LOG(
"gevserv",
pINFO) <<
"...done!";
318 <<
"Sending total xsec for enabled channels - Input info : " << mesg;
322 <<
"Event server is not configured - Can not generate event";
335 assert(sv.size()==2);
337 int ipdgnu = atoi(sv[0].c_str());
338 int ipdgtgt = atoi(sv[1].c_str());
346 <<
"No GEVGDriver object for init state: " << init_state.
AsString();
356 <<
"Requesting total cross section for init state: "
360 1000 , 0.001 , 300 ,
true );
363 assert(total_xsec_spl);
369 double Emax = 200.010;
370 int np = (int) TMath::Ceil((Emax-Emin)/dE);
372 ostringstream xsec_hdr;
374 gSock->Send(xsec_hdr.str().c_str());
376 for(
int ip=0; ip<np; ip++) {
377 double E = Emin + ip*dE;
380 ostringstream xsec_spl_knot;
381 xsec_spl_knot << ip <<
" " << E <<
" " << Form(
"%15.8e",xs);
382 gSock->Send(xsec_spl_knot.str().c_str());
387 LOG(
"gevserv",
pINFO) <<
"...done!";
392 LOG(
"gevserv",
pNOTICE) <<
"Generating event - Input info : " << mesg;
396 <<
"Event server is not configured - Can not generate event";
410 assert(sv.size()==11);
411 int irun = atoi(sv[0].c_str());
412 int ievt = atoi(sv[1].c_str());
413 int ipdgnunoosc = atoi(sv[2].c_str());
414 double vtxx = atof(sv[3].c_str());
415 double vtxy = atof(sv[4].c_str());
416 double vtxz = atof(sv[5].c_str());
417 int ipdgnu = atoi(sv[6].c_str());
418 int ipdgtgt = atoi(sv[7].c_str());
419 double px = atof(sv[8].c_str());
420 double py = atof(sv[9].c_str());
421 double pz = atof(sv[10].c_str());
422 double E = TMath::Sqrt(px*px + py*py + pz*pz);
424 TLorentzVector p4(px,py,pz,E);
432 <<
"No GEVGDriver object for init state: " << init_state.
AsString();
446 <<
"Failed to generate the requested event";
451 LOG(
"gevserv",
pINFO) <<
"Generated event: " << *event;
455 const Interaction * interaction =
event->Summary();
461 else if (proc_info.
IsResonant()) int_type = 2;
463 else if (proc_info.IsCoherent()) int_type = 4;
468 if (proc_info.
IsWeakNC()) iaction = 0;
469 else if (proc_info.
IsWeakCC()) iaction = 1;
475 nucleon = hitnucl->
Pdg();
480 bool get_selected =
true;
481 double xbj_sel = kine.
x (get_selected);
482 double y_sel = kine.
y (get_selected);
483 double W2_sel = TMath::Power(kine.
W (get_selected), 2.);
484 double q2_sel = -1 * kine.
Q2(get_selected);
486 double tot_xsec =
event->XSec();
487 double diff_xsec =
event->DiffXSec();
493 ostringstream hdr1, hdr2, hdr3, hdr4, stdhep_hdr;
499 << ipdgnunoosc <<
" "
525 <<
event->GetEntriesFast();
527 gSock->Send(hdr1.str().c_str());
528 gSock->Send(hdr2.str().c_str());
529 gSock->Send(hdr3.str().c_str());
530 gSock->Send(hdr4.str().c_str());
531 gSock->Send(stdhep_hdr.str().c_str());
534 TIter event_iter(event);
536 while ( (p =
dynamic_cast<GHepParticle *
>(event_iter.Next())) ) {
538 ostringstream stdhep_entry;
541 << i <<
" " << p->
Status() <<
" " << p->
Pdg() <<
" "
544 << p->
Px() <<
" " << p->
Py() <<
" " << p->
Pz() <<
" " << p->
E() <<
" "
546 << p->
Vx() <<
" " << p->
Vy() <<
" " << p->
Vz() <<
" " << p->
Vt();
548 gSock->Send(stdhep_entry.str().c_str());
558 LOG(
"gevserv",
pINFO) <<
"...done!";
563 LOG(
"gevserv",
pNOTICE) <<
"Shutting GENIE event server down ...";
569 LOG(
"gevserv",
pINFO) <<
"...done!";
574 if(gSystem->Getenv(
"GSPLOAD")) {
575 string splines_filename = gSystem->Getenv(
"GSPLOAD");
576 bool is_accessible = ! (gSystem->AccessPathName( splines_filename.c_str() ));
577 if (!is_accessible) {
579 <<
"*** The file (" << splines_filename
580 <<
") specified in $GSPLOAD doesn't seem to be available!";
582 <<
"*** Expect a significant start-up overhead!";
585 LOG(
"gevserv",
pWARN) <<
"*** $GSPLOAD was not set!";
586 LOG(
"gevserv",
pWARN) <<
"*** Expect a significant start-up overhead!";
592 LOG(
"gevserv",
pNOTICE) <<
"Parsing command line arguments";
598 LOG(
"gevserv",
pINFO) <<
"Reading port number";
602 <<
"Unspecified port number - Using default (" <<
kDefPortNum <<
")";
610 <<
"\n\n" <<
"Syntax:" <<
"\n"
611 <<
" gevserv [-p port] \n";
#define LOG(stream, priority)
A macro that returns the requested log4cpp::Category appending a string (using the FILE,...
Command line argument parser.
bool OptionExists(char opt)
was option set?
Generated Event Record. It is a GHepRecord object that can accept / be visited by EventRecordVisitorI...
GENIE Event Generation Driver. A minimalist user interface object for generating neutrino interaction...
void Configure(int nu_pdgc, int Z, int A)
const Spline * XSecSumSpline(void) const
EventRecord * GenerateEvent(const TLorentzVector &nu4p)
void CreateXSecSumSpline(int nk, double Emin, double Emax, bool inlogE=true)
A pool of GEVGDriver objects with an initial state key.
STDHEP-like event record entry that can fit a particle or a nucleus.
int FirstMother(void) const
double Vy(void) const
Get production y.
double Mass(void) const
Mass that corresponds to the PDG code.
int LastMother(void) const
int LastDaughter(void) const
double Px(void) const
Get Px.
double E(void) const
Get energy.
double Pz(void) const
Get Pz.
double Py(void) const
Get Py.
double Vz(void) const
Get production z.
GHepStatus_t Status(void) const
double Vx(void) const
Get production x.
double Vt(void) const
Get production time.
int FirstDaughter(void) const
virtual bool IsUnphysical(void) const
Initial State information.
const Target & Tgt(void) const
string AsString(void) const
Summary information for an interaction.
const Kinematics & Kine(void) const
const ProcessInfo & ProcInfo(void) const
const InitialState & InitState(void) const
Generated/set kinematical variables for an event.
double Q2(bool selected=false) const
double y(bool selected=false) const
double W(bool selected=false) const
double x(bool selected=false) const
void push_back(int pdg_code)
A class encapsulating an enumeration of interaction types (EM, Weak-CC, Weak-NC) and scattering types...
bool IsWeakNC(void) const
bool IsNuElectronElastic(void) const
bool IsDeepInelastic(void) const
bool IsInverseMuDecay(void) const
bool IsWeakCC(void) const
bool IsQuasiElastic(void) const
bool IsResonant(void) const
A numeric analysis tool class for interpolating 1-D functions.
double Evaluate(double x) const
int HitQrkPdg(void) const
List of cross section vs energy splines.
static XSecSplineList * Instance()
void Configure(string mesg)
const string kShutdownOkMesgSent
const string kXSecOkMesgSent
const string kConfigCmdNeuList
const string kHandshakeMesgSent
const string kXSecCmdRecv
const string kErrNoDriver
void CalcTotalXSec(string mesg)
const string kConfigCmdLdSpl
const string kEvgenOkMesgSent
const string kEvgenCmdRecv
const string kConfigCmdRecv
void GetCommandLineArgs(int argc, char **argv)
const string kConfigCmdTgtList
const string kShutdownCmdRecv
void HandleMesg(string mesg)
const string kEvgenStdhepCmdSent
const string kConfigOkMesgSent
const string kEvgenHdrCmdSent
const string kXSecCmdSent
const string kHandshakeCmdRecv
void GenerateEvent(string mesg)
static constexpr double cm2
string TrimSpaces(string input)
string FilterString(string filt, string input)
vector< string > Split(string input, string delim)
Root of GENIE utility namespaces.
THE MAIN GENIE PROJECT NAMESPACE