CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SeedingOTEDProducer.cc
Go to the documentation of this file.
1 
5 
13 
19 
21 
23 
27 
31 
34 
36 
38 public:
39  explicit SeedingOTEDProducer(const edm::ParameterSet&);
40  ~SeedingOTEDProducer() override;
41  void produce(edm::Event&, const edm::EventSetup&) override;
42 
44 
46  unsigned int checkLayer(unsigned int iidd);
47  std::vector<const VectorHit*> collectVHsOnLayer(const edmNew::DetSetVector<VectorHit>&, unsigned int);
48  void printVHsOnLayer(const edmNew::DetSetVector<VectorHit>&, unsigned int);
51  std::pair<bool, TrajectoryStateOnSurface> propagateAndUpdate(const TrajectoryStateOnSurface initialTSOS,
52  const Propagator&,
53  const TrackingRecHit& hit) const;
54  float computeGlobalThetaError(const VectorHit* vh, const double sigmaZ_beamSpot) const;
55  float computeInverseMomentumError(const VectorHit* vh,
56  const float globalTheta,
57  const double sigmaZ_beamSpot,
58  const double transverseMomentum) const;
59 
61  const edm::OwnVector<TrackingRecHit>& container,
62  const DetId& id,
63  const Propagator& prop) const;
64 
65  struct isInvalid {
66  bool operator()(const TrajectoryMeasurement& measurement) {
67  return ((measurement.recHit() == nullptr) || !(measurement.recHit()->isValid()) ||
68  !((measurement).updatedState().isValid()));
69  }
70  };
71 
72 private:
76  std::unique_ptr<LayerMeasurements> layerMeasurements_;
85 
93 };
94 
96  : tkMeasEventToken_(consumes<MeasurementTrackerEvent>(conf.getParameter<edm::InputTag>("trackerEvent"))),
97  topoToken_(esConsumes()),
98  propagatorToken_(esConsumes(edm::ESInputTag("", "PropagatorWithMaterial"))),
99  magFieldToken_(esConsumes()),
100  updatorToken_(esConsumes(edm::ESInputTag("", "KFUpdator"))),
101  measurementTrackerToken_(esConsumes()),
102  estToken_(esConsumes(edm::ESInputTag("", "Chi2"))) {
103  vhProducerToken_ = consumes<VectorHitCollection>(edm::InputTag(conf.getParameter<edm::InputTag>("src")));
104  beamSpotToken_ = consumes<reco::BeamSpot>(conf.getParameter<edm::InputTag>("beamSpotLabel"));
105  updatorName_ = conf.getParameter<std::string>("updator");
106  putToken_ = produces<TrajectorySeedCollection>();
107 }
108 
110 
113  desc.add<edm::InputTag>("src", edm::InputTag("siPhase2VectorHits", "accepted"));
114  desc.add<edm::InputTag>("trackerEvent", edm::InputTag("MeasurementTrackerEvent"));
115  desc.add<edm::InputTag>("beamSpotLabel", edm::InputTag("offlineBeamSpot"));
116  desc.add<std::string>("updator", std::string("KFUpdator"));
117  descriptions.add("SeedingOTEDProducer", desc);
118 }
119 
121  tkTopo_ = &es.getData(topoToken_);
122 
124  measurementTracker_ = measurementTrackerHandle.product();
125 
126  auto const& measurementTrackerEvent = event.get(tkMeasEventToken_);
127 
128  layerMeasurements_ = std::make_unique<LayerMeasurements>(*measurementTrackerHandle, measurementTrackerEvent);
129 
131 
133 
135 
137 
138  beamSpot_ = &event.get(beamSpotToken_);
139 
140  // Get the vector hits
141  auto vhs = event.getHandle(vhProducerToken_);
142 
143  event.emplace(putToken_, run(vhs));
144 }
145 
148  //check if all the first three layers have VHs
149  std::vector<const VectorHit*> vhSeedsL1 = collectVHsOnLayer(*vHs.product(), 1);
150  std::vector<const VectorHit*> vhSeedsL2 = collectVHsOnLayer(*vHs.product(), 2);
151  std::vector<const VectorHit*> vhSeedsL3 = collectVHsOnLayer(*vHs.product(), 3);
152  if (vhSeedsL1.empty() || vhSeedsL2.empty() || vhSeedsL3.empty()) {
153  return result;
154  }
155 
156  //seeds are built in the L3 of the OT
157  const BarrelDetLayer* barrelOTLayer2 = measurementTracker_->geometricSearchTracker()->tobLayers().at(1);
158 
159  //the search propag directiondepend on the sign of signZ*signPz, while the building is always the contrary
160  Propagator* searchingPropagator = &*propagator_->clone();
161  Propagator* buildingPropagator = &*propagator_->clone();
162  buildingPropagator->setPropagationDirection(alongMomentum);
163 
164  for (const auto& hitL3 : vhSeedsL3) {
165  //building a tsos out of a VectorHit
166  const TrajectoryStateOnSurface initialTSOS = buildInitialTSOS(hitL3);
167  float signZ = copysign(1.0, initialTSOS.globalPosition().z());
168  float signPz = copysign(1.0, initialTSOS.globalMomentum().z());
169 
170  //set the direction of the propagator
171  if (signZ * signPz > 0.0)
172  searchingPropagator->setPropagationDirection(oppositeToMomentum);
173  else
174  searchingPropagator->setPropagationDirection(alongMomentum);
175 
176  //find vHits in layer 2
177  std::vector<TrajectoryMeasurement> measurementsL2 =
178  layerMeasurements_->measurements(*barrelOTLayer2, initialTSOS, *searchingPropagator, *estimator_);
179 
180  std::vector<TrajectoryMeasurement>::iterator measurementsL2end =
181  std::remove_if(measurementsL2.begin(), measurementsL2.end(), isInvalid());
182  measurementsL2.erase(measurementsL2end, measurementsL2.end());
183 
184  if (!measurementsL2.empty()) {
185  //not sure if building it everytime takes time/memory
186  const DetLayer* barrelOTLayer1 = measurementTracker_->geometricSearchTracker()->tobLayers().at(0);
187 
188  for (const auto& mL2 : measurementsL2) {
189  const TrackingRecHit* hitL2 = mL2.recHit().get();
190 
191  //propagate to the L2 and update the TSOS
192  std::pair<bool, TrajectoryStateOnSurface> updatedTSOS =
193  propagateAndUpdate(initialTSOS, *searchingPropagator, *hitL2);
194  if (!updatedTSOS.first)
195  continue;
196 
197  //searching possible VHs in L1
198  std::vector<TrajectoryMeasurement> measurementsL1 =
199  layerMeasurements_->measurements(*barrelOTLayer1, updatedTSOS.second, *searchingPropagator, *estimator_);
200  std::vector<TrajectoryMeasurement>::iterator measurementsL1end =
201  std::remove_if(measurementsL1.begin(), measurementsL1.end(), isInvalid());
202  measurementsL1.erase(measurementsL1end, measurementsL1.end());
203 
204  if (!measurementsL1.empty()) {
205  for (const auto& mL1 : measurementsL1) {
206  const TrackingRecHit* hitL1 = mL1.recHit().get();
207 
208  //propagate to the L1 and update the TSOS
209  std::pair<bool, TrajectoryStateOnSurface> updatedTSOSL1 =
210  propagateAndUpdate(updatedTSOS.second, *searchingPropagator, *hitL1);
211  if (!updatedTSOSL1.first)
212  continue;
213 
214  //building trajectory inside-out
215  if (searchingPropagator->propagationDirection() == alongMomentum) {
216  buildingPropagator->setPropagationDirection(oppositeToMomentum);
217  } else {
218  buildingPropagator->setPropagationDirection(alongMomentum);
219  }
220 
221  updatedTSOSL1.second.rescaleError(100);
222 
223  TrajectoryStateOnSurface updatedTSOSL1_final = updator_->update(updatedTSOSL1.second, *hitL1);
224  if UNLIKELY (!updatedTSOSL1_final.isValid())
225  continue;
226  std::pair<bool, TrajectoryStateOnSurface> updatedTSOSL2_final =
227  propagateAndUpdate(updatedTSOSL1_final, *buildingPropagator, *hitL2);
228  if (!updatedTSOSL2_final.first)
229  continue;
230  std::pair<bool, TrajectoryStateOnSurface> updatedTSOSL3_final =
231  propagateAndUpdate(updatedTSOSL2_final.second, *buildingPropagator, *hitL3);
232  if (!updatedTSOSL3_final.first)
233  continue;
234 
236  container.push_back(hitL1->clone());
237  container.push_back(hitL2->clone());
238  container.push_back(hitL3->clone());
239 
240  TrajectorySeed ts =
241  createSeed(updatedTSOSL3_final.second, container, hitL3->geographicalId(), *buildingPropagator);
242  result.push_back(ts);
243  }
244  }
245  }
246  }
247  }
248  result.shrink_to_fit();
249  return result;
250 }
251 
252 unsigned int SeedingOTEDProducer::checkLayer(unsigned int iidd) {
254  unsigned int subid = strip.subdetId();
255  if (subid == StripSubdetector::TIB || subid == StripSubdetector::TOB) {
256  return tkTopo_->layer(iidd);
257  }
258  return 0;
259 }
260 
262  unsigned int layerNumber) {
263  std::vector<const VectorHit*> vHsOnLayer;
264  if (!input.empty()) {
265  for (const auto& DSViter : input) {
266  if (checkLayer(DSViter.id()) == layerNumber) {
267  for (const auto& vh : DSViter) {
268  vHsOnLayer.push_back(&vh);
269  }
270  }
271  }
272  }
273 
274  return vHsOnLayer;
275 }
276 
278  if (!input.empty()) {
279  for (const auto& DSViter : input) {
280  for (const auto& vh : DSViter) {
281  if (checkLayer(DSViter.id()) == layerNumber)
282  LogTrace("SeedingOTEDProducer") << " VH in layer " << layerNumber << " >> " << vh;
283  }
284  }
285  } else {
286  LogTrace("SeedingOTEDProducer") << " No VHs in layer " << layerNumber << ".";
287  }
288 }
289 
291  // having fun with theta
292  Global3DVector gv(vHit->globalPosition().x(), vHit->globalPosition().y(), vHit->globalPosition().z());
293  float theta = gv.theta();
294  // gv transform to local (lv)
295  const Local3DVector lv(vHit->det()->surface().toLocal(gv));
296 
297  //FIXME::charge is fine 1 every two times!!
298  GlobalPoint center(0.0, 0.0, 0.0);
299  int charge = 1;
300  // momentum is a signed quantity in this case
301  float mom = vHit->momentum(magField_->inTesla(center).z());
302  float xPos = vHit->localPosition().x();
303  float yPos = vHit->localPosition().y();
304  float dx = vHit->localDirection().x();
305  // for dy use second component of the lv renormalized to the z component
306  float dy = lv.y() / lv.z();
307 
308  // Pz and Dz should have the same sign
309  float signPz = copysign(1.0, vHit->globalPosition().z());
310 
311  LocalTrajectoryParameters ltpar2(charge / mom, dx, dy, xPos, yPos, signPz);
313  // set the error on 1/p
314  mat[0][0] = pow(computeInverseMomentumError(
315  vHit, theta, beamSpot_->sigmaZ(), vHit->transverseMomentum(magField_->inTesla(center).z())),
316  2);
317 
318  //building tsos
319  LocalTrajectoryError lterr(mat);
320  const TrajectoryStateOnSurface tsos(ltpar2, lterr, vHit->det()->surface(), magField_);
321 
322  return tsos;
323 }
324 
327  for (int i = 1; i < 5; i++) {
328  for (int j = 1; j < 5; j++) {
329  result[i][j] = mat44[i - 1][j - 1];
330  }
331  }
332  return result;
333 }
334 
335 std::pair<bool, TrajectoryStateOnSurface> SeedingOTEDProducer::propagateAndUpdate(
336  const TrajectoryStateOnSurface initialTSOS, const Propagator& prop, const TrackingRecHit& hit) const {
337  TrajectoryStateOnSurface propTSOS = prop.propagate(initialTSOS, hit.det()->surface());
338  if UNLIKELY (!propTSOS.isValid())
339  return std::make_pair(false, propTSOS);
340  TrajectoryStateOnSurface updatedTSOS = updator_->update(propTSOS, hit);
341  if UNLIKELY (!updatedTSOS.isValid())
342  return std::make_pair(false, updatedTSOS);
343  return std::make_pair(true, updatedTSOS);
344 }
345 
346 float SeedingOTEDProducer::computeGlobalThetaError(const VectorHit* vh, const double sigmaZ_beamSpot) const {
347  double derivative = vh->globalPosition().perp() / vh->globalPosition().mag2();
348  double derivative2 = pow(derivative, 2);
349  return pow(derivative2 * vh->lowerGlobalPosErr().czz() + derivative2 * pow(sigmaZ_beamSpot, 2), 0.5);
350 }
351 
353  const float globalTheta,
354  const double sigmaZ_beamSpot,
355  const double transverseMomentum) const {
356  //for pT > 2GeV, 1/pT has sigma = 1/sqrt(12)
357  float varianceInverseTransvMomentum = 1. / 12;
358  float derivativeTheta2 = pow(cos(globalTheta) / transverseMomentum, 2);
359  float derivativeInverseTransvMomentum2 = pow(sin(globalTheta), 2);
360  float thetaError = computeGlobalThetaError(vh, sigmaZ_beamSpot);
361  return pow(derivativeTheta2 * pow(thetaError, 2) + derivativeInverseTransvMomentum2 * varianceInverseTransvMomentum,
362  0.5);
363 }
364 
366  const edm::OwnVector<TrackingRecHit>& container,
367  const DetId& id,
368  const Propagator& prop) const {
370  return TrajectorySeed(seedTSOS, container, prop.propagationDirection());
371 }
SeedingOTEDProducer(const edm::ParameterSet &)
virtual void setPropagationDirection(PropagationDirection dir)
Definition: Propagator.h:130
edm::ESGetToken< Chi2MeasurementEstimatorBase, TrackingComponentsRecord > estToken_
T mag2() const
Definition: PV3DBase.h:63
T perp() const
Definition: PV3DBase.h:69
ConstRecHitPointer const & recHit() const
TrajectorySeed createSeed(const TrajectoryStateOnSurface &tsos, const edm::OwnVector< TrackingRecHit > &container, const DetId &id, const Propagator &prop) const
Derivative< X, A >::type derivative(const A &_)
Definition: Derivative.h:18
virtual LocalVector localDirection() const
Definition: VectorHit.h:75
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
GlobalError lowerGlobalPosErr() const
Definition: VectorHit.cc:123
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void produce(edm::Event &, const edm::EventSetup &) override
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
Geom::Theta< T > theta() const
T y() const
Definition: PV3DBase.h:60
virtual Propagator * clone() const =0
GlobalPoint globalPosition() const
void printVHsOnLayer(const edmNew::DetSetVector< VectorHit > &, unsigned int)
std::vector< BarrelDetLayer const * > const & tobLayers() const
virtual PropagationDirection propagationDirection() const final
Definition: Propagator.h:139
edm::EDGetTokenT< reco::BeamSpot > beamSpotToken_
static void fillDescriptions(edm::ConfigurationDescriptions &)
float transverseMomentum(float magField) const
Definition: VectorHit.cc:156
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
#define LogTrace(id)
static std::string const input
Definition: EdmProvDump.cc:47
tuple result
Definition: mps_fire.py:311
bool getData(T &iHolder) const
Definition: EventSetup.h:128
float computeGlobalThetaError(const VectorHit *vh, const double sigmaZ_beamSpot) const
void push_back(D *&d)
Definition: OwnVector.h:326
virtual TrajectoryStateOnSurface update(const TrajectoryStateOnSurface &, const TrackingRecHit &) const =0
float computeInverseMomentumError(const VectorHit *vh, const float globalTheta, const double sigmaZ_beamSpot, const double transverseMomentum) const
std::vector< TrajectorySeed > TrajectorySeedCollection
const GeomDet * det() const
LocalPoint toLocal(const GlobalPoint &gp) const
T z() const
Definition: PV3DBase.h:61
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< const VectorHit * > collectVHsOnLayer(const edmNew::DetSetVector< VectorHit > &, unsigned int)
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
edm::ESGetToken< MeasurementTracker, CkfComponentsRecord > measurementTrackerToken_
float momentum(float magField) const
Definition: VectorHit.cc:161
ROOT::Math::SMatrix< double, 4, 4, ROOT::Math::MatRepSym< double, 4 > > AlgebraicSymMatrix44
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > topoToken_
static constexpr auto TOB
TrajectorySeedCollection run(edm::Handle< VectorHitCollection >)
edm::ESGetToken< TrajectoryStateUpdator, TrackingComponentsRecord > updatorToken_
ParameterDescriptionBase * add(U const &iLabel, T const &value)
edm::EDGetTokenT< VectorHitCollection > vhProducerToken_
const AlgebraicSymMatrix44 & covMatrix() const
Definition: VectorHit.cc:171
const TrackerTopology * tkTopo_
const MagneticField * magField_
virtual TrackingRecHit * clone() const =0
ValidHit vh
Definition: classes.h:14
Definition: DetId.h:17
GlobalPoint globalPosition() const final
LocalPoint localPosition() const override
Definition: VectorHit.h:74
const TrajectoryStateUpdator * updator_
static constexpr auto TIB
T const * product() const
Definition: Handle.h:70
std::pair< bool, TrajectoryStateOnSurface > propagateAndUpdate(const TrajectoryStateOnSurface initialTSOS, const Propagator &, const TrackingRecHit &hit) const
double sigmaZ() const
sigma z
Definition: BeamSpot.h:76
T const * product() const
Definition: ESHandle.h:86
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ROOT::Math::SMatrix< double, 5, 5, ROOT::Math::MatRepSym< double, 5 > > AlgebraicSymMatrix55
void add(std::string const &label, ParameterSetDescription const &psetDescription)
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
Definition: Propagator.h:50
const Propagator * propagator_
unsigned int layer(const DetId &id) const
AlgebraicSymMatrix55 assign44To55(const AlgebraicSymMatrix44 &) const
const MeasurementTracker * measurementTracker_
GlobalVector globalMomentum() const
edm::EDPutTokenT< TrajectorySeedCollection > putToken_
const MeasurementEstimator * estimator_
edm::ESGetToken< Propagator, TrackingComponentsRecord > propagatorToken_
const TrajectoryStateOnSurface buildInitialTSOS(const VectorHit *) const
const edm::EDGetTokenT< MeasurementTrackerEvent > tkMeasEventToken_
#define UNLIKELY(x)
Definition: Likely.h:21
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
Definition: EventSetup.h:157
const reco::BeamSpot * beamSpot_
std::unique_ptr< LayerMeasurements > layerMeasurements_
const GeometricSearchTracker * geometricSearchTracker() const
unsigned int checkLayer(unsigned int iidd)
T x() const
Definition: PV3DBase.h:59
ESGetTokenH3DDVariant esConsumes(std::string const &Reccord, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
bool operator()(const TrajectoryMeasurement &measurement)
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > magFieldToken_