CMS 3D CMS Logo

RPCHitAssociator.cc
Go to the documentation of this file.
3 
4 using namespace std;
5 
6 // Constructor
8  : RPCdigisimlinkTag(conf.getParameter<edm::InputTag>("RPCdigisimlinkTag")),
9  // CrossingFrame used or not ?
10  RPCsimhitsTag(conf.getParameter<edm::InputTag>("RPCsimhitsTag")),
11  RPCsimhitsXFTag(conf.getParameter<edm::InputTag>("RPCsimhitsXFTag")),
12  crossingframe(conf.getParameter<bool>("crossingframe")) {
13  if (crossingframe) {
15  } else if (!RPCsimhitsTag.label().empty()) {
17  }
18 
20 }
21 
23 
25 
26 {
28  LogTrace("RPCHitAssociator") << "getting CrossingFrame<PSimHit> collection - " << theConfig.RPCsimhitsXFTag;
30 
31  std::unique_ptr<MixCollection<PSimHit>> RPCsimhits(new MixCollection<PSimHit>(&cf));
32  LogTrace("RPCHitAssociator") << "... size = " << RPCsimhits->size();
33 
34  // MixCollection<PSimHit> & simHits = *hits;
35 
36  for (MixCollection<PSimHit>::MixItr hitItr = RPCsimhits->begin(); hitItr != RPCsimhits->end(); ++hitItr) {
37  _SimHitMap[hitItr->detUnitId()].push_back(*hitItr);
38  }
39 
40  } else if (!theConfig.RPCsimhitsTag.label().empty()) {
41  LogTrace("RPCHitAssociator") << "getting PSimHit collection - " << theConfig.RPCsimhitsTag;
42  edm::PSimHitContainer const &RPCsimhits = e.get(theConfig.RPCsimhitsToken_);
43  LogTrace("RPCHitAssociator") << "... size = " << RPCsimhits.size();
44 
45  // arrange the hits by detUnit
46  for (edm::PSimHitContainer::const_iterator hitItr = RPCsimhits.begin(); hitItr != RPCsimhits.end(); ++hitItr) {
47  _SimHitMap[hitItr->detUnitId()].push_back(*hitItr);
48  }
49  }
50 
51  LogTrace("RPCHitAssociator") << "getting RPCDigiSimLink collection - " << theConfig.RPCdigisimlinkTag;
53 }
54 // end of constructor
55 
56 std::vector<RPCHitAssociator::SimHitIdpr> RPCHitAssociator::associateRecHit(const TrackingRecHit &hit) const {
57  std::vector<SimHitIdpr> matched;
58 
59  const TrackingRecHit *hitp = &hit;
60  const RPCRecHit *rpcrechit = dynamic_cast<const RPCRecHit *>(hitp);
61 
62  if (rpcrechit) {
63  RPCDetId rpcDetId = rpcrechit->rpcId();
64  int fstrip = rpcrechit->firstClusterStrip();
65  int cls = rpcrechit->clusterSize();
66  int bx = rpcrechit->BunchX();
67 
68  for (int i = fstrip; i < fstrip + cls; ++i) {
69  std::set<RPCDigiSimLink> links = findRPCDigiSimLink(rpcDetId.rawId(), i, bx);
70 
71  if (links.empty())
72  LogTrace("RPCHitAssociator") << "*** WARNING in RPCHitAssociator::associateRecHit, RPCRecHit " << *rpcrechit
73  << ", strip " << i << " has no associated RPCDigiSimLink !" << endl;
74 
75  for (std::set<RPCDigiSimLink>::iterator itlink = links.begin(); itlink != links.end(); ++itlink) {
76  SimHitIdpr currentId(itlink->getTrackId(), itlink->getEventId());
77  if (find(matched.begin(), matched.end(), currentId) == matched.end())
78  matched.push_back(currentId);
79  }
80  }
81 
82  } else
83  LogTrace("RPCHitAssociator") << "*** WARNING in RPCHitAssociator::associateRecHit, null "
84  "dynamic_cast !";
85 
86  return matched;
87 }
88 
89 std::set<RPCDigiSimLink> RPCHitAssociator::findRPCDigiSimLink(uint32_t rpcDetId, int strip, int bx) const {
90  std::set<RPCDigiSimLink> links;
91 
93  itlink != _thelinkDigis->end();
94  itlink++) {
95  for (edm::DetSet<RPCDigiSimLink>::const_iterator digi_iter = itlink->data.begin(); digi_iter != itlink->data.end();
96  ++digi_iter) {
97  uint32_t detid = digi_iter->getDetUnitId();
98  int str = digi_iter->getStrip();
99  int bunchx = digi_iter->getBx();
100 
101  if (detid == rpcDetId && str == strip && bunchx == bx) {
102  links.insert(*digi_iter);
103  }
104  }
105  }
106 
107  return links;
108 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
Config(const edm::ParameterSet &, edm::ConsumesCollector ic)
std::set< RPCDigiSimLink > findRPCDigiSimLink(uint32_t rpcDetId, int strip, int bx) const
RPCHitAssociator(const edm::Event &e, const Config &conf)
edm::EDGetTokenT< CrossingFrame< PSimHit > > RPCsimhitsXFToken_
std::string const & label() const
Definition: InputTag.h:36
edm::Handle< edm::DetSetVector< RPCDigiSimLink > > _thelinkDigis
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
#define LogTrace(id)
void initEvent(const edm::Event &)
RPCDetId rpcId() const
Return the rpcId.
Definition: RPCRecHit.h:71
std::vector< SimHitIdpr > associateRecHit(const TrackingRecHit &hit) const
int BunchX() const
Definition: RPCRecHit.h:73
std::map< unsigned int, edm::PSimHitContainer > _SimHitMap
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:316
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int clusterSize() const
Definition: RPCRecHit.h:77
Config const & theConfig
std::pair< uint32_t, EncodedEventId > SimHitIdpr
edm::EDGetTokenT< edm::PSimHitContainer > RPCsimhitsToken_
int firstClusterStrip() const
Definition: RPCRecHit.h:75
HLT enums.
edm::EDGetTokenT< edm::DetSetVector< RPCDigiSimLink > > RPCdigisimlinkToken_
Definition: Config.py:1
edm::InputTag RPCdigisimlinkTag
std::vector< PSimHit > PSimHitContainer
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:305
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
#define str(s)