CMS 3D CMS Logo

TrackTransformer.cc
Go to the documentation of this file.
2 
6 
9 
13 
20 
24 
25 using namespace std;
26 using namespace edm;
27 
30  theRPCInTheFit(parameterSet.getParameter<bool>("RefitRPCHits")),
31  theDoPredictionsOnly(parameterSet.getParameter<bool>("DoPredictionsOnly")),
32  theRefitDirection(parameterSet.getParameter<string>("RefitDirection")),
33  theFitterName(parameterSet.getParameter<string>("Fitter")),
34  theSmootherName(parameterSet.getParameter<string>("Smoother")),
35  thePropagatorName(parameterSet.getParameter<string>("Propagator")),
36  theTrackerRecHitBuilderName(parameterSet.getParameter<string>("TrackerRecHitBuilder")),
37  theMuonRecHitBuilderName(parameterSet.getParameter<string>("MuonRecHitBuilder"))
38  {}
39 
42 
43 
45 
46  const std::string metname = "Reco|TrackingTools|TrackTransformer";
47 
50  setup.get<TrajectoryFitter::Record>().get(theFitterName,aFitter);
51  setup.get<TrajectoryFitter::Record>().get(theSmootherName,aSmoother);
52  theFitter = aFitter->clone();
53  theSmoother.reset(aSmoother->clone());
54 
55  unsigned long long newCacheId_TC = setup.get<TrackingComponentsRecord>().cacheIdentifier();
56 
57  if ( newCacheId_TC != theCacheId_TC ){
58  LogTrace(metname) << "Tracking Component changed!";
59  theCacheId_TC = newCacheId_TC;
61  }
62 
63  // Global Tracking Geometry
64  unsigned long long newCacheId_GTG = setup.get<GlobalTrackingGeometryRecord>().cacheIdentifier();
65  if ( newCacheId_GTG != theCacheId_GTG ) {
66  LogTrace(metname) << "GlobalTrackingGeometry changed!";
67  theCacheId_GTG = newCacheId_GTG;
69  }
70 
71  // Magfield Field
72  unsigned long long newCacheId_MG = setup.get<IdealMagneticFieldRecord>().cacheIdentifier();
73  if ( newCacheId_MG != theCacheId_MG ) {
74  LogTrace(metname) << "Magnetic Field changed!";
75  theCacheId_MG = newCacheId_MG;
77  }
78 
79  // Transient Rechit Builders
80  unsigned long long newCacheId_TRH = setup.get<TransientRecHitRecord>().cacheIdentifier();
81  if ( newCacheId_TRH != theCacheId_TRH ) {
82  theCacheId_TRH = newCacheId_TRH;
83  LogTrace(metname) << "TransientRecHitRecord changed!";
87  }
88  theFitter->setHitCloner(&hitCloner);
89  theSmoother->setHitCloner(&hitCloner);
90 
91 }
92 
93 
94 vector<Trajectory> TrackTransformer::transform(const reco::TrackRef& track) const {
95  return transform(*track);
96 }
97 
98 
101 
103  auto tkbuilder = static_cast<TkTransientTrackingRecHitBuilder const *>(theTrackerRecHitBuilder.product());
104 
105 
106  for (auto hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit) {
107  if((*hit)->isValid()) {
108  if ( (*hit)->geographicalId().det() == DetId::Tracker ) {
109  result.emplace_back((**hit).cloneForFit(*tkbuilder->geometry()->idToDet( (**hit).geographicalId() ) ) );
110  } else if ( (*hit)->geographicalId().det() == DetId::Muon ){
111  if( (*hit)->geographicalId().subdetId() == 3 && !theRPCInTheFit){
112  LogTrace("Reco|TrackingTools|TrackTransformer") << "RPC Rec Hit discarged";
113  continue;
114  }
115  result.push_back(theMuonRecHitBuilder->build(&**hit));
116  }
117  }
118  }
119 
120  return result;
121 }
122 
123 // FIXME: check this method!
126 
127  if (!recHits.empty()){
128  GlobalPoint first = trackingGeometry()->idToDet(recHits.front()->geographicalId())->position();
129  GlobalPoint last = trackingGeometry()->idToDet(recHits.back()->geographicalId())->position();
130 
131  // maybe perp2?
132  auto rFirst = first.mag2();
133  auto rLast = last.mag2();
134  if(rFirst < rLast) return RefitDirection::insideOut;
135  if(rFirst > rLast) return RefitDirection::outsideIn;
136  }
137  LogDebug("Reco|TrackingTools|TrackTransformer") << "Impossible to determine the rechits order" <<endl;
139 }
140 
141 
143 vector<Trajectory> TrackTransformer::transform(const reco::Track& newTrack) const {
144 
145  const std::string metname = "Reco|TrackingTools|TrackTransformer";
146 
148 
149  auto recHitsForReFit = getTransientRecHits(track);
150  return transform(track, recHitsForReFit);
151 }
152 
153 
156  TransientTrackingRecHit::ConstRecHitContainer& recHitsForReFit) const {
157 
158  const std::string metname = "Reco|TrackingTools|TrackTransformer";
159 
160  if(recHitsForReFit.size() < 2) return vector<Trajectory>();
161 
162  // 8 cases are foreseen:
163  // [RH = rec hit order, P = momentum dir, FD = fit direction. IO/OI = inside-out/outside-in, AM/OM = along momentum/opposite to momentum]
164  // (1) RH IO | P IO | FD AM ---> Start from IN
165  // (2) RH IO | P IO | FD OM ---> Reverse RH and start from OUT
166  // (3) RH IO | P OI | FD AM ---> Reverse RH and start from IN
167  // (4) RH IO | P OI | FD OM ---> Start from OUT
168  // (5) RH OI | P IO | FD AM ---> Reverse RH and start from IN
169  // (6) RH OI | P IO | FD OM ---> Start from OUT
170  // (7) RH OI | P OI | FD AM ---> Start from IN
171  // (8) RH OI | P OI | FD OM ---> Reverse RH and start from OUT
172  //
173  // *** Rules: ***
174  // -A- If RH-FD agree (IO-AM,OI-OM) do not reverse the RH
175  // -B- If FD along momentum start from innermost state, otherwise use outermost
176 
177  // Other special cases can be handled:
178  // (1 bis) RH IO | P IO | GFD IO => FD AM ---> Start from IN
179  // (2 bis) RH IO | P IO | GFD OI => FD OM ---> Reverse RH and start from OUT
180  // (3 bis) RH IO | P OI | GFD OI => FD AM ---> Reverse RH and start from OUT
181  // (4 bis) RH IO | P OI | GFD IO => FD OM ---> Start from IN
182  // (5 bis) RH OI | P IO | GFD IO => FD AM ---> Reverse RH and start from IN
183  // (6 bis) RH OI | P IO | GFD OI => FD OM ---> Start from OUT
184  // (7 bis) RH OI | P OI | GFD OI => FD AM ---> Start from OUT
185  // (8 bis) RH OI | P OI | GFD IO => FD OM ---> Reverse RH and start from IN
186  //
187  // *** Additional rule: ***
188  // -A0- If P and GFD agree, then FD is AM otherwise is OM
189  // -A00- rechit must be ordered as GFD in order to handle the case of cosmics
190  // -B0- The starting state is decided by GFD
191 
192  // Determine the RH order
193  RefitDirection::GeometricalDirection recHitsOrder = checkRecHitsOrdering(recHitsForReFit); // FIXME change nome of the *type* --> RecHit order!
194  LogTrace(metname) << "RH order (0-insideOut, 1-outsideIn): " << recHitsOrder;
195 
197 
198  // Apply rule -A0-
199  if(propagationDirection == anyDirection){
202  RefitDirection::GeometricalDirection p = (momentum.x()*position.x() > 0 || momentum.y()*position.y() > 0) ? RefitDirection::insideOut : RefitDirection::outsideIn;
203 
205  LogTrace(metname) << "P (0-insideOut, 1-outsideIn): " << p;
206  LogTrace(metname) << "FD (0-OM, 1-AM, 2-ANY): " << propagationDirection;
207  }
208  // -A0-
209 
210  // Apply rule -A-
212  if((recHitsOrder == RefitDirection::insideOut && propagationDirection == oppositeToMomentum) ||
213  (recHitsOrder == RefitDirection::outsideIn && propagationDirection == alongMomentum) )
214  reverse(recHitsForReFit.begin(),recHitsForReFit.end());}
215  // -A-
216  // Apply rule -A00-
217  else{
218  // reorder the rechit as defined in theRefitDirection.geometricalDirection();
219  if(theRefitDirection.geometricalDirection() != recHitsOrder) reverse(recHitsForReFit.begin(),recHitsForReFit.end());
220  }
221  // -A00-
222 
223  // Apply rule -B-
225  unsigned int innerId = track.track().innerDetId();
227  if(propagationDirection == oppositeToMomentum){
228  innerId = track.track().outerDetId();
229  firstTSOS = track.outermostMeasurementState();
230  }
231  }
232  else { // if(theRefitDirection.propagationDirection() == anyDirection)
233  // Apply rule -B0-
235  innerId = track.track().outerDetId();
236  firstTSOS = track.outermostMeasurementState();
237  }
238  // -B0-
239  }
240  // -B-
241 
242  if(!firstTSOS.isValid()){
243  LogTrace(metname)<<"Error wrong initial state!"<<endl;
244  return vector<Trajectory>();
245  }
246 
248 
249  if(recHitsForReFit.front()->geographicalId() != DetId(innerId)){
250  LogTrace(metname)<<"Propagation occured"<<endl;
251  firstTSOS = propagator()->propagate(firstTSOS, recHitsForReFit.front()->det()->surface());
252  if(!firstTSOS.isValid()){
253  LogTrace(metname)<<"Propagation error!"<<endl;
254  return vector<Trajectory>();
255  }
256  }
257 
259  Trajectory aTraj(seed,propagationDirection);
260  TrajectoryStateOnSurface predTSOS = firstTSOS;
261  for(auto const & hit : recHitsForReFit) {
262  predTSOS = propagator()->propagate(predTSOS, hit->det()->surface());
263  if (predTSOS.isValid()) aTraj.push(TrajectoryMeasurement(predTSOS, hit));
264  }
265  return vector<Trajectory>(1, aTraj);
266  }
267 
268 
269  auto const & trajectories = theFitter->fit(seed,recHitsForReFit,firstTSOS);
270 
271  if(trajectories.empty()){
272  LogTrace(metname)<<"No Track refitted!"<<endl;
273  return trajectories;
274  }
275 
276  auto const & trajectoryBW = trajectories.front();
277 
278  auto const & trajectoriesSM = theSmoother->trajectories(trajectoryBW);
279 
280  if(trajectoriesSM.empty()){
281  LogTrace(metname)<<"No Track smoothed!"<<endl;
282  }
283 
284  return trajectoriesSM;
285 
286 }
287 
288 
#define LogDebug(id)
const std::string theTrackerRecHitBuilderName
T mag2() const
Definition: PV3DBase.h:66
const MagneticField * magneticField() const
the magnetic field
PropagationDirection propagationDirection() const
void setServices(const edm::EventSetup &) override
set the services needed by the TrackTransformer
const std::string metname
const RefitDirection theRefitDirection
GeometricalDirection geometricalDirection() const
const bool theRPCInTheFit
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
GlobalPoint globalPosition() const
PropagationDirection
unsigned long long theCacheId_TRH
TrajectoryStateOnSurface innermostMeasurementState() const
virtual TrajectorySmoother * clone() const =0
RefitDirection::GeometricalDirection checkRecHitsOrdering(TransientTrackingRecHit::ConstRecHitContainer const &) const
edm::ESHandle< GlobalTrackingGeometry > theTrackingGeometry
virtual std::unique_ptr< TrajectoryFitter > clone() const =0
edm::ESHandle< Propagator > thePropagator
unsigned long long theCacheId_MG
TransientTrackingRecHit::ConstRecHitContainer getTransientRecHits(const reco::TransientTrack &track) const
const SurfaceType & surface() const
edm::ESHandle< TransientTrackingRecHitBuilder > theMuonRecHitBuilder
std::unique_ptr< TrajectoryFitter > theFitter
unsigned long long theCacheId_TC
const std::string thePropagatorName
const std::string theFitterName
edm::ESHandle< MagneticField > theMGField
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:94
unsigned long long theCacheId_GTG
TrajectoryStateOnSurface outermostMeasurementState() const
edm::ESHandle< Propagator > const & propagator() const
std::vector< Trajectory > transform(const reco::Track &) const override
Convert a reco::Track into Trajectory.
edm::ESHandle< TransientTrackingRecHitBuilder > theTrackerRecHitBuilder
#define LogTrace(id)
const std::string theMuonRecHitBuilderName
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
trackingRecHit_iterator recHitsEnd() const
last iterator to RecHits
std::vector< ConstRecHitPointer > ConstRecHitContainer
TkClonerImpl hitCloner
Definition: DetId.h:18
const Track & track() const
const std::string theSmootherName
const T & get() const
Definition: EventSetup.h:59
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:53
const bool theDoPredictionsOnly
HLT enums.
GlobalVector globalMomentum() const
static int position[264][3]
Definition: ReadPGInfo.cc:509
const GeomDet * idToDet(DetId) const override
edm::ESHandle< GlobalTrackingGeometry > trackingGeometry() const
the tracking geometry
T x() const
Definition: PV3DBase.h:62
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:99
~TrackTransformer() override
Destructor.
T const * product() const
Definition: ESHandle.h:86
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:50
trackingRecHit_iterator recHitsBegin() const
first iterator to RecHits
std::unique_ptr< TrajectorySmoother > theSmoother
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
TrackTransformer(const edm::ParameterSet &)
Constructor.