Message: Re: How to define different colors of the hits. Not Logged In (login)
 Next-in-Thread Next-in-Thread
 Next-in-Forum Next-in-Forum

Idea Re: How to define different colors of the hits. 

Forum: Particles
Re: Question How to define different colors of the hits. (Gardenia)
Date: 15 May, 2013
From: Zach Hartwig <Zach Hartwig>

Hi Gardenia,

Drawing and coloring of hits on a sensitive detector are handled by the G4VHit::Draw() method, which you can override in your derived hit class. Typically, you will instantiate a concrete hit object in your derived G4VSensitiveDetector::ProcessHits() method, fill the hit with data, and then store the hit into your sensitive detector hits collection. To color the hit by particle type, you could (as a rough example)

1. Create a G4Colour data member in your hit class, along with a public method to set the color:

  class MyHit : public G4VHit
    G4Colour HitColour;
    void SetHitColour(G4Colour aColour) {HitColour = aColour;}

2. Override the G4VHit::Draw() method in your hit class with something like:

  void scintillatorSDHit::Draw()
    G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
      G4Circle circle(position);
      G4VisAttributes attribs(HitColour);

3. Determine the hit particle in your sensitive detector class and set the the colour in each concrete hit object you instantiate

  MySD::ProcessHits(G4Step *aStep, G4TouchableHistory *tHistory)
   MyHit *NewHit = new MyHit;
   // Fill with other data 
   // Example of coloring hits by particle type
   if(currentTrack->GetParticleDefinition() == G4Proton::ProtonDefinition)
     NewHit->SetHitColour(G4Colour(1.0, 0.0, 0.0, 1.0)); // RED
   else if(currentTrack->GetParticleDefinition() == G4Electron::ElectronDefinition)
     NewHit->SetHitColour(G4Colour(0.0, 1.0, 0.0, 1.0)); // GREEN
     NewHit->SetHitColour(G4Colour(0.0, 0.0, 1.0, 1.0)); // BLUE

Hope that helps.


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

1 None: Re: How to define different colors of the hits.   (Gardenia - 15 May, 2013)
 Add Message Add Message
to: "Re: How to define different colors of the hits."

 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 ]