34 assocHitbySimTrack_(
false) {
45 std::vector<std::string> trackerContainers;
47 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIBLowTof");
48 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIBHighTof");
49 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIDLowTof");
50 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIDHighTof");
51 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTOBLowTof");
52 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTOBHighTof");
53 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTECLowTof");
54 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTECHighTof");
55 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelBarrelLowTof");
56 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelBarrelHighTof");
57 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelEndcapLowTof");
58 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelEndcapHighTof");
59 cfTokens_.reserve(trackerContainers.size());
61 for(
auto const& trackerContainer : trackerContainers) {
85 std::vector<std::string> trackerContainers(conf.
getParameter<std::vector<std::string> >(
"ROUList"));
86 cfTokens_.reserve(trackerContainers.size());
88 for(
auto const& trackerContainer : trackerContainers) {
122 for(
auto const& cfToken : config.
cfTokens_) {
125 if (theEvent.
getByToken(cfToken, cf_simhit)) {
127 for (
auto const& isim : *thisContainerHits) {
128 DetId theDet(isim.detUnitId());
132 LogDebug(
"TrkHitAssocTrace") <<
"simHits from crossing frames; map size = " <<
SimHitMap.size() <<
", Hit count = " << Nhits << std::endl;
139 for (
auto const& isim : *simHits) {
140 DetId theDet(isim.detUnitId());
144 LogDebug(
"TrkHitAssocTrace") <<
"simHits from prompt collections; map size = " <<
SimHitMap.size() <<
", Hit count = " << Nhits << std::endl;
148 const char*
const highTag =
"HighTof";
152 unsigned int collectionIndex = 0;
153 for(
auto const& cfToken : config.
cfTokens_) {
157 if (theEvent.
getByToken(cfToken, cf_simhit)) {
165 for (
auto const& isim : *thisContainerHits) {
166 DetId theDet(isim.detUnitId());
167 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
169 SimHitMap[SimHitCollMap[theSubDetTofBin]].push_back(isim);
172 LogDebug(
"TrkHitAssocTrace") <<
"simHits from crossing frames " << collectionIndex <<
": " << Nhits << std::endl;
187 for (
auto const& isim : *simHits) {
188 DetId theDet(isim.detUnitId());
189 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
191 SimHitMap[SimHitCollMap[theSubDetTofBin]].push_back(isim);
194 LogDebug(
"TrkHitAssocTrace") <<
"simHits from prompt collection " << collectionIndex <<
": " << Nhits << std::endl;
208 std::vector<PSimHit>
result;
213 std::vector<SimHitIdpr> simtrackid;
214 std::vector<simhitAddr> simhitCFPos;
218 uint32_t detID = detid.
rawId();
232 if(dynamic_cast<const SiStripMatchedRecHit2D *>(&thit)) {
233 for(
auto const& theSimHitAddr : simhitCFPos) {
235 auto it =
SimHitMap.find(theSimHitCollID);
237 unsigned int theSimHitIndex = theSimHitAddr.second;
238 if (theSimHitIndex < (it->second).size()) {
239 const PSimHit& theSimHit = (it->second)[theSimHitIndex];
241 unsigned int simHitid = theSimHit.
trackId();
243 for(
auto const&
id : simtrackid) {
244 if(simHitid ==
id.
first && simHiteid ==
id.
second) {
245 result.push_back(theSimHit);
249 <<
"by CFpos, simHit detId = " << theSimHit.
detUnitId()
250 <<
" address = (" << theSimHitAddr.first <<
", " << theSimHitIndex
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 result.push_back((it->second)[theSimHitIndex]);
265 <<
"by CFpos, simHit detId = " << (it->second)[theSimHitIndex].detUnitId()
266 <<
" address = (" << theSimHitCollID <<
", " << theSimHitIndex
267 <<
"), process = " << (it->second)[theSimHitIndex].processType() <<
" (" << (it->second)[theSimHitIndex].eventId().bunchCrossing()
268 <<
", " << (it->second)[theSimHitIndex].eventId().event() <<
", " << (it->second)[theSimHitIndex].trackId() <<
")" << std::endl;
279 for (
auto const& ihit : it->second) {
280 unsigned int simHitid = ihit.trackId();
282 for(
auto id : simtrackid) {
283 if(simHitid ==
id.
first && simHiteid ==
id.
second) {
284 result.push_back(ihit);
286 <<
"by TrackID, simHit detId = " << ihit.detUnitId()
287 <<
", process = " << ihit.processType() <<
" (" << ihit.eventId().bunchCrossing()
288 <<
", " << ihit.eventId().event() <<
", " << ihit.trackId() <<
")" << std::endl;
300 std::vector<PSimHit> simHitVector = itrphi->second;
301 simHitVector.insert(simHitVector.end(), (itster->second).
begin(), (itster->second).
end());
302 for (
auto const& ihit : simHitVector) {
303 unsigned int simHitid = ihit.trackId();
305 for(
auto const&
id : simtrackid) {
306 if(simHitid ==
id.
first && simHiteid ==
id.
second) {
307 result.push_back(ihit);
309 <<
"by TrackID, simHit detId = " << ihit.detUnitId()
310 <<
", process = " << ihit.processType() <<
" (" << ihit.eventId().bunchCrossing()
311 <<
", " << ihit.eventId().event() <<
", " << ihit.trackId() <<
")" << std::endl;
324 std::vector< SimHitIdpr > simhitid;
330 std::vector<simhitAddr>* simhitCFPos)
const 338 if (
const SiStripRecHit2D * rechit = dynamic_cast<const SiStripRecHit2D *>(&thit))
342 else if(
const SiStripRecHit1D * rechit = dynamic_cast<const SiStripRecHit1D *>(&thit))
358 else if(
const SiPixelRecHit * rechit = dynamic_cast<const SiPixelRecHit *>(&thit))
378 std::vector<SimHitIdpr>& simtrackid,
379 std::vector<PSimHit>& simhit)
const {
380 std::vector<simhitAddr> simhitCFPos;
383 for(
auto const& theSimHitAddr : simhitCFPos ) {
385 auto it =
SimHitMap.find(theSimHitCollID);
388 unsigned int theSimHitIndex = theSimHitAddr.second;
389 if (theSimHitIndex < (it->second).size()) simhit.push_back((it->second)[theSimHitIndex]);
391 <<
"For cluster, simHit detId = " << (it->second)[theSimHitIndex].detUnitId()
392 <<
" address = (" << theSimHitCollID <<
", " << theSimHitIndex
393 <<
"), process = " << (it->second)[theSimHitIndex].processType()
394 <<
" (bnch, evt, trk) = (" << (it->second)[theSimHitIndex].eventId().bunchCrossing()
395 <<
", " << (it->second)[theSimHitIndex].eventId().event()
396 <<
", " << (it->second)[theSimHitIndex].trackId() <<
")" << std::endl;
403 std::vector<SimHitIdpr>& simtrackid,
404 std::vector<simhitAddr>* simhitCFPos)
const {
406 uint32_t detID = detid.
rawId();
409 auto link_detset = (*isearch);
414 int last = first + clusiz;
416 LogDebug(
"TrkHitAssocDbg") <<
"Cluster size " << clusiz <<
" first strip = " << first <<
" last strip = " << last-1 << std::endl
417 <<
" detID = " << detID <<
" DETSET size = " << link_detset.data.size() << std::endl;
419 for (
auto linkiter : link_detset.data) {
420 channel = (
int)(linkiter.channel());
421 if( channel >= first && channel < last ) {
422 LogDebug(
"TrkHitAssocDbg") <<
"Channel = " << std::setw(4) << linkiter.channel()
423 <<
", TrackID = " << std::setw(8) << linkiter.SimTrackId()
424 <<
", tofBin = " << std::setw(3) << linkiter.TofBin()
425 <<
", fraction = " << std::setw(8) << linkiter.fraction()
426 <<
", Position = " << linkiter.CFposition() << std::endl;
427 SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
432 if(
find(simtrackid.begin(), simtrackid.end(), currentId ) == simtrackid.end()){
433 LogDebug(
"TrkHitAssocDbg") <<
" Adding track id = " << currentId.first
434 <<
" Event id = " << currentId.second.event()
435 <<
" Bunch Xing = " << currentId.second.bunchCrossing()
437 simtrackid.push_back(currentId);
440 if (simhitCFPos !=
nullptr) {
443 unsigned int currentCFPos = linkiter.CFposition();
444 unsigned int tofBin = linkiter.TofBin();
448 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
449 if(
find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
450 simhitCFPos->push_back(currentAddr);
458 edm::LogError(
"TrackerHitAssociator")<<
"no cluster reference attached";
465 std::vector<SimHitIdpr> matched_mono;
466 std::vector<SimHitIdpr> matched_st;
475 std::vector<SimHitIdpr> simtrackid;
476 if(!(matched_mono.empty() || matched_st.empty())){
477 for(
auto const& mhit: matched_mono){
479 if(
find(simtrackid.begin(), simtrackid.end(), mhit) == simtrackid.end()) {
481 if(
find(matched_st.begin(), matched_st.end(), mhit) != matched_st.end()) {
482 simtrackid.push_back(mhit);
491 std::vector<simhitAddr>* simhitCFPos)
const 495 std::vector<SimHitIdpr> matched_mono;
503 std::vector<SimHitIdpr> & simtrackid,
504 std::vector<simhitAddr>* simhitCFPos)
const 510 uint32_t detID = detid.
rawId();
514 auto link_detset = (*isearch);
519 int minRow = (*cluster).firstStrip();
520 int maxRow = (*cluster).firstStrip() + (*cluster).size();
521 int Col = (*cluster).column();
522 LogDebug(
"TrkHitAssocDbg") <<
" Cluster minRow " << minRow <<
" maxRow " << maxRow <<
" column " << Col << std::endl;
524 for(
auto const& linkiter : link_detset.data) {
527 LogDebug(
"TrkHitAssocDbg") <<
" " << dsl <<
") Digi link: row " << coord.first <<
" col " << coord.second << std::endl;
528 if( coord.first <= maxRow &&
529 coord.first >= minRow &&
530 coord.second == Col ) {
531 LogDebug(
"TrkHitAssocDbg") <<
" !-> trackid " << linkiter.SimTrackId() << endl
532 <<
" fraction " << linkiter.fraction() << endl;
533 SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
534 if(
find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()){
535 simtrackid.push_back(currentId);
538 if (simhitCFPos !=
nullptr) {
541 unsigned int currentCFPos = linkiter.CFposition();
542 unsigned int tofBin = linkiter.TofBin();
546 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
547 if(
find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
548 simhitCFPos->push_back(currentAddr);
556 edm::LogError(
"TrackerHitAssociator")<<
"no Phase2 outer tracker cluster reference attached";
562 std::vector<SimHitIdpr> & simtrackid,
563 std::vector<simhitAddr>* simhitCFPos)
const 569 uint32_t detID = detid.
rawId();
573 auto link_detset = (*isearch);
580 int minPixelRow = (*cluster).minPixelRow();
581 int maxPixelRow = (*cluster).maxPixelRow();
582 int minPixelCol = (*cluster).minPixelCol();
583 int maxPixelCol = (*cluster).maxPixelCol();
584 LogDebug(
"TrkHitAssocDbg") <<
" Cluster minRow " << minPixelRow <<
" maxRow " << maxPixelRow << std::endl
585 <<
" Cluster minCol " << minPixelCol <<
" maxCol " << maxPixelCol << std::endl;
587 for(
auto const& linkiter : link_detset.data) {
590 LogDebug(
"TrkHitAssocDbg") <<
" " << dsl <<
") Digi link: row " << pixel_coord.first <<
" col " << pixel_coord.second << std::endl;
591 if( pixel_coord.first <= maxPixelRow &&
592 pixel_coord.first >= minPixelRow &&
593 pixel_coord.second <= maxPixelCol &&
594 pixel_coord.second >= minPixelCol ) {
595 LogDebug(
"TrkHitAssocDbg") <<
" !-> trackid " << linkiter.SimTrackId() << endl
596 <<
" fraction " << linkiter.fraction() << endl;
597 SimHitIdpr currentId(linkiter.SimTrackId(), linkiter.eventId());
598 if(
find(simtrackid.begin(), simtrackid.end(), currentId) == simtrackid.end()){
599 simtrackid.push_back(currentId);
602 if (simhitCFPos !=
nullptr) {
605 unsigned int currentCFPos = linkiter.CFposition();
606 unsigned int tofBin = linkiter.TofBin();
610 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
611 if(
find(simhitCFPos->begin(), simhitCFPos->end(), currentAddr) == simhitCFPos->end()) {
612 simhitCFPos->push_back(currentAddr);
620 edm::LogError(
"TrackerHitAssociator")<<
"no Pixel cluster reference attached";
626 std::vector<const TrackingRecHit*> componenthits = multirechit->
recHits();
628 int size=multirechit->
weights().size(), idmostprobable=0;
631 if(multirechit->
weight(
i)>multirechit->
weight(idmostprobable)) idmostprobable=
i;
638 std::vector<const TrackingRecHit*> componenthits = multirechit->
recHits();
639 int size=multirechit->
weights().size(), idmostprobable=0;
642 if(multirechit->
weight(
i)>multirechit->
weight(idmostprobable)) idmostprobable=
i;
645 std::vector< SimHitIdpr > simhitid;
646 associateHitId(*componenthits[idmostprobable], simhitid, simhitCFPos);
653 vector<SimHitIdpr> simtrackid;
657 simtrackid.push_back(currentId);
665 message <<
"recHit subdet, detID = " << detid.
subdetId() <<
", " << detID <<
", (bnch, evt, trk) = ";
666 for (
size_t i=0;
i<simtrackid.size(); ++
i)
667 message <<
", (" << simtrackid[
i].
second.bunchCrossing() <<
", " 668 << simtrackid[
i].second.event() <<
", " << simtrackid[
i].first <<
")";
670 return message.str();
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
T getParameter(std::string const &) const
int event() const
get the contents of the subdetector field (should be protected?)
unsigned int simHitCollectionID
std::vector< SimHitIdpr > associateMultiRecHitId(const SiTrackerMultiRecHit *multirechit, std::vector< simhitAddr > *simhitCFPos=0) const
edm::Handle< edm::DetSetVector< StripDigiSimLink > > stripdigisimlink
std::vector< PSimHit > associateMultiRecHit(const SiTrackerMultiRecHit *multirechit) const
std::string printDetBnchEvtTrk(const DetId &detid, const uint32_t &detID, std::vector< SimHitIdpr > &simtrackid) const
std::vector< edm::EDGetTokenT< CrossingFrame< PSimHit > > > cfTokens_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::pair< unsigned int, unsigned int > simhitAddr
std::vector< const TrackingRecHit * > recHits() const override
Access to component RecHits (if any)
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > ph2OTrToken_
std::vector< SimHitIdpr > associateFastRecHit(const FastTrackerRecHit *rechit) const
uint16_t firstStrip() const
virtual int32_t simTrackEventId(size_t i) const
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > pixeldigisimlink
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::pair< unsigned int, unsigned int > subDetTofBin
void associateSimpleRecHitCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
edm::EDGetTokenT< edm::DetSetVector< PixelDigiSimLink > > pixelToken_
float weight(unsigned int i) const
uint32_t rawId() const
get the raw id
U second(std::pair< T, U > const &p)
void makeMaps(const edm::Event &theEvent, const Config &config)
std::vector< float > const & weights() const
int bunchCrossing() const
get the detector field from this detid
virtual int32_t simTrackId(size_t i) const
EncodedEventId eventId() const
bool isFast(TrackingRecHit const &hit)
int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
bool isNull() const
Checks for null.
edm::EDGetTokenT< edm::DetSetVector< StripDigiSimLink > > stripToken_
void associatePixelRecHit(const SiPixelRecHit *pixelrechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
std::vector< edm::EDGetTokenT< std::vector< PSimHit > > > simHitTokens_
simhit_collectionMap SimHitCollMap
SiStripRecHit2D originalHit() const
void associateCluster(const SiStripCluster *clust, const DetId &detid, std::vector< SimHitIdpr > &simtrackid, std::vector< PSimHit > &simhit) const
std::pair< uint32_t, EncodedEventId > SimHitIdpr
SiStripRecHit2D stereoHit() const
T const * product() const
ClusterRef cluster() const
static std::pair< int, int > channelToPixel(int ch)
virtual size_t nSimTrackIds() const
TrackerHitAssociator(const edm::Event &e, const Config &config)
void associatePhase2TrackerRecHit(const Phase2TrackerRecHit1D *rechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
unsigned short processType() const
SiStripRecHit2D monoHit() const
std::vector< SimHitIdpr > associateHitId(const TrackingRecHit &thit) const
char const * productInstance
std::vector< SimHitIdpr > associateProjectedRecHit(const ProjectedSiStripRecHit2D *projectedrechit, std::vector< simhitAddr > *simhitCFPos=0) const
unsigned int trackId() const
std::vector< PSimHit > associateHit(const TrackingRecHit &thit) const
Config(const edm::ParameterSet &conf, edm::ConsumesCollector &&iC)
DetId geographicalId() const
edm::Handle< edm::DetSetVector< PixelDigiSimLink > > ph2trackerdigisimlink
std::vector< SimHitIdpr > associateMatchedRecHit(const SiStripMatchedRecHit2D *matchedrechit, std::vector< simhitAddr > *simhitCFPos=0) const
void associateSiStripRecHit(const T *simplerechit, std::vector< SimHitIdpr > &simtrackid, std::vector< simhitAddr > *simhitCFPos=0) const
const std::vector< uint8_t > & amplitudes() const
static std::pair< unsigned int, unsigned int > channelToPixel(unsigned int ch)
unsigned int detUnitId() const