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 
24 
25 #include <string>
26 
27 //----------------------------------------------------------------------------------------------------
28 
30 {
31  public:
32 
34 
35  ~CTPPSCommonDQMSource() override;
36 
37  protected:
38 
39  void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
40  void analyze(edm::Event const& e, edm::EventSetup const& eSetup) override;
41  void beginLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& c) override;
42  void endLuminosityBlock(const edm::LuminosityBlock& iLumi, const edm::EventSetup& c) override;
43 
44  private:
45  unsigned int verbosity;
46  const static int MAX_LUMIS = 6000;
47  const static int MAX_VBINS = 18;
48 
51 
52  int currentLS;
53  int endLS;
54 
55  std::vector<int> rpstate;
56 
58  struct GlobalPlots
59  {
60  MonitorElement *RPState = nullptr;
63 
64  void Init(DQMStore::IBooker &ibooker);
65  };
66 
68 
70  struct ArmPlots
71  {
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 
78 
79  ArmPlots(DQMStore::IBooker &ibooker, int _id);
80  };
81 
82  std::map<unsigned int, ArmPlots> armPlots;
83 };
84 
85 //----------------------------------------------------------------------------------------------------
86 //----------------------------------------------------------------------------------------------------
87 
88 using namespace std;
89 using namespace edm;
90 
93 
94 //----------------------------------------------------------------------------------------------------
95 
97 {
98  ibooker.setCurrentFolder("CTPPS/common");
99 
100  events_per_bx = ibooker.book1D("events per BX", "rp;Event.BX", 4002, -1.5, 4000. + 0.5);
101  events_per_bx_short = ibooker.book1D("events per BX (short)", "rp;Event.BX", 102, -1.5, 100. + 0.5);
102 
103  RPState = ibooker.book2D("rpstate per LS","RP State per Lumisection;Luminosity Section;",MAX_LUMIS, 0, MAX_LUMIS, MAX_VBINS, 0., MAX_VBINS);
104  {
105  TH2F* hist = RPState->getTH2F();
106  hist->SetCanExtend(TH1::kAllAxes);
107  TAxis* ya = hist->GetYaxis();
108  ya->SetBinLabel(1, "45, 210, FR-BT");
109  ya->SetBinLabel(2, "45, 210, FR-HR");
110  ya->SetBinLabel(3, "45, 210, FR-TP");
111  ya->SetBinLabel(4, "45, 220, C1");
112  ya->SetBinLabel(5, "45, 220, FR-BT");
113  ya->SetBinLabel(6, "45, 220, FR-HR");
114  ya->SetBinLabel(7, "45, 220, FR-TP");
115  ya->SetBinLabel(8, "45, 220, NR-BP");
116  ya->SetBinLabel(9, "45, 220, NR-TP");
117  ya->SetBinLabel(10, "56, 210, FR-BT");
118  ya->SetBinLabel(11, "56, 210, FR-HR");
119  ya->SetBinLabel(12, "56, 210, FR-TP");
120  ya->SetBinLabel(13, "56, 220, C1");
121  ya->SetBinLabel(14, "56, 220, FR-BT");
122  ya->SetBinLabel(15, "56, 220, FR-HR");
123  ya->SetBinLabel(16, "56, 220, FR-TP");
124  ya->SetBinLabel(17, "56, 220, NR-BP");
125  ya->SetBinLabel(18, "56, 220, NR-TP");
126  }
127 
128  h_trackCorr_hor = ibooker.book2D("track correlation hor", "ctpps_common_rp_hor", 6, -0.5, 5.5, 6, -0.5, 5.5);
129  {
130  TH2F* hist = h_trackCorr_hor->getTH2F();
131  TAxis* xa = hist->GetXaxis(), *ya = hist->GetYaxis();
132  xa->SetBinLabel(1, "45, 210, far"); ya->SetBinLabel(1, "45, 210, far");
133  xa->SetBinLabel(2, "45, 220, far"); ya->SetBinLabel(2, "45, 220, far");
134  xa->SetBinLabel(3, "45, 220, cyl"); ya->SetBinLabel(3, "45, 220, cyl");
135  xa->SetBinLabel(4, "56, 210, far"); ya->SetBinLabel(4, "56, 210, far");
136  xa->SetBinLabel(5, "56, 220, far"); ya->SetBinLabel(5, "56, 220, far");
137  xa->SetBinLabel(6, "56, 220, cyl"); ya->SetBinLabel(6, "56, 220, cyl");
138  }
139 
140  h_trackCorr_vert = ibooker.book2D("track correlation vert", "ctpps_common_rp_vert", 8, -0.5, 7.5, 8, -0.5, 7.5);
141  {
142  TH2F* hist = h_trackCorr_vert->getTH2F();
143  TAxis* xa = hist->GetXaxis(), *ya = hist->GetYaxis();
144  xa->SetBinLabel(1, "45, 210, far, top"); ya->SetBinLabel(1, "45, 210, far, top");
145  xa->SetBinLabel(2, "45, 210, far, bot"); ya->SetBinLabel(2, "45, 210, far, bot");
146  xa->SetBinLabel(3, "45, 220, far, top"); ya->SetBinLabel(3, "45, 220, far, top");
147  xa->SetBinLabel(4, "45, 220, far, bot"); ya->SetBinLabel(4, "45, 220, far, bot");
148  xa->SetBinLabel(5, "56, 210, far, top"); ya->SetBinLabel(5, "56, 210, far, top");
149  xa->SetBinLabel(6, "56, 210, far, bot"); ya->SetBinLabel(6, "56, 210, far, bot");
150  xa->SetBinLabel(7, "56, 220, far, top"); ya->SetBinLabel(7, "56, 220, far, top");
151  xa->SetBinLabel(8, "56, 220, far, bot"); ya->SetBinLabel(8, "56, 220, far, bot");
152  }
153 }
154 
155 //----------------------------------------------------------------------------------------------------
156 
158 {
159  string name;
161 
162  ibooker.setCurrentFolder("CTPPS/common/sector " + name);
163 
164  string title = "ctpps_common_sector_" + name;
165 
166  h_numRPWithTrack_top = ibooker.book1D("number of top RPs with tracks", title+";number of top RPs with tracks", 5, -0.5, 4.5);
167  h_numRPWithTrack_hor = ibooker.book1D("number of hor RPs with tracks", title+";number of hor RPs with tracks", 5, -0.5, 4.5);
168  h_numRPWithTrack_bot = ibooker.book1D("number of bot RPs with tracks", title+";number of bot RPs with tracks", 5, -0.5, 4.5);
169 
170  h_trackCorr = ibooker.book2D("track correlation", title, 7, -0.5, 6.5, 7, -0.5, 6.5);
171  TH2F *h_trackCorr_h = h_trackCorr->getTH2F();
172  TAxis *xa = h_trackCorr_h->GetXaxis(), *ya = h_trackCorr_h->GetYaxis();
173  xa->SetBinLabel( 1, "210, far, hor"); ya->SetBinLabel( 1, "210, far, hor");
174  xa->SetBinLabel( 2, "210, far, top"); ya->SetBinLabel( 2, "210, far, top");
175  xa->SetBinLabel( 3, "210, far, bot"); ya->SetBinLabel( 3, "210, far, bot");
176  xa->SetBinLabel( 4, "220, cyl" ); ya->SetBinLabel( 4, "220, cyl" );
177  xa->SetBinLabel( 5, "220, far, hor"); ya->SetBinLabel( 5, "220, far, hor");
178  xa->SetBinLabel( 6, "220, far, top"); ya->SetBinLabel( 6, "220, far, top");
179  xa->SetBinLabel( 7, "220, far, bot"); ya->SetBinLabel( 7, "220, far, bot");
180 
181  h_trackCorr_overlap = ibooker.book2D("track correlation hor-vert overlaps", title, 7, -0.5, 6.5, 7, -0.5, 6.5);
182  h_trackCorr_h = h_trackCorr_overlap->getTH2F();
183  xa = h_trackCorr_h->GetXaxis(); ya = h_trackCorr_h->GetYaxis();
184  xa->SetBinLabel( 1, "210, far, hor"); ya->SetBinLabel( 1, "210, far, hor");
185  xa->SetBinLabel( 2, "210, far, top"); ya->SetBinLabel( 2, "210, far, top");
186  xa->SetBinLabel( 3, "210, far, bot"); ya->SetBinLabel( 3, "210, far, bot");
187  xa->SetBinLabel( 4, "220, cyl" ); ya->SetBinLabel( 4, "220, cyl" );
188  xa->SetBinLabel( 5, "220, far, hor"); ya->SetBinLabel( 5, "220, far, hor");
189  xa->SetBinLabel( 6, "220, far, top"); ya->SetBinLabel( 6, "220, far, top");
190  xa->SetBinLabel( 7, "220, far, bot"); ya->SetBinLabel( 7, "220, far, bot");
191 }
192 
193 //----------------------------------------------------------------------------------------------------
194 //----------------------------------------------------------------------------------------------------
195 
197  verbosity(ps.getUntrackedParameter<unsigned int>("verbosity", 0))
198 {
199  tokenLocalTrackLite = consumes< vector<CTPPSLocalTrackLite> >(ps.getParameter<edm::InputTag>("tagLocalTrackLite"));
200  ctppsRecordToken = consumes<CTPPSRecord>(ps.getUntrackedParameter<edm::InputTag>("ctppsmetadata"));
201 
202  currentLS = 0;
203  endLS = 0;
204  rpstate.clear();
205 
206 }
207 
208 //----------------------------------------------------------------------------------------------------
209 
211 {
212 }
213 
214 //----------------------------------------------------------------------------------------------------
215 
217 {
218  // global plots
219  globalPlots.Init(ibooker);
220 
221  // loop over arms
222  for (unsigned int arm = 0; arm < 2; arm++)
223  {
224  armPlots[arm] = ArmPlots(ibooker, arm);
225  }
226 }
227 
228 //----------------------------------------------------------------------------------------------------
229 
231 {
232 
233  // get CTPPS Event Record
235  event.getByToken(ctppsRecordToken, rp);
236 
237  /*
238  RP State (HV & LV & Insertion):
239  0 -> not used
240  1 -> bad
241  2 -> warning
242  3 -> ok
243 
244  CTPPSRecord Order:
245  RP name: RP_45_210_FR_BT
246  RP name: RP_45_210_FR_HR
247  RP name: RP_45_210_FR_TP
248  RP name: RP_45_220_C1
249  RP name: RP_45_220_FR_BT
250  RP name: RP_45_220_FR_HR
251  RP name: RP_45_220_FR_TP
252  RP name: RP_45_220_NR_BT
253  RP name: RP_45_220_NR_TP
254  RP name: RP_56_210_FR_BT
255  RP name: RP_56_210_FR_HR
256  RP name: RP_56_210_FR_TP
257  RP name: RP_56_220_C1
258  RP name: RP_56_220_FR_BT
259  RP name: RP_56_220_FR_HR
260  RP name: RP_56_220_FR_TP
261  RP name: RP_56_220_NR_BT
262  RP name: RP_56_220_NR_TP
263  */
264 
265  if(currentLS > endLS){
266  rpstate.clear();
267  for (uint8_t i = 0; i < CTPPSRecord::RomanPot::Last; ++i) {
268  rpstate.push_back(rp->status(i));
269  }
271  }
272 
273  // get event data
275  event.getByToken(tokenLocalTrackLite, tracks);
276 
277  // check validity
278  bool valid = true;
279  valid &= tracks.isValid();
280 
281  if (!valid)
282  {
283  if (verbosity)
284  {
285  LogProblem("CTPPSCommonDQMSource")
286  << " trackLites.isValid = " << tracks.isValid();
287  }
288 
289  return;
290  }
291 
292  //------------------------------
293  // collect indeces of RP with tracks, for each correlation plot
294  set<signed int> s_rp_idx_global_hor, s_rp_idx_global_vert;
295  map<unsigned int, set<signed int>> ms_rp_idx_arm;
296 
297  for (auto &tr : *tracks)
298  {
299  const CTPPSDetId rpId(tr.getRPId());
300  const unsigned int arm = rpId.arm();
301  const unsigned int stNum = rpId.station();
302  const unsigned int rpNum = rpId.rp();
303  const unsigned int stRPNum = stNum * 10 + rpNum;
304 
305  {
306  signed int idx = -1;
307  if (stRPNum == 3) idx = 0;
308  if (stRPNum == 23) idx = 1;
309  if (stRPNum == 16) idx = 2;
310 
311  if (idx >= 0)
312  s_rp_idx_global_hor.insert(3*arm + idx);
313  }
314 
315  {
316  signed int idx = -1;
317  if (stRPNum == 4) idx = 0;
318  if (stRPNum == 5) idx = 1;
319  if (stRPNum == 24) idx = 2;
320  if (stRPNum == 25) idx = 3;
321 
322  if (idx >= 0)
323  s_rp_idx_global_vert.insert(4*arm + idx);
324  }
325 
326  {
327  signed int idx = -1;
328  if (stRPNum == 3) idx = 0;
329  if (stRPNum == 4) idx = 1;
330  if (stRPNum == 5) idx = 2;
331  if (stRPNum == 16) idx = 3;
332  if (stRPNum == 23) idx = 4;
333  if (stRPNum == 24) idx = 5;
334  if (stRPNum == 25) idx = 6;
335 
336  const signed int hor = ((rpNum == 2) || (rpNum == 3) || (rpNum == 6)) ? 1 : 0;
337 
338  if (idx >= 0)
339  ms_rp_idx_arm[arm].insert(idx * 10 + hor);
340  }
341  }
342 
343  //------------------------------
344  // Global Plots
345 
348 
349  for (const auto &idx1 : s_rp_idx_global_hor)
350  for (const auto &idx2 : s_rp_idx_global_hor)
351  globalPlots.h_trackCorr_hor->Fill(idx1, idx2);
352 
353  for (const auto &idx1 : s_rp_idx_global_vert)
354  for (const auto &idx2 : s_rp_idx_global_vert)
355  globalPlots.h_trackCorr_vert->Fill(idx1, idx2);
356 
357  //------------------------------
358  // Arm Plots
359 
360  map<unsigned int, set<unsigned int>> mTop, mHor, mBot;
361 
362  for (auto &tr : *tracks)
363  {
364  CTPPSDetId rpId(tr.getRPId());
365  const unsigned int rpNum = rpId.rp();
366  const unsigned int armIdx = rpId.arm();
367 
368  if (rpNum == 0 || rpNum == 4)
369  mTop[armIdx].insert(rpId);
370  if (rpNum == 2 || rpNum == 3 || rpNum == 6)
371  mHor[armIdx].insert(rpId);
372  if (rpNum == 1 || rpNum == 5)
373  mBot[armIdx].insert(rpId);
374  }
375 
376  for (auto &p : armPlots)
377  {
378  p.second.h_numRPWithTrack_top->Fill(mTop[p.first].size());
379  p.second.h_numRPWithTrack_hor->Fill(mHor[p.first].size());
380  p.second.h_numRPWithTrack_bot->Fill(mBot[p.first].size());
381  }
382 
383  // track RP correlation
384  for (const auto &ap : ms_rp_idx_arm)
385  {
386  auto &plots = armPlots[ap.first];
387 
388  for (const auto &idx1 : ap.second)
389  {
390  for (const auto &idx2 : ap.second)
391  {
392  plots.h_trackCorr->Fill(idx1/10, idx2/10);
393 
394  if ((idx1 % 10) != (idx2 % 10))
395  plots.h_trackCorr_overlap->Fill(idx1/10, idx2/10);
396  }
397  }
398  }
399 
400 }
401 //----------------------------------------------------------------------------------------------------
402 
404 
405  currentLS = iLumi.id().luminosityBlock();
406 
407 }
408 
409 //----------------------------------------------------------------------------------------------------
410 
412 
413  for(std::vector<int>::size_type i=0; i<rpstate.size();i++){
415  }
416 
417  endLS = iLumi.luminosityBlock();
418  rpstate.clear();
419 
420 }
421 //----------------------------------------------------------------------------------------------------
422 
LuminosityBlockID id() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< std::vector< CTPPSLocalTrackLite > > tokenLocalTrackLite
int bunchCrossing() const
Definition: EventBase.h:66
void beginLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &c) override
uint16_t size_type
CTPPSCommonDQMSource(const edm::ParameterSet &ps)
std::vector< int > rpstate
void Fill(long long x)
std::map< unsigned int, ArmPlots > armPlots
LuminosityBlockNumber_t luminosityBlock() const
void Init(DQMStore::IBooker &ibooker)
static const int MAX_VBINS
edm::EDGetTokenT< CTPPSRecord > ctppsRecordToken
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
uint32_t arm() const
Definition: CTPPSDetId.h:52
bool isValid() const
Definition: HandleBase.h:74
void armName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:115
TH2F * getTH2F() const
plots related to the whole system
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
HLT enums.
void analyze(edm::Event const &e, edm::EventSetup const &eSetup) override
void endLuminosityBlock(const edm::LuminosityBlock &iLumi, const edm::EventSetup &c) override
static const int MAX_LUMIS
Definition: event.py:1
Definition: Run.h:44
uint32_t rp() const
Definition: CTPPSDetId.h:74