CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
31  // Refit direction
32  string refitDirectionName = parameterSet.getParameter<string>("RefitDirection");
33  theRefitDirection = RefitDirection(refitDirectionName);
34 
35  theFitterName = parameterSet.getParameter<string>("Fitter");
36  theSmootherName = parameterSet.getParameter<string>("Smoother");
37  thePropagatorName = parameterSet.getParameter<string>("Propagator");
38 
39  theTrackerRecHitBuilderName = parameterSet.getParameter<string>("TrackerRecHitBuilder");
40  theMuonRecHitBuilderName = parameterSet.getParameter<string>("MuonRecHitBuilder");
41 
42  theRPCInTheFit = parameterSet.getParameter<bool>("RefitRPCHits");
43  theDoPredictionsOnly = parameterSet.getParameter<bool>("DoPredictionsOnly");
44 
45  theCacheId_TC = theCacheId_GTG = theCacheId_MG = theCacheId_TRH = 0;
46 }
47 
50 
51 
53 
54  const std::string metname = "Reco|TrackingTools|TrackTransformer";
55 
56  setup.get<TrajectoryFitter::Record>().get(theFitterName,theFitter);
57  setup.get<TrajectoryFitter::Record>().get(theSmootherName,theSmoother);
58 
59 
60  unsigned long long newCacheId_TC = setup.get<TrackingComponentsRecord>().cacheIdentifier();
61 
62  if ( newCacheId_TC != theCacheId_TC ){
63  LogTrace(metname) << "Tracking Component changed!";
64  theCacheId_TC = newCacheId_TC;
65  setup.get<TrackingComponentsRecord>().get(thePropagatorName,thePropagator);
66  }
67 
68  // Global Tracking Geometry
69  unsigned long long newCacheId_GTG = setup.get<GlobalTrackingGeometryRecord>().cacheIdentifier();
70  if ( newCacheId_GTG != theCacheId_GTG ) {
71  LogTrace(metname) << "GlobalTrackingGeometry changed!";
72  theCacheId_GTG = newCacheId_GTG;
73  setup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
74  }
75 
76  // Magfield Field
77  unsigned long long newCacheId_MG = setup.get<IdealMagneticFieldRecord>().cacheIdentifier();
78  if ( newCacheId_MG != theCacheId_MG ) {
79  LogTrace(metname) << "Magnetic Field changed!";
80  theCacheId_MG = newCacheId_MG;
81  setup.get<IdealMagneticFieldRecord>().get(theMGField);
82  }
83 
84  // Transient Rechit Builders
85  unsigned long long newCacheId_TRH = setup.get<TransientRecHitRecord>().cacheIdentifier();
86  if ( newCacheId_TRH != theCacheId_TRH ) {
87  theCacheId_TRH = newCacheId_TRH;
88  LogTrace(metname) << "TransientRecHitRecord changed!";
89  setup.get<TransientRecHitRecord>().get(theTrackerRecHitBuilderName,theTrackerRecHitBuilder);
90  setup.get<TransientRecHitRecord>().get(theMuonRecHitBuilderName,theMuonRecHitBuilder);
91  }
92 }
93 
94 
95 vector<Trajectory> TrackTransformer::transform(const reco::TrackRef& track) const {
96  return transform(*track);
97 }
98 
99 
102 
104 
105  for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit) {
106  if((*hit)->isValid()) {
107  if ( (*hit)->geographicalId().det() == DetId::Tracker ) {
108  result.push_back(theTrackerRecHitBuilder->build(&**hit));
109  } else if ( (*hit)->geographicalId().det() == DetId::Muon ){
110  if( (*hit)->geographicalId().subdetId() == 3 && !theRPCInTheFit){
111  LogTrace("Reco|TrackingTools|TrackTransformer") << "RPC Rec Hit discarged";
112  continue;
113  }
114  result.push_back(theMuonRecHitBuilder->build(&**hit));
115  }
116  }
117  }
118 
119  return result;
120 }
121 
122 // FIXME: check this method!
125 
126  if (!recHits.empty()){
127  GlobalPoint first = trackingGeometry()->idToDet(recHits.front()->geographicalId())->position();
128  GlobalPoint last = trackingGeometry()->idToDet(recHits.back()->geographicalId())->position();
129 
130  double rFirst = first.mag();
131  double rLast = last.mag();
132  if(rFirst < rLast) return RefitDirection::insideOut;
133  else if(rFirst > rLast) return RefitDirection::outsideIn;
134  else{
135  LogDebug("Reco|TrackingTools|TrackTransformer") << "Impossible to determine the rechits order" <<endl;
137  }
138  }
139  else{
140  LogDebug("Reco|TrackingTools|TrackTransformer") << "Impossible to determine the rechits order" <<endl;
142  }
143 }
144 
145 // void reorder(TransientTrackingRecHit::ConstRecHitContainer& recHits, RefitDirection::GeometricalDirection recHitsOrder) const{
146 
147 // if(theRefitDirection.geometricalDirection() != recHitsOrder) reverse(recHits.begin(),recHits.end());
148 
149 // if(theRefitDirection.geometricalDirection() == RefitDirection::insideOut &&recHitsOrder){}
150 // else if(theRefitDirection.geometricalDirection() == RefitDirection::outsideIn){}
151 // else LogWarning("Reco|TrackingTools|TrackTransformer") << "Impossible to determine the rechits order" <<endl;
152 // }
153 
154 
156 vector<Trajectory> TrackTransformer::transform(const reco::Track& newTrack) const {
157 
158  const std::string metname = "Reco|TrackingTools|TrackTransformer";
159 
160  reco::TransientTrack track(newTrack,magneticField(),trackingGeometry());
161 
162  // Build the transient Rechits
163  TransientTrackingRecHit::ConstRecHitContainer recHitsForReFit = getTransientRecHits(track);
164 
165  return transform(track, recHitsForReFit);
166 }
167 
168 
170 vector<Trajectory> TrackTransformer::transform(const reco::TransientTrack& track,
171  const TransientTrackingRecHit::ConstRecHitContainer& _recHitsForReFit) const {
172 
173  TransientTrackingRecHit::ConstRecHitContainer recHitsForReFit = _recHitsForReFit;
174  const std::string metname = "Reco|TrackingTools|TrackTransformer";
175 
176  if(recHitsForReFit.size() < 2) return vector<Trajectory>();
177 
178  // 8 cases are foreseen:
179  // [RH = rec hit order, P = momentum dir, FD = fit direction. IO/OI = inside-out/outside-in, AM/OM = along momentum/opposite to momentum]
180  // (1) RH IO | P IO | FD AM ---> Start from IN
181  // (2) RH IO | P IO | FD OM ---> Reverse RH and start from OUT
182  // (3) RH IO | P OI | FD AM ---> Reverse RH and start from IN
183  // (4) RH IO | P OI | FD OM ---> Start from OUT
184  // (5) RH OI | P IO | FD AM ---> Reverse RH and start from IN
185  // (6) RH OI | P IO | FD OM ---> Start from OUT
186  // (7) RH OI | P OI | FD AM ---> Start from IN
187  // (8) RH OI | P OI | FD OM ---> Reverse RH and start from OUT
188  //
189  // *** Rules: ***
190  // -A- If RH-FD agree (IO-AM,OI-OM) do not reverse the RH
191  // -B- If FD along momentum start from innermost state, otherwise use outermost
192 
193  // Other special cases can be handled:
194  // (1 bis) RH IO | P IO | GFD IO => FD AM ---> Start from IN
195  // (2 bis) RH IO | P IO | GFD OI => FD OM ---> Reverse RH and start from OUT
196  // (3 bis) RH IO | P OI | GFD OI => FD AM ---> Reverse RH and start from OUT
197  // (4 bis) RH IO | P OI | GFD IO => FD OM ---> Start from IN
198  // (5 bis) RH OI | P IO | GFD IO => FD AM ---> Reverse RH and start from IN
199  // (6 bis) RH OI | P IO | GFD OI => FD OM ---> Start from OUT
200  // (7 bis) RH OI | P OI | GFD OI => FD AM ---> Start from OUT
201  // (8 bis) RH OI | P OI | GFD IO => FD OM ---> Reverse RH and start from IN
202  //
203  // *** Additional rule: ***
204  // -A0- If P and GFD agree, then FD is AM otherwise is OM
205  // -A00- rechit must be ordered as GFD in order to handle the case of cosmics
206  // -B0- The starting state is decided by GFD
207 
208  // Determine the RH order
209  RefitDirection::GeometricalDirection recHitsOrder = checkRecHitsOrdering(recHitsForReFit); // FIXME change nome of the *type* --> RecHit order!
210  LogTrace(metname) << "RH order (0-insideOut, 1-outsideIn): " << recHitsOrder;
211 
212  PropagationDirection propagationDirection = theRefitDirection.propagationDirection();
213 
214  // Apply rule -A0-
215  if(propagationDirection == anyDirection){
218  RefitDirection::GeometricalDirection p = (momentum.x()*position.x() > 0 || momentum.y()*position.y() > 0) ? RefitDirection::insideOut : RefitDirection::outsideIn;
219 
220  propagationDirection = p == theRefitDirection.geometricalDirection() ? alongMomentum : oppositeToMomentum;
221  LogTrace(metname) << "P (0-insideOut, 1-outsideIn): " << p;
222  LogTrace(metname) << "FD (0-OM, 1-AM, 2-ANY): " << propagationDirection;
223  }
224  // -A0-
225 
226  // Apply rule -A-
227  if(theRefitDirection.propagationDirection() != anyDirection){
228  if((recHitsOrder == RefitDirection::insideOut && propagationDirection == oppositeToMomentum) ||
229  (recHitsOrder == RefitDirection::outsideIn && propagationDirection == alongMomentum) )
230  reverse(recHitsForReFit.begin(),recHitsForReFit.end());}
231  // -A-
232  // Apply rule -A00-
233  else{
234  // reorder the rechit as defined in theRefitDirection.geometricalDirection();
235  if(theRefitDirection.geometricalDirection() != recHitsOrder) reverse(recHitsForReFit.begin(),recHitsForReFit.end());
236  }
237  // -A00-
238 
239  // Apply rule -B-
241  unsigned int innerId = track.track().innerDetId();
242  if(theRefitDirection.propagationDirection() != anyDirection){
243  if(propagationDirection == oppositeToMomentum){
244  innerId = track.track().outerDetId();
245  firstTSOS = track.outermostMeasurementState();
246  }
247  }
248  else { // if(theRefitDirection.propagationDirection() == anyDirection)
249  // Apply rule -B0-
250  if(theRefitDirection.geometricalDirection() == RefitDirection::outsideIn){
251  innerId = track.track().outerDetId();
252  firstTSOS = track.outermostMeasurementState();
253  }
254  // -B0-
255  }
256  // -B-
257 
258  if(!firstTSOS.isValid()){
259  LogTrace(metname)<<"Error wrong initial state!"<<endl;
260  return vector<Trajectory>();
261  }
262 
264 
265  if(recHitsForReFit.front()->geographicalId() != DetId(innerId)){
266  LogTrace(metname)<<"Propagation occured"<<endl;
267  firstTSOS = propagator()->propagate(firstTSOS, recHitsForReFit.front()->det()->surface());
268  if(!firstTSOS.isValid()){
269  LogTrace(metname)<<"Propagation error!"<<endl;
270  return vector<Trajectory>();
271  }
272  }
273 
274  if(theDoPredictionsOnly){
275  Trajectory aTraj(seed,propagationDirection);
276  TrajectoryStateOnSurface predTSOS = firstTSOS;
277  for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihit = recHitsForReFit.begin();
278  ihit != recHitsForReFit.end(); ++ihit ) {
279  predTSOS = propagator()->propagate(predTSOS, (*ihit)->det()->surface());
280  if (predTSOS.isValid()) aTraj.push(TrajectoryMeasurement(predTSOS, *ihit));
281  }
282  return vector<Trajectory>(1, aTraj);
283  }
284 
285 
286  vector<Trajectory> trajectories = theFitter->fit(seed,recHitsForReFit,firstTSOS);
287 
288  if(trajectories.empty()){
289  LogTrace(metname)<<"No Track refitted!"<<endl;
290  return vector<Trajectory>();
291  }
292 
293  Trajectory trajectoryBW = trajectories.front();
294 
295  vector<Trajectory> trajectoriesSM = theSmoother->trajectories(trajectoryBW);
296 
297  if(trajectoriesSM.empty()){
298  LogTrace(metname)<<"No Track smoothed!"<<endl;
299  return vector<Trajectory>();
300  }
301 
302  return trajectoriesSM;
303 
304 }
305 
306 
#define LogDebug(id)
T getParameter(std::string const &) const
RefitDirection::GeometricalDirection checkRecHitsOrdering(TransientTrackingRecHit::ConstRecHitContainer &) const
const std::string metname
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
T y() const
Definition: PV3DBase.h:63
GlobalPoint globalPosition() const
PropagationDirection
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
TrajectoryStateOnSurface innermostMeasurementState() const
TransientTrackingRecHit::ConstRecHitContainer getTransientRecHits(const reco::TransientTrack &track) const
const SurfaceType & surface() const
T mag() const
Definition: PV3DBase.h:67
tuple result
Definition: query.py:137
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:59
virtual void setServices(const edm::EventSetup &)
set the services needed by the TrackTransformer
TrajectoryStateOnSurface outermostMeasurementState() const
bool first
Definition: L1TdeRCT.cc:94
#define LogTrace(id)
trackingRecHit_iterator recHitsEnd() const
last iterator to RecHits
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: DetId.h:20
const Track & track() const
const T & get() const
Definition: EventSetup.h:55
GlobalVector globalMomentum() const
virtual std::vector< Trajectory > transform(const reco::Track &) const
Convert a reco::Track into Trajectory.
virtual ~TrackTransformer()
Destructor.
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:61
void push(const TrajectoryMeasurement &tm)
Definition: Trajectory.cc:35
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
trackingRecHit_iterator recHitsBegin() const
first iterator to RecHits
TrackTransformer(const edm::ParameterSet &)
Constructor.