CMS 3D CMS Logo

RPCPointVsRecHit.cc
Go to the documentation of this file.
3 
6 
8 
9 using namespace std;
10 
12 
14  refHitToken_ = consumes<RPCRecHitCollection>(pset.getParameter<edm::InputTag>("refHit"));
15  recHitToken_ = consumes<RPCRecHitCollection>(pset.getParameter<edm::InputTag>("recHit"));
16 
17  subDir_ = pset.getParameter<std::string>("subDir");
18 
19  rpcGeomToken_ = esConsumes();
20 }
21 
23  // Get the RPC Geometry
24  auto rpcGeom = eventSetup.getHandle(rpcGeomToken_);
25 
26  // Retrieve RefHits from the event
28  if (!event.getByToken(refHitToken_, refHitHandle)) {
29  edm::LogInfo("RPCPointVsRecHit") << "Cannot find reference hit collection\n";
30  return;
31  }
32 
33  // Retrieve RecHits from the event
35  if (!event.getByToken(recHitToken_, recHitHandle)) {
36  edm::LogInfo("RPCPointVsRecHit") << "Cannot find recHit collection\n";
37  return;
38  }
39 
40  typedef RPCRecHitCollection::const_iterator RecHitIter;
41 
42  // Loop over refHits, fill histograms which does not need associations
43  int nRefHitBarrel = 0, nRefHitEndcap = 0;
44  for (RecHitIter refHitIter = refHitHandle->begin(); refHitIter != refHitHandle->end(); ++refHitIter) {
45  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
46  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(detId()));
47  if (!roll)
48  continue;
49 
50  const int region = roll->id().region();
51  const int ring = roll->id().ring();
52  // const int sector = roll->id().sector();
53  const int station = roll->id().station();
54  // const int layer = roll->id().layer();
55  // const int subSector = roll->id().subsector();
56 
57  if (region == 0) {
58  h_.refHitOccupancyBarrel_wheel->Fill(ring);
59  h_.refHitOccupancyBarrel_station->Fill(station);
60  h_.refHitOccupancyBarrel_wheel_station->Fill(ring, station);
61  } else {
62  h_.refHitOccupancyEndcap_disk->Fill(region * station);
63  h_.refHitOccupancyEndcap_disk_ring->Fill(region * station, ring);
64  }
65  }
66  h_.nRefHitBarrel->Fill(nRefHitBarrel);
67  h_.nRefHitEndcap->Fill(nRefHitEndcap);
68 
69  // Loop over recHits, fill histograms which does not need associations
70  int sumClusterSizeBarrel = 0, sumClusterSizeEndcap = 0;
71  int nRecHitBarrel = 0, nRecHitEndcap = 0;
72  for (RecHitIter recHitIter = recHitHandle->begin(); recHitIter != recHitHandle->end(); ++recHitIter) {
73  const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
74  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(detId()));
75  if (!roll)
76  continue;
77 
78  const int region = roll->id().region();
79  const int ring = roll->id().ring();
80  // const int sector = roll->id().sector();
81  const int station = (roll->id().station());
82  // const int layer = roll->id().layer();
83  // const int subSector = roll->id().subsector();
84 
85  h_.clusterSize->Fill(recHitIter->clusterSize());
86 
87  if (region == 0) {
88  ++nRecHitBarrel;
89  sumClusterSizeBarrel += recHitIter->clusterSize();
90  h_.clusterSizeBarrel->Fill(recHitIter->clusterSize());
91  h_.recHitOccupancyBarrel_wheel->Fill(ring);
92  h_.recHitOccupancyBarrel_station->Fill(station);
93  h_.recHitOccupancyBarrel_wheel_station->Fill(ring, station);
94  } else {
95  ++nRecHitEndcap;
96  sumClusterSizeEndcap += recHitIter->clusterSize();
97  h_.clusterSizeEndcap->Fill(recHitIter->clusterSize());
98  h_.recHitOccupancyEndcap_disk->Fill(region * station);
99  h_.recHitOccupancyEndcap_disk_ring->Fill(ring, region * station);
100  }
101  }
102  const double nRecHit = nRecHitBarrel + nRecHitEndcap;
103  h_.nRecHitBarrel->Fill(nRecHitBarrel);
104  h_.nRecHitEndcap->Fill(nRecHitEndcap);
105  if (nRecHit > 0) {
106  const int sumClusterSize = sumClusterSizeBarrel + sumClusterSizeEndcap;
107  h_.avgClusterSize->Fill(double(sumClusterSize) / nRecHit);
108 
109  if (nRecHitBarrel > 0) {
110  h_.avgClusterSizeBarrel->Fill(double(sumClusterSizeBarrel) / nRecHitBarrel);
111  }
112  if (nRecHitEndcap > 0) {
113  h_.avgClusterSizeEndcap->Fill(double(sumClusterSizeEndcap) / nRecHitEndcap);
114  }
115  }
116 
117  // Start matching RefHits to RecHits
118  typedef std::map<RecHitIter, RecHitIter> RecToRecHitMap;
119  RecToRecHitMap refToRecHitMap;
120 
121  for (RecHitIter refHitIter = refHitHandle->begin(); refHitIter != refHitHandle->end(); ++refHitIter) {
122  const RPCDetId refDetId = static_cast<const RPCDetId>(refHitIter->rpcId());
123  const RPCRoll *refRoll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(refDetId));
124  if (!refRoll)
125  continue;
126 
127  const double refX = refHitIter->localPosition().x();
128 
129  for (RecHitIter recHitIter = recHitHandle->begin(); recHitIter != recHitHandle->end(); ++recHitIter) {
130  const RPCDetId recDetId = static_cast<const RPCDetId>(recHitIter->rpcId());
131  const RPCRoll *recRoll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(recDetId));
132  if (!recRoll)
133  continue;
134 
135  if (refDetId != recDetId)
136  continue;
137 
138  const double recX = recHitIter->localPosition().x();
139  const double newDx = fabs(recX - refX);
140 
141  // Associate RefHit to RecHit
142  RecToRecHitMap::const_iterator prevRefToReco = refToRecHitMap.find(refHitIter);
143  if (prevRefToReco == refToRecHitMap.end()) {
144  refToRecHitMap.insert(std::make_pair(refHitIter, recHitIter));
145  } else {
146  const double oldDx = fabs(prevRefToReco->second->localPosition().x() - refX);
147 
148  if (newDx < oldDx) {
149  refToRecHitMap[refHitIter] = recHitIter;
150  }
151  }
152  }
153  }
154 
155  // Now we have refHit-recHit mapping
156  // So we can fill up relavant histograms
157  for (RecToRecHitMap::const_iterator match = refToRecHitMap.begin(); match != refToRecHitMap.end(); ++match) {
158  RecHitIter refHitIter = match->first;
159  RecHitIter recHitIter = match->second;
160 
161  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
162  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(detId));
163 
164  const int region = roll->id().region();
165  const int ring = roll->id().ring();
166  // const int sector = roll->id().sector();
167  const int station = roll->id().station();
168  // const int layer = roll->id().layer();
169  // const int subsector = roll->id().subsector();
170 
171  const double refX = refHitIter->localPosition().x();
172  const double recX = recHitIter->localPosition().x();
173  const double errX = sqrt(recHitIter->localPositionError().xx());
174  const double dX = recX - refX;
175  const double pull = errX == 0 ? -999 : dX / errX;
176 
177  // const GlobalPoint refPos = roll->toGlobal(refHitIter->localPosition());
178  // const GlobalPoint recPos = roll->toGlobal(recHitIter->localPosition());
179 
180  if (region == 0) {
181  h_.resBarrel->Fill(dX);
182  h_.pullBarrel->Fill(pull);
183  h_.matchOccupancyBarrel_wheel->Fill(ring);
184  h_.matchOccupancyBarrel_station->Fill(station);
185  h_.matchOccupancyBarrel_wheel_station->Fill(ring, station);
186 
187  h_.res_wheel_res->Fill(ring, dX);
188  h_.res_station_res->Fill(station, dX);
189  h_.pull_wheel_pull->Fill(ring, pull);
190  h_.pull_station_pull->Fill(station, pull);
191  } else {
192  h_.resEndcap->Fill(dX);
193  h_.pullEndcap->Fill(pull);
194  h_.matchOccupancyEndcap_disk->Fill(region * station);
195  h_.matchOccupancyEndcap_disk_ring->Fill(region * station, ring);
196 
197  h_.res_disk_res->Fill(region * station, dX);
198  h_.res_ring_res->Fill(ring, dX);
199  h_.pull_disk_pull->Fill(region * station, pull);
200  h_.pull_ring_pull->Fill(ring, pull);
201  }
202  }
203 }
204 
206  edm::Run const &run,
207  edm::EventSetup const &eventSetup) {
208  // Book MonitorElements
209  h_.bookHistograms(booker, subDir_);
210 }
211 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:43
T sqrt(T t)
Definition: SSEVec.h:23
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Log< level::Info, false > LogInfo
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup) override
float dX(const MatchPair &match)
RPCPointVsRecHit(const edm::ParameterSet &pset)
RPCPointVsRecHit::MonitorElement * MEP
Definition: event.py:1
Definition: Run.h:45