30 assocHitbySimTrack_(
false) {
35 std::vector<std::string> trackerContainers;
37 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIBLowTof");
38 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIBHighTof");
39 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIDLowTof");
40 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTIDHighTof");
41 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTOBLowTof");
42 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTOBHighTof");
43 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTECLowTof");
44 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsTECHighTof");
45 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelBarrelLowTof");
46 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelBarrelHighTof");
47 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelEndcapLowTof");
48 trackerContainers.emplace_back(
"g4SimHitsTrackerHitsPixelEndcapHighTof");
49 cfTokens_.reserve(trackerContainers.size());
51 for(
auto const& trackerContainer : trackerContainers) {
62 doPixel_( conf.getParameter<bool>(
"associatePixel") ),
63 doStrip_( conf.getParameter<bool>(
"associateStrip") ),
64 doTrackAssoc_( conf.getParameter<bool>(
"associateRecoTracks") ),
65 assocHitbySimTrack_(conf.existsAs<bool>(
"associateHitbySimTrack") ? conf.getParameter<bool>(
"associateHitbySimTrack") :
false) {
70 std::vector<std::string> trackerContainers(conf.
getParameter<std::vector<std::string> >(
"ROUList"));
71 cfTokens_.reserve(trackerContainers.size());
73 for(
auto const& trackerContainer : trackerContainers) {
103 for(
auto const& cfToken : config.
cfTokens_) {
106 if (theEvent.
getByToken(cfToken, cf_simhit)) {
108 for (
auto const& isim : *thisContainerHits) {
109 DetId theDet(isim.detUnitId());
119 if(theEvent.
getByToken(simHitToken, simHits)) {
120 for (
auto const& isim : *simHits) {
121 DetId theDet(isim.detUnitId());
129 const char*
const highTag =
"HighTof";
133 unsigned int collectionIndex = 0;
134 for(
auto const& cfToken : config.
cfTokens_) {
138 if (theEvent.
getByToken(cfToken, cf_simhit)) {
146 for (
auto const& isim : *thisContainerHits) {
147 DetId theDet(isim.detUnitId());
148 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
150 SimHitMap[SimHitCollMap[theSubDetTofBin]].push_back(isim);
161 if(theEvent.
getByToken(simHitToken, simHits)) {
168 for (
auto const& isim : *simHits) {
169 DetId theDet(isim.detUnitId());
170 theSubDetTofBin = std::make_pair(theDet.subdetId(), tofBin);
174 SimHitMap[SimHitCollMap[theSubDetTofBin]].push_back(isim);
191 std::vector<PSimHit>
result;
196 std::vector<SimHitIdpr> simtrackid;
197 std::vector<simhitAddr> simhitCFPos;
201 uint32_t detID = detid.
rawId();
220 if(dynamic_cast<const SiStripMatchedRecHit2D *>(&thit)) {
221 for(
auto const& theSimHitAddr : simhitCFPos) {
223 simhit_map::const_iterator it =
SimHitMap.find(theSimHitCollID);
225 unsigned int theSimHitIndex = theSimHitAddr.second;
226 if (theSimHitIndex < (it->second).size()) {
227 const PSimHit& theSimHit = (it->second)[theSimHitIndex];
229 unsigned int simHitid = theSimHit.
trackId();
231 for(
auto const&
id : simtrackid) {
232 if(simHitid ==
id.
first && simHiteid ==
id.
second) {
233 result.push_back(theSimHit);
244 for(
auto const& theSimHitAddr : simhitCFPos) {
246 simhit_map::const_iterator it =
SimHitMap.find(theSimHitCollID);
248 unsigned int theSimHitIndex = theSimHitAddr.second;
249 if (theSimHitIndex < (it->second).size()) {
250 result.push_back((it->second)[theSimHitIndex]);
264 std::map<unsigned int, std::vector<PSimHit> >::const_iterator it =
SimHitMap.find(detID);
266 vector<PSimHit>::const_iterator simHitIter = (it->second).
begin();
267 vector<PSimHit>::const_iterator simHitIterEnd = (it->second).
end();
268 for (;simHitIter != simHitIterEnd; ++simHitIter) {
269 const PSimHit& ihit = *simHitIter;
270 unsigned int simHitid = ihit.
trackId();
274 for(
auto id : simtrackid) {
275 if(simHitid ==
id.
first && simHiteid ==
id.
second) {
279 result.push_back(ihit);
289 std::map<unsigned int, std::vector<PSimHit> >::const_iterator itrphi =
291 std::map<unsigned int, std::vector<PSimHit> >::const_iterator itster =
294 std::vector<PSimHit> simHitVector = itrphi->second;
295 simHitVector.insert(simHitVector.end(),(itster->second).
begin(),(itster->second).
end());
296 vector<PSimHit>::const_iterator simHitIter = simHitVector.begin();
297 vector<PSimHit>::const_iterator simHitIterEnd = simHitVector.end();
298 for (;simHitIter != simHitIterEnd; ++simHitIter) {
299 const PSimHit& ihit = *simHitIter;
300 unsigned int simHitid = ihit.
trackId();
302 for(
auto const&
id : simtrackid) {
303 if(simHitid ==
id.
first && simHiteid ==
id.
second) {
307 result.push_back(ihit);
320 std::vector< SimHitIdpr > simhitid;
326 std::vector<simhitAddr>* simhitCFPos)
const 346 dynamic_cast<const SiStripRecHit2D *>(&thit))
352 dynamic_cast<const SiStripRecHit1D *>(&thit))
358 dynamic_cast<const SiStripMatchedRecHit2D *>(&thit))
364 dynamic_cast<const ProjectedSiStripRecHit2D *>(&thit))
377 if(
const SiPixelRecHit * rechit = dynamic_cast<const SiPixelRecHit *>(&thit))
401 std::vector<SimHitIdpr>& simtrackid,
402 std::vector<PSimHit>& simhit)
const {
403 std::vector<simhitAddr> simhitCFPos;
406 for(
auto const& theSimHitAddr : simhitCFPos ) {
408 simhit_map::const_iterator it =
SimHitMap.find(theSimHitCollID);
410 unsigned int theSimHitIndex = theSimHitAddr.second;
411 if (theSimHitIndex < (it->second).size()) simhit.push_back((it->second)[theSimHitIndex]);
423 std::vector<SimHitIdpr>& simtrackid,
424 std::vector<simhitAddr>* simhitCFPos)
const {
426 uint32_t detID = detid.
rawId();
434 int last = first + clusiz;
439 std::vector<SimHitIdpr> idcachev;
440 std::vector<simhitAddr> CFposcachev;
444 channel = (
int)(linkiter->channel());
445 if( channel >= first && channel < last ){
457 SimHitIdpr currentId(linkiter->SimTrackId(), linkiter->eventId());
462 if(
find(idcachev.begin(),idcachev.end(),currentId ) == idcachev.end()){
469 idcachev.push_back(currentId);
470 simtrackid.push_back(currentId);
473 if (simhitCFPos != 0) {
476 unsigned int currentCFPos = linkiter->CFposition();
477 unsigned int tofBin = linkiter->TofBin();
479 simhit_collectionMap::const_iterator it =
SimHitCollMap.find(theSubDetTofBin);
481 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
483 if(
find(CFposcachev.begin(), CFposcachev.end(), currentAddr ) == CFposcachev.end()) {
492 CFposcachev.push_back(currentAddr);
493 simhitCFPos->push_back(currentAddr);
501 edm::LogError(
"TrackerHitAssociator")<<
"no cluster reference attached";
508 std::vector<SimHitIdpr> matched_mono;
509 std::vector<SimHitIdpr> matched_st;
518 std::vector<SimHitIdpr> simtrackid;
519 if(!(matched_mono.empty() || matched_st.empty())){
520 std::vector<SimHitIdpr> idcachev;
521 for(
auto const& mhit: matched_mono){
523 if(
find(idcachev.begin(), idcachev.end(), mhit) == idcachev.end()) {
524 idcachev.push_back(mhit);
526 if(
find(matched_st.begin(), matched_st.end(), mhit) != matched_st.end()) {
527 simtrackid.push_back(mhit);
538 std::vector<simhitAddr>* simhitCFPos)
const 542 std::vector<SimHitIdpr> matched_mono;
550 std::vector<SimHitIdpr> & simtrackid,
551 std::vector<simhitAddr>* simhitCFPos)
const 557 uint32_t detID = detid.
rawId();
568 int minPixelRow = (*cluster).minPixelRow();
569 int maxPixelRow = (*cluster).maxPixelRow();
570 int minPixelCol = (*cluster).minPixelCol();
571 int maxPixelCol = (*cluster).maxPixelCol();
576 std::vector<SimHitIdpr> idcachev;
577 std::vector<simhitAddr> CFposcachev;
578 for( ; linkiter != linkEnd; ++linkiter) {
582 if( pixel_coord.first <= maxPixelRow &&
583 pixel_coord.first >= minPixelRow &&
584 pixel_coord.second <= maxPixelCol &&
585 pixel_coord.second >= minPixelCol ) {
588 SimHitIdpr currentId(linkiter->SimTrackId(), linkiter->eventId());
589 if(
find(idcachev.begin(),idcachev.end(),currentId) == idcachev.end()){
590 simtrackid.push_back(currentId);
591 idcachev.push_back(currentId);
594 if (simhitCFPos != 0) {
597 unsigned int currentCFPos = linkiter->CFposition();
598 unsigned int tofBin = linkiter->TofBin();
600 simhit_collectionMap::const_iterator it =
SimHitCollMap.find(theSubDetTofBin);
602 simhitAddr currentAddr = std::make_pair(it->second, currentCFPos);
603 if(
find(CFposcachev.begin(), CFposcachev.end(), currentAddr) == CFposcachev.end()) {
604 CFposcachev.push_back(currentAddr);
605 simhitCFPos->push_back(currentAddr);
614 edm::LogError(
"TrackerHitAssociator")<<
"no Pixel cluster reference attached";
621 std::vector<const TrackingRecHit*> componenthits = multirechit->
recHits();
623 int size=multirechit->
weights().size(), idmostprobable=0;
626 if(multirechit->
weight(
i)>multirechit->
weight(idmostprobable)) idmostprobable=
i;
633 std::vector<const TrackingRecHit*> componenthits = multirechit->
recHits();
634 int size=multirechit->
weights().size(), idmostprobable=0;
637 if(multirechit->
weight(
i)>multirechit->
weight(idmostprobable)) idmostprobable=
i;
640 std::vector< SimHitIdpr > simhitid;
641 associateHitId(*componenthits[idmostprobable], simhitid, simhitCFPos);
648 vector<SimHitIdpr> simtrackid;
652 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
void associatePixelRecHit(const SiPixelRecHit *pixelrechit, std::vector< SimHitIdpr > &simhitid, std::vector< simhitAddr > *simhitCFPos=0) const
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_
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)
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
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