00001 //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ 00002 // 00003 // File: LCDG4LcioHelper.hh 00004 // Module: lcdg4 00005 // 00006 // Purpose: Prepare LCIO data objects for persistency, and 00007 // save them into an LCIO output file 00008 // 00009 // 20040805 - G.Lima - Created 00010 // 00011 //\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/ 00012 #ifndef _LCDG4LCIOHELPER_HH_ 00013 #define _LCDG4LCIOHELPER_HH_ 00014 00015 #include "LCDG4CalHit.hh" 00016 #include "LCDG4TrackerHit.hh" 00017 #include "LCDMcPart.hh" 00018 00019 #include "IO/LCWriter.h" 00020 #include "IMPL/SimCalorimeterHitImpl.h" 00021 #include "IMPL/SimTrackerHitImpl.h" 00022 #include "IMPL/MCParticleImpl.h" 00023 #include "IMPL/LCRunHeaderImpl.h" 00024 00025 #include <fstream> 00026 #include <vector> 00027 00028 // forward declarations 00029 class G4Run; 00030 class G4Event; 00031 class IMPL::LCCollectionVec; 00032 00033 class LCDG4LcioHelper { 00034 public: // typedefs 00035 typedef std::map<int,IMPL::MCParticleImpl*> TagToMCParticleMap; 00036 typedef std::map<IMPL::MCParticleImpl*,int> MCParticleToTagMap; 00037 00038 // object accessor 00039 static LCDG4LcioHelper* getInstance(); 00040 00041 // destructor 00042 ~LCDG4LcioHelper(); 00043 00044 IO::LCWriter* getWriter() const { return _writer; } 00045 void openLcioFile(const std::string& filename); 00046 void beginRun(const G4Run*, const std::string& detname); 00047 void endRun(); 00048 void writeEvent(const G4Event*); 00049 void reset(); 00050 00051 void saveCollection(const std::string& collName, 00052 IMPL::LCCollectionVec* coll); 00053 00054 // Create calorimeter-like hits 00055 IMPL::SimCalorimeterHitImpl* getCalHitLcio(const LCDG4CalHit& hit); 00056 // Create tracker-like hits 00057 IMPL::SimTrackerHitImpl* getTrkHitLcio(const LCDG4TrackerHit& hit); 00058 00059 // Create MCParticle table 00060 void buildMCParticleColl(const std::vector<LCDMcPart*>& lcdMcpColl); 00061 void buildParentageLinks(const std::vector<LCDMcPart*>& lcdMcpColl); 00062 IMPL::MCParticleImpl* getMCParticleLcio(LCDMcPart& part); 00063 void prepareMCParticleCollection(IMPL::LCCollectionVec* newColl); 00064 void insertAllFamily(IMPL::LCCollectionVec* newColl, 00065 TagToMCParticleMap::iterator head); 00066 00067 void dumpParticleLists(const std::vector<LCDMcPart*>& lcdMcpColl) const; 00068 00069 private: 00070 // constructor 00071 LCDG4LcioHelper(); 00072 00073 private: // attributes 00074 static LCDG4LcioHelper* _me; 00075 00076 IO::LCWriter* _writer; 00077 TagToMCParticleMap* _mcPartColl; 00078 MCParticleToTagMap _mcp2tag; 00079 IMPL::LCRunHeaderImpl* _runHdr; 00080 std::map<std::string, IMPL::LCCollectionVec*> _savedColls; 00081 }; 00082 00083 #endif // _LCDG4LCIOHELPER_HH_
1.3.4