CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackTransformerForGlobalCosmicMuons.cc
Go to the documentation of this file.
2 
6 
9 
13 
20 
24 
25 
36 
37 
38 using namespace std;
39 using namespace edm;
40 
43 
44  theTrackerRecHitBuilderName = parameterSet.getParameter<string>("TrackerRecHitBuilder");
45  theMuonRecHitBuilderName = parameterSet.getParameter<string>("MuonRecHitBuilder");
46 
47  theRPCInTheFit = parameterSet.getParameter<bool>("RefitRPCHits");
48 
49  theCacheId_TC = theCacheId_GTG = theCacheId_MG = theCacheId_TRH = 0;
50  theSkipStationDT = parameterSet.getParameter<int>("SkipStationDT");
51  theSkipStationCSC = parameterSet.getParameter<int>("SkipStationCSC");
52  theSkipWheelDT = parameterSet.getParameter<int>("SkipWheelDT");
53  theTrackerSkipSystem = parameterSet.getParameter<int>("TrackerSkipSystem");
54  theTrackerSkipSection = parameterSet.getParameter<int>("TrackerSkipSection");//layer, wheel, or disk depending on the system
55 }
56 
59 
60 
62 
63  const std::string metname = "Reco|TrackingTools|TrackTransformer";
64 
65  setup.get<TrajectoryFitter::Record>().get("KFFitterForRefitInsideOut",theFitterIO);
66  setup.get<TrajectoryFitter::Record>().get("KFSmootherForRefitInsideOut",theSmootherIO);
67  setup.get<TrajectoryFitter::Record>().get("KFFitterForRefitOutsideIn",theFitterOI);
68  setup.get<TrajectoryFitter::Record>().get("KFSmootherForRefitOutsideIn",theSmootherOI);
69 
70  unsigned long long newCacheId_TC = setup.get<TrackingComponentsRecord>().cacheIdentifier();
71 
72  if ( newCacheId_TC != theCacheId_TC ){
73  LogTrace(metname) << "Tracking Component changed!";
74  theCacheId_TC = newCacheId_TC;
75  setup.get<TrackingComponentsRecord>().get("SmartPropagatorRK",thePropagatorIO);
76  setup.get<TrackingComponentsRecord>().get("SmartPropagatorRKOpposite",thePropagatorOI);
77 
78  }
79 
80  // Global Tracking Geometry
81  unsigned long long newCacheId_GTG = setup.get<GlobalTrackingGeometryRecord>().cacheIdentifier();
82  if ( newCacheId_GTG != theCacheId_GTG ) {
83  LogTrace(metname) << "GlobalTrackingGeometry changed!";
84  theCacheId_GTG = newCacheId_GTG;
85  setup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
86  }
87 
88  // Magfield Field
89  unsigned long long newCacheId_MG = setup.get<IdealMagneticFieldRecord>().cacheIdentifier();
90  if ( newCacheId_MG != theCacheId_MG ) {
91  LogTrace(metname) << "Magnetic Field changed!";
92  theCacheId_MG = newCacheId_MG;
93  setup.get<IdealMagneticFieldRecord>().get(theMGField);
94  }
95 
96  // Transient Rechit Builders
97  unsigned long long newCacheId_TRH = setup.get<TransientRecHitRecord>().cacheIdentifier();
98  if ( newCacheId_TRH != theCacheId_TRH ) {
99  theCacheId_TRH = newCacheId_TRH;
100  LogTrace(metname) << "TransientRecHitRecord changed!";
101  setup.get<TransientRecHitRecord>().get(theTrackerRecHitBuilderName,theTrackerRecHitBuilder);
102  setup.get<TransientRecHitRecord>().get(theMuonRecHitBuilderName,theMuonRecHitBuilder);
103  }
104 }
105 
106 
109 
112 
113  for (trackingRecHit_iterator hit = track.recHitsBegin(); hit != track.recHitsEnd(); ++hit) {
114  if((*hit)->isValid()) {
115  if ( (*hit)->geographicalId().det() == DetId::Tracker && TrackerKeep((*hit)->geographicalId())) {
116  tkHits.push_back(theTrackerRecHitBuilder->build(&**hit));
117  } else if ( (*hit)->geographicalId().det() == DetId::Muon && MuonKeep((*hit)->geographicalId())){
118  if( (*hit)->geographicalId().subdetId() == 3 && !theRPCInTheFit){
119  LogTrace("Reco|TrackingTools|TrackTransformer") << "RPC Rec Hit discarged";
120  continue;
121  }
122  staHits.push_back(theMuonRecHitBuilder->build(&**hit));
123  }
124  }
125  }
126 
127  if(staHits.empty()) return staHits;
128 
129 /*
130  bool up = staHits.front()->globalPosition().y()>0 ? true : false;
131 
132  if(up){
133  reverse(staHits.begin(),staHits.end());
134  reverse(tkHits.begin(),tkHits.end());
135  }
136 */
137  copy(staHits.begin(),staHits.end(),back_inserter(tkHits));
138 
139  for(TransientTrackingRecHit::ConstRecHitContainer::const_iterator hit = tkHits.begin();
140  hit !=tkHits.end(); ++hit){
141 
142  DetId hitId = (*hit)->geographicalId();
143  GlobalPoint glbpoint = trackingGeometry()->idToDet(hitId)->position();
144 
145  if(hitId.det() == DetId::Tracker) {
146  if (hitId.subdetId() == StripSubdetector::TIB )
147  LogTrace("TrackFitters") << glbpoint << " I am TIB " << TIBDetId(hitId).layer();
148  else if (hitId.subdetId() == StripSubdetector::TOB )
149  LogTrace("TrackFitters") << glbpoint << " I am TOB " << TOBDetId(hitId).layer();
150  else if (hitId.subdetId() == StripSubdetector::TEC )
151  LogTrace("TrackFitters") << glbpoint << " I am TEC " << TECDetId(hitId).wheel();
152  else if (hitId.subdetId() == StripSubdetector::TID )
153  LogTrace("TrackFitters") << glbpoint << " I am TID " << TIDDetId(hitId).wheel();
154  else if (hitId.subdetId() == StripSubdetector::TID )
155  LogTrace("TrackFitters") << glbpoint << " I am TID " << TIDDetId(hitId).wheel();
156  else if (hitId.subdetId() == (int) PixelSubdetector::PixelBarrel )
157  LogTrace("TrackFitters") << glbpoint << " I am PixBar " << PXBDetId(hitId).layer();
158  else if (hitId.subdetId() == (int) PixelSubdetector::PixelEndcap )
159  LogTrace("TrackFitters") << glbpoint << " I am PixFwd " << PXFDetId(hitId).disk();
160  else
161  LogTrace("TrackFitters") << " UNKNOWN TRACKER HIT TYPE ";
162  } else if(hitId.det() == DetId::Muon) {
163  if(hitId.subdetId() == MuonSubdetId::DT)
164  LogTrace("TrackFitters") << glbpoint << " I am DT " << DTWireId(hitId);
165  else if (hitId.subdetId() == MuonSubdetId::CSC )
166  LogTrace("TrackFitters") << glbpoint << " I am CSC " << CSCDetId(hitId);
167  else if (hitId.subdetId() == MuonSubdetId::RPC )
168  LogTrace("TrackFitters") << glbpoint << " I am RPC " << RPCDetId(hitId);
169  else
170  LogTrace("TrackFitters") << " UNKNOWN MUON HIT TYPE ";
171  } else
172  LogTrace("TrackFitters") << " UNKNOWN HIT TYPE ";
173  }
174 
175  return tkHits;
176 }
177 
178 
181  if(up) return theFitterOI;
182  else return theFitterIO;
183 }
184 
187  if(up) return theSmootherOI;
188  else return theSmootherIO;
189 }
190 
192  if(up) return thePropagatorIO;
193  else return thePropagatorOI;
194 }
195 
196 
197 
200 
201  const std::string metname = "Reco|TrackingTools|TrackTransformer";
202 
203  reco::TransientTrack track(tr,magneticField(),trackingGeometry());
204 
205  // Build the transient Rechits
206  TransientTrackingRecHit::ConstRecHitContainer recHitsForReFit = getTransientRecHits(track);
207 
208  if(recHitsForReFit.size() < 2) return vector<Trajectory>();
209 
210  bool up = recHitsForReFit.back()->globalPosition().y()>0 ? true : false;
211  LogTrace(metname) << "Up ? " << up;
212 
213  PropagationDirection propagationDirection = up ? oppositeToMomentum : alongMomentum;
215  unsigned int innerId = up ? track.track().outerDetId() : track.track().innerDetId();
216 
217  LogTrace(metname) << "Prop Dir: " << propagationDirection << " FirstId " << innerId << " firstTSOS " << firstTSOS;
218 
220 
221 
222  if(recHitsForReFit.front()->geographicalId() != DetId(innerId)){
223  LogTrace(metname)<<"Propagation occurring"<<endl;
224  firstTSOS = propagator(up)->propagate(firstTSOS, recHitsForReFit.front()->det()->surface());
225  LogTrace(metname)<<"Final destination: " << recHitsForReFit.front()->det()->surface().position() << endl;
226  if(!firstTSOS.isValid()){
227  LogTrace(metname)<<"Propagation error!"<<endl;
228  return vector<Trajectory>();
229  }
230  }
231 
232 
233  vector<Trajectory> trajectories = fitter(up)->fit(seed,recHitsForReFit,firstTSOS);
234 
235  if(trajectories.empty()){
236  LogTrace(metname)<<"No Track refitted!"<<endl;
237  return vector<Trajectory>();
238  }
239 
240  Trajectory trajectoryBW = trajectories.front();
241 
242  vector<Trajectory> trajectoriesSM = smoother(up)->trajectories(trajectoryBW);
243 
244  if(trajectoriesSM.empty()){
245  LogTrace(metname)<<"No Track smoothed!"<<endl;
246  return vector<Trajectory>();
247  }
248 
249  return trajectoriesSM;
250 
251 }
252 
253 //
254 // Selection for Tracker Hits
255 //
257 
258  bool retVal = true;
259  if (id.det() != DetId::Tracker ) return false;
260  if (theTrackerSkipSystem < 0 ) return true;
261 
262 
263  int layer = -999;
264  int disk = -999;
265  int wheel = -999;
266 
267  if ( id.subdetId() == theTrackerSkipSystem){
268 
269  if (theTrackerSkipSystem == PixelSubdetector::PixelBarrel) {
270  PXBDetId did(id.rawId());
271  layer = did.layer();
272  }
273 
274  if (theTrackerSkipSystem == StripSubdetector::TIB) {
275  TIBDetId did(id.rawId());
276  layer = did.layer();
277  }
278 
279  if (theTrackerSkipSystem == StripSubdetector::TOB) {
280  TOBDetId did(id.rawId());
281  layer = did.layer();
282  }
283  if (theTrackerSkipSystem == PixelSubdetector::PixelEndcap) {
284  PXFDetId did(id.rawId());
285  disk = did.disk();
286  }
287  if (theTrackerSkipSystem == StripSubdetector::TID) {
288  TIDDetId did(id.rawId());
289  wheel = did.wheel();
290  }
291  if (theTrackerSkipSystem == StripSubdetector::TEC) {
292  TECDetId did(id.rawId());
293  wheel = did.wheel();
294  }
295  }
296 
297  if (theTrackerSkipSection > -998 && layer == theTrackerSkipSection) retVal = false;
298  if (theTrackerSkipSection > -998 && disk == theTrackerSkipSection) retVal = false;
299  if (theTrackerSkipSection > -998 && wheel == theTrackerSkipSection) retVal = false;
300 
301  return retVal;
302 }
303 //
304 // Selection for Muon hits
305 //
307 
308  if (id.det() != DetId::Muon) return false;
309  if (theSkipStationDT < 0 && theSkipStationCSC < 0) return true;
310 
311  int station = -999;
312  int wheel = -999;
313  bool isRPC = false;
314  bool isDT = false;
315  bool isCSC = false;
316 
317  if ( id.subdetId() == MuonSubdetId::DT ) {
318  DTChamberId did(id.rawId());
319  station = did.station();
320  wheel = did.wheel();
321  isDT = true;
322  } else if ( id.subdetId() == MuonSubdetId::CSC ) {
323  CSCDetId did(id.rawId());
324  station = did.station();
325  isCSC = true;
326  } else if ( id.subdetId() == MuonSubdetId::RPC ) {
327  RPCDetId rpcid(id.rawId());
328  station = rpcid.station();
329  isRPC = true;
330  }
331 
332  if (isRPC && (station == theSkipStationCSC || station == theSkipStationDT)) return false;
333  if (isDT && station == theSkipStationDT ) return false;
334  if (isCSC && station == theSkipStationCSC ) return false;
335 
336  if (isDT && theSkipWheelDT > -998 && wheel == theSkipWheelDT) return false;
337 
338  return true;
339 }
T getParameter(std::string const &) const
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
const std::string metname
bool TrackerKeep(DetId id) const
check (via options) if this is a tracker rec hit for removal
edm::ESHandle< TrajectoryFitter > fitter(bool) const
the refitter used to refit the reco::Track
virtual void setServices(const edm::EventSetup &)
set the services needed by the TrackTransformer
PropagationDirection
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
TrajectoryStateOnSurface innermostMeasurementState() const
edm::ESHandle< TrajectorySmoother > smoother(bool) const
the smoother used to smooth the trajectory which came from the refitting step
static const int CSC
Definition: MuonSubdetId.h:15
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:59
TrajectoryStateOnSurface outermostMeasurementState() const
bool MuonKeep(DetId id) const
check (via options) if this is a muon rec hit for removal
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
#define LogTrace(id)
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
trackingRecHit_iterator recHitsEnd() const
last iterator to RecHits
std::vector< ConstRecHitPointer > ConstRecHitContainer
virtual std::vector< Trajectory > transform(const reco::Track &) const
Convert a reco::Track into Trajectory.
Definition: DetId.h:20
const Track & track() const
TrackTransformerForGlobalCosmicMuons(const edm::ParameterSet &)
Constructor.
const T & get() const
Definition: EventSetup.h:55
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
static const int RPC
Definition: MuonSubdetId.h:16
edm::ESHandle< Propagator > propagator(bool) const
int station() const
Definition: CSCDetId.h:88
static const int DT
Definition: MuonSubdetId.h:14
int station() const
Return the station number.
Definition: DTChamberId.h:53
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:61
trackingRecHit_iterator recHitsBegin() const
first iterator to RecHits
TransientTrackingRecHit::ConstRecHitContainer getTransientRecHits(const reco::TransientTrack &track) const
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50
int station() const
Definition: RPCDetId.h:98