G4TrajectoryOriginVolumeFilter.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // Filter trajectories according to volume name. Only registered 
00029 // volumes will pass the filter.
00030 //
00031 // Jane Tinslay May 2006
00032 //
00033 #include "G4TrajectoryOriginVolumeFilter.hh"
00034 #include "G4TransportationManager.hh"
00035 #include "G4VTrajectoryPoint.hh"
00036 
00037 G4TrajectoryOriginVolumeFilter::G4TrajectoryOriginVolumeFilter(const G4String& name)
00038   :G4SmartFilter<G4VTrajectory>(name)
00039 {}
00040 
00041 G4TrajectoryOriginVolumeFilter::~G4TrajectoryOriginVolumeFilter() {}
00042 
00043 bool
00044 G4TrajectoryOriginVolumeFilter::Evaluate(const G4VTrajectory& traj) const
00045 {
00046   G4Navigator* navigator = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking();
00047   
00048   G4VTrajectoryPoint* aTrajectoryPoint = traj.GetPoint(0);
00049   assert (0 != aTrajectoryPoint);
00050   
00051   G4VPhysicalVolume* volume = navigator->LocateGlobalPointAndSetup(aTrajectoryPoint->GetPosition());
00052 
00053   // Logical volume
00054   G4LogicalVolume* logicalVolume = volume->GetLogicalVolume();
00055   assert (0 != logicalVolume);
00056 
00057   // Get volume names
00058   G4String logicalName = logicalVolume->GetName();
00059   G4String physicalName = volume->GetName();
00060 
00061   if (GetVerbose()) {
00062     G4cout<<"G4TrajectoryOriginVolumeFilter processing trajectory with originating volume "<<G4endl;
00063     G4cout<<"logical and physical names:  "<<logicalName<<" "<<physicalName<<G4endl;
00064   }
00065   // Search for logical volume name
00066   std::vector<G4String>::const_iterator iterLogical = std::find(fVolumes.begin(), fVolumes.end(), logicalName);
00067 
00068   // Keep if logical volume registered
00069   if (iterLogical != fVolumes.end()) return true;
00070 
00071   // Repeat for physical volume name
00072   std::vector<G4String>::const_iterator iterPhysical = std::find(fVolumes.begin(), fVolumes.end(), physicalName);
00073 
00074   if (iterPhysical != fVolumes.end()) return true;
00075 
00076   // Volume names not registered
00077   return false;
00078 }
00079 
00080 void
00081 G4TrajectoryOriginVolumeFilter::Add(const G4String& volume)
00082 {
00083   fVolumes.push_back(volume);
00084 }
00085 
00086 void
00087 G4TrajectoryOriginVolumeFilter::Print(std::ostream& ostr) const
00088 {
00089   ostr<<"Volume names registered: "<<G4endl;
00090   std::vector<G4String>::const_iterator iter = fVolumes.begin();
00091   
00092   while (iter != fVolumes.end()) {
00093     ostr<<*iter<<G4endl;    
00094     iter++;
00095   }
00096 }
00097 
00098 void 
00099 G4TrajectoryOriginVolumeFilter::Clear()
00100 {
00101   // Clear volume vector
00102   fVolumes.clear();
00103 }

Generated on Mon May 27 17:50:02 2013 for Geant4 by  doxygen 1.4.7