CMS 3D CMS Logo

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