Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4TrajectoryOriginVolumeFilter.cc
Go to the documentation of this file.
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 66373 2012-12-18 09:41:34Z gcosmo $
27 //
28 // Filter trajectories according to volume name. Only registered
29 // volumes will pass the filter.
30 //
31 // Jane Tinslay May 2006
32 //
35 #include "G4VTrajectoryPoint.hh"
36 
39 {}
40 
42 
43 bool
45 {
47 
48  G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(0);
49  assert (0 != aTrajectoryPoint);
50 
51  G4VPhysicalVolume* volume = navigator->LocateGlobalPointAndSetup(aTrajectoryPoint->GetPosition());
52 
53  // Logical volume
54  G4LogicalVolume* logicalVolume = volume->GetLogicalVolume();
55  assert (0 != logicalVolume);
56 
57  // Get volume names
58  G4String logicalName = logicalVolume->GetName();
59  G4String physicalName = volume->GetName();
60 
61  if (GetVerbose()) {
62  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 
80 void
82 {
83  fVolumes.push_back(volume);
84 }
85 
86 void
87 G4TrajectoryOriginVolumeFilter::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 
98 void
100 {
101  // Clear volume vector
102  fVolumes.clear();
103 }
G4String GetName() const
#define assert(x)
Definition: mymalloc.cc:1309
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
G4Navigator * GetNavigatorForTracking() const
const XML_Char * name
G4TrajectoryOriginVolumeFilter(const G4String &name="Unspecified")
G4GLOB_DLL std::ostream G4cout
const G4String & GetName() const
static G4TransportationManager * GetTransportationManager()
virtual const G4ThreeVector GetPosition() const =0
G4LogicalVolume * GetLogicalVolume() const
virtual G4VPhysicalVolume * LocateGlobalPointAndSetup(const G4ThreeVector &point, const G4ThreeVector *direction=0, const G4bool pRelativeSearch=true, const G4bool ignoreDirection=true)
Definition: G4Navigator.cc:118
virtual bool Evaluate(const G4VTrajectory &) const
virtual void Print(std::ostream &ostr) const
#define G4endl
Definition: G4ios.hh:61