Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:46:01

0001 #include "FastSimulation/CTPPSFastGeometry/interface/CTPPSToFDetector.h"
0002 #include <cmath>
0003 
0004 CTPPSToFDetector::CTPPSToFDetector(
0005     int ncellx, int ncelly, std::vector<double>& cellw, double cellh, double pitchx, double pitchy, double pos, int res)
0006     : nCellX_(ncellx),
0007       nCellY_(ncelly),
0008       cellW_(cellw),
0009       cellH_(cellh),
0010       pitchX_(pitchx),
0011       pitchY_(pitchy),
0012       fToFResolution_(res),
0013       detPosition_(pos) {
0014   // the vertical positions starts from the negative(bottom) to the positive(top) corner
0015   // vector index points to the row number from below
0016   cellRow_.push_back(std::pair<double, double>(-cellH_ * 0.5, cellH_ * 0.5));
0017   cellColumn_.reserve(nCellX_);  // vector index points to the column number
0018   for (int i = 0; i < nCellX_; i++) {
0019     double x1 = 0., x2 = 0.;
0020     if (i == 0) {
0021       detW_ = pitchX_;
0022       x1 = -(detPosition_ + detW_);
0023     } else
0024       x1 = -detPosition_ + detW_;  //detPosition_ - shift the limit of a column depending on the detector position
0025     x2 = x1 - cellW_.at(i);
0026     detW_ += (x2 - x1) - pitchX_;
0027     cellColumn_.push_back(std::pair<double, double>(x1, x2));
0028   }
0029   //diamond geometry
0030   detH_ = nCellY_ * cellH_;
0031   detW_ = -detW_ - 2 * pitchX_;
0032 };
0033 
0034 CTPPSToFDetector::CTPPSToFDetector(
0035     int ncellx, int ncelly, double cellwq, double cellh, double pitchx, double pitchy, double pos, int res)
0036     : nCellX_(ncellx),
0037       nCellY_(ncelly),
0038       cellWq_(cellwq),
0039       cellH_(cellh),
0040       pitchX_(pitchx),
0041       pitchY_(pitchy),
0042       fToFResolution_(res),
0043       detPosition_(pos) {
0044   //
0045   detW_ = nCellX_ * cellWq_ + (nCellX_ - 1) * pitchX_;
0046   detH_ = nCellY_ * cellH_ + (nCellY_ - 1) * pitchY_;
0047   // the vertical positions starts from the negative(bottom) to the positive(top) corner
0048   cellRow_.reserve(nCellY_);  // vector index points to the row number from below
0049   for (int i = 0; i < nCellY_; i++) {
0050     double y1 = cellH_ * (i - nCellY_ * 0.5) + pitchY_ * (i - (nCellY_ - 1) * 0.5);
0051     double y2 = y1 + cellH_;
0052     cellRow_.push_back(std::pair<double, double>(y1, y2));
0053   }
0054   cellColumn_.reserve(nCellX_);  // vector index points to the column number
0055   for (int i = 0; i < nCellX_; i++) {
0056     double x1 = -(cellWq_ * i + pitchX_ * i);
0057     x1 -= detPosition_;  // shift the limit of a column depending on the detector position
0058     double x2 = x1 - cellWq_;
0059     cellColumn_.push_back(std::pair<double, double>(x1, x2));
0060   }
0061 };
0062 void CTPPSToFDetector::AddHit(double x, double y, double tof) {
0063   int cellid = findCellId(x, y);
0064   if (cellid == 0)
0065     return;
0066   if (theToFInfo.find(cellid) == theToFInfo.end())
0067     theToFInfo[cellid];  // add empty cell
0068   std::vector<double>* tofs = &(theToFInfo.find(cellid)->second);
0069   int ntof = tofs->size();
0070   int i = 0;
0071   double oneOverRes = 1.0 / fToFResolution_;
0072   for (; i < ntof; i++) {
0073     if (fabs(tofs->at(i) - tof) * oneOverRes < 3) {
0074       tofs->at(i) = (tofs->at(i) + tof) / 2.;
0075       nADC_.at(cellid).at(i)++;
0076       return;
0077     }
0078   }
0079   tofs->push_back(tof);  // no other ToF inside resolution found
0080   nHits_++;
0081   nADC_[cellid].push_back(1);
0082 }
0083 int CTPPSToFDetector::findCellId(double x, double y) {
0084   int y_idx, x_idx;
0085   // first, get the row number
0086   unsigned int i;
0087   unsigned int start_idx = 0;
0088   unsigned int end_idx = cellRow_.size();
0089   for (i = 0; i < cellRow_.size(); i++) {
0090     if (y >= cellRow_.at(i).first && y <= cellRow_.at(i).second)
0091       break;
0092   }
0093   if (i >= cellRow_.size())
0094     return 0;
0095   y_idx = i + 1;
0096   start_idx = 0;
0097   end_idx = cellColumn_.size();
0098   for (i = start_idx; i < end_idx; i++) {
0099     if (x <= cellColumn_.at(i).first && x > cellColumn_.at(i).second)
0100       break;
0101   }
0102   if (i >= end_idx)
0103     return 0;
0104   x_idx = i + 1 - start_idx;
0105   return 100 * y_idx + x_idx;
0106 }
0107 bool CTPPSToFDetector::get_CellCenter(int cell_id, double& x, double& y) {
0108   if (cell_id == 0)
0109     return false;
0110   //if(!isValidCellId(cell_id)) return 0;
0111   unsigned int y_idx = int(cell_id * 0.01);
0112   unsigned int x_idx = cell_id - y_idx * 100;
0113   x = (cellColumn_.at(x_idx - 1).first + cellColumn_.at(x_idx - 1).second) / 2.0;
0114   y = (cellRow_.at(y_idx - 1).first + cellRow_.at(y_idx - 1).second) / 2.0;
0115   return true;
0116 }