CMS 3D CMS Logo

MkFitSeedConverter.cc
Go to the documentation of this file.
2 
6 
12 
16 
20 
23 
26 
28 
29 // ROOT
30 #include "Math/SVector.h"
31 #include "Math/SMatrix.h"
32 
33 // mkFit includes
36 
38 public:
39  explicit MkFitSeedConverter(edm::ParameterSet const& iConfig);
40  ~MkFitSeedConverter() override = default;
41 
42  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
43 
44 private:
45  void produce(edm::StreamID, edm::Event& iEvent, const edm::EventSetup& iSetup) const override;
46 
48  const TrackerTopology& ttopo,
49  const TransientTrackingRecHitBuilder& ttrhBuilder,
50  const MagneticField& mf,
51  const MkFitGeometry& mkFitGeom) const;
52 
53  using SVector3 = ROOT::Math::SVector<float, 3>;
54  using SMatrixSym33 = ROOT::Math::SMatrix<float, 3, 3, ROOT::Math::MatRepSym<float, 3>>;
55  using SMatrixSym66 = ROOT::Math::SMatrix<float, 6, 6, ROOT::Math::MatRepSym<float, 6>>;
56 
63  const unsigned int maxNSeeds_;
64 };
65 
67  : seedToken_{consumes<edm::View<TrajectorySeed>>(iConfig.getParameter<edm::InputTag>("seeds"))},
68  ttrhBuilderToken_{esConsumes<TransientTrackingRecHitBuilder, TransientRecHitRecord>(
69  iConfig.getParameter<edm::ESInputTag>("ttrhBuilder"))},
70  ttopoToken_{esConsumes<TrackerTopology, TrackerTopologyRcd>()},
71  mkFitGeomToken_{esConsumes<MkFitGeometry, TrackerRecoGeometryRecord>()},
72  mfToken_{esConsumes<MagneticField, IdealMagneticFieldRecord>()},
73  putToken_{produces<MkFitSeedWrapper>()},
74  maxNSeeds_{iConfig.getParameter<unsigned int>("maxNSeeds")} {}
75 
78 
79  desc.add("seeds", edm::InputTag{"initialStepSeeds"});
80  desc.add("ttrhBuilder", edm::ESInputTag{"", "WithTrackAngle"});
81  desc.add("maxNSeeds", 500000U);
82 
83  descriptions.addWithDefaultLabel(desc);
84 }
85 
87  iEvent.emplace(putToken_,
89  iSetup.getData(ttopoToken_),
90  iSetup.getData(ttrhBuilderToken_),
91  iSetup.getData(mfToken_),
92  iSetup.getData(mkFitGeomToken_)));
93 }
94 
96  const TrackerTopology& ttopo,
97  const TransientTrackingRecHitBuilder& ttrhBuilder,
98  const MagneticField& mf,
99  const MkFitGeometry& mkFitGeom) const {
101  if (seeds.size() > maxNSeeds_) {
102  edm::LogError("TooManySeeds") << "Exceeded maximum number of seeds! maxNSeeds=" << maxNSeeds_
103  << " nSeed=" << seeds.size();
104  return ret;
105  }
106  ret.reserve(seeds.size());
107 
108  auto isPlusSide = [&ttopo](const DetId& detid) {
109  return ttopo.side(detid) == static_cast<unsigned>(TrackerDetSide::PosEndcap);
110  };
111 
112  int seed_index = 0;
113  for (const auto& seed : seeds) {
114  auto const& hitRange = seed.recHits();
115  const auto lastRecHit = ttrhBuilder.build(&*(hitRange.end() - 1));
116  const auto tsos = trajectoryStateTransform::transientState(seed.startingState(), lastRecHit->surface(), &mf);
117  const auto& stateGlobal = tsos.globalParameters();
118  const auto& gpos = stateGlobal.position();
119  const auto& gmom = stateGlobal.momentum();
120  SVector3 pos(gpos.x(), gpos.y(), gpos.z());
121  SVector3 mom(gmom.x(), gmom.y(), gmom.z());
122 
123  const auto& cov = tsos.curvilinearError().matrix();
124  SMatrixSym66 err; //fill a sub-matrix, mkfit::TrackState will convert internally
125  for (int i = 0; i < 5; ++i) {
126  for (int j = i; j < 5; ++j) {
127  err.At(i, j) = cov[i][j];
128  }
129  }
130 
131  mkfit::TrackState state(tsos.charge(), pos, mom, err);
132  state.convertFromGlbCurvilinearToCCS();
133  ret.emplace_back(state, 0, seed_index, 0, nullptr);
134  LogTrace("MkFitSeedConverter") << "Inserted seed with index " << seed_index;
135 
136  // Add hits
137  for (auto const& recHit : hitRange) {
139  throw cms::Exception("Assert") << "Encountered a seed with a hit which is not trackerHitRTTI::isFromDet()";
140  }
141  auto& baseTrkRecHit = static_cast<const BaseTrackerRecHit&>(recHit);
142  if (!baseTrkRecHit.isMatched()) {
143  const auto& clusterRef = baseTrkRecHit.firstClusterRef();
144  const auto detId = recHit.geographicalId();
145  const auto ilay = mkFitGeom.layerNumberConverter().convertLayerNumber(
146  detId.subdetId(), ttopo.layer(detId), false, ttopo.isStereo(detId), isPlusSide(detId));
147  LogTrace("MkFitSeedConverter") << " adding hit detid " << detId.rawId() << " index " << clusterRef.index()
148  << " ilay " << ilay;
149  ret.back().addHitIdx(clusterRef.index(), ilay, 0); // per-hit chi2 is not known
150  } else {
151  auto& matched2D = dynamic_cast<const SiStripMatchedRecHit2D&>(recHit);
152  const OmniClusterRef* const clRefs[2] = {&matched2D.monoClusterRef(), &matched2D.stereoClusterRef()};
153  const DetId detIds[2] = {matched2D.monoId(), matched2D.stereoId()};
154  for (int ii = 0; ii < 2; ++ii) {
155  const auto& detId = detIds[ii];
156  const auto ilay = mkFitGeom.layerNumberConverter().convertLayerNumber(
157  detId.subdetId(), ttopo.layer(detId), false, ttopo.isStereo(detId), isPlusSide(detId));
158  LogTrace("MkFitSeedConverter") << " adding matched hit detid " << detId.rawId() << " index "
159  << clRefs[ii]->index() << " ilay " << ilay;
160  ret.back().addHitIdx(clRefs[ii]->index(), ilay, 0); // per-hit chi2 is not known
161  }
162  }
163  }
164  ++seed_index;
165  }
166  return ret;
167 }
168 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
bool isFromDet(TrackingRecHit const &hit)
const edm::ESGetToken< MkFitGeometry, TrackerRecoGeometryRecord > mkFitGeomToken_
const edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken_
ret
prodAgent to be discontinued
const GlobalTrajectoryParameters & globalParameters() const
const unsigned int maxNSeeds_
ROOT::Math::SMatrix< float, 3, 3, ROOT::Math::MatRepSym< float, 3 > > SMatrixSym33
unsigned int index() const
const edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > ttopoToken_
mkfit::TrackVec convertSeeds(const edm::View< TrajectorySeed > &seeds, const TrackerTopology &ttopo, const TransientTrackingRecHitBuilder &ttrhBuilder, const MagneticField &mf, const MkFitGeometry &mkFitGeom) const
bool isStereo(const DetId &id) const
Log< level::Error, false > LogError
unsigned int side(const DetId &id) const
unsigned int layer(const DetId &id) const
#define LogTrace(id)
MkFitSeedConverter(edm::ParameterSet const &iConfig)
int iEvent
Definition: GenABIO.cc:224
virtual RecHitPointer build(const TrackingRecHit *p) const =0
build a tracking rechit from an existing rechit
const edm::ESGetToken< TransientTrackingRecHitBuilder, TransientRecHitRecord > ttrhBuilderToken_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const edm::EDPutTokenT< MkFitSeedWrapper > putToken_
ii
Definition: cuy.py:589
mkfit::LayerNumberConverter const & layerNumberConverter() const
Definition: MkFitGeometry.h:33
Definition: DetId.h:17
std::vector< Track > TrackVec
ROOT::Math::SMatrix< float, 6, 6, ROOT::Math::MatRepSym< float, 6 > > SMatrixSym66
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
virtual OmniClusterRef const & firstClusterRef() const =0
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void produce(edm::StreamID, edm::Event &iEvent, const edm::EventSetup &iSetup) const override
ROOT::Math::SVector< float, 3 > SVector3
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > mfToken_
int convertLayerNumber(int det, int lay, bool useMatched, int isStereo, bool posZ) const
~MkFitSeedConverter() override=default