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

TrFitTrack2TrackCnv.cpp

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

Generated on Thu Apr 7 22:43:27 2005 for New Track Event Model by doxygen 1.4.1