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) {
89 std::vector<std::string> trackerContainers(conf.
getParameter<std::vector<std::string>>(
"ROUList"));
90 cfTokens_.reserve(trackerContainers.size());
92 for (
auto const& trackerContainer : trackerContainers) {
100 desc.setComment(
"auxilliary class to store information about recHit/simHit association");
101 desc.add<
bool>(
"associatePixel",
false);
102 desc.add<
bool>(
"associateStrip",
false);
103 desc.add<
bool>(
"usePhase2Tracker",
false);
104 desc.add<
bool>(
"associateRecoTracks",
false);
105 desc.add<
bool>(
"associateHitbySimTrack",
false);
109 desc.add<std::vector<std::string>>(
110 "ROUList", {
"TrackerHitsTIBLowTof",
"TrackerHitsTIBHighTof",
"TrackerHitsTOBLowTof",
"TrackerHitsTOBHighTof"});
143 for (
auto const& cfToken :
config.cfTokens_) {
146 if (theEvent.
getByToken(cfToken, cf_simhit)) {
148 for (
auto const& isim : *thisContainerHits) {
149 DetId theDet(isim.detUnitId());
153 LogDebug(
"TrkHitAssocTrace") <<
"simHits from crossing frames; map size = " <<
SimHitMap.size()
154 <<
", Hit count = " << Nhits << std::endl;
161 for (
auto const& isim : *
simHits) {
162 DetId theDet(isim.detUnitId());
166 LogDebug(
"TrkHitAssocTrace") <<
"simHits from prompt collections; map size = " <<
SimHitMap.size()
167 <<
", Hit count = " << Nhits << std::endl;
171 const char*
const highTag =
"HighTof";
175 unsigned int collectionIndex = 0;
176 for (
auto const& cfToken :
config.cfTokens_) {
180 if (theEvent.
getByToken(cfToken, cf_simhit)) {
183 if (std::strstr(
labels.productInstance, highTag) !=
nullptr) {
188 for (
auto const& isim : *thisContainerHits) {
189 DetId theDet(isim.detUnitId());
190 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
195 LogDebug(
"TrkHitAssocTrace") <<
"simHits from crossing frames " << collectionIndex <<
": " << Nhits
206 if (std::strstr(
labels.productInstance, highTag) !=
nullptr) {
211 for (
auto const& isim : *
simHits) {
212 DetId theDet(isim.detUnitId());
213 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
218 LogDebug(
"TrkHitAssocTrace") <<
"simHits from prompt collection " << collectionIndex <<
": " << Nhits
231 std::vector<PSimHit>
result;
237 std::vector<SimHitIdpr> simtrackid;
238 std::vector<simhitAddr> simhitCFPos;
242 uint32_t detID = detid.
rawId();
256 if (dynamic_cast<const SiStripMatchedRecHit2D*>(&thit)) {
257 for (
auto const& theSimHitAddr : simhitCFPos) {
259 auto it =
SimHitMap.find(theSimHitCollID);
261 unsigned int theSimHitIndex = theSimHitAddr.second;
262 if (theSimHitIndex < (it->second).size()) {
263 const PSimHit& theSimHit = (it->second)[theSimHitIndex];
265 unsigned int simHitid = theSimHit.
trackId();
267 for (
auto const&
id : simtrackid) {
268 if (simHitid ==
id.
first && simHiteid ==
id.
second) {
269 result.push_back(theSimHit);
272 LogDebug(
"TrkHitAssocTrace") <<
"by CFpos, simHit detId = " << theSimHit.
detUnitId() <<
" address = (" 273 << theSimHitAddr.first <<
", " << theSimHitIndex
274 <<
"), process = " << theSimHit.
processType() <<
" (" 276 <<
", " << theSimHit.
trackId() <<
")" << std::endl;
281 for (
auto const& theSimHitAddr : simhitCFPos) {
283 auto it =
SimHitMap.find(theSimHitCollID);
285 unsigned int theSimHitIndex = theSimHitAddr.second;
286 if (theSimHitIndex < (it->second).size()) {
287 result.push_back((it->second)[theSimHitIndex]);
288 LogDebug(
"TrkHitAssocTrace") <<
"by CFpos, simHit detId = " << (it->second)[theSimHitIndex].detUnitId()
289 <<
" address = (" << theSimHitCollID <<
", " << theSimHitIndex
290 <<
"), process = " << (it->second)[theSimHitIndex].processType() <<
" (" 291 << (it->second)[theSimHitIndex].eventId().bunchCrossing() <<
", " 292 << (it->second)[theSimHitIndex].eventId().event() <<
", " 293 << (it->second)[theSimHitIndex].trackId() <<
")" << std::endl;
304 for (
auto const& ihit : it->second) {
305 unsigned int simHitid = ihit.trackId();
307 for (
auto id : simtrackid) {
308 if (simHitid ==
id.
first && simHiteid ==
id.
second) {
310 LogDebug(
"TrkHitAssocTrace") <<
"by TrackID, simHit detId = " << ihit.detUnitId()
311 <<
", process = " << ihit.processType() <<
" (" << ihit.eventId().bunchCrossing()
312 <<
", " << ihit.eventId().event() <<
", " << ihit.trackId() <<
")" << std::endl;
323 std::vector<PSimHit> simHitVector = itrphi->second;
324 simHitVector.insert(simHitVector.end(), (itster->second).begin(), (itster->second).
end());
325 for (
auto const& ihit : simHitVector) {
326 unsigned int simHitid = ihit.trackId();
328 for (
auto const&
id : simtrackid) {
329 if (simHitid ==
id.
first && simHiteid ==
id.
second) {
331 LogDebug(
"TrkHitAssocTrace") <<
"by TrackID, simHit detId = " << ihit.detUnitId()
332 <<
", process = " << ihit.processType() <<
" (" 333 << ihit.eventId().bunchCrossing() <<
", " << ihit.eventId().event() <<
", " 334 << ihit.trackId() <<
")" << std::endl;
346 std::vector<SimHitIdpr> simhitid;
352 std::vector<SimHitIdpr>& simtkid,
353 std::vector<simhitAddr>* simhitCFPos)
const {
360 if (
const SiStripRecHit2D* rechit = dynamic_cast<const SiStripRecHit2D*>(&thit))
364 else if (
const SiStripRecHit1D* rechit = dynamic_cast<const SiStripRecHit1D*>(&thit))
380 else if (
const SiPixelRecHit* rechit = dynamic_cast<const SiPixelRecHit*>(&thit))
388 template <
typename T>
390 std::vector<SimHitIdpr>& simtrackid,
391 std::vector<simhitAddr>* simhitCFPos)
const {
401 std::vector<SimHitIdpr>& simtrackid,
402 std::vector<PSimHit>& simhit)
const {
403 std::vector<simhitAddr> simhitCFPos;
406 for (
auto const& theSimHitAddr : simhitCFPos) {
408 auto it =
SimHitMap.find(theSimHitCollID);
411 unsigned int theSimHitIndex = theSimHitAddr.second;
412 if (theSimHitIndex < (it->second).size())
413 simhit.push_back((it->second)[theSimHitIndex]);
414 LogDebug(
"TrkHitAssocTrace") <<
"For cluster, simHit detId = " << (it->second)[theSimHitIndex].detUnitId()
415 <<
" address = (" << theSimHitCollID <<
", " << theSimHitIndex
416 <<
"), process = " << (it->second)[theSimHitIndex].processType()
417 <<
" (bnch, evt, trk) = (" << (it->second)[theSimHitIndex].eventId().bunchCrossing()
418 <<
", " << (it->second)[theSimHitIndex].eventId().event() <<
", " 419 << (it->second)[theSimHitIndex].trackId() <<
")" << std::endl;
426 std::vector<SimHitIdpr>& simtrackid,
427 std::vector<simhitAddr>* simhitCFPos)
const {
428 uint32_t detID = detid.
rawId();
431 auto link_detset = (*isearch);
433 if (clust !=
nullptr) {
438 LogDebug(
"TrkHitAssocDbg") <<
"Cluster size " << clusiz <<
" first strip = " <<
first 439 <<
" last strip = " <<
last - 1 << std::endl
440 <<
" detID = " << detID <<
" DETSET size = " << link_detset.data.size() << std::endl;
442 for (
const auto& linkiter : link_detset.data) {
443 channel = (
int)(linkiter.channel());
444 if (channel >=
first && channel <
last) {
445 LogDebug(
"TrkHitAssocDbg") <<
"Channel = " << std::setw(4) << linkiter.channel()
446 <<
", TrackID = " << std::setw(8) << linkiter.SimTrackId()
447 <<
", tofBin = " << std::setw(3) << linkiter.TofBin()
448 <<
", fraction = " << std::setw(8) << linkiter.fraction()
449 <<
", Position = " << linkiter.CFposition() << std::endl;
450 SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
455 if (
find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()) {
456 LogDebug(
"TrkHitAssocDbg") <<
" Adding track id = " << currentId.first
457 <<
" Event id = " << currentId.second.event()
458 <<
" Bunch Xing = " << currentId.second.bunchCrossing() << std::endl;
459 simtrackid.push_back(currentId);
462 if (simhitCFPos !=
nullptr) {
465 unsigned int currentCFPos = linkiter.CFposition();
466 unsigned int tofBin = linkiter.TofBin();
470 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
471 if (
find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
472 simhitCFPos->push_back(currentAddr);
479 edm::LogError(
"TrackerHitAssociator") <<
"no cluster reference attached";
485 std::vector<simhitAddr>* simhitCFPos)
const {
486 std::vector<SimHitIdpr> matched_mono;
487 std::vector<SimHitIdpr> matched_st;
496 std::vector<SimHitIdpr> simtrackid;
497 if (!(matched_mono.empty() || matched_st.empty())) {
498 for (
auto const& mhit : matched_mono) {
500 if (
find(simtrackid.begin(), simtrackid.end(), mhit) == simtrackid.end()) {
502 if (
find(matched_st.begin(), matched_st.end(), mhit) != matched_st.end()) {
503 simtrackid.push_back(mhit);
512 std::vector<simhitAddr>* simhitCFPos)
const {
515 std::vector<SimHitIdpr> matched_mono;
523 std::vector<SimHitIdpr>& simtrackid,
524 std::vector<simhitAddr>* simhitCFPos)
const {
529 uint32_t detID = detid.
rawId();
533 auto link_detset = (*isearch);
537 if (!(cluster.
isNull())) {
538 int minRow = (*cluster).firstStrip();
539 int maxRow = (*cluster).firstStrip() + (*cluster).size();
540 int Col = (*cluster).column();
541 LogDebug(
"TrkHitAssocDbg") <<
" Cluster minRow " << minRow <<
" maxRow " << maxRow <<
" column " << Col
544 for (
auto const& linkiter : link_detset.data) {
547 LogDebug(
"TrkHitAssocDbg") <<
" " << dsl <<
") Digi link: row " << coord.first <<
" col " << coord.second
549 if (coord.first <= maxRow && coord.first >= minRow && coord.second == Col) {
550 LogDebug(
"TrkHitAssocDbg") <<
" !-> trackid " << linkiter.SimTrackId() << endl
551 <<
" fraction " << linkiter.fraction() << endl;
552 SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
553 if (
find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()) {
554 simtrackid.push_back(currentId);
557 if (simhitCFPos !=
nullptr) {
560 unsigned int currentCFPos = linkiter.CFposition();
561 unsigned int tofBin = linkiter.TofBin();
565 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
566 if (
find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
567 simhitCFPos->push_back(currentAddr);
574 edm::LogError(
"TrackerHitAssociator") <<
"no Phase2 outer tracker cluster reference attached";
580 std::vector<SimHitIdpr>& simtrackid,
581 std::vector<simhitAddr>* simhitCFPos)
const {
586 uint32_t detID = detid.
rawId();
590 auto link_detset = (*isearch);
595 if (!(cluster.
isNull())) {
597 int minPixelRow = (*cluster).minPixelRow();
598 int maxPixelRow = (*cluster).maxPixelRow();
599 int minPixelCol = (*cluster).minPixelCol();
600 int maxPixelCol = (*cluster).maxPixelCol();
601 LogDebug(
"TrkHitAssocDbg") <<
" Cluster minRow " << minPixelRow <<
" maxRow " << maxPixelRow << std::endl
602 <<
" Cluster minCol " << minPixelCol <<
" maxCol " << maxPixelCol << std::endl;
604 for (
auto const& linkiter : link_detset.data) {
607 LogDebug(
"TrkHitAssocDbg") <<
" " << dsl <<
") Digi link: row " << pixel_coord.first <<
" col " 608 << pixel_coord.second << std::endl;
609 if (pixel_coord.first <= maxPixelRow && pixel_coord.first >= minPixelRow && pixel_coord.second <= maxPixelCol &&
610 pixel_coord.second >= minPixelCol) {
611 LogDebug(
"TrkHitAssocDbg") <<
" !-> trackid " << linkiter.SimTrackId() << endl
612 <<
" fraction " << linkiter.fraction() << endl;
613 SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
614 if (
find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()) {
615 simtrackid.push_back(currentId);
618 if (simhitCFPos !=
nullptr) {
621 unsigned int currentCFPos = linkiter.CFposition();
622 unsigned int tofBin = linkiter.TofBin();
626 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
627 if (
find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
628 simhitCFPos->push_back(currentAddr);
635 edm::LogError(
"TrackerHitAssociator") <<
"no Pixel cluster reference attached";
641 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))
654 std::vector<simhitAddr>* simhitCFPos)
const {
655 std::vector<const TrackingRecHit*> componenthits = multirechit->
recHits();
656 int size = multirechit->
weights().size(), idmostprobable = 0;
658 for (
int i = 0;
i <
size; ++
i) {
659 if (multirechit->
weight(
i) > multirechit->
weight(idmostprobable))
663 std::vector<SimHitIdpr> simhitid;
664 associateHitId(*componenthits[idmostprobable], simhitid, simhitCFPos);
670 vector<SimHitIdpr> simtrackid;
674 simtrackid.push_back(currentId);
680 const uint32_t& detID,
681 std::vector<SimHitIdpr>& simtrackid)
const {
682 std::stringstream message;
683 message <<
"recHit subdet, detID = " << detid.
subdetId() <<
", " << detID <<
", (bnch, evt, trk) = ";
684 for (
size_t i = 0;
i < simtrackid.size(); ++
i)
685 message <<
", (" << simtrackid[
i].
second.bunchCrossing() <<
", " << simtrackid[
i].second.event() <<
", " 686 << simtrackid[
i].first <<
")";
688 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 void fillPSetDescription(edm::ParameterSetDescription &descriptions)
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
ClusterRef cluster() const
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)