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 
11 
12 using namespace std;
13 
15 
17 {
18  rootFileName_ = pset.getUntrackedParameter<string>("rootFileName", "");
19  refHitLabel_ = pset.getParameter<edm::InputTag>("refHit");
20  recHitLabel_ = pset.getParameter<edm::InputTag>("recHit");
21 
22  isStandAloneMode_ = pset.getUntrackedParameter<bool>("standAloneMode", false);
23 
25  if ( !dbe_ )
26  {
27  edm::LogError("RPCPointVsRecHit") << "No DQMStore instance\n";
28  return;
29  }
30 
31  // Book MonitorElements
32  const std::string subDir = pset.getParameter<std::string>("subDir");
33  h_.bookHistograms(dbe_, subDir);
34 }
35 
37 {
38  if ( dbe_ )
39  {
40  if ( !rootFileName_.empty() ) dbe_->save(rootFileName_);
41  }
42 }
43 
45 {
46 }
47 
49 {
50 }
51 
53 {
54  if ( !dbe_ )
55  {
56  edm::LogError("RPCPointVsRecHit") << "No DQMStore instance\n";
57  return;
58  }
59 
60  // Get the RPC Geometry
62  eventSetup.get<MuonGeometryRecord>().get(rpcGeom);
63 
64  // Retrieve RefHits from the event
66  if ( !event.getByLabel(refHitLabel_, refHitHandle) )
67  {
68  edm::LogInfo("RPCPointVsRecHit") << "Cannot find reference hit collection\n";
69  return;
70  }
71 
72  // Retrieve RecHits from the event
74  if ( !event.getByLabel(recHitLabel_, recHitHandle) )
75  {
76  edm::LogInfo("RPCPointVsRecHit") << "Cannot find recHit collection\n";
77  return;
78  }
79 
80  typedef RPCRecHitCollection::const_iterator RecHitIter;
81 
82  // Loop over refHits, fill histograms which does not need associations
83  for ( RecHitIter refHitIter = refHitHandle->begin();
84  refHitIter != refHitHandle->end(); ++refHitIter )
85  {
86  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
87  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
88  if ( !roll ) continue;
89 
90  const int region = roll->id().region();
91  const int ring = roll->id().ring();
92  //const int sector = roll->id().sector();
93  const int station = roll->id().station();
94  //const int layer = roll->id().layer();
95  //const int subSector = roll->id().subsector();
96 
97  if ( region == 0 )
98  {
99  h_.nRefHit_W->Fill(ring);
100  h_.nRefHit_WvsR->Fill(ring, station);
101  }
102  else
103  {
104  h_.nRefHit_D->Fill(region*station);
105  h_.nRefHit_DvsR->Fill(region*station, ring);
106  }
107 
108  const GlobalPoint pos = roll->toGlobal(refHitIter->localPosition());
109  //h_[HName::RefHitEta]->Fill(pos.eta());
110  }
111 
112  // Loop over recHits, fill histograms which does not need associations
113  for ( RecHitIter recHitIter = recHitHandle->begin();
114  recHitIter != recHitHandle->end(); ++recHitIter )
115  {
116  const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
117  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId()));
118  if ( !roll ) continue;
119 
120  const int region = roll->id().region();
121  const int ring = roll->id().ring();
122  //const int sector = roll->id().sector();
123  const int station = (roll->id().station());
124  //const int layer = roll->id().layer();
125  //const int subSector = roll->id().subsector();
126 
127  h_.clusterSize->Fill(recHitIter->clusterSize());
128 
129  if ( region == 0 )
130  {
131  h_.nRecHit_W->Fill(ring);
132  h_.nRecHit_WvsR->Fill(ring, station);
133  }
134  else
135  {
136  h_.nRecHit_D->Fill(region*station);
137  h_.nRecHit_DvsR->Fill(ring, region*station);
138  }
139 
140 
141  const GlobalPoint pos = roll->toGlobal(recHitIter->localPosition());
142  //h_[HName::RecHitEta]->Fill(pos.eta());
143  }
144 
145  // Start matching RefHits to RecHits
146  typedef std::map<RecHitIter, RecHitIter> RecToRecHitMap;
147  RecToRecHitMap refToRecHitMap;
148 
149  for ( RecHitIter refHitIter = refHitHandle->begin();
150  refHitIter != refHitHandle->end(); ++refHitIter )
151  {
152  const RPCDetId refDetId = static_cast<const RPCDetId>(refHitIter->rpcId());
153  const RPCRoll* refRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(refDetId));
154  if ( !refRoll ) continue;
155 
156  const double refX = refHitIter->localPosition().x();
157 
158  for ( RecHitIter recHitIter = recHitHandle->begin();
159  recHitIter != recHitHandle->end(); ++recHitIter )
160  {
161  const RPCDetId recDetId = static_cast<const RPCDetId>(recHitIter->rpcId());
162  const RPCRoll* recRoll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(recDetId));
163  if ( !recRoll ) continue;
164 
165  if ( refDetId != recDetId ) continue;
166 
167  const double recX = recHitIter->localPosition().x();
168  const double newDx = fabs(recX - refX);
169 
170  // Associate RefHit to RecHit
171  RecToRecHitMap::const_iterator prevRefToReco = refToRecHitMap.find(refHitIter);
172  if ( prevRefToReco == refToRecHitMap.end() )
173  {
174  refToRecHitMap.insert(std::make_pair(refHitIter, recHitIter));
175  }
176  else
177  {
178  const double oldDx = fabs(prevRefToReco->second->localPosition().x() - refX);
179 
180  if ( newDx < oldDx )
181  {
182  refToRecHitMap[refHitIter] = recHitIter;
183  }
184  }
185  }
186  }
187 
188  // Now we have refHit-recHit mapping
189  // So we can fill up relavant histograms
190  for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
191  match != refToRecHitMap.end(); ++match )
192  {
193  RecHitIter refHitIter = match->first;
194  RecHitIter recHitIter = match->second;
195 
196  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
197  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
198 
199  const int region = roll->id().region();
200  const int ring = roll->id().ring();
201  //const int sector = roll->id().sector();
202  const int station = roll->id().station();
203  //const int layer = roll->id().layer();
204  //const int subsector = roll->id().subsector();
205 
206  const double refX = refHitIter->localPosition().x();
207  const double recX = recHitIter->localPosition().x();
208  const double errX = recHitIter->localPositionError().xx();
209  const double dX = recX - refX;
210  const double pull = errX == 0 ? -999 : dX/errX;
211 
212  const GlobalPoint refPos = roll->toGlobal(refHitIter->localPosition());
213  const GlobalPoint recPos = roll->toGlobal(recHitIter->localPosition());
214 
215  if ( region == 0 )
216  {
217  h_.res_W->Fill(dX);
218  h_.pull_W->Fill(pull);
219  h_.nMatchedRefHit_W->Fill(ring);
220  h_.nMatchedRefHit_WvsR->Fill(ring, station);
221 
222  h_.res2_W->Fill(ring, dX);
223  h_.pull2_W->Fill(ring, pull);
224  }
225  else
226  {
227  h_.res_D->Fill(dX);
228  h_.pull_D->Fill(pull);
229  h_.nMatchedRefHit_D->Fill(region*station);
230  h_.nMatchedRefHit_DvsR->Fill(region*station, ring);
231 
232  h_.res2_D->Fill(region*station, dX);
233  h_.pull2_D->Fill(region*station, pull);
234  }
235  }
236 
237  // Find Lost hits
238  for ( RecHitIter refHitIter = refHitHandle->begin();
239  refHitIter != refHitHandle->end(); ++refHitIter )
240  {
241  const RPCDetId detId = static_cast<const RPCDetId>(refHitIter->rpcId());
242  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
243 
244  const int region = roll->id().region();
245  const int ring = roll->id().ring();
246  //const int sector = roll->id().sector();
247  const int station = roll->id().station();
248  //const int layer = roll->id().layer();
249  //const int subsector = roll->id().subsector();
250 
251  bool matched = false;
252  for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
253  match != refToRecHitMap.end(); ++match )
254  {
255  if ( refHitIter == match->first )
256  {
257  matched = true;
258  break;
259  }
260  }
261 
262  if ( !matched )
263  {
264  if ( region == 0 )
265  {
266  h_.nUnMatchedRefHit_W->Fill(ring);
267  h_.nUnMatchedRefHit_WvsR->Fill(ring, station);
268  }
269  else
270  {
271  h_.nUnMatchedRefHit_D->Fill(region*station);
272  h_.nUnMatchedRefHit_DvsR->Fill(region*station, ring);
273  }
274  }
275  }
276 
277  // Find Noisy hits
278  for ( RecHitIter recHitIter = recHitHandle->begin();
279  recHitIter != recHitHandle->end(); ++recHitIter )
280  {
281  const RPCDetId detId = static_cast<const RPCDetId>(recHitIter->rpcId());
282  const RPCRoll* roll = dynamic_cast<const RPCRoll*>(rpcGeom->roll(detId));
283 
284  const int region = roll->id().region();
285  const int ring = roll->id().ring();
286  //const int sector = roll->id().sector();
287  const int station = roll->id().station();
288  //const int layer = roll->id().layer();
289  //const int subsector = roll->id().subsector();
290 
291  bool matched = false;
292  for ( RecToRecHitMap::const_iterator match = refToRecHitMap.begin();
293  match != refToRecHitMap.end(); ++match )
294  {
295  if ( recHitIter == match->second )
296  {
297  matched = true;
298  break;
299  }
300  }
301 
302  if ( !matched )
303  {
304  if ( region == 0 )
305  {
306  h_.nUnMatchedRecHit_W->Fill(ring);
307  h_.nUnMatchedRecHit_WvsR->Fill(ring, station);
308  }
309  else
310  {
311  h_.nUnMatchedRecHit_D->Fill(region*station);
312  h_.nUnMatchedRecHit_DvsR->Fill(region*station, ring);
313  }
314 
315  const GlobalPoint pos = roll->toGlobal(recHitIter->localPosition());
316  //h_[HName::NoisyHitEta]->Fill(pos.eta());
317  }
318  }
319 }
320 
322 
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:49
void save(const std::string &filename, const std::string &path="", const std::string &pattern="", const std::string &rewrite="", SaveReferenceTag ref=SaveWithReference, int minStatus=dqm::qstatus::STATUS_OK, const std::string &fileupdate="RECREATE")
Definition: DQMStore.cc:1898
void analyze(const edm::Event &event, const edm::EventSetup &eventSetup)
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:46
RPCDetId id() const
Definition: RPCRoll.cc:24
MonitorElement * MEP
int ring() const
Definition: RPCDetId.h:74
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
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:355
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:65
int station() const
Definition: RPCDetId.h:98