Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-20 22:34:35

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