Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-05-22 04:03:19

0001 #include "RecoLocalTracker/SiPixelRecHits/interface/PixelCPEGenericBase.h"
0002 
0003 namespace {
0004   constexpr float micronsToCm = 1.0e-4;
0005   const auto convertDoubleVecToFloatVec = [](std::vector<double> const& iIn) {
0006     return std::vector<float>(iIn.begin(), iIn.end());
0007   };
0008 }  // namespace
0009 
0010 PixelCPEGenericBase::PixelCPEGenericBase(edm::ParameterSet const& conf,
0011                                          const MagneticField* mag,
0012                                          const TrackerGeometry& geom,
0013                                          const TrackerTopology& ttopo,
0014                                          const SiPixelLorentzAngle* lorentzAngle,
0015                                          const SiPixelGenErrorDBObject* genErrorDBObject,
0016                                          const SiPixelLorentzAngle* lorentzAngleWidth = nullptr)
0017     : PixelCPEBase(conf, mag, geom, ttopo, lorentzAngle, genErrorDBObject, nullptr, lorentzAngleWidth, 0),
0018       edgeClusterErrorX_{static_cast<float>(conf.getParameter<double>("EdgeClusterErrorX"))},
0019       edgeClusterErrorY_{static_cast<float>(conf.getParameter<double>("EdgeClusterErrorY"))},
0020       useErrorsFromTemplates_{conf.getParameter<bool>("UseErrorsFromTemplates")},
0021       truncatePixelCharge_{conf.getParameter<bool>("TruncatePixelCharge")},
0022       xerr_barrel_l1_{convertDoubleVecToFloatVec(conf.getParameter<std::vector<double>>("xerr_barrel_l1"))},
0023       yerr_barrel_l1_{convertDoubleVecToFloatVec(conf.getParameter<std::vector<double>>("yerr_barrel_l1"))},
0024       xerr_barrel_ln_{convertDoubleVecToFloatVec(conf.getParameter<std::vector<double>>("xerr_barrel_ln"))},
0025       yerr_barrel_ln_{convertDoubleVecToFloatVec(conf.getParameter<std::vector<double>>("yerr_barrel_ln"))},
0026       xerr_endcap_{convertDoubleVecToFloatVec(conf.getParameter<std::vector<double>>("xerr_endcap"))},
0027       yerr_endcap_{convertDoubleVecToFloatVec(conf.getParameter<std::vector<double>>("yerr_endcap"))},
0028       xerr_barrel_l1_def_{static_cast<float>(conf.getParameter<double>("xerr_barrel_l1_def"))},
0029       yerr_barrel_l1_def_{static_cast<float>(conf.getParameter<double>("yerr_barrel_l1_def"))},
0030       xerr_barrel_ln_def_{static_cast<float>(conf.getParameter<double>("xerr_barrel_ln_def"))},
0031       yerr_barrel_ln_def_{static_cast<float>(conf.getParameter<double>("yerr_barrel_ln_def"))},
0032       xerr_endcap_def_{static_cast<float>(conf.getParameter<double>("xerr_endcap_def"))},
0033       yerr_endcap_def_{static_cast<float>(conf.getParameter<double>("yerr_endcap_def"))} {};
0034 
0035 std::unique_ptr<PixelCPEBase::ClusterParam> PixelCPEGenericBase::createClusterParam(const SiPixelCluster& cl) const {
0036   return std::make_unique<ClusterParamGeneric>(cl);
0037 }
0038 
0039 //-----------------------------------------------------------------------------
0040 //!  Collect the edge charges in x and y, in a single pass over the pixel vector.
0041 //!  Calculate charge in the first and last pixel projected in x and y
0042 //!  and the inner cluster charge, projected in x and y.
0043 //-----------------------------------------------------------------------------
0044 void PixelCPEGenericBase::collect_edge_charges(ClusterParam& theClusterParamBase,  //!< input, the cluster
0045                                                int& q_f_X,                         //!< output, Q first  in X
0046                                                int& q_l_X,                         //!< output, Q last   in X
0047                                                int& q_f_Y,                         //!< output, Q first  in Y
0048                                                int& q_l_Y,                         //!< output, Q last   in Y
0049                                                bool truncate) {
0050   ClusterParamGeneric& theClusterParam = static_cast<ClusterParamGeneric&>(theClusterParamBase);
0051 
0052   // Initialize return variables.
0053   q_f_X = q_l_X = 0;
0054   q_f_Y = q_l_Y = 0;
0055 
0056   // Obtain boundaries in index units
0057   int xmin = theClusterParam.theCluster->minPixelRow();
0058   int xmax = theClusterParam.theCluster->maxPixelRow();
0059   int ymin = theClusterParam.theCluster->minPixelCol();
0060   int ymax = theClusterParam.theCluster->maxPixelCol();
0061 
0062   // Iterate over the pixels.
0063   int isize = theClusterParam.theCluster->size();
0064   for (int i = 0; i != isize; ++i) {
0065     auto const& pixel = theClusterParam.theCluster->pixel(i);
0066     // ggiurgiu@fnal.gov: add pixel charge truncation
0067     int pix_adc = pixel.adc;
0068     if (truncate)
0069       pix_adc = std::min(pix_adc, theClusterParam.pixmx);
0070 
0071     //
0072     // X projection
0073     if (pixel.x == xmin)
0074       q_f_X += pix_adc;
0075     if (pixel.x == xmax)
0076       q_l_X += pix_adc;
0077     //
0078     // Y projection
0079     if (pixel.y == ymin)
0080       q_f_Y += pix_adc;
0081     if (pixel.y == ymax)
0082       q_l_Y += pix_adc;
0083   }
0084 }
0085 
0086 void PixelCPEGenericBase::initializeLocalErrorVariables(
0087     float& xerr,
0088     float& yerr,
0089     bool& edgex,
0090     bool& edgey,
0091     bool& bigInX,
0092     bool& bigInY,
0093     int& maxPixelCol,
0094     int& maxPixelRow,
0095     int& minPixelCol,
0096     int& minPixelRow,
0097     uint& sizex,
0098     uint& sizey,
0099     DetParam const& theDetParam,
0100     ClusterParamGeneric const& theClusterParam) const {  // Default errors are the maximum error used for edge clusters.
0101   // These are determined by looking at residuals for edge clusters
0102   xerr = edgeClusterErrorX_ * micronsToCm;
0103   yerr = edgeClusterErrorY_ * micronsToCm;
0104 
0105   // Find if cluster is at the module edge.
0106   maxPixelCol = theClusterParam.theCluster->maxPixelCol();
0107   maxPixelRow = theClusterParam.theCluster->maxPixelRow();
0108   minPixelCol = theClusterParam.theCluster->minPixelCol();
0109   minPixelRow = theClusterParam.theCluster->minPixelRow();
0110 
0111   edgex =
0112       (theDetParam.theTopol->isItEdgePixelInX(minPixelRow)) || (theDetParam.theTopol->isItEdgePixelInX(maxPixelRow));
0113   edgey =
0114       (theDetParam.theTopol->isItEdgePixelInY(minPixelCol)) || (theDetParam.theTopol->isItEdgePixelInY(maxPixelCol));
0115 
0116   sizex = theClusterParam.theCluster->sizeX();
0117   sizey = theClusterParam.theCluster->sizeY();
0118 
0119   // Find if cluster contains double (big) pixels.
0120   bigInX = theDetParam.theTopol->containsBigPixelInX(minPixelRow, maxPixelRow);
0121   bigInY = theDetParam.theTopol->containsBigPixelInY(minPixelCol, maxPixelCol);
0122 };
0123 
0124 void PixelCPEGenericBase::setXYErrors(float& xerr,
0125                                       float& yerr,
0126                                       const bool edgex,
0127                                       const bool edgey,
0128                                       const unsigned int sizex,
0129                                       const unsigned int sizey,
0130                                       const bool bigInX,
0131                                       const bool bigInY,
0132                                       const bool useTemplateErrors,
0133                                       DetParam const& theDetParam,
0134                                       ClusterParamGeneric const& theClusterParam) const {
0135   if (useTemplateErrors) {
0136     if (!edgex) {  // Only use this for non-edge clusters
0137       if (sizex == 1) {
0138         if (!bigInX) {
0139           xerr = theClusterParam.sx1;
0140         } else {
0141           xerr = theClusterParam.sx2;
0142         }
0143       } else {
0144         xerr = theClusterParam.sigmax;
0145       }
0146     }
0147 
0148     if (!edgey) {  // Only use for non-edge clusters
0149       if (sizey == 1) {
0150         if (!bigInY) {
0151           yerr = theClusterParam.sy1;
0152         } else {
0153           yerr = theClusterParam.sy2;
0154         }
0155       } else {
0156         yerr = theClusterParam.sigmay;
0157       }
0158     }
0159 
0160   } else {  // simple errors
0161 
0162     if (GeomDetEnumerators::isTrackerPixel(theDetParam.thePart)) {
0163       if (GeomDetEnumerators::isBarrel(theDetParam.thePart)) {
0164         DetId id = (theDetParam.theDet->geographicalId());
0165         int layer = ttopo_.layer(id);
0166         if (layer == 1) {
0167           if (!edgex) {
0168             if (sizex <= xerr_barrel_l1_.size())
0169               xerr = xerr_barrel_l1_[sizex - 1];
0170             else
0171               xerr = xerr_barrel_l1_def_;
0172           }
0173 
0174           if (!edgey) {
0175             if (sizey <= yerr_barrel_l1_.size())
0176               yerr = yerr_barrel_l1_[sizey - 1];
0177             else
0178               yerr = yerr_barrel_l1_def_;
0179           }
0180         } else {  // layer 2,3
0181           if (!edgex) {
0182             if (sizex <= xerr_barrel_ln_.size())
0183               xerr = xerr_barrel_ln_[sizex - 1];
0184             else
0185               xerr = xerr_barrel_ln_def_;
0186           }
0187 
0188           if (!edgey) {
0189             if (sizey <= yerr_barrel_ln_.size())
0190               yerr = yerr_barrel_ln_[sizey - 1];
0191             else
0192               yerr = yerr_barrel_ln_def_;
0193           }
0194         }
0195 
0196       } else {  // EndCap
0197 
0198         if (!edgex) {
0199           if (sizex <= xerr_endcap_.size())
0200             xerr = xerr_endcap_[sizex - 1];
0201           else
0202             xerr = xerr_endcap_def_;
0203         }
0204 
0205         if (!edgey) {
0206           if (sizey <= yerr_endcap_.size())
0207             yerr = yerr_endcap_[sizey - 1];
0208           else
0209             yerr = yerr_endcap_def_;
0210         }
0211       }  // end endcap
0212     }
0213   }
0214 }
0215 
0216 void PixelCPEGenericBase::fillPSetDescription(edm::ParameterSetDescription& desc) {
0217   desc.add<std::vector<double>>("xerr_barrel_l1", {0.00115, 0.00120, 0.00088});
0218   desc.add<std::vector<double>>("yerr_barrel_l1",
0219                                 {0.00375, 0.00230, 0.00250, 0.00250, 0.00230, 0.00230, 0.00210, 0.00210, 0.00240});
0220   desc.add<std::vector<double>>("xerr_barrel_ln", {0.00115, 0.00120, 0.00088});
0221   desc.add<std::vector<double>>("yerr_barrel_ln",
0222                                 {0.00375, 0.00230, 0.00250, 0.00250, 0.00230, 0.00230, 0.00210, 0.00210, 0.00240});
0223   desc.add<std::vector<double>>("xerr_endcap", {0.0020, 0.0020});
0224   desc.add<std::vector<double>>("yerr_endcap", {0.00210});
0225   desc.add<double>("xerr_barrel_l1_def", 0.01030);
0226   desc.add<double>("yerr_barrel_l1_def", 0.00210);
0227   desc.add<double>("xerr_barrel_ln_def", 0.01030);
0228   desc.add<double>("yerr_barrel_ln_def", 0.00210);
0229   desc.add<double>("xerr_endcap_def", 0.0020);
0230   desc.add<double>("yerr_endcap_def", 0.00075);
0231 }