#include #include #include #include using namespace std; #include "HDDM/hddm_s.h" #include "particleType.h" char *INPUT_FILE=NULL; string OUTPUT_FILE("output.hddm"); void ParseCommandLineArguments(int narg,char *argv[]); int Str2GeantParticleID(char *str); void Usage(void); double randm(double, double); float vertex[4]={0.0, 0.0, 65.0, 65.0}; Particle_t targetType = Proton; Particle_t beamType = Gamma; bool FIXED_BEAM_MOMENTUM = false; float BEAM_MOMENTUM = 8.5; float BEAM_MOMENTUM_SIGMA = 0.005; #include TRandom *rnd; #define SQR(X) ((X)*(X)) time_t now; //------------------------------- // main //------------------------------- int main(int narg, char *argv[]) { ParseCommandLineArguments(narg,argv); if(!INPUT_FILE){ cerr<<"No input file!"<is_open()){ cerr<<"Unable to open file \""<eof()){ int runNumber=0, eventNumber=0, nParticles=0; (*file)>> runNumber >> eventNumber >> nParticles; if(runNumber==0 && eventNumber==0 && nParticles==0)break; // Start a new event s_PhysicsEvents_t* pes; s_Reactions_t* rs; s_Target_t* ta; s_Beam_t* be; s_Vertices_t* vs; s_Origin_t* origin; s_Products_t* ps; s_HDDM_t *thisOutputEvent = make_s_HDDM(); thisOutputEvent->physicsEvents = pes = make_s_PhysicsEvents(1); pes->mult = 1; pes->in[0].runNo = runNumber; pes->in[0].eventNo = eventNumber; pes->in[0].reactions = rs = make_s_Reactions(1); rs->mult = 1; rs->in[0].target = ta = make_s_Target(); ta->type = targetType; ta->properties = make_s_Properties(); ta->properties->charge = ParticleCharge(targetType); ta->properties->mass = ParticleMass(targetType); ta->momentum = make_s_Momentum(); ta->momentum->px = 0; ta->momentum->py = 0; ta->momentum->pz = 0; ta->momentum->E = ParticleMass(targetType); rs->in[0].beam = be = make_s_Beam(); be->type = beamType; be->properties = make_s_Properties(); be->properties->charge = ParticleCharge(beamType); be->properties->mass = ParticleMass(beamType); be->momentum = make_s_Momentum(); be->momentum->px = -ta->momentum->px; be->momentum->py = -ta->momentum->py; be->momentum->pz = -ta->momentum->pz; be->momentum->E = -ta->momentum->E; rs->in[0].vertices = vs = make_s_Vertices(1); vs->mult = 1; vs->in[0].origin = origin = make_s_Origin(); vs->in[0].products = ps = make_s_Products(nParticles); ps->mult = 0; origin->t = 0.0; origin->vx = vertex[0]; origin->vy = vertex[1]; if(vertex[2]vz = randm(vertex[2],vertex[3]); } else { origin->vz = vertex[2]; } for(int i=0;imult++){ int N, charge, type; char typestr[256]; float mass, px, py, pz, E; (*file)>> N >> typestr >> mass; (*file)>> charge >> px >> py >> pz >> E; type = Str2GeantParticleID(typestr); if(type<0)type = atoi(typestr); ps->in[ps->mult].type = (Particle_t)type; ps->in[ps->mult].pdgtype = 0; /* don't bother with the PDG type here */ ps->in[ps->mult].id = i+1; /* unique value for this particle within the event */ ps->in[ps->mult].parentid = 0; /* All internally generated particles have no parent */ ps->in[ps->mult].mech = 0; /* maybe this should be set to something? */ ps->in[ps->mult].momentum = make_s_Momentum(); ps->in[ps->mult].momentum->px = px; ps->in[ps->mult].momentum->py = py; ps->in[ps->mult].momentum->pz = pz; ps->in[ps->mult].momentum->E = E; be->momentum->px += px; be->momentum->py += py; be->momentum->pz += pz; be->momentum->E += E; } // If a specific beam momentum was specified, overwrite // the calculated momentum with it. if(FIXED_BEAM_MOMENTUM){ float p = BEAM_MOMENTUM; if(BEAM_MOMENTUM_SIGMA!=0.0){ float delta_p = BEAM_MOMENTUM_SIGMA*rnd->Gaus(); p += delta_p; } be->momentum->px = 0.0; be->momentum->py = 0.0; be->momentum->pz = p; } be->momentum->E = sqrt(SQR(be->properties->mass)+ SQR(be->momentum->px)+ SQR(be->momentum->py)+ SQR(be->momentum->pz) ); if(nParticles>0){ flush_s_HDDM(thisOutputEvent, thisOutputStream); if(eventNumber%1000 == 0){cout<<"Wrote event "<close(); // Close output file close_s_HDDM(thisOutputStream); cout<<"Wrote "< vertex[3]){ cerr<<"Invalid parameter: z_min > z_max"<< endl; exit(-1); } break; case 'b': beamType = (Particle_t)Str2GeantParticleID(&ptr[1]); break; case 't': targetType = (Particle_t)Str2GeantParticleID(&ptr[1]); break; case 'P': FIXED_BEAM_MOMENTUM = true; BEAM_MOMENTUM = atof(&ptr[1]); break; case 's': BEAM_MOMENTUM_SIGMA = atof(&ptr[1])/1000.0; break; default: cerr<<"Unknown option \""<Rndm() + low); }