• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/Users/jmonk/Physics/ForIA/src/Vertex.cxx

Go to the documentation of this file.
00001 #include "ForIA/Vertex.hh"
00002 #include "ForIA/Event.hh"
00003 #include <set>
00004 #include <stdexcept>
00005 #include <cmath>
00006 
00007 namespace ForIA{
00008 
00009   using std::set;
00010   
00011   Vertex::Vertex(): m_event(0), m_gotR(false), m_type(BAD), 
00012   m_gotTracks(false), m_haveTrackIDs(false){
00013     
00014   }
00015   
00016   int Vertex::nTracks() const{
00017     return m_nTracks;
00018   }
00019   
00020   Vertex::VertexType Vertex::type() const{
00021     return m_type;
00022   }
00023   
00024   double Vertex::x() const{
00025     return m_x;
00026   }
00027   
00028   double Vertex::y() const{
00029     return m_y;
00030   }
00031   
00032   double Vertex::z() const{
00033     return m_z;
00034   }
00035  
00036   double Vertex::r()const{
00037     if(!m_gotR){
00038       m_r = m_x * m_x + m_y * m_y + m_z * m_z;
00039       m_r = sqrt(m_r);
00040       m_gotR = true;
00041     }
00042     
00043     return m_r;
00044   }
00045   
00046   bool Vertex::hasTrackAssociations()const{
00047     return m_haveTrackIDs;
00048   }
00049   
00050   const TrackVector &Vertex::associatedTracks()const{
00051     
00052     if(m_gotTracks || !hasTrackAssociations()) return m_associatedTracks;
00053     
00054     if(m_event == 0){
00055       throw std::runtime_error
00056       ("Vertex::associatedTracks: No Event pointer is set, therefore cannot access the tracks for the event.");
00057     }
00058     
00059     m_associatedTracks.clear();
00060     
00061     TrackVector allTracks = m_event->tracks();
00062     
00063     set<int> ids(m_trackIDs.begin(), m_trackIDs.end());
00064     
00065     for(TrackVector::const_iterator trk = allTracks.begin();
00066         trk != allTracks.end(); ++trk){
00067       if(ids.count((*trk)->id()) != 0){
00068         m_associatedTracks.push_back(*trk);
00069       }
00070     }
00071     
00072     if(m_associatedTracks.size() != ids.size()){
00073       throw std::runtime_error
00074       ("Vertex::associatedTracks: The number of tracks in the event matching this vertex is less than the number of track IDs held by the vertex.");
00075     }
00076     
00077     m_gotTracks = true;
00078     
00079     return m_associatedTracks;
00080   }
00081   
00082   std::ostream &operator <<(std::ostream &out, const Vertex &vtx){
00083     out<<"Vertex: Type = " << vtx.m_type;
00084     out<<" {x, y, z} = {"<<vtx.m_x<<", "<<vtx.m_y<<", "<<vtx.m_z<<"}, ";
00085     out<<"r = "<<vtx.r()<<", ";
00086     out<<"Number of tracks = "<<vtx.m_nTracks;
00087     return out;
00088   }
00089   
00090 }

Generated on Mon Jul 30 2012 16:56:35 for ForIA by  doxygen 1.7.2