CMS 3D CMS Logo

HICTrajectoryBuilder.cc

Go to the documentation of this file.
00001 #include "RecoHIMuon/HiMuTracking/interface/HICTrajectoryBuilder.h"
00002 #include "RecoHIMuon/HiMuTracking/interface/HICTrajectoryCorrector.h"
00003 
00004 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00005 
00006 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00007 
00008 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00009 #include "TrackingTools/PatternTools/interface/TrajectoryStateUpdator.h"
00010 #include "TrackingTools/PatternTools/interface/MeasurementEstimator.h"
00011 
00012 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00013 #include "TrackingTools/PatternTools/interface/TrajMeasLessEstim.h"
00014 #include "TrackingTools/TrajectoryState/interface/BasicSingleTrajectoryState.h"
00015 #include "TrackingTools/MeasurementDet/interface/LayerMeasurements.h"
00016 
00017 
00018 #include "RecoTracker/CkfPattern/src/RecHitIsInvalid.h"
00019 #include "RecoTracker/CkfPattern/interface/TrajCandLess.h"
00020 #include "TrackingTools/TrajectoryFiltering/interface/MinPtTrajectoryFilter.h"
00021 #include "TrackingTools/TrajectoryFiltering/interface/MaxHitsTrajectoryFilter.h"
00022 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00023 
00024 #include "RecoTracker/CkfPattern/interface/IntermediateTrajectoryCleaner.h"
00025 #include "RecoHIMuon/HiMuSeed/interface/HICConst.h"
00026 #include "RecoHIMuon/HiMuSeed/interface/DiMuonTrajectorySeed.h"
00027 #include "RecoHIMuon/HiMuTracking/interface/HICMuonUpdator.h"
00028 #include "RecoHIMuon/HiMuPropagator/interface/HICMuonPropagator.h"
00029 
00030 
00031 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00032 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00033 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
00034 #include "DataFormats/TrackReco/interface/TrackBase.h"
00035 #include "TrackingTools/PatternTools/interface/TrajectorySmoother.h"
00036 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
00037 #include "TrackingTools/PatternTools/interface/TrajectoryStateClosestToBeamLineBuilder.h"
00038 
00039 using namespace std;
00040 using namespace cms;
00041 //#define DEBUG
00042 
00043 HICTrajectoryBuilder::
00044   HICTrajectoryBuilder(const edm::ParameterSet&              conf, 
00045                        const edm::EventSetup&                es1,
00046                        const TrajectoryStateUpdator*         updator,
00047                        const Propagator*                     propagatorAlong,
00048                        const Propagator*                     propagatorOpposite,
00049                        const Chi2MeasurementEstimatorBase*   estimator,
00050                        const TransientTrackingRecHitBuilder* RecHitBuilder,
00051                        const MeasurementTracker*             measurementTracker,
00052                        const TrajectoryFilter*               filter):
00053 
00054     theUpdator(updator),thePropagatorAlong(propagatorAlong),
00055     thePropagatorOpposite(propagatorOpposite),theEstimator(estimator),
00056     theTTRHBuilder(RecHitBuilder),theMeasurementTracker(measurementTracker),
00057     theLayerMeasurements(new LayerMeasurements(theMeasurementTracker)),
00058     theForwardPropagator(0), theBackwardPropagator(0),
00059     BaseCkfTrajectoryBuilder(conf,
00060                              updator, propagatorAlong,propagatorOpposite,
00061                              estimator, RecHitBuilder, measurementTracker,filter)
00062 {
00063   theMaxCand              = 1;
00064   theMaxLostHit           = 0;
00065   theMaxConsecLostHit     = 0;
00066   theLostHitPenalty       = 0.;
00067   theIntermediateCleaning = false;
00068   theMinimumNumberOfHits  = 5;
00069   theAlwaysUseInvalidHits = false;
00070   es1.get<GlobalTrackingGeometryRecord>().get(globTkGeomHandle);
00071   es1.get<TrackingComponentsRecord>().get("KFFitterForRefitInsideOut",theFitterTrack);
00072   es1.get<TrackingComponentsRecord>().get("KFSmootherForRefitInsideOut",theSmootherTrack);
00073   es1.get<TrackingComponentsRecord>().get("SmartPropagatorAny",thePropagatorTrack);
00074   
00075 #ifdef DEBUG  
00076   cout<<" HICTrajectoryBuilder::contructor "<<endl;
00077 #endif 
00078 }
00079 
00080 HICTrajectoryBuilder::~HICTrajectoryBuilder()
00081 {
00082   delete theLayerMeasurements;
00083   delete theMinPtCondition;
00084   delete theMaxHitsCondition;
00085 }
00086 
00087 void HICTrajectoryBuilder::setEvent(const edm::Event& event) const
00088 {
00089   theMeasurementTracker->update(event);
00090 }
00091 
00092 HICTrajectoryBuilder::TrajectoryContainer 
00093 HICTrajectoryBuilder::trajectories(const TrajectorySeed& seed) const
00094 { 
00095    theHICConst = dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->getHICConst(); 
00096 #ifdef DEBUG
00097    cout<<" HICTrajectoryBuilder::trajectories start with seed"<<endl;
00098 #endif   
00099   TrajectoryContainer result;
00100 
00101   TempTrajectory startingTraj = createStartingTrajectory( seed );
00102 #ifdef DEBUG  
00103   cout<<" HICTrajectoryBuilder::trajectories starting trajectories created "<<endl;
00104 #endif  
00105   if(startingTraj.empty()) {
00106 #ifdef DEBUG
00107         cout<<" Problem with starting trajectory "<<endl; 
00108 #endif
00109   return result;
00110   }
00111 
00114 
00115   limitedCandidates( startingTraj, result);
00116 #ifdef DEBUG  
00117    cout<<" HICTrajectoryBuilder::trajectories candidates found "<<result.size()<<endl;
00118 #endif
00119 
00120   return result;
00121 }
00122 
00123 TempTrajectory HICTrajectoryBuilder::
00124 createStartingTrajectory( const TrajectorySeed& seed) const
00125 {
00126 #ifdef DEBUG
00127   cout<<" HICTrajectoryBuilder::createStartingTrajectory "<<seed.direction()<<endl;
00128 #endif  
00129   TempTrajectory result( seed, oppositeToMomentum );
00130   theForwardPropagator = &(*thePropagatorOpposite);
00131   theBackwardPropagator = &(*thePropagatorAlong);
00132 
00133   std::vector<TM> seedMeas = seedMeasurements(seed);
00134 
00135 #ifdef DEBUG  
00136   std::cout<<" Size of seed "<<seedMeas.size()<<endl;
00137 #endif  
00138   if ( !seedMeas.empty()) {
00139 #ifdef DEBUG
00140   std::cout<<" TempTrajectory "<<std::endl;
00141 #endif
00142     for (std::vector<TM>::const_iterator i=seedMeas.begin(); i!=seedMeas.end(); i++){
00143     
00144        result.push(*i); 
00145       
00146                  
00147     }
00148   }
00149    
00150   return result;
00151   
00152 }
00153 
00154 void HICTrajectoryBuilder::
00155 limitedCandidates( TempTrajectory& startingTraj, 
00156                    TrajectoryContainer& result) const
00157 {
00158   TempTrajectoryContainer candidates; // = TrajectoryContainer();
00159   TempTrajectoryContainer newCand; // = TrajectoryContainer();
00160   candidates.push_back( startingTraj);
00161 // Add the additional stuff
00162 #ifdef DEBUG
00163   cout<<" HICTrajectoryBuilder::limitedCandidates "<<candidates.size()<<endl;
00164 #endif   
00165 
00166   int theIniSign = 1;
00167   dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->setSign(theIniSign);
00168 #ifdef DEBUG
00169   cout<<" Number of measurements "<<startingTraj.measurements().size()<<endl;
00170 #endif
00171 //
00172 // Calculate the number of final trajectories. Allow no more then 4.
00173 //
00174    
00175   int numtraj = 0; 
00176    
00177   while ( !candidates.empty()) {
00178 #ifdef DEBUG
00179   cout<<" HICTrajectoryBuilder::limitedCandidates::cycle "<<candidates.size()<<endl;
00180 #endif
00181     newCand.clear();
00182 
00183     for (TempTrajectoryContainer::iterator traj=candidates.begin();
00184          traj!=candidates.end(); traj++) {
00185 #ifdef DEBUG     
00186          cout<< " Before findCompatibleMeasurements "<<endl;
00187 #endif
00188       std::vector<TM> meas = findCompatibleMeasurements(*traj);
00189 #ifdef DEBUG
00190          cout<< " After findCompatibleMeasurements "<<meas.size()<<endl;
00191 #endif
00192 
00193       if ( meas.empty()) {
00194 #ifdef DEBUG
00195         cout<<": Measurements empty : "<<endl;
00196 #endif
00197         if ( qualityFilter( *traj)) {addToResult( *traj, result); numtraj++;}
00198       }
00199       else {
00200 #ifdef DEBUG
00201         cout<<" : Update trajectoris :   "<<endl;
00202 #endif
00203         for( std::vector<TM>::const_iterator itm = meas.begin(); 
00204                                              itm != meas.end(); itm++) {
00205           TempTrajectory newTraj = *traj;
00206           bool good = updateTrajectory( newTraj, *itm);
00207           if(good)
00208           {
00209             if ( toBeContinued(newTraj)) {
00210                         newCand.push_back(newTraj);
00211 #ifdef DEBUG
00212                cout<<": toBeContinued : increase "<<newCand.size()<<" maximal size "<<theMaxCand<<endl;
00213 #endif
00214              }
00215              else {
00216 #ifdef DEBUG
00217                cout<<": good TM : to be stored :"<<endl;
00218 #endif
00219                if ( qualityFilter(newTraj)) {addToResult( newTraj, result); numtraj++;}
00221                   }
00222           } // good
00223             else
00224             {
00225 #ifdef DEBUG
00226                   cout<<": bad TM : to be stored :"<<endl;
00227 #endif
00228                if ( qualityFilter( *traj)) {addToResult( *traj, result);numtraj++;}
00229             }
00230          } //meas 
00231       }
00232     
00233 //      if ((int)newCand.size() > theMaxCand) {
00234 //      sort( newCand.begin(), newCand.end(), TrajCandLess<TempTrajectory>(theLostHitPenalty));
00235 //      newCand.erase( newCand.begin()+theMaxCand, newCand.end());
00236 //      }
00237 
00238         if(numtraj > 4) break;
00239     } // trajectories
00240         if(numtraj > 4) break;
00241         candidates.swap(newCand);
00242   }
00243 
00244 #ifdef DEBUG 
00245   std::cout<<" qualityFilter::Number of trajectories "<<numtraj<<std::endl;
00246 #endif
00247   
00248 }
00249 
00250 
00251 
00252 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
00253 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00254 #include "RecoHIMuon/HiMuSeed/interface/DiMuonTrajectorySeed.h"
00255 
00256 std::vector<TrajectoryMeasurement> 
00257 HICTrajectoryBuilder::seedMeasurements(const TrajectorySeed& seed) const
00258 {
00259   std::vector<TrajectoryMeasurement> result;
00260   TrajectoryStateTransform tsTransform;
00261 
00262 #ifdef DEBUG 
00263   cout<<" HICTrajectoryBuilder::seedMeasurements number of TM "<<dynamic_cast<DiMuonTrajectorySeed*>(const_cast<TrajectorySeed*>(&seed))->measurements().size()<<endl;
00264 #endif  
00265 
00266    std::vector<TrajectoryMeasurement> start = dynamic_cast<DiMuonTrajectorySeed*>(const_cast<TrajectorySeed*>(&seed))->measurements();
00267    for(std::vector<TrajectoryMeasurement>::iterator imh = start.begin(); imh != start.end(); imh++)
00268    { 
00269 #ifdef DEBUG       
00270      cout<<" HICTrajectoryBuilder::seedMeasurements::RecHit "<<endl;
00271 #endif       
00272      result.push_back(*imh);
00273    }
00274 
00275   return result;
00276 }
00277 
00278  bool HICTrajectoryBuilder::qualityFilter( const TempTrajectory& traj) const
00279 {
00280 #ifdef DEBUG
00281     cout << "qualityFilter called for trajectory with " 
00282          << traj.foundHits() << " found hits and Chi2 = "
00283          << traj.chiSquared() << endl;
00284 #endif
00285   if ( traj.foundHits() < theMinimumNumberOfHits) {
00286     return false;
00287   }
00288 
00289   Trajectory traj0 = traj.toTrajectory();
00290 // Check the number of pixels
00291   const Trajectory::DataContainer tms = traj0.measurements();
00292   int ipix = 0; 
00293   for( Trajectory::DataContainer::const_iterator itm = tms.begin(); itm != tms.end(); itm++) {
00294      if((*itm).layer()->subDetector() == GeomDetEnumerators::PixelEndcap || (*itm).layer()->subDetector() == GeomDetEnumerators::PixelBarrel) ipix++;
00295   }
00296   
00297 #ifdef DEBUG
00298  cout<<" Number of pixels "<<ipix<<endl;
00299 #endif
00300 
00301  if(ipix < 1) return false;
00302  
00303 //
00304 // Refit the trajectory
00305 //
00306 
00307     reco::BeamSpot::CovarianceMatrix matrix;
00308     matrix(2,2) = 0.001;
00309     matrix(3,3) = 0.001;
00310 
00311     reco::BeamSpot bs( reco::BeamSpot::Point(0., 0., theHICConst->zvert),
00312                                                      0.1,
00313                                                      0.,
00314                                                      0.,
00315                                                      0.,
00316                                                     matrix
00317                      );
00318     
00319     enum RefitDirection{insideOut,outsideIn,undetermined};
00320     
00321     Trajectory::ConstRecHitContainer recHitsForReFit = traj0.recHits();
00322     
00323     PTrajectoryStateOnDet garbage1;
00324     edm::OwnVector<TrackingRecHit> garbage2;
00325     TrajectoryStateOnSurface firstTSOS = traj0.firstMeasurement().updatedState(); 
00326 
00327     PropagationDirection propDir = oppositeToMomentum;
00328 
00329     TrajectorySeed seed(garbage1,garbage2,propDir);
00330     vector<Trajectory> trajectories = theFitterTrack->fit(seed,recHitsForReFit,firstTSOS);
00331 
00332     TrajectoryStateOnSurface innertsos;
00333 
00334     if (traj0.direction() == alongMomentum) {
00335    //    cout<<" Direction is along momentum "<<endl;
00336       innertsos = traj0.firstMeasurement().updatedState();
00337     } else {
00338       innertsos = traj0.lastMeasurement().updatedState();
00339    //   cout<<" Direction is opposite to momentum "<<endl;
00340       
00341     }
00342 
00343     TrajectoryStateClosestToBeamLineBuilder tscblBuilder;
00344     TrajectoryStateClosestToBeamLine tscbl = tscblBuilder(*(innertsos.freeState()),bs);
00345 
00346     if (tscbl.isValid()==false) {
00347     //cout<<" false track "<<endl; 
00348      return false;
00349     }
00350     
00351     GlobalPoint v = tscbl.trackStateAtPCA().position();
00352     math::XYZPoint  pos( v.x(), v.y(), v.z() );
00353     
00354     if(v.perp() > 0.1 ) return false;
00355     if(fabs(v.z() - theHICConst->zvert ) > 0.4 ) return false;
00356 
00357  return true;
00358  
00359 }
00360 
00361 
00362 void HICTrajectoryBuilder::addToResult( TempTrajectory& tmptraj, 
00363                                         TrajectoryContainer& result) const
00364 {
00365   Trajectory traj = tmptraj.toTrajectory();
00366   result.push_back( traj);
00367 }
00368 
00369 bool HICTrajectoryBuilder::updateTrajectory( TempTrajectory& traj,
00370                                              const TM& tm) const
00371 {
00372   bool good=false; 
00373 #ifdef DEBUG
00374   std::cout<<"HICTrajectoryBuilder::updateTrajectory::start"<<std::endl;
00375 #endif
00376   TSOS predictedState = tm.predictedState();
00377   TM::ConstRecHitPointer hit = tm.recHit();
00378   Trajectory traj0 = traj.toTrajectory();
00379 // My update
00380    vector<double> theCut = dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->setCuts(traj0,tm.layer());
00381    int icut = 3;
00382    dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->chooseCuts(icut);
00383    const MagneticField * mf = dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->getField();
00384    HICMuonUpdator hicup(theCut[2],theCut[3], mf,theHICConst);
00385    double chi2rz,chi2rf;
00386  
00387   if ( hit->isValid()) {
00388 
00389 // Update trajectory
00390 //
00391   TrajectoryStateOnSurface newUpdateState=hicup.update(traj0, predictedState, tm, tm.layer(), chi2rz, chi2rf);
00392   bool accept=
00393               (dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->estimate(newUpdateState,*hit)).first;
00394   if(accept)
00395   {
00396 #ifdef DEBUG
00397   std::cout<<" updateTrajectory::UpdateState::New momentum "<<newUpdateState.freeTrajectoryState()->momentum().perp()<<" "<<newUpdateState.freeTrajectoryState()->momentum().z()<<std::endl;
00398 #endif
00399   TM tmp = TM(predictedState, newUpdateState, hit, tm.estimate(), tm.layer());
00400 
00401   traj.push(tmp );
00402   good=true;
00403   return good;
00404   }
00405     else
00406     {
00407 #ifdef DEBUG
00408        std::cout<<" updateTrajectory::failed after update "<<accept<<std::endl;
00409 #endif
00410        return good;
00411     }
00412   }
00413   else {
00414     return good;
00415   }
00416 }
00417 
00418 bool HICTrajectoryBuilder::toBeContinued (const TempTrajectory& traj) const
00419 {
00420   if ( traj.lostHits() > theMaxLostHit) return false;
00421 
00422   // check for conscutive lost hits only at the end 
00423   // (before the last valid hit),
00424   // since if there was an unacceptable gap before the last 
00425   // valid hit the trajectory would have been stopped already
00426 
00427   int consecLostHit = 0;
00428 
00429   const TempTrajectory::DataContainer & tms = traj.measurements();
00430   //for( TempTrajectory::DataContainer::const_iterator itm=tms.end()-1; itm>=tms.begin(); itm--) {
00431   for( TempTrajectory::DataContainer::const_iterator itm=tms.rbegin(), itb = tms.rend(); itm != itb; --itm) {
00432     if (itm->recHit()->isValid()) break;
00433     else if ( // FIXME: restore this:   !Trajectory::inactive(itm->recHit()->det()) &&
00434              Trajectory::lost(*itm->recHit())) consecLostHit++;
00435   }
00436   if (consecLostHit > theMaxConsecLostHit) return false; 
00437 
00438   // stopping condition from region has highest priority
00439   // if ( regionalCondition && !(*regionalCondition)(traj) )  return false;
00440   // next: pt-cut
00441   //if ( !(*theMinPtCondition)(traj) )  return false;
00442   //if ( !(*theMaxHitsCondition)(traj) )  return false;
00443   // finally: configurable condition
00444   // FIXME: restore this:  if ( !(*theConfigurableCondition)(traj) )  return false;
00445 
00446   return true;
00447 }
00448 
00449 std::vector<TrajectoryMeasurement> 
00450 HICTrajectoryBuilder::findCompatibleMeasurements( const TempTrajectory& traj) const
00451 {
00452   //cout<<" HICTrajectoryBuilder::FindCompatibleMeasurement start "<<traj.empty()<<endl; 
00453   vector<TM> result;
00454   int invalidHits = 0;
00455   int theLowMult = 1; 
00456 
00457   TSOS currentState( traj.lastMeasurement().updatedState());
00458 
00459   vector<const DetLayer*> nl = 
00460                                traj.lastLayer()->nextLayers( *currentState.freeState(), traj.direction());
00461 #ifdef DEBUG
00462   std::cout<<" Number of layers "<<nl.size()<<std::endl;
00463 #endif
00464   
00465   if (nl.empty()) return result;
00466 
00467   int seedLayerCode = dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->
00468                                                               getDetectorCode(traj.measurements().front().layer());
00469 #ifdef DEBUG
00470   std::cout<<"findCompatibleMeasurements Point 0 "<<seedLayerCode<<std::endl;
00471 #endif
00472                                                               
00473   int currentLayerCode = dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->
00474                                                                getDetectorCode(traj.lastLayer()); 
00475 #ifdef DEBUG
00476   std::cout<<"findCompatibleMeasurements Point 1 "<<currentLayerCode<<std::endl;
00477 #endif
00478   for (vector<const DetLayer*>::iterator il = nl.begin(); 
00479                                          il != nl.end(); il++) {
00480 
00481    int nextLayerCode = dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->
00482                                                                getDetectorCode((*il)); 
00483 #ifdef DEBUG
00484   std::cout<<"findCompatibleMeasurements Point 2 "<<nextLayerCode<<std::endl;
00485 #endif
00486 
00487    if( traj.lastLayer()->location() == GeomDetEnumerators::endcap && (**il).location() == GeomDetEnumerators::barrel )
00488    {
00489    if( abs(seedLayerCode) > 100 && abs(seedLayerCode) < 108 )
00490    {
00491       if( (**il).subDetector() == GeomDetEnumerators::PixelEndcap ) continue;
00492    } // 100-108
00493    else
00494    {
00495     if(theLowMult == 0 )
00496     {      
00497       if( nextLayerCode == 0 ) continue;
00498     }         
00499       if( (**il).subDetector() == GeomDetEnumerators::TID || (**il).subDetector() == GeomDetEnumerators::TEC) continue;
00500    } // 100-108
00501    } // barrel and endcap
00502    
00503    if( currentLayerCode == 101 && nextLayerCode < 100 ) {
00504      continue; 
00505    }  // currentLayer-nextLayer
00506 #ifdef DEBUG   
00507   std::cout<<" findCompatibleMeasurements Point 3 "<<nextLayerCode<<std::endl;
00508 #endif   
00509                                                                        
00510   Trajectory traj0 = traj.toTrajectory();
00511   
00512   vector<double> theCut = dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->setCuts(traj0,(*il));
00513   
00514   // Choose Win
00515   int icut = 1;
00516   dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->chooseCuts(icut);
00517 #ifdef DEBUG
00518   std::cout<<" findCompatibleMeasurements::current state : "<<
00519              " charge "<< currentState.freeTrajectoryState()->parameters().charge()<<
00520              " pt "<<currentState.freeTrajectoryState()->parameters().momentum().perp()<<
00521              " pz "<<currentState.freeTrajectoryState()->parameters().momentum().z()<<
00522              " r  "<<currentState.freeTrajectoryState()->parameters().position().perp()<<
00523              " phi  "<<currentState.freeTrajectoryState()->parameters().position().phi()<<
00524              " z  "<<currentState.freeTrajectoryState()->parameters().position().z()<<
00525              endl; 
00526 #endif
00527   const MagneticField * mf = dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->getField();
00528   vector<TM> tmp0;
00529 //  if(currentLayerCode > 100&&traj0.measurements().size()>1) {
00530 //           HICMuonPropagator hmp(mf);
00531 //#ifdef DEBUG
00532 //  std::cout<<" findCompatibleMeasurements::HICMuonPropagator::for forward "<<std::endl;
00533 //#endif           
00534 //               tmp0 = 
00535 //                      theLayerMeasurements->measurements((**il), currentState, hmp, *theEstimator); 
00536 //  }
00537 //  else
00538 //  {
00539                tmp0 = 
00540                       theLayerMeasurements->measurements((**il), currentState, *theForwardPropagator, *theEstimator); 
00541 //  }                 
00542                       
00543 #ifdef DEBUG 
00544   std::cout<<" findCompatibleMeasurements Point 6 "<<theCut[0]<<" "<<theCut[1]<<std::endl;
00545   std::cout<<" findCompatibleMeasurements Point 7 "<<traj0.measurements().size()<<std::endl;
00546 #endif
00547 //   
00548 // ========================= Choose Cut and filter =================================
00549 //
00550      vector<TM> tmp;
00551      icut = 2;
00552      dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->chooseCuts(icut);
00553 #ifdef DEBUG
00554      std::cout<<" findCompatibleMeasurements Point 8 "<<theCut[0]<<" "<<theCut[1]<<" Size of candidates "<<tmp0.size()<<std::endl;
00555 #endif  
00556     int numtmp = 0; 
00557      for( vector<TM>::iterator itm = tmp0.begin(); itm != tmp0.end(); itm++ )
00558      {
00559         TM tm = (*itm);
00560         TSOS predictedState = tm.predictedState();
00561         TM::ConstRecHitPointer  hit = tm.recHit();
00562         TSOS updateState = traj0.lastMeasurement().updatedState();
00563 #ifdef DEBUG
00564         std::cout<<" findCompatibleMeasurements::Size of trajectory "<<traj0.measurements().size()<<" Number of TM "<< numtmp<<
00565                    " valid updated state "<< updateState.isValid()<<" Predicted state is valid "<<predictedState.isValid()<<
00566                    " charge "<< predictedState.freeTrajectoryState()->parameters().charge()<<
00567                    " pt "<<predictedState.freeTrajectoryState()->parameters().momentum().perp()<<
00568                    " pz "<<predictedState.freeTrajectoryState()->parameters().momentum().z()<<
00569                    " r  "<<predictedState.freeTrajectoryState()->parameters().position().perp()<<
00570                    " phi  "<<predictedState.freeTrajectoryState()->parameters().position().phi()<<
00571                    " z  "<<predictedState.freeTrajectoryState()->parameters().position().z()<<
00572          std::endl;
00573 #endif
00574 
00575   if( traj0.measurements().size() == 1 )
00576   {
00577 #ifdef DEBUG
00578        std::cout<<" findCompatibleMeasurements::start corrector "<<std::endl;
00579 #endif
00580         HICTrajectoryCorrector theCorrector(mf,theHICConst);
00581 #ifdef DEBUG    
00582         std::cout<<" findCompatibleMeasurements::corrector::initialized "<<std::endl;
00583 #endif  
00584         TSOS predictedState0 = theCorrector.correct( (*traj0.lastMeasurement().updatedState().freeTrajectoryState()), 
00585                                                       (*(predictedState.freeTrajectoryState())), 
00586                                                       hit->det() );
00587 #ifdef DEBUG                                                  
00588      std::cout<<" findCompatibleMeasurements::end corrector "<<std::endl; 
00589 #endif
00590       if(predictedState0.isValid()) 
00591       {
00592 #ifdef DEBUG
00593               std::cout<<" Accept the corrected state "<<numtmp<<std::endl; 
00594 #endif
00595               predictedState = predictedState0;
00596               
00597         if((*hit).isValid())
00598         {
00599   
00600               bool accept= true;
00601               accept = (dynamic_cast<HICMeasurementEstimator*>(const_cast<Chi2MeasurementEstimatorBase*>(theEstimator))->estimate(predictedState,*hit)).first; 
00602               
00603               if(!accept) {
00604 #ifdef DEBUG
00605                   std::cout<<" findCompatibleMeasurements::failed after the first step "<<numtmp<<std::endl;
00606 #endif
00607                   numtmp++;
00608                   continue;
00609               } // accept
00610 #ifdef DEBUG
00611              std::cout<<" findCompatibleMeasurements::estimate at the first step is ok "<<numtmp<<std::endl;
00612 #endif
00613 // Add trajectory measurements
00614              tmp.push_back(TM(predictedState, updateState, hit, tm.estimate(), tm.layer())); 
00615 #ifdef DEBUG
00616              std::cout<<" findCompatibleMeasurements::fill estimate "<<numtmp<<std::endl;
00617 #endif
00618         } // Hit Valid
00619         
00620        } // predicted state is valid
00621    } // first step
00622       else
00623       { 
00624 //          tmp.push_back(TM(predictedState, updateState, hit, tm.estimate(), tm.layer()));
00625 #ifdef DEBUG
00626             std::cout<<" findCompatibleMeasurements::Add TM to collection::Predicted state is valid "<<predictedState.isValid()<<" Hit is valid "<<(*hit).isValid()<<std::endl;
00627 #endif      
00628             if( predictedState.isValid() && (*hit).isValid() ) tmp.push_back(*itm);
00629       } 
00630           numtmp++;
00631 
00632   }             // tm                      
00633 #ifdef DEBUG
00634         std::cout<<" findCompatibleMeasurements::point 9 "<<std::endl;
00635 #endif
00636     if ( !tmp.empty()) {
00637       if ( result.empty() ) result = tmp;
00638       else {
00639         // keep one dummy TM at the end, skip the others
00640         result.insert( result.end(), tmp.begin(), tmp.end());
00641       }
00642     }
00643    //  std::cout<<" Results size "<<result.size()<<std::endl;
00644   } // next layers
00645 
00646   // sort the final result, keep dummy measurements at the end
00647   if ( result.size() > 1) {
00648     sort( result.begin(), result.end(), TrajMeasLessEstim());
00649   }
00650 #ifdef DEBUG
00651        std::cout<<" findCompatibleMeasurements::point 10 "<<std::endl;
00652 #endif
00653   return result;
00654 }
00655 

Generated on Tue Jun 9 17:43:38 2009 for CMSSW by  doxygen 1.5.4