CMS 3D CMS Logo

CTPPSCommonDQMSource.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of TotemDQM and TOTEM offline software.
4  * Authors:
5  * Jan Kašpar (jan.kaspar@gmail.com)
6  *
7  ****************************************************************************/
8 
16 
19 
24 
25 #include <string>
26 
27 //----------------------------------------------------------------------------------------------------
28 
29 class CTPPSCommonDQMSource : public DQMOneEDAnalyzer<edm::LuminosityBlockCache<std::vector<int>>> {
30 public:
32  ~CTPPSCommonDQMSource() override;
33 
34 protected:
35  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
36  void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override;
37  std::shared_ptr<std::vector<int>> globalBeginLuminosityBlock(const edm::LuminosityBlock &iLumi,
38  const edm::EventSetup &c) const override;
39  void globalEndLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &c) override;
40 
41  void analyzeCTPPSRecord(edm::Event const &event, edm::EventSetup const &eventSetup);
42  void analyzeTracks(edm::Event const &event, edm::EventSetup const &eventSetup);
43  void analyzeProtons(edm::Event const &event, edm::EventSetup const &eventSetup);
44 
45 private:
46  const unsigned int verbosity;
47  constexpr static int MAX_LUMIS = 6000;
48  constexpr static int MAX_VBINS = 18;
49 
53 
54  int currentLS;
55  int endLS;
56 
57  std::vector<int> rpstate;
58 
60  struct GlobalPlots {
61  MonitorElement *RPState = nullptr;
64 
65  void Init(DQMStore::IBooker &ibooker);
66  };
67 
69 
71  struct ArmPlots {
72  int id;
73 
74  MonitorElement *h_numRPWithTrack_top = nullptr, *h_numRPWithTrack_hor = nullptr, *h_numRPWithTrack_bot = nullptr;
75  MonitorElement *h_trackCorr = nullptr, *h_trackCorr_overlap = nullptr;
76 
77  MonitorElement *h_proton_xi = nullptr, *h_proton_t = nullptr, *h_proton_time = nullptr;
78 
79  struct TrackingRPPlots {
81  };
82 
83  std::map<unsigned int, TrackingRPPlots> trackingRPPlots;
84 
85  struct TimingRPPlots {
86  MonitorElement *h_x, *h_time;
87  };
88 
89  std::map<unsigned int, TimingRPPlots> timingRPPlots;
90 
91  ArmPlots() {}
92 
93  ArmPlots(DQMStore::IBooker &ibooker, int _id);
94  };
95 
96  std::map<unsigned int, ArmPlots> armPlots;
97 };
98 
99 //----------------------------------------------------------------------------------------------------
100 //----------------------------------------------------------------------------------------------------
101 
102 using namespace std;
103 using namespace edm;
104 
107 
108 //----------------------------------------------------------------------------------------------------
109 
111  ibooker.setCurrentFolder("CTPPS/common");
112 
113  events_per_bx = ibooker.book1D("events per BX", "rp;Event.BX", 4002, -1.5, 4000. + 0.5);
114  events_per_bx_short = ibooker.book1D("events per BX (short)", "rp;Event.BX", 102, -1.5, 100. + 0.5);
115 
116  /*
117  RP State (HV & LV & Insertion):
118  0 -> not used
119  1 -> bad
120  2 -> warning
121  3 -> ok
122  */
123  RPState = ibooker.book2D("rpstate per LS",
124  "RP State per Lumisection;Luminosity Section;",
125  MAX_LUMIS,
126  0,
127  MAX_LUMIS,
128  MAX_VBINS,
129  0.,
130  MAX_VBINS);
131  {
132  TH2F *hist = RPState->getTH2F();
133  hist->SetCanExtend(TH1::kAllAxes);
134  TAxis *ya = hist->GetYaxis();
135  ya->SetBinLabel(1, "45, 210, FR-BT");
136  ya->SetBinLabel(2, "45, 210, FR-HR");
137  ya->SetBinLabel(3, "45, 210, FR-TP");
138  ya->SetBinLabel(4, "45, 220, C1");
139  ya->SetBinLabel(5, "45, 220, FR-BT");
140  ya->SetBinLabel(6, "45, 220, FR-HR");
141  ya->SetBinLabel(7, "45, 220, FR-TP");
142  ya->SetBinLabel(8, "45, 220, NR-BP");
143  ya->SetBinLabel(9, "45, 220, NR-TP");
144  ya->SetBinLabel(10, "56, 210, FR-BT");
145  ya->SetBinLabel(11, "56, 210, FR-HR");
146  ya->SetBinLabel(12, "56, 210, FR-TP");
147  ya->SetBinLabel(13, "56, 220, C1");
148  ya->SetBinLabel(14, "56, 220, FR-BT");
149  ya->SetBinLabel(15, "56, 220, FR-HR");
150  ya->SetBinLabel(16, "56, 220, FR-TP");
151  ya->SetBinLabel(17, "56, 220, NR-BP");
152  ya->SetBinLabel(18, "56, 220, NR-TP");
153  }
154 
155  h_trackCorr_hor = ibooker.book2D("track correlation hor", "ctpps_common_rp_hor", 6, -0.5, 5.5, 6, -0.5, 5.5);
156  {
157  TH2F *hist = h_trackCorr_hor->getTH2F();
158  TAxis *xa = hist->GetXaxis(), *ya = hist->GetYaxis();
159  xa->SetBinLabel(1, "45, 210, far");
160  ya->SetBinLabel(1, "45, 210, far");
161  xa->SetBinLabel(2, "45, 220, far");
162  ya->SetBinLabel(2, "45, 220, far");
163  xa->SetBinLabel(3, "45, 220, cyl");
164  ya->SetBinLabel(3, "45, 220, cyl");
165  xa->SetBinLabel(4, "56, 210, far");
166  ya->SetBinLabel(4, "56, 210, far");
167  xa->SetBinLabel(5, "56, 220, far");
168  ya->SetBinLabel(5, "56, 220, far");
169  xa->SetBinLabel(6, "56, 220, cyl");
170  ya->SetBinLabel(6, "56, 220, cyl");
171  }
172 
173  h_trackCorr_vert = ibooker.book2D("track correlation vert", "ctpps_common_rp_vert", 8, -0.5, 7.5, 8, -0.5, 7.5);
174  {
175  TH2F *hist = h_trackCorr_vert->getTH2F();
176  TAxis *xa = hist->GetXaxis(), *ya = hist->GetYaxis();
177  xa->SetBinLabel(1, "45, 210, far, top");
178  ya->SetBinLabel(1, "45, 210, far, top");
179  xa->SetBinLabel(2, "45, 210, far, bot");
180  ya->SetBinLabel(2, "45, 210, far, bot");
181  xa->SetBinLabel(3, "45, 220, far, top");
182  ya->SetBinLabel(3, "45, 220, far, top");
183  xa->SetBinLabel(4, "45, 220, far, bot");
184  ya->SetBinLabel(4, "45, 220, far, bot");
185  xa->SetBinLabel(5, "56, 210, far, top");
186  ya->SetBinLabel(5, "56, 210, far, top");
187  xa->SetBinLabel(6, "56, 210, far, bot");
188  ya->SetBinLabel(6, "56, 210, far, bot");
189  xa->SetBinLabel(7, "56, 220, far, top");
190  ya->SetBinLabel(7, "56, 220, far, top");
191  xa->SetBinLabel(8, "56, 220, far, bot");
192  ya->SetBinLabel(8, "56, 220, far, bot");
193  }
194 }
195 
196 //----------------------------------------------------------------------------------------------------
197 
199  string name;
201 
202  ibooker.setCurrentFolder("CTPPS/common/sector " + name);
203 
204  string title = "ctpps_common_sector_" + name;
205 
207  ibooker.book1D("number of top RPs with tracks", title + ";number of top RPs with tracks", 5, -0.5, 4.5);
209  ibooker.book1D("number of hor RPs with tracks", title + ";number of hor RPs with tracks", 5, -0.5, 4.5);
211  ibooker.book1D("number of bot RPs with tracks", title + ";number of bot RPs with tracks", 5, -0.5, 4.5);
212 
213  h_trackCorr = ibooker.book2D("track correlation", title, 7, -0.5, 6.5, 7, -0.5, 6.5);
214  TH2F *h_trackCorr_h = h_trackCorr->getTH2F();
215  TAxis *xa = h_trackCorr_h->GetXaxis(), *ya = h_trackCorr_h->GetYaxis();
216  xa->SetBinLabel(1, "210, far, hor");
217  ya->SetBinLabel(1, "210, far, hor");
218  xa->SetBinLabel(2, "210, far, top");
219  ya->SetBinLabel(2, "210, far, top");
220  xa->SetBinLabel(3, "210, far, bot");
221  ya->SetBinLabel(3, "210, far, bot");
222  xa->SetBinLabel(4, "220, cyl");
223  ya->SetBinLabel(4, "220, cyl");
224  xa->SetBinLabel(5, "220, far, hor");
225  ya->SetBinLabel(5, "220, far, hor");
226  xa->SetBinLabel(6, "220, far, top");
227  ya->SetBinLabel(6, "220, far, top");
228  xa->SetBinLabel(7, "220, far, bot");
229  ya->SetBinLabel(7, "220, far, bot");
230 
231  h_trackCorr_overlap = ibooker.book2D("track correlation hor-vert overlaps", title, 7, -0.5, 6.5, 7, -0.5, 6.5);
232  h_trackCorr_h = h_trackCorr_overlap->getTH2F();
233  xa = h_trackCorr_h->GetXaxis();
234  ya = h_trackCorr_h->GetYaxis();
235  xa->SetBinLabel(1, "210, far, hor");
236  ya->SetBinLabel(1, "210, far, hor");
237  xa->SetBinLabel(2, "210, far, top");
238  ya->SetBinLabel(2, "210, far, top");
239  xa->SetBinLabel(3, "210, far, bot");
240  ya->SetBinLabel(3, "210, far, bot");
241  xa->SetBinLabel(4, "220, cyl");
242  ya->SetBinLabel(4, "220, cyl");
243  xa->SetBinLabel(5, "220, far, hor");
244  ya->SetBinLabel(5, "220, far, hor");
245  xa->SetBinLabel(6, "220, far, top");
246  ya->SetBinLabel(6, "220, far, top");
247  xa->SetBinLabel(7, "220, far, bot");
248  ya->SetBinLabel(7, "220, far, bot");
249 
250  h_proton_xi = ibooker.book1D("proton xi", title + ";xi", 100, 0., 0.3);
251  h_proton_t = ibooker.book1D("proton t", title + ";|t| GeV^{2}", 100, 0., 5.);
252  h_proton_time = ibooker.book1D("proton time", title + ";time (ns)", 100, -25., 50.);
253 
254  for (const unsigned int &rpDecId : {2, 3, 16, 23}) {
255  unsigned int st = rpDecId / 10, rp = rpDecId % 10, rpFullDecId = id * 100 + rpDecId;
256  CTPPSDetId rpId(CTPPSDetId::sdTrackingStrip, id, st, rp);
257  string stName, rpName;
258  rpId.stationName(stName, CTPPSDetId::nShort);
259  rpId.rpName(rpName, CTPPSDetId::nShort);
260  rpName = stName + "_" + rpName;
261 
262  if (rp == 6) {
263  timingRPPlots[rpFullDecId] = {
264  ibooker.book1D(rpName + " - track x histogram", title + "/" + rpName + ";track x (mm)", 200, 0., 40.),
265  ibooker.book1D(
266  rpName + " - track time histogram", title + "/" + rpName + ";track time (ns)", 100, -25., +50.)};
267  } else {
268  trackingRPPlots[rpFullDecId] = {
269  ibooker.book1D(rpName + " - track x histogram", title + "/" + rpName + ";track x (mm)", 200, 0., 40.),
270  ibooker.book1D(rpName + " - track y histogram", title + "/" + rpName + ";track y (mm)", 200, -20., +20.)};
271  }
272  }
273 }
274 
275 //----------------------------------------------------------------------------------------------------
276 //----------------------------------------------------------------------------------------------------
277 
279  : verbosity(ps.getUntrackedParameter<unsigned int>("verbosity", 0)),
280  ctppsRecordToken(consumes<CTPPSRecord>(ps.getUntrackedParameter<edm::InputTag>("ctppsmetadata"))),
281  tokenLocalTrackLite(consumes<vector<CTPPSLocalTrackLite>>(ps.getParameter<edm::InputTag>("tagLocalTrackLite"))),
282  tokenRecoProtons(consumes<std::vector<reco::ForwardProton>>(ps.getParameter<InputTag>("tagRecoProtons"))) {
283  currentLS = 0;
284  endLS = 0;
285  rpstate.clear();
286 }
287 
288 //----------------------------------------------------------------------------------------------------
289 
291 
292 //----------------------------------------------------------------------------------------------------
293 
295  // global plots
296  globalPlots.Init(ibooker);
297 
298  // loop over arms
299  for (unsigned int arm = 0; arm < 2; arm++) {
300  armPlots[arm] = ArmPlots(ibooker, arm);
301  }
302 }
303 
304 //----------------------------------------------------------------------------------------------------
305 
307  analyzeCTPPSRecord(event, eventSetup);
308  analyzeTracks(event, eventSetup);
309  analyzeProtons(event, eventSetup);
310 }
311 
312 //----------------------------------------------------------------------------------------------------
313 
315  Handle<CTPPSRecord> hCTPPSRecord;
316  event.getByToken(ctppsRecordToken, hCTPPSRecord);
317 
318  if (!hCTPPSRecord.isValid()) {
319  if (verbosity)
320  LogProblem("CTPPSCommonDQMSource") << "ERROR in CTPPSCommonDQMSource::analyzeCTPPSRecord > input not available.";
321 
322  return;
323  }
324 
325  auto &rpstate = *luminosityBlockCache(event.getLuminosityBlock().index());
326  if (rpstate.empty()) {
327  rpstate.reserve(CTPPSRecord::RomanPot::Last);
328  for (uint8_t i = 0; i < CTPPSRecord::RomanPot::Last; ++i)
329  rpstate.push_back(hCTPPSRecord->status(i));
330  }
331 }
332 
333 //----------------------------------------------------------------------------------------------------
334 
336  // get event data
338  event.getByToken(tokenLocalTrackLite, hTracks);
339 
340  // check validity
341  if (!hTracks.isValid()) {
342  if (verbosity)
343  LogProblem("CTPPSCommonDQMSource") << "ERROR in CTPPSCommonDQMSource::analyzeTracks > input not available.";
344 
345  return;
346  }
347 
348  //------------------------------
349  // collect indeces of RP with tracks, for each correlation plot
350  set<signed int> s_rp_idx_global_hor, s_rp_idx_global_vert;
351  map<unsigned int, set<signed int>> ms_rp_idx_arm;
352 
353  for (auto &tr : *hTracks) {
354  const CTPPSDetId rpId(tr.rpId());
355  const unsigned int arm = rpId.arm();
356  const unsigned int stNum = rpId.station();
357  const unsigned int rpNum = rpId.rp();
358  const unsigned int stRPNum = stNum * 10 + rpNum;
359 
360  {
361  signed int idx = -1;
362  if (stRPNum == 3)
363  idx = 0;
364  if (stRPNum == 23)
365  idx = 1;
366  if (stRPNum == 16)
367  idx = 2;
368 
369  if (idx >= 0)
370  s_rp_idx_global_hor.insert(3 * arm + idx);
371  }
372 
373  {
374  signed int idx = -1;
375  if (stRPNum == 4)
376  idx = 0;
377  if (stRPNum == 5)
378  idx = 1;
379  if (stRPNum == 24)
380  idx = 2;
381  if (stRPNum == 25)
382  idx = 3;
383 
384  if (idx >= 0)
385  s_rp_idx_global_vert.insert(4 * arm + idx);
386  }
387 
388  {
389  signed int idx = -1;
390  if (stRPNum == 3)
391  idx = 0;
392  if (stRPNum == 4)
393  idx = 1;
394  if (stRPNum == 5)
395  idx = 2;
396  if (stRPNum == 16)
397  idx = 3;
398  if (stRPNum == 23)
399  idx = 4;
400  if (stRPNum == 24)
401  idx = 5;
402  if (stRPNum == 25)
403  idx = 6;
404 
405  const signed int hor = ((rpNum == 2) || (rpNum == 3) || (rpNum == 6)) ? 1 : 0;
406 
407  if (idx >= 0)
408  ms_rp_idx_arm[arm].insert(idx * 10 + hor);
409  }
410  }
411 
412  //------------------------------
413  // Global Plots
414 
417 
418  for (const auto &idx1 : s_rp_idx_global_hor)
419  for (const auto &idx2 : s_rp_idx_global_hor)
420  globalPlots.h_trackCorr_hor->Fill(idx1, idx2);
421 
422  for (const auto &idx1 : s_rp_idx_global_vert)
423  for (const auto &idx2 : s_rp_idx_global_vert)
424  globalPlots.h_trackCorr_vert->Fill(idx1, idx2);
425 
426  //------------------------------
427  // Arm Plots
428 
429  map<unsigned int, set<unsigned int>> mTop, mHor, mBot;
430 
431  for (auto &tr : *hTracks) {
432  CTPPSDetId rpId(tr.rpId());
433  const unsigned int rpNum = rpId.rp();
434  const unsigned int armIdx = rpId.arm();
435 
436  if (rpNum == 0 || rpNum == 4)
437  mTop[armIdx].insert(rpId);
438  if (rpNum == 2 || rpNum == 3 || rpNum == 6)
439  mHor[armIdx].insert(rpId);
440  if (rpNum == 1 || rpNum == 5)
441  mBot[armIdx].insert(rpId);
442 
443  auto &ap = armPlots[rpId.arm()];
444  unsigned int rpDecId = rpId.arm() * 100 + rpId.station() * 10 + rpId.rp();
445 
446  // fill in reference tracking-RP plots
447  {
448  auto it = ap.trackingRPPlots.find(rpDecId);
449  if (it != ap.trackingRPPlots.end()) {
450  it->second.h_x->Fill(tr.x());
451  it->second.h_y->Fill(tr.y());
452  }
453  }
454 
455  // fill in reference timing-RP plots
456  {
457  auto it = ap.timingRPPlots.find(rpDecId);
458  if (it != ap.timingRPPlots.end()) {
459  it->second.h_x->Fill(tr.x());
460  it->second.h_time->Fill(tr.time());
461  }
462  }
463  }
464 
465  for (auto &p : armPlots) {
466  p.second.h_numRPWithTrack_top->Fill(mTop[p.first].size());
467  p.second.h_numRPWithTrack_hor->Fill(mHor[p.first].size());
468  p.second.h_numRPWithTrack_bot->Fill(mBot[p.first].size());
469  }
470 
471  //------------------------------
472  // Correlation plots
473 
474  for (const auto &ap : ms_rp_idx_arm) {
475  auto &plots = armPlots[ap.first];
476 
477  for (const auto &idx1 : ap.second) {
478  for (const auto &idx2 : ap.second) {
479  plots.h_trackCorr->Fill(idx1 / 10, idx2 / 10);
480 
481  if ((idx1 % 10) != (idx2 % 10))
482  plots.h_trackCorr_overlap->Fill(idx1 / 10, idx2 / 10);
483  }
484  }
485  }
486 }
487 
488 //----------------------------------------------------------------------------------------------------
489 
491  // get event data
493  event.getByToken(tokenRecoProtons, hRecoProtons);
494 
495  // check validity
496  if (!hRecoProtons.isValid()) {
497  if (verbosity)
498  LogProblem("CTPPSCommonDQMSource") << "ERROR in CTPPSCommonDQMSource::analyzeProtons > input not available.";
499 
500  return;
501  }
502 
503  // loop over protons
504  for (auto &p : *hRecoProtons) {
505  if (!p.validFit())
506  continue;
507 
508  signed int armIndex = -1;
509  if (p.lhcSector() == reco::ForwardProton::LHCSector::sector45)
510  armIndex = 0;
511  if (p.lhcSector() == reco::ForwardProton::LHCSector::sector56)
512  armIndex = 1;
513  if (armIndex < 0)
514  continue;
515 
516  auto &plots = armPlots[armIndex];
517 
518  plots.h_proton_xi->Fill(p.xi());
519  plots.h_proton_t->Fill(fabs(p.t()));
520  plots.h_proton_time->Fill(p.time());
521  }
522 }
523 
524 //----------------------------------------------------------------------------------------------------
525 
527  const edm::EventSetup &) const {
528  return std::make_shared<std::vector<int>>();
529 }
530 
531 //----------------------------------------------------------------------------------------------------
532 
534  auto const &rpstate = *luminosityBlockCache(iLumi.index());
535  auto currentLS = iLumi.id().luminosityBlock();
536  for (std::vector<int>::size_type i = 0; i < rpstate.size(); i++)
537  globalPlots.RPState->setBinContent(currentLS, i + 1, rpstate[i]);
538 }
539 
540 //----------------------------------------------------------------------------------------------------
541 
LuminosityBlockID id() const
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
LuminosityBlockIndex index() const
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
std::map< unsigned int, TimingRPPlots > timingRPPlots
Local (=single RP) track with essential information only.
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
int bunchCrossing() const
Definition: EventBase.h:64
const unsigned int verbosity
uint16_t size_type
void globalEndLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &c) override
CTPPSCommonDQMSource(const edm::ParameterSet &ps)
std::vector< int > rpstate
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
std::map< unsigned int, ArmPlots > armPlots
void Fill(long long x)
void Init(DQMStore::IBooker &ibooker)
const edm::EDGetTokenT< std::vector< reco::ForwardProton > > tokenRecoProtons
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void analyzeTracks(edm::Event const &event, edm::EventSetup const &eventSetup)
void rpName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:128
LuminosityBlock const & getLuminosityBlock() const
Definition: Event.h:98
uint32_t arm() const
Definition: CTPPSDetId.h:51
bool isValid() const
Definition: HandleBase.h:70
void armName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:92
std::shared_ptr< std::vector< int > > globalBeginLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &c) const override
plots related to the whole system
std::map< unsigned int, TrackingRPPlots > trackingRPPlots
Status status(const uint8_t rp) const
Return the status of the given roman pot.
Definition: CTPPSRecord.h:61
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
LuminosityBlockNumber_t luminosityBlock() const
Base class for CTPPS detector IDs.
Definition: CTPPSDetId.h:32
const edm::EDGetTokenT< std::vector< CTPPSLocalTrackLite > > tokenLocalTrackLite
void analyzeProtons(edm::Event const &event, edm::EventSetup const &eventSetup)
Class to contain CTPPS information from soft FED 1022.
Definition: CTPPSRecord.h:20
fixed size matrix
HLT enums.
void analyzeCTPPSRecord(edm::Event const &event, edm::EventSetup const &eventSetup)
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override
void stationName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:110
const edm::EDGetTokenT< CTPPSRecord > ctppsRecordToken
#define constexpr
Definition: event.py:1
Definition: Run.h:45
uint32_t rp() const
Definition: CTPPSDetId.h:65