Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TrackEventFitter.cpp

Go to the documentation of this file.
00001 // $Id: TrackEventFitter.cpp,v 1.1 2005/06/29 15:35:02 erodrigu Exp $
00002 // Include files
00003 // -------------
00004 // from Gaudi
00005 #include "GaudiKernel/AlgFactory.h" 
00006 
00007 // from CLHEP
00008 #include "CLHEP/Units/PhysicalConstants.h"
00009 
00010 // from TrackEvent
00011 #include "Event/Track.h"
00012 #include "Event/TrackKeys.h"
00013 
00014 // local
00015 #include "TrackEventFitter.h"
00016 
00017 //-----------------------------------------------------------------------------
00018 // Implementation file for class : TrackEventFitter
00019 //
00020 // 2005-05-30 : Eduardo Rodrigues
00021 //-----------------------------------------------------------------------------
00022 
00023 // Declaration of the Algorithm Factory
00024 static const  AlgFactory<TrackEventFitter>          s_factory ;
00025 const        IAlgFactory& TrackEventFitterFactory = s_factory ; 
00026 
00027 
00028 //=============================================================================
00029 // Standard constructor, initializes variables
00030 //=============================================================================
00031 TrackEventFitter::TrackEventFitter( const std::string& name,
00032                                     ISvcLocator* pSvcLocator)
00033   : GaudiAlgorithm ( name , pSvcLocator )
00034   , m_tracksFitter(0)
00035   , m_measProvider(0)
00036 {
00037   declareProperty( "TracksInContainer", 
00038                    m_tracksInContainer = TrackLocation::Default );
00039   declareProperty( "TracksOutContainer", 
00040                    m_tracksOutContainer = "Rec/Track/FitIdeal" );
00041   declareProperty( "FitterName"      , m_fitterName = "KalmanFilter" );
00042   declareProperty( "FitUpstream"     , m_fitUpstream   = false );
00043 }
00044 
00045 //=============================================================================
00046 // Destructor
00047 //=============================================================================
00048 TrackEventFitter::~TrackEventFitter() {}; 
00049 
00050 //=============================================================================
00051 // Initialization
00052 //=============================================================================
00053 StatusCode TrackEventFitter::initialize() {
00054   StatusCode sc = GaudiAlgorithm::initialize(); // must be executed first
00055   if ( sc.isFailure() ) return sc;  // error printed already by GaudiAlgorithm
00056 
00057   debug() << "==> Initialize" << endmsg;
00058 
00059   m_tracksFitter = tool<ITrackFitter>( m_fitterName, "Fitter", this );
00060 
00061   m_measProvider = tool<IMeasurementProvider>( "MeasurementProvider",
00062                                                "MeasProvider", this );
00063 
00064   // Print out the user-defined settings
00065   // -----------------------------------
00066   std::string fitType;
00067   if ( m_fitUpstream ) fitType = "upstream";
00068   else                 fitType = "downstream";
00069 
00070   info()
00071     << " " << endreq
00072     << "================ TrackEventFitter Settings ================"
00073     << endreq
00074     << "  Tracks input container   : " << m_tracksInContainer << endreq
00075     << "  Tracks output container  : " << m_tracksOutContainer << endreq
00076     << "  Fitter name              : " << m_fitterName << endreq
00077     << "  Fit type                 : " << fitType << endreq
00078     << "==========================================================="
00079     << endreq
00080     << " " << endreq;
00081 
00082   return StatusCode::SUCCESS;
00083 };
00084 
00085 //=============================================================================
00086 // Main execution
00087 //=============================================================================
00088 StatusCode TrackEventFitter::execute() {
00089 
00090   debug() << "==> Execute" << endmsg;
00091 
00092   StatusCode sc = StatusCode::SUCCESS;
00093 
00094   debug() << "-> getting input Tracks container ..." << endmsg;
00095   // Retrieve the Tracks container
00096   // -----------------------------
00097   Tracks* tracksCont = get<Tracks>( m_tracksInContainer );
00098 
00099   debug() << "-> creating output Tracks container ..." << endmsg;
00100   // Make container for tracks
00101   // -------------------------
00102   Tracks* tracksNewCont = new Tracks();
00103 
00104   // Loop over the tracks and fit them
00105   // ---------------------------------
00106   //Tracks::const_iterator iTrack = tracksCont -> begin();
00107   Tracks::const_iterator iTrack;
00108   unsigned int nFitFail = 0;
00109 
00110   debug() << "-> tarting loop over input Tracks ..." << endmsg;
00111   for ( iTrack=tracksCont->begin(); iTrack != tracksCont->end(); ++iTrack ) {
00112 
00113     // Make a new track keeping the same key
00114     Track& track = *( (*iTrack) -> cloneWithKey() );
00115 
00116     // check if it is needed to populate the track with measurements
00117     if ( track.checkFlag( TrackKeys::PatRecIDs ) ) {
00118       m_measProvider -> load();    
00119       sc = m_measProvider -> load( track );
00120       if ( sc.isFailure() )
00121         return Error( "Unable to load measurements!", StatusCode::FAILURE); 
00122     }
00123 
00124     // get the seed state
00125     if ( track.nStates() == 0 )
00126       return Error( "Track has no state!", StatusCode::FAILURE);
00127 
00128     State& seed = seedState( track );
00129 
00130     debug() << "#### Fitting Track # " << track.key() << " ####" << endreq;
00131 
00132     if ( m_fitUpstream ) {  // fit upstream from last measurement
00133       //sc = m_tracksFitter -> fitReverse( track );
00134     } 
00135     else {                       // fit downstream from first measurement
00136       sc = m_tracksFitter -> fit( track, seed );
00137     }
00138 
00139     if ( sc.isSuccess() ) {
00140       debug() << "Fitted successfully track # " << track.key() << endreq;
00141       track.setStatus( TrackKeys::Fitted );
00142       // Add the track to the new Tracks container
00143       // -----------------------------------------
00144       tracksNewCont -> add( &track );
00145     }
00146     else {
00147       debug() << "Unable to fit the track # " << track.key() << endreq;
00148       track.setFlag( TrackKeys::Invalid, true );
00149       track.setStatus( TrackKeys::FitFailed );
00150       nFitFail++;
00151     }
00152 
00153   } // loop over input Tracks
00154   
00155   if ( nFitFail == 0 )
00156     info() << "All tracks fitted succesfully." << endreq;
00157   else
00158     info() << "Fitted successfully " << (tracksCont->size()-nFitFail)
00159            << " out of " << tracksCont->size() << endreq;
00160 
00161   // Store the Tracks in the TES
00162   // ---------------------------
00163   sc = registerTracks( tracksNewCont );
00164   if( sc.isFailure() ) return sc;
00165 
00166   return StatusCode::SUCCESS;
00167 }
00168 
00169 //=============================================================================
00170 //  Finalize
00171 //=============================================================================
00172 StatusCode TrackEventFitter::finalize() {
00173 
00174   debug() << "==> Finalize" << endmsg;
00175 
00176   return GaudiAlgorithm::finalize();  // must be called after all other actions
00177 }
00178 
00179 //=============================================================================
00180 // Get a seed State from the Track
00181 //=============================================================================
00182 State& TrackEventFitter::seedState( Track& track )
00183 {
00184   if ( m_fitUpstream )  // fit upstream
00185     return *( *(track.states().end()-1) );
00186   else                  // fit downstream
00187     return track.firstState();
00188 }
00189 
00190 //=============================================================================
00191 // Register the tracks container in the TES
00192 //=============================================================================
00193 StatusCode TrackEventFitter::registerTracks( Tracks* tracksCont )
00194 {
00195   StatusCode sc = put( tracksCont, m_tracksOutContainer );
00196 
00197   if ( sc.isFailure() )
00198     error() << "Unable to register the output container at "
00199             << m_tracksOutContainer << ". Status is " << sc << endreq;
00200 
00201   debug() << "Tracks container stored in the TES" << endreq;
00202 
00203   return StatusCode::SUCCESS;
00204 }
00205 
00206 //=============================================================================

Generated on Mon Jul 4 13:54:29 2005 for New Track Event Model by doxygen 1.4.1