CMS 3D CMS Logo

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