Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-06-12 23:30:06

0001 #include "RecoPPS/Local/interface/RPixClusterToHit.h"
0002 
0003 RPixClusterToHit::RPixClusterToHit(edm::ParameterSet const &conf)
0004     : verbosity_(conf.getUntrackedParameter<int>("RPixVerbosity")) {}
0005 
0006 void RPixClusterToHit::buildHits(unsigned int detId,
0007                                  const std::vector<CTPPSPixelCluster> &clusters,
0008                                  std::vector<CTPPSPixelRecHit> &hits,
0009                                  const PPSPixelTopology &ppt) const {
0010   if (verbosity_)
0011     edm::LogInfo("PPS") << " RPixClusterToHit " << detId << " received cluster array of size = " << clusters.size();
0012 
0013   for (unsigned int i = 0; i < clusters.size(); i++) {
0014     makeHit(clusters[i], hits, ppt);
0015   }
0016 }
0017 
0018 void RPixClusterToHit::makeHit(CTPPSPixelCluster cluster,
0019                                std::vector<CTPPSPixelRecHit> &hits,
0020                                const PPSPixelTopology &ppt) const {
0021   // take a cluster, generate a rec hit and push it in the rec hit vector
0022 
0023   //call the numbering inside the ROC
0024   CTPPSPixelIndices pxlInd;
0025   // get information from the cluster
0026   // get the whole cluster size and row/col size
0027   unsigned int thisClusterSize = cluster.size();
0028   unsigned int thisClusterRowSize = cluster.sizeRow();
0029   unsigned int thisClusterColSize = cluster.sizeCol();
0030 
0031   // get the minimum pixel row/col
0032   unsigned int thisClusterMinRow = cluster.minPixelRow();
0033   unsigned int thisClusterMinCol = cluster.minPixelCol();
0034 
0035   // calculate "on edge" flag
0036   bool anEdgePixel = false;
0037   if (cluster.minPixelRow() == 0 || cluster.minPixelCol() == 0 ||
0038       int(cluster.minPixelRow() + cluster.rowSpan()) == (pxlInd.getDefaultRowDetSize() - 1) ||
0039       int(cluster.minPixelCol() + cluster.colSpan()) == (pxlInd.getDefaultColDetSize() - 1))
0040     anEdgePixel = true;
0041 
0042   // check for bad (ADC=0) pixels in cluster
0043   bool aBadPixel = false;
0044   for (unsigned int i = 0; i < thisClusterSize; i++) {
0045     if (cluster.pixelADC(i) == 0)
0046       aBadPixel = true;
0047   }
0048 
0049   // check for spanning two ROCs
0050   bool twoRocs = false;
0051   int currROCId = pxlInd.getROCId(cluster.pixelCol(0), cluster.pixelRow(0));
0052 
0053   for (unsigned int i = 1; i < thisClusterSize; i++) {
0054     if (pxlInd.getROCId(cluster.pixelCol(i), cluster.pixelRow(i)) != currROCId) {
0055       twoRocs = true;
0056       break;
0057     }
0058   }
0059 
0060   // estimate position and error of the hit
0061   double avgWLocalX = 0;
0062   double avgWLocalY = 0;
0063   double weights = 0;
0064   double weightedVarianceX = 0.;
0065   double weightedVarianceY = 0.;
0066 
0067   if (verbosity_)
0068     edm::LogInfo("PPS") << "RPixClusterToHit "
0069                         << " hit pixels: ";
0070 
0071   for (unsigned int i = 0; i < thisClusterSize; i++) {
0072     if (verbosity_)
0073       edm::LogInfo("PPS") << "RPixClusterToHit " << cluster.pixelRow(i) << " " << cluster.pixelCol(i) << " "
0074                           << cluster.pixelADC(i);
0075 
0076     double minPxlX = 0;
0077     double minPxlY = 0;
0078     double maxPxlX = 0;
0079     double maxPxlY = 0;
0080 
0081     ppt.pixelRange(cluster.pixelRow(i), cluster.pixelCol(i), minPxlX, maxPxlX, minPxlY, maxPxlY);
0082     double halfSizeX = (maxPxlX - minPxlX) / 2.;
0083     double halfSizeY = (maxPxlY - minPxlY) / 2.;
0084     double avgPxlX = minPxlX + halfSizeX;
0085     double avgPxlY = minPxlY + halfSizeY;
0086 
0087     // error propagation
0088     weightedVarianceX += cluster.pixelADC(i) * cluster.pixelADC(i) * halfSizeX * halfSizeX / 3.;
0089     weightedVarianceY += cluster.pixelADC(i) * cluster.pixelADC(i) * halfSizeY * halfSizeY / 3.;
0090 
0091     avgWLocalX += avgPxlX * cluster.pixelADC(i);
0092     avgWLocalY += avgPxlY * cluster.pixelADC(i);
0093     weights += cluster.pixelADC(i);
0094   }
0095 
0096   if (weights == 0) {
0097     edm::LogError("RPixClusterToHit") << " unexpected weights = 0 for cluster (Row_min, Row_max, Col_min, Col_max) = ("
0098                                       << cluster.minPixelRow() << "," << cluster.minPixelRow() + cluster.rowSpan()
0099                                       << "," << cluster.minPixelCol() << ","
0100                                       << cluster.minPixelCol() + cluster.colSpan() << ")";
0101     return;
0102   }
0103 
0104   double invWeights = 1. / weights;
0105   double avgLocalX = avgWLocalX * invWeights;
0106   double avgLocalY = avgWLocalY * invWeights;
0107 
0108   double varianceX = weightedVarianceX * invWeights * invWeights;
0109   double varianceY = weightedVarianceY * invWeights * invWeights;
0110 
0111   LocalPoint lp(avgLocalX, avgLocalY, 0);
0112   LocalError le(varianceX, 0, varianceY);
0113   if (verbosity_)
0114     edm::LogInfo("PPS") << "RPixClusterToHit " << lp << " with error " << le;
0115 
0116   hits.emplace_back(lp,
0117                     le,
0118                     anEdgePixel,
0119                     aBadPixel,
0120                     twoRocs,
0121                     thisClusterMinRow,
0122                     thisClusterMinCol,
0123                     thisClusterSize,
0124                     thisClusterRowSize,
0125                     thisClusterColSize);
0126 }