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