Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:27:40

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