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 theTrajectoryCleaner_ = new TrajectoryCleanerBySharedHits();
00029
00030
00031
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
00039 theSeedCleaner_ = new CachingSeedCleanerBySharedInput();
00040 } else if (cleaner == "none") {
00041 theSeedCleaner_ = 0;
00042 } else {
00043 throw cms::Exception("InOutRedundantSeedCleaner not found", cleaner);
00044 }
00045
00046 }
00047
00048
00049 InOutConversionTrackFinder::~InOutConversionTrackFinder() {
00050
00051 delete theTrajectoryCleaner_;
00052 if (theSeedCleaner_) delete theSeedCleaner_;
00053 }
00054
00055
00056
00057
00058 std::vector<Trajectory> InOutConversionTrackFinder::tracks(const TrajectorySeedCollection inOutSeeds,
00059 TrackCandidateCollection &output_p ) const {
00060
00061
00062
00063
00064
00065 std::vector<Trajectory> tmpO;
00066 tmpO.erase(tmpO.begin(), tmpO.end() ) ;
00067
00068 std::vector<Trajectory> result;
00069 result.erase(result.begin(), result.end() ) ;
00070
00071
00072 std::vector<Trajectory> rawResult;
00073 if (theSeedCleaner_) theSeedCleaner_->init( &rawResult );
00074
00075
00076
00077
00078 int goodSeed=0;
00079 for(TrajectorySeedCollection::const_iterator iSeed=inOutSeeds.begin(); iSeed!=inOutSeeds.end();iSeed++){
00080 if (!theSeedCleaner_ || theSeedCleaner_->good(&(*iSeed))) {
00081 goodSeed++;
00082
00083 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks hits in the seed " << iSeed->nHits() << "\n";
00084 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks seed starting state position " << iSeed->startingState().parameters().position() << " momentum " << iSeed->startingState().parameters().momentum() << " charge " << iSeed->startingState().parameters().charge() << "\n";
00085 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks seed starting state para, vector " << iSeed->startingState().parameters().vector() << "\n";
00086
00087
00088
00089 std::vector<Trajectory> theTmpTrajectories;
00090
00091 theTmpTrajectories = theCkfTrajectoryBuilder_->trajectories(*iSeed);
00092
00093 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track returned " << theTmpTrajectories.size() << " trajectories for this seed " << "\n";
00094
00095 theTrajectoryCleaner_->clean(theTmpTrajectories);
00096
00097 for(std::vector<Trajectory>::const_iterator it=theTmpTrajectories.begin(); it!=theTmpTrajectories.end(); it++){
00098 if( it->isValid() ) {
00099 rawResult.push_back(*it);
00100 if (theSeedCleaner_) theSeedCleaner_->add( & (*it) );
00101 }
00102 }
00103 }
00104 }
00105
00106
00107
00108 LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track Good seeds " << goodSeed << "\n" ;
00109 LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track rawResult size after cleaning " << rawResult.size() << "\n";
00110
00111 if (theSeedCleaner_) theSeedCleaner_->done();
00112
00113
00114 std::vector<Trajectory> unsmoothedResult;
00115 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track Start second cleaning " << "\n";
00116 theTrajectoryCleaner_->clean(rawResult);
00117 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track rawResult size after cleaning " << rawResult.size() << "\n";
00118
00119
00120
00121 int tra=0;
00122 for (std::vector<Trajectory>::const_iterator itraw = rawResult.begin(); itraw != rawResult.end(); itraw++) {
00123 tra++;
00124 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder looping of rawResult after cleaning " << tra << "\n";
00125 if((*itraw).isValid()) {
00126
00127 tmpO.push_back( *itraw );
00128 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track rawResult num of valid recHits per trajectory " << (*itraw).foundHits() << "\n";
00129 }
00130
00131 }
00132
00133 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder tmpO size " << tmpO.size() << " before sorting " << "\n";
00134
00135
00136
00137
00138 precomputed_value_sort( tmpO.begin(), tmpO.end(), ExtractNumOfHits() );
00139
00140
00141 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder tmpO after sorting " << "\n";
00142
00143
00144
00145
00146 for (int i=tmpO.size()-1; i>=0; i--) {
00147 unsmoothedResult.push_back( tmpO[i] );
00148 }
00149 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder unsmoothedResult size " << unsmoothedResult.size() << "\n";
00150
00151
00152
00153
00154
00155
00156
00157 for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
00158
00159 if( !it->isValid() ) continue;
00160
00161 edm::OwnVector<TrackingRecHit> recHits;
00162 Trajectory::RecHitContainer thits = it->recHits();
00163 for (Trajectory::RecHitContainer::const_iterator hitIt = thits.begin(); hitIt != thits.end(); hitIt++) {
00164 recHits.push_back( (**hitIt).hit()->clone());
00165 }
00166
00167
00168 std::pair<TrajectoryStateOnSurface, const GeomDet*> initState = theInitialState_->innerState( *it);
00169
00170
00171 if (! initState.first.isValid() || initState.second == 0) {
00172
00173 continue;
00174 }
00175
00176 PTrajectoryStateOnDet* state = TrajectoryStateTransform().persistentState( initState.first, initState.second->geographicalId().rawId());
00177
00178 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";
00179 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track TSOS charge " << initState.first.charge() << "\n";
00180
00181 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track PTrajectoryStateOnDet* state position " << state->parameters().position() << " momentum " << state->parameters().momentum() << " charge " << state->parameters().charge () << "\n";
00182
00183
00184 result.push_back(*it);
00185
00186 output_p.push_back(TrackCandidate(recHits, it->seed(),*state ) );
00187 delete state;
00188 }
00189
00190 LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track Returning " << result.size() << " valid In Out Trajectories " << "\n";
00191 return result;
00192 }