//////////////////////////////////////////////////////////////////////// /// \class RAT::InHepEvt /// /// \brief Reads in HEPEVT files and simulates the MC event in geant /// /// \author Matthew Strait -- contact person /// /// \details InHepEvt is used to take event vertices generated by some /// other program in the standard HEPEVT format and simulate them in /// RAT. To use this generator the command is /// /// /generator/add inhepevt filename /// /// The "HEPEVT standard" does not specify the ASCII file format, but /// specifies what the fields mean in a FORTRAN common block. See, e.g. /// http://cepa.fnal.gov/psm/simulation/mcgen/lund/pythia_manual/pythia6.3/pythia6301/node39.html /// The definition of the ASCII file has been taken from GLG4Sim. /// /// The ASCII HEPEVT format consists of lines with information about /// all of the particles in an event. This is preceded by a line with /// a single integer which indicates the number of particles in the /// event. This format repeats until the end of the file, and so the /// file is made of blocks like: /// /// NHEP /// ISTHEP IDHEP JDAHEP1 JDAHEP2 PHEP1 PHEP2 PHEP3 PHEP5 DT X Y Z PLX PLY PLZ /// ISTHEP IDHEP JDAHEP1 JDAHEP2 PHEP1 PHEP2 PHEP3 PHEP5 DT X Y Z PLX PLY PLZ /// ... [NHEP times] /// /// where /// /// ISTHEP == status code /// IDHEP == HEP PDG code /// JDAHEP == first daughter /// JDAHEP == last daughter /// PHEP1 == px in GeV /// PHEP2 == py in GeV /// PHEP3 == pz in GeV /// PHEP5 == mass in GeV /// DT == vertex _delta_ time, in ns /// X == x vertex in mm /// Y == y vertex in mm /// Z == z vertex in mm /// PLX == x polarization /// PLY == y polarization /// PLZ == z polarization /// /// followed by any number of additional blocks of the same sort. For /// instance, to simulate two back-to-back electrons in an event and one /// positron in another, you could say: /// /// 2 /// 1 11 0 0 0 0 -0.027 0.000510998928 0 -500 100 500 /// 1 11 0 0 0 0 0.027 0.000510998928 0 -500 100 500 /// 1 /// 1 -11 0 0 0 0 -0.027 0.000510998928 0 -500 100 500 /// /// PHEP5, DT, X, Y, Z, PLX, PLY, and PLZ are all optional. If omitted, /// the respective quantity is set to the most recent line that contains /// it, where this can cross event boundaries. /// /// The status code (ISTHEP) is typically set to 1, meaning a normal /// particle that you want to simulate. Parents of particles that you /// want to simulate (but which you don't want simulated) can be given /// with status == 2. See the HEPEVT standard for more. /// /// The DT of the first particle in the first event sets the absolute /// time of that event to the DT given plus RAT's default time specified /// in data/DATE.ratdb The DT for each subsequent particle is relative /// to the previous particle, including across event boundaries. /// /// Time is given in ns, contrary to the HEPEVT standard, which has it /// in mm/c (~3.33ps). This is for our sanity and for compatibility with /// GLG4Sim. /// /// Energy and mass are given in GeV, in conformance to both the HEPEVT /// standard and GLG4Sim, but this harms our sanity because RAT uses /// MeV. /// /// Revision History: \n /// 13 Nov 2014: Matt Strait - Fixed shadowed variable warning /// 07 Feb 2016: Nuno Barros - Removed inherited low level gens (time, pos) /// 13 Feb 2017: Nuno Barros - Added custom base constructor with generator name /// //////////////////////////////////////////////////////////////////////// #ifndef __RAT_InHEPEVT_ #define __RAT_InHEPEVT_ #include #include #include namespace RAT { namespace HepEvt{ /// \struct RAT::HepEvt::Particle /// \brief One particle from a HEPEVT file. /// This holds all the fields of a HEPEVT particle, whether or not /// they are obviously relevant to RAT. struct Particle{ // mandatory fields int stat, pdg; unsigned int daughter[2]; double px, py, pz; // optional fields. double mass, time, x, y, z, plx, ply, plz; }; /// \struct RAT::HepEvt::Event /// \brief An event read from a HEPEVT file. /// Holds the event time and list of particles. struct Event{ /// The starting time for the whole event. The particle times /// are offsets from this. The first particle need not have an /// offset of zero. double time; /// The particles of the event to be simulated. std::vector part; }; } // namespace HepEvt class InHepEvt: public GLG4Gen { public: InHepEvt() : GLG4Gen("InHepEvt"), fDone(false), fCurrentEvent(0) {}; virtual ~InHepEvt(){}; void GenerateEvent(G4Event *event); /// Whether we're done. Returns false when the input file has ended or /// has had a syntax error /// @return Whether we are willing to be called again. bool IsRepeatable() const {return !fDone;} /// Sets the time of the next event. This time is relative to the /// previous event, except that for the first event, it is the /// absolute time of the first event. The times can either come from /// the HEPEVT file or a separate time generator. In any case, the /// offset is added to the result. /// /// @param[in] offset Time shift relative to real delta-t void ResetTime(double offset=0.0); /// Despite the name, used only to pass the input file name in. /// GLG4Gen does not say what this "state" business is all about. /// @param[in] state The input HEPEVT file name. void SetState(G4String state); /// GLG4Gen defines this as a virtual method and does not say what /// it is supposed to do. Appears to be harmless. /// @return The empty string. G4String GetState() const {return "";} /// specify/get parameters for time generator (e.g. from /// generator/rate/ commands) overriding HEPEVT file /// @param[in] state the time generator state void SetTimeState(G4String state); /// Returns the "state" of the external time generator, if any. /// @returns The state string. G4String GetTimeState() const; /// specify/get parameters for time generator (e.g. from /// generator/pos commands) overriding HEPEVT file /// @param[in] state the pos generator state void SetPosState(G4String state); /// Returns the "state" of the external position generator, if any. /// @returns The state string. G4String GetPosState() const; protected: /// Called when the last event is sent for simulation so that we /// aren't asked for any more. void BecomeDone(); /// Whether we are done. We become done once the last event has /// been simulated. bool fDone; /// The list of parsed HEPEVT events. std::vector fHepEvts; /// Read all the HEPEVT events out of the input file into fHepEvts. /// If there is a syntax error in the file, we Die() immediately /// before simulating any events. /// @param[in] infile The HEPEVT file name void ReadHepEvtFile(std::ifstream & infile); /// The number of the event being simulated. unsigned int fCurrentEvent; }; } #endif