Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-20 10:42:30

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author D. Trocino - University and INFN Torino
0005  */
0006 
0007 #include "TrackingTools/TrackRefitter/interface/SeedTransformer.h"
0008 
0009 // System include files
0010 // #include <memory>
0011 // #include <Riostream.h>
0012 
0013 // Framework
0014 #include "FWCore/Framework/interface/MakerMacros.h"
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/Framework/interface/Event.h"
0017 #include "FWCore/Framework/interface/EventSetup.h"
0018 #include "FWCore/Framework/interface/ESHandle.h"
0019 #include "FWCore/Framework/interface/ConsumesCollector.h"
0020 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0022 
0023 // Services and Tools
0024 
0025 // Geometry and Magnetic field
0026 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
0027 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0028 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0029 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0030 
0031 // Other include files
0032 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
0033 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0034 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0035 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0036 #include "TrackingTools/Records/interface/TrackingComponentsRecord.h"
0037 #include "TrackingTools/TrackFitters/interface/TrajectoryFitter.h"
0038 #include "TrackingTools/PatternTools/interface/Trajectory.h"
0039 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0040 
0041 #include "RecoMuon/TransientTrackingRecHit/interface/MuonTransientTrackingRecHitBreaker.h"
0042 
0043 using namespace std;
0044 using namespace edm;
0045 using namespace reco;
0046 
0047 SeedTransformer::SeedTransformer(const ParameterSet& iConfig, ConsumesCollector iC) {
0048   LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer constructor called." << endl << endl;
0049 
0050   theTrackingGeometryToken = iC.esConsumes();
0051   theMagneticFieldToken = iC.esConsumes();
0052   auto fitterName = iConfig.getParameter<string>("Fitter");
0053   theFitterToken = iC.esConsumes(edm::ESInputTag("", fitterName));
0054   auto muonRecHitBuilderName = iConfig.getParameter<string>("MuonRecHitBuilder");
0055   theMuonRecHitBuilderToken = iC.esConsumes(edm::ESInputTag("", muonRecHitBuilderName));
0056   auto propagatorName = iConfig.getParameter<string>("Propagator");
0057   thePropagatorToken = iC.esConsumes(edm::ESInputTag("", propagatorName));
0058 
0059   nMinRecHits = iConfig.getParameter<unsigned int>("NMinRecHits");
0060   errorRescale = iConfig.getParameter<double>("RescaleError");
0061   useSubRecHits = iConfig.getParameter<bool>("UseSubRecHits");
0062 }
0063 
0064 SeedTransformer::~SeedTransformer() {
0065   LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer destructor called." << endl << endl;
0066 }
0067 
0068 void SeedTransformer::setServices(const EventSetup& iSetup) {
0069   theTrackingGeometry = &iSetup.getData(theTrackingGeometryToken);
0070   theMagneticField = &iSetup.getData(theMagneticFieldToken);
0071   theFitter = &iSetup.getData(theFitterToken);
0072   theMuonRecHitBuilder = &iSetup.getData(theMuonRecHitBuilderToken);
0073   thePropagator = &iSetup.getData(thePropagatorToken);
0074 }
0075 
0076 vector<Trajectory> SeedTransformer::seedTransform(const TrajectorySeed& aSeed) const {
0077   const string metname = "Reco|TrackingTools|SeedTransformer";
0078 
0079   LogTrace(metname) << " Number of valid RecHits:      " << aSeed.nHits() << endl;
0080 
0081   if (aSeed.nHits() < nMinRecHits) {
0082     LogTrace(metname) << "    --- Too few RecHits, no refit performed! ---" << endl;
0083     return vector<Trajectory>();
0084   }
0085 
0086   TrajectoryStateOnSurface aTSOS(seedTransientState(aSeed));
0087 
0088   // Rescale errors before refit, not to bias the result
0089   aTSOS.rescaleError(errorRescale);
0090 
0091   vector<TransientTrackingRecHit::ConstRecHitPointer> recHits;
0092 
0093   for (auto const& recHit : aSeed.recHits()) {
0094     if (recHit.isValid()) {
0095       TransientTrackingRecHit::ConstRecHitPointer ttrh(theMuonRecHitBuilder->build(&recHit));
0096 
0097       if (useSubRecHits) {
0098         TransientTrackingRecHit::ConstRecHitContainer subHits =
0099             MuonTransientTrackingRecHitBreaker::breakInSubRecHits(ttrh, 2);
0100         copy(subHits.begin(), subHits.end(), back_inserter(recHits));
0101       } else {
0102         recHits.push_back(ttrh);
0103       }
0104     }
0105   }
0106 
0107   TrajectoryStateOnSurface aInitTSOS = thePropagator->propagate(aTSOS, recHits.front()->det()->surface());
0108 
0109   if (!aInitTSOS.isValid()) {
0110     LogTrace(metname) << "    --- Initial state for refit not valid! ---" << endl;
0111     return vector<Trajectory>();
0112   }
0113 
0114   vector<Trajectory> refittedSeed = theFitter->fit(aSeed, recHits, aInitTSOS);
0115 
0116   if (refittedSeed.empty()) {
0117     LogTrace(metname) << "    --- Seed fit failed! ---" << endl;
0118     return vector<Trajectory>();
0119   }
0120 
0121   else if (!refittedSeed.front().isValid()) {
0122     LogTrace(metname) << "    --- Seed fitted, but trajectory not valid! ---" << endl;
0123     return vector<Trajectory>();
0124   }
0125 
0126   else
0127     LogTrace(metname) << "    +++ Seed fit succeded! +++" << endl;
0128 
0129   return refittedSeed;
0130 }
0131 
0132 TrajectoryStateOnSurface SeedTransformer::seedTransientState(const TrajectorySeed& tmpSeed) const {
0133   PTrajectoryStateOnDet tmpTSOD = tmpSeed.startingState();
0134   DetId tmpDetId(tmpTSOD.detId());
0135   const GeomDet* tmpGeomDet = theTrackingGeometry->idToDet(tmpDetId);
0136 
0137   TrajectoryStateOnSurface tmpTSOS =
0138       trajectoryStateTransform::transientState(tmpTSOD, &(tmpGeomDet->surface()), &(*theMagneticField));
0139 
0140   return tmpTSOS;
0141 }