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