CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RPCPointVsRecHit.cc
Go to the documentation of this file.
3 
6 
10 
11 using namespace std;
12 
14 
16 {
17  refHitToken_ = consumes<RPCRecHitCollection>(pset.getParameter<edm::InputTag>("refHit"));
18  recHitToken_ = consumes<RPCRecHitCollection>(pset.getParameter<edm::InputTag>("recHit"));
19 
21  if ( !dbe_ )
22  {
23  edm::LogError("RPCPointVsRecHit") << "No DQMStore instance\n";
24  return;
25  }
26 
27  // Book MonitorElements
28  const std::string subDir = pset.getParameter<std::string>("subDir");
29  h_.bookHistograms(dbe_, subDir);
30 }
31 
33 {
34 }
35 
37 {
38 }
39 
41 {
42 }
43 
45 {
46  if ( !dbe_ )
47  {
48  edm::LogError("RPCPointVsRecHit") << "No DQMStore instance\n";
49  return;
50  }
51 
52  // Get the RPC Geometry
54  eventSetup.get<MuonGeometryRecord>().get(rpcGeom);
55 
56  // Retrieve RefHits from the event
58  if ( !event.getByToken(refHitToken_, refHitHandle) )
59  {
60  edm::LogInfo("RPCPointVsRecHit") << "Cannot find reference hit collection\n";
61  return;
62  }
63 
64  // Retrieve RecHits from the event
66  if ( !event.getByToken(recHitToken_, recHitHandle) )
67  {
68  edm::LogInfo("RPCPointVsRecHit") << "Cannot find recHit collection\n";
69  return;
70  }
71 
72  typedef RPCRecHitCollection::const_iterator RecHitIter;
73 
74  // Loop over refHits, fill histograms which does not need associations
75  int nRefHitBarrel = 0, nRefHitEndcap = 0;
76  for ( RecHitIter refHitIter = refHitHandle->begin();
77  refHitIter != refHitHandle->end(); ++refHitIter )
78  {
79  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
80  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
81  if ( !roll ) continue;
82 
83  const int region = roll->id().region();
84  const int ring = roll->id().ring();
85  //const int sector = roll->id().sector();
86  const int station = roll->id().station();
87  //const int layer = roll->id().layer();
88  //const int subSector = roll->id().subsector();
89 
90  if ( region == 0 )
91  {
92  h_.refHitOccupancyBarrel_wheel->Fill(ring);
93  h_.refHitOccupancyBarrel_station->Fill(station);
94  h_.refHitOccupancyBarrel_wheel_station->Fill(ring, station);
95  }
96  else
97  {
98  h_.refHitOccupancyEndcap_disk->Fill(region*station);
99  h_.refHitOccupancyEndcap_disk_ring->Fill(region*station, ring);
100  }
101 
102  }
103  h_.nRefHitBarrel->Fill(nRefHitBarrel);
104  h_.nRefHitEndcap->Fill(nRefHitEndcap);
105 
106  // Loop over recHits, fill histograms which does not need associations
107  int sumClusterSizeBarrel = 0, sumClusterSizeEndcap = 0;
108  int nRecHitBarrel = 0, nRecHitEndcap = 0;
109  for ( RecHitIter recHitIter = recHitHandle->begin();
110  recHitIter != recHitHandle->end(); ++recHitIter )
111  {
112  const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
113  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
114  if ( !roll ) continue;
115 
116  const int region = roll->id().region();
117  const int ring = roll->id().ring();
118  //const int sector = roll->id().sector();
119  const int station = (roll->id().station());
120  //const int layer = roll->id().layer();
121  //const int subSector = roll->id().subsector();
122 
123  h_.clusterSize->Fill(recHitIter->clusterSize());
124 
125  if ( region == 0 )
126  {
127  ++nRecHitBarrel;
128  sumClusterSizeBarrel += recHitIter->clusterSize();
129  h_.clusterSizeBarrel->Fill(recHitIter->clusterSize());
130  h_.recHitOccupancyBarrel_wheel->Fill(ring);
131  h_.recHitOccupancyBarrel_station->Fill(station);
132  h_.recHitOccupancyBarrel_wheel_station->Fill(ring, station);
133  }
134  else
135  {
136  ++nRecHitEndcap;
137  sumClusterSizeEndcap += recHitIter->clusterSize();
138  h_.clusterSizeEndcap->Fill(recHitIter->clusterSize());
139  h_.recHitOccupancyEndcap_disk->Fill(region*station);
140  h_.recHitOccupancyEndcap_disk_ring->Fill(ring, region*station);
141  }
142 
143  }
144  const double nRecHit = nRecHitBarrel+nRecHitEndcap;
145  h_.nRecHitBarrel->Fill(nRecHitBarrel);
146  h_.nRecHitEndcap->Fill(nRecHitEndcap);
147  if ( nRecHit > 0 )
148  {
149  const int sumClusterSize = sumClusterSizeBarrel+sumClusterSizeEndcap;
150  h_.avgClusterSize->Fill(double(sumClusterSize)/nRecHit);
151 
152  if ( nRecHitBarrel > 0 )
153  {
154  h_.avgClusterSizeBarrel->Fill(double(sumClusterSizeBarrel)/nRecHitBarrel);
155  }
156  if ( nRecHitEndcap > 0 )
157  {
158  h_.avgClusterSizeEndcap->Fill(double(sumClusterSizeEndcap)/nRecHitEndcap);
159  }
160  }
161 
162  // Start matching RefHits to RecHits
163  typedef std::map<RecHitIter, RecHitIter> RecToRecHitMap;
164  RecToRecHitMap refToRecHitMap;
165 
166  for ( RecHitIter refHitIter = refHitHandle->begin();
167  refHitIter != refHitHandle->end(); ++refHitIter )
168  {
169  const RPCDetId refDetId = static_cast<const RPCDetId>(refHitIter->rpcId());
170  const RPCRoll* refRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(refDetId));
171  if ( !refRoll ) continue;
172 
173  const double refX = refHitIter->localPosition().x();
174 
175  for ( RecHitIter recHitIter = recHitHandle->begin();
176  recHitIter != recHitHandle->end(); ++recHitIter )
177  {
178  const RPCDetId recDetId = static_cast<const RPCDetId>(recHitIter->rpcId());
179  const RPCRoll* recRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(recDetId));
180  if ( !recRoll ) continue;
181 
182  if ( refDetId != recDetId ) continue;
183 
184  const double recX = recHitIter->localPosition().x();
185  const double newDx = fabs(recX - refX);
186 
187  // Associate RefHit to RecHit
188  RecToRecHitMap::const_iterator prevRefToReco = refToRecHitMap.find(refHitIter);
189  if ( prevRefToReco == refToRecHitMap.end() )
190  {
191  refToRecHitMap.insert(std::make_pair(refHitIter, recHitIter));
192  }
193  else
194  {
195  const double oldDx = fabs(prevRefToReco->second->localPosition().x() - refX);
196 
197  if ( newDx < oldDx )
198  {
199  refToRecHitMap[refHitIter] = recHitIter;
200  }
201  }
202  }
203  }
204 
205  // Now we have refHit-recHit mapping
206  // So we can fill up relavant histograms
207  for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
208  match != refToRecHitMap.end(); ++match )
209  {
210  RecHitIter refHitIter = match->first;
211  RecHitIter recHitIter = match->second;
212 
213  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
214  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
215 
216  const int region = roll->id().region();
217  const int ring = roll->id().ring();
218  //const int sector = roll->id().sector();
219  const int station = roll->id().station();
220  //const int layer = roll->id().layer();
221  //const int subsector = roll->id().subsector();
222 
223  const double refX = refHitIter->localPosition().x();
224  const double recX = recHitIter->localPosition().x();
225  const double errX = sqrt(recHitIter->localPositionError().xx());
226  const double dX = recX - refX;
227  const double pull = errX == 0 ? -999 : dX/errX;
228 
229  //const GlobalPoint refPos = roll->toGlobal(refHitIter->localPosition());
230  //const GlobalPoint recPos = roll->toGlobal(recHitIter->localPosition());
231 
232  if ( region == 0 )
233  {
234  h_.resBarrel->Fill(dX);
235  h_.pullBarrel->Fill(pull);
236  h_.matchOccupancyBarrel_wheel->Fill(ring);
237  h_.matchOccupancyBarrel_station->Fill(station);
238  h_.matchOccupancyBarrel_wheel_station->Fill(ring, station);
239 
240  h_.res_wheel_res->Fill(ring, dX);
241  h_.res_station_res->Fill(station, dX);
242  h_.pull_wheel_pull->Fill(ring, pull);
243  h_.pull_station_pull->Fill(station, pull);
244  }
245  else
246  {
247  h_.resEndcap->Fill(dX);
248  h_.pullEndcap->Fill(pull);
249  h_.matchOccupancyEndcap_disk->Fill(region*station);
250  h_.matchOccupancyEndcap_disk_ring->Fill(region*station, ring);
251 
252  h_.res_disk_res->Fill(region*station, dX);
253  h_.res_ring_res->Fill(ring, dX);
254  h_.pull_disk_pull->Fill(region*station, pull);
255  h_.pull_ring_pull->Fill(ring, pull);
256  }
257  }
258 
259 /*
260  // Find Lost hits
261  for ( RecHitIter refHitIter = refHitHandle->begin();
262  refHitIter != refHitHandle->end(); ++refHitIter )
263  {
264  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
265  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
266 
267  const int region = roll->id().region();
268  const int ring = roll->id().ring();
269  //const int sector = roll->id().sector();
270  const int station = roll->id().station();
271  //const int layer = roll->id().layer();
272  //const int subsector = roll->id().subsector();
273 
274  bool matched = false;
275  for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
276  match != refToRecHitMap.end(); ++match )
277  {
278  if ( refHitIter == match->first )
279  {
280  matched = true;
281  break;
282  }
283  }
284 
285  if ( !matched )
286  {
287  if ( region == 0 )
288  {
289  h_.nUrefHitOccupancyBarrel_wheel->Fill(ring);
290  h_.nUrefHitOccupancyBarrel_wheel_ring->Fill(ring, station);
291  }
292  else
293  {
294  h_.nUnMatchedRefHit_disk->Fill(region*station);
295  h_.nUnMatchedRefHit_disk_ring->Fill(region*station, ring);
296  }
297  }
298  }
299 */
300 
301  // Find Noisy hits
302  for ( RecHitIter recHitIter = recHitHandle->begin();
303  recHitIter != recHitHandle->end(); ++recHitIter )
304  {
305  const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
306  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
307 
308  const int region = roll->id().region();
309  const int ring = roll->id().ring();
310  //const int sector = roll->id().sector();
311  const int station = roll->id().station();
312  //const int layer = roll->id().layer();
313  //const int subsector = roll->id().subsector();
314 
315  bool matched = false;
316  for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
317  match != refToRecHitMap.end(); ++match )
318  {
319  if ( recHitIter == match->second )
320  {
321  matched = true;
322  break;
323  }
324  }
325 
326  if ( !matched )
327  {
328  if ( region == 0 )
329  {
330  h_.umOccupancyBarrel_wheel->Fill(ring);
331  h_.umOccupancyBarrel_station->Fill(station);
332  h_.umOccupancyBarrel_wheel_station->Fill(ring, station);
333  }
334  else
335  {
336  h_.umOccupancyEndcap_disk->Fill(region*station);
337  h_.umOccupancyEndcap_disk_ring->Fill(region*station, ring);
338  }
339 
340  //const GlobalPoint pos = roll->toGlobal(recHitIter->localPosition());
341  //h_[HName::NoisyHitEta]->Fill(pos.eta());
342  }
343  }
344 }
345 
347 
T getParameter(std::string const &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:446
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
RPCDetId id() const
Definition: RPCRoll.cc:24
MonitorElement * MEP
int ring() const
Definition: RPCDetId.h:72
T sqrt(T t)
Definition: SSEVec.h:48
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
DQMStore * dbe_
const T & get() const
Definition: EventSetup.h:55
RPCPointVsRecHit(const edm::ParameterSet &pset)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96