Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #ifndef TrackingTools_DetLayers_GeneralBinFinderInR_H
0002 #define TrackingTools_DetLayers_GeneralBinFinderInR_H
0003 
0004 /** \class GeneralBinFinderInR
0005  *  A R binfinder for a non-periodic group of detectors.
0006  *
0007  *  \author N. Amapane - INFN Torino
0008  */
0009 
0010 #include <Utilities/BinningTools/interface/BaseBinFinder.h>
0011 #include "TrackingTools/DetLayers/interface/RBorderFinder.h"
0012 
0013 #include <cmath>
0014 #include <vector>
0015 
0016 template <class T>
0017 class GeneralBinFinderInR : public BaseBinFinder<T> {
0018 public:
0019   typedef RBorderFinder::Det Det;  //FIXME!!!
0020 
0021   GeneralBinFinderInR() : theNbins(0) {}
0022 
0023   /// Construct from an already initialized RBorderFinder
0024   GeneralBinFinderInR(const RBorderFinder& bf) {
0025     theBorders = bf.RBorders();
0026     theBins = bf.RBins();
0027     theNbins = theBins.size();
0028   }
0029 
0030   /// Construct from the list of Det*
0031   GeneralBinFinderInR(std::vector<Det*>::const_iterator first, std::vector<Det*>::const_iterator last)
0032       : theNbins(last - first) {
0033     std::vector<const Det*> dets(first, last);
0034     RBorderFinder bf(dets);
0035     theBorders = bf.RBorders();
0036     theBins = bf.RBins();
0037     theNbins = theBins.size();
0038   }
0039 
0040   /// Returns an index in the valid range for the bin that contains
0041   /// AND is closest to R
0042   int binIndex(T R) const override {
0043     int i;
0044     for (i = 0; i < theNbins; i++) {
0045       if (R < theBorders[i]) {
0046         break;
0047       }
0048     }
0049     return binIndex(i - 1);
0050   }
0051 
0052   /// Returns an index in the valid range
0053   int binIndex(int i) const override { return std::min(std::max(i, 0), theNbins - 1); }
0054 
0055   /// The middle of the bin
0056   T binPosition(int ind) const override { return theBins[binIndex(ind)]; }
0057 
0058 private:
0059   int theNbins;
0060   std::vector<T> theBorders;
0061   std::vector<T> theBins;
0062 };
0063 #endif