Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:59:51

0001 #include "FWCore/Utilities/interface/Exception.h"
0002 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0003 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0004 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0005 
0006 /**
0007  * Helper that stores one parameter for each layer/ring (wrapper around std::map<std::vector<double>>)
0008  */
0009 class SiStripFakeAPVParameters {
0010 public:
0011   using index = std::pair<int, int>;
0012 
0013   SiStripFakeAPVParameters() {}
0014 
0015   /// Fills the parameters read from cfg and matching the name in the map
0016   SiStripFakeAPVParameters(const edm::ParameterSet& pset, const std::string& parameterName) {
0017     const int layersTIB = 4;
0018     const int ringsTID = 3;
0019     const int layersTOB = 6;
0020     const int ringsTEC = 7;
0021 
0022     fillSubDetParameter(
0023         pset.getParameter<std::vector<double>>(parameterName + "TIB"), int(StripSubdetector::TIB), layersTIB);
0024     fillSubDetParameter(
0025         pset.getParameter<std::vector<double>>(parameterName + "TID"), int(StripSubdetector::TID), ringsTID);
0026     fillSubDetParameter(
0027         pset.getParameter<std::vector<double>>(parameterName + "TOB"), int(StripSubdetector::TOB), layersTOB);
0028     fillSubDetParameter(
0029         pset.getParameter<std::vector<double>>(parameterName + "TEC"), int(StripSubdetector::TEC), ringsTEC);
0030   }
0031 
0032   inline double get(const index& idx) const { return m_data.at(idx.first)[idx.second]; }
0033 
0034   static index getIndex(const TrackerTopology* tTopo, DetId id) {
0035     int layerId{0};
0036     const int subId = StripSubdetector(id).subdetId();
0037     switch (subId) {
0038       case int(StripSubdetector::TIB):
0039         layerId = tTopo->tibLayer(id) - 1;
0040         break;
0041       case int(StripSubdetector::TOB):
0042         layerId = tTopo->tobLayer(id) - 1;
0043         break;
0044       case int(StripSubdetector::TID):
0045         layerId = tTopo->tidRing(id) - 1;
0046         break;
0047       case int(StripSubdetector::TEC):
0048         layerId = tTopo->tecRing(id) - 1;
0049         break;
0050       default:
0051         break;
0052     }
0053     return std::make_pair(subId, layerId);
0054   }
0055 
0056 private:
0057   using LayerParameters = std::vector<double>;
0058   using SubdetParameters = std::map<int, LayerParameters>;
0059   SubdetParameters m_data;
0060 
0061   /**
0062    * Fills the map with the paramters for the given subdetector. <br>
0063    * Each vector "v" holds the parameters for the layers/rings, if the vector has only one parameter
0064    * all the layers/rings get that parameter. <br>
0065    * The only other possibility is that the number of parameters equals the number of layers, otherwise
0066    * an exception of type "Configuration" will be thrown.
0067    */
0068   void fillSubDetParameter(const std::vector<double>& v, const int subDet, const unsigned short layers) {
0069     if (v.size() == layers) {
0070       m_data.insert(std::make_pair(subDet, v));
0071     } else if (v.size() == 1) {
0072       LayerParameters parV(layers, v[0]);
0073       m_data.insert(std::make_pair(subDet, parV));
0074     } else {
0075       throw cms::Exception("Configuration") << "ERROR: number of parameters for subDet " << subDet << " are "
0076                                             << v.size() << ". They must be either 1 or " << layers << std::endl;
0077     }
0078   }
0079 };