CMS 3D CMS Logo

TotemT2DQMSource.cc
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * This is a part of TOTEM offline software.
4  * Author:
5  * Laurent Forthomme
6  * Arkadiusz Cwikla
7  *
8  ****************************************************************************/
9 
16 
19 
21 
25 
28 
29 #include <string>
30 
32 public:
34  ~TotemT2DQMSource() override = default;
35 
36 protected:
37  void dqmBeginRun(const edm::Run&, const edm::EventSetup&) override;
38  void bookHistograms(DQMStore::IBooker&, const edm::Run&, const edm::EventSetup&) override;
39  void analyze(const edm::Event&, const edm::EventSetup&) override;
40 
41 private:
42  void fillActivePlanes(std::unordered_map<unsigned int, std::set<unsigned int>>&, const TotemT2DetId&);
43  void fillTriggerBitset(const TotemT2DetId&);
44  void clearTriggerBitset();
48  void fillEdges(const TotemT2Digi&, const TotemT2DetId&);
49  void fillToT(const TotemT2RecHit&, const TotemT2DetId&);
50 
54 
55  std::unique_ptr<TotemT2Segmentation> segm_;
56 
57  static constexpr double HPTDC_BIN_WIDTH_NS_ = 25. / 1024;
59 
60  const unsigned int nbinsx_, nbinsy_;
61  const unsigned int windowsNum_;
62 
63  struct SectorPlots {
66 
68  std::bitset<(TotemT2DetId::maxPlane + 1) * (TotemT2DetId::maxChannel + 1)> hitTilesArray;
69  static const unsigned int MINIMAL_TRIGGER = 3;
70 
71  MonitorElement *leadingEdge = nullptr, *trailingEdge = nullptr, *timeOverTreshold = nullptr;
72 
73  SectorPlots() = default;
75  DQMStore::IBooker& ibooker, unsigned int id, unsigned int nbinsx, unsigned int nbinsy, unsigned int windowsNum);
76  };
77 
78  struct PlanePlots {
81 
82  PlanePlots() = default;
83  PlanePlots(DQMStore::IBooker& ibooker, unsigned int id, unsigned int nbinsx, unsigned int nbinsy);
84  };
85 
86  std::unordered_map<unsigned int, SectorPlots> sectorPlots_;
87  std::unordered_map<unsigned int, PlanePlots> planePlots_;
88 };
89 
91  DQMStore::IBooker& ibooker, unsigned int id, unsigned int nbinsx, unsigned int nbinsy, unsigned int windowsNum) {
93 
95  ibooker.setCurrentFolder(path);
96 
98 
99  activePlanes = ibooker.book1D("active planes", title + " which planes are active;plane number", 8, -0.5, 7.5);
100 
101  activePlanesCount = ibooker.book1D(
102  "number of active planes", title + " how many planes are active;number of active planes", 9, -0.5, 8.5);
103 
104  triggerEmulator = ibooker.book2DD("trigger emulator",
105  title + " trigger emulator;arbitrary unit;arbitrary unit",
106  nbinsx,
107  -0.5,
108  double(nbinsx) - 0.5,
109  nbinsy,
110  -0.5,
111  double(nbinsy) - 0.5);
112  leadingEdge = ibooker.book1D(
113  "leading edge", title + " leading edge (DIGIs); leading edge (ns)", 25 * windowsNum, 0, 25 * windowsNum);
114  trailingEdge = ibooker.book1D(
115  "trailing edge", title + " trailing edge (DIGIs); trailing edge (ns)", 25 * windowsNum, 0, 25 * windowsNum);
116 
117  timeOverTreshold = ibooker.book1D(
118  "time over threshold", title + " time over threshold (rechit);time over threshold (ns)", 250, -25, 100);
119 }
120 
122  unsigned int id,
123  unsigned int nbinsx,
124  unsigned int nbinsy) {
128  ibooker.setCurrentFolder(path);
129 
130  digisMultiplicity = ibooker.book2DD("digis multiplicity",
131  title + " digis multiplicity;arbitrary unit;arbitrary unit",
132  nbinsx,
133  -0.5,
134  double(nbinsx) - 0.5,
135  nbinsy,
136  -0.5,
137  double(nbinsy) - 0.5);
138  rechitMultiplicity = ibooker.book2DD("rechits multiplicity",
139  title + " rechits multiplicity;x;y",
140  nbinsx,
141  -0.5,
142  double(nbinsx) - 0.5,
143  nbinsy,
144  -0.5,
145  double(nbinsy) - 0.5);
146 }
147 
150  digiToken_(consumes<edmNew::DetSetVector<TotemT2Digi>>(iConfig.getParameter<edm::InputTag>("digisTag"))),
151  rechitToken_(consumes<edmNew::DetSetVector<TotemT2RecHit>>(iConfig.getParameter<edm::InputTag>("rechitsTag"))),
152  nbinsx_(iConfig.getParameter<unsigned int>("nbinsx")),
153  nbinsy_(iConfig.getParameter<unsigned int>("nbinsy")),
154  windowsNum_(iConfig.getParameter<unsigned int>("windowsNum")) {}
155 
157 
159  ibooker.cd();
160  ibooker.setCurrentFolder("TotemT2");
161 
162  bookErrorFlagsHistogram(ibooker);
163 
164  for (unsigned int arm = 0; arm <= CTPPSDetId::maxArm; ++arm) {
165  for (unsigned int pl = 0; pl <= TotemT2DetId::maxPlane; ++pl) {
166  const TotemT2DetId detid(arm, pl, 0);
167  const TotemT2DetId planeId(detid.planeId());
168  planePlots_[planeId] = PlanePlots(ibooker, planeId, nbinsx_, nbinsy_);
169  }
170  const TotemT2DetId detid(arm, 0, 0);
171  const TotemT2DetId secId(detid.armId());
172  sectorPlots_[secId] = SectorPlots(ibooker, secId, nbinsx_, nbinsy_, windowsNum_);
173  }
174 
175  // build a segmentation helper for the size of histograms previously booked
176  segm_ = std::make_unique<TotemT2Segmentation>(iSetup.getData(geometryToken_), nbinsx_, nbinsy_);
177 }
178 
180  // fill digis information
181  for (const auto& ds_digis : iEvent.get(digiToken_)) {
182  const TotemT2DetId detid(ds_digis.detId());
183  const TotemT2DetId planeId(detid.planeId());
184  for (const auto& digi : ds_digis) {
185  segm_->fill(planePlots_[planeId].digisMultiplicity->getTH2D(), detid);
186  fillTriggerBitset(detid);
188  fillEdges(digi, detid);
189  }
190  }
191 
192  // fill rechits information
193  std::unordered_map<unsigned int, std::set<unsigned int>> planes;
194  for (const auto& ds_rechits : iEvent.get(rechitToken_)) {
195  const TotemT2DetId detid(ds_rechits.detId());
196  const TotemT2DetId planeId(detid.planeId());
197  for (const auto& rechit : ds_rechits) {
198  segm_->fill(planePlots_[planeId].rechitMultiplicity->getTH2D(), detid);
199  fillToT(rechit, detid);
200  fillActivePlanes(planes, detid);
201  }
202  }
203 
204  for (const auto& plt : sectorPlots_)
205  plt.second.activePlanesCount->Fill(planes[plt.first].size());
206 
207  for (unsigned short arm = 0; arm <= CTPPSDetId::maxArm; ++arm)
208  for (unsigned short plane = 0; plane <= 1; ++plane)
209  for (unsigned short id = 0; id <= TotemT2DetId::maxChannel; ++id) {
210  const TotemT2DetId detid(arm, plane, id);
211  if (areChannelsTriggered(detid)) {
212  const TotemT2DetId secId(detid.armId());
213  segm_->fill(sectorPlots_[secId].triggerEmulator->getTH2D(), detid);
214  }
215  }
216 
218 }
219 
220 void TotemT2DQMSource::fillActivePlanes(std::unordered_map<unsigned int, std::set<unsigned int>>& planes,
221  const TotemT2DetId& detid) {
222  const TotemT2DetId secId(detid.armId());
223  unsigned short pl = detid.plane();
224 
225  planes[secId].insert(pl);
226 
227  sectorPlots_[secId].activePlanes->Fill(pl);
228 }
229 
231  const TotemT2DetId secId(detid.armId());
232  unsigned short pl = detid.plane();
233  unsigned short ch = detid.channel();
234  sectorPlots_[secId].hitTilesArray[4 * pl + ch] = true;
235 }
236 
238  for (auto& sectorPlot : sectorPlots_)
239  sectorPlot.second.hitTilesArray.reset();
240 }
241 
243  unsigned int channel = detid.channel();
244 
245  // prepare mask
246  std::bitset<(TotemT2DetId::maxPlane + 1) * (TotemT2DetId::maxChannel + 1)> mask;
247  // check if plane is even or not
248  unsigned int pl = detid.plane() % 2 == 0 ? 0 : 1;
249  // set only even or only odd plane bits for this channel
250  for (; pl <= TotemT2DetId::maxPlane; pl += 2)
251  mask[4 * pl + channel] = true;
252  const TotemT2DetId secId(detid.armId());
253  // check how many masked channels were hit
254  unsigned int triggeredChannelsNumber = (mask & sectorPlots_[secId].hitTilesArray).count();
255 
256  return triggeredChannelsNumber >= SectorPlots::MINIMAL_TRIGGER;
257 }
258 
260  HPTDCErrorFlags_2D_ = ibooker.book2D("HPTDC Errors", " HPTDC Errors?", 8, -0.5, 7.5, 2, -0.5, 1.5);
261  for (unsigned short error_index = 1; error_index <= 8; ++error_index)
262  HPTDCErrorFlags_2D_->setBinLabel(error_index, "Flag " + std::to_string(error_index));
263 
264  int tmpIndex = 0;
265  HPTDCErrorFlags_2D_->setBinLabel(++tmpIndex, "some id 0", /* axis */ 2);
266  HPTDCErrorFlags_2D_->setBinLabel(++tmpIndex, "some id 1", /* axis */ 2);
267 }
268 
270  // placeholder for error hitogram filling
271  (void)digi;
272 }
273 
274 void TotemT2DQMSource::fillEdges(const TotemT2Digi& digi, const TotemT2DetId& detid) {
275  const TotemT2DetId secId(detid.armId());
276  sectorPlots_[secId].leadingEdge->Fill(HPTDC_BIN_WIDTH_NS_ * digi.leadingEdge());
277  sectorPlots_[secId].trailingEdge->Fill(HPTDC_BIN_WIDTH_NS_ * digi.trailingEdge());
278 }
279 
280 void TotemT2DQMSource::fillToT(const TotemT2RecHit& rechit, const TotemT2DetId& detid) {
281  const TotemT2DetId secId(detid.armId());
282  sectorPlots_[secId].timeOverTreshold->Fill(rechit.toT());
283 }
284 
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void fillActivePlanes(std::unordered_map< unsigned int, std::set< unsigned int >> &, const TotemT2DetId &)
MonitorElement * digisMultiplicity
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
Detector ID class for Totem T2 detectors. Bits [19:31] : Base CTPPSDetId class attributes Bits [16:18...
Definition: TotemT2DetId.h:25
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
std::unique_ptr< TotemT2Segmentation > segm_
MonitorElement * HPTDCErrorFlags_2D_
void fillEdges(const TotemT2Digi &, const TotemT2DetId &)
static constexpr uint32_t maxChannel
Definition: TotemT2DetId.h:35
std::string to_string(const V &value)
Definition: OMSAccess.h:71
TotemT2DetId planeId() const
Definition: TotemT2DetId.h:60
static const unsigned int MINIMAL_TRIGGER
const unsigned int nbinsx_
TotemT2DQMSource(const edm::ParameterSet &)
static constexpr uint32_t maxPlane
Definition: TotemT2DetId.h:34
constexpr uint32_t mask
Definition: gpuClustering.h:26
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
void bookHistograms(DQMStore::IBooker &, const edm::Run &, const edm::EventSetup &) override
uint32_t plane() const
Definition: TotemT2DetId.h:44
MonitorElement * rechitMultiplicity
int iEvent
Definition: GenABIO.cc:224
void fillToT(const TotemT2RecHit &, const TotemT2DetId &)
const edm::EDGetTokenT< edmNew::DetSetVector< TotemT2Digi > > digiToken_
const unsigned int nbinsy_
static const uint32_t maxArm
Definition: CTPPSDetId.h:51
Transition
Definition: Transition.h:12
void planeName(std::string &name, NameFlag flag=nFull) const
Definition: TotemT2DetId.cc:39
void armName(std::string &name, NameFlag flag=nFull) const
Definition: CTPPSDetId.h:98
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
static constexpr double HPTDC_BIN_WIDTH_NS_
const unsigned int windowsNum_
void analyze(const edm::Event &, const edm::EventSetup &) override
std::bitset<(TotemT2DetId::maxPlane+1) *(TotemT2DetId::maxChannel+1)> hitTilesArray
const edm::EDGetTokenT< edmNew::DetSetVector< TotemT2RecHit > > rechitToken_
CTPPSDetId armId() const
Definition: CTPPSDetId.h:80
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:212
bool areChannelsTriggered(const TotemT2DetId &)
Event setup record containing the real (actual) geometry information.
MonitorElement * book2DD(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:338
std::unordered_map< unsigned int, PlanePlots > planePlots_
HLT enums.
~TotemT2DQMSource() override=default
unsigned short trailingEdge() const
Definition: TotemT2Digi.h:20
void fillTriggerBitset(const TotemT2DetId &)
const edm::ESGetToken< TotemGeometry, TotemGeometryRcd > geometryToken_
unsigned short leadingEdge() const
Definition: TotemT2Digi.h:18
std::unordered_map< unsigned int, SectorPlots > sectorPlots_
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX, FUNC onbooking=NOOP())
Definition: DQMStore.h:98
void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override
void bookErrorFlagsHistogram(DQMStore::IBooker &)
void fillErrorFlagsHistogram(const TotemT2Digi &)
uint32_t channel() const
Definition: TotemT2DetId.h:51
float toT() const
Definition: TotemT2RecHit.h:25
Definition: Run.h:45