Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:29

0001 #include "CondFormats/PPSObjects/interface/PPSPixelTopology.h"
0002 
0003 // Constructors
0004 
0005 PPSPixelTopology::PPSPixelTopology()
0006     : runType_(""),
0007       pitch_simY_(0.),
0008       pitch_simX_(0.),
0009       thickness_(0.),
0010       no_of_pixels_simX_(0.),
0011       no_of_pixels_simY_(0.),
0012       no_of_pixels_(0.),
0013       simX_width_(0.),
0014       simY_width_(0.),
0015       dead_edge_width_(0.),
0016       active_edge_sigma_(0.),
0017       phys_active_edge_dist_(0.),
0018       active_edge_x_(0.),
0019       active_edge_y_(0.) {}
0020 
0021 // Destructor
0022 PPSPixelTopology::~PPSPixelTopology() {}
0023 
0024 unsigned short PPSPixelTopology::pixelIndex(PixelInfo pI) const {
0025   return no_of_pixels_simX_ * pI.pixelColNo() + pI.pixelRowNo();
0026 }
0027 
0028 bool PPSPixelTopology::isPixelHit(float xLocalCoordinate, float yLocalCoordinate, bool is3x2 = true) const {
0029   // check hit fiducial boundaries
0030   const double xModuleSize = 2 * ((no_of_pixels_simX_ / 2. + 1) * pitch_simX_ + dead_edge_width_);
0031   if (xLocalCoordinate < -xModuleSize / 2. || xLocalCoordinate > xModuleSize / 2.)
0032     return false;
0033 
0034   const double yModuleSize = (no_of_pixels_simY_ + 4.) * pitch_simY_ + 2. * dead_edge_width_;
0035   const double y2x2top = no_of_pixels_simY_ / 6. * pitch_simY_ + dead_edge_width_;
0036   if (is3x2 && (yLocalCoordinate < -yModuleSize / 2. || yLocalCoordinate > yModuleSize / 2.))
0037     return false;
0038   if (!is3x2 && (runType_ == "Run2") && (yLocalCoordinate < -yModuleSize / 2. || yLocalCoordinate > y2x2top))
0039     return false;
0040   if (!is3x2 && (runType_ == "Run3") && (yLocalCoordinate < -yModuleSize / 2. || yLocalCoordinate > yModuleSize / 2.))
0041     return false;
0042 
0043   return true;
0044 }
0045 
0046 PPSPixelTopology::PixelInfo PPSPixelTopology::getPixelsInvolved(
0047     double x, double y, double sigma, double& hit_pos_x, double& hit_pos_y) const {
0048   //hit position wrt the bottom left corner of the sensor (-8.3, -12.2) in sensor view, rocs behind
0049   hit_pos_x = x + simX_width_ / 2.;
0050   hit_pos_y = y + simY_width_ / 2.;
0051   if (!(hit_pos_x * hit_pos_y > 0))
0052     throw cms::Exception("PPSPixelTopology") << "pixel out of reference frame";
0053 
0054   double hit_factor = activeEdgeFactor(x, y);
0055 
0056   unsigned int interested_row = row(x);
0057   unsigned int interested_col = col(y);
0058   double low_pixel_range_x, high_pixel_range_x, low_pixel_range_y, high_pixel_range_y;
0059   pixelRange(
0060       interested_row, interested_col, low_pixel_range_x, high_pixel_range_x, low_pixel_range_y, high_pixel_range_y);
0061 
0062   return PPSPixelTopology::PixelInfo(low_pixel_range_x,
0063                                      high_pixel_range_x,
0064                                      low_pixel_range_y,
0065                                      high_pixel_range_y,
0066                                      hit_factor,
0067                                      interested_row,
0068                                      interested_col);
0069 }
0070 
0071 void PPSPixelTopology::pixelRange(
0072     unsigned int arow, unsigned int acol, double& lower_x, double& higher_x, double& lower_y, double& higher_y) const {
0073   // x and y in the system  of Geant4 SIMULATION
0074   arow = (2 * rpixValues::ROCSizeInX - 1) - arow;
0075   if (arow > (2 * rpixValues::ROCSizeInX - 1) || acol > (3 * rpixValues::ROCSizeInY - 1))
0076     throw cms::Exception("PPSPixelTopology") << "pixel rows or columns exceeding limits";
0077 
0078   // rows (x segmentation)
0079   if (arow == 0) {
0080     lower_x = dead_edge_width_ - phys_active_edge_dist_;  // 50 um
0081     higher_x = dead_edge_width_ + pitch_simX_;            // 300 um
0082   } else if (arow <= (rpixValues::ROCSizeInX - 2)) {
0083     lower_x = dead_edge_width_ + arow * pitch_simX_;
0084     higher_x = dead_edge_width_ + (arow + 1) * pitch_simX_;
0085   } else if (arow == (rpixValues::ROCSizeInX - 1)) {
0086     lower_x = dead_edge_width_ + arow * pitch_simX_;
0087     higher_x = dead_edge_width_ + (arow + 2) * pitch_simX_;
0088   } else if (arow == rpixValues::ROCSizeInX) {
0089     lower_x = dead_edge_width_ + (arow + 1) * pitch_simX_;
0090     higher_x = dead_edge_width_ + (arow + 3) * pitch_simX_;
0091   } else if (arow <= (2 * rpixValues::ROCSizeInX - 2)) {
0092     lower_x = dead_edge_width_ + (arow + 2) * pitch_simX_;
0093     higher_x = dead_edge_width_ + (arow + 3) * pitch_simX_;
0094   } else if (arow == (2 * rpixValues::ROCSizeInX - 1)) {
0095     lower_x = dead_edge_width_ + (arow + 2) * pitch_simX_;
0096     higher_x = dead_edge_width_ + (arow + 3) * pitch_simX_ + phys_active_edge_dist_;
0097   }
0098   // columns (y segmentation)
0099   if (acol == 0) {
0100     lower_y = dead_edge_width_ - phys_active_edge_dist_;  // 50 um
0101     higher_y = dead_edge_width_ + pitch_simY_;            // 350 um
0102   } else if (acol <= (rpixValues::ROCSizeInY - 2)) {
0103     lower_y = dead_edge_width_ + acol * pitch_simY_;
0104     higher_y = dead_edge_width_ + (acol + 1) * pitch_simY_;
0105   } else if (acol == (rpixValues::ROCSizeInY - 1)) {
0106     lower_y = dead_edge_width_ + acol * pitch_simY_;
0107     higher_y = dead_edge_width_ + (acol + 2) * pitch_simY_;
0108   } else if (acol == rpixValues::ROCSizeInY) {
0109     lower_y = dead_edge_width_ + (acol + 1) * pitch_simY_;
0110     higher_y = dead_edge_width_ + (acol + 3) * pitch_simY_;
0111   } else if (acol <= (2 * rpixValues::ROCSizeInY - 2)) {
0112     lower_y = dead_edge_width_ + (acol + 2) * pitch_simY_;
0113     higher_y = dead_edge_width_ + (acol + 3) * pitch_simY_;
0114   } else if (acol == (2 * rpixValues::ROCSizeInY - 1)) {
0115     lower_y = dead_edge_width_ + (acol + 2) * pitch_simY_;
0116     higher_y = dead_edge_width_ + (acol + 4) * pitch_simY_;
0117   } else if (acol == (2 * rpixValues::ROCSizeInY)) {
0118     lower_y = dead_edge_width_ + (acol + 3) * pitch_simY_;
0119     higher_y = dead_edge_width_ + (acol + 5) * pitch_simY_;
0120   } else if (acol <= (3 * rpixValues::ROCSizeInY - 2)) {
0121     lower_y = dead_edge_width_ + (acol + 4) * pitch_simY_;
0122     higher_y = dead_edge_width_ + (acol + 5) * pitch_simY_;
0123   } else if (acol == (3 * rpixValues::ROCSizeInY - 1)) {
0124     lower_y = dead_edge_width_ + (acol + 4) * pitch_simY_;
0125     higher_y = dead_edge_width_ + (acol + 5) * pitch_simY_ + phys_active_edge_dist_;
0126   }
0127 
0128   lower_x = lower_x - simX_width_ / 2.;
0129   lower_y = lower_y - simY_width_ / 2.;
0130   higher_x = higher_x - simX_width_ / 2.;
0131   higher_y = higher_y - simY_width_ / 2.;
0132 }
0133 
0134 double PPSPixelTopology::activeEdgeFactor(double x, double y) const {
0135   const double inv_sigma = 1. / active_edge_sigma_;  // precaching
0136   const double topEdgeFactor = std::erf(-distanceFromTopActiveEdge(x, y) * inv_sigma) * 0.5 + 0.5;
0137   const double bottomEdgeFactor = std::erf(-distanceFromBottomActiveEdge(x, y) * inv_sigma) * 0.5 + 0.5;
0138   const double rightEdgeFactor = std::erf(-distanceFromRightActiveEdge(x, y) * inv_sigma) * 0.5 + 0.5;
0139   const double leftEdgeFactor = std::erf(-distanceFromLeftActiveEdge(x, y) * inv_sigma) * 0.5 + 0.5;
0140 
0141   const double aEF = topEdgeFactor * bottomEdgeFactor * rightEdgeFactor * leftEdgeFactor;
0142 
0143   if (aEF > 1.)
0144     throw cms::Exception("PPSPixelTopology") << " pixel active edge factor > 1";
0145 
0146   return aEF;
0147 }
0148 
0149 double PPSPixelTopology::distanceFromTopActiveEdge(double x, double y) const { return (y - active_edge_y_); }
0150 double PPSPixelTopology::distanceFromBottomActiveEdge(double x, double y) const { return (-y - active_edge_y_); }
0151 double PPSPixelTopology::distanceFromRightActiveEdge(double x, double y) const { return (x - active_edge_x_); }
0152 double PPSPixelTopology::distanceFromLeftActiveEdge(double x, double y) const { return (-x - active_edge_x_); }
0153 
0154 unsigned int PPSPixelTopology::row(double x) const {
0155   // x in the G4 simulation system
0156   x = x + simX_width_ / 2.;
0157 
0158   // now x in the system centered in the bottom left corner of the sensor (sensor view, rocs behind)
0159   if (x < 0. || x > simX_width_)
0160     throw cms::Exception("PPSPixelTopology") << " pixel out of reference frame";
0161 
0162   // rows (x segmentation)
0163   unsigned int arow;
0164   if (x <= (dead_edge_width_ + pitch_simX_))
0165     arow = 0;
0166   else if (x <= (dead_edge_width_ + (rpixValues::ROCSizeInX - 1) * pitch_simX_))
0167     arow = int((x - dead_edge_width_ - pitch_simX_) / pitch_simX_) + 1;
0168   else if (x <= (dead_edge_width_ + (rpixValues::ROCSizeInX + 1) * pitch_simX_))
0169     arow = (rpixValues::ROCSizeInX - 1);
0170   else if (x <= (dead_edge_width_ + (rpixValues::ROCSizeInX + 3) * pitch_simX_))
0171     arow = rpixValues::ROCSizeInX;
0172   else if (x <= (dead_edge_width_ + (2 * rpixValues::ROCSizeInX + 2) * pitch_simX_))
0173     arow = int((x - dead_edge_width_ - pitch_simX_) / pitch_simX_) - 1;
0174   else
0175     arow = (2 * rpixValues::ROCSizeInX - 1);
0176 
0177   arow = (2 * rpixValues::ROCSizeInX - 1) - arow;
0178   if (arow > (2 * rpixValues::ROCSizeInX - 1))
0179     throw cms::Exception("PPSPixelTopology") << " pixel row number exceeding limit";
0180 
0181   return arow;
0182 }
0183 
0184 unsigned int PPSPixelTopology::col(double y) const {
0185   // y in the G4 simulation system
0186   unsigned int column;
0187 
0188   // columns (y segmentation)
0189   // now y in the system centered in the bottom left corner of the sensor (sensor view, rocs behind)
0190   y = y + simY_width_ / 2.;
0191   if (y < 0. || y > simY_width_)
0192     throw cms::Exception("PPSPixelTopology") << "pixel out of reference frame";
0193 
0194   if (y <= (dead_edge_width_ + pitch_simY_))
0195     column = 0;
0196   else if (y <= (dead_edge_width_ + (rpixValues::ROCSizeInY - 1) * pitch_simY_))
0197     column = int((y - dead_edge_width_ - pitch_simY_) / pitch_simY_) + 1;
0198   else if (y <= (dead_edge_width_ + (rpixValues::ROCSizeInY + 1) * pitch_simY_))
0199     column = rpixValues::ROCSizeInY - 1;
0200   else if (y <= (dead_edge_width_ + (rpixValues::ROCSizeInY + 3) * pitch_simY_))
0201     column = rpixValues::ROCSizeInY;
0202   else if (y <= (dead_edge_width_ + (2 * rpixValues::ROCSizeInY + 1) * pitch_simY_))
0203     column = int((y - dead_edge_width_ - pitch_simY_) / pitch_simY_) - 1;
0204   else if (y <= (dead_edge_width_ + (2 * rpixValues::ROCSizeInY + 3) * pitch_simY_))
0205     column = 2 * rpixValues::ROCSizeInY - 1;
0206   else if (y <= (dead_edge_width_ + (2 * rpixValues::ROCSizeInY + 5) * pitch_simY_))
0207     column = 2 * rpixValues::ROCSizeInY;
0208   else if (y <= (dead_edge_width_ + (3 * rpixValues::ROCSizeInY + 3) * pitch_simY_))
0209     column = int((y - dead_edge_width_ - pitch_simY_) / pitch_simY_) - 3;
0210   else
0211     column = (3 * rpixValues::ROCSizeInY - 1);
0212 
0213   return column;
0214 }
0215 
0216 void PPSPixelTopology::rowCol2Index(unsigned int arow, unsigned int acol, unsigned int& index) const {
0217   index = acol * no_of_pixels_simX_ + arow;
0218 }
0219 
0220 void PPSPixelTopology::index2RowCol(unsigned int& arow, unsigned int& acol, unsigned int index) const {
0221   acol = index / no_of_pixels_simX_;
0222   arow = index % no_of_pixels_simX_;
0223 }
0224 
0225 // Getters
0226 
0227 std::string PPSPixelTopology::getRunType() const { return runType_; }
0228 double PPSPixelTopology::getPitchSimY() const { return pitch_simY_; }
0229 double PPSPixelTopology::getPitchSimX() const { return pitch_simX_; }
0230 double PPSPixelTopology::getThickness() const { return thickness_; }
0231 unsigned short PPSPixelTopology::getNoPixelsSimX() const { return no_of_pixels_simX_; }
0232 unsigned short PPSPixelTopology::getNoPixelsSimY() const { return no_of_pixels_simY_; }
0233 unsigned short PPSPixelTopology::getNoPixels() const { return no_of_pixels_; }
0234 double PPSPixelTopology::getSimXWidth() const { return simX_width_; }
0235 double PPSPixelTopology::getSimYWidth() const { return simY_width_; }
0236 double PPSPixelTopology::getDeadEdgeWidth() const { return dead_edge_width_; }
0237 double PPSPixelTopology::getActiveEdgeSigma() const { return active_edge_sigma_; }
0238 double PPSPixelTopology::getPhysActiveEdgeDist() const { return phys_active_edge_dist_; }
0239 double PPSPixelTopology::getActiveEdgeX() const { return active_edge_x_; }
0240 double PPSPixelTopology::getActiveEdgeY() const { return active_edge_y_; }
0241 
0242 // Setters
0243 
0244 void PPSPixelTopology::setRunType(std::string rt) { runType_ = rt; }
0245 void PPSPixelTopology::setPitchSimY(double psy) { pitch_simY_ = psy; }
0246 void PPSPixelTopology::setPitchSimX(double psx) { pitch_simX_ = psx; }
0247 void PPSPixelTopology::setThickness(double tss) { thickness_ = tss; }
0248 void PPSPixelTopology::setNoPixelsSimX(unsigned short npx) { no_of_pixels_simX_ = npx; }
0249 void PPSPixelTopology::setNoPixelsSimY(unsigned short npy) { no_of_pixels_simY_ = npy; }
0250 void PPSPixelTopology::setNoPixels(unsigned short np) { no_of_pixels_ = np; }
0251 void PPSPixelTopology::setSimXWidth(double sxw) { simX_width_ = sxw; }
0252 void PPSPixelTopology::setSimYWidth(double syw) { simY_width_ = syw; }
0253 void PPSPixelTopology::setDeadEdgeWidth(double dew) { dead_edge_width_ = dew; }
0254 void PPSPixelTopology::setActiveEdgeSigma(double aes) { active_edge_sigma_ = aes; }
0255 void PPSPixelTopology::setPhysActiveEdgeDist(double pae) { phys_active_edge_dist_ = pae; }
0256 void PPSPixelTopology::setActiveEdgeX(double aex) { active_edge_x_ = aex; }
0257 void PPSPixelTopology::setActiveEdgeY(double aey) { active_edge_y_ = aey; }
0258 
0259 void PPSPixelTopology::printInfo(std::stringstream& s) {
0260   s << "\n PPS Topology parameters : \n"
0261     << "\n  runType_  = " << runType_ << "\n  pitch_simY_  = " << pitch_simY_ << "\n   pitch_simX_ = " << pitch_simX_
0262     << "\n   thickness_ = " << thickness_ << "\n   no_of_pixels_simX_ " << no_of_pixels_simX_
0263     << "\n   no_of_pixels_simY_ " << no_of_pixels_simY_ << "\n   no_of_pixels_ " << no_of_pixels_ << "\n   simX_width_ "
0264     << simX_width_ << "\n   simY_width_ " << simY_width_ << "\n   dead_edge_width_ " << dead_edge_width_
0265     << "\n   active_edge_sigma_ " << active_edge_sigma_ << "\n   phys_active_edge_dist_ " << phys_active_edge_dist_
0266 
0267     << "\n   active_edge_x_ " << active_edge_x_ << "\n   active_edge_y_ " << active_edge_y_
0268 
0269     << std::endl;
0270 }
0271 
0272 std::ostream& operator<<(std::ostream& os, PPSPixelTopology info) {
0273   std::stringstream ss;
0274   info.printInfo(ss);
0275   os << ss.str();
0276   return os;
0277 }