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 }
DDAxes::y
mps_fire.i
i
Definition: mps_fire.py:355
CTPPSToFDetector::nHits_
int nHits_
Definition: CTPPSToFDetector.h:79
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
CTPPSToFDetector::pitchX_
double pitchX_
Definition: CTPPSToFDetector.h:68
pos
Definition: PixelAliasList.h:18
CTPPSToFDetector::cellH_
double cellH_
Definition: CTPPSToFDetector.h:67
CTPPSToFDetector::cellWq_
double cellWq_
Definition: CTPPSToFDetector.h:65
CTPPSToFDetector::pitchY_
double pitchY_
Definition: CTPPSToFDetector.h:69
DDAxes::x
CTPPSToFDetector::CTPPSToFDetector
CTPPSToFDetector(int ncellx, int ncelly, std::vector< double > &cellw, double cellh, double pitchx, double pitchy, double pos, int res)
Definition: CTPPSToFDetector.cc:4
CTPPSToFDetector::detW_
double detW_
Definition: CTPPSToFDetector.h:74
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
CTPPSToFDetector::cellRow_
std::vector< std::pair< double, double > > cellRow_
Definition: CTPPSToFDetector.h:72
vertices_cff.x
x
Definition: vertices_cff.py:29
CTPPSToFDetector::fToFResolution_
int fToFResolution_
Definition: CTPPSToFDetector.h:70
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
CTPPSToFDetector::get_CellCenter
bool get_CellCenter(int cell_id, double &x, double &y)
Definition: CTPPSToFDetector.cc:107
createfilelist.int
int
Definition: createfilelist.py:10
CTPPSToFDetector::nADC_
std::map< int, std::vector< int > > nADC_
Definition: CTPPSToFDetector.h:80
CTPPSToFDetector::findCellId
int findCellId(double x, double y)
Definition: CTPPSToFDetector.cc:83
res
Definition: Electron.h:6
CTPPSToFDetector::detPosition_
double detPosition_
Definition: CTPPSToFDetector.h:76
CTPPSToFDetector::cellColumn_
std::vector< std::pair< double, double > > cellColumn_
Definition: CTPPSToFDetector.h:71
CTPPSToFDetector.h
detailsBasic3DVector::y
float float y
Definition: extBasic3DVector.h:14
CTPPSToFDetector::AddHit
void AddHit(double x, double y, double tof)
Definition: CTPPSToFDetector.cc:62
CTPPSToFDetector::nCellX_
int nCellX_
Definition: CTPPSToFDetector.h:60
CTPPSToFDetector::nCellY_
int nCellY_
Definition: CTPPSToFDetector.h:64
CTPPSToFDetector::theToFInfo
std::map< int, std::vector< double > > theToFInfo
Definition: CTPPSToFDetector.h:82
CTPPSToFDetector::detH_
double detH_
Definition: CTPPSToFDetector.h:75
CTPPSToFDetector::cellW_
std::vector< double > cellW_
Definition: CTPPSToFDetector.h:66