Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-23 03:25:30

0001 // Package:    RecoTracker/SingleTrackPattern
0002 // Class:      CosmicTrackFinder
0003 // Original Author:  Michele Pioppi-INFN perugia
0004 #include <memory>
0005 #include <string>
0006 
0007 #include "RecoTracker/SingleTrackPattern/interface/CosmicTrackFinder.h"
0008 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0009 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
0010 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
0011 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
0012 #include "DataFormats/Common/interface/Handle.h"
0013 #include "FWCore/Framework/interface/ESHandle.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "DataFormats/TrackReco/interface/Track.h"
0016 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0017 #include "DataFormats/TrackReco/interface/TrackExtra.h"
0018 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0019 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0020 #include "TrackingTools/PatternTools/interface/TSCPBuilderNoMaterial.h"
0021 #include "FWCore/Utilities/interface/InputTag.h"
0022 #include "TrackingTools/PatternTools/interface/TrajTrackAssociation.h"
0023 
0024 #include "RecoTracker/TransientTrackingRecHit/interface/Traj2TrackHits.h"
0025 
0026 namespace cms {
0027 
0028   CosmicTrackFinder::CosmicTrackFinder(edm::ParameterSet const& conf)
0029       : cosmicTrajectoryBuilder_(conf, consumesCollector()), crackTrajectoryBuilder_(conf, consumesCollector()) {
0030     geometry = conf.getUntrackedParameter<std::string>("GeometricStructure", "STANDARD");
0031     useHitsSplitting_ = conf.getParameter<bool>("useHitsSplitting");
0032     matchedrecHitsToken_ =
0033         consumes<SiStripMatchedRecHit2DCollection>(conf.getParameter<edm::InputTag>("matchedRecHits"));
0034     rphirecHitsToken_ = consumes<SiStripRecHit2DCollection>(conf.getParameter<edm::InputTag>("rphirecHits"));
0035     stereorecHitsToken_ = consumes<SiStripRecHit2DCollection>(conf.getParameter<edm::InputTag>("stereorecHits"));
0036     pixelRecHitsToken_ = consumes<SiPixelRecHitCollection>(conf.getParameter<edm::InputTag>("pixelRecHits"));
0037     seedToken_ = consumes<TrajectorySeedCollection>(conf.getParameter<edm::InputTag>("cosmicSeeds"));
0038 
0039     produces<TrackCandidateCollection>();
0040   }
0041 
0042   // Virtual destructor needed.
0043   CosmicTrackFinder::~CosmicTrackFinder() {}
0044 
0045   // Functions that gets called by framework every event
0046   void CosmicTrackFinder::produce(edm::Event& e, const edm::EventSetup& es) {
0047     using namespace std;
0048 
0049     // retrieve seeds
0050     edm::Handle<TrajectorySeedCollection> seed;
0051     e.getByToken(seedToken_, seed);
0052 
0053     //retrieve PixelRecHits
0054     static const SiPixelRecHitCollection s_empty;
0055     const SiPixelRecHitCollection* pixelHitCollection = &s_empty;
0056     edm::Handle<SiPixelRecHitCollection> pixelHits;
0057     if (geometry != "MTCC" && (geometry != "CRACK")) {
0058       if (e.getByToken(pixelRecHitsToken_, pixelHits)) {
0059         pixelHitCollection = pixelHits.product();
0060       } else {
0061         Labels l;
0062         labelsForToken(pixelRecHitsToken_, l);
0063         edm::LogWarning("CosmicTrackFinder") << "Collection SiPixelRecHitCollection with InputTag " << l.module
0064                                              << " cannot be found, using empty collection of same type.";
0065       }
0066     }
0067 
0068     //retrieve StripRecHits
0069     edm::Handle<SiStripMatchedRecHit2DCollection> matchedrecHits;
0070     e.getByToken(matchedrecHitsToken_, matchedrecHits);
0071     edm::Handle<SiStripRecHit2DCollection> rphirecHits;
0072     e.getByToken(rphirecHitsToken_, rphirecHits);
0073     edm::Handle<SiStripRecHit2DCollection> stereorecHits;
0074     e.getByToken(stereorecHitsToken_, stereorecHits);
0075 
0076     // Step B: create empty output collection
0077     auto output = std::make_unique<TrackCandidateCollection>();
0078 
0079     edm::LogVerbatim("CosmicTrackFinder") << "========== Cosmic Track Finder Info ==========";
0080     edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Seeds " << (*seed).size();
0081     if (!(*seed).empty()) {
0082       std::vector<Trajectory> trajoutput;
0083 
0084       const TransientTrackingRecHitBuilder* hitBuilder = nullptr;
0085       if (geometry != "CRACK") {
0086         cosmicTrajectoryBuilder_.run(
0087             *seed, *stereorecHits, *rphirecHits, *matchedrecHits, *pixelHitCollection, es, e, trajoutput);
0088         hitBuilder = cosmicTrajectoryBuilder_.hitBuilder();
0089       } else {
0090         crackTrajectoryBuilder_.run(
0091             *seed, *stereorecHits, *rphirecHits, *matchedrecHits, *pixelHitCollection, es, e, trajoutput);
0092         hitBuilder = crackTrajectoryBuilder_.hitBuilder();
0093       }
0094       assert(hitBuilder);
0095       Traj2TrackHits t2t(hitBuilder, true);
0096 
0097       edm::LogVerbatim("CosmicTrackFinder") << " Numbers of Temp Trajectories " << trajoutput.size();
0098       edm::LogVerbatim("CosmicTrackFinder") << "========== END Info ==========";
0099       if (!trajoutput.empty()) {
0100         // crazyness...
0101         std::vector<Trajectory*> tmpTraj;
0102         std::vector<Trajectory>::iterator itr;
0103         for (itr = trajoutput.begin(); itr != trajoutput.end(); itr++)
0104           tmpTraj.push_back(&(*itr));
0105 
0106         //The best track is selected
0107         //FOR MTCC the criteria are:
0108         //1)# of layers,2) # of Hits,3)Chi2
0109         if (geometry == "MTCC")
0110           stable_sort(tmpTraj.begin(), tmpTraj.end(), CompareTrajLay());
0111         else
0112           stable_sort(tmpTraj.begin(), tmpTraj.end(), CompareTrajChi());
0113 
0114         ///.....
0115 
0116         const Trajectory theTraj = *(*tmpTraj.begin());
0117         bool seedplus = (theTraj.seed().direction() == alongMomentum);
0118 
0119         // std::cout << "CosmicTrackFinder " <<"Reconstruction " <<  (seedplus ? "along" : "opposite to") << " momentum" << std::endl;
0120         LogDebug("CosmicTrackFinder") << "Reconstruction " << (seedplus ? "along" : "opposite to") << " momentum";
0121 
0122         /*
0123     // === the convention is to save always final tracks with hits sorted *along* momentum
0124         // --- this is NOT what was necessaraly happening before and not consistent with what done in standard CKF (this is a candidate not a track)    
0125     */
0126         edm::OwnVector<TrackingRecHit> recHits;
0127         if (theTraj.direction() == alongMomentum)
0128           std::cout << "cosmic: along momentum... " << std::endl;
0129         t2t(theTraj, recHits, useHitsSplitting_);
0130         recHits.reverse();  // according to original code
0131 
0132         /*
0133     Trajectory::RecHitContainer thits;
0134     //it->recHitsV(thits);
0135         theTraj.recHitsV(thits,useHitsSplitting_);
0136     edm::OwnVector<TrackingRecHit> recHits;
0137     recHits.reserve(thits.size());
0138     // reverse hit order
0139     for (Trajectory::RecHitContainer::const_iterator hitIt = thits.end()-1;
0140          hitIt >= thits.begin(); hitIt--) {
0141       recHits.push_back( (**hitIt).hit()->clone());
0142     }
0143        */
0144 
0145         TSOS firstState;
0146         unsigned int firstId;
0147 
0148         // assume not along momentum....
0149         firstState = theTraj.lastMeasurement().updatedState();
0150         firstId = theTraj.lastMeasurement().recHitR().rawId();
0151         //firstId = recHits.front().rawId();
0152 
0153         /*
0154     cout << "firstState y, z: " << firstState.globalPosition().y() 
0155          << " , " << firstState.globalPosition().z() <<  endl;
0156 
0157     */
0158 
0159         AlgebraicSymMatrix55 C = AlgebraicMatrixID();
0160         TSOS startingState(
0161             firstState.localParameters(), LocalTrajectoryError(C), firstState.surface(), firstState.magneticField());
0162 
0163         // protection againt invalid initial states
0164         if (!firstState.isValid()) {
0165           edm::LogWarning("CosmicTrackFinder") << "invalid innerState, will not make TrackCandidate";
0166           edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(std::move(output));
0167           return;
0168         }
0169 
0170         // FIXME in case of slitting this can happen see CkfTrackCandidateMakerBase
0171         if (firstId != recHits.front().rawId()) {
0172           edm::LogWarning("CosmicTrackFinder") << "Mismatch in DetID of first hit: firstID= " << firstId
0173                                                << "   DetId= " << recHits.front().geographicalId().rawId();
0174           edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(std::move(output));
0175           return;
0176         }
0177 
0178         PTrajectoryStateOnDet const& state = trajectoryStateTransform::persistentState(startingState, firstId);
0179 
0180         output->push_back(TrackCandidate(recHits, theTraj.seed(), state, theTraj.seedRef()));
0181       }
0182     }
0183     edm::OrphanHandle<TrackCandidateCollection> rTrackCand = e.put(std::move(output));
0184   }
0185 }  // namespace cms