CMS 3D CMS Logo

CTPPSToFDetector.cc
Go to the documentation of this file.
2 #include <algorithm>
3 #include <cmath>
4 
6  int ncellx, int ncelly, std::vector<double>& cellw, double cellh, double pitchx, double pitchy, double pos, int res)
7  : nCellX_(ncellx),
8  nCellY_(ncelly),
9  cellW_(cellw),
10  cellH_(cellh),
11  pitchX_(pitchx),
12  pitchY_(pitchy),
13  fToFResolution_(res),
14  detPosition_(pos) {
15  // the vertical positions starts from the negative(bottom) to the positive(top) corner
16  // vector index points to the row number from below
17  cellRow_.push_back(std::pair<double, double>(-cellH_ * 0.5, cellH_ * 0.5));
18  cellColumn_.reserve(nCellX_); // vector index points to the column number
19  for (int i = 0; i < nCellX_; i++) {
20  double x1 = 0., x2 = 0.;
21  if (i == 0) {
22  detW_ = pitchX_;
23  x1 = -(detPosition_ + detW_);
24  } else
25  x1 = -detPosition_ + detW_; //detPosition_ - shift the limit of a column depending on the detector position
26  x2 = x1 - cellW_.at(i);
27  detW_ += (x2 - x1) - pitchX_;
28  cellColumn_.push_back(std::pair<double, double>(x1, x2));
29  }
30  //diamond geometry
31  detH_ = nCellY_ * cellH_;
32  detW_ = -detW_ - 2 * pitchX_;
33 };
34 
36  int ncellx, int ncelly, double cellwq, double cellh, double pitchx, double pitchy, double pos, int res)
37  : nCellX_(ncellx),
38  nCellY_(ncelly),
39  cellWq_(cellwq),
40  cellH_(cellh),
41  pitchX_(pitchx),
42  pitchY_(pitchy),
43  fToFResolution_(res),
44  detPosition_(pos) {
45  //
46  detW_ = nCellX_ * cellWq_ + (nCellX_ - 1) * pitchX_;
47  detH_ = nCellY_ * cellH_ + (nCellY_ - 1) * pitchY_;
48  // the vertical positions starts from the negative(bottom) to the positive(top) corner
49  cellRow_.reserve(nCellY_); // vector index points to the row number from below
50  for (int i = 0; i < nCellY_; i++) {
51  double y1 = cellH_ * (i - nCellY_ * 0.5) + pitchY_ * (i - (nCellY_ - 1) * 0.5);
52  double y2 = y1 + cellH_;
53  cellRow_.push_back(std::pair<double, double>(y1, y2));
54  }
55  cellColumn_.reserve(nCellX_); // vector index points to the column number
56  for (int i = 0; i < nCellX_; i++) {
57  double x1 = -(cellWq_ * i + pitchX_ * i);
58  x1 -= detPosition_; // shift the limit of a column depending on the detector position
59  double x2 = x1 - cellWq_;
60  cellColumn_.push_back(std::pair<double, double>(x1, x2));
61  }
62 };
63 void CTPPSToFDetector::AddHit(double x, double y, double tof) {
64  int cellid = findCellId(x, y);
65  if (cellid == 0)
66  return;
67  if (theToFInfo.find(cellid) == theToFInfo.end())
68  theToFInfo[cellid]; // add empty cell
69  std::vector<double>* tofs = &(theToFInfo.find(cellid)->second);
70  int ntof = tofs->size();
71  int i = 0;
72  double oneOverRes = 1.0 / fToFResolution_;
73  for (; i < ntof; i++) {
74  if (fabs(tofs->at(i) - tof) * oneOverRes < 3) {
75  tofs->at(i) = (tofs->at(i) + tof) / 2.;
76  nADC_.at(cellid).at(i)++;
77  return;
78  }
79  }
80  tofs->push_back(tof); // no other ToF inside resolution found
81  nHits_++;
82  nADC_[cellid].push_back(1);
83 }
84 int CTPPSToFDetector::findCellId(double x, double y) {
85  auto it = std::find_if(
86  cellRow_.begin(), cellRow_.end(), [y](const auto& cell) { return y >= cell.first && y <= cell.second; });
87 
88  if (it == cellRow_.end())
89  return 0;
90 
91  unsigned int y_idx = std::distance(cellRow_.begin(), it) + 1;
92 
93  it = std::find_if(
94  cellColumn_.begin(), cellColumn_.end(), [x](const auto& cell) { return x <= cell.first && x > cell.second; });
95 
96  if (it == cellColumn_.end())
97  return 0;
98 
99  unsigned int x_idx = std::distance(cellColumn_.begin(), it) + 1;
100  return 100 * y_idx + x_idx;
101 }
102 bool CTPPSToFDetector::get_CellCenter(int cell_id, double& x, double& y) {
103  if (cell_id == 0)
104  return false;
105  //if(!isValidCellId(cell_id)) return 0;
106  unsigned int y_idx = int(cell_id * 0.01);
107  unsigned int x_idx = cell_id - y_idx * 100;
108  x = (cellColumn_.at(x_idx - 1).first + cellColumn_.at(x_idx - 1).second) / 2.0;
109  y = (cellRow_.at(y_idx - 1).first + cellRow_.at(y_idx - 1).second) / 2.0;
110  return true;
111 }
bool get_CellCenter(int cell_id, double &x, double &y)
std::vector< std::pair< double, double > > cellRow_
int findCellId(double x, double y)
std::map< int, std::vector< int > > nADC_
Definition: Electron.h:6
void AddHit(double x, double y, double tof)
std::vector< std::pair< double, double > > cellColumn_
CTPPSToFDetector(int ncellx, int ncelly, std::vector< double > &cellw, double cellh, double pitchx, double pitchy, double pos, int res)
std::map< int, std::vector< double > > theToFInfo
std::vector< double > cellW_
float x