TestTrackViewer.cxx

Go to the documentation of this file.
00001 // ================================================
00002 // TestTrackViewer class Implementation
00003 // ================================================
00004 //
00005 //
00006 // Namespace ATLFast
00007 //
00008 #include "AtlfastAlgs/TestTrackViewer.h"
00009 #include "AtlfastAlgs/GlobalEventData.h"
00010 #include "AtlfastAlgs/ITrackViewer.h"
00011 #include "AtlfastAlgs/AtlfTrackViewer.h"
00012 #include "AtlfastAlgs/ITrackParameterView.h"
00013 #include "AtlfastAlgs/AtlfTrackParameterView.h"
00014 
00015 #include "AtlfastEvent/ITrackParameters.h"
00016 #include "AtlfastEvent/CollectionDefs.h"
00017 
00018 // Utilities
00019 #include <cmath> 
00020 #include <cassert> 
00021 #include <stdexcept>
00022 #include <sstream>
00023 #include "AtlfastEvent/Phi.h"
00024 #include "AtlfastUtils/HeaderPrinter.h"
00025 
00026 // This is part of the STL and allows you to use
00027 // generic sort algorithms (amongst other things)
00028 #include <algorithm>
00029 #include "AtlfastUtils/FunctionObjects.h"
00030 
00031 // Athena/Gaudi includes
00032 #include "GaudiKernel/DataSvc.h"
00033 
00034 //#include "AtlfastEvent/MsgStreamDefs.h"
00035 
00036 // A somewhat nicer assert...
00037 class atl_test_err
00038   : public std::exception
00039 {
00040 public:
00041   explicit atl_test_err (const char* file,
00042                         int line,
00043                         const char* what);
00044   virtual ~atl_test_err() throw() {}
00045   virtual const char* what() const throw() { return m_what.c_str(); }
00046 private:
00047   std::string m_what;
00048 };
00049 
00050 
00051 atl_test_err::atl_test_err (const char* file,
00052                             int line,
00053                             const char* what)
00054 {
00055   std::ostringstream os;
00056   os << file << ":" << line << " assertion failure: " << what;
00057   m_what = os.str();
00058 }
00059 
00060 
00061 void throw_atl_test_err (const char* file, int line, const char* what)
00062 {
00063   throw (atl_test_err (file, line, what));
00064 }
00065 
00066 #define ATL_ASSERT(X) do {     \
00067     if (!(X)) { \
00068       throw_atl_test_err (__FILE__, __LINE__, #X); \
00069     } \
00070   } while (0)
00071 
00072 //
00073 
00074 namespace Atlfast {
00075   using std::abs;
00076   using std::endl;
00077   
00078   
00079   //--------------------------------
00080   // Constructors and destructors
00081   //--------------------------------
00082   
00083   TestTrackViewer::TestTrackViewer ( const std::string& name, 
00084                                ISvcLocator* pSvcLocator ) 
00085     : Algorithm( name, pSvcLocator ){
00086     
00087     // Setting the parameter defaults.
00088     m_trackLocation      = "/Event/AtlfastTracks";
00089     declareProperty( "TrackLocation",    m_trackLocation ) ;
00090     
00091   }
00092   
00093   // Destructor
00094   TestTrackViewer::~TestTrackViewer() {
00095     MsgStream log( messageService(), name() ) ;
00096     log << MSG::INFO << "Destructor called" << endreq;
00097   } 
00098   
00099   
00100   //---------------------------------
00101   // initialise() 
00102   //---------------------------------
00103   
00104   StatusCode TestTrackViewer::initialize(){
00105     
00106     // We must here instantiate items which can only be made after
00107     // any job options have been set
00108     
00109     MsgStream log( messageService(), name() ) ;
00110     log << MSG::DEBUG << "Initialising" << endreq;
00111     HeaderPrinter hp("TestTrackViewer:",log);
00112     hp.add( "TrackLocation   ",   m_trackLocation ) ;
00113     hp.print();
00114 
00115     m_nevents = 0;
00116     m_ntracks = 0;
00117 
00118     GlobalEventData* ged = GlobalEventData::Instance();
00119     // load the location of the MC in StoreGate
00120     m_mcLocation       = ged -> mcLocation();
00121 
00122     //    m_tesIO = new TesIO(eventDataService());
00123     m_tesIO = new TesIO(m_mcLocation, ged->justHardScatter());
00124     
00125     return StatusCode::SUCCESS ;
00126   }
00127   
00128   
00129   //---------------------------------
00130   // finalise() 
00131   //---------------------------------
00132   
00133   StatusCode TestTrackViewer::finalize(){
00134     MsgStream log( messageService(), name() ) ;
00135     log << MSG::INFO << "Finalizing" << endreq;
00136     log<<  MSG::INFO  << "Events Processed: "<<m_nevents<<endreq;
00137     log<<  MSG::INFO  << "Tracks Processed: "<<m_ntracks<<endreq;
00138     return StatusCode::SUCCESS ;
00139   }
00140   
00141   
00142   //----------------------------------------------
00143   // execute() method called once per event
00144   //----------------------------------------------
00145   //
00146   
00147   
00148   StatusCode TestTrackViewer::execute( ){
00149     
00150     //................................
00151     // make a message logging stream 
00152     
00153     MsgStream log( messageService(), name() ) ;
00154     ++m_nevents;
00155     
00156     
00157     //.........................................................
00158     // This is how you extract the things you want to look at. 
00159     // Look at the userguide for details of ReconstructedParticle, Cell
00160     // and Cluster classes
00161     std::vector<Track*> tracks;
00162     if(!m_tesIO->copy<TrackCollection >(tracks, m_trackLocation)){
00163       log << MSG::DEBUG 
00164           << "No Tracks found in TES at " 
00165           << m_trackLocation 
00166           << endreq ;
00167     }else{
00168       log << MSG::DEBUG 
00169           << "No. of Tracks found in TES  = " 
00170           << tracks.size() 
00171           << endreq ;
00172     }
00173     
00174     //.........................................................
00175     // Here are example things you might do
00176     
00177     
00178     if( tracks.size() ) this->testViewer( log, tracks ) ;
00179     
00180     return StatusCode::SUCCESS ;
00181     
00182   }
00183   
00184   
00185   //-------------------------------------------
00186   // private: testViewer
00187   //------------------------------------------
00188   
00189   void TestTrackViewer::testViewer ( MsgStream& log, 
00190                                      std::vector<Track*>& tracks){
00191     
00192     log << MSG::DEBUG << "Starting track view tester" << endreq ;
00193     
00194     
00195     
00196     // traverse collection of particles
00197     std::vector<Track*>::const_iterator track;
00198     
00199     for( track = tracks.begin(); track < tracks.end(); ++track ){
00200       
00201       log << MSG::DEBUG << *track << endreq;
00202       ++m_ntracks;
00203       TrackTrajectory traj = (*track)->trajectory();
00204       AtlfAna::AtlfTrackViewer trackViewer(*track);
00205       AtlfAna::ITrackParameterView& parameterView =  trackViewer;
00206       log<<MSG::DEBUG<<parameterView.trackParameters()<<endreq;
00207       const ITrackParameters& tp = parameterView.trackParameters();
00208       double eps = 0.0000001;
00209       TrackParameters testParam = (*track)->trajectory().parameters();
00210       ATL_ASSERT(abs( tp.eta()-testParam.eta() )                         < eps);
00211       ATL_ASSERT(abs( tp.phi()-testParam.phi() )                         < eps);
00212       ATL_ASSERT(abs( tp.cotTheta()-testParam.cotTheta() )               < eps);
00213       ATL_ASSERT(abs( tp.impactParameter()-testParam.impactParameter() ) < eps);
00214       ATL_ASSERT(abs( tp.zPerigee()-testParam.zPerigee() )               < eps);
00215       ATL_ASSERT(abs( tp.invPtCharge()-testParam.invPtCharge() )         < eps);
00216     }
00217     
00218   }
00219   
00220   
00221 } // end of namespace bracket

Generated on Mon Sep 24 14:19:12 2007 for AtlfastAlgs by  doxygen 1.5.1