CMS 3D CMS Logo

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