CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCHitAssociator.cc
Go to the documentation of this file.
2 
3 using namespace std;
4 
5 // Constructor
7 
8  RPCdigisimlinkTag(conf.getParameter<edm::InputTag>("RPCdigisimlinkTag")),
9  // CrossingFrame used or not ?
10  crossingframe(conf.getParameter<bool>("crossingframe")),
11  RPCsimhitsTag(conf.getParameter<edm::InputTag>("RPCsimhitsTag")),
12  RPCsimhitsXFTag(conf.getParameter<edm::InputTag>("RPCsimhitsXFTag"))
13 
14 {
15  if (crossingframe) {
16 
18  LogTrace("RPCHitAssociator") <<"getting CrossingFrame<PSimHit> collection - "<<RPCsimhitsXFTag;
20 
21  std::auto_ptr<MixCollection<PSimHit> >
22  RPCsimhits( new MixCollection<PSimHit>(cf.product()) );
23  LogTrace("RPCHitAssociator") <<"... size = "<<RPCsimhits->size();
24 
25  // MixCollection<PSimHit> & simHits = *hits;
26 
27  for(MixCollection<PSimHit>::MixItr hitItr = RPCsimhits->begin();
28  hitItr != RPCsimhits->end(); ++hitItr)
29  {
30  _SimHitMap[hitItr->detUnitId()].push_back(*hitItr);
31  }
32 
33  } else if (!RPCsimhitsTag.label().empty()) {
35  LogTrace("RPCHitAssociator") <<"getting PSimHit collection - "<<RPCsimhitsTag;
36  e.getByLabel(RPCsimhitsTag, RPCsimhits);
37  LogTrace("RPCHitAssociator") <<"... size = "<<RPCsimhits->size();
38 
39  // arrange the hits by detUnit
40  for(edm::PSimHitContainer::const_iterator hitItr = RPCsimhits->begin();
41  hitItr != RPCsimhits->end(); ++hitItr)
42  {
43  _SimHitMap[hitItr->detUnitId()].push_back(*hitItr);
44  }
45  }
46 
48  LogTrace("RPCHitAssociator") <<"getting RPCDigiSimLink collection - "<<RPCdigisimlinkTag;
49  e.getByLabel(RPCdigisimlinkTag, thelinkDigis);
50  _thelinkDigis = thelinkDigis;
51 }
52 // end of constructor
53 
54 std::vector<RPCHitAssociator::SimHitIdpr> RPCHitAssociator::associateRecHit(const TrackingRecHit & hit) {
55 
56  std::vector<SimHitIdpr> matched;
57 
58  const TrackingRecHit * hitp = &hit;
59  const RPCRecHit * rpcrechit = dynamic_cast<const RPCRecHit *>(hitp);
60 
61  if (rpcrechit) {
62 
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()) edm::LogWarning("RPCHitAssociator")
72  <<"*** WARNING in RPCHitAssociator::associateRecHit, RPCRecHit "<<*rpcrechit<<", strip "<<i<<" has no associated RPCDigiSimLink !"<<endl;
73 
74  for(std::set<RPCDigiSimLink>::iterator itlink = links.begin(); itlink != links.end(); ++itlink) {
75  SimHitIdpr currentId(itlink->getTrackId(),itlink->getEventId());
76  if(find(matched.begin(),matched.end(),currentId ) == matched.end())
77  matched.push_back(currentId);
78  }
79  }
80 
81  } else edm::LogWarning("RPCHitAssociator")<<"*** WARNING in RPCHitAssociator::associateRecHit, null dynamic_cast !";
82 
83  return matched;
84 }
85 
86 std::set<RPCDigiSimLink> RPCHitAssociator::findRPCDigiSimLink(uint32_t rpcDetId, int strip, int bx){
87 
88  std::set<RPCDigiSimLink> links;
89 
91  for(edm::DetSet<RPCDigiSimLink>::const_iterator digi_iter=itlink->data.begin();digi_iter != itlink->data.end();++digi_iter){
92 
93  uint32_t detid = digi_iter->getDetUnitId();
94  int str = digi_iter->getStrip();
95  int bunchx = digi_iter->getBx();
96 
97  if(detid == rpcDetId && str == strip && bunchx == bx){
98  links.insert(*digi_iter);
99  }
100 
101  }
102  }
103 
104  return links;
105 }
106 
107 
int firstClusterStrip() const
Definition: RPCRecHit.h:107
int i
Definition: DBlmapReader.cc:9
edm::InputTag RPCdigisimlinkTag
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
std::set< RPCDigiSimLink > findRPCDigiSimLink(uint32_t rpcDetId, int strip, int bx)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
RPCHitAssociator(const edm::Event &, const edm::EventSetup &, const edm::ParameterSet &)
int clusterSize() const
Definition: RPCRecHit.h:111
RPCDetId rpcId() const
Return the rpcId.
Definition: RPCRecHit.h:99
std::map< unsigned int, edm::PSimHitContainer > _SimHitMap
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:356
#define LogTrace(id)
tuple conf
Definition: dbtoconf.py:185
edm::InputTag RPCsimhitsTag
edm::InputTag RPCsimhitsXFTag
T const * product() const
Definition: Handle.h:74
std::pair< uint32_t, EncodedEventId > SimHitIdpr
std::string const & label() const
Definition: InputTag.h:42
int BunchX() const
Definition: RPCRecHit.h:103
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:341
collection_type::const_iterator const_iterator
Definition: DetSet.h:34
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:106
std::vector< SimHitIdpr > associateRecHit(const TrackingRecHit &hit)
edm::Handle< edm::DetSetVector< RPCDigiSimLink > > _thelinkDigis