Beispiel #1
0
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;
}