31 assocHitbySimTrack_(
false) {
42 std::vector<std::string> trackerContainers;
44 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIBLowTof");
45 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIBHighTof");
46 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIDLowTof");
47 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIDHighTof");
48 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTOBLowTof");
49 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTOBHighTof");
50 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTECLowTof");
51 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTECHighTof");
52 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelBarrelLowTof");
53 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelBarrelHighTof");
54 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelEndcapLowTof");
55 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelEndcapHighTof");
56 cfTokens_.reserve(trackerContainers.size());
58 for(
auto const& trackerContainer : trackerContainers) {
69 doPixel_( conf.getParameter<bool>(
"associatePixel") ),
70 doStrip_( conf.getParameter<bool>(
"associateStrip") ),
71 useOTph2_( conf.existsAs<bool>(
"usePhase2Tracker") ? conf.getParameter<bool>(
"usePhase2Tracker") :
false),
73 doTrackAssoc_( conf.getParameter<bool>(
"associateRecoTracks") ),
74 assocHitbySimTrack_(conf.existsAs<bool>(
"associateHitbySimTrack") ? conf.getParameter<bool>(
"associateHitbySimTrack") :
false) {
82 std::vector<std::string> trackerContainers(conf.
getParameter<std::vector<std::string> >(
"ROUList"));
83 cfTokens_.reserve(trackerContainers.size());
85 for(
auto const& trackerContainer : trackerContainers) {
119 for(
auto const& cfToken : config.
cfTokens_) {
122 if (theEvent.
getByToken(cfToken, cf_simhit)) {
124 for (
auto const& isim : *thisContainerHits) {
125 DetId theDet(isim.detUnitId());
135 if(theEvent.
getByToken(simHitToken, simHits)) {
136 for (
auto const& isim : *simHits) {
137 DetId theDet(isim.detUnitId());
145 const char*
const highTag =
"HighTof";
149 unsigned int collectionIndex = 0;
150 for(
auto const& cfToken : config.
cfTokens_) {
154 if (theEvent.
getByToken(cfToken, cf_simhit)) {
162 for (
auto const& isim : *thisContainerHits) {
163 DetId theDet(isim.detUnitId());
164 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
166 SimHitMap[SimHitCollMap[theSubDetTofBin]].push_back(isim);
177 if(theEvent.
getByToken(simHitToken, simHits)) {
184 for (
auto const& isim : *simHits) {
185 DetId theDet(isim.detUnitId());
186 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
190 SimHitMap[SimHitCollMap[theSubDetTofBin]].push_back(isim);
207 std::vector<PSimHit>
result;
212 std::vector<SimHitIdpr> simtrackid;
213 std::vector<simhitAddr> simhitCFPos;
217 uint32_t detID = detid.
rawId();
236 if(dynamic_cast<const SiStripMatchedRecHit2D *>(&thit)) {
237 for(
auto const& theSimHitAddr : simhitCFPos) {
239 simhit_map::const_iterator it =
SimHitMap.find(theSimHitCollID);
241 unsigned int theSimHitIndex = theSimHitAddr.second;
242 if (theSimHitIndex < (it->second).size()) {
243 const PSimHit& theSimHit = (it->second)[theSimHitIndex];
245 unsigned int simHitid = theSimHit.
trackId();
247 for(
auto const&
id : simtrackid) {
248 if(simHitid ==
id.
first && simHiteid ==
id.
second) {
249 result.push_back(theSimHit);
260 for(
auto const& theSimHitAddr : simhitCFPos) {
262 simhit_map::const_iterator it =
SimHitMap.find(theSimHitCollID);
264 unsigned int theSimHitIndex = theSimHitAddr.second;
265 if (theSimHitIndex < (it->second).size()) {
266 result.push_back((it->second)[theSimHitIndex]);
280 std::map<unsigned int, std::vector<PSimHit> >::const_iterator it =
SimHitMap.find(detID);
282 vector<PSimHit>::const_iterator simHitIter = (it->second).
begin();
283 vector<PSimHit>::const_iterator simHitIterEnd = (it->second).
end();
284 for (;simHitIter != simHitIterEnd; ++simHitIter) {
285 const PSimHit& ihit = *simHitIter;
286 unsigned int simHitid = ihit.
trackId();
290 for(
auto id : simtrackid) {
291 if(simHitid ==
id.
first && simHiteid ==
id.
second) {
295 result.push_back(ihit);
305 std::map<unsigned int, std::vector<PSimHit> >::const_iterator itrphi =
307 std::map<unsigned int, std::vector<PSimHit> >::const_iterator itster =
310 std::vector<PSimHit> simHitVector = itrphi->second;
311 simHitVector.insert(simHitVector.end(),(itster->second).
begin(),(itster->second).
end());
312 vector<PSimHit>::const_iterator simHitIter = simHitVector.begin();
313 vector<PSimHit>::const_iterator simHitIterEnd = simHitVector.end();
314 for (;simHitIter != simHitIterEnd; ++simHitIter) {
315 const PSimHit& ihit = *simHitIter;
316 unsigned int simHitid = ihit.
trackId();
318 for(
auto const&
id : simtrackid) {
319 if(simHitid ==
id.
first && simHiteid ==
id.
second) {
323 result.push_back(ihit);
336 std::vector< SimHitIdpr > simhitid;
342 std::vector<simhitAddr>* simhitCFPos)
const 350 if (
const SiStripRecHit2D * rechit = dynamic_cast<const SiStripRecHit2D *>(&thit))
354 else if(
const SiStripRecHit1D * rechit = dynamic_cast<const SiStripRecHit1D *>(&thit))
370 else if(
const SiPixelRecHit * rechit = dynamic_cast<const SiPixelRecHit *>(&thit))
390 std::vector<SimHitIdpr>& simtrackid,
391 std::vector<PSimHit>& simhit)
const {
392 std::vector<simhitAddr> simhitCFPos;
395 for(
auto const& theSimHitAddr : simhitCFPos ) {
397 simhit_map::const_iterator it =
SimHitMap.find(theSimHitCollID);
399 unsigned int theSimHitIndex = theSimHitAddr.second;
400 if (theSimHitIndex < (it->second).size()) simhit.push_back((it->second)[theSimHitIndex]);
412 std::vector<SimHitIdpr>& simtrackid,
413 std::vector<simhitAddr>* simhitCFPos)
const {
415 uint32_t detID = detid.
rawId();
423 int last = first + clusiz;
428 std::vector<SimHitIdpr> idcachev;
429 std::vector<simhitAddr> CFposcachev;
433 channel = (
int)(linkiter->channel());
434 if( channel >= first && channel < last ){
446 SimHitIdpr currentId(linkiter->SimTrackId(), linkiter->eventId());
451 if(
find(idcachev.begin(),idcachev.end(),currentId ) == idcachev.end()){
458 idcachev.push_back(currentId);
459 simtrackid.push_back(currentId);
462 if (simhitCFPos != 0) {
465 unsigned int currentCFPos = linkiter->CFposition();
466 unsigned int tofBin = linkiter->TofBin();
468 simhit_collectionMap::const_iterator it =
SimHitCollMap.find(theSubDetTofBin);
470 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
472 if(
find(CFposcachev.begin(), CFposcachev.end(), currentAddr ) == CFposcachev.end()) {
481 CFposcachev.push_back(currentAddr);
482 simhitCFPos->push_back(currentAddr);
490 edm::LogError(
"TrackerHitAssociator")<<
"no cluster reference attached";
497 std::vector<SimHitIdpr> matched_mono;
498 std::vector<SimHitIdpr> matched_st;
507 std::vector<SimHitIdpr> simtrackid;
508 if(!(matched_mono.empty() || matched_st.empty())){
509 std::vector<SimHitIdpr> idcachev;
510 for(
auto const& mhit: matched_mono){
512 if(
find(idcachev.begin(), idcachev.end(), mhit) == idcachev.end()) {
513 idcachev.push_back(mhit);
515 if(
find(matched_st.begin(), matched_st.end(), mhit) != matched_st.end()) {
516 simtrackid.push_back(mhit);
526 std::vector<simhitAddr>* simhitCFPos)
const 530 std::vector<SimHitIdpr> matched_mono;
538 std::vector<SimHitIdpr> & simtrackid,
539 std::vector<simhitAddr>* simhitCFPos)
const 545 uint32_t detID = detid.
rawId();
555 int minRow = (*cluster).firstStrip();
556 int maxRow = (*cluster).firstStrip() + (*cluster).size();
557 int Col = (*cluster).column();
561 std::vector<SimHitIdpr> idcachev;
562 std::vector<simhitAddr> CFposcachev;
563 for( ; linkiter != linkEnd; ++linkiter) {
567 if( coord.first <= maxRow &&
568 coord.first >= minRow &&
569 coord.second == Col ) {
572 SimHitIdpr currentId(linkiter->SimTrackId(), linkiter->eventId());
573 if(
find(idcachev.begin(),idcachev.end(),currentId) == idcachev.end()){
574 simtrackid.push_back(currentId);
575 idcachev.push_back(currentId);
578 if (simhitCFPos != 0) {
581 unsigned int currentCFPos = linkiter->CFposition();
582 unsigned int tofBin = linkiter->TofBin();
584 simhit_collectionMap::const_iterator it =
SimHitCollMap.find(theSubDetTofBin);
586 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
587 if(
find(CFposcachev.begin(), CFposcachev.end(), currentAddr) == CFposcachev.end()) {
588 CFposcachev.push_back(currentAddr);
589 simhitCFPos->push_back(currentAddr);
598 edm::LogError(
"TrackerHitAssociator")<<
"no Pixel cluster reference attached";
605 std::vector<SimHitIdpr> & simtrackid,
606 std::vector<simhitAddr>* simhitCFPos)
const 612 uint32_t detID = detid.
rawId();
623 int minPixelRow = (*cluster).minPixelRow();
624 int maxPixelRow = (*cluster).maxPixelRow();
625 int minPixelCol = (*cluster).minPixelCol();
626 int maxPixelCol = (*cluster).maxPixelCol();
631 std::vector<SimHitIdpr> idcachev;
632 std::vector<simhitAddr> CFposcachev;
633 for( ; linkiter != linkEnd; ++linkiter) {
637 if( pixel_coord.first <= maxPixelRow &&
638 pixel_coord.first >= minPixelRow &&
639 pixel_coord.second <= maxPixelCol &&
640 pixel_coord.second >= minPixelCol ) {
643 SimHitIdpr currentId(linkiter->SimTrackId(), linkiter->eventId());
644 if(
find(idcachev.begin(),idcachev.end(),currentId) == idcachev.end()){
645 simtrackid.push_back(currentId);
646 idcachev.push_back(currentId);
649 if (simhitCFPos != 0) {
652 unsigned int currentCFPos = linkiter->CFposition();
653 unsigned int tofBin = linkiter->TofBin();
655 simhit_collectionMap::const_iterator it =
SimHitCollMap.find(theSubDetTofBin);
657 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
658 if(
find(CFposcachev.begin(), CFposcachev.end(), currentAddr) == CFposcachev.end()) {
659 CFposcachev.push_back(currentAddr);
660 simhitCFPos->push_back(currentAddr);
669 edm::LogError(
"TrackerHitAssociator")<<
"no Pixel cluster reference attached";
676 std::vector<const TrackingRecHit*> componenthits = multirechit->
recHits();
678 int size=multirechit->
weights().size(), idmostprobable=0;
681 if(multirechit->
weight(
i)>multirechit->
weight(idmostprobable)) idmostprobable=
i;
688 std::vector<const TrackingRecHit*> componenthits = multirechit->
recHits();
689 int size=multirechit->
weights().size(), idmostprobable=0;
692 if(multirechit->
weight(
i)>multirechit->
weight(idmostprobable)) idmostprobable=
i;
695 std::vector< SimHitIdpr > simhitid;
696 associateHitId(*componenthits[idmostprobable], simhitid, simhitCFPos);
703 vector<SimHitIdpr> simtrackid;
707 simtrackid.push_back(currentId);
void labelsForToken(EDGetToken const &iToken, ProductLabels &oLabels) const
T getParameter(std::string const &) const
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::vector< edm::EDGetTokenT< CrossingFrame< PSimHit > > > cfTokens_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
std::pair< unsigned int, unsigned int > simhitAddr
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)
virtual std::vector< const TrackingRecHit * > recHits() const
Access to component RecHits (if any)
void makeMaps(const edm::Event &theEvent, const Config &config)
std::vector< float > const & weights() const
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
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
collection_type::const_iterator const_iterator
collection_type::const_iterator const_iterator
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)