Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "TrackingTools/DetLayers/interface/RBorderFinder.h"
0002 
0003 RBorderFinder::RBorderFinder(const std::vector<const Det*>& utheDets)
0004     : theNbins(utheDets.size()), isRPeriodic_(false), isROverlapping_(false) {
0005   std::vector<const Det*> theDets = utheDets;
0006   precomputed_value_sort(theDets.begin(), theDets.end(), DetR());
0007 
0008   std::vector<ConstReferenceCountingPointer<BoundDisk> > disks(theNbins);
0009   for (int i = 0; i < theNbins; i++) {
0010     disks[i] = dynamic_cast<const BoundDisk*>(&(theDets[i]->surface()));
0011     if (disks[i] == nullptr) {
0012       throw cms::Exception("UnexpectedState") << "RBorderFinder: implemented for BoundDisks only";
0013     }
0014   }
0015 
0016   if (theNbins == 1) {    // Trivial case
0017     isRPeriodic_ = true;  // meaningless in this case
0018     theRBorders.push_back(disks.front()->innerRadius());
0019     theRBins.push_back((disks.front()->outerRadius() + disks.front()->innerRadius()));
0020     //       std::cout << "RBorderFinder:  theNbins " << theNbins << std::endl
0021     //      << " C: " << theRBins[0]
0022     //      << " Border: " << theRBorders[0] << std::endl;
0023   } else {  // More than 1 bin
0024     double step = (disks.back()->innerRadius() - disks.front()->innerRadius()) / (theNbins - 1);
0025     std::vector<double> spread;
0026     std::vector<std::pair<double, double> > REdge;
0027     REdge.reserve(theNbins);
0028     theRBorders.reserve(theNbins);
0029     theRBins.reserve(theNbins);
0030     spread.reserve(theNbins);
0031 
0032     for (int i = 0; i < theNbins; i++) {
0033       theRBins.push_back((disks[i]->outerRadius() + disks[i]->innerRadius()) / 2.);
0034       spread.push_back(theRBins.back() - (theRBins[0] + i * step));
0035       REdge.push_back(std::pair<double, double>(disks[i]->innerRadius(), disks[i]->outerRadius()));
0036     }
0037 
0038     theRBorders.push_back(REdge[0].first);
0039     for (int i = 1; i < theNbins; i++) {
0040       // Average borders of previous and next bins
0041       double br = (REdge[(i - 1)].second + REdge[i].first) / 2.;
0042       theRBorders.push_back(br);
0043     }
0044 
0045     for (int i = 1; i < theNbins; i++) {
0046       if (REdge[i].first - REdge[i - 1].second < 0) {
0047         isROverlapping_ = true;
0048         break;
0049       }
0050     }
0051 
0052     double rms = stat_RMS(spread);
0053     if (rms < 0.01 * step) {
0054       isRPeriodic_ = true;
0055     }
0056   }
0057 
0058   //Check that everything is proper
0059   if ((int)theRBorders.size() != theNbins || (int)theRBins.size() != theNbins)
0060     throw cms::Exception("UnexpectedState") << "RBorderFinder consistency error";
0061 }