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  TransientTrackingRecHit::ConstRecHitContainer recHitsForReFit) const {
172 
173  const std::string metname = "Reco|TrackingTools|TrackTransformer";
174 
175  if(recHitsForReFit.size() < 2) return vector<Trajectory>();
176 
177  // 8 cases are foreseen:
178  // [RH = rec hit order, P = momentum dir, FD = fit direction. IO/OI = inside-out/outside-in, AM/OM = along momentum/opposite to momentum]
179  // (1) RH IO | P IO | FD AM ---> Start from IN
180  // (2) RH IO | P IO | FD OM ---> Reverse RH and start from OUT
181  // (3) RH IO | P OI | FD AM ---> Reverse RH and start from IN
182  // (4) RH IO | P OI | FD OM ---> Start from OUT
183  // (5) RH OI | P IO | FD AM ---> Reverse RH and start from IN
184  // (6) RH OI | P IO | FD OM ---> Start from OUT
185  // (7) RH OI | P OI | FD AM ---> Start from IN
186  // (8) RH OI | P OI | FD OM ---> Reverse RH and start from OUT
187  //
188  // *** Rules: ***
189  // -A- If RH-FD agree (IO-AM,OI-OM) do not reverse the RH
190  // -B- If FD along momentum start from innermost state, otherwise use outermost
191 
192  // Other special cases can be handled:
193  // (1 bis) RH IO | P IO | GFD IO => FD AM ---> Start from IN
194  // (2 bis) RH IO | P IO | GFD OI => FD OM ---> Reverse RH and start from OUT
195  // (3 bis) RH IO | P OI | GFD OI => FD AM ---> Reverse RH and start from OUT
196  // (4 bis) RH IO | P OI | GFD IO => FD OM ---> Start from IN
197  // (5 bis) RH OI | P IO | GFD IO => FD AM ---> Reverse RH and start from IN
198  // (6 bis) RH OI | P IO | GFD OI => FD OM ---> Start from OUT
199  // (7 bis) RH OI | P OI | GFD OI => FD AM ---> Start from OUT
200  // (8 bis) RH OI | P OI | GFD IO => FD OM ---> Reverse RH and start from IN
201  //
202  // *** Additional rule: ***
203  // -A0- If P and GFD agree, then FD is AM otherwise is OM
204  // -A00- rechit must be ordered as GFD in order to handle the case of cosmics
205  // -B0- The starting state is decided by GFD
206 
207  // Determine the RH order
208  RefitDirection::GeometricalDirection recHitsOrder = checkRecHitsOrdering(recHitsForReFit); // FIXME change nome of the *type* --> RecHit order!
209  LogTrace(metname) << "RH order (0-insideOut, 1-outsideIn): " << recHitsOrder;
210 
211  PropagationDirection propagationDirection = theRefitDirection.propagationDirection();
212 
213  // Apply rule -A0-
214  if(propagationDirection == anyDirection){
217  RefitDirection::GeometricalDirection p = (momentum.x()*position.x() > 0 || momentum.y()*position.y() > 0) ? RefitDirection::insideOut : RefitDirection::outsideIn;
218 
219  propagationDirection = p == theRefitDirection.geometricalDirection() ? alongMomentum : oppositeToMomentum;
220  LogTrace(metname) << "P (0-insideOut, 1-outsideIn): " << p;
221  LogTrace(metname) << "FD (0-OM, 1-AM, 2-ANY): " << propagationDirection;
222  }
223  // -A0-
224 
225  // Apply rule -A-
226  if(theRefitDirection.propagationDirection() != anyDirection){
227  if((recHitsOrder == RefitDirection::insideOut && propagationDirection == oppositeToMomentum) ||
228  (recHitsOrder == RefitDirection::outsideIn && propagationDirection == alongMomentum) )
229  reverse(recHitsForReFit.begin(),recHitsForReFit.end());}
230  // -A-
231  // Apply rule -A00-
232  else{
233  // reorder the rechit as defined in theRefitDirection.geometricalDirection();
234  if(theRefitDirection.geometricalDirection() != recHitsOrder) reverse(recHitsForReFit.begin(),recHitsForReFit.end());
235  }
236  // -A00-
237 
238  // Apply rule -B-
240  unsigned int innerId = track.track().innerDetId();
241  if(theRefitDirection.propagationDirection() != anyDirection){
242  if(propagationDirection == oppositeToMomentum){
243  innerId = track.track().outerDetId();
244  firstTSOS = track.outermostMeasurementState();
245  }
246  }
247  else { // if(theRefitDirection.propagationDirection() == anyDirection)
248  // Apply rule -B0-
249  if(theRefitDirection.geometricalDirection() == RefitDirection::outsideIn){
250  innerId = track.track().outerDetId();
251  firstTSOS = track.outermostMeasurementState();
252  }
253  // -B0-
254  }
255  // -B-
256 
257  if(!firstTSOS.isValid()){
258  LogTrace(metname)<<"Error wrong initial state!"<<endl;
259  return vector<Trajectory>();
260  }
261 
263 
264  if(recHitsForReFit.front()->geographicalId() != DetId(innerId)){
265  LogTrace(metname)<<"Propagation occured"<<endl;
266  firstTSOS = propagator()->propagate(firstTSOS, recHitsForReFit.front()->det()->surface());
267  if(!firstTSOS.isValid()){
268  LogTrace(metname)<<"Propagation error!"<<endl;
269  return vector<Trajectory>();
270  }
271  }
272 
273  if(theDoPredictionsOnly){
274  Trajectory aTraj(seed,propagationDirection);
275  TrajectoryStateOnSurface predTSOS = firstTSOS;
276  for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator ihit = recHitsForReFit.begin();
277  ihit != recHitsForReFit.end(); ++ihit ) {
278  predTSOS = propagator()->propagate(predTSOS, (*ihit)->det()->surface());
279  if (predTSOS.isValid()) aTraj.push(TrajectoryMeasurement(predTSOS, *ihit));
280  }
281  return vector<Trajectory>(1, aTraj);
282  }
283 
284 
285  vector<Trajectory> trajectories = theFitter->fit(seed,recHitsForReFit,firstTSOS);
286 
287  if(trajectories.empty()){
288  LogTrace(metname)<<"No Track refitted!"<<endl;
289  return vector<Trajectory>();
290  }
291 
292  Trajectory trajectoryBW = trajectories.front();
293 
294  vector<Trajectory> trajectoriesSM = theSmoother->trajectories(trajectoryBW);
295 
296  if(trajectoriesSM.empty()){
297  LogTrace(metname)<<"No Track smoothed!"<<endl;
298  return vector<Trajectory>();
299  }
300 
301  return trajectoriesSM;
302 
303 }
304 
305 
#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:62
GlobalPoint globalPosition() const
PropagationDirection
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
TrajectoryStateOnSurface innermostMeasurementState() const
TransientTrackingRecHit::ConstRecHitContainer getTransientRecHits(const reco::TransientTrack &track) const
T mag() const
Definition: PV3DBase.h:66
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.
const Surface & surface() const
T x() const
Definition: PV3DBase.h:61
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.