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
21 
22 // Services and Tools
23 
24 // Geometry and Magnetic field
29 
30 // Other include files
39 
41 
42 using namespace std;
43 using namespace edm;
44 using namespace reco;
45 
47  LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer constructor called." << endl << endl;
48 
49  theFitterName = iConfig.getParameter<string>("Fitter");
50  theMuonRecHitBuilderName = iConfig.getParameter<string>("MuonRecHitBuilder");
51  thePropagatorName = iConfig.getParameter<string>("Propagator");
52 
53  nMinRecHits = iConfig.getParameter<unsigned int>("NMinRecHits");
54  errorRescale = iConfig.getParameter<double>("RescaleError");
55  useSubRecHits = iConfig.getParameter<bool>("UseSubRecHits");
56 }
57 
59  LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer destructor called." << endl << endl;
60 }
61 
63  iSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
64  iSetup.get<IdealMagneticFieldRecord>().get(theMagneticField);
65  iSetup.get<TrajectoryFitter::Record>().get(theFitterName, theFitter);
66  iSetup.get<TransientRecHitRecord>().get(theMuonRecHitBuilderName, theMuonRecHitBuilder);
67  iSetup.get<TrackingComponentsRecord>().get(thePropagatorName, thePropagator);
68 }
69 
70 vector<Trajectory> SeedTransformer::seedTransform(const TrajectorySeed& aSeed) const {
71  const string metname = "Reco|TrackingTools|SeedTransformer";
72 
73  LogTrace(metname) << " Number of valid RecHits: " << aSeed.nHits() << endl;
74 
75  if (aSeed.nHits() < nMinRecHits) {
76  LogTrace(metname) << " --- Too few RecHits, no refit performed! ---" << endl;
77  return vector<Trajectory>();
78  }
79 
80  TrajectoryStateOnSurface aTSOS(seedTransientState(aSeed));
81 
82  // Rescale errors before refit, not to bias the result
83  aTSOS.rescaleError(errorRescale);
84 
85  vector<TransientTrackingRecHit::ConstRecHitPointer> recHits;
86  unsigned int countRH = 0;
87 
88  for (TrajectorySeed::recHitContainer::const_iterator itRecHits = aSeed.recHits().first;
89  itRecHits != aSeed.recHits().second;
90  ++itRecHits, ++countRH) {
91  if ((*itRecHits).isValid()) {
92  TransientTrackingRecHit::ConstRecHitPointer ttrh(theMuonRecHitBuilder->build(&(*itRecHits)));
93 
94  if (useSubRecHits) {
97  copy(subHits.begin(), subHits.end(), back_inserter(recHits));
98  } else {
99  recHits.push_back(ttrh);
100  }
101  }
102  } // end for(TrajectorySeed::recHitContainer::const_iterator itRecHits=aSeed.recHits().first; itRecHits!=aSeed.recHits().second; ++itRecHits, ++countRH)
103 
104  TrajectoryStateOnSurface aInitTSOS = thePropagator->propagate(aTSOS, recHits.front()->det()->surface());
105 
106  if (!aInitTSOS.isValid()) {
107  LogTrace(metname) << " --- Initial state for refit not valid! ---" << endl;
108  return vector<Trajectory>();
109  }
110 
111  vector<Trajectory> refittedSeed = theFitter->fit(aSeed, recHits, aInitTSOS);
112 
113  if (refittedSeed.empty()) {
114  LogTrace(metname) << " --- Seed fit failed! ---" << endl;
115  return vector<Trajectory>();
116  }
117 
118  else if (!refittedSeed.front().isValid()) {
119  LogTrace(metname) << " --- Seed fitted, but trajectory not valid! ---" << endl;
120  return vector<Trajectory>();
121  }
122 
123  else
124  LogTrace(metname) << " +++ Seed fit succeded! +++" << endl;
125 
126  return refittedSeed;
127 }
128 
130  PTrajectoryStateOnDet tmpTSOD = tmpSeed.startingState();
131  DetId tmpDetId(tmpTSOD.detId());
132  const GeomDet* tmpGeomDet = theTrackingGeometry->idToDet(tmpDetId);
133 
134  TrajectoryStateOnSurface tmpTSOS =
135  trajectoryStateTransform::transientState(tmpTSOD, &(tmpGeomDet->surface()), &(*theMagneticField));
136 
137  return tmpTSOS;
138 }
T getParameter(std::string const &) const
const std::string metname
void setServices(const edm::EventSetup &)
Set the services needed by the SeedTransformer.
virtual ~SeedTransformer()
Destructor.
static TransientTrackingRecHit::ConstRecHitContainer breakInSubRecHits(TransientTrackingRecHit::ConstRecHitPointer, int granularity)
takes a muon rechit and returns its sub-rechits given a certain granularity
std::vector< Trajectory > seedTransform(const TrajectorySeed &) const
Performs the fit.
SeedTransformer(const edm::ParameterSet &)
Constructor.
std::shared_ptr< TrackingRecHit const > ConstRecHitPointer
unsigned int detId() const
#define LogTrace(id)
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: DetId.h:17
PTrajectoryStateOnDet const & startingState() const
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
range recHits() const
TrajectoryStateOnSurface seedTransientState(const TrajectorySeed &) const
unsigned int nHits() const
fixed size matrix
HLT enums.
T get() const
Definition: EventSetup.h:73