CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/TrackingTools/PatternTools/src/TempTrajectory.cc

Go to the documentation of this file.
00001 #include "TrackingTools/PatternTools/interface/TempTrajectory.h"
00002 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 
00005 
00006 TempTrajectory::TempTrajectory( const Trajectory& traj):
00007   theChiSquared(0),
00008   theNumberOfFoundHits(0), theNumberOfLostHits(0),
00009   theDirection(traj.direction()), theDirectionValidity(true),
00010   theValid(traj.isValid()),
00011   theNLoops(traj.nLoops()),
00012   theDPhiCache(traj.dPhiCacheForLoopersReconstruction()) {
00013   
00014   Trajectory::DataContainer::const_iterator begin=traj.measurements().begin();
00015   Trajectory::DataContainer::const_iterator end=traj.measurements().end();
00016   
00017   for(Trajectory::DataContainer::const_iterator it=begin; it!=end; ++it){
00018     push(*it);
00019   }
00020 
00021 }
00022 
00023 
00024 void TempTrajectory::pop() { 
00025   if (!empty()) {
00026     if (theData.back().recHit()->isValid())             theNumberOfFoundHits--;
00027     else if(lost(* (theData.back().recHit()) )) theNumberOfLostHits--;
00028     theData.pop_back();
00029   }
00030 }
00031 
00032 
00033 
00034 void TempTrajectory::pushAux(double chi2Increment) {
00035   const TrajectoryMeasurement& tm = theData.back();
00036   if ( tm.recHit()->isValid()) {
00037     theNumberOfFoundHits++;
00038    }
00039   //else if (lost( tm.recHit()) && !inactive(tm.recHit().det())) theNumberOfLostHits++;
00040   else if (lost( *(tm.recHit()) ) )   theNumberOfLostHits++;
00041   
00042   
00043   theChiSquared += chi2Increment;
00044 
00045   // in case of a Trajectory constructed without direction, 
00046   // determine direction from the radii of the first two measurements
00047 
00048   if ( !theDirectionValidity && theData.size() >= 2) {
00049     if (theData.front().updatedState().globalPosition().perp2() <
00050         theData.back().updatedState().globalPosition().perp2())
00051       theDirection = alongMomentum;
00052     else theDirection = oppositeToMomentum;
00053     theDirectionValidity = true;
00054   }
00055 }
00056 
00057 void TempTrajectory::push(const TempTrajectory& segment) {
00058   assert (segment.theDirection == theDirection) ;
00059   assert(theDirectionValidity); // given the above...
00060 
00061   const int N = segment.measurements().size();
00062   TrajectoryMeasurement const * tmp[N];
00063   int i=0;
00064   //for (DataContainer::const_iterator it = segment.measurements().rbegin(), ed = segment.measurements().rend(); it != ed; --it)
00065   for ( auto const & tm : segment.measurements())
00066     tmp[i++] =&tm;
00067   while(i!=0) theData.push_back(*tmp[--i]);
00068   theNumberOfFoundHits+= segment.theNumberOfFoundHits;
00069   theNumberOfLostHits += segment.theNumberOfLostHits;
00070   theChiSquared += segment.theChiSquared;
00071 }
00072 
00073 void TempTrajectory::join( TempTrajectory& segment) {
00074   assert (segment.theDirection == theDirection) ;
00075   assert(theDirectionValidity);
00076 
00077   if (segment.theData.shared()) {
00078     push(segment); 
00079     segment.theData.clear(); // obey the contract, and increase the chances it will be not shared one day
00080   } else {
00081     theData.join(segment.theData);
00082     theNumberOfFoundHits+= segment.theNumberOfFoundHits;
00083     theNumberOfLostHits += segment.theNumberOfLostHits;
00084     theChiSquared += segment.theChiSquared;
00085   }
00086 }
00087 
00088 
00089 /*
00090 Trajectory::RecHitContainer Trajectory::recHits() const {
00091   RecHitContainer hits;
00092   hits.reserve(theData.size());
00093 
00094   for (Trajectory::DataContainer::const_iterator itm
00095          = theData.begin(); itm != theData.end(); itm++) {
00096     hits.push_back((*itm).recHit());
00097   }
00098   return hits;
00099 }
00100 
00101 */
00102 
00103 PropagationDirection TempTrajectory::direction() const {
00104   if (theDirectionValidity) return PropagationDirection(theDirection);
00105   else throw cms::Exception("TrackingTools/PatternTools","Trajectory::direction() requested but not set");
00106 }
00107 
00108 void TempTrajectory::check() const {
00109   if ( theData.size() == 0) 
00110     throw cms::Exception("TrackingTools/PatternTools","Trajectory::check() - information requested from empty Trajectory");
00111 }
00112 
00113 bool TempTrajectory::lost( const TransientTrackingRecHit& hit)
00114 {
00115   if  likely(hit.isValid()) return false;
00116 
00117   //     // A DetLayer is always inactive in this logic.
00118   //     // The DetLayer is the Det of an invalid RecHit only if no DetUnit 
00119   //     // is compatible with the predicted state, so we don't really expect
00120   //     // a hit in this case.
00121   
00122   if(hit.geographicalId().rawId() == 0) {return false;}
00123   return hit.getType() == TrackingRecHit::missing;
00124 }
00125 
00126 Trajectory TempTrajectory::toTrajectory() const {
00127   assert(theDirectionValidity);
00128   PropagationDirection p=PropagationDirection(theDirection);
00129   Trajectory traj(p);
00130   traj.setNLoops(theNLoops);
00131 
00132   traj.reserve(theData.size());
00133   const TrajectoryMeasurement* tmp[theData.size()];
00134   int i=0;
00135   for (DataContainer::const_iterator it = theData.rbegin(), ed = theData.rend(); it != ed; --it)
00136     tmp[i++] = &(*it);
00137   while(i!=0) traj.push(*tmp[--i]);
00138   return traj;
00139 }
00140