CMS 3D CMS Logo

RPCDigiValid.cc
Go to the documentation of this file.
2 
5 
11 
12 #include <cmath>
13 #include <fmt/format.h>
14 
15 using namespace std;
16 using namespace edm;
17 
19  // Init the tokens for run data retrieval - stanislav
20  // ps.getUntackedParameter<InputTag> retrieves a InputTag from the
21  // configuration. The second param is default value module, instance and
22  // process labels may be passed in a single string if separated by colon ':'
23  // (@see the edm::InputTag constructor documentation)
24  simHitToken_ = consumes<PSimHitContainer>(
25  ps.getUntrackedParameter<edm::InputTag>("simHitTag", edm::InputTag("g4SimHits:MuonRPCHits")));
26  rpcDigiToken_ = consumes<RPCDigiCollection>(
27  ps.getUntrackedParameter<edm::InputTag>("rpcDigiTag", edm::InputTag("simMuonRPCDigis")));
28 
29  rpcGeomToken_ = esConsumes();
30 }
31 
33  // Get the RPC Geometry
34  auto rpcGeom = eventSetup.getHandle(rpcGeomToken_);
35 
36  edm::Handle<PSimHitContainer> simHitHandle;
37  edm::Handle<RPCDigiCollection> rpcDigisHandle;
38  event.getByToken(simHitToken_, simHitHandle);
39  event.getByToken(rpcDigiToken_, rpcDigisHandle);
40 
41  // loop over Simhit
42  std::map<const RPCRoll *, std::vector<double>> detToSimHitXsMap;
43  for (auto simIt = simHitHandle->begin(); simIt != simHitHandle->end(); ++simIt) {
44  const RPCDetId rsid = simIt->detUnitId();
45  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(rsid));
46  if (!roll)
47  continue;
48 
49  if (detToSimHitXsMap.find(roll) == detToSimHitXsMap.end())
50  detToSimHitXsMap[roll] = std::vector<double>();
51  detToSimHitXsMap[roll].push_back(simIt->localPosition().x());
52 
53  const int region = rsid.region();
54  const GlobalPoint gp = roll->toGlobal(simIt->localPosition());
55 
56  hRZ_->Fill(gp.z(), gp.perp());
57 
58  if (region == 0) {
59  // Barrel
60  hXY_Barrel_->Fill(gp.x(), gp.y());
61 
62  const int station = rsid.station();
63  const int layer = rsid.layer();
64  const int stla = (station <= 2) ? (2 * (station - 1) + layer) : (station + 2);
65 
66  auto match = hZPhi_.find(stla);
67  if (match != hZPhi_.end()) {
68  const double phiInDeg = 180. * gp.barePhi() / TMath::Pi();
69  match->second->Fill(gp.z(), phiInDeg);
70  }
71  } else {
72  // Endcap
73  const int disk = region * rsid.station();
74  auto match = hXY_Endcap_.find(disk);
75  if (match != hXY_Endcap_.end())
76  match->second->Fill(gp.x(), gp.y());
77  }
78  }
79  for (auto detToSimHitXs : detToSimHitXsMap) {
80  hNSimHitPerRoll_->Fill(detToSimHitXs.second.size());
81  }
82 
83  // loop over Digis
84  std::map<const RPCRoll *, std::vector<double>> detToDigiXsMap;
85  for (auto detUnitIt = rpcDigisHandle->begin(); detUnitIt != rpcDigisHandle->end(); ++detUnitIt) {
86  const RPCDetId rsid = (*detUnitIt).first;
87  const RPCRoll *roll = dynamic_cast<const RPCRoll *>(rpcGeom->roll(rsid));
88  if (!roll)
89  continue;
90  const int region = rsid.region();
91 
92  const RPCDigiCollection::Range &range = (*detUnitIt).second;
93 
94  for (auto digiIt = range.first; digiIt != range.second; ++digiIt) {
95  // Strip profile
96  const int strip = digiIt->strip();
97  hStripProf_->Fill(strip);
98 
99  if (region == 0) {
100  const int station = rsid.station();
101  if (station == 1 or station == 2)
102  hStripProf_RB12_->Fill(strip);
103  else if (station == 3 or station == 4)
104  hStripProf_RB34_->Fill(strip);
105  } else {
106  if (roll->isIRPC())
107  hStripProf_IRPC_->Fill(strip);
108  else
109  hStripProf_Endcap_->Fill(strip);
110  }
111 
112  // Bunch crossing
113  const int bx = digiIt->bx();
114  hBxDist_->Fill(bx);
115  // bx for 4 endcaps
116  if (rsid.station() == 4) {
117  if (region == 1) {
118  hBxDisc_4Plus_->Fill(bx);
119  } else if (region == -1) {
120  hBxDisc_4Min_->Fill(bx);
121  }
122  }
123 
124  // Fill timing information
125  const double digiTime = digiIt->hasTime() ? digiIt->time() : digiIt->bx() * 25;
126  hDigiTimeAll_->Fill(digiTime);
127  if (digiIt->hasTime()) {
128  hDigiTime_->Fill(digiTime);
129  if (roll->isIRPC())
130  hDigiTimeIRPC_->Fill(digiTime);
131  else
132  hDigiTimeNoIRPC_->Fill(digiTime);
133  }
134 
135  // Keep digi position
136  const double digiX = roll->centreOfStrip(digiIt->strip()).x();
137  if (detToDigiXsMap.find(roll) == detToDigiXsMap.end())
138  detToDigiXsMap[roll] = std::vector<double>();
139  detToDigiXsMap[roll].push_back(digiX);
140  }
141  }
142  for (auto detToDigiXs : detToDigiXsMap) {
143  const auto digiXs = detToDigiXs.second;
144  const int nDigi = digiXs.size();
145  hNDigiPerRoll_->Fill(nDigi);
146 
147  // Fill residual plots, only for nDigi==1 and nSimHit==1
148  const auto roll = detToDigiXs.first;
149  const auto detId = roll->id();
150  if (nDigi != 1)
151  continue;
152  if (detToSimHitXsMap.find(roll) == detToSimHitXsMap.end())
153  continue;
154 
155  const auto simHitXs = detToSimHitXsMap[roll];
156  const int nSimHit = simHitXs.size();
157  if (nSimHit != 1)
158  continue;
159 
160  const double dx = digiXs[0] - simHitXs[0];
161  hRes_->Fill(dx);
162  if (roll->isBarrel()) {
163  const int wheel = detId.ring(); // ring() is wheel number for Barrel
164  const int station = detId.station();
165  const int layer = detId.layer();
166  const int stla = (station <= 2) ? (2 * (station - 1) + layer) : (station + 2);
167 
168  auto matchLayer = hResBarrelLayers_.find(stla);
169  if (matchLayer != hResBarrelLayers_.end())
170  matchLayer->second->Fill(dx);
171 
172  auto matchWheel = hResBarrelWheels_.find(wheel);
173  if (matchWheel != hResBarrelWheels_.end())
174  matchWheel->second->Fill(dx);
175  } else {
176  const int disk = detId.region() * detId.station();
177  auto matchDisk = hResEndcapDisks_.find(disk);
178  if (matchDisk != hResEndcapDisks_.end())
179  matchDisk->second->Fill(dx);
180 
181  auto matchRing = hResEndcapRings_.find(detId.ring());
182  if (matchRing != hResEndcapRings_.end())
183  matchRing->second->Fill(dx);
184  }
185  }
186 }
187 
189  booker.setCurrentFolder("RPCDigisV/RPCDigis");
190 
191  // Define binnings of 2D-histograms
192  const double maxZ = 1100;
193  const int nbinsZ = 220; // bin width: 10cm
194  const double maxXY = 800;
195  const int nbinsXY = 160; // bin width: 10cm
196  const double minR = 100, maxR = 800;
197  const int nbinsR = 70; // bin width: 10cm
198  const int nbinsPhi = 72; // bin width: 5 degree
199  const double maxBarrelZ = 700;
200  const int nbinsBarrelZ = 140; // bin width: 10cm
201 
202  // RZ plot
203  hRZ_ = booker.book2D("RZ", "R-Z view;Z (cm);R (cm)", nbinsZ, -maxZ, maxZ, nbinsR, minR, maxR);
204 
205  // XY plots
206  hXY_Barrel_ = booker.book2D("XY_Barrel", "X-Y view of Barrel", nbinsXY, -maxXY, maxXY, nbinsXY, -maxXY, maxXY);
207  for (int disk = 1; disk <= 4; ++disk) {
208  const std::string meNameP = fmt::format("XY_Endcap_p{:1d}", disk);
209  const std::string meNameN = fmt::format("XY_Endcap_m{:1d}", disk);
210  const std::string meTitleP = fmt::format("X-Y view of Endcap{:+1d};X (cm);Y (cm)", disk);
211  const std::string meTitleN = fmt::format("X-Y view of Endcap{:+1d};X (cm);Y (cm)", -disk);
212  hXY_Endcap_[disk] = booker.book2D(meNameP, meTitleP, nbinsXY, -maxXY, maxXY, nbinsXY, -maxXY, maxXY);
213  hXY_Endcap_[-disk] = booker.book2D(meNameN, meTitleN, nbinsXY, -maxXY, maxXY, nbinsXY, -maxXY, maxXY);
214  }
215 
216  // Z-phi plots
217  for (int layer = 1; layer <= 6; ++layer) {
218  const std::string meName = fmt::format("ZPhi_Layer{:1d}", layer);
219  const std::string meTitle = fmt::format("Z-#phi view of Layer{:1d};Z (cm);#phi (degree)", layer);
220  hZPhi_[layer] = booker.book2D(meName, meTitle, nbinsBarrelZ, -maxBarrelZ, maxBarrelZ, nbinsPhi, -180, 180);
221  }
222 
223  // Strip profile
224  hStripProf_ = booker.book1D("Strip_Profile", "Strip_Profile;Strip Number", 100, 0, 100);
225  hStripProf_RB12_ = booker.book1D("Strip_Profile_RB12", "Strip Profile RB1 and RB2;Strip Number", 92, 0, 92);
226  hStripProf_RB34_ = booker.book1D("Strip_Profile_RB34", "Strip Profile RB3 and RB4;Strip Number", 62, 0, 62);
227  hStripProf_Endcap_ = booker.book1D("Strip_Profile_Endcap", "Strip Profile Endcap;Strip Number", 40, 0, 40);
228  hStripProf_IRPC_ = booker.book1D("Strip_Profile_IRPC", "Strip Profile IRPC;Strip Number", 100, 0, 100);
229 
230  // Bunch crossing
231  hBxDist_ = booker.book1D("Bunch_Crossing", "Bunch Crossing;Bunch crossing", 20, -10., 10.);
232  hBxDisc_4Plus_ = booker.book1D("BxDisc_4Plus", "BxDisc_4Plus", 20, -10., 10.);
233  hBxDisc_4Min_ = booker.book1D("BxDisc_4Min", "BxDisc_4Min", 20, -10., 10.);
234 
235  // Timing informations
236  hDigiTimeAll_ =
237  booker.book1D("DigiTimeAll", "Digi time including present electronics;Digi time (ns)", 100, -12.5, 12.5);
238  hDigiTime_ = booker.book1D("DigiTime", "Digi time only with timing information;Digi time (ns)", 100, -12.5, 12.5);
239  hDigiTimeIRPC_ = booker.book1D("DigiTimeIRPC", "IRPC Digi time;Digi time (ns)", 100, -12.5, 12.5);
240  hDigiTimeNoIRPC_ = booker.book1D("DigiTimeNoIRPC", "non-IRPC Digi time;Digi time (ns)", 100, -12.5, 12.5);
241 
242  // SimHit and Digi multiplicity per roll
243  hNSimHitPerRoll_ = booker.book1D("NSimHitPerRoll", "SimHit multiplicity per Roll;Multiplicity", 10, 0, 10);
244  hNDigiPerRoll_ = booker.book1D("NDigiPerRoll", "Digi multiplicity per Roll;Multiplicity", 10, 0, 10);
245 
246  // Residual of SimHit-Digi x-position
247  hRes_ = booker.book1D("Digi_SimHit_Difference", "Digi-SimHit difference;dx (cm)", 100, -8, 8);
248 
249  for (int layer = 1; layer <= 6; ++layer) {
250  const std::string meName = fmt::format("Residual_Barrel_Layer{:1d}", layer);
251  const std::string meTitle = fmt::format("Residual of Barrel Layer{:1d};dx (cm)", layer);
252  hResBarrelLayers_[layer] = booker.book1D(meName, meTitle, 100, -8, 8);
253  }
254 
255  hResBarrelWheels_[-2] = booker.book1D("Residual_Barrel_Wheel_m2", "Residual of Barrel Wheel-2;dx (cm)", 100, -8, 8);
256  hResBarrelWheels_[-1] = booker.book1D("Residual_Barrel_Wheel_m1", "Residual of Barrel Wheel-1;dx (cm)", 100, -8, 8);
257  hResBarrelWheels_[+0] = booker.book1D("Residual_Barrel_Wheel_00", "Residual of Barrel Wheel 0;dx (cm)", 100, -8, 8);
258  hResBarrelWheels_[+1] = booker.book1D("Residual_Barrel_Wheel_p1", "Residual of Barrel Wheel+1;dx (cm)", 100, -8, 8);
259  hResBarrelWheels_[+2] = booker.book1D("Residual_Barrel_Wheel_p2", "Residual of Barrel Wheel+2;dx (cm)", 100, -8, 8);
260 
261  for (int disk = 1; disk <= 4; ++disk) {
262  const std::string meNameP = fmt::format("Residual_Endcap_Disk_p{:1d}", disk);
263  const std::string meNameN = fmt::format("Residual_Endcap_Disk_m{:1d}", disk);
264  const std::string meTitleP = fmt::format("Residual of Endcap Disk{:+1d};dx (cm)", disk);
265  const std::string meTitleN = fmt::format("Residual of Endcap Disk{:+1d};dx (cm)", -disk);
266  hResEndcapDisks_[+disk] = booker.book1D(meNameP, meTitleP, 100, -8, 8);
267  hResEndcapDisks_[-disk] = booker.book1D(meNameN, meTitleN, 100, -8, 8);
268  }
269 
270  for (int ring = 1; ring <= 3; ++ring) {
271  const std::string meName = fmt::format("Residual_Endcap_Ring{:1d}", ring);
272  const std::string meTitle = fmt::format("Residual of Endcap Ring{:1d};dx (cm)", ring);
273  hResEndcapRings_[ring] = booker.book1D(meName, meTitle, 100, -8, 8);
274  }
275 }
const double Pi
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
RPCDigiValid(const edm::ParameterSet &ps)
Definition: RPCDigiValid.cc:18
T getUntrackedParameter(std::string const &, T const &) const
void analyze(const edm::Event &e, const edm::EventSetup &c) override
Definition: RPCDigiValid.cc:32
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
std::pair< const_iterator, const_iterator > Range
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:221
int station() const
Definition: RPCDetId.h:78
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
HLT enums.
float x
int layer() const
Definition: RPCDetId.h:85
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
Definition: event.py:1
Definition: Run.h:45