Message: optical photon hit coordinate at detector Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Question optical photon hit coordinate at detector 

Keywords: coordinate
Forum: Hits, Digitization and Pileup
Date: 15 Aug, 2007
From: jaypee quino <jaypee quino>

what's wrong with this code in getting the photon hit coordinate??? I never got the reasonable coordinate.. It gives out values like 1 hit stored in SD1

> with coordinates x=1.44e-269,
> y=1.44e-269,z=1.74e-290}, which actually not
> reasonable

//################################################## //AHit.cc //##################################################

#include "AHit.hh"
#include "G4UnitsTable.hh"
#include "G4VVisManager.hh"
#include "G4Circle.hh"
#include "G4Colour.hh"
#include "G4VisAttributes.hh"

G4Allocator<AHit> AHitAllocator;

AHit::AHit() 
{
  pos      = 0.0;
}

AHit::~AHit() {}

AHit::AHit(const AHit& right)
  : G4VHit()
{
  trackID   = right.trackID;
//  edep      = right.edep;
  pos       = right.pos;
}

const AHit& AHit::operator=(const AHit& right)
{
  trackID   = right.trackID;
  pos       = right.pos;
  return *this;
}

G4int AHit::operator==(const AHit& right) const
{
  return (this==&right) ? 1 : 0;
}

void AHit::Draw()
{
  G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
  if(pVVisManager)
  {
    G4Circle circle(pos);
    circle.SetScreenSize(2.);
    circle.SetFillStyle(G4Circle::filled);
    G4Colour colour(1.,0.,0.);
    G4VisAttributes attribs(colour);
    circle.SetVisAttributes(attribs);
    pVVisManager->Draw(circle);
  } 
}

void AHit::Print() {

}

//################################################## //AHit.cc //##################################################

#include "AHit.hh"
#include "ASD.hh"
#include "G4HCofThisEvent.hh"
#include "G4Step.hh"
#include "G4ThreeVector.hh"
#include "G4ios.hh"

ASD::ASD(G4String name)
:G4VSensitiveDetector(name)
{
  G4String HCname;
  collectionName.insert(HCname="ACollection");
}

ASD::~ASD(){ }

void ASD::Initialize(G4HCofThisEvent* HCE)
{
  static int HCID = -1;
  ACollection = new AHitsCollection
                          (SensitiveDetectorName,collectionName[0]); 
  if(HCID<0)
  { HCID = GetCollectionID(0); }
  HCE->AddHitsCollection(HCID, ACollection); 
  }

G4bool ASD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {

  G4String particleName = aStep->GetTrack()->GetDefinition()->GetParticleName();
  if(particleName == "opticalphoton") aStep->GetTrack()->SetTrackStatus(fStopAndKill);

  G4StepPoint* thePrePoint = aStep->GetPreStepPoint();
  G4StepPoint* thePostPoint = aStep->GetPostStepPoint();

  //Get the average position of the hit
  G4ThreeVector pos = thePrePoint->GetPosition() + thePostPoint->GetPosition();
  pos/=2.;

  AHit* newHit = new AHit();
  newHit->SetTrackID(aStep->GetTrack()->GetTrackID());
  newHit->SetPos(aStep->GetPreStepPoint()->GetPosition());
  ACollection->insert(newHit);

return true; }

void ASD::EndOfEvent(G4HCofThisEvent* HCE)
{
  static G4int HCID = -1;
  if (HCID<0)
    { HCID = GetCollectionID(0);}
  HCE->AddHitsCollection( HCID, ACollection);

}

void ASD::clear() { }

void ASD::DrawAll() { }

void ASD::PrintAll() { }

//################################################## //EventAction.cc //##################################################

#include "EventAction.hh"

#include "AHit.hh"
#include "BHit.hh"

#include "G4HCofThisEvent.hh"
#include "G4VHitsCollection.hh"
#include "G4SDManager.hh"
#include "G4Event.hh"
#include "G4EventManager.hh"
#include "G4TrajectoryContainer.hh"
#include "G4Trajectory.hh"
#include "G4VVisManager.hh"
#include "G4ios.hh"
#include <fstream>

EventAction::EventAction() {

  AID = -1;
  BID = -1;

  m = 0;
  m1=0;
}

EventAction::~EventAction() {;}

void EventAction::BeginOfEventAction(const G4Event*)
{
  G4SDManager * SDman = G4SDManager::GetSDMpointer();

  if(AID<0){
    G4String colNam;
    AID = SDman->GetCollectionID(colNam="ACollection");
  } 
  if(BID<0){
    G4String colNam;
    BID = SDman->GetCollectionID(colNam="BCollection");
  }
}

void EventAction::EndOfEventAction(const G4Event* evt)
{
  G4cout << ">> Event " << evt->GetEventID() << G4endl;

  G4TrajectoryContainer* trajectoryContainer = evt->GetTrajectoryContainer();
  G4int n_trajectories = 0;
  if (trajectoryContainer) n_trajectories = trajectoryContainer->entries();

  if (G4VVisManager::GetConcreteInstance())
    {
     for (G4int i=0; i<n_trajectories; i++) 
        { G4Trajectory* trj = (G4Trajectory*)
	                            ((*(evt->GetTrajectoryContainer()))[i]);
          trj->DrawTrajectory(50);
        }
    }

  G4HCofThisEvent * HCE = evt->GetHCofThisEvent();

  AHitsCollection* AHC = 0;
  BHitsCollection* BHC = 0;
//Get the hit collections
  if(HCE){
  AHC = (AHitsCollection*)(HCE->GetHC(AID));
  BHC = (BHitsCollection*)(HCE->GetHC(BID));
         }

  std::fstream iopos("det.dat",std::ios::out | std::ios::app);

// hits in Detector A
  if (AHC){
    int n_hit = AHC->entries();
    if(n_hit>0){
      m = m + 1;

  G4ThreeVector pos = (*AHC)[n_hit]->GetPos()/mm;

  G4ThreeVector position = 0;
  if (AHC){
    int n_hit = AHC->entries();
    if(n_hit>0){

        G4ThreeVector pos = (*AHC)[n_hit]->GetPos();
        G4cout << n_hit << " : " << n_hit << " Hits out w/ pos(x,y,z) = "
               << pos.x() << "\t" << pos.y() << "\t" << pos.z() << G4endl;

         store in a dat file the position of the hit
        iopos << pos.x() << "\t" << pos.y() << "\t" << pos.z() << G4endl;
       }
  }

//or alternatively

/*
  if (AHC){

    int n_hit = AHC->entries();
    if(n_hit>0){
      m = m+1;
    iopos << m << "Hits in" << std::endl;
    }}

  if (BHC){
    int n_hit = BHC->entries();
    if(n_hit>0){
      m2 = m2 + 1;
      for (int ihit = 0 ; ihit < m2; ihit++) {
        G4ThreeVector pos = (*BHC)[ihit]->GetPos();
        G4cout << m2 << " : " << n_hit << " Hits out w/ pos(x,y,z) = "
               << pos.x() << "\t" << pos.y() << "\t" << pos.z() << G4endl;
        iopos << m2 << " Hits out w/ pos(x,y,z) = "
              << pos.x() << "\t" << pos.y() << "\t" << pos.z() << G4endl;
      }
    }
  }   */

iopos.close(); }

Inline Depth:
 1 1
 All All
Outline Depth:
 1 1
 2 2
 All All
Add message: (add)

 Add Message Add Message
to: "optical photon hit coordinate at detector"

 Subscribe Subscribe

This site runs SLAC HyperNews version 1.11-slac-98, derived from the original HyperNews


[ Geant 4 Home | Geant 4 HyperNews | Search | Request New Forum | Feedback ]