CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackTransformerForCosmicMuons.cc
Go to the documentation of this file.
2 
6 
9 
13 
20 
24 
25 
30 
31 
32 using namespace std;
33 using namespace edm;
34 
37 
38  theTrackerRecHitBuilderName = parameterSet.getParameter<string>("TrackerRecHitBuilder");
39  theMuonRecHitBuilderName = parameterSet.getParameter<string>("MuonRecHitBuilder");
40 
41  theRPCInTheFit = parameterSet.getParameter<bool>("RefitRPCHits");
42 
43  theCacheId_TC = theCacheId_GTG = theCacheId_MG = theCacheId_TRH = 0;
44 }
45 
48 
49 
51 
52  const std::string metname = "Reco|TrackingTools|TrackTransformer";
53 
54  setup.get<TrajectoryFitter::Record>().get("KFFitterForRefitInsideOut",theFitterIO);
55  setup.get<TrajectoryFitter::Record>().get("KFSmootherForRefitInsideOut",theSmootherIO);
56  setup.get<TrajectoryFitter::Record>().get("KFFitterForRefitOutsideIn",theFitterOI);
57  setup.get<TrajectoryFitter::Record>().get("KFSmootherForRefitOutsideIn",theSmootherOI);
58 
59  unsigned long long newCacheId_TC = setup.get<TrackingComponentsRecord>().cacheIdentifier();
60 
61  if ( newCacheId_TC != theCacheId_TC ){
62  LogTrace(metname) << "Tracking Component changed!";
63  theCacheId_TC = newCacheId_TC;
64  setup.get<TrackingComponentsRecord>().get("SmartPropagatorRK",thePropagatorIO);
65  setup.get<TrackingComponentsRecord>().get("SmartPropagatorRKOpposite",thePropagatorOI);
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 
97 
100 
101  bool printout = false;
102 
103  bool quad1 = false;
104  bool quad2 = false;
105  bool quad3 = false;
106  bool quad4 = false;
107 
108  for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit)
109  if((*hit)->isValid())
110  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  staHits.push_back(theMuonRecHitBuilder->build(&**hit));
116  DetId hitId = staHits.back()->geographicalId();
117  GlobalPoint glbpoint = trackingGeometry()->idToDet(hitId)->position();
118  float gpy=glbpoint.y();
119  float gpz=glbpoint.z();
120 // if (gpy != 0 && gpz !=0) slopeSum += gpy / gpz;
121 
122  if (gpy > 0 && gpz > 0) quad1 = true;
123  else if (gpy > 0 && gpz < 0) quad2 = true;
124  else if (gpy < 0 && gpz < 0) quad3 = true;
125  else if (gpy < 0 && gpz > 0) quad4 = true;
126  else return tkHits;
127  }
128 
129  if(staHits.empty()) return staHits;
130 
131  if (quad1 && quad2) return tkHits;
132  if (quad1 && quad3) return tkHits;
133  if (quad1 && quad4) return tkHits;
134  if (quad2 && quad3) return tkHits;
135  if (quad2 && quad4) return tkHits;
136  if (quad3 && quad4) return tkHits;
137 
138 
139  bool doReverse = staHits.front()->globalPosition().y()>0 ? true : false;
140 
141  if (quad1) doReverse = SlopeSum(staHits);
142  if (quad2) doReverse = SlopeSum(staHits);
143  if (quad3) doReverse = SlopeSum(staHits);
144  if (quad4) doReverse = SlopeSum(staHits);
145  if(doReverse){
146  reverse(staHits.begin(),staHits.end());
147  }
148 
149  copy(staHits.begin(),staHits.end(),back_inserter(tkHits));
150 
151 
153 // if ( quad2 && slopeSum > 0) printout = true;
156 // swap = printout;
157 
158  printout = quad1;
159 
160  if (printout) for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator hit = tkHits.begin();
161  hit !=tkHits.end(); ++hit){
162 
163  DetId hitId = (*hit)->geographicalId();
164  GlobalPoint glbpoint = trackingGeometry()->idToDet(hitId)->position();
165 
166 
167  if(hitId.det() == DetId::Muon) {
168  if(hitId.subdetId() == MuonSubdetId::DT)
169  LogTrace("TrackFitters") << glbpoint << " I am DT " << DTWireId(hitId);
170 // std::cout<< glbpoint << " I am DT " << DTWireId(hitId)<<std::endl;
171  else if (hitId.subdetId() == MuonSubdetId::CSC )
172  LogTrace("TrackFitters") << glbpoint << " I am CSC " << CSCDetId(hitId);
173 // std::cout<< glbpoint << " I am CSC " << CSCDetId(hitId)<<std::endl;
174  else if (hitId.subdetId() == MuonSubdetId::RPC )
175  LogTrace("TrackFitters") << glbpoint << " I am RPC " << RPCDetId(hitId);
176  else
177  LogTrace("TrackFitters") << " UNKNOWN MUON HIT TYPE ";
178  }
179  }
180  return tkHits;
181 }
182 
183 
186  if(quad ==1) {if (sumy < 0) return theFitterOI; else return theFitterIO;}
187  if(quad ==2) {if (sumy < 0) return theFitterOI; else return theFitterIO;}
188  if(quad ==3) {if (sumy > 0) return theFitterOI; else return theFitterIO;}
189  if(quad ==4) {if (sumy > 0) return theFitterOI; else return theFitterIO;}
190 
191  if(up) return theFitterOI;
192  else return theFitterIO;
193 }
194 
197  if(quad ==1){ if (sumy < 0) return theSmootherOI; else return theSmootherIO;}
198  if(quad ==2){ if (sumy < 0) return theSmootherOI; else return theSmootherIO;}
199  if(quad ==3){ if (sumy > 0) return theSmootherOI; else return theSmootherIO;}
200  if(quad ==4){ if (sumy > 0) return theSmootherOI; else return theSmootherIO;}
201  if(up) return theSmootherOI;
202  else return theSmootherIO;
203 }
204 
206  if(quad ==1) {if (sumy > 0) return thePropagatorOI; else return thePropagatorIO;}
207  if(quad ==2) {if (sumy > 0) return thePropagatorOI; else return thePropagatorIO;}
208  if(quad ==3) {if (sumy < 0) return thePropagatorOI; else return thePropagatorIO;}
209  if(quad ==4) {if (sumy < 0) return thePropagatorOI; else return thePropagatorIO;}
210  if(up) return thePropagatorIO;
211  else return thePropagatorOI;
212 }
213 
214 
215 
217 vector<Trajectory> TrackTransformerForCosmicMuons::transform(const reco::Track& tr) const {
218 
219  const std::string metname = "Reco|TrackingTools|TrackTransformer";
220 
221  reco::TransientTrack track(tr,magneticField(),trackingGeometry());
222 
223  // Build the transient Rechits
224  TransientTrackingRecHit::ConstRecHitContainer recHitsForReFit;// = getTransientRecHits(track);
226 
227 
228  bool quad1 = false;
229  bool quad2 = false;
230  bool quad3 = false;
231  bool quad4 = false;
232  int quadrant = 0;
233 
234  for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit)
235  if((*hit)->isValid())
236  if ( (*hit)->geographicalId().det() == DetId::Muon ){
237  if( (*hit)->geographicalId().subdetId() == 3 && !theRPCInTheFit){
238  LogTrace("Reco|TrackingTools|TrackTransformer") << "RPC Rec Hit discarged";
239  continue;
240  }
241  staHits.push_back(theMuonRecHitBuilder->build(&**hit));
242  DetId hitId = staHits.back()->geographicalId();
243  GlobalPoint glbpoint = trackingGeometry()->idToDet(hitId)->position();
244  float gpy=glbpoint.y();
245  float gpz=glbpoint.z();
246 // if (gpy != 0 && gpz !=0) slopeSum += gpy / gpz;
247 
248  if (gpy > 0 && gpz > 0) {quad1 = true; quadrant = 1;}
249  else if (gpy > 0 && gpz < 0){quad2 = true; quadrant = 2;}
250  else if (gpy < 0 && gpz < 0){quad3 = true; quadrant = 3;}
251  else if (gpy < 0 && gpz > 0){quad4 = true; quadrant = 4;}
252  else return vector<Trajectory>();
253  }
254 
255 
256  if(staHits.empty()) return vector<Trajectory>();
257 
258  if (quad1 && quad2) return vector<Trajectory>();
259  if (quad1 && quad3) return vector<Trajectory>();
260  if (quad1 && quad4) return vector<Trajectory>();
261  if (quad2 && quad3) return vector<Trajectory>();
262  if (quad2 && quad4) return vector<Trajectory>();
263  if (quad3 && quad4) return vector<Trajectory>();
264 
265  bool doReverse = false;
266 
267  if (quad1) doReverse = SlopeSum(staHits);
268  if (quad2) doReverse = SlopeSum(staHits);
269  if (quad3) doReverse = SlopeSum(staHits);
270  if (quad4) doReverse = SlopeSum(staHits);
271 
272 
273  if(doReverse){
274  reverse(staHits.begin(),staHits.end());
275  }
276 
277  copy(staHits.begin(),staHits.end(),back_inserter(recHitsForReFit));
278 
284 
285 
286  if(recHitsForReFit.size() < 2) return vector<Trajectory>();
287 
288  bool up = recHitsForReFit.back()->globalPosition().y()>0 ? true : false;
289  LogTrace(metname) << "Up ? " << up;
290 
291  float sumdy = SumDy(recHitsForReFit);
292 
293 
294  PropagationDirection propagationDirection = doReverse ? oppositeToMomentum : alongMomentum;
295  TrajectoryStateOnSurface firstTSOS = doReverse ? track.outermostMeasurementState() : track.innermostMeasurementState();
296  unsigned int innerId = doReverse ? track.track().outerDetId() : track.track().innerDetId();
297 
298  LogTrace(metname) << "Prop Dir: " << propagationDirection << " FirstId " << innerId << " firstTSOS " << firstTSOS;
299 
301 
302 
303  if(recHitsForReFit.front()->geographicalId() != DetId(innerId)){
304  LogTrace(metname)<<"Propagation occurring"<<endl;
305  firstTSOS = propagator(up, quadrant, sumdy)->propagate(firstTSOS, recHitsForReFit.front()->det()->surface());
306  LogTrace(metname)<<"Final destination: " << recHitsForReFit.front()->det()->surface().position() << endl;
307  if(!firstTSOS.isValid()){
308  std::cout<<"Propagation error! Dumping RecHits..."<<std::endl;
309 
310  for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator hit = recHitsForReFit.begin();
311  hit !=recHitsForReFit.end(); ++hit){
312 
313  DetId hitId = (*hit)->geographicalId();
314  GlobalPoint glbpoint = trackingGeometry()->idToDet(hitId)->position();
315  if(hitId.subdetId() == MuonSubdetId::DT)
316  std::cout<< glbpoint << " I am DT " << DTWireId(hitId)<<std::endl;
317  else if (hitId.subdetId() == MuonSubdetId::CSC )
318  std::cout<< glbpoint << " I am CSC " << CSCDetId(hitId)<<std::endl;
319  }
320 
321 
322  LogTrace(metname)<<"Propagation error!"<<endl;
323  return vector<Trajectory>();
324  }
325  }
326 
327 
328  vector<Trajectory> && trajectories = fitter(up, quadrant, sumdy)->fit(seed,recHitsForReFit,firstTSOS);
329 
330  if(trajectories.empty()){
331  LogTrace(metname)<<"No Track refitted!"<<endl;
332  return vector<Trajectory>();
333  }
334 
335  Trajectory const & trajectoryBW = trajectories.front();
336 
337  vector<Trajectory> && trajectoriesSM = smoother(up, quadrant, sumdy)->trajectories(trajectoryBW);
338 
339  if(trajectoriesSM.empty()){
340  LogTrace(metname)<<"No Track smoothed!"<<endl;
341  return vector<Trajectory>();
342  }
343 
344  return trajectoriesSM;
345 
346 }
347 
348 
349 
352 
353  bool retval = false;
354  float y1 = 0 ;
355  float z1 = 0 ;
356 
357  bool first = true;
358 
359  std::vector<float> py;
360  std::vector<float> pz;
361 // int quadrant = -1;
362 
363  float sumdy = 0;
364  float sumdz = 0;
365 
366  for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator hit = tkHits.begin();
367  hit !=tkHits.end(); ++hit){
368 
369  DetId hitId = (*hit)->geographicalId();
370  GlobalPoint glbpoint = trackingGeometry()->idToDet(hitId)->position();
371  if ( hitId.det() != DetId::Muon || hitId.subdetId() == 3 )continue;
372 
373  float y2 = glbpoint.y();
374  float z2 = glbpoint.z();
375  float dslope = 0;
376  float dy = y2 - y1;
377  float dz = z2 - z1;
378 
379 // if (y2 > 0 && z2 > 0) quadrant = 1;
380 // else if (y2 > 0 && z2 < 0) quadrant = 2;
381 // else if (y2 < 0 && z2 < 0) quadrant = 3;
382 // else if (y2 < 0 && z2 > 0) quadrant = 4;
383 
384 
385  if (fabs(dz) > 1e-3) dslope = dy / dz;
386  if ( !first) {
387  retval+=dslope;
388  sumdy +=dy;
389  sumdz +=dz;
390  }
391  first = false;
392  py.push_back(y1);
393  pz.push_back(z1);
394  y1 = y2;
395  z1 = z2;
396  }
397 // std::cout<<"quadrant "<<quadrant;
398 // std::cout<<"\tsum dy = "<<sumdy;
399 // std::cout<<"\tsum dz = "<<sumdz;
400 // std::cout<<std::endl;
401 
402 
403  if ( sumdz < 0) retval = true;
404 
405  return retval;
406 
407 }
408 
409 
412 
413  bool retval = false;
414  float y1 = 0 ;
415  float z1 = 0 ;
416 
417  bool first = true;
418 
419  std::vector<float> py;
420  std::vector<float> pz;
421 // int quadrant = -1;
422 
423  float sumdy = 0;
424  float sumdz = 0;
425 
426 
427 
428  for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator hit = tkHits.begin();
429  hit !=tkHits.end(); ++hit){
430 
431  DetId hitId = (*hit)->geographicalId();
432  GlobalPoint glbpoint = trackingGeometry()->idToDet(hitId)->position();
433  if ( hitId.det() != DetId::Muon || hitId.subdetId() == 3 )continue;
434 
435  float y2 = glbpoint.y();
436  float z2 = glbpoint.z();
437  float dslope = 0;
438  float dy = y2 - y1;
439  float dz = z2 - z1;
440 
441 // if (y2 > 0 && z2 > 0) quadrant = 1;
442 // else if (y2 > 0 && z2 < 0) quadrant = 2;
443 // else if (y2 < 0 && z2 < 0) quadrant = 3;
444 // else if (y2 < 0 && z2 > 0) quadrant = 4;
445 
446 
447  if (fabs(dz) > 1e-3) dslope = dy / dz;
448  if ( !first) {
449  retval+=dslope;
450  sumdy +=dy;
451  sumdz +=dz;
452  }
453  first = false;
454  py.push_back(y1);
455  pz.push_back(z1);
456  y1 = y2;
457  z1 = z2;
458  }
459 // std::cout<<"quadrant "<<quadrant;
460 // std::cout<<"\tsum dy = "<<sumdy;
461 // std::cout<<"\tsum dz = "<<sumdz;
462 // std::cout<<std::endl;
463 
464  return sumdy;
465 }
466 
Definition: BitonicSort.h:8
T getParameter(std::string const &) const
edm::ESHandle< Propagator > propagator(bool, int, float) const
const std::string metname
virtual void setServices(const edm::EventSetup &)
set the services needed by the TrackTransformer
T y() const
Definition: PV3DBase.h:63
TrackTransformerForCosmicMuons(const edm::ParameterSet &)
Constructor.
PropagationDirection
edm::ESHandle< TrajectoryFitter > fitter(bool, int, float) const
the refitter used to refit the reco::Track
TrajectoryStateOnSurface innermostMeasurementState() const
float SumDy(const TransientTrackingRecHit::ConstRecHitContainer &) const
decide if the track should be reversed
virtual std::vector< Trajectory > transform(const reco::Track &) const
Convert a reco::Track into Trajectory.
static const int CSC
Definition: MuonSubdetId.h:13
T z() const
Definition: PV3DBase.h:64
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:94
bool SlopeSum(const TransientTrackingRecHit::ConstRecHitContainer &) const
calculate the sum of slopes for the track
TrajectoryStateOnSurface outermostMeasurementState() const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
#define LogTrace(id)
trackingRecHit_iterator recHitsEnd() const
last iterator to RecHits
std::vector< ConstRecHitPointer > ConstRecHitContainer
Definition: DetId.h:18
const Track & track() const
const T & get() const
Definition: EventSetup.h:56
edm::ESHandle< TrajectorySmoother > smoother(bool, int, float) const
the smoother used to smooth the trajectory which came from the refitting step
static const int RPC
Definition: MuonSubdetId.h:14
tuple cout
Definition: gather_cfg.py:145
static const int DT
Definition: MuonSubdetId.h:12
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:99
trackingRecHit_iterator recHitsBegin() const
first iterator to RecHits
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
TransientTrackingRecHit::ConstRecHitContainer getTransientRecHits(const reco::TransientTrack &track) const