CMS 3D CMS Logo

TrackCandidateProducer.cc
Go to the documentation of this file.
1 // system
2 #include <memory>
3 #include <vector>
4 #include <map>
5 
6 // framework
14 
15 // data format
24 
25 // geometry / magnetic field / propagation
35 
36 // fastsim
41 
43 public:
44  explicit TrackCandidateProducer(const edm::ParameterSet& conf);
45 
46  void produce(edm::Event& e, const edm::EventSetup& es) override;
47 
48 private:
49  // tokens & labels
55 
56  // other data
58  bool splitHits;
61 };
62 
64  // produces
65  produces<TrackCandidateCollection>();
66 
67  // consumes
68  if (conf.exists("hitMasks")) {
69  hitMasksToken = consumes<std::vector<bool> >(conf.getParameter<edm::InputTag>("hitMasks"));
70  }
71  seedToken = consumes<edm::View<TrajectorySeed> >(conf.getParameter<edm::InputTag>("src"));
73  consumes<FastTrackerRecHitCombinationCollection>(conf.getParameter<edm::InputTag>("recHitCombinations"));
74  simTrackToken = consumes<edm::SimTrackContainer>(conf.getParameter<edm::InputTag>("simTracks"));
75 
76  // other parameters
77  maxSeedMatchEstimator = conf.getUntrackedParameter<double>("maxSeedMatchEstimator", 0);
78  rejectOverlaps = conf.getParameter<bool>("OverlapCleaning");
79  splitHits = conf.getParameter<bool>("SplitHits");
80  propagatorLabel = conf.getParameter<std::string>("propagator");
81 }
82 
84  // get records
87 
88  edm::ESHandle<TrackerGeometry> trackerGeometry;
89  es.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
90 
91  edm::ESHandle<TrackerTopology> trackerTopology;
92  es.get<TrackerTopologyRcd>().get(trackerTopology);
93 
96 
97  // get products
99  e.getByToken(seedToken, seeds);
100 
103 
105  e.getByToken(simTrackToken, simTracks);
106 
109  e.getByToken(hitMasksToken, hitMasks);
110  }
111 
112  // output collection
113  std::unique_ptr<TrackCandidateCollection> output(new TrackCandidateCollection);
114 
115  // loop over the seeds
116  for (unsigned seedIndex = 0; seedIndex < seeds->size(); ++seedIndex) {
117  const TrajectorySeed seed = (*seeds)[seedIndex];
118  std::vector<int32_t> recHitCombinationIndices;
119 
120  // match hitless seeds to simTracks and find corresponding recHitCombination
121  if (seed.nHits() == 0) {
122  recHitCombinationIndices = SeedMatcher::matchRecHitCombinations(
124  }
125  // for normal seeds, retrieve the corresponding recHitCombination from the seed hits
126  else {
128  recHitCombinationIndices.push_back(icomb);
129  }
130 
131  // loop over the matched recHitCombinations
132  for (auto icomb : recHitCombinationIndices) {
133  if (icomb < 0 || unsigned(icomb) >= recHitCombinations->size()) {
134  throw cms::Exception("TrackCandidateProducer")
135  << " found seed with recHitCombination out or range: " << icomb << std::endl;
136  }
137  const FastTrackerRecHitCombination& recHitCombination = (*recHitCombinations)[icomb];
138 
139  // container for select hits
140  std::vector<const FastTrackerRecHit*> selectedRecHits;
141 
142  // add the seed hits
143  for (auto const& recHit : seed.recHits()) {
144  selectedRecHits.push_back(static_cast<const FastTrackerRecHit*>(&recHit));
145  }
146 
147  // prepare to skip seed hits
148  const FastTrackerRecHit* lastHitToSkip = nullptr;
149  if (!selectedRecHits.empty()) {
150  lastHitToSkip = selectedRecHits.back();
151  }
152 
153  // inOut or outIn tracking ?
154  bool hitsAlongMomentum = (seed.direction() == alongMomentum);
155 
156  // add hits from combination to hit selection
157  for (unsigned hitIndex = hitsAlongMomentum ? 0 : recHitCombination.size() - 1;
158  hitIndex < recHitCombination.size();
159  hitsAlongMomentum ? ++hitIndex : --hitIndex) {
160  const FastTrackerRecHit* selectedRecHit = recHitCombination[hitIndex].get();
161 
162  // skip seed hits
163  if (lastHitToSkip) {
164  if (lastHitToSkip->sameId(selectedRecHit)) {
165  lastHitToSkip = nullptr;
166  }
167  continue;
168  }
169 
170  // apply hit masking
171  if (hitMasks.isValid() && fastTrackingUtilities::hitIsMasked(selectedRecHit, *hitMasks)) {
172  continue;
173  }
174 
175  // if overlap rejection is not switched on, accept all hits
176  // always accept the first hit
177  // also accept a hit if it is not on the layer of the previous hit
178  if (!rejectOverlaps || selectedRecHits.empty() ||
179  (TrackingLayer::createFromDetId(selectedRecHits.back()->geographicalId(), *trackerTopology.product()) !=
180  TrackingLayer::createFromDetId(selectedRecHit->geographicalId(), *trackerTopology.product()))) {
181  selectedRecHits.push_back(selectedRecHit);
182  }
183  // else:
184  // overlap rejection is switched on
185  // the hit is on the same layer as the previous hit
186  // accept the one with smallest error
187  else if (fastTrackingUtilities::hitLocalError(selectedRecHit) <
188  fastTrackingUtilities::hitLocalError(selectedRecHits.back())) {
189  selectedRecHits.back() = selectedRecHit;
190  }
191  }
192 
193  // split hits / store copies for the track candidate
194  edm::OwnVector<TrackingRecHit> hitsForTrackCandidate;
195  for (unsigned index = 0; index < selectedRecHits.size(); ++index) {
196  if (splitHits) {
197  // add split hits to splitSelectedRecHits
198  hitSplitter.split(*selectedRecHits[index], hitsForTrackCandidate, hitsAlongMomentum);
199  } else {
200  hitsForTrackCandidate.push_back(selectedRecHits[index]->clone());
201  }
202  }
203 
204  // set the recHitCombinationIndex
205  fastTrackingUtilities::setRecHitCombinationIndex(hitsForTrackCandidate, icomb);
206 
207  // create track candidate state
208  // 1. get seed state (defined on the surface of the most outer hit)
209  DetId seedDetId(seed.startingState().detId());
210  const GeomDet* gdet = trackerGeometry->idToDet(seedDetId);
211  TrajectoryStateOnSurface seedTSOS =
212  trajectoryStateTransform::transientState(seed.startingState(), &(gdet->surface()), magneticField.product());
213  // 2. backPropagate the seedState to the surfuce of the most inner hit
214  const GeomDet* initialLayer = trackerGeometry->idToDet(hitsForTrackCandidate.front().geographicalId());
215  const TrajectoryStateOnSurface initialTSOS = propagator->propagate(seedTSOS, initialLayer->surface());
216  // 3. check validity and transform
217  if (!initialTSOS.isValid())
218  continue;
220  initialTSOS, hitsForTrackCandidate.front().geographicalId().rawId());
221 
222  // add track candidate to output collection
223  output->push_back(
224  TrackCandidate(hitsForTrackCandidate, seed, PTSOD, edm::RefToBase<TrajectorySeed>(seeds, seedIndex)));
225  }
226  }
227 
228  // Save the track candidates
229  e.put(std::move(output));
230 }
231 
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
Propagator.h
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
TrajectoryStateOnSurface.h
Handle.h
fastTrackingUtilities::hitLocalError
double hitLocalError(const TrackingRecHit *hit)
Definition: FastTrackingUtilities.h:48
SeedMatcher.h
FreeTrajectoryState.h
MessageLogger.h
TrackerGeometry.h
GeomDet
Definition: GeomDet.h:27
DetachedQuadStep_cff.hitMasks
hitMasks
Definition: DetachedQuadStep_cff.py:99
TrackCandidateCollection.h
ESHandle.h
FastTrackingUtilities.h
TrackingLayer::createFromDetId
static TrackingLayer createFromDetId(const DetId &detId, const TrackerTopology &trackerTopology)
Definition: TrackingLayer.cc:9
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:72
edm::EDGetTokenT
Definition: EDGetToken.h:33
trajectoryStateTransform::persistentState
PTrajectoryStateOnDet persistentState(const TrajectoryStateOnSurface &ts, unsigned int detid)
Definition: TrajectoryStateTransform.cc:14
fastTrackingUtilities::setRecHitCombinationIndex
void setRecHitCombinationIndex(edm::OwnVector< T > &recHits, int32_t icomb)
Definition: FastTrackingUtilities.h:11
FastTrackerRecHit::sameId
bool sameId(const FastTrackerRecHit *other, size_t i=0, size_t j=0) const
Definition: FastTrackerRecHit.h:136
fastTrackingUtilities::hitIsMasked
bool hitIsMasked(const FastTrackerRecHit *hit, const std::vector< bool > &hitMasks)
Definition: FastTrackingUtilities.h:39
SeedMatcher::matchRecHitCombinations
static std::vector< int > matchRecHitCombinations(const TrajectorySeed &seed, const FastTrackerRecHitCombinationCollection &recHitCombinationCollection, const std::vector< SimTrack > &simTrackCollection, double maxMatchEstimator, const Propagator &propagator, const MagneticField &magneticField, const TrackerGeometry &trackerGeometry)
Definition: SeedMatcher.cc:14
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
EDProducer.h
TrackCandidateProducer_cfi.simTracks
simTracks
Definition: TrackCandidateProducer_cfi.py:15
FastTrackerRecHit
Definition: FastTrackerRecHit.h:40
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
TrackCandidateProducer::simTrackToken
edm::EDGetTokenT< edm::SimTrackContainer > simTrackToken
Definition: TrackCandidateProducer.cc:53
HLT_FULL_cff.magneticField
magneticField
Definition: HLT_FULL_cff.py:348
edm::Handle
Definition: AssociativeIterator.h:50
TrackCandidateProducer::produce
void produce(edm::Event &e, const edm::EventSetup &es) override
Definition: TrackCandidateProducer.cc:83
TrackingRecHit::geographicalId
DetId geographicalId() const
Definition: TrackingRecHit.h:120
rpcPointValidation_cfi.recHit
recHit
Definition: rpcPointValidation_cfi.py:7
TrackCandidateProducer::seedToken
edm::EDGetTokenT< edm::View< TrajectorySeed > > seedToken
Definition: TrackCandidateProducer.cc:50
TrackCandidateProducer::splitHits
bool splitHits
Definition: TrackCandidateProducer.cc:58
TrackCandidateProducer::rejectOverlaps
bool rejectOverlaps
Definition: TrackCandidateProducer.cc:57
fileCollector.seed
seed
Definition: fileCollector.py:127
IdealMagneticFieldRecord
Definition: IdealMagneticFieldRecord.h:11
DetId
Definition: DetId.h:17
TrajectoryStateOnSurface
Definition: TrajectoryStateOnSurface.h:16
MakerMacros.h
FastTrackerRecHitSplitter.h
TrackCandidateProducer::TrackCandidateProducer
TrackCandidateProducer(const edm::ParameterSet &conf)
Definition: TrackCandidateProducer.cc:63
TrackerTopologyRcd.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:80
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrackCandidateProducer_cfi.propagator
propagator
Definition: TrackCandidateProducer_cfi.py:17
TrackCandidateProducer::hitSplitter
FastTrackerRecHitSplitter hitSplitter
Definition: TrackCandidateProducer.cc:59
clone
TEveGeoShape * clone(const TEveElement *element, TEveElement *parent)
Definition: eve_macros.cc:135
fastTrackingUtilities::getRecHitCombinationIndex
int32_t getRecHitCombinationIndex(const T &object)
Definition: FastTrackingUtilities.h:22
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
IdealMagneticFieldRecord.h
edm::ESHandle< MagneticField >
TrackCandidateProducer::maxSeedMatchEstimator
double maxSeedMatchEstimator
Definition: TrackCandidateProducer.cc:60
FastTrackerRecHitSplitter::split
void split(const FastTrackerRecHit &hitIn, edm::OwnVector< TrackingRecHit > &hitsOut, bool alongMomentum) const
Definition: FastTrackerRecHitSplitter.h:17
edm::OwnVector::front
reference front()
Definition: OwnVector.h:459
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TrackingLayer.h
InitialStep_cff.seeds
seeds
Definition: InitialStep_cff.py:230
edm::ParameterSet::exists
bool exists(std::string const &parameterName) const
checks if a parameter exists
Definition: ParameterSet.cc:681
TrackerDigiGeometryRecord.h
edm::ParameterSet
Definition: ParameterSet.h:47
TrackCandidateCollection
std::vector< TrackCandidate > TrackCandidateCollection
Definition: TrackCandidateCollection.h:7
Event.h
TrackCandidate
Definition: TrackCandidate.h:24
TrackCandidateProducer::recHitCombinationsToken
edm::EDGetTokenT< FastTrackerRecHitCombinationCollection > recHitCombinationsToken
Definition: TrackCandidateProducer.cc:51
trajectoryStateTransform::transientState
TrajectoryStateOnSurface transientState(const PTrajectoryStateOnDet &ts, const Surface *surface, const MagneticField *field)
Definition: TrajectoryStateTransform.cc:35
edm::stream::EDProducer
Definition: EDProducer.h:38
edm::EventSetup
Definition: EventSetup.h:57
FastTrackerRecHitCollection.h
get
#define get
TrajectorySeedCollection.h
InputTag.h
TrackCandidateProducer_cfi.recHitCombinations
recHitCombinations
Definition: TrackCandidateProducer_cfi.py:5
eostools.move
def move(src, dest)
Definition: eostools.py:511
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
TrackCandidateProducer::hitMasksToken
edm::EDGetTokenT< std::vector< bool > > hitMasksToken
Definition: TrackCandidateProducer.cc:52
FastTrackerRecHitCombination
std::vector< FastTrackerRecHitRef > FastTrackerRecHitCombination
Definition: FastTrackerRecHitCollection.h:11
TrackingComponentsRecord.h
Exception
Definition: hltDiff.cc:246
TrajectorySeed
Definition: TrajectorySeed.h:18
EventSetup.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
edm::RefToBase< TrajectorySeed >
TrajectoryStateTransform.h
edm::OwnVector::push_back
void push_back(D *&d)
Definition: OwnVector.h:326
TrajectoryStateOnSurface::surface
const SurfaceType & surface() const
Definition: TrajectoryStateOnSurface.h:78
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
FastTrackerRecHit.h
TrackCandidateProducer::propagatorLabel
std::string propagatorLabel
Definition: TrackCandidateProducer.cc:54
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
PTrajectoryStateOnDet
Definition: PTrajectoryStateOnDet.h:10
SimTrack.h
ParameterSet.h
OwnVector.h
edm::Event
Definition: Event.h:73
TrackCandidateProducer
Definition: TrackCandidateProducer.cc:42
SimTrackContainer.h
edm::InputTag
Definition: InputTag.h:15
alongMomentum
Definition: PropagationDirection.h:4
TrajectoryStateOnSurface::isValid
bool isValid() const
Definition: TrajectoryStateOnSurface.h:54
edm::OwnVector< TrackingRecHit >
FastTrackerRecHitSplitter
Definition: FastTrackerRecHitSplitter.h:12
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
TrackingComponentsRecord
Definition: TrackingComponentsRecord.h:12