CMS 3D CMS Logo

SeedTransformer.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author D. Trocino - University and INFN Torino
5  */
6 
8 
9 // System include files
10 // #include <memory>
11 // #include <Riostream.h>
12 
13 // Framework
22 
23 // Services and Tools
24 
25 // Geometry and Magnetic field
30 
31 // Other include files
40 
42 
43 using namespace std;
44 using namespace edm;
45 using namespace reco;
46 
48  LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer constructor called." << endl << endl;
49 
50  theTrackingGeometryToken = iC.esConsumes();
51  theMagneticFieldToken = iC.esConsumes();
52  auto fitterName = iConfig.getParameter<string>("Fitter");
53  theFitterToken = iC.esConsumes(edm::ESInputTag("", fitterName));
54  auto muonRecHitBuilderName = iConfig.getParameter<string>("MuonRecHitBuilder");
55  theMuonRecHitBuilderToken = iC.esConsumes(edm::ESInputTag("", muonRecHitBuilderName));
56  auto propagatorName = iConfig.getParameter<string>("Propagator");
57  thePropagatorToken = iC.esConsumes(edm::ESInputTag("", propagatorName));
58 
59  nMinRecHits = iConfig.getParameter<unsigned int>("NMinRecHits");
60  errorRescale = iConfig.getParameter<double>("RescaleError");
61  useSubRecHits = iConfig.getParameter<bool>("UseSubRecHits");
62 }
63 
65  LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer destructor called." << endl << endl;
66 }
67 
69  theTrackingGeometry = &iSetup.getData(theTrackingGeometryToken);
70  theMagneticField = &iSetup.getData(theMagneticFieldToken);
71  theFitter = &iSetup.getData(theFitterToken);
72  theMuonRecHitBuilder = &iSetup.getData(theMuonRecHitBuilderToken);
73  thePropagator = &iSetup.getData(thePropagatorToken);
74 }
75 
76 vector<Trajectory> SeedTransformer::seedTransform(const TrajectorySeed& aSeed) const {
77  const string metname = "Reco|TrackingTools|SeedTransformer";
78 
79  LogTrace(metname) << " Number of valid RecHits: " << aSeed.nHits() << endl;
80 
81  if (aSeed.nHits() < nMinRecHits) {
82  LogTrace(metname) << " --- Too few RecHits, no refit performed! ---" << endl;
83  return vector<Trajectory>();
84  }
85 
86  TrajectoryStateOnSurface aTSOS(seedTransientState(aSeed));
87 
88  // Rescale errors before refit, not to bias the result
89  aTSOS.rescaleError(errorRescale);
90 
91  vector<TransientTrackingRecHit::ConstRecHitPointer> recHits;
92 
93  for (auto const& recHit : aSeed.recHits()) {
94  if (recHit.isValid()) {
95  TransientTrackingRecHit::ConstRecHitPointer ttrh(theMuonRecHitBuilder->build(&recHit));
96 
97  if (useSubRecHits) {
100  copy(subHits.begin(), subHits.end(), back_inserter(recHits));
101  } else {
102  recHits.push_back(ttrh);
103  }
104  }
105  }
106 
107  TrajectoryStateOnSurface aInitTSOS = thePropagator->propagate(aTSOS, recHits.front()->det()->surface());
108 
109  if (!aInitTSOS.isValid()) {
110  LogTrace(metname) << " --- Initial state for refit not valid! ---" << endl;
111  return vector<Trajectory>();
112  }
113 
114  vector<Trajectory> refittedSeed = theFitter->fit(aSeed, recHits, aInitTSOS);
115 
116  if (refittedSeed.empty()) {
117  LogTrace(metname) << " --- Seed fit failed! ---" << endl;
118  return vector<Trajectory>();
119  }
120 
121  else if (!refittedSeed.front().isValid()) {
122  LogTrace(metname) << " --- Seed fitted, but trajectory not valid! ---" << endl;
123  return vector<Trajectory>();
124  }
125 
126  else
127  LogTrace(metname) << " +++ Seed fit succeded! +++" << endl;
128 
129  return refittedSeed;
130 }
131 
133  PTrajectoryStateOnDet tmpTSOD = tmpSeed.startingState();
134  DetId tmpDetId(tmpTSOD.detId());
135  const GeomDet* tmpGeomDet = theTrackingGeometry->idToDet(tmpDetId);
136 
137  TrajectoryStateOnSurface tmpTSOS =
138  trajectoryStateTransform::transientState(tmpTSOD, &(tmpGeomDet->surface()), &(*theMagneticField));
139 
140  return tmpTSOS;
141 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
const std::string metname
RecHitRange recHits() const
void setServices(const edm::EventSetup &)
Set the services needed by the SeedTransformer.
virtual ~SeedTransformer()
Destructor.
SeedTransformer(const edm::ParameterSet &, edm::ConsumesCollector)
Constructor.
unsigned int detId() const
#define LogTrace(id)
static TransientTrackingRecHit::ConstRecHitContainer breakInSubRecHits(TransientTrackingRecHit::ConstRecHitPointer, int granularity)
takes a muon rechit and returns its sub-rechits given a certain granularity
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
unsigned int nHits() const
std::vector< Trajectory > seedTransform(const TrajectorySeed &) const
Performs the fit.
PTrajectoryStateOnDet const & startingState() const
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: DetId.h:17
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
fixed size matrix
HLT enums.
TrajectoryStateOnSurface seedTransientState(const TrajectorySeed &) const