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 
40 
42 
43 using namespace std;
44 using namespace edm;
45 using namespace reco;
46 
47 
49 
50  LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer constructor called." << endl << endl;
51 
52  theFitterName = iConfig.getParameter<string>("Fitter");
53  theMuonRecHitBuilderName = iConfig.getParameter<string>("MuonRecHitBuilder");
54  thePropagatorName = iConfig.getParameter<string>("Propagator");
55 
56  nMinRecHits = iConfig.getParameter<unsigned int>("NMinRecHits");
57  errorRescale = iConfig.getParameter<double>("RescaleError");
58  useSubRecHits = iConfig.getParameter<bool>("UseSubRecHits");
59 }
60 
62 
63  LogTrace("Reco|TrackingTools|SeedTransformer") << "SeedTransformer destructor called." << endl << endl;
64 
65 }
66 
68 
69  iSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
70  iSetup.get<IdealMagneticFieldRecord>().get(theMagneticField);
71  iSetup.get<TrajectoryFitter::Record>().get(theFitterName,theFitter);
72  iSetup.get<TransientRecHitRecord>().get(theMuonRecHitBuilderName,theMuonRecHitBuilder);
73  iSetup.get<TrackingComponentsRecord>().get(thePropagatorName,thePropagator);
74 
75 }
76 
77 vector<Trajectory> SeedTransformer::seedTransform(const TrajectorySeed& aSeed) const {
78 
79  const string metname = "Reco|TrackingTools|SeedTransformer";
80 
81  LogTrace(metname) << " Number of valid RecHits: " << aSeed.nHits() << endl;
82 
83  if( aSeed.nHits() < nMinRecHits ) {
84  LogTrace(metname) << " --- Too few RecHits, no refit performed! ---" << endl;
85  return vector<Trajectory>();
86  }
87 
88  TrajectoryStateOnSurface aTSOS(seedTransientState(aSeed));
89 
90  // Rescale errors before refit, not to bias the result
91  aTSOS.rescaleError(errorRescale);
92 
93  vector<TransientTrackingRecHit::ConstRecHitPointer> recHits;
94  unsigned int countRH = 0;
95 
96  for(TrajectorySeed::recHitContainer::const_iterator itRecHits=aSeed.recHits().first; itRecHits!=aSeed.recHits().second; ++itRecHits, ++countRH) {
97  if((*itRecHits).isValid()) {
98  TransientTrackingRecHit::ConstRecHitPointer ttrh(theMuonRecHitBuilder->build(&(*itRecHits)));
99 
100  if(useSubRecHits){
103  copy(subHits.begin(),subHits.end(),back_inserter(recHits));
104  }
105  else{
106  recHits.push_back(ttrh);
107  }
108  }
109  } // end for(TrajectorySeed::recHitContainer::const_iterator itRecHits=aSeed.recHits().first; itRecHits!=aSeed.recHits().second; ++itRecHits, ++countRH)
110 
111  TrajectoryStateOnSurface aInitTSOS = thePropagator->propagate(aTSOS, recHits.front()->det()->surface());
112 
113  if(!aInitTSOS.isValid()) {
114  LogTrace(metname) << " --- Initial state for refit not valid! ---" << endl;
115  return vector<Trajectory>();
116  }
117 
118  vector<Trajectory> refittedSeed = theFitter->fit(aSeed, recHits, aInitTSOS);
119 
120  if(refittedSeed.empty()) {
121  LogTrace(metname) << " --- Seed fit failed! ---" << endl;
122  return vector<Trajectory>();
123  }
124 
125  else if(!refittedSeed.front().isValid()) {
126  LogTrace(metname) << " --- Seed fitted, but trajectory not valid! ---" << endl;
127  return vector<Trajectory>();
128  }
129 
130  else
131  LogTrace(metname) << " +++ Seed fit succeded! +++" << endl;
132 
133  return refittedSeed;
134 
135 }
136 
138 
139  PTrajectoryStateOnDet tmpTSOD = tmpSeed.startingState();
140  DetId tmpDetId(tmpTSOD.detId());
141  const GeomDet* tmpGeomDet = theTrackingGeometry->idToDet(tmpDetId);
142 
143 
144  TrajectoryStateOnSurface tmpTSOS = trajectoryStateTransform::transientState(tmpTSOD, &(tmpGeomDet->surface()), &(*theMagneticField));
145 
146  return tmpTSOS;
147 
148 }
T getParameter(std::string const &) const
def copy(args, dbName)
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:18
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:68