Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-28 03:59:16

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 //
0003 #include "RecoEgamma/EgammaPhotonAlgos/interface/InOutConversionTrackFinder.h"
0004 
0005 //
0006 #include "RecoTracker/CkfPattern/interface/CachingSeedCleanerBySharedInput.h"
0007 #include "RecoTracker/CkfPattern/interface/TransientInitialStateEstimator.h"
0008 //
0009 #include "TrackingTools/PatternTools/interface/TrajectoryBuilder.h"
0010 #include "TrackingTools/TrajectoryCleaning/interface/TrajectoryCleanerBySharedHits.h"
0011 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0012 #include "RecoTracker/TransientTrackingRecHit/interface/Traj2TrackHits.h"
0013 //
0014 #include "DataFormats/Common/interface/OwnVector.h"
0015 //
0016 #include "Utilities/General/interface/precomputed_value_sort.h"
0017 
0018 #include <sstream>
0019 
0020 InOutConversionTrackFinder::InOutConversionTrackFinder(const edm::ParameterSet& conf,
0021                                                        const BaseCkfTrajectoryBuilder* trajectoryBuilder,
0022                                                        edm::ConsumesCollector iC)
0023     : ConversionTrackFinder(conf, trajectoryBuilder, iC) {
0024   theTrajectoryCleaner_ = new TrajectoryCleanerBySharedHits(conf);
0025 
0026   // get the seed cleaner
0027   std::string cleaner = conf.getParameter<std::string>("InOutRedundantSeedCleaner");
0028   if (cleaner == "CachingSeedCleanerBySharedInput") {
0029     theSeedCleaner_ = new CachingSeedCleanerBySharedInput();
0030   } else if (cleaner == "none") {
0031     theSeedCleaner_ = nullptr;
0032   } else {
0033     throw cms::Exception("InOutRedundantSeedCleaner not found, please use CachingSeedCleanerBySharedInput or none",
0034                          cleaner);
0035   }
0036 }
0037 
0038 InOutConversionTrackFinder::~InOutConversionTrackFinder() {
0039   delete theTrajectoryCleaner_;
0040   if (theSeedCleaner_)
0041     delete theSeedCleaner_;
0042 }
0043 
0044 std::vector<Trajectory> InOutConversionTrackFinder::tracks(const TrajectorySeedCollection& inOutSeeds,
0045                                                            TrackCandidateCollection& output_p) const {
0046   //  std::cout << " InOutConversionTrackFinder::tracks getting " <<  inOutSeeds.size() << " In-Out seeds " << "\n";
0047 
0048   std::vector<Trajectory> tmpO;
0049   tmpO.erase(tmpO.begin(), tmpO.end());
0050 
0051   std::vector<Trajectory> result;
0052   result.erase(result.begin(), result.end());
0053 
0054   std::vector<Trajectory> rawResult;
0055   if (theSeedCleaner_)
0056     theSeedCleaner_->init(&rawResult);
0057 
0058   // Loop over the seeds
0059   int goodSeed = 0;
0060   for (TrajectorySeedCollection::const_iterator iSeed = inOutSeeds.begin(); iSeed != inOutSeeds.end(); iSeed++) {
0061     if (!theSeedCleaner_ || theSeedCleaner_->good(&(*iSeed))) {
0062       goodSeed++;
0063 
0064       LogDebug("InOutConversionTrackFinder")
0065           << " InOutConversionTrackFinder::tracks hits in the seed " << iSeed->nHits() << "\n";
0066       LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::tracks seed starting state position  "
0067                                              << iSeed->startingState().parameters().position() << " momentum "
0068                                              << iSeed->startingState().parameters().momentum() << " charge "
0069                                              << iSeed->startingState().parameters().charge() << "\n";
0070       LogDebug("InOutConversionTrackFinder")
0071           << " InOutConversionTrackFinder::tracks seed  starting state para, vector  "
0072           << iSeed->startingState().parameters().vector() << "\n";
0073 
0074       std::vector<Trajectory> theTmpTrajectories;
0075 
0076       theTmpTrajectories = theCkfTrajectoryBuilder_->trajectories(*iSeed);
0077 
0078       LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track returned "
0079                                              << theTmpTrajectories.size() << " trajectories for this seed "
0080                                              << "\n";
0081 
0082       theTrajectoryCleaner_->clean(theTmpTrajectories);
0083 
0084       for (std::vector<Trajectory>::const_iterator it = theTmpTrajectories.begin(); it != theTmpTrajectories.end();
0085            it++) {
0086         if (it->isValid()) {
0087           rawResult.push_back(*it);
0088           if (theSeedCleaner_)
0089             theSeedCleaner_->add(&(*it));
0090         }
0091       }
0092     }
0093   }  // end loop over the seeds
0094 
0095   LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track Good seeds " << goodSeed << "\n";
0096   LogDebug("InOutConversionTrackFinder") << "InOutConversionTrackFinder::track rawResult size after cleaning "
0097                                          << rawResult.size() << "\n";
0098 
0099   if (theSeedCleaner_)
0100     theSeedCleaner_->done();
0101 
0102   std::vector<Trajectory> unsmoothedResult;
0103   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track  Start second cleaning "
0104                                          << "\n";
0105   theTrajectoryCleaner_->clean(rawResult);
0106   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder::track rawResult size after cleaning "
0107                                          << rawResult.size() << "\n";
0108 
0109   int tra = 0;
0110   for (std::vector<Trajectory>::const_iterator itraw = rawResult.begin(); itraw != rawResult.end(); itraw++) {
0111     tra++;
0112     LogDebug("InOutConversionTrackFinder")
0113         << " InOutConversionTrackFinder looping of rawResult after cleaning " << tra << "\n";
0114     if ((*itraw).isValid()) {
0115       // unsmoothedResult.push_back( *itraw);
0116       tmpO.push_back(*itraw);
0117       LogDebug("InOutConversionTrackFinder")
0118           << " InOutConversionTrackFinder::track rawResult num of valid recHits per trajectory " << (*itraw).foundHits()
0119           << "\n";
0120     }
0121   }
0122 
0123   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  tmpO size " << tmpO.size()
0124                                          << " before sorting "
0125                                          << "\n";
0126   //  for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
0127   // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  tmpO num of hits " << (*it).foundHits() << " before ordering " << "\n";
0128   //}
0129 
0130   precomputed_value_sort(tmpO.begin(), tmpO.end(), ExtractNumOfHits());
0131 
0132   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  tmpO after sorting "
0133                                          << "\n";
0134   //  for (std::vector<Trajectory>::const_iterator it =tmpO.begin(); it != tmpO.end(); it++) {
0135   // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  tmpO  num of hits " << (*it).foundHits() << "\n";
0136   // }
0137 
0138   for (int i = tmpO.size() - 1; i >= 0; i--) {
0139     unsmoothedResult.push_back(tmpO[i]);
0140   }
0141   LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  unsmoothedResult size  "
0142                                          << unsmoothedResult.size() << "\n";
0143 
0144   //  for (std::vector<Trajectory>::const_iterator it =  unsmoothedResult.begin(); it !=  unsmoothedResult.end(); it++) {
0145   // LogDebug("InOutConversionTrackFinder") << " InOutConversionTrackFinder  unsmoothedResult  after reordering " <<(*it).foundHits() <<  "\n";
0146   //  }
0147 
0148   // Convert to TrackCandidates and fill in the output_p
0149   Traj2TrackHits t2t(theCkfTrajectoryBuilder_->hitBuilder(), true);
0150   for (std::vector<Trajectory>::const_iterator it = unsmoothedResult.begin(); it != unsmoothedResult.end(); it++) {
0151     edm::OwnVector<TrackingRecHit> recHits;
0152     if (it->direction() != alongMomentum)
0153       LogDebug("InOutConversionTrackFinder") << "InOutConv not along momentum... " << std::endl;
0154 
0155     t2t(*it, recHits, useSplitHits_);
0156 
0157     std::pair<TrajectoryStateOnSurface, const GeomDet*> initState = theInitialState_->innerState(*it);
0158 
0159     // temporary protection againt invalid initial states
0160     if ((!initState.first.isValid()) | (initState.second == nullptr)) {
0161       LogDebug("InOutConversionTrackFinder") << "invalid innerState, will not make TrackCandidate" << std::endl;
0162       continue;
0163     }
0164 
0165     PTrajectoryStateOnDet state;
0166     if (useSplitHits_ && (initState.second != recHits.front().det()) && recHits.front().det()) {
0167       TrajectoryStateOnSurface propagated =
0168           thePropagator_->propagate(initState.first, recHits.front().det()->surface());
0169       if (!propagated.isValid())
0170         continue;
0171       state = trajectoryStateTransform::persistentState(propagated, recHits.front().rawId());
0172     } else
0173       state = trajectoryStateTransform::persistentState(initState.first, initState.second->geographicalId().rawId());
0174 
0175     LogDebug("InOutConversionTrackFinder") << "  InOutConversionTrackFinder::track Making the result: seed position "
0176                                            << it->seed().startingState().parameters().position() << " seed momentum "
0177                                            << it->seed().startingState().parameters().momentum() << " charge "
0178                                            << it->seed().startingState().parameters().charge() << "\n";
0179     LogDebug("InOutConversionTrackFinder")
0180         << "  InOutConversionTrackFinder::track TSOS charge  " << initState.first.charge() << "\n";
0181 
0182     LogDebug("InOutConversionTrackFinder")
0183         << " InOutConversionTrackFinder::track  PTrajectoryStateOnDet* state position  "
0184         << state.parameters().position() << " momentum " << state.parameters().momentum() << " charge "
0185         << state.parameters().charge() << "\n";
0186 
0187     result.push_back(*it);
0188     output_p.push_back(TrackCandidate(recHits, it->seed(), state));
0189   }
0190   // assert(result.size()==output_p.size());
0191   LogDebug("InOutConversionTrackFinder") << "  InOutConversionTrackFinder::track Returning " << result.size()
0192                                          << " valid In Out Trajectories "
0193                                          << "\n";
0194   return result;
0195 }