CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
OutsideInMuonSeeder.cc
Go to the documentation of this file.
1 
2 //
3 // $Id: OutsideInMuonSeeder.cc,v 1.2 2013/02/27 14:58:17 muzaffar Exp $
4 //
5 
21 
23 
28 
45 
47  public:
48  explicit OutsideInMuonSeeder(const edm::ParameterSet & iConfig);
49  virtual ~OutsideInMuonSeeder() { }
50 
51  virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup) override;
52 
53  private:
56 
59 
62 
65 
68 
71 
77 
79 
87 
89  bool debug_;
90 
93 
94  int doLayer(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &state, std::vector<TrajectorySeed> &out) const ;
95  void doDebug(const reco::Track &tk) const;
96 
97 };
98 
100  src_(iConfig.getParameter<edm::InputTag>("src")),
101  selector_(iConfig.existsAs<std::string>("cut") ? iConfig.getParameter<std::string>("cut") : "", true),
102  layersToTry_(iConfig.getParameter<int32_t>("layersToTry")),
103  hitsToTry_(iConfig.getParameter<int32_t>("hitsToTry")),
104  fromVertex_(iConfig.getParameter<bool>("fromVertex")),
105  errorRescaling_(iConfig.getParameter<double>("errorRescaleFactor")),
106  trackerPropagatorName_(iConfig.getParameter<std::string>("trackerPropagator")),
107  muonPropagatorName_(iConfig.getParameter<std::string>("muonPropagator")),
108  estimatorName_(iConfig.getParameter<std::string>("hitCollector")),
109  minEtaForTEC_(iConfig.getParameter<double>("minEtaForTEC")),
110  maxEtaForTOB_(iConfig.getParameter<double>("maxEtaForTOB")),
111  debug_(iConfig.getUntrackedParameter<bool>("debug",false)),
112  dummyPlane_(Plane::build(Plane::PositionType(), Plane::RotationType()))
113 {
114  produces<std::vector<TrajectorySeed> >();
116  updatorName_ = "KFUpdator";
117 }
118 
119 void
121  using namespace edm;
122  using namespace std;
123  iSetup.get<IdealMagneticFieldRecord>().get(magfield_);
130 
131  measurementTracker_->update(iEvent);
132 
134  iEvent.getByLabel(src_, src);
135 
136 
137  auto_ptr<vector<TrajectorySeed> > out(new vector<TrajectorySeed>());
138 
139  for (View<reco::Muon>::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
140  const reco::Muon &mu = *it;
141  if (mu.outerTrack().isNull() || !selector_(mu)) continue;
142  if (debug_ && mu.innerTrack().isNonnull()) doDebug(*mu.innerTrack());
143 
144  muonPropagator_->setPropagationDirection(fromVertex_ ? alongMomentum : oppositeToMomentum);
145  trackerPropagator_->setPropagationDirection(alongMomentum);
146 
147  int sizeBefore = out->size();
148  if (debug_) std::cout << "\n\n\nSeeding for muon of pt " << mu.pt() << ", eta " << mu.eta() << ", phi " << mu.phi() << std::endl;
149  const reco::Track &tk = *mu.outerTrack();
150 
152  if (fromVertex_) {
154  dummyPlane_->move(fstate.position() - dummyPlane_->position());
155  state = TrajectoryStateOnSurface(fstate, *dummyPlane_);
156  } else {
158  }
159  if (std::abs(tk.eta()) < maxEtaForTOB_) {
160  std::vector< BarrelDetLayer * > const & tob = measurementTracker_->geometricSearchTracker()->tobLayers();
161  int iLayer = 6, found = 0;
162  for (std::vector<BarrelDetLayer *>::const_reverse_iterator it = tob.rbegin(), ed = tob.rend(); it != ed; ++it, --iLayer) {
163  if (debug_) std::cout << "\n ==== Trying TOB " << iLayer << " ====" << std::endl;
164  if (doLayer(**it, state, *out)) {
165  if (++found == layersToTry_) break;
166  }
167  }
168  }
169  if (tk.eta() > minEtaForTEC_) {
170  int iLayer = 9, found = 0;
171  std::vector< ForwardDetLayer * > const & tec = measurementTracker_->geometricSearchTracker()->posTecLayers();
172  for (std::vector<ForwardDetLayer *>::const_reverse_iterator it = tec.rbegin(), ed = tec.rend(); it != ed; ++it, --iLayer) {
173  if (debug_) std::cout << "\n ==== Trying TEC " << +iLayer << " ====" << std::endl;
174  if (doLayer(**it, state, *out)) {
175  if (++found == layersToTry_) break;
176  }
177  }
178  }
179  if (tk.eta() < -minEtaForTEC_) {
180  int iLayer = 9, found = 0;
181  std::vector< ForwardDetLayer * > const & tec = measurementTracker_->geometricSearchTracker()->negTecLayers();
182  for (std::vector<ForwardDetLayer *>::const_reverse_iterator it = tec.rbegin(), ed = tec.rend(); it != ed; ++it, --iLayer) {
183  if (debug_) std::cout << "\n ==== Trying TEC " << -iLayer << " ====" << std::endl;
184  if (doLayer(**it, state, *out)) {
185  if (++found == layersToTry_) break;
186  }
187  }
188  }
189  if (debug_) std::cout << "Outcome of seeding for muon of pt " << mu.pt() << ", eta " << mu.eta() << ", phi " << mu.phi() << ": found " << (out->size() - sizeBefore) << " seeds."<< std::endl;
190 
191  }
192 
193  iEvent.put(out);
194 }
195 
196 int
197 OutsideInMuonSeeder::doLayer(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &state, std::vector<TrajectorySeed> &out) const {
198  TrajectoryStateOnSurface onLayer(state);
199  onLayer.rescaleError(errorRescaling_);
200  std::vector< GeometricSearchDet::DetWithState > dets;
201  layer.compatibleDetsV(onLayer, *muonPropagator_, *estimator_, dets);
202 
203  if (debug_) {
204  std::cout << "Query on layer around x = " << onLayer.globalPosition() <<
205  " with local pos error " << sqrt(onLayer.localError().positionError().xx()) << " , " << sqrt(onLayer.localError().positionError().yy()) << " , " <<
206  " returned " << dets.size() << " compatible detectors" << std::endl;
207  }
208 
209  std::vector<TrajectoryMeasurement> meas;
210  for (std::vector<GeometricSearchDet::DetWithState>::const_iterator it = dets.begin(), ed = dets.end(); it != ed; ++it) {
211  const MeasurementDet *det = measurementTracker_->idToDet(it->first->geographicalId());
212  if (det == 0) { std::cerr << "BOGUS detid " << it->first->geographicalId().rawId() << std::endl; continue; }
213  if (!it->second.isValid()) continue;
214  std::vector < TrajectoryMeasurement > mymeas = det->fastMeasurements(it->second, state, *trackerPropagator_, *estimator_);
215  if (debug_) std::cout << "Query on detector " << it->first->geographicalId().rawId() << " returned " << mymeas.size() << " measurements." << std::endl;
216  for (std::vector<TrajectoryMeasurement>::const_iterator it2 = mymeas.begin(), ed2 = mymeas.end(); it2 != ed2; ++it2) {
217  if (it2->recHit()->isValid()) meas.push_back(*it2);
218  }
219  }
220  int found = 0;
221  std::sort(meas.begin(), meas.end(), TrajMeasLessEstim());
222  for (std::vector<TrajectoryMeasurement>::const_iterator it2 = meas.begin(), ed2 = meas.end(); it2 != ed2; ++it2) {
223  if (debug_) {
224  std::cout << " inspecting Hit with chi2 = " << it2->estimate() << std::endl;
225  std::cout << " track state " << it2->forwardPredictedState().globalPosition() << std::endl;
226  std::cout << " rechit position " << it2->recHit()->globalPosition() << std::endl;
227  }
228  TrajectoryStateOnSurface updated = updator_->update(it2->forwardPredictedState(), *it2->recHit());
229  if (updated.isValid()) {
230  if (debug_) std::cout << " --> updated state: x = " << updated.globalPosition() << ", p = " << updated.globalMomentum() << std::endl;
232  seedHits.push_back(*it2->recHit()->hit());
233  PTrajectoryStateOnDet const & pstate = trajectoryStateTransform::persistentState(updated, it2->recHit()->geographicalId().rawId());
234  TrajectorySeed seed(pstate, std::move(seedHits), oppositeToMomentum);
235  out.push_back(seed);
236  found++; if (found == hitsToTry_) break;
237  }
238  }
239  return found;
240 }
241 
242 void
245  muonPropagator_->setPropagationDirection(alongMomentum);
246  for (unsigned int i = 0; i < tk.recHitsSize(); ++i) {
247  const TrackingRecHit *hit = &*tk.recHit(i);
248  const GeomDet *det = geometry_->idToDet(hit->geographicalId());
249  if (det == 0) continue;
250  if (i != 0) tsos = muonPropagator_->propagate(tsos, det->surface());
251  if (!tsos.isValid()) continue;
252  std::cout << " state " << i << " at x = " << tsos.globalPosition() << ", p = " << tsos.globalMomentum() << std::endl;
253  if (hit->isValid()) {
254  std::cout << " valid rechit on detid " << hit->geographicalId().rawId() << std::endl;
255  } else {
256  std::cout << " invalid rechit on detid " << hit->geographicalId().rawId() << std::endl;
257  }
258  }
259 }
260 
int hitsToTry_
How many hits to try on same layer.
TkRotation< Scalar > RotationType
Definition: Definitions.h:29
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:24
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
TrajectoryStateOnSurface innerStateOnSurface(const reco::Track &tk, const TrackingGeometry &geom, const MagneticField *field)
edm::InputTag src_
Labels for input collections.
virtual TrackRef innerTrack() const
Definition: Muon.h:49
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
Definition: Track.h:69
edm::ESHandle< Chi2MeasurementEstimatorBase > estimator_
edm::ESHandle< MagneticField > magfield_
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
edm::ESHandle< GlobalTrackingGeometry > geometry_
#define abs(x)
Definition: mlp_lapack.h:159
GlobalPoint globalPosition() const
edm::ESHandle< Propagator > trackerPropagator_
edm::ESHandle< TrajectoryStateUpdator > updator_
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
LocalError positionError() const
Definition: Plane.h:17
std::vector< TrajectoryMeasurement > fastMeasurements(const TrajectoryStateOnSurface &stateOnThisDet, const TrajectoryStateOnSurface &, const Propagator &, const MeasurementEstimator &est) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
Point3DBase< Scalar, GlobalTag > PositionType
Definition: Definitions.h:30
bool isNonnull() const
Checks for non-null.
Definition: Ref.h:250
void push_back(D *&d)
Definition: OwnVector.h:273
virtual float phi() const GCC11_FINAL
momentum azimuthal angle
std::string trackerPropagatorName_
int iEvent
Definition: GenABIO.cc:243
bool isNull() const
Checks for null.
Definition: Ref.h:247
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
float yy() const
Definition: LocalError.h:26
bool debug_
Dump deug information.
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:94
T sqrt(T t)
Definition: SSEVec.h:48
virtual void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
const int mu
Definition: Constants.h:23
const LocalTrajectoryError & localError() const
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
virtual TrackRef outerTrack() const
reference to Track reconstructed in the muon detector only
Definition: Muon.h:52
edm::ESHandle< Propagator > muonPropagator_
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
tuple out
Definition: dbtoconf.py:99
GlobalPoint position() const
FreeTrajectoryState initialFreeState(const reco::Track &tk, const MagneticField *field)
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
bool isValid() const
int layersToTry_
How many layers to try.
StringCutObjectSelector< reco::Muon > selector_
Muon selection.
char state
Definition: procUtils.cc:75
double errorRescaling_
How much to rescale errors from STA.
int doLayer(const GeometricSearchDet &layer, const TrajectoryStateOnSurface &state, std::vector< TrajectorySeed > &out) const
void doDebug(const reco::Track &tk) const
GlobalVector globalMomentum() const
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
Definition: Track.h:67
tuple cout
Definition: gather_cfg.py:121
DetId geographicalId() const
edm::ESHandle< MeasurementTracker > measurementTracker_
Plane::PlanePointer dummyPlane_
Surface used to make a TSOS at the PCA to the beamline.
virtual float pt() const GCC11_FINAL
transverse momentum
std::string measurementTrackerName_
bool fromVertex_
Do inside-out.
virtual void compatibleDetsV(const TrajectoryStateOnSurface &startingState, const Propagator &prop, const MeasurementEstimator &est, std::vector< DetWithState > &result) const
OutsideInMuonSeeder(const edm::ParameterSet &iConfig)