Skip to content

Commit

Permalink
PMTInfo should write position in global coordinate system
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesJieranShen committed Jul 18, 2024
1 parent b734c31 commit 46140db
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/geo/include/RAT/PMTInfoParser.hh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class PMTInfoParser {
// Returns the offset between local and global coordinates
// e.g. local = global - offset
G4ThreeVector GetLocalOffset() { return fLocalOffset; }
static G4ThreeVector ComputeLocalOffset(const std::string &);

// Returns the direction vector of the front face of the PMTs
const std::vector<G4ThreeVector> &GetPMTDirections() const { return fDir; };
Expand Down
12 changes: 9 additions & 3 deletions src/geo/src/pmt/PMTFactoryBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <RAT/Materials.hh>
#include <RAT/PMTConstruction.hh>
#include <RAT/PMTFactoryBase.hh>
#include <RAT/PMTInfoParser.hh>
#include <algorithm>
#include <vector>

Expand Down Expand Up @@ -42,6 +43,7 @@ G4VPhysicalVolume *PMTFactoryBase::ConstructPMTs(
if (phys_mother == 0) {
Log::Die("PMTParser: PMT mother physical volume " + mother_name + " not found");
}
G4ThreeVector local_offset = PMTInfoParser::ComputeLocalOffset(mother_name);

PMTConstruction *construction = PMTConstruction::NewConstruction(lpmt, mother);
G4LogicalVolume *log_pmt = construction->BuildVolume(volume_name);
Expand Down Expand Up @@ -234,6 +236,9 @@ G4VPhysicalVolume *PMTFactoryBase::ConstructPMTs(

G4ThreeVector pmtpos = pmt_pos[i];
G4ThreeVector pmtdir = pmt_dir[i];
// Compute PMT position in global coordinate system
// TODO: We should also account for a rotation of the mother volume at some point
G4ThreeVector pmtpos_global = pmtpos + local_offset;

// Store individual efficiency
EfficiencyCorrection[id] = pmt_effi_corr[i];
Expand All @@ -242,10 +247,11 @@ G4VPhysicalVolume *PMTFactoryBase::ConstructPMTs(
// This goes into the DS by way of Gsim
// NOTE: Since the BField stuff isn't used currently, add the efficiency here.
// If we revive the BField code, this needs to be moved after so that the efficiency is correct
pmtinfo.AddPMT(TVector3(pmtpos.x(), pmtpos.y(), pmtpos.z()), TVector3(pmtdir.x(), pmtdir.y(), pmtdir.z()),
pmt_type[i], channel_number[i], pmt_model, pmt_effi_corr[i], individual_noise_rate[i],
individual_afterpulse_fraction[i]);
pmtinfo.AddPMT(TVector3(pmtpos_global.x(), pmtpos_global.y(), pmtpos_global.z()),
TVector3(pmtdir.x(), pmtdir.y(), pmtdir.z()), pmt_type[i], channel_number[i], pmt_model,
pmt_effi_corr[i], individual_noise_rate[i], individual_afterpulse_fraction[i]);

// TODO: Check if logic below should use pmtpos or pmtpos_global
// if requested, generates the magnetic efficiency corrections as the PMTs
// are created
if (BFieldOn) {
Expand Down
8 changes: 6 additions & 2 deletions src/geo/src/pmt/PMTInfoParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,19 @@ PMTInfoParser::PMTInfoParser(DBLinkPtr lpos_table, const std::string &mother_nam
if (phys_mother == 0) {
Log::Die("PMTParser: PMT mother physical volume " + mother_name + " not found");
}
fLocalOffset = ComputeLocalOffset(mother_name);
}

G4ThreeVector PMTInfoParser::ComputeLocalOffset(const std::string &mother_name) {
// PMTINFO is always in global coordinates - so calculate the local offset first
fLocalOffset = G4ThreeVector(0.0, 0.0, 0.0);
G4ThreeVector offset(0.0, 0.0, 0.0);
for (string parent_name = mother_name; parent_name != "";) {
G4VPhysicalVolume *parent_phys = GeoFactory::FindPhysMother(parent_name);
fLocalOffset -= parent_phys->GetFrameTranslation();
offset -= parent_phys->GetFrameTranslation();
DBLinkPtr parent_table = DB::Get()->GetLink("GEO", parent_name);
parent_name = parent_table->GetS("mother");
}
return offset;
}

G4RotationMatrix PMTInfoParser::GetPMTRotation(int i) const {
Expand Down

0 comments on commit 46140db

Please sign in to comment.