CMS 3D CMS Logo

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