CMS 3D CMS Logo

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