Commit aa0243fe authored by Paul Schütze's avatar Paul Schütze
Browse files

Merge branch 'remove_g4_check' into 'master'

Remove Per-Carrier Check for Correct Coordinate Transformation

See merge request allpix-squared/allpix-squared!697
parents 5692e983 e20ebdcd
Loading
Loading
Loading
Loading
+1 −15
Original line number Diff line number Diff line
@@ -402,12 +402,9 @@ void DepositionGeant4Module::construct_sensitive_detectors_and_fields(double fan
        }
        useful_deposition = true;

        // Get the hit transformation matrix
        auto* hit_transform = calculate_hit_transform(detector->getModel());

        // Get model of the sensitive device
        auto* sensitive_detector_action = new SensitiveDetectorActionG4(
            detector, track_info_manager_.get(), hit_transform, charge_creation_energy, fano_factor, cutoff_time);
            detector, track_info_manager_.get(), charge_creation_energy, fano_factor, cutoff_time);
        auto logical_volume = geo_manager_->getExternalObject<G4LogicalVolume>(detector->getName(), "sensor_log");
        if(logical_volume == nullptr) {
            throw ModuleError("Detector " + detector->getName() + " has no sensitive device (broken Geant4 geometry)");
@@ -475,14 +472,3 @@ void DepositionGeant4Module::record_module_statistics() {
        total_charges_ += sensor->getTotalDepositedCharge();
    }
}

G4RotationMatrix* DepositionGeant4Module::calculate_hit_transform(const std::shared_ptr<DetectorModel>& model) {
    // For radial_strip models a rotation around X-axis is necessary to align G4 and APSQ coordinate systems
    if(std::dynamic_pointer_cast<RadialStripDetectorModel>(model) != nullptr) {
        auto* radialRot = new G4RotationMatrix();
        radialRot->rotateX(-90.0 * CLHEP::degree);
        return radialRot;
    }

    return new G4RotationMatrix();
}
+0 −10
Original line number Diff line number Diff line
@@ -105,16 +105,6 @@ namespace allpix {
         */
        void record_module_statistics();

        /**
         * @brief Calculate hit transformation matrix for a given detector model
         * @param model Detector model
         * @returns Hit transformation matrix pointer
         *
         * @note This matrix transforms the Geant4 local coordinate system of the sensor
         * volume to the APSQ local coordinate system based on the detector model type.
         */
        G4RotationMatrix* calculate_hit_transform(const std::shared_ptr<DetectorModel>& model);

        // Configuration parameters:
        bool output_plots_{};
        unsigned int number_of_particles_{};
+0 −17
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ using namespace allpix;

SensitiveDetectorActionG4::SensitiveDetectorActionG4(const std::shared_ptr<Detector>& detector,
                                                     TrackInfoManager* track_info_manager,
                                                     const G4RotationMatrix* hit_transform,
                                                     double charge_creation_energy,
                                                     double fano_factor,
                                                     double cutoff_time)
@@ -49,8 +48,6 @@ SensitiveDetectorActionG4::SensitiveDetectorActionG4(const std::shared_ptr<Detec
    // Add the sensor to the internal sensitive detector manager
    G4SDManager* sd_man_g4 = G4SDManager::GetSDMpointer();
    sd_man_g4->AddNewDetector(this);

    hit_transform_ = hit_transform;
}

G4bool SensitiveDetectorActionG4::ProcessHits(G4Step* step, G4TouchableHistory*) {
@@ -78,10 +75,6 @@ G4bool SensitiveDetectorActionG4::ProcessHits(G4Step* step, G4TouchableHistory*)

    // Calculate the charge deposit at a local position
    auto deposit_position = detector_->getLocalPosition(static_cast<ROOT::Math::XYZPoint>(step_pos));
    auto deposit_position_g4 = theTouchable->GetHistory()->GetTopTransform().TransformPoint(step_pos);

    // Transform the hit position using the rotation matrix
    deposit_position_g4 *= *hit_transform_;

    // Calculate number of electron hole pairs produced, taking into account fluctuations between ionization and lattice
    // excitations via the Fano factor. We assume Gaussian statistics here.
@@ -89,11 +82,6 @@ G4bool SensitiveDetectorActionG4::ProcessHits(G4Step* step, G4TouchableHistory*)
    allpix::normal_distribution<double> charge_fluctuation(mean_charge, std::sqrt(mean_charge * fano_factor_));
    auto charge = static_cast<unsigned int>(charge_fluctuation(random_generator_));

    auto deposit_position_g4loc =
        ROOT::Math::XYZPoint(deposit_position_g4.x() + detector_->getModel()->getSensorCenter().x(),
                             deposit_position_g4.y() + detector_->getModel()->getSensorCenter().y(),
                             deposit_position_g4.z() + detector_->getModel()->getSensorCenter().z());

    const auto* userTrackInfo = dynamic_cast<TrackInfoG4*>(track->GetUserInformation());
    if(userTrackInfo == nullptr) {
        throw ModuleError("No track information attached to track.");
@@ -133,11 +121,6 @@ G4bool SensitiveDetectorActionG4::ProcessHits(G4Step* step, G4TouchableHistory*)
    deposit_time_.push_back(step_time);
    deposit_to_id_.push_back(trackID);

    LOG(DEBUG) << "Geant4 transformation to local: " << Units::display(deposit_position_g4loc, {"mm", "um"});
    if((deposit_position_g4loc - deposit_position).mag2() > 0.001) {
        LOG(ERROR) << "Difference G4 to internal: "
                   << Units::display((deposit_position_g4loc - deposit_position), {"mm", "um"});
    }
    return true;
}

+0 −4
Original line number Diff line number Diff line
@@ -38,14 +38,12 @@ namespace allpix {
         * @brief Constructs the action handling for every sensitive detector
         * @param detector Detector this sensitive device is bound to
         * @param track_info_manager Pointer to the track information manager
         * @param hit_transform Pointer to the hit transformation matrix
         * @param charge_creation_energy Energy needed per deposited charge
         * @param fano_factor Fano factor for fluctuations in the energy fraction going into e/h pair creation
         * @param cutoff_time Cut-off time for the creation of secondary particles
         */
        SensitiveDetectorActionG4(const std::shared_ptr<Detector>& detector,
                                  TrackInfoManager* track_info_manager,
                                  const G4RotationMatrix* hit_transform,
                                  double charge_creation_energy,
                                  double fano_factor,
                                  double cutoff_time);
@@ -142,8 +140,6 @@ namespace allpix {
        std::vector<int> deposit_to_id_;
        // Map from track id to mc particle index
        std::map<int, size_t> id_to_particle_;

        const G4RotationMatrix* hit_transform_;
    };
} // namespace allpix

+12 −12
Original line number Diff line number Diff line
@@ -108,23 +108,23 @@ void DetectorConstructionG4::build(const std::shared_ptr<G4LogicalVolume>& world
        ROOT::Math::XYZPoint vx, vy, vz;
        orientation.GetComponents(vx, vy, vz);
        auto rotWrapper = std::make_shared<G4RotationMatrix>(copy_vec.data());
        auto wrapperGeoTranslation = toG4Vector(model->getMatrixCenter() - model->getModelCenter());
        wrapperGeoTranslation *= *rotWrapper;
        // Additional rotation for radial_strip models

        // Additional rotation for models that require alignment of their G4 local coordinates with the framework coordinates
        auto model_rotation = std::make_shared<G4RotationMatrix>();
        if(radial_model != nullptr) {
            auto rotRad = std::make_shared<G4RotationMatrix>();
            rotRad->rotateX(-90.0 * CLHEP::degree);
            wrapperGeoTranslation *= *rotRad;
            model_rotation->rotateX(-90.0 * CLHEP::degree);
        }

        // Apply additional rotation on top of the rotation in the global frame
        geo_manager_->setExternalObject(name, "model_rotation", model_rotation);
        *rotWrapper *= *model_rotation;

        // Build full transformation
        auto wrapperGeoTranslation = toG4Vector(model->getMatrixCenter() - model->getModelCenter());
        wrapperGeoTranslation *= *rotWrapper;
        G4ThreeVector posWrapper = toG4Vector(position) - wrapperGeoTranslation;
        geo_manager_->setExternalObject(name, "rotation_matrix", rotWrapper);
        G4Transform3D transform_phys(*rotWrapper, posWrapper);
        // Additional rotation for radial_strip models
        if(radial_model != nullptr) {
            auto rotRad = std::make_shared<G4RotationMatrix>();
            rotRad->rotateX(-90.0 * CLHEP::degree);
            transform_phys = G4Transform3D(*rotWrapper * *rotRad, posWrapper);
        }

        G4LogicalVolumeStore* log_volume_store = G4LogicalVolumeStore::GetInstance();
        G4LogicalVolume* world_log_volume = log_volume_store->GetVolume("World_log");
Loading