Geant4-11
G4TrajectoryEncounteredVolumeFilter.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//
27// Filter trajectories according to encountered volume name. Only registered
28// volumes will pass the filter.
29//
30// John Allison, Feb 2016
31//
34#include "G4VTrajectoryPoint.hh"
35#include "G4AttValue.hh"
36#include "G4RichTrajectory.hh"
37
40{}
41
43
44bool
46{
47 try
48 {
49 const G4RichTrajectory& richTrajectory = dynamic_cast<const G4RichTrajectory&>(traj);
50
51 for (const auto& pvname: fVolumes) {
52 for (G4int iPoint = 0; iPoint < richTrajectory.GetPointEntries(); iPoint++) {
53 G4VTrajectoryPoint* point = richTrajectory.GetPoint(iPoint);
54 if (!point) continue;
55 std::vector<G4AttValue>* attValues = point->CreateAttValues();
56 std::vector<G4AttValue>::const_iterator iAtt;
57 for (iAtt = attValues->begin(); iAtt != attValues->end(); ++iAtt) {
58 if (iAtt->GetName() == "PostVPath" &&
59 G4StrUtil::contains(iAtt->GetValue(),pvname)) break;
60 }
61 if (iAtt != attValues->end()) { // Required value found
62 return true; // First found pvname determines selection.
63 }
64 }
65 }
66 return false;
67 }
68
69 catch (const std::bad_cast&)
70 {
72 ed << "Requires G4RichTrajectory - \"/vis/scene/add/trajectories rich\"";
74 ("G4TrajectoryEncounteredVolumeFilter::Evaluate(const G4VTrajectory& traj)",
75 "modeling0126",
76 JustWarning, ed);
77 return false;
78 }
79}
80
81void
83{
84 fVolumes.push_back(volume);
85}
86
87void
89{
90 ostr<<"Volume names registered: "<<G4endl;
91 std::vector<G4String>::const_iterator iter = fVolumes.begin();
92
93 while (iter != fVolumes.end()) {
94 ostr<<*iter<<G4endl;
95 iter++;
96 }
97}
98
99void
101{
102 // Clear volume vector
103 fVolumes.clear();
104}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4VTrajectoryPoint * GetPoint(G4int i) const
G4int GetPointEntries() const
virtual bool Evaluate(const G4VTrajectory &) const
virtual void Print(std::ostream &ostr) const
G4TrajectoryEncounteredVolumeFilter(const G4String &name="Unspecified")
virtual std::vector< G4AttValue > * CreateAttValues() const
const char * name(G4int ptype)
G4bool contains(const G4String &str, std::string_view ss)
Check if a string contains a given substring.