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 
20  subDir_ = pset.getParameter<std::string>("subDir");
21 }
22 
24 {
25  // Get the RPC Geometry
27  eventSetup.get<MuonGeometryRecord>().get(rpcGeom);
28 
29  // Retrieve RefHits from the event
31  if ( !event.getByToken(refHitToken_, refHitHandle) )
32  {
33  edm::LogInfo("RPCPointVsRecHit") << "Cannot find reference hit collection\n";
34  return;
35  }
36 
37  // Retrieve RecHits from the event
39  if ( !event.getByToken(recHitToken_, recHitHandle) )
40  {
41  edm::LogInfo("RPCPointVsRecHit") << "Cannot find recHit collection\n";
42  return;
43  }
44 
45  typedef RPCRecHitCollection::const_iterator RecHitIter;
46 
47  // Loop over refHits, fill histograms which does not need associations
48  int nRefHitBarrel = 0, nRefHitEndcap = 0;
49  for ( RecHitIter refHitIter = refHitHandle->begin();
50  refHitIter != refHitHandle->end(); ++refHitIter )
51  {
52  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
53  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
54  if ( !roll ) continue;
55 
56  const int region = roll->id().region();
57  const int ring = roll->id().ring();
58  //const int sector = roll->id().sector();
59  const int station = roll->id().station();
60  //const int layer = roll->id().layer();
61  //const int subSector = roll->id().subsector();
62 
63  if ( region == 0 )
64  {
65  h_.refHitOccupancyBarrel_wheel->Fill(ring);
66  h_.refHitOccupancyBarrel_station->Fill(station);
67  h_.refHitOccupancyBarrel_wheel_station->Fill(ring, station);
68  }
69  else
70  {
71  h_.refHitOccupancyEndcap_disk->Fill(region*station);
72  h_.refHitOccupancyEndcap_disk_ring->Fill(region*station, ring);
73  }
74 
75  }
76  h_.nRefHitBarrel->Fill(nRefHitBarrel);
77  h_.nRefHitEndcap->Fill(nRefHitEndcap);
78 
79  // Loop over recHits, fill histograms which does not need associations
80  int sumClusterSizeBarrel = 0, sumClusterSizeEndcap = 0;
81  int nRecHitBarrel = 0, nRecHitEndcap = 0;
82  for ( RecHitIter recHitIter = recHitHandle->begin();
83  recHitIter != recHitHandle->end(); ++recHitIter )
84  {
85  const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
86  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
87  if ( !roll ) continue;
88 
89  const int region = roll->id().region();
90  const int ring = roll->id().ring();
91  //const int sector = roll->id().sector();
92  const int station = (roll->id().station());
93  //const int layer = roll->id().layer();
94  //const int subSector = roll->id().subsector();
95 
96  h_.clusterSize->Fill(recHitIter->clusterSize());
97 
98  if ( region == 0 )
99  {
100  ++nRecHitBarrel;
101  sumClusterSizeBarrel += recHitIter->clusterSize();
102  h_.clusterSizeBarrel->Fill(recHitIter->clusterSize());
103  h_.recHitOccupancyBarrel_wheel->Fill(ring);
104  h_.recHitOccupancyBarrel_station->Fill(station);
105  h_.recHitOccupancyBarrel_wheel_station->Fill(ring, station);
106  }
107  else
108  {
109  ++nRecHitEndcap;
110  sumClusterSizeEndcap += recHitIter->clusterSize();
111  h_.clusterSizeEndcap->Fill(recHitIter->clusterSize());
112  h_.recHitOccupancyEndcap_disk->Fill(region*station);
113  h_.recHitOccupancyEndcap_disk_ring->Fill(ring, region*station);
114  }
115 
116  }
117  const double nRecHit = nRecHitBarrel+nRecHitEndcap;
118  h_.nRecHitBarrel->Fill(nRecHitBarrel);
119  h_.nRecHitEndcap->Fill(nRecHitEndcap);
120  if ( nRecHit > 0 )
121  {
122  const int sumClusterSize = sumClusterSizeBarrel+sumClusterSizeEndcap;
123  h_.avgClusterSize->Fill(double(sumClusterSize)/nRecHit);
124 
125  if ( nRecHitBarrel > 0 )
126  {
127  h_.avgClusterSizeBarrel->Fill(double(sumClusterSizeBarrel)/nRecHitBarrel);
128  }
129  if ( nRecHitEndcap > 0 )
130  {
131  h_.avgClusterSizeEndcap->Fill(double(sumClusterSizeEndcap)/nRecHitEndcap);
132  }
133  }
134 
135  // Start matching RefHits to RecHits
136  typedef std::map<RecHitIter, RecHitIter> RecToRecHitMap;
137  RecToRecHitMap refToRecHitMap;
138 
139  for ( RecHitIter refHitIter = refHitHandle->begin();
140  refHitIter != refHitHandle->end(); ++refHitIter )
141  {
142  const RPCDetId refDetId = static_cast<const RPCDetId>(refHitIter->rpcId());
143  const RPCRoll* refRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(refDetId));
144  if ( !refRoll ) continue;
145 
146  const double refX = refHitIter->localPosition().x();
147 
148  for ( RecHitIter recHitIter = recHitHandle->begin();
149  recHitIter != recHitHandle->end(); ++recHitIter )
150  {
151  const RPCDetId recDetId = static_cast<const RPCDetId>(recHitIter->rpcId());
152  const RPCRoll* recRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(recDetId));
153  if ( !recRoll ) continue;
154 
155  if ( refDetId != recDetId ) continue;
156 
157  const double recX = recHitIter->localPosition().x();
158  const double newDx = fabs(recX - refX);
159 
160  // Associate RefHit to RecHit
161  RecToRecHitMap::const_iterator prevRefToReco = refToRecHitMap.find(refHitIter);
162  if ( prevRefToReco == refToRecHitMap.end() )
163  {
164  refToRecHitMap.insert(std::make_pair(refHitIter, recHitIter));
165  }
166  else
167  {
168  const double oldDx = fabs(prevRefToReco->second->localPosition().x() - refX);
169 
170  if ( newDx < oldDx )
171  {
172  refToRecHitMap[refHitIter] = recHitIter;
173  }
174  }
175  }
176  }
177 
178  // Now we have refHit-recHit mapping
179  // So we can fill up relavant histograms
180  for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
181  match != refToRecHitMap.end(); ++match )
182  {
183  RecHitIter refHitIter = match->first;
184  RecHitIter recHitIter = match->second;
185 
186  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
187  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
188 
189  const int region = roll->id().region();
190  const int ring = roll->id().ring();
191  //const int sector = roll->id().sector();
192  const int station = roll->id().station();
193  //const int layer = roll->id().layer();
194  //const int subsector = roll->id().subsector();
195 
196  const double refX = refHitIter->localPosition().x();
197  const double recX = recHitIter->localPosition().x();
198  const double errX = sqrt(recHitIter->localPositionError().xx());
199  const double dX = recX - refX;
200  const double pull = errX == 0 ? -999 : dX/errX;
201 
202  //const GlobalPoint refPos = roll->toGlobal(refHitIter->localPosition());
203  //const GlobalPoint recPos = roll->toGlobal(recHitIter->localPosition());
204 
205  if ( region == 0 )
206  {
207  h_.resBarrel->Fill(dX);
208  h_.pullBarrel->Fill(pull);
209  h_.matchOccupancyBarrel_wheel->Fill(ring);
210  h_.matchOccupancyBarrel_station->Fill(station);
211  h_.matchOccupancyBarrel_wheel_station->Fill(ring, station);
212 
213  h_.res_wheel_res->Fill(ring, dX);
214  h_.res_station_res->Fill(station, dX);
215  h_.pull_wheel_pull->Fill(ring, pull);
216  h_.pull_station_pull->Fill(station, pull);
217  }
218  else
219  {
220  h_.resEndcap->Fill(dX);
221  h_.pullEndcap->Fill(pull);
222  h_.matchOccupancyEndcap_disk->Fill(region*station);
223  h_.matchOccupancyEndcap_disk_ring->Fill(region*station, ring);
224 
225  h_.res_disk_res->Fill(region*station, dX);
226  h_.res_ring_res->Fill(ring, dX);
227  h_.pull_disk_pull->Fill(region*station, pull);
228  h_.pull_ring_pull->Fill(ring, pull);
229  }
230  }
231 
232 /*
233  // Find Lost hits
234  for ( RecHitIter refHitIter = refHitHandle->begin();
235  refHitIter != refHitHandle->end(); ++refHitIter )
236  {
237  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
238  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
239 
240  const int region = roll->id().region();
241  const int ring = roll->id().ring();
242  //const int sector = roll->id().sector();
243  const int station = roll->id().station();
244  //const int layer = roll->id().layer();
245  //const int subsector = roll->id().subsector();
246 
247  bool matched = false;
248  for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
249  match != refToRecHitMap.end(); ++match )
250  {
251  if ( refHitIter == match->first )
252  {
253  matched = true;
254  break;
255  }
256  }
257 
258  if ( !matched )
259  {
260  if ( region == 0 )
261  {
262  h_.nUrefHitOccupancyBarrel_wheel->Fill(ring);
263  h_.nUrefHitOccupancyBarrel_wheel_ring->Fill(ring, station);
264  }
265  else
266  {
267  h_.nUnMatchedRefHit_disk->Fill(region*station);
268  h_.nUnMatchedRefHit_disk_ring->Fill(region*station, ring);
269  }
270  }
271  }
272 */
273 
274  // Find Noisy hits
275  for ( RecHitIter recHitIter = recHitHandle->begin();
276  recHitIter != recHitHandle->end(); ++recHitIter )
277  {
278  const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
279  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
280 
281  const int region = roll->id().region();
282  const int ring = roll->id().ring();
283  //const int sector = roll->id().sector();
284  const int station = roll->id().station();
285  //const int layer = roll->id().layer();
286  //const int subsector = roll->id().subsector();
287 
288  bool matched = false;
289  for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
290  match != refToRecHitMap.end(); ++match )
291  {
292  if ( recHitIter == match->second )
293  {
294  matched = true;
295  break;
296  }
297  }
298 
299  if ( !matched )
300  {
301  if ( region == 0 )
302  {
303  h_.umOccupancyBarrel_wheel->Fill(ring);
304  h_.umOccupancyBarrel_station->Fill(station);
305  h_.umOccupancyBarrel_wheel_station->Fill(ring, station);
306  }
307  else
308  {
309  h_.umOccupancyEndcap_disk->Fill(region*station);
310  h_.umOccupancyEndcap_disk_ring->Fill(region*station, ring);
311  }
312 
313  //const GlobalPoint pos = roll->toGlobal(recHitIter->localPosition());
314  //h_[HName::NoisyHitEta]->Fill(pos.eta());
315  }
316  }
317 }
318 
320  edm::Run const & run, edm::EventSetup const & eventSetup)
321 {
322  // Book MonitorElements
323  h_.bookHistograms(booker, subDir_);
324 }
325 
326 
328 
T getParameter(std::string const &) const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#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:18
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
const T & get() const
Definition: EventSetup.h:56
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:10
Definition: Run.h:43
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96