lcdd/src
diff -N StepReadout.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ StepReadout.cc 18 Dec 2006 21:19:12 -0000 1.1
@@ -0,0 +1,201 @@
+// $Header: /cvs/lcd/lcdd/src/StepReadout.cc,v 1.1 2006/12/18 21:19:12 jeremy Exp $
+#include "StepReadout.hh"
+
+// LCDD
+#include "ReadoutUtil.hh"
+#include "TrackInformation.hh"
+
+// G4
+#include "G4Step.hh"
+#include "G4StepPoint.hh"
+#include "G4Track.hh"
+#include "G4VSolid.hh"
+#include "G4VPhysicalVolume.hh"
+#include "G4VSensitiveDetector.hh"
+#include "G4TouchableHandle.hh"
+#include "G4Region.hh"
+#include "G4Material.hh"
+#include "G4LogicalVolume.hh"
+
+StepReadout::StepReadout()
+ : m_step(0)
+{}
+
+StepReadout::~StepReadout()
+{}
+
+void StepReadout::setStep(G4Step* s)
+{
+ m_step = s;
+}
+
+G4Step* StepReadout::step() const
+{
+ return m_step;
+}
+
+bool StepReadout::hasStep() const
+{
+ return ( 0 != m_step );
+}
+
+G4StepPoint* StepReadout::pre() const
+{
+ return step()->GetPreStepPoint();
+}
+
+G4StepPoint* StepReadout::post() const
+{
+ return step()->GetPostStepPoint();
+}
+
+G4VPhysicalVolume* StepReadout::prePV() const
+{
+ return preTouchableHandle()->GetVolume();
+}
+
+G4VPhysicalVolume* StepReadout::postPV() const
+{
+ return postTouchableHandle()->GetVolume();
+}
+
+G4VSolid* StepReadout::preSolid() const
+{
+ return preLV()->GetSolid();
+}
+
+G4VSolid* StepReadout::postSolid() const
+{
+ return postLV()->GetSolid();
+}
+
+G4LogicalVolume* StepReadout::preLV() const
+{
+ return prePV()->GetLogicalVolume();
+}
+
+G4LogicalVolume* StepReadout::postLV() const
+{
+ return postPV()->GetLogicalVolume();
+}
+
+G4Material* StepReadout::preMaterial() const
+{
+ return pre()->GetMaterial();
+}
+
+G4Material* StepReadout::postMaterial() const
+{
+ return post()->GetMaterial();
+}
+
+G4VSensitiveDetector* StepReadout::preSD() const
+{
+ return ((G4StepPoint*)pre())->GetSensitiveDetector();
+}
+
+G4VSensitiveDetector* StepReadout::postSD() const
+{
+ return ((G4StepPoint*)post())->GetSensitiveDetector();
+}
+
+bool StepReadout::hasSameSD() const
+{
+ bool r = false;
+
+ // post vol has an SD
+ if ( 0 != postSD() ) {
+
+ // post SD same as pre SD
+ if ( preSD() == postSD() ) {
+ r = true;
+ }
+ }
+
+ return r;
+}
+
+G4ThreeVector StepReadout::volumePosition(G4TouchableHandle theTouchable) const
+{
+ return theTouchable->GetHistory()->GetTopTransform().Inverse().TransformPoint( m_origin );
+}
+
+G4ThreeVector StepReadout::preVolumePosition() const
+{
+ return volumePosition( preTouchableHandle() );
+}
+
+G4ThreeVector StepReadout::postVolumePosition() const
+{
+ return volumePosition( postTouchableHandle() );
+}
+
+double StepReadout::edep() const
+{
+ return step()->GetTotalEnergyDeposit();
+}
+
+G4Track* StepReadout::track() const
+{
+ return step()->GetTrack();
+}
+
+double StepReadout::globalTime() const
+{
+ return track()->GetGlobalTime();
+}
+
+int StepReadout::trackID() const
+{
+ return track()->GetTrackID();
+}
+
+G4ThreeVector StepReadout::momentum() const
+{
+ return track()->GetMomentum();
+}
+
+TrackInformation* StepReadout::trackInformation() const
+{
+ return TrackInformation::getTrackInformation( track() );
+}
+
+G4ThreeVector StepReadout::prePosition() const
+{
+ return pre()->GetPosition();
+}
+
+G4ThreeVector StepReadout::midPosition() const
+{
+ return ReadoutUtil::computeThreeVectorMean( prePosition(), postPosition() );
+}
+
+G4ThreeVector StepReadout::postPosition() const
+{
+ return post()->GetPosition();
+}
+
+G4ThreeVector StepReadout::preMomentum() const
+{
+ return pre()->GetMomentum();
+}
+
+G4ThreeVector StepReadout::postMomentum() const
+{
+ return post()->GetMomentum();
+}
+
+G4ThreeVector StepReadout::meanMomentum() const
+{
+ return ReadoutUtil::computeThreeVectorMean( preMomentum(), postMomentum() );
+}
+
+G4TouchableHandle StepReadout::preTouchableHandle() const
+{
+ return pre()->GetTouchableHandle();
+}
+
+G4TouchableHandle StepReadout::postTouchableHandle() const
+{
+ return post()->GetTouchableHandle();
+}
lcdd/include
diff -N StepReadout.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ StepReadout.hh 18 Dec 2006 21:19:12 -0000 1.1
@@ -0,0 +1,116 @@
+// $Header: /cvs/lcd/lcdd/include/StepReadout.hh,v 1.1 2006/12/18 21:19:12 jeremy Exp $
+#ifndef LCDD_STEPREADOUT_HH
+#define LCDD_STEPREADOUT_HH 1
+
+// G4
+#include "G4ThreeVector.hh"
+#include "G4TouchableHandle.hh"
+
+// std
+#include <vector>
+
+// G4
+class G4VPhysicalVolume;
+class G4VSensitiveDetector;
+class G4Step;
+class G4StepPoint;
+class G4Region;
+class G4Material;
+class G4LogicalVolume;
+class G4VSolid;
+class G4Track;
+
+// LCDD
+class TrackInformation;
+class G4UserRegionInformation;
+
+/**
+ * @class StepReadout
+ * @brief Utility functions to return commonly used pointers and data values from a G4Step object.
+ * @note The only cached data is the step pointer.
+*/
+class StepReadout
+{
+public:
+ StepReadout();
+ virtual ~StepReadout();
+
+public:
+
+ // step
+ void setStep(G4Step* s);
+ G4Step* step() const;
+ bool hasStep() const;
+
+ // step points
+ G4StepPoint* pre() const;
+ G4StepPoint* post() const;
+
+ // PV from pre and post
+ G4VPhysicalVolume* prePV() const;
+ G4VPhysicalVolume* postPV() const;
+
+ // solid from pre and post
+ G4VSolid* preSolid() const;
+ G4VSolid* postSolid() const;
+
+ // LV from pre and post
+ G4LogicalVolume* preLV() const;
+ G4LogicalVolume* postLV() const;
+
+ // material from pre and post
+ G4Material* preMaterial() const;
+ G4Material* postMaterial() const;
+
+ // region from pre and post
+ G4Region* preRegion() const;
+ G4Region* postRegion() const;
+
+ // pre and post position of PV
+ G4ThreeVector volumePosition(G4TouchableHandle theTouchable) const;
+ G4ThreeVector preVolumePosition() const;
+ G4ThreeVector postVolumePosition() const;
+
+ // SD from pre and post
+ G4VSensitiveDetector* preSD() const;
+ G4VSensitiveDetector* postSD() const;
+
+ // are pre and post SD the same?
+ bool hasSameSD() const;
+
+ // edep from step
+ double edep() const;
+
+ // track
+ G4Track* track() const;
+
+ // data from track
+ double globalTime() const;
+ int trackID() const;
+ G4ThreeVector momentum() const;
+ TrackInformation* trackInformation() const;
+
+ // pre, mid and post positions
+ G4ThreeVector prePosition() const;
+ G4ThreeVector midPosition() const;
+ G4ThreeVector postPosition() const;
+
+ // pre, post and mean momentum
+ G4ThreeVector preMomentum() const;
+ G4ThreeVector postMomentum() const;
+ G4ThreeVector meanMomentum() const;
+
+ // pre and post handles
+ G4TouchableHandle preTouchableHandle() const;
+ G4TouchableHandle postTouchableHandle() const;
+
+protected:
+
+ // cached step
+ G4Step* m_step;
+
+ // vector = [0,0,0]
+ const G4ThreeVector m_origin;
+};
+
+#endif