CMS 3D CMS Logo

ElasticPlotDQMSource.cc
Go to the documentation of this file.
1 /****************************************************************************
2 *
3 * Authors:
4 * Jan Kašpar (jan.kaspar@gmail.com)
5 *
6 ****************************************************************************/
7 
13 
16 
22 
23 #include <string>
24 #include <array>
25 #include <map>
26 
27 //----------------------------------------------------------------------------------------------------
28 
30 public:
32  ~ElasticPlotDQMSource() override;
33 
34 protected:
35  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
36 
37  void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override;
38 
39 private:
40  static constexpr double ls_duration_inverse = 1. / 23.357; // s^-1
41  static constexpr unsigned int ls_min = 0;
42  static constexpr unsigned int ls_max = 2000; // little more than 12h
43 
44  unsigned int verbosity;
45 
49 
51  struct DiagonalPlots {
52  // in the order 45-220-fr, 45-210-fr, 56-210-fr, 56-220-fr
53  std::array<unsigned int, 4> rpIds;
54 
55  // track correlation in vertical RPs
57 
58  // y distributions in a RP (1st index) with another RP (2nd index) in coincidence
59  std::array<std::array<MonitorElement *, 4>, 4> v_h_y;
60 
61  // XY hit maps in a give RP (array index) under these conditions
62  // 4rp: all 4 diagonal RPs have a track
63  // 2rp: diagonal RPs in 220-fr have a track
64  std::array<MonitorElement *, 4> v_h2_y_vs_x_dgn_4rp;
65  std::array<MonitorElement *, 4> v_h2_y_vs_x_dgn_2rp;
66 
67  // event rates vs. time
70 
72 
73  DiagonalPlots(DQMStore::IBooker &ibooker, int _id);
74  };
75 
76  std::map<unsigned int, DiagonalPlots> diagonalPlots;
77 
79  struct PotPlots {
80  // event rates vs. time
81  // suff = singal sufficient to reconstruct track
82  // track = track is reconstructed
83  // unresolved = suff && !track
87 
88  PotPlots() {}
89  PotPlots(DQMStore::IBooker &ibooker, unsigned int id);
90  };
91 
92  std::map<unsigned int, PotPlots> potPlots;
93 };
94 
95 //----------------------------------------------------------------------------------------------------
96 //----------------------------------------------------------------------------------------------------
97 
98 using namespace std;
99 using namespace edm;
100 
101 //----------------------------------------------------------------------------------------------------
102 
104  // determine captions
105  bool top45 = id & 2;
106  bool top56 = id & 1;
107  bool diag = (top45 != top56);
108 
109  string name = string((diag) ? "diagonal" : "antidiagonal") + " 45" + ((top45) ? "top" : "bot") + " - 56" +
110  ((top56) ? "top" : "bot");
111 
112  const string &title = name;
113 
114  // dermine RP ids of this diagonal
115  rpIds[0] = TotemRPDetId(0, 2, (top45) ? 4 : 5);
116  rpIds[1] = TotemRPDetId(0, 0, (top45) ? 4 : 5);
117  rpIds[2] = TotemRPDetId(1, 0, (top56) ? 4 : 5);
118  rpIds[3] = TotemRPDetId(1, 2, (top56) ? 4 : 5);
119 
120  // book histograms
121  ibooker.setCurrentFolder("CTPPS/TrackingStrip/" + name);
122 
123  h2_track_corr_vert = ibooker.book2D("track correlation in verticals", title + ";;", 4, -0.5, 3.5, 4, -0.5, 3.5);
124  TH2F *h2 = h2_track_corr_vert->getTH2F();
125  TAxis *xa = h2->GetXaxis(), *ya = h2->GetYaxis();
126  for (unsigned int i = 0; i < 4; i++) {
127  string rpName;
129  rpName = rpName.substr(15); // removes obvious prefix for better readability
130 
131  xa->SetBinLabel(i + 1, rpName.c_str());
132  ya->SetBinLabel(i + 1, rpName.c_str());
133  }
134 
135  h_rate_vs_time_dgn_4rp =
136  ibooker.book1D("rate - 4 RPs", title + ";lumi section", ls_max - ls_min + 1, -0.5 + ls_min, +0.5 + ls_max);
137  h_rate_vs_time_dgn_2rp = ibooker.book1D(
138  "rate - 2 RPs (220-fr)", title + ";lumi section", ls_max - ls_min + 1, -0.5 + ls_min, +0.5 + ls_max);
139 
140  for (unsigned int i = 0; i < 4; i++) {
141  string rpName;
143  rpName = rpName.substr(15);
144 
145  ibooker.setCurrentFolder("CTPPS/TrackingStrip/" + name + "/xy hists");
146 
147  v_h2_y_vs_x_dgn_4rp[i] = ibooker.book2D(
148  "xy hist - " + rpName + " - 4 RPs cond", title + ";x (mm);y (mm)", 100, -18., +18., 100, -18., +18.);
149  v_h2_y_vs_x_dgn_2rp[i] = ibooker.book2D(
150  "xy hist - " + rpName + " - 2 RPs cond", title + ";x (mm);y (mm)", 100, -18., +18., 100, -18., +18.);
151 
152  ibooker.setCurrentFolder("CTPPS/TrackingStrip/" + name + "/y hists");
153 
154  for (unsigned int j = 0; j < 4; j++) {
155  string rpCoincName;
157  rpCoincName = rpCoincName.substr(15);
158 
159  v_h_y[i][j] =
160  ibooker.book1D("y hist - " + rpName + " - coinc " + rpCoincName, title + ";y (mm)", 180, -18., +18.);
161  }
162  }
163 }
164 
165 //----------------------------------------------------------------------------------------------------
166 
168  string path;
170  ibooker.setCurrentFolder(path);
171 
172  string title;
174 
175  h_rate_vs_time_suff =
176  ibooker.book1D("rate - suff", title + ";lumi section", ls_max - ls_min + 1, -0.5 + ls_min, +0.5 + ls_max);
177  h_rate_vs_time_track =
178  ibooker.book1D("rate - track", title + ";lumi section", ls_max - ls_min + 1, -0.5 + ls_min, +0.5 + ls_max);
179  h_rate_vs_time_unresolved =
180  ibooker.book1D("rate - unresolved", title + ";lumi section", ls_max - ls_min + 1, -0.5 + ls_min, +0.5 + ls_max);
181 }
182 
183 //----------------------------------------------------------------------------------------------------
184 //----------------------------------------------------------------------------------------------------
185 
187  : verbosity(ps.getUntrackedParameter<unsigned int>("verbosity", 0)) {
188  tokenRecHit = consumes<edm::DetSetVector<TotemRPRecHit>>(ps.getParameter<edm::InputTag>("tagRecHit"));
189  tokenUVPattern = consumes<DetSetVector<TotemRPUVPattern>>(ps.getParameter<edm::InputTag>("tagUVPattern"));
190  tokenLocalTrack = consumes<DetSetVector<TotemRPLocalTrack>>(ps.getParameter<edm::InputTag>("tagLocalTrack"));
191 }
192 
193 //----------------------------------------------------------------------------------------------------
194 
196 
197 //----------------------------------------------------------------------------------------------------
198 
200  ibooker.cd();
201  ibooker.setCurrentFolder("CTPPS");
202 
203  // initialize (anti-)diagonal plots
204  diagonalPlots[0] = DiagonalPlots(ibooker, 0); // 45 bot - 56 bot
205  diagonalPlots[1] = DiagonalPlots(ibooker, 1); // 45 bot - 56 top
206  diagonalPlots[2] = DiagonalPlots(ibooker, 2); // 45 top - 56 bot
207  diagonalPlots[3] = DiagonalPlots(ibooker, 3); // 45 top - 56 top
208 
209  // loop over arms
210  for (unsigned int arm = 0; arm < 2; arm++) {
211  // loop over stations
212  for (unsigned int st : {0, 2}) {
213  // loop over RPs
214  for (unsigned int rp : {4, 5}) {
215  TotemRPDetId rpId(arm, st, rp);
216  potPlots[rpId] = PotPlots(ibooker, rpId);
217  }
218  }
219  }
220 }
221 
222 //----------------------------------------------------------------------------------------------------
223 
225  // get event data
227  event.getByToken(tokenRecHit, hits);
228 
230  event.getByToken(tokenUVPattern, patterns);
231 
233  event.getByToken(tokenLocalTrack, tracks);
234 
235  // check validity
236  bool valid = true;
237  valid &= hits.isValid();
238  valid &= patterns.isValid();
239  valid &= tracks.isValid();
240 
241  if (!valid) {
242  if (verbosity) {
243  LogProblem("ElasticPlotDQMSource") << "ERROR in ElasticPlotDQMSource::analyze > some of the required inputs are "
244  "not valid. Skipping this event.\n"
245  << " hits.isValid = " << hits.isValid() << "\n"
246  << " patterns.isValid = " << patterns.isValid() << "\n"
247  << " tracks.isValid = " << tracks.isValid();
248  }
249 
250  return;
251  }
252 
253  //------------------------------
254  // categorise RP data
255  map<unsigned int, unsigned int> rp_planes_u_too_full, rp_planes_v_too_full;
256  map<unsigned int, bool> rp_pat_suff;
257  map<unsigned int, const TotemRPLocalTrack *> rp_track;
258 
259  for (const auto &ds : *hits) {
260  TotemRPDetId detId(ds.detId());
261  CTPPSDetId rpId = detId.rpId();
262 
263  if (ds.size() > 5) {
264  if (detId.isStripsCoordinateUDirection())
265  rp_planes_u_too_full[rpId]++;
266  else
267  rp_planes_v_too_full[rpId]++;
268  }
269  }
270 
271  for (auto &ds : *patterns) {
272  CTPPSDetId rpId(ds.detId());
273 
274  // count U and V patterns
275  unsigned int n_pat_u = 0, n_pat_v = 0;
276  for (auto &p : ds) {
277  if (!p.fittable())
278  continue;
279 
280  if (p.projection() == TotemRPUVPattern::projU)
281  n_pat_u++;
282  else if (p.projection() == TotemRPUVPattern::projV)
283  n_pat_v++;
284  }
285 
286  rp_pat_suff[rpId] =
287  (n_pat_u > 0 || rp_planes_u_too_full[rpId] >= 3) && (n_pat_v > 0 || rp_planes_v_too_full[rpId] >= 3);
288  }
289 
290  for (auto &ds : *tracks) {
291  CTPPSDetId rpId(ds.detId());
292 
293  const TotemRPLocalTrack *track = nullptr;
294  for (auto &ft : ds) {
295  if (ft.isValid()) {
296  track = &ft;
297  break;
298  }
299  }
300 
301  rp_track[rpId] = track;
302  }
303 
304  //------------------------------
305  // diagonal plots
306 
307  for (auto &dpp : diagonalPlots) {
308  auto &dp = dpp.second;
309 
310  // determine diagonal conditions
311  bool cond_4rp = true, cond_2rp = true;
312  for (unsigned int i = 0; i < 4; i++) {
313  if (rp_track[dp.rpIds[i]] == nullptr)
314  cond_4rp = false;
315 
316  if ((i == 0 || i == 3) && rp_track[dp.rpIds[i]] == nullptr)
317  cond_2rp = false;
318  }
319 
320  if (cond_4rp)
321  dp.h_rate_vs_time_dgn_4rp->Fill(event.luminosityBlock(), ls_duration_inverse);
322 
323  if (cond_2rp)
324  dp.h_rate_vs_time_dgn_2rp->Fill(event.luminosityBlock(), ls_duration_inverse);
325 
326  for (unsigned int i = 0; i < 4; i++) {
327  const TotemRPLocalTrack *tr_i = rp_track[dp.rpIds[i]];
328 
329  if (tr_i == nullptr)
330  continue;
331 
332  if (cond_4rp)
333  dp.v_h2_y_vs_x_dgn_4rp[i]->Fill(tr_i->x0(), tr_i->y0());
334 
335  if (cond_2rp)
336  dp.v_h2_y_vs_x_dgn_2rp[i]->Fill(tr_i->x0(), tr_i->y0());
337 
338  for (unsigned int j = 0; j < 4; j++) {
339  if (rp_track[dp.rpIds[j]] == nullptr)
340  continue;
341 
342  dp.h2_track_corr_vert->Fill(i, j);
343 
344  dp.v_h_y[i][j]->Fill(tr_i->y0());
345  }
346  }
347  }
348 
349  //------------------------------
350  // pot plots
351 
352  for (const auto &p : rp_pat_suff) {
353  const auto &rpId = p.first;
354  auto pp_it = potPlots.find(rpId);
355  if (pp_it == potPlots.end())
356  continue;
357  auto &pp = pp_it->second;
358 
359  const auto &pat_suff = rp_pat_suff[rpId];
360  const auto &has_track = (rp_track[rpId] != nullptr);
361 
362  if (pat_suff)
363  pp.h_rate_vs_time_suff->Fill(event.luminosityBlock(), ls_duration_inverse);
364  if (has_track)
365  pp.h_rate_vs_time_track->Fill(event.luminosityBlock(), ls_duration_inverse);
366  if (pat_suff && !has_track)
367  pp.h_rate_vs_time_unresolved->Fill(event.luminosityBlock(), ls_duration_inverse);
368  }
369 }
370 
371 //----------------------------------------------------------------------------------------------------
372 
Detector ID class for TOTEM Si strip detectors.
Definition: TotemRPDetId.h:30
edm::EDGetTokenT< edm::DetSetVector< TotemRPRecHit > > tokenRecHit
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
ElasticPlotDQMSource(const edm::ParameterSet &ps)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:32
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
double y0() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
static constexpr double ls_duration_inverse
A track fit through a single RP.
std::array< unsigned int, 4 > rpIds
virtual TH2F * getTH2F() const
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override
void rpName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:128
edm::EDGetTokenT< edm::DetSetVector< TotemRPLocalTrack > > tokenLocalTrack
CTPPSDetId rpId() const
Definition: CTPPSDetId.h:78
edm::EDGetTokenT< edm::DetSetVector< TotemRPUVPattern > > tokenUVPattern
std::array< std::array< MonitorElement *, 4 >, 4 > v_h_y
std::map< unsigned int, PotPlots > potPlots
std::map< unsigned int, DiagonalPlots > diagonalPlots
auto const & tracks
cannot be loose
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:212
static constexpr unsigned int ls_min
bool isValid() const
Definition: HandleBase.h:70
std::array< MonitorElement *, 4 > v_h2_y_vs_x_dgn_4rp
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
HLT enums.
static constexpr unsigned int ls_max
std::array< MonitorElement *, 4 > v_h2_y_vs_x_dgn_2rp
plots related to one (anti)diagonal
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
double x0() const
Definition: event.py:1
Definition: Run.h:45
Log< level::Error, true > LogProblem