00001
00002
00003
00004 #include "GaudiKernel/AlgFactory.h"
00005 #include "GaudiKernel/IDataProviderSvc.h"
00006
00007
00008 #include "Event/TrFitTrack.h"
00009 #include "Event/ITClusterOnTrack.h"
00010 #include "Event/OTClusterOnTrack.h"
00011 #include "Event/VeloRClusterOnTrack.h"
00012 #include "Event/VeloPhiClusterOnTrack.h"
00013
00014
00015 #include "Event/Track.h"
00016 #include "Event/TrackKeys.h"
00017
00018
00019 #include "Kernel/LHCbID.h"
00020
00021
00022 #include "TrFitTrack2TrackCnv.h"
00023
00024
00025
00026
00027
00028
00029
00030
00031 static const AlgFactory<TrFitTrack2TrackCnv> Factory ;
00032 const IAlgFactory& TrFitTrack2TrackCnvFactory = Factory ;
00033
00034
00035
00036
00037 TrFitTrack2TrackCnv::TrFitTrack2TrackCnv( const std::string& name,
00038 ISvcLocator* pSvcLocator)
00039 : GaudiAlgorithm ( name , pSvcLocator )
00040 , m_inputTrackName ( TrFitTrackLocation::Default )
00041 , m_outputTrackName ( TrackLocation::Default )
00042 {
00043 declareProperty( "InputTracks" , m_inputTrackName );
00044 declareProperty( "OutputTracks", m_outputTrackName );
00045 }
00046
00047
00048
00049
00050 TrFitTrack2TrackCnv::~TrFitTrack2TrackCnv() {};
00051
00052
00053
00054
00055 StatusCode TrFitTrack2TrackCnv::initialize() {
00056
00057
00058
00059 StatusCode sc = GaudiAlgorithm::initialize() ;
00060 if ( sc.isFailure() )
00061 return Error( "Base class \"GaudiAlgorithm\" was not initialized properly!" );
00062
00063 debug() << "==> Initialize" << endreq;
00064
00065 return StatusCode::SUCCESS;
00066 };
00067
00068
00069
00070
00071 StatusCode TrFitTrack2TrackCnv::execute() {
00072
00073 debug() << "==> Execute" << endreq;
00074
00075
00076 TrFitTracks* inTra = get<TrFitTracks>( m_inputTrackName );
00077 debug() << "- # TrFitTracks = " << inTra -> size() << endreq;
00078
00079
00080 Tracks* outTra = new Tracks();
00081 StatusCode sc = eventSvc() -> registerObject( m_outputTrackName, outTra );
00082 if( sc.isFailure() ) {
00083 delete outTra;
00084 error() << "Unable to register the output container "
00085 << m_outputTrackName << ". Status is " << sc << endreq;
00086 return sc ;
00087 }
00088 else {
00089 debug() << "Output container " << m_outputTrackName
00090 << " registered" << endreq;
00091 }
00092
00093 TrStateP* trStaP;
00094 TrStateL* trStaL;
00095 TrState* trSta;
00096 OTClusterOnTrack* myOt;
00097 ITClusterOnTrack* myIt;
00098 VeloRClusterOnTrack* myRV;
00099 VeloPhiClusterOnTrack* myPV;
00100 TrFitTracks::const_iterator itF;
00101 TrStates::const_iterator itS;
00102 TrTrack::TrMeasurements::const_iterator itM;
00103
00104 Track* trSto;
00105 LHCbID myID;
00106 std::vector<LHCbID> myIDs;
00107
00108 debug() << "Processing TrFitTracks ... " << endreq;
00109
00110 for ( itF = inTra->begin() ; inTra->end() != itF ; ++itF ) {
00111
00112 trSto = new Track();
00113 outTra -> insert( trSto, (*itF)->key() );
00114
00115
00116 debug()
00117 << "- TrFitTrack with key # " << (*itF) -> key() << endreq
00118 << " * # states = " << (*itF) -> nStates() << endreq
00119 << " * # measurements = " << (*itF) -> nMeasurements() << endreq
00120 << " - # IT = " << (*itF) -> nMeasurements( TrMeasurement::kITClusterOnTrack ) << endreq
00121 << " - # OT = " << (*itF) -> nMeasurements( TrMeasurement::kOTClusterOnTrack ) << endreq
00122 << " - # VeloR = " << (*itF) -> nMeasurements( TrMeasurement::kVeloRClusterOnTrack ) << endreq
00123 << " - # VeloPhi = " << (*itF) -> nMeasurements( TrMeasurement::kVeloPhiClusterOnTrack ) << endreq
00124 << " * charge = " << (*itF) -> charge() << endreq
00125 << " * error flag = " << (*itF) -> errorFlag() << endreq
00126 << " * is Unique = " << (*itF) -> unique() << endreq
00127 << " * is Long = " << (*itF) -> isLong() << endreq
00128 << " * is Upstream = " << (*itF) -> isUpstream() << endreq
00129 << " * is Downstream = " << (*itF) -> isDownstream() << endreq
00130 << " * is Velotrack = " << (*itF) -> isVelotrack() << endreq
00131 << " * is Backward = " << (*itF) -> isBackward() << endreq
00132 << " * is Ttrack = " << (*itF) -> isTtrack() << endreq
00133 << " * velo = " << (*itF) -> velo() << endreq
00134 << " * seed = " << (*itF) -> seed() << endreq
00135 << " * match = " << (*itF) -> match() << endreq
00136 << " * forward = " << (*itF) -> forward() << endreq
00137 << " * follow = " << (*itF) -> follow() << endreq
00138 << " * veloTT = " << (*itF) -> veloTT() << endreq
00139 << " * veloBack = " << (*itF) -> veloBack() << endreq
00140 << " * ksTrack = " << (*itF) -> ksTrack() << endreq;
00141
00142
00143
00144 if ( (bool) (!(*itF)->errorFlag()) ) trSto -> setFlag( TrackKeys::Valid, true );
00145 if ( (bool) (*itF)->unique() ) trSto -> setFlag( TrackKeys::Unique, true );
00146
00147 if ( (*itF)->isLong() ) trSto -> setType( TrackKeys::Long );
00148 else if ( (*itF)->isUpstream() ) trSto -> setType( TrackKeys::Upstream );
00149 else if ( (*itF)->isDownstream() ) trSto -> setType( TrackKeys::Downstream );
00150 else if ( (*itF)->isVelotrack() ) trSto -> setType( TrackKeys::Velo );
00151 else if ( (*itF)->isBackward() ) trSto -> setType( TrackKeys::Backward );
00152 else if ( (*itF)->isTtrack() ) trSto -> setType( TrackKeys::Ttrack );
00153
00154 if ( (*itF)->ksTrack() ) trSto -> setHistory( TrackKeys::TrKshort );
00155
00156
00157 debug()
00158 << " -> Track stored with key # " << trSto -> key() << endreq
00159 << " * is Valid = "
00160 << trSto -> checkFlag( TrackKeys::Valid ) << endreq
00161 << " * is Unique = "
00162 << trSto -> checkFlag( TrackKeys::Unique ) << endreq
00163 << " * is Long = "
00164 << trSto -> checkType( TrackKeys::Long ) << endreq
00165 << " * is Upstream = "
00166 << trSto -> checkType( TrackKeys::Upstream ) << endreq
00167 << " * is Downstream = "
00168 << trSto -> checkType( TrackKeys::Downstream ) << endreq
00169 << " * is Velo = "
00170 << trSto -> checkType( TrackKeys::Velo ) << endreq
00171 << " * is Backward = "
00172 << trSto -> checkType( TrackKeys::Backward ) << endreq
00173 << " * is Ttrack = "
00174 << trSto -> checkType( TrackKeys::Ttrack ) << endreq;
00175
00176
00177 unsigned ist = 0;
00178 for ( itS = (*itF)->beginS() ; (*itF)->endS() != itS; itS++ ) {
00179 trSta = (*itS)->clone();
00180 trStaP = dynamic_cast<TrStateP*>(trSta);
00181 trStaL = dynamic_cast<TrStateL*>(trSta);
00182 if ( 0 != trStaP ) {
00183 debug() << " * TrStateP # " << ist++ << endreq
00184 << " - (x,y,z) = (" << trStaP -> x() << ", "
00185 << trStaP -> y() << ", "
00186 << trStaP -> z() << ")" << endreq
00187 << " - tx, ty, Q/P = " << trStaP -> tx() << ", "
00188 << trStaP -> ty() << ", "
00189 << trStaP -> qDivP() << endreq;
00190 }
00191 else if ( 0 != trStaL ) {
00192 debug() << " * TrStateL # " << ist++ << endreq
00193 << " - (x,y,z) = (" << trStaL -> x() << ", "
00194 << trStaL -> y() << ", "
00195 << trStaL -> z() << ")" << endreq
00196 << " - tx, ty = " << trStaL -> tx() << ", "
00197 << trStaL -> ty() << endreq;
00198 }
00199 else {
00200 verbose() << " * unknown state at z =" << trSta -> z() << "!" << endreq;
00201 delete trSta;
00202 }
00203 }
00204
00205
00206 trSta = (*itF) -> closestState(0.);
00207 trStaP = dynamic_cast<TrStateP*>(trSta);
00208 trStaL = dynamic_cast<TrStateL*>(trSta);
00209 if ( 0 != trStaP ) {
00210 State& pstate = trSto -> firstState();
00211 pstate.setState( trStaP->x(), trStaP->y(), trStaP->z(),
00212 trStaP->tx(), trStaP->ty(), trStaP->qDivP() );
00213 pstate.setCovariance( trStaP->stateCov() );
00214 debug() << " -> stored TrStateP at z = " << trStaP -> z()
00215 << " as first state" << endreq;
00216 }
00217 else if ( 0 != trStaL ) {
00218 verbose() << " -> no first state stored!" << endreq;
00219 }
00220 debug() << " -> track charge = " << trSto -> charge() << endreq;
00221
00222
00223 myIDs.clear();
00224 for ( itM = (*itF)->beginM() ; (*itF)->endM() != itM ; itM++ ) {
00225 if ( TrMeasurement::kOTClusterOnTrack == (*itM)->measType()) {
00226
00227
00228
00229
00230
00231
00232
00233
00234 myOt = dynamic_cast<OTClusterOnTrack*>(*itM);
00235 OTTime* otTime = myOt -> time();
00236 myID = LHCbID( otTime -> channel() );
00237 int amb = myOt -> ambiguity();
00238
00239 if ( amb != 0 ) {
00240 ( amb < 0 ) ? myID.setSpareBits( 2 ) : myID.setSpareBits( 3 );
00241 }
00242 else {
00243 myID.setSpareBits( 0 );
00244 }
00245 myIDs.push_back( myID );
00246 debug() << " * OTCluster at z = " << myOt -> z()
00247 << " , channelID = " << otTime -> channel().channelID()
00248 << " , ambiguity = " << amb << endreq
00249 << " -> stored as LHCbID = " << myID.lhcbID()
00250 << " (detectorType / spareBits = "
00251 << myID.detectorType() << " / "
00252 << myID.spareBits() << ")" << endreq;
00253 }
00254 else if ( TrMeasurement::kITClusterOnTrack == (*itM)->measType() ) {
00255
00256
00257
00258
00259
00260
00261
00262 myIt = dynamic_cast<ITClusterOnTrack*>(*itM);
00263 ITCluster* itClu = myIt -> cluster();
00264 myID = LHCbID( itClu -> channelID() );
00265 myIDs.push_back( myID );
00266 debug() << " * ITCluster at z = " << myIt -> z()
00267 << " , channelID = "
00268 << itClu -> channelID().channelID() << endreq
00269 << " -> stored as LHCbID = " << myID.lhcbID()
00270 << " (detectorType / spareBits = "
00271 << myID.detectorType() << " / "
00272 << myID.spareBits() << ")" << endreq;
00273 }
00274 else if ( TrMeasurement::kVeloRClusterOnTrack == (*itM)->measType() ) {
00275
00276
00277
00278
00279
00280
00281
00282 myRV = dynamic_cast<VeloRClusterOnTrack*>(*itM);
00283 VeloCluster* veloClu = myRV -> cluster();
00284 debug() << " -> VeloChannelID of type "
00285 << veloClu->channelID(0).type() << endreq;
00286 myID = LHCbID( veloClu -> channelID( 0 ) );
00287 myIDs.push_back( myID );
00288 debug() << " * R Velo Cluster at z = " << myRV -> z()
00289 << " , channelID = "
00290 << veloClu -> channelID(0).channelID() << endreq
00291 << " -> stored as LHCbID = " << myID.lhcbID()
00292 << " (detectorType / spareBits = "
00293 << myID.detectorType() << " / "
00294 << myID.spareBits() << ")" << endreq;
00295 }
00296 else if ( TrMeasurement::kVeloPhiClusterOnTrack == (*itM)->measType() ) {
00297
00298
00299
00300
00301
00302
00303 myPV = dynamic_cast<VeloPhiClusterOnTrack*>(*itM);
00304 VeloCluster* veloClu = myPV -> cluster();
00305 myID = LHCbID( veloClu -> channelID(0) );
00306 debug() << " -> VeloChannelID of type "
00307 << veloClu->channelID(0).type() << endreq;
00308 myIDs.push_back( myID );
00309 debug() << " * Phi Velo Cluster at z = " << myPV -> z()
00310 << " , channelID = "
00311 << veloClu -> channelID(0).channelID() << endreq
00312 << " -> stored as LHCbID = " << myID.lhcbID()
00313 << " (detectorType / spareBits = "
00314 << myID.detectorType() << " / "
00315 << myID.spareBits() << ")" << endreq;
00316 }
00317 }
00318
00319 trSto -> setLhcbIDs( myIDs );
00320 debug() << " -> # LHCbIDs stored = " << myIDs.size() << endreq;
00321 }
00322
00323 debug() << "-> stored " << outTra -> size() << " Tracks " << endreq;
00324
00325 return StatusCode::SUCCESS;
00326 };
00327
00328
00329
00330
00331 StatusCode TrFitTrack2TrackCnv::finalize() {
00332
00333 debug() << "==> Finalize" << endreq;
00334
00335
00336
00337 return GaudiAlgorithm::finalize();
00338 }
00339
00340