CMS 3D CMS Logo

TotemT2Segmentation.cc
Go to the documentation of this file.
1 
2 /****************************************************************************
3  *
4  * This is a part of TOTEM offline software.
5  * Author:
6  * Laurent Forthomme
7  * Arkadiusz Cwikla
8  *
9  ****************************************************************************/
10 
13 
14 #include "TH2D.h"
15 
17  : geom_(geom), nbinsx_(nbinsx), nbinsy_(nbinsy) {
18  for (unsigned short arm = 0; arm <= CTPPSDetId::maxArm; ++arm)
19  for (unsigned short plane = 0; plane <= TotemT2DetId::maxPlane; ++plane)
20  for (unsigned short id = 0; id <= TotemT2DetId::maxChannel; ++id) {
21  const TotemT2DetId detid(arm, plane, id);
22  bins_map_[detid] = computeBins(detid);
23  }
24 }
25 
26 void TotemT2Segmentation::fill(TH2D* hist, const TotemT2DetId& detid, double value) {
27  if (bins_map_.count(detid) == 0)
28  throw cms::Exception("TotemT2Segmentation") << "Failed to retrieve list of bins for TotemT2DetId " << detid << ".";
29  if (static_cast<size_t>(hist->GetXaxis()->GetNbins()) != nbinsx_ ||
30  static_cast<size_t>(hist->GetYaxis()->GetNbins()) != nbinsy_)
31  throw cms::Exception("TotemT2Segmentation")
32  << "Trying to fill a summary plot with invalid number of bins. "
33  << "Should be of dimension (" << nbinsx_ << ", " << nbinsy_ << "), but has dimension ("
34  << hist->GetXaxis()->GetNbins() << ", " << hist->GetYaxis()->GetNbins() << ").";
35  for (const auto& bin : bins_map_.at(detid))
36  hist->Fill(bin.first, bin.second, value);
37 }
38 
39 std::vector<std::pair<short, short> > TotemT2Segmentation::computeBins(const TotemT2DetId& detid) const {
40  std::vector<std::pair<short, short> > bins;
41  // find the histogram centre
42  const auto ox = floor(nbinsx_ * 0.5), oy = floor(nbinsy_ * 0.5);
43  // compute the ellipse parameters
44  const auto ax = ceil(nbinsx_ * 0.5), by = ceil(nbinsy_ * 0.5);
45 
46  const float max_half_angle_rad = 0.3;
47  // find the coordinates of the tile centre to extract its angle
48  const auto tile_centre = geom_.tile(detid).centre();
49  const auto tile_angle_rad = std::atan2(tile_centre.y(), tile_centre.x());
50  // Geometric way of associating a DetId to a vector<ix, iy> of bins given the size (nx_, ny_) of
51  // the TH2D('s) to be filled
52  for (size_t ix = 0; ix < nbinsx_; ++ix)
53  for (size_t iy = 0; iy < nbinsy_; ++iy) {
54  const auto ell_rad_norm = std::pow((ix - ox) / ax, 2) + std::pow((iy - oy) / by, 2);
55  if (ell_rad_norm < 1. && ell_rad_norm >= 0.1 &&
56  fabs(std::atan2(iy - oy, ix - ox) - tile_angle_rad) < max_half_angle_rad)
57  bins.emplace_back(ix, iy);
58  }
59 
60  return bins;
61 }
constexpr int32_t ceil(float num)
Detector ID class for Totem T2 detectors. Bits [19:31] : Base CTPPSDetId class attributes Bits [16:18...
Definition: TotemT2DetId.h:25
const TotemGeometry geom_
void fill(TH2D *, const TotemT2DetId &, double value=1.)
static constexpr uint32_t maxChannel
Definition: TotemT2DetId.h:35
TotemT2Segmentation(const TotemGeometry &, size_t, size_t)
const GlobalPoint & centre() const
Definition: TotemT2Tile.h:21
static constexpr uint32_t maxPlane
Definition: TotemT2DetId.h:34
static const uint32_t maxArm
Definition: CTPPSDetId.h:51
const TotemT2Tile & tile(const TotemT2DetId &) const
Definition: value.py:1
std::unordered_map< TotemT2DetId, std::vector< std::pair< short, short > > > bins_map_
std::vector< std::pair< short, short > > computeBins(const TotemT2DetId &detid) const
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29