44 std::vector<std::string> trackerContainers;
46 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIBLowTof");
47 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIBHighTof");
48 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIDLowTof");
49 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIDHighTof");
50 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTOBLowTof");
51 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTOBHighTof");
52 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTECLowTof");
53 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTECHighTof");
54 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelBarrelLowTof");
55 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelBarrelHighTof");
56 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelEndcapLowTof");
57 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelEndcapHighTof");
58 cfTokens_.reserve(trackerContainers.size());
60 for (
auto const& trackerContainer : trackerContainers) {
77 conf.existsAs<
bool>(
"associateHitbySimTrack") ? conf.getParameter<
bool>(
"associateHitbySimTrack") :
false) {
90 std::vector<std::string> trackerContainers(conf.
getParameter<std::vector<std::string> >(
"ROUList"));
91 cfTokens_.reserve(trackerContainers.size());
93 for (
auto const& trackerContainer : trackerContainers) {
130 for (
auto const& cfToken :
config.cfTokens_) {
133 if (theEvent.
getByToken(cfToken, cf_simhit)) {
135 for (
auto const& isim : *thisContainerHits) {
136 DetId theDet(isim.detUnitId());
140 LogDebug(
"TrkHitAssocTrace") <<
"simHits from crossing frames; map size = " <<
SimHitMap.size()
141 <<
", Hit count = " << Nhits << std::endl;
148 for (
auto const& isim : *
simHits) {
149 DetId theDet(isim.detUnitId());
153 LogDebug(
"TrkHitAssocTrace") <<
"simHits from prompt collections; map size = " <<
SimHitMap.size()
154 <<
", Hit count = " << Nhits << std::endl;
158 const char*
const highTag =
"HighTof";
162 unsigned int collectionIndex = 0;
163 for (
auto const& cfToken :
config.cfTokens_) {
167 if (theEvent.
getByToken(cfToken, cf_simhit)) {
170 if (std::strstr(
labels.productInstance, highTag) !=
nullptr) {
175 for (
auto const& isim : *thisContainerHits) {
176 DetId theDet(isim.detUnitId());
177 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
182 LogDebug(
"TrkHitAssocTrace") <<
"simHits from crossing frames " << collectionIndex <<
": " << Nhits
193 if (std::strstr(
labels.productInstance, highTag) !=
nullptr) {
198 for (
auto const& isim : *
simHits) {
199 DetId theDet(isim.detUnitId());
200 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
205 LogDebug(
"TrkHitAssocTrace") <<
"simHits from prompt collection " << collectionIndex <<
": " << Nhits
218 std::vector<PSimHit>
result;
224 std::vector<SimHitIdpr> simtrackid;
225 std::vector<simhitAddr> simhitCFPos;
229 uint32_t detID = detid.
rawId();
243 if (dynamic_cast<const SiStripMatchedRecHit2D*>(&thit)) {
244 for (
auto const& theSimHitAddr : simhitCFPos) {
246 auto it =
SimHitMap.find(theSimHitCollID);
248 unsigned int theSimHitIndex = theSimHitAddr.second;
249 if (theSimHitIndex < (it->second).size()) {
250 const PSimHit& theSimHit = (it->second)[theSimHitIndex];
252 unsigned int simHitid = theSimHit.
trackId();
254 for (
auto const&
id : simtrackid) {
255 if (simHitid ==
id.
first && simHiteid ==
id.
second) {
256 result.push_back(theSimHit);
259 LogDebug(
"TrkHitAssocTrace") <<
"by CFpos, simHit detId = " << theSimHit.
detUnitId() <<
" address = (" 260 << theSimHitAddr.first <<
", " << theSimHitIndex
261 <<
"), process = " << theSimHit.
processType() <<
" (" 263 <<
", " << theSimHit.
trackId() <<
")" << std::endl;
268 for (
auto const& theSimHitAddr : simhitCFPos) {
270 auto it =
SimHitMap.find(theSimHitCollID);
272 unsigned int theSimHitIndex = theSimHitAddr.second;
273 if (theSimHitIndex < (it->second).size()) {
274 result.push_back((it->second)[theSimHitIndex]);
275 LogDebug(
"TrkHitAssocTrace") <<
"by CFpos, simHit detId = " << (it->second)[theSimHitIndex].detUnitId()
276 <<
" address = (" << theSimHitCollID <<
", " << theSimHitIndex
277 <<
"), process = " << (it->second)[theSimHitIndex].processType() <<
" (" 278 << (it->second)[theSimHitIndex].eventId().bunchCrossing() <<
", " 279 << (it->second)[theSimHitIndex].eventId().event() <<
", " 280 << (it->second)[theSimHitIndex].trackId() <<
")" << std::endl;
291 for (
auto const& ihit : it->second) {
292 unsigned int simHitid = ihit.trackId();
294 for (
auto id : simtrackid) {
295 if (simHitid ==
id.
first && simHiteid ==
id.
second) {
297 LogDebug(
"TrkHitAssocTrace") <<
"by TrackID, simHit detId = " << ihit.detUnitId()
298 <<
", process = " << ihit.processType() <<
" (" << ihit.eventId().bunchCrossing()
299 <<
", " << ihit.eventId().event() <<
", " << ihit.trackId() <<
")" << std::endl;
310 std::vector<PSimHit> simHitVector = itrphi->second;
311 simHitVector.insert(simHitVector.end(), (itster->second).begin(), (itster->second).
end());
312 for (
auto const& ihit : simHitVector) {
313 unsigned int simHitid = ihit.trackId();
315 for (
auto const&
id : simtrackid) {
316 if (simHitid ==
id.
first && simHiteid ==
id.
second) {
318 LogDebug(
"TrkHitAssocTrace") <<
"by TrackID, simHit detId = " << ihit.detUnitId()
319 <<
", process = " << ihit.processType() <<
" (" 320 << ihit.eventId().bunchCrossing() <<
", " << ihit.eventId().event() <<
", " 321 << ihit.trackId() <<
")" << std::endl;
333 std::vector<SimHitIdpr> simhitid;
339 std::vector<SimHitIdpr>& simtkid,
340 std::vector<simhitAddr>* simhitCFPos)
const {
347 if (
const SiStripRecHit2D* rechit = dynamic_cast<const SiStripRecHit2D*>(&thit))
351 else if (
const SiStripRecHit1D* rechit = dynamic_cast<const SiStripRecHit1D*>(&thit))
367 else if (
const SiPixelRecHit* rechit = dynamic_cast<const SiPixelRecHit*>(&thit))
375 template <
typename T>
377 std::vector<SimHitIdpr>& simtrackid,
378 std::vector<simhitAddr>* simhitCFPos)
const {
388 std::vector<SimHitIdpr>& simtrackid,
389 std::vector<PSimHit>& simhit)
const {
390 std::vector<simhitAddr> simhitCFPos;
393 for (
auto const& theSimHitAddr : simhitCFPos) {
395 auto it =
SimHitMap.find(theSimHitCollID);
398 unsigned int theSimHitIndex = theSimHitAddr.second;
399 if (theSimHitIndex < (it->second).size())
400 simhit.push_back((it->second)[theSimHitIndex]);
401 LogDebug(
"TrkHitAssocTrace") <<
"For cluster, simHit detId = " << (it->second)[theSimHitIndex].detUnitId()
402 <<
" address = (" << theSimHitCollID <<
", " << theSimHitIndex
403 <<
"), process = " << (it->second)[theSimHitIndex].processType()
404 <<
" (bnch, evt, trk) = (" << (it->second)[theSimHitIndex].eventId().bunchCrossing()
405 <<
", " << (it->second)[theSimHitIndex].eventId().event() <<
", " 406 << (it->second)[theSimHitIndex].trackId() <<
")" << std::endl;
413 std::vector<SimHitIdpr>& simtrackid,
414 std::vector<simhitAddr>* simhitCFPos)
const {
415 uint32_t detID = detid.
rawId();
418 auto link_detset = (*isearch);
420 if (clust !=
nullptr) {
425 LogDebug(
"TrkHitAssocDbg") <<
"Cluster size " << clusiz <<
" first strip = " <<
first 426 <<
" last strip = " <<
last - 1 << std::endl
427 <<
" detID = " << detID <<
" DETSET size = " << link_detset.data.size() << std::endl;
429 for (
const auto& linkiter : link_detset.data) {
430 channel = (
int)(linkiter.channel());
431 if (channel >=
first && channel <
last) {
432 LogDebug(
"TrkHitAssocDbg") <<
"Channel = " << std::setw(4) << linkiter.channel()
433 <<
", TrackID = " << std::setw(8) << linkiter.SimTrackId()
434 <<
", tofBin = " << std::setw(3) << linkiter.TofBin()
435 <<
", fraction = " << std::setw(8) << linkiter.fraction()
436 <<
", Position = " << linkiter.CFposition() << std::endl;
437 SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
442 if (
find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()) {
443 LogDebug(
"TrkHitAssocDbg") <<
" Adding track id = " << currentId.first
444 <<
" Event id = " << currentId.second.event()
445 <<
" Bunch Xing = " << currentId.second.bunchCrossing() << std::endl;
446 simtrackid.push_back(currentId);
449 if (simhitCFPos !=
nullptr) {
452 unsigned int currentCFPos = linkiter.CFposition();
453 unsigned int tofBin = linkiter.TofBin();
457 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
458 if (
find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
459 simhitCFPos->push_back(currentAddr);
466 edm::LogError(
"TrackerHitAssociator") <<
"no cluster reference attached";
472 std::vector<simhitAddr>* simhitCFPos)
const {
473 std::vector<SimHitIdpr> matched_mono;
474 std::vector<SimHitIdpr> matched_st;
483 std::vector<SimHitIdpr> simtrackid;
484 if (!(matched_mono.empty() || matched_st.empty())) {
485 for (
auto const& mhit : matched_mono) {
487 if (
find(simtrackid.begin(), simtrackid.end(), mhit) == simtrackid.end()) {
489 if (
find(matched_st.begin(), matched_st.end(), mhit) != matched_st.end()) {
490 simtrackid.push_back(mhit);
499 std::vector<simhitAddr>* simhitCFPos)
const {
502 std::vector<SimHitIdpr> matched_mono;
510 std::vector<SimHitIdpr>& simtrackid,
511 std::vector<simhitAddr>* simhitCFPos)
const {
516 uint32_t detID = detid.
rawId();
520 auto link_detset = (*isearch);
524 if (!(cluster.
isNull())) {
525 int minRow = (*cluster).firstStrip();
526 int maxRow = (*cluster).firstStrip() + (*cluster).size();
527 int Col = (*cluster).column();
528 LogDebug(
"TrkHitAssocDbg") <<
" Cluster minRow " << minRow <<
" maxRow " << maxRow <<
" column " << Col
531 for (
auto const& linkiter : link_detset.data) {
534 LogDebug(
"TrkHitAssocDbg") <<
" " << dsl <<
") Digi link: row " << coord.first <<
" col " << coord.second
536 if (coord.first <= maxRow && coord.first >= minRow && coord.second == Col) {
537 LogDebug(
"TrkHitAssocDbg") <<
" !-> trackid " << linkiter.SimTrackId() << endl
538 <<
" fraction " << linkiter.fraction() << endl;
539 SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
540 if (
find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()) {
541 simtrackid.push_back(currentId);
544 if (simhitCFPos !=
nullptr) {
547 unsigned int currentCFPos = linkiter.CFposition();
548 unsigned int tofBin = linkiter.TofBin();
552 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
553 if (
find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
554 simhitCFPos->push_back(currentAddr);
561 edm::LogError(
"TrackerHitAssociator") <<
"no Phase2 outer tracker cluster reference attached";
567 std::vector<SimHitIdpr>& simtrackid,
568 std::vector<simhitAddr>* simhitCFPos)
const {
573 uint32_t detID = detid.
rawId();
577 auto link_detset = (*isearch);
582 if (!(cluster.
isNull())) {
584 int minPixelRow = (*cluster).minPixelRow();
585 int maxPixelRow = (*cluster).maxPixelRow();
586 int minPixelCol = (*cluster).minPixelCol();
587 int maxPixelCol = (*cluster).maxPixelCol();
588 LogDebug(
"TrkHitAssocDbg") <<
" Cluster minRow " << minPixelRow <<
" maxRow " << maxPixelRow << std::endl
589 <<
" Cluster minCol " << minPixelCol <<
" maxCol " << maxPixelCol << std::endl;
591 for (
auto const& linkiter : link_detset.data) {
594 LogDebug(
"TrkHitAssocDbg") <<
" " << dsl <<
") Digi link: row " << pixel_coord.first <<
" col " 595 << pixel_coord.second << std::endl;
596 if (pixel_coord.first <= maxPixelRow && pixel_coord.first >= minPixelRow && pixel_coord.second <= maxPixelCol &&
597 pixel_coord.second >= minPixelCol) {
598 LogDebug(
"TrkHitAssocDbg") <<
" !-> trackid " << linkiter.SimTrackId() << endl
599 <<
" fraction " << linkiter.fraction() << endl;
600 SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
601 if (
find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()) {
602 simtrackid.push_back(currentId);
605 if (simhitCFPos !=
nullptr) {
608 unsigned int currentCFPos = linkiter.CFposition();
609 unsigned int tofBin = linkiter.TofBin();
613 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
614 if (
find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
615 simhitCFPos->push_back(currentAddr);
622 edm::LogError(
"TrackerHitAssociator") <<
"no Pixel cluster reference attached";
628 std::vector<const TrackingRecHit*> componenthits = multirechit->
recHits();
630 int size = multirechit->
weights().size(), idmostprobable = 0;
632 for (
int i = 0;
i <
size; ++
i) {
633 if (multirechit->
weight(
i) > multirechit->
weight(idmostprobable))
641 std::vector<simhitAddr>* simhitCFPos)
const {
642 std::vector<const TrackingRecHit*> componenthits = multirechit->
recHits();
643 int size = multirechit->
weights().size(), idmostprobable = 0;
645 for (
int i = 0;
i <
size; ++
i) {
646 if (multirechit->
weight(
i) > multirechit->
weight(idmostprobable))
650 std::vector<SimHitIdpr> simhitid;
651 associateHitId(*componenthits[idmostprobable], simhitid, simhitCFPos);
657 vector<SimHitIdpr> simtrackid;
661 simtrackid.push_back(currentId);
667 const uint32_t& detID,
668 std::vector<SimHitIdpr>& simtrackid)
const {
669 std::stringstream message;
670 message <<
"recHit subdet, detID = " << detid.
subdetId() <<
", " << detID <<
", (bnch, evt, trk) = ";
671 for (
size_t i = 0;
i < simtrackid.size(); ++
i)
672 message <<
", (" << simtrackid[
i].
second.bunchCrossing() <<
", " << simtrackid[
i].second.event() <<
", " 673 << simtrackid[
i].first <<
")";
675 return message.str();
ClusterRef cluster() const
std::string printDetBnchEvtTrk(const DetId &detid, const uint32_t &detID, std::vector< SimHitIdpr > &simtrackid) const
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > pixeldigisimlink
T getParameter(std::string const &) const
uint16_t firstStrip() const
SiStripRecHit2D stereoHit() const
unsigned int simHitCollectionID
iterator find(det_id_type id)
int event() const
get the contents of the subdetector field (should be protected?)
std::vector< float > const & weights() const
static std::pair< int, int > channelToPixel(int ch)
unsigned int detUnitId() const
std::vector< SimHitIdpr > associateFastRecHit(const FastTrackerRecHit *rechit) const
std::vector< edm::EDGetTokenT< CrossingFrame< PSimHit > > > cfTokens_
edm::Handle< edm::DetSetVector< StripDigiSimLink > > stripdigisimlink
void associatePixelRecHit(const SiPixelRecHit *pixelrechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=nullptr) const
std::pair< unsigned int, unsigned int > simhitAddr
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > ph2OTrToken_
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
void associateSiStripRecHit(const T *simplerechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=nullptr) const
T const * product() const
std::vector< SimHitIdpr > associateMatchedRecHit(const SiStripMatchedRecHit2D *matchedrechit, std::vector< simhitAddr > *simhitCFPos=nullptr) const
void associateCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< PSimHit > &simhit) const
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::pair< unsigned int, unsigned int > subDetTofBin
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > pixelToken_
U second(std::pair< T, U > const &p)
void makeMaps(const edm::Event &theEvent, const Config &config)
std::vector< PSimHit > associateMultiRecHit(const SiTrackerMultiRecHit *multirechit) const
std::vector< PSimHit > associateHit(const TrackingRecHit &thit) const
SiStripCluster const & amplitudes() const
int bunchCrossing() const
get the detector field from this detid
unsigned short processType() const
virtual int32_t simTrackId(size_t i) const
std::vector< SimHitIdpr > associateMultiRecHitId(const SiTrackerMultiRecHit *multirechit, std::vector< simhitAddr > *simhitCFPos=nullptr) const
void associateSimpleRecHitCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=nullptr) const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
unsigned int trackId() const
virtual size_t nSimTrackIds() const
EncodedEventId eventId() const
bool isFast(TrackingRecHit const &hit)
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > ph2trackerdigisimlink
bool isNull() const
Checks for null.
iterator end()
Return the off-the-end iterator.
edm::EDGetTokenT< edm::DetSetVector< StripDigiSimLink > > stripToken_
virtual int32_t simTrackEventId(size_t i) const
std::vector< edm::EDGetTokenT< std::vector< PSimHit > > > simHitTokens_
simhit_collectionMap SimHitCollMap
std::pair< uint32_t, EncodedEventId > SimHitIdpr
DetId geographicalId() const
constexpr uint32_t rawId() const
get the raw id
TrackerHitAssociator(const edm::Event &e, const Config &config)
float weight(unsigned int i) const
static std::pair< unsigned int, unsigned int > channelToPixel(unsigned int ch)
SiStripRecHit2D originalHit() const
std::vector< SimHitIdpr > associateProjectedRecHit(const ProjectedSiStripRecHit2D *projectedrechit, std::vector< simhitAddr > *simhitCFPos=nullptr) const
SiStripRecHit2D monoHit() const
void associatePhase2TrackerRecHit(const Phase2TrackerRecHit1D *rechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=nullptr) const
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)