Go to the documentation of this file.00001 #include "SimMuon/MCTruth/interface/RPCHitAssociator.h"
00002
00003 using namespace std;
00004
00005
00006 RPCHitAssociator::RPCHitAssociator(const edm::Event& e, const edm::EventSetup& eventSetup, const edm::ParameterSet& conf):
00007
00008 RPCdigisimlinkTag(conf.getParameter<edm::InputTag>("RPCdigisimlinkTag")),
00009
00010 crossingframe(conf.getParameter<bool>("crossingframe")),
00011 RPCsimhitsTag(conf.getParameter<edm::InputTag>("RPCsimhitsTag")),
00012 RPCsimhitsXFTag(conf.getParameter<edm::InputTag>("RPCsimhitsXFTag"))
00013
00014 {
00015 if (crossingframe) {
00016
00017 edm::Handle<CrossingFrame<PSimHit> > cf;
00018 LogTrace("RPCHitAssociator") <<"getting CrossingFrame<PSimHit> collection - "<<RPCsimhitsXFTag;
00019 e.getByLabel(RPCsimhitsXFTag, cf);
00020
00021 std::auto_ptr<MixCollection<PSimHit> >
00022 RPCsimhits( new MixCollection<PSimHit>(cf.product()) );
00023 LogTrace("RPCHitAssociator") <<"... size = "<<RPCsimhits->size();
00024
00025
00026
00027 for(MixCollection<PSimHit>::MixItr hitItr = RPCsimhits->begin();
00028 hitItr != RPCsimhits->end(); ++hitItr)
00029 {
00030 _SimHitMap[hitItr->detUnitId()].push_back(*hitItr);
00031 }
00032
00033 } else if (!RPCsimhitsTag.label().empty()) {
00034 edm::Handle<edm::PSimHitContainer> RPCsimhits;
00035 LogTrace("RPCHitAssociator") <<"getting PSimHit collection - "<<RPCsimhitsTag;
00036 e.getByLabel(RPCsimhitsTag, RPCsimhits);
00037 LogTrace("RPCHitAssociator") <<"... size = "<<RPCsimhits->size();
00038
00039
00040 for(edm::PSimHitContainer::const_iterator hitItr = RPCsimhits->begin();
00041 hitItr != RPCsimhits->end(); ++hitItr)
00042 {
00043 _SimHitMap[hitItr->detUnitId()].push_back(*hitItr);
00044 }
00045 }
00046
00047 edm::Handle< edm::DetSetVector<RPCDigiSimLink> > thelinkDigis;
00048 LogTrace("RPCHitAssociator") <<"getting RPCDigiSimLink collection - "<<RPCdigisimlinkTag;
00049 e.getByLabel(RPCdigisimlinkTag, thelinkDigis);
00050 _thelinkDigis = thelinkDigis;
00051 }
00052
00053
00054 std::vector<RPCHitAssociator::SimHitIdpr> RPCHitAssociator::associateRecHit(const TrackingRecHit & hit) {
00055
00056 std::vector<SimHitIdpr> matched;
00057
00058 const TrackingRecHit * hitp = &hit;
00059 const RPCRecHit * rpcrechit = dynamic_cast<const RPCRecHit *>(hitp);
00060
00061 if (rpcrechit) {
00062
00063 RPCDetId rpcDetId = rpcrechit->rpcId();
00064 int fstrip = rpcrechit->firstClusterStrip();
00065 int cls = rpcrechit->clusterSize();
00066 int bx = rpcrechit->BunchX();
00067
00068 for(int i = fstrip; i < fstrip+cls; ++i) {
00069 std::set<RPCDigiSimLink> links = findRPCDigiSimLink(rpcDetId.rawId(),i,bx);
00070
00071 if (links.empty()) edm::LogWarning("RPCHitAssociator")
00072 <<"*** WARNING in RPCHitAssociator::associateRecHit, RPCRecHit "<<*rpcrechit<<", strip "<<i<<" has no associated RPCDigiSimLink !"<<endl;
00073
00074 for(std::set<RPCDigiSimLink>::iterator itlink = links.begin(); itlink != links.end(); ++itlink) {
00075 SimHitIdpr currentId(itlink->getTrackId(),itlink->getEventId());
00076 if(find(matched.begin(),matched.end(),currentId ) == matched.end())
00077 matched.push_back(currentId);
00078 }
00079 }
00080
00081 } else edm::LogWarning("RPCHitAssociator")<<"*** WARNING in RPCHitAssociator::associateRecHit, null dynamic_cast !";
00082
00083 return matched;
00084 }
00085
00086 std::set<RPCDigiSimLink> RPCHitAssociator::findRPCDigiSimLink(uint32_t rpcDetId, int strip, int bx){
00087
00088 std::set<RPCDigiSimLink> links;
00089
00090 for (edm::DetSetVector<RPCDigiSimLink>::const_iterator itlink = _thelinkDigis->begin(); itlink != _thelinkDigis->end(); itlink++){
00091 for(edm::DetSet<RPCDigiSimLink>::const_iterator digi_iter=itlink->data.begin();digi_iter != itlink->data.end();++digi_iter){
00092
00093 uint32_t detid = digi_iter->getDetUnitId();
00094 int str = digi_iter->getStrip();
00095 int bunchx = digi_iter->getBx();
00096
00097 if(detid == rpcDetId && str == strip && bunchx == bx){
00098 links.insert(*digi_iter);
00099 }
00100
00101 }
00102 }
00103
00104 return links;
00105 }
00106
00107