00001
00002
00003
00004
00005 #include "GaudiKernel/AlgFactory.h"
00006
00007
00008 #include "CLHEP/Units/PhysicalConstants.h"
00009
00010
00011 #include "Event/Track.h"
00012 #include "Event/TrackKeys.h"
00013
00014
00015 #include "TrackEventFitter.h"
00016
00017
00018
00019
00020
00021
00022
00023
00024 static const AlgFactory<TrackEventFitter> s_factory ;
00025 const IAlgFactory& TrackEventFitterFactory = s_factory ;
00026
00027
00028
00029
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
00047
00048 TrackEventFitter::~TrackEventFitter() {};
00049
00050
00051
00052
00053 StatusCode TrackEventFitter::initialize() {
00054 StatusCode sc = GaudiAlgorithm::initialize();
00055 if ( sc.isFailure() ) return sc;
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
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
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
00096
00097 Tracks* tracksCont = get<Tracks>( m_tracksInContainer );
00098
00099 debug() << "-> creating output Tracks container ..." << endmsg;
00100
00101
00102 Tracks* tracksNewCont = new Tracks();
00103
00104
00105
00106
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
00114 Track& track = *( (*iTrack) -> cloneWithKey() );
00115
00116
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
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 ) {
00133
00134 }
00135 else {
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
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 }
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
00162
00163 sc = registerTracks( tracksNewCont );
00164 if( sc.isFailure() ) return sc;
00165
00166 return StatusCode::SUCCESS;
00167 }
00168
00169
00170
00171
00172 StatusCode TrackEventFitter::finalize() {
00173
00174 debug() << "==> Finalize" << endmsg;
00175
00176 return GaudiAlgorithm::finalize();
00177 }
00178
00179
00180
00181
00182 State& TrackEventFitter::seedState( Track& track )
00183 {
00184 if ( m_fitUpstream )
00185 return *( *(track.states().end()-1) );
00186 else
00187 return track.firstState();
00188 }
00189
00190
00191
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