CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEgamma/EgammaPhotonAlgos/src/InOutConversionTrackFinder.cc

Go to the documentation of this file.
00001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00002 //
00003 #include "RecoEgamma/EgammaPhotonAlgos/interface/InOutConversionTrackFinder.h"
00004 
00005 //
00006 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00007 #include "RecoTracker/CkfPattern/interface/SeedCleanerByHitPosition.h"
00008 #include "RecoTracker/CkfPattern/interface/CachingSeedCleanerByHitPosition.h"
00009 #include "RecoTracker/CkfPattern/interface/CachingSeedCleanerBySharedInput.h"
00010 #include "RecoTracker/CkfPattern/interface/TransientInitialStateEstimator.h"
00011 //
00012 #include "TrackingTools/PatternTools/interface/TrajectoryBuilder.h"
00013 #include "TrackingTools/KalmanUpdators/interface/KFUpdator.h"
00014 #include "TrackingTools/TrajectoryCleaning/interface/TrajectoryCleanerBySharedHits.h"
00015 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00016 //
00017 #include "DataFormats/Common/interface/OwnVector.h"
00018 //
00019 #include "Utilities/General/interface/precomputed_value_sort.h"
00020 
00021 #include <sstream>
00022 
00023 
00024 InOutConversionTrackFinder::InOutConversionTrackFinder(const edm::EventSetup& es, 
00025                                                        const edm::ParameterSet& conf ) : ConversionTrackFinder (es,  conf ) 
00026 { 
00027 
00028  
00029   theTrajectoryCleaner_ = new TrajectoryCleanerBySharedHits(conf);
00030 
00031  // get the seed cleaner
00032  std::string cleaner = conf_.getParameter<std::string>("InOutRedundantSeedCleaner");
00033  if (cleaner == "SeedCleanerByHitPosition") {
00034    theSeedCleaner_ = new SeedCleanerByHitPosition();
00035  } else if (cleaner == "CachingSeedCleanerByHitPosition") {
00036    theSeedCleaner_ = new CachingSeedCleanerByHitPosition();
00037  } else if (cleaner == "CachingSeedCleanerBySharedInput") {
00038    theSeedCleaner_ = new CachingSeedCleanerBySharedInput();
00039  } else if (cleaner == "none") {
00040    theSeedCleaner_ = 0;
00041  } else {
00042    throw cms::Exception("InOutRedundantSeedCleaner not found", cleaner);
00043  }
00044 
00045 }
00046 
00047 
00048 InOutConversionTrackFinder::~InOutConversionTrackFinder() {
00049 
00050   delete theTrajectoryCleaner_;
00051   if (theSeedCleaner_) delete theSeedCleaner_;
00052 }
00053 
00054 
00055 
00056 
00057 std::vector<Trajectory> InOutConversionTrackFinder::tracks(const TrajectorySeedCollection  inOutSeeds, 
00058                                                            TrackCandidateCollection &output_p ) const {
00059 
00060 
00061 
00062   //  std::cout << " InOutConversionTrackFinder::tracks getting " <<  inOutSeeds.size() << " In-Out seeds " << "\n"; 
00063    
00064   std::vector<Trajectory> tmpO;
00065   tmpO.erase(tmpO.begin(), tmpO.end() ) ;
00066   
00067   std::vector<Trajectory> result;
00068   result.erase(result.begin(), result.end() ) ;
00069 
00070 
00071   std::vector<Trajectory> rawResult;
00072    if (theSeedCleaner_) theSeedCleaner_->init( &rawResult );
00073 
00074 
00075 
00076   // Loop over the seeds
00077   int goodSeed=0;
00078   for(TrajectorySeedCollection::const_iterator iSeed=inOutSeeds.begin(); iSeed!=inOutSeeds.end();iSeed++){
00079     if (!theSeedCleaner_ || theSeedCleaner_->good(&(*iSeed))) {
00080     goodSeed++;
00081     
00082     LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks hits in the seed " << iSeed->nHits() << "\n";
00083     LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks seed starting state position  " << iSeed->startingState().parameters().position() << " momentum " <<  iSeed->startingState().parameters().momentum() << " charge " << iSeed->startingState().parameters().charge() << "\n";
00084     LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks seed  starting state para, vector  " << iSeed->startingState().parameters().vector() << "\n";
00085      
00086 
00087     
00088     std::vector<Trajectory> theTmpTrajectories;
00089 
00090     theTmpTrajectories = theCkfTrajectoryBuilder_->trajectories(*iSeed);
00091     
00092     LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track returned " << theTmpTrajectories.size() << " trajectories for this seed " << "\n";
00093     
00094     theTrajectoryCleaner_->clean(theTmpTrajectories);
00095     
00096     for(std::vector<Trajectory>::const_iterator it=theTmpTrajectories.begin(); it!=theTmpTrajectories.end(); it++){
00097       if( it->isValid() ) {
00098         rawResult.push_back(*it);
00099         if (theSeedCleaner_) theSeedCleaner_->add( & (*it) );   
00100       }
00101     }
00102     }
00103   }  // end loop over the seeds 
00104    
00105  
00106 
00107   LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track Good seeds " << goodSeed   << "\n"  ;
00108   LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track rawResult size after cleaning " << rawResult.size() << "\n";  
00109 
00110   if (theSeedCleaner_) theSeedCleaner_->done();
00111 
00112 
00113   std::vector<Trajectory> unsmoothedResult;
00114   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track  Start second cleaning " << "\n";
00115   theTrajectoryCleaner_->clean(rawResult);
00116   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track rawResult size after cleaning " << rawResult.size() << "\n";
00117   
00118 
00119 
00120   int tra=0;
00121   for (std::vector<Trajectory>::const_iterator itraw = rawResult.begin(); itraw != rawResult.end(); itraw++) {
00122     tra++;
00123     LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder looping of rawResult after cleaning " << tra << "\n";
00124     if((*itraw).isValid()) {
00125       // unsmoothedResult.push_back( *itraw);
00126       tmpO.push_back( *itraw );
00127       LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track rawResult num of valid recHits per trajectory " << (*itraw).foundHits() << "\n";
00128     }
00129 
00130   }
00131   
00132   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  tmpO size " << tmpO.size() << " before sorting " << "\n"; 
00133   //  for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
00134   // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  tmpO num of hits " << (*it).foundHits() << " before ordering " << "\n"; 
00135   //}
00136   
00137   precomputed_value_sort( tmpO.begin(), tmpO.end(), ExtractNumOfHits()  ); 
00138   
00139   
00140   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  tmpO after sorting " << "\n"; 
00141   //  for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
00142   // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  tmpO  num of hits " << (*it).foundHits() << "\n"; 
00143   // }
00144 
00145   for (int i=tmpO.size()-1; i>=0; i--) {
00146     unsmoothedResult.push_back(  tmpO[i] );  
00147   }
00148   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  unsmoothedResult size  " <<  unsmoothedResult.size() << "\n";   
00149 
00150   //  for (std::vector<Trajectory>::const_iterator it =  unsmoothedResult.begin(); it !=  unsmoothedResult.end(); it++) {
00151   // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  unsmoothedResult  after reordering " <<(*it).foundHits() <<  "\n"; 
00152   //  }
00153 
00154 
00155   // Convert to TrackCandidates and fill in the output_p
00156   for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
00157 
00158     // if( !it->isValid() ) continue;
00159     
00160     edm::OwnVector<TrackingRecHit> recHits;
00161     Trajectory::RecHitContainer thits;
00162     it->recHitsV(thits,useSplitHits_);
00163     recHits.reserve(thits.size());
00164     for (Trajectory::RecHitContainer::const_iterator hitIt = thits.begin(); hitIt != thits.end(); hitIt++) {
00165       recHits.push_back( (**hitIt).hit()->clone());
00166     }
00167     
00168     
00169     std::pair<TrajectoryStateOnSurface, const GeomDet*> initState =  theInitialState_->innerState( *it);
00170     
00171     // temporary protection againt invalid initial states
00172     if (! initState.first.isValid() || initState.second == 0) {
00173       //cout << "invalid innerState, will not make TrackCandidate" << endl;
00174       continue;
00175     }
00176     
00177     PTrajectoryStateOnDet* state = 0;
00178     if(useSplitHits_ && (initState.second != thits.front()->det()) && thits.front()->det() ){ 
00179       TrajectoryStateOnSurface propagated = thePropagator_->propagate(initState.first,thits.front()->det()->surface());
00180       if (!propagated.isValid()) continue;
00181       state = TrajectoryStateTransform().persistentState(propagated,
00182                                                          thits.front()->det()->geographicalId().rawId());
00183     }
00184     if(!state) state = TrajectoryStateTransform().persistentState( initState.first,
00185                                                                    initState.second->geographicalId().rawId());
00186     
00187     LogDebug("InOutConversionTrackFinder") << "  InOutConversionTrackFinder::track Making the result: seed position " << it->seed().startingState().parameters().position()  << " seed momentum " <<  it->seed().startingState().parameters().momentum() << " charge " <<  it->seed().startingState().parameters().charge () << "\n";
00188     LogDebug("InOutConversionTrackFinder") << "  InOutConversionTrackFinder::track TSOS charge  " << initState.first.charge() << "\n";
00189     
00190     LogDebug("InOutConversionTrackFinder") <<   " InOutConversionTrackFinder::track  PTrajectoryStateOnDet* state position  " << state->parameters().position() << " momentum " << state->parameters().momentum() << " charge " <<   state->parameters().charge () << "\n";
00191     
00192     result.push_back(*it);  
00193     
00194     output_p.push_back(TrackCandidate(recHits, it->seed(),*state ) );
00195     delete state;
00196   }
00197   
00198   LogDebug("InOutConversionTrackFinder") << "  InOutConversionTrackFinder::track Returning " << result.size() << " valid In Out Trajectories " << "\n";
00199   return  result;
00200 }