Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 95115 2016-01-26 16:33:29Z 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 {
46  G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(0);
47  assert (0 != aTrajectoryPoint);
48 
49  G4Navigator* navigator =
51 
52  G4VPhysicalVolume* volume = navigator->LocateGlobalPointAndSetup
53  (aTrajectoryPoint->GetPosition(), nullptr,false,true);
54 
55  // Logical volume
56  G4LogicalVolume* logicalVolume = volume->GetLogicalVolume();
57  assert (0 != logicalVolume);
58 
59  // Get volume names
60  G4String logicalName = logicalVolume->GetName();
61  G4String physicalName = volume->GetName();
62 
63  if (GetVerbose()) {
64  G4cout<<"G4TrajectoryOriginVolumeFilter processing trajectory with originating volume "<<G4endl;
65  G4cout<<"logical and physical names: "<<logicalName<<" "<<physicalName<<G4endl;
66  }
67  // Search for logical volume name
68  std::vector<G4String>::const_iterator iterLogical = std::find(fVolumes.begin(), fVolumes.end(), logicalName);
69 
70  // Keep if logical volume registered
71  if (iterLogical != fVolumes.end()) return true;
72 
73  // Repeat for physical volume name
74  std::vector<G4String>::const_iterator iterPhysical = std::find(fVolumes.begin(), fVolumes.end(), physicalName);
75 
76  if (iterPhysical != fVolumes.end()) return true;
77 
78  // Volume names not registered
79  return false;
80 }
81 
82 void
84 {
85  fVolumes.push_back(volume);
86 }
87 
88 void
89 G4TrajectoryOriginVolumeFilter::Print(std::ostream& ostr) const
90 {
91  ostr<<"Volume names registered: "<<G4endl;
92  std::vector<G4String>::const_iterator iter = fVolumes.begin();
93 
94  while (iter != fVolumes.end()) {
95  ostr<<*iter<<G4endl;
96  iter++;
97  }
98 }
99 
100 void
102 {
103  // Clear volume vector
104  fVolumes.clear();
105 }
const XML_Char * name
Definition: expat.h:151
virtual G4VTrajectoryPoint * GetPoint(G4int i) const =0
G4Navigator * GetNavigatorForTracking() const
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:125
virtual bool Evaluate(const G4VTrajectory &) const
virtual void Print(std::ostream &ostr) const
#define G4endl
Definition: G4ios.hh:61
const G4String & GetName() const