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 diagonal plots
210  diagonalPlots[1] = DiagonalPlots(ibooker, 1); // 45 bot - 56 top
211  diagonalPlots[2] = DiagonalPlots(ibooker, 2); // 45 top - 45 bot
212 
213  // loop over arms
214  for (unsigned int arm = 0; arm < 2; arm++)
215  {
216  // loop over stations
217  for (unsigned int st : {0, 2})
218  {
219  // loop over RPs
220  for (unsigned int rp : {4, 5})
221  {
222  TotemRPDetId rpId(arm, st, rp);
223  potPlots[rpId] = PotPlots(ibooker, rpId);
224  }
225  }
226  }
227 }
228 
229 //----------------------------------------------------------------------------------------------------
230 
232 {
233  // get event data
235  event.getByToken(tokenRecHit, hits);
236 
238  event.getByToken(tokenUVPattern, patterns);
239 
241  event.getByToken(tokenLocalTrack, tracks);
242 
243  // check validity
244  bool valid = true;
245  valid &= hits.isValid();
246  valid &= patterns.isValid();
247  valid &= tracks.isValid();
248 
249  if (!valid)
250  {
251  if (verbosity)
252  {
253  LogProblem("ElasticPlotDQMSource") <<
254  "ERROR in TotemDQMModuleRP::analyze > some of the required inputs are not valid. Skipping this event.\n"
255  << " hits.isValid = " << hits.isValid() << "\n"
256  << " patterns.isValid = " << patterns.isValid() << "\n"
257  << " tracks.isValid = " << tracks.isValid();
258  }
259 
260  return;
261  }
262 
263  //------------------------------
264  // categorise RP data
265  map<unsigned int, unsigned int> rp_planes_u_too_full, rp_planes_v_too_full;
266  map<unsigned int, bool> rp_pat_suff;
267  map<unsigned int, const TotemRPLocalTrack*> rp_track;
268 
269  for (const auto &ds : *hits)
270  {
271  TotemRPDetId detId(ds.detId());
272  CTPPSDetId rpId = detId.getRPId();
273 
274  if (ds.size() > 5)
275  {
276  if (detId.isStripsCoordinateUDirection())
277  rp_planes_u_too_full[rpId]++;
278  else
279  rp_planes_v_too_full[rpId]++;
280  }
281  }
282 
283  for (auto &ds : *patterns)
284  {
285  CTPPSDetId rpId(ds.detId());
286 
287  // count U and V patterns
288  unsigned int n_pat_u = 0, n_pat_v = 0;
289  for (auto &p : ds)
290  {
291  if (! p.getFittable())
292  continue;
293 
294  if (p.getProjection() == TotemRPUVPattern::projU)
295  n_pat_u++;
296  else if (p.getProjection() == TotemRPUVPattern::projV)
297  n_pat_v++;
298  }
299 
300  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);
301  }
302 
303  for (auto &ds : *tracks)
304  {
305  CTPPSDetId rpId(ds.detId());
306 
307  const TotemRPLocalTrack *track = nullptr;
308  for (auto &ft : ds)
309  {
310  if (ft.isValid())
311  {
312  track = &ft;
313  break;
314  }
315  }
316 
317  rp_track[rpId] = track;
318  }
319 
320  //------------------------------
321  // diagonal plots
322 
323  for (auto &dpp : diagonalPlots)
324  {
325  auto &dp = dpp.second;
326 
327  // determine diagonal conditions
328  bool cond_4rp = true, cond_2rp = true;
329  for (unsigned int i = 0; i < 4; i++)
330  {
331  if (rp_track[dp.rpIds[i]] == nullptr)
332  cond_4rp = false;
333 
334  if ((i == 0 || i == 3) && rp_track[dp.rpIds[i]] == nullptr)
335  cond_2rp = false;
336  }
337 
338  if (cond_4rp)
339  dp.h_rate_vs_time_dgn_4rp->Fill(event.luminosityBlock(), ls_duration_inverse);
340 
341  if (cond_2rp)
342  dp.h_rate_vs_time_dgn_2rp->Fill(event.luminosityBlock(), ls_duration_inverse);
343 
344  for (unsigned int i = 0; i < 4; i++)
345  {
346  const TotemRPLocalTrack *tr_i = rp_track[dp.rpIds[i]];
347 
348  if (tr_i == nullptr)
349  continue;
350 
351  if (cond_4rp)
352  dp.v_h2_y_vs_x_dgn_4rp[i]->Fill(tr_i->getX0(), tr_i->getY0());
353 
354  if (cond_2rp)
355  dp.v_h2_y_vs_x_dgn_2rp[i]->Fill(tr_i->getX0(), tr_i->getY0());
356 
357  for (unsigned int j = 0; j < 4; j++)
358  {
359  if (rp_track[dp.rpIds[j]] == nullptr)
360  continue;
361 
362  dp.h2_track_corr_vert->Fill(i, j);
363 
364  dp.v_h_y[i][j]->Fill(tr_i->getY0());
365  }
366  }
367  }
368 
369  //------------------------------
370  // pot plots
371 
372  for (const auto &p : rp_pat_suff)
373  {
374  const auto &rpId = p.first;
375  auto pp_it = potPlots.find(rpId);
376  if (pp_it == potPlots.end())
377  continue;
378  auto &pp = pp_it->second;
379 
380  const auto &pat_suff = rp_pat_suff[rpId];
381  const auto &has_track = (rp_track[rpId] != nullptr);
382 
383  if (pat_suff)
384  pp.h_rate_vs_time_suff->Fill(event.luminosityBlock(), ls_duration_inverse);
385  if (has_track)
386  pp.h_rate_vs_time_track->Fill(event.luminosityBlock(), ls_duration_inverse);
387  if (pat_suff && !has_track)
388  pp.h_rate_vs_time_unresolved->Fill(event.luminosityBlock(), ls_duration_inverse);
389  }
390 }
391 
392 //----------------------------------------------------------------------------------------------------
393 
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
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:63
static double ls_duration_inverse
A track fit through a single RP.
#define constexpr
edm::EDGetTokenT< edm::DetSetVector< TotemRPLocalTrack > > tokenLocalTrack
std::array< unsigned int, 4 > rpIds
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override
static unsigned int ls_min
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:118
std::array< std::array< MonitorElement *, 4 >, 4 > v_h_y
void rpName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:139
std::map< unsigned int, PotPlots > potPlots
CTPPSDetId getRPId() const
Definition: CTPPSDetId.h:97
bool isValid() const
Definition: HandleBase.h:74
TH2F * getTH2F() const
std::map< unsigned int, DiagonalPlots > diagonalPlots
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:279
MonitorElement * book2D(Args &&...args)
Definition: DQMStore.h:136
auto dp
Definition: deltaR.h:22
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
Definition: event.py:1
Definition: Run.h:43