diff --git a/Generator/CMakeLists.txt b/Generator/CMakeLists.txt index e411a4826..e3f207777 100644 --- a/Generator/CMakeLists.txt +++ b/Generator/CMakeLists.txt @@ -10,8 +10,8 @@ gaudi_add_module(GenAlgo src/GenReader.cpp src/StdHepRdr.cpp src/GenPrinter.cpp - # src/LCAscHepRdr.cc - # src/HepevtRdr.cpp + src/LCAscHepRdr.cc + src/HepevtRdr.cpp src/SLCIORdr.cpp src/HepMCRdr.cpp src/GtGunTool.cpp diff --git a/Generator/src/HepevtRdr.cpp b/Generator/src/HepevtRdr.cpp index 7f036e2e9..faf5ad9e0 100644 --- a/Generator/src/HepevtRdr.cpp +++ b/Generator/src/HepevtRdr.cpp @@ -7,12 +7,10 @@ #include "IMPL/MCParticleImpl.h" -#include "plcio/MCParticle.h" //plcio -#include "plcio/MCParticleObj.h" -#include "plcio/MCParticleCollection.h" -#include "plcio/DoubleThree.h" -#include "plcio/FloatThree.h" -#include "plcio/EventHeaderCollection.h" +#include "edm4hep/MCParticle.h" //edm4hep +#include "edm4hep/MCParticleObj.h" +#include "edm4hep/MCParticleCollection.h" +#include "edm4hep/EventHeaderCollection.h" @@ -23,7 +21,7 @@ using namespace lcio; using namespace IMPL; -using namespace plcio; +using namespace edm4hep; using namespace std; typedef enum HEPFILEFORMATS @@ -35,28 +33,57 @@ typedef enum HEPFILEFORMATS } HEPFILEFORMAT; -HepevtRdr::HepevtRdr(string name){ +DECLARE_COMPONENT(HepevtRdr) -m_hepevt_rdr = new UTIL::LCAscHepRdr(name.c_str(), hepevt); -m_processed_event=0; -std::cout<<"initial hepevt_rdr"<readEvent(); if(mc_vec==nullptr) return false; m_processed_event ++; - int n_mc = mc_vec->getNumberOfElements(); + int n_mc = mc_vec->size(); std::cout<<"Read event :"<< m_processed_event <<", mc size :"<< n_mc < pmcid_lmcid; for (int i=0; i < n_mc; i++){ MCParticleImpl* mc = (MCParticleImpl*) mc_vec->getElementAt(i); - //std::cout<<"At mc :"<< i <(mc->id(),i)); //std::cout<<"map:"<id()<<","<< i <getMass()); mcp.setVertex (mc->getVertex()); mcp.setEndpoint (mc->getEndpoint()); - mcp.setMomentum (FloatThree(float(mc->getMomentum()[0]), float(mc->getMomentum()[1]), float(mc->getMomentum()[2]) )); - mcp.setMomentumAtEndpoint (FloatThree(float(mc->getMomentumAtEndpoint()[0]), float(mc->getMomentumAtEndpoint()[1]), float(mc->getMomentumAtEndpoint()[2]) )); + mcp.setMomentum (edm4hep::Vector3f(float(mc->getMomentum()[0]), float(mc->getMomentum()[1]), float(mc->getMomentum()[2]) )); + mcp.setMomentumAtEndpoint (edm4hep::Vector3f(float(mc->getMomentumAtEndpoint()[0]), float(mc->getMomentumAtEndpoint()[1]), float(mc->getMomentumAtEndpoint()[2]) )); mcp.setSpin (mc->getSpin()); mcp.setColorFlow (mc->getColorFlow()); } @@ -79,16 +106,16 @@ bool HepevtRdr::mutate(MyHepMC::GenEvent& event){ MCParticleImpl* mc = (MCParticleImpl*) mc_vec->getElementAt(i); const MCParticleVec & mc_parents = mc->getParents(); const MCParticleVec & mc_daughters = mc->getDaughters(); - plcio::MCParticle pmc = event.m_mc_vec.at(i); + auto pmc = event.m_mc_vec.at(i); //std::cout<<"mc at "<< i<<", parent size "<id(); //std::cout<<"parent id "<id(); //std::cout<<"daughter id "< { public: - HepevtRdr(string name); + using extends::extends; ~HepevtRdr(); - bool configure(); + + StatusCode initialize() override; + StatusCode finalize() override; + + bool configure_gentool(); bool mutate(MyHepMC::GenEvent& event); bool finish(); bool isEnd(); private: - UTIL::LCAscHepRdr* m_hepevt_rdr; - long m_total_event; - long m_processed_event; + UTIL::LCAscHepRdr* m_hepevt_rdr = nullptr; + long m_total_event = -1; + long m_processed_event = -1; + + // input file name + Gaudi::Property m_filename{this, "Input"}; + Gaudi::Property m_format{this, "Format"}; }; #endif diff --git a/Generator/src/LCAscHepRdr.cc b/Generator/src/LCAscHepRdr.cc index eabca0bb1..ac99d8f22 100644 --- a/Generator/src/LCAscHepRdr.cc +++ b/Generator/src/LCAscHepRdr.cc @@ -56,11 +56,16 @@ namespace UTIL{ // // Read the event, check for errors // - int NHEP; // number of entries - int NOUT ; // number of outgoing particles - int BRE ; // beam remnants - double WEIGHT ; // weight - inputFile >> NHEP >> NOUT >> BRE >> WEIGHT; + int NHEP = -1; // number of entries + int NOUT = -1; // number of outgoing particles + int BRE = -1; // beam remnants + double WEIGHT = -1; // weight + + std::string line; // modified by Tao + std::getline(inputFile, line); + std::stringstream ss_(line); + ss_ >> NHEP >> NOUT >> BRE >> WEIGHT; + // std::cout << "NHEP: " << NHEP << std::endl; if( inputFile.eof() ) { // @@ -74,6 +79,7 @@ namespace UTIL{ // Create a Collection Vector // mcVec = new IMPL::LCCollectionVec(LCIO::MCPARTICLE); + // std::cout << "mc size: " << mcVec->size() << std::endl; MCParticleImpl* p; MCParticleImpl* d; @@ -101,12 +107,18 @@ namespace UTIL{ for( int IHEP=0; IHEP> ISTHEP >> IDHEP >> JDAHEP1 >> JDAHEP2 + std::getline(inputFile, line); + if(inputFile.eof()) + return nullptr; + + // std::cout << "LINE: " << line << std::endl; + std::stringstream ss(line); + + if ( theFileFormat == HEPEvt) + ss >> ISTHEP >> IDHEP >> JDAHEP1 >> JDAHEP2 >> PHEP1 >> PHEP2 >> PHEP3 >> PHEP5; else - inputFile >> ISTHEP >> IDHEP + ss >> ISTHEP >> IDHEP >> JMOHEP1 >> JMOHEP2 >> JDAHEP1 >> JDAHEP2 >> PHEP1 >> PHEP2 >> PHEP3 @@ -114,8 +126,8 @@ namespace UTIL{ >> VHEP1 >> VHEP2 >> VHEP3 >> VHEP4; - if(inputFile.eof()) - return nullptr; + // std::cout << "ISTHEP: " << ISTHEP << std::endl; + // // Create a MCParticle and fill it from stdhep info // @@ -124,6 +136,7 @@ namespace UTIL{ // PDGID // mcp->setPDG(IDHEP); + // std::cout << "PDG: " << IDHEP << std::endl; // // Momentum vector // @@ -221,6 +234,7 @@ namespace UTIL{ // for( int IHEP=0; IHEP