StatusCode G4SaveSmearedParticles::saveOutput(const G4Event& aEvent) { auto particles = m_particles.createAndPut(); auto associations = m_particlesMCparticles.createAndPut(); for(int i=0;i<aEvent.GetNumberOfPrimaryVertex();i++) { for(int j=0;j<aEvent.GetPrimaryVertex(i)->GetNumberOfParticle();j++) { const G4PrimaryParticle* g4particle = aEvent.GetPrimaryVertex(i)->GetPrimary(j); sim::ParticleInformation* info = dynamic_cast<sim::ParticleInformation*>(g4particle->GetUserInformation()); const fcc::MCParticle& MCparticle = info->mcParticle(); fcc::Particle particle = particles->create(); fcc::ParticleMCParticleAssociation association = associations->create(); association.Rec(particle); association.Sim(MCparticle); fcc::BareParticle& core = particle.Core(); core.Type = g4particle->GetPDGcode(); core.Status = 1; // how it is defined ???? as in HepMC ? core.Charge = g4particle->GetCharge(); core.P4.Px = info->endMomentum().x()*sim::g42edm::energy; core.P4.Py = info->endMomentum().y()*sim::g42edm::energy; core.P4.Pz = info->endMomentum().z()*sim::g42edm::energy; core.P4.Mass = g4particle->GetMass()*sim::g42edm::energy; core.Vertex.X = info->vertexPosition().x()*sim::g42edm::length; core.Vertex.Y = info->vertexPosition().y()*sim::g42edm::length; core.Vertex.Z = info->vertexPosition().z()*sim::g42edm::length; } } return StatusCode::SUCCESS; }
StatusCode SimG4SaveParticleHistory::saveOutput(const G4Event& aEvent) { auto evtinfo = dynamic_cast<sim::EventInformation*>(aEvent.GetUserInformation()); // take over ownership of particle and vertex collections evtinfo->setCollections(m_genVertexColl, m_mcParticleColl); info() << "Saved " << m_mcParticleColl->size() << " particles from Geant4 history." << endmsg; m_mcParticles.put(m_mcParticleColl); m_genVertices.put(m_genVertexColl); return StatusCode::SUCCESS; }
StatusCode G4SaveCalHits::saveOutput(const G4Event& aEvent) { G4HCofThisEvent* collections = aEvent.GetHCofThisEvent(); G4VHitsCollection* collect; DD4hep::Simulation::Geant4CalorimeterHit* hit; if(collections != nullptr) { fcc::CaloClusterCollection* edmClusters = new fcc::CaloClusterCollection(); fcc::CaloHitCollection* edmHits = new fcc::CaloHitCollection(); // CaloClusterHitsAssociationCollection* edmAssociations = new CaloClusterHitsAssociationCollection(); for (int iter_coll=0; iter_coll<collections->GetNumberOfCollections(); iter_coll++) { collect = collections->GetHC(iter_coll); if (collect->GetName().find(m_calType) != std::string::npos) { size_t n_hit = collect->GetSize(); info() << "\t" << n_hit<< " hits are stored in a HCal collection #"<<iter_coll<<": "<<collect->GetName()<<endmsg; for(size_t iter_hit=0; iter_hit<n_hit; iter_hit++ ) { hit = dynamic_cast<DD4hep::Simulation::Geant4CalorimeterHit*>(collect->GetHit(iter_hit)); debug() << hit->cellID << " "; debug() << hit->energyDeposit << " "; debug() << hit->position.x() << " "; debug() << hit->position.y() << " "; debug() << hit->position.z() << endmsg; fcc::CaloHit edmHit = edmHits->create(); fcc::CaloCluster edmCluster = edmClusters->create(); fcc::BareHit& edmHitCore = edmHit.Core(); fcc::BareCluster& edmClusterCore = edmCluster.Core(); edmHitCore.Cellid = hit->cellID; edmHitCore.Energy = hit->energyDeposit; edmClusterCore.position.X = hit->position.x(); edmClusterCore.position.Y = hit->position.y(); edmClusterCore.position.Z = hit->position.z(); edmClusterCore.Energy = hit->energyDeposit; // CaloClusterHitsAssociationHandle edmAssociation = edmAssociations->create(); // edmAssociation.mod().Cluster = edmCluster; // edmAssociation.mod().Hit = edmHit; } } } m_caloClusters.put(edmClusters); m_caloHits.put(edmHits); } return StatusCode::SUCCESS; }
StatusCode SimG4SaveTrackerHits::saveOutput(const G4Event& aEvent) { G4HCofThisEvent* collections = aEvent.GetHCofThisEvent(); G4VHitsCollection* collect; DD4hep::Simulation::Geant4TrackerHit* hit; if(collections != nullptr) { fcc::TrackClusterCollection* edmClusters = new fcc::TrackClusterCollection(); fcc::TrackHitCollection* edmHits = new fcc::TrackHitCollection(); fcc::TrackClusterHitsAssociationCollection* edmAssociations = new fcc::TrackClusterHitsAssociationCollection(); for (int iter_coll=0; iter_coll<collections->GetNumberOfCollections(); iter_coll++) { collect = collections->GetHC(iter_coll); if (std::find(m_readoutNames.begin(), m_readoutNames.end(), collect->GetName()) != m_readoutNames.end()) { size_t n_hit = collect->GetSize(); info() << "\t" << n_hit<< " hits are stored in a tracker collection #"<<iter_coll<<": "<<collect->GetName()<<endmsg; for(size_t iter_hit=0; iter_hit<n_hit; iter_hit++ ) { hit = dynamic_cast<DD4hep::Simulation::Geant4TrackerHit*>(collect->GetHit(iter_hit)); fcc::TrackHit edmHit = edmHits->create(); fcc::TrackCluster edmCluster = edmClusters->create(); fcc::BareHit& edmHitCore = edmHit.Core(); fcc::BareCluster& edmClusterCore = edmCluster.Core(); edmHitCore.Cellid = hit->cellID; edmHitCore.Energy = hit->energyDeposit; edmHitCore.Time = hit->truth.time; edmClusterCore.position.X = hit->position.x(); edmClusterCore.position.Y = hit->position.y(); edmClusterCore.position.Z = hit->position.z(); edmClusterCore.Energy = hit->energyDeposit; edmClusterCore.Time = hit->truth.time; fcc::TrackClusterHitsAssociation edmAssociation = edmAssociations->create(); edmAssociation.Cluster(edmCluster); edmAssociation.Hit(edmHit); } } } m_trackClusters.put(edmClusters); m_trackHits.put(edmHits); m_trackHitsClusters.put(edmAssociations); } return StatusCode::SUCCESS; }