Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef CRackTrajectoryBuilder_h
0002 #define CRackTrajectoryBuilder_h
0003 
0004 //
0005 // Package:         RecoTracker/SingleTrackPattern
0006 // Class:           CRackTrajectoryBuilder
0007 // Original Author:  Michele Pioppi-INFN perugia
0008 
0009 #include <string>
0010 
0011 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0012 #include "FWCore/Framework/interface/EventSetup.h"
0013 #include "FWCore/Framework/interface/ConsumesCollector.h"
0014 
0015 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
0016 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
0017 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2DCollection.h"
0018 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2DCollection.h"
0019 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
0020 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0021 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0022 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0023 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
0024 #include "TrackingTools/KalmanUpdators/interface/KFUpdator.h"
0025 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
0026 #include "MagneticField/Engine/interface/MagneticField.h"
0027 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0028 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
0029 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
0030 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0031 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0032 #include "DataFormats/TrackReco/interface/Track.h"
0033 #include "DataFormats/TrackReco/interface/TrackExtra.h"
0034 #include "TrackingTools/TrackFitters/interface/KFTrajectoryFitter.h"
0035 #include "TrackingTools/TrackFitters/interface/KFTrajectorySmoother.h"
0036 #include "TrackingTools/MeasurementDet/interface/LayerMeasurements.h"
0037 #include "RecoTracker/MeasurementDet/interface/MeasurementTracker.h"
0038 #include "TrackingTools/MaterialEffects/interface/PropagatorWithMaterial.h"
0039 
0040 //to sort hits by the det position
0041 class CompareDetY_plus {
0042 public:
0043   CompareDetY_plus(const TrackerGeometry& tracker) : _tracker(tracker) {}
0044   bool operator()(const TrackingRecHit* rh1, const TrackingRecHit* rh2) {
0045     const GeomDet* detPos1 = _tracker.idToDet(rh1->geographicalId());
0046     const GeomDet* detPos2 = _tracker.idToDet(rh2->geographicalId());
0047 
0048     const GlobalPoint& gp1 = detPos1->position();
0049     const GlobalPoint& gp2 = detPos2->position();
0050 
0051     if (gp1.y() > gp2.y())
0052       return true;
0053     if (gp1.y() < gp2.y())
0054       return false;
0055     //  if (gp1.y()== gp2.y())
0056     //
0057     return (rh1->geographicalId() < rh2->geographicalId());
0058   };
0059 
0060 private:
0061   //   edm::ESHandle<TrackerGeometry> _tracker;
0062   const TrackerGeometry& _tracker;
0063 };
0064 
0065 class CompareDetY_minus {
0066 public:
0067   CompareDetY_minus(const TrackerGeometry& tracker) : _tracker(tracker) {}
0068   bool operator()(const TrackingRecHit* rh1, const TrackingRecHit* rh2) {
0069     const GeomDet* detPos1 = _tracker.idToDet(rh1->geographicalId());
0070     const GeomDet* detPos2 = _tracker.idToDet(rh2->geographicalId());
0071 
0072     const GlobalPoint& gp1 = detPos1->position();
0073     const GlobalPoint& gp2 = detPos2->position();
0074 
0075     if (gp1.y() < gp2.y())
0076       return true;
0077     if (gp1.y() > gp2.y())
0078       return false;
0079     //  if (gp1.y()== gp2.y())
0080     //
0081     return (rh1->geographicalId() < rh2->geographicalId());
0082   };
0083 
0084 private:
0085   //   edm::ESHandle<TrackerGeometry> _tracker;
0086   const TrackerGeometry& _tracker;
0087 };
0088 
0089 #ifndef TrajectoryBuilder_CompareHitY
0090 #define TrajectoryBuilder_CompareHitY
0091 
0092 class CompareHitY {
0093 public:
0094   CompareHitY(const TrackerGeometry& tracker) : _tracker(tracker) {}
0095   bool operator()(const TrackingRecHit* rh1, const TrackingRecHit* rh2) {
0096     GlobalPoint gp1 = _tracker.idToDet(rh1->geographicalId())->surface().toGlobal(rh1->localPosition());
0097     GlobalPoint gp2 = _tracker.idToDet(rh2->geographicalId())->surface().toGlobal(rh2->localPosition());
0098     return gp1.y() < gp2.y();
0099   };
0100 
0101 private:
0102   //   edm::ESHandle<TrackerGeometry> _tracker;
0103   const TrackerGeometry& _tracker;
0104 };
0105 
0106 class CompareHitY_plus {
0107 public:
0108   CompareHitY_plus(const TrackerGeometry& tracker) : _tracker(tracker) {}
0109   bool operator()(const TrackingRecHit* rh1, const TrackingRecHit* rh2) {
0110     GlobalPoint gp1 = _tracker.idToDet(rh1->geographicalId())->surface().toGlobal(rh1->localPosition());
0111     GlobalPoint gp2 = _tracker.idToDet(rh2->geographicalId())->surface().toGlobal(rh2->localPosition());
0112     return gp1.y() > gp2.y();
0113   };
0114 
0115 private:
0116   //   edm::ESHandle<TrackerGeometry> _tracker;
0117   const TrackerGeometry& _tracker;
0118 };
0119 
0120 #endif
0121 
0122 class CRackTrajectoryBuilder {
0123   //  using namespace std;
0124 
0125   typedef TrajectoryStateOnSurface TSOS;
0126   typedef TrajectoryMeasurement TM;
0127 
0128   typedef std::vector<const TrackingRecHit*>::iterator TrackingRecHitIterator;
0129 
0130   typedef std::pair<TrackingRecHitIterator, TrackingRecHitIterator> TrackingRecHitRange;
0131   typedef std::vector<TrackingRecHitRange>::iterator TrackingRecHitRangeIterator;
0132 
0133   //  typedef std::pair<TrackingRecHitIterator, TSOS> PairTrackingRecHitTsos;
0134   typedef std::pair<TrackingRecHitRangeIterator, TSOS> PairTrackingRecHitTsos;
0135 
0136 public:
0137   class CompareDetByTraj;
0138   friend class CompareDetByTraj;
0139 
0140   class CompareDetByTraj {
0141   public:
0142     CompareDetByTraj(const TSOS& tSos) : _tSos(tSos){};
0143     bool operator()(const std::pair<TrackingRecHitRangeIterator, TSOS> rh1,
0144                     const std::pair<TrackingRecHitRangeIterator, TSOS> rh2) {
0145       GlobalPoint gp1 = rh1.second.globalPosition();
0146       GlobalPoint gp2 = rh2.second.globalPosition();
0147 
0148       GlobalPoint gpT = _tSos.globalPosition();
0149       GlobalVector gpDiff1 = gp1 - gpT;
0150       GlobalVector gpDiff2 = gp2 - gpT;
0151 
0152       //this might have a better performance ...
0153       //       float dist1 = ( gp1.x()-gpT.x() ) * ( gp1.x()-gpT.x() ) + ( gp1.y()-gpT.y() ) * ( gp1.y()-gpT.y() ) + ( gp1.z()-gpT.z() ) * ( gp1.z()-gpT.z() );
0154       //       float dist2 = ( gp2.x()-gpT.x() ) * ( gp2.x()-gpT.x() ) + ( gp2.y()-gpT.y() ) * ( gp2.y()-gpT.y() ) + ( gp2.z()-gpT.z() ) * ( gp2.z()-gpT.z() );
0155       //if ( dist1<dist2 )
0156 
0157       //     if ( gpDiff1.mag2() < gpDiff2.mag2() )
0158 
0159       float dist1 = gpDiff1 * _tSos.globalDirection();
0160       float dist2 = gpDiff2 * _tSos.globalDirection();
0161 
0162       if (dist1 < 0)
0163         return false;
0164       if (dist1 < dist2)
0165         return true;
0166 
0167       return false;
0168     };
0169 
0170   private:
0171     const TrajectoryStateOnSurface& _tSos;
0172   };
0173 
0174 public:
0175   CRackTrajectoryBuilder(const edm::ParameterSet& conf, edm::ConsumesCollector iC);
0176   ~CRackTrajectoryBuilder();
0177 
0178   /// Runs the algorithm
0179 
0180   void run(const TrajectorySeedCollection& collseed,
0181            const SiStripRecHit2DCollection& collstereo,
0182            const SiStripRecHit2DCollection& collrphi,
0183            const SiStripMatchedRecHit2DCollection& collmatched,
0184            const SiPixelRecHitCollection& collpixel,
0185            const edm::EventSetup& es,
0186            edm::Event& e,
0187            std::vector<Trajectory>& trajoutput);
0188 
0189   void init(const edm::EventSetup& es, bool);
0190   Trajectory createStartingTrajectory(const TrajectorySeed& seed) const;
0191 
0192   const TransientTrackingRecHitBuilder* hitBuilder() const { return RHBuilder; }
0193 
0194 private:
0195   std::vector<TrajectoryMeasurement> seedMeasurements(const TrajectorySeed& seed) const;
0196 
0197   std::vector<const TrackingRecHit*> SortHits(const SiStripRecHit2DCollection& collstereo,
0198                                               const SiStripRecHit2DCollection& collrphi,
0199                                               const SiStripMatchedRecHit2DCollection& collmatched,
0200                                               const SiPixelRecHitCollection& collpixel,
0201                                               const TrajectorySeed& seed,
0202                                               const bool bAddSeedHits);
0203 
0204   //    std::vector<TrackingRecHitRange> SortByTrajectory (const std::vector<TrackingRecHitRange>& inputHits);
0205 
0206   TSOS startingTSOS(const TrajectorySeed& seed) const;
0207   void updateTrajectory(Trajectory& traj, const TM& tm, const TransientTrackingRecHit& hit) const;
0208 
0209   void AddHit(Trajectory& traj, const std::vector<const TrackingRecHit*>& Hits, Propagator* currPropagator);
0210   //        edm::OwnVector<TransientTrackingRecHit> hits);
0211   bool qualityFilter(const Trajectory& traj);
0212 
0213   bool isDifferentStripReHit2D(const SiStripRecHit2D& hitA, const SiStripRecHit2D& hitB);
0214 
0215   std::pair<TrajectoryStateOnSurface, const GeomDet*> innerState(const Trajectory& traj) const;
0216 
0217 private:
0218   const edm::ESGetToken<MagneticField, IdealMagneticFieldRecord> magfieldToken_;
0219   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> trackerToken_;
0220   const edm::ESGetToken<TransientTrackingRecHitBuilder, TransientRecHitRecord> builderToken_;
0221   const MagneticField* magfield;
0222   const TrackerGeometry* tracker;
0223 
0224   PropagatorWithMaterial* thePropagator;
0225   PropagatorWithMaterial* thePropagatorOp;
0226 
0227   //   AnalyticalPropagator *thePropagator;
0228   //   AnalyticalPropagator *thePropagatorOp;
0229 
0230   KFUpdator* theUpdator;
0231   Chi2MeasurementEstimator* theEstimator;
0232   const TransientTrackingRecHitBuilder* RHBuilder;
0233   const KFTrajectorySmoother* theSmoother;
0234   const KFTrajectoryFitter* theFitter;
0235   //   const KFTrajectoryFitter * theFitterOp;
0236 
0237   bool debug_info;
0238   bool fastPropagation;
0239   bool useMatchedHits;
0240 
0241   int theMinHits;
0242   double chi2cut;
0243   std::vector<Trajectory> trajFit;
0244   //RC edm::OwnVector<const TransientTrackingRecHit> hits;
0245   TransientTrackingRecHit::RecHitContainer hits;
0246   bool seed_plus;
0247   std::string geometry;
0248   //   TransientInitialStateEstimator*  theInitialState;
0249 };
0250 
0251 #endif