source: trunk/examples/extended/eventgenerator/HepMC/MCTruth/src/MCTruthTrackingAction.cc @ 1337

Last change on this file since 1337 was 1337, checked in by garnier, 14 years ago

tag geant4.9.4 beta 1 + modifs locales

File size: 4.5 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer                                           *
4// *                                                                  *
5// * The  Geant4 software  is  copyright of the Copyright Holders  of *
6// * the Geant4 Collaboration.  It is provided  under  the terms  and *
7// * conditions of the Geant4 Software License,  included in the file *
8// * LICENSE and available at  http://cern.ch/geant4/license .  These *
9// * include a list of copyright holders.                             *
10// *                                                                  *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work  make  any representation or  warranty, express or implied, *
14// * regarding  this  software system or assume any liability for its *
15// * use.  Please see the license in the file  LICENSE  and URL above *
16// * for the full disclaimer and the limitation of liability.         *
17// *                                                                  *
18// * This  code  implementation is the result of  the  scientific and *
19// * technical work of the GEANT4 collaboration.                      *
20// * By using,  copying,  modifying or  distributing the software (or *
21// * any work based  on the software)  you  agree  to acknowledge its *
22// * use  in  resulting  scientific  publications,  and indicate your *
23// * acceptance of all terms of the Geant4 Software license.          *
24// ********************************************************************
25//
26//
27// $Id: MCTruthTrackingAction.cc,v 1.1 2006/11/22 14:51:30 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-04-beta-01 $
29//
30//
31// --------------------------------------------------------------
32//      GEANT 4 - MCTruthTrackingAction class
33// --------------------------------------------------------------
34//
35// Author: Witold POKORSKI (Witold.Pokorski@cern.ch)
36//
37// --------------------------------------------------------------
38
39#include <iostream>
40
41#include "G4Track.hh"
42#include "G4TrackVector.hh"
43#include "G4TrackingManager.hh"
44#include "MCTruthTrackingAction.hh"
45#include "MCTruthTrackInformation.hh"
46
47MCTruthTrackingAction::MCTruthTrackingAction() 
48{}
49
50MCTruthTrackingAction::~MCTruthTrackingAction() 
51{} 
52
53void MCTruthTrackingAction::PreUserTrackingAction(const G4Track* track)
54{
55  fmom = G4LorentzVector(track->GetMomentum(), track->GetTotalEnergy());
56 
57  if(!track->GetUserInformation()) 
58  {
59    G4VUserTrackInformation* mcinf = new MCTruthTrackInformation;
60    fpTrackingManager->SetUserTrackInformation(mcinf);
61  }
62}
63
64void MCTruthTrackingAction::PostUserTrackingAction(const G4Track* track)
65{
66
67  G4LorentzVector prodpos(track->GetGlobalTime() - track->GetLocalTime(),
68                             track->GetVertexPosition());
69  G4LorentzVector endpos(track->GetGlobalTime(), track->GetPosition());
70
71  // here (?) make all different checks to decide whether to store the particle
72  //
73  if (trackToBeStored(track))
74  {
75    MCTruthTrackInformation* mcinf =
76      (MCTruthTrackInformation*) track->GetUserInformation();
77
78    MCTruthManager::GetInstance()->
79      AddParticle(fmom, prodpos, endpos,
80                  track->GetDefinition()->GetPDGEncoding(),
81                  track->GetTrackID(),
82                  track->GetParentID(), mcinf->GetDirectParent());
83  }
84  else
85  {
86    // If track is not to be stored, propagate it's parent ID (stored)
87    // to its secondaries
88    //
89    G4TrackVector* childrens = fpTrackingManager->GimmeSecondaries() ;
90
91    for( unsigned int index = 0 ; index < childrens->size() ; ++index )
92    {
93      G4Track* tr = (*childrens)[index] ;
94      tr->SetParentID( track->GetParentID() );
95
96      // set the flag saying that the direct mother is not stored
97      //
98      MCTruthTrackInformation* mcinf =
99        (MCTruthTrackInformation*) tr->GetUserInformation();
100      if(!mcinf)
101        tr->SetUserInformation(mcinf = new MCTruthTrackInformation);
102
103      mcinf->SetDirectParent(false); 
104    }     
105  }
106}
107
108G4bool MCTruthTrackingAction::trackToBeStored(const G4Track* track)
109{
110  MCTruthConfig* config = MCTruthManager::GetInstance()->GetConfig();
111 
112  // check energy
113  if (fmom.e() > config->GetMinE()) return true;
114 
115  // particle type
116  std::vector<G4int> types = config->GetParticleTypes();
117 
118  if(std::find( types.begin(), types.end(),
119                track->GetDefinition()->GetPDGEncoding())
120     != types.end()) return true;
121
122  // creator process
123
124  // etc...
125 
126  return false;
127}
Note: See TracBrowser for help on using the repository browser.