CMS 3D CMS Logo

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