source: trunk/source/visualization/modeling/src/G4TrajectoryOriginVolumeFilter.cc @ 1346

Last change on this file since 1346 was 1346, checked in by garnier, 13 years ago

before tag

File size: 3.9 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// $Id: G4TrajectoryOriginVolumeFilter.cc,v 1.3 2006/08/25 19:44:14 tinslay Exp $
27// GEANT4 tag $Name:  $
28//
29// Filter trajectories according to volume name. Only registered
30// volumes will pass the filter.
31//
32// Jane Tinslay May 2006
33//
34#include "G4TrajectoryOriginVolumeFilter.hh"
35#include "G4TransportationManager.hh"
36#include "G4VTrajectoryPoint.hh"
37
38G4TrajectoryOriginVolumeFilter::G4TrajectoryOriginVolumeFilter(const G4String& name)
39  :G4SmartFilter<G4VTrajectory>(name)
40{}
41
42G4TrajectoryOriginVolumeFilter::~G4TrajectoryOriginVolumeFilter() {}
43
44bool
45G4TrajectoryOriginVolumeFilter::Evaluate(const G4VTrajectory& traj) const
46{
47  G4Navigator* navigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
48 
49  G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(0);
50  assert (0 != aTrajectoryPoint);
51 
52  G4VPhysicalVolume* volume = navigator->LocateGlobalPointAndSetup(aTrajectoryPoint->GetPosition());
53
54  // Logical volume
55  G4LogicalVolume* logicalVolume = volume->GetLogicalVolume();
56  assert (0 != logicalVolume);
57
58  // Get volume names
59  G4String logicalName = logicalVolume->GetName();
60  G4String physicalName = volume->GetName();
61
62  if (GetVerbose()) G4cout<<"G4TrajectoryOriginVolumeFilter processing trajectory with originating volume "<<G4endl;
63  G4cout<<"logical and physical names:  "<<logicalName<<" "<<physicalName<<G4endl;
64
65  // Search for logical volume name
66  std::vector<G4String>::const_iterator iterLogical = std::find(fVolumes.begin(), fVolumes.end(), logicalName);
67
68  // Keep if logical volume registered
69  if (iterLogical != fVolumes.end()) return true;
70
71  // Repeat for physical volume name
72  std::vector<G4String>::const_iterator iterPhysical = std::find(fVolumes.begin(), fVolumes.end(), physicalName);
73
74  if (iterPhysical != fVolumes.end()) return true;
75
76  // Volume names not registered
77  return false;
78}
79
80void
81G4TrajectoryOriginVolumeFilter::Add(const G4String& volume)
82{
83  fVolumes.push_back(volume);
84}
85
86void
87G4TrajectoryOriginVolumeFilter::Print(std::ostream& ostr) const
88{
89  ostr<<"Volume names registered: "<<G4endl;
90  std::vector<G4String>::const_iterator iter = fVolumes.begin();
91 
92  while (iter != fVolumes.end()) {
93    ostr<<*iter<<G4endl;   
94    iter++;
95  }
96}
97
98void 
99G4TrajectoryOriginVolumeFilter::Clear()
100{
101  // Clear volume vector
102  fVolumes.clear();
103}
Note: See TracBrowser for help on using the repository browser.