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