Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:02

0001 /*
0002  *  See header file for a description of this class.
0003  *
0004  *  \author Paolo Ronchese INFN Padova
0005  *
0006  */
0007 
0008 //----------------------
0009 // This Class' Header --
0010 //----------------------
0011 #include "CondFormats/DTObjects/interface/DTPerformance.h"
0012 
0013 //-------------------------------
0014 // Collaborating Class Headers --
0015 //-------------------------------
0016 #include "CondFormats/DTObjects/interface/DTBufferTree.h"
0017 
0018 //---------------
0019 // C++ Headers --
0020 //---------------
0021 #include <iostream>
0022 #include <sstream>
0023 
0024 //-------------------
0025 // Initializations --
0026 //-------------------
0027 
0028 //----------------
0029 // Constructors --
0030 //----------------
0031 DTPerformance::DTPerformance() : dataVersion(" "), nsPerCount(0.0), dBuf(new DTBufferTree<int, int>) {
0032   dataList.reserve(1000);
0033 }
0034 
0035 DTPerformance::DTPerformance(const std::string& version)
0036     : dataVersion(version), nsPerCount(0.0), dBuf(new DTBufferTree<int, int>) {
0037   dataList.reserve(1000);
0038 }
0039 
0040 DTPerformanceId::DTPerformanceId() : wheelId(0), stationId(0), sectorId(0), slId(0) {}
0041 
0042 DTPerformanceData::DTPerformanceData()
0043     : meanT0(0.0),
0044       meanTtrig(0.0),
0045       meanMtime(0.0),
0046       meanNoise(0.0),
0047       meanAfterPulse(0.0),
0048       meanResolution(0.0),
0049       meanEfficiency(0.0) {}
0050 
0051 //--------------
0052 // Destructor --
0053 //--------------
0054 DTPerformance::~DTPerformance() {}
0055 
0056 DTPerformanceData::~DTPerformanceData() {}
0057 
0058 DTPerformanceId::~DTPerformanceId() {}
0059 
0060 //--------------
0061 // Operations --
0062 //--------------
0063 int DTPerformance::get(int wheelId,
0064                        int stationId,
0065                        int sectorId,
0066                        int slId,
0067                        float& meanT0,
0068                        float& meanTtrig,
0069                        float& meanMtime,
0070                        float& meanNoise,
0071                        float& meanAfterPulse,
0072                        float& meanResolution,
0073                        float& meanEfficiency,
0074                        DTTimeUnits::type unit) const {
0075   meanT0 = meanTtrig = meanMtime = meanNoise = meanAfterPulse = meanResolution = meanEfficiency = 0.0;
0076 
0077   std::vector<int> chanKey;
0078   chanKey.reserve(4);
0079   chanKey.push_back(wheelId);
0080   chanKey.push_back(stationId);
0081   chanKey.push_back(sectorId);
0082   chanKey.push_back(slId);
0083   int ientry;
0084   //Guarantee const correctness for thread-safety
0085   const DTBufferTree<int, int>* constDBuf = dBuf;
0086   int searchStatus = constDBuf->find(chanKey.begin(), chanKey.end(), ientry);
0087   if (!searchStatus) {
0088     const DTPerformanceData& data(dataList[ientry].second);
0089     meanT0 = data.meanT0;
0090     meanTtrig = data.meanTtrig;
0091     meanMtime = data.meanMtime;
0092     meanNoise = data.meanNoise;
0093     meanAfterPulse = data.meanAfterPulse;
0094     meanResolution = data.meanResolution;
0095     meanEfficiency = data.meanEfficiency;
0096     if (unit == DTTimeUnits::ns) {
0097       meanT0 *= nsPerCount;
0098       meanTtrig *= nsPerCount;
0099       meanMtime *= nsPerCount;
0100     }
0101   }
0102 
0103   return searchStatus;
0104 }
0105 
0106 int DTPerformance::get(const DTSuperLayerId& id,
0107                        float& meanT0,
0108                        float& meanTtrig,
0109                        float& meanMtime,
0110                        float& meanNoise,
0111                        float& meanAfterPulse,
0112                        float& meanResolution,
0113                        float& meanEfficiency,
0114                        DTTimeUnits::type unit) const {
0115   return get(id.wheel(),
0116              id.station(),
0117              id.sector(),
0118              id.superLayer(),
0119              meanT0,
0120              meanTtrig,
0121              meanMtime,
0122              meanNoise,
0123              meanAfterPulse,
0124              meanResolution,
0125              meanEfficiency,
0126              unit);
0127 }
0128 
0129 float DTPerformance::unit() const { return nsPerCount; }
0130 
0131 const std::string& DTPerformance::version() const { return dataVersion; }
0132 
0133 std::string& DTPerformance::version() { return dataVersion; }
0134 
0135 void DTPerformance::clear() {
0136   dataList.clear();
0137   initialize();
0138   return;
0139 }
0140 
0141 int DTPerformance::set(int wheelId,
0142                        int stationId,
0143                        int sectorId,
0144                        int slId,
0145                        float meanT0,
0146                        float meanTtrig,
0147                        float meanMtime,
0148                        float meanNoise,
0149                        float meanAfterPulse,
0150                        float meanResolution,
0151                        float meanEfficiency,
0152                        DTTimeUnits::type unit) {
0153   if (unit == DTTimeUnits::ns) {
0154     meanT0 /= nsPerCount;
0155     meanTtrig /= nsPerCount;
0156     meanMtime /= nsPerCount;
0157   }
0158 
0159   std::vector<int> chanKey;
0160   chanKey.reserve(4);
0161   chanKey.push_back(wheelId);
0162   chanKey.push_back(stationId);
0163   chanKey.push_back(sectorId);
0164   chanKey.push_back(slId);
0165   int ientry;
0166   int searchStatus = dBuf->find(chanKey.begin(), chanKey.end(), ientry);
0167 
0168   if (!searchStatus) {
0169     DTPerformanceData& data(dataList[ientry].second);
0170     data.meanT0 = meanT0;
0171     data.meanTtrig = meanTtrig;
0172     data.meanMtime = meanMtime;
0173     data.meanNoise = meanNoise;
0174     data.meanAfterPulse = meanAfterPulse;
0175     data.meanResolution = meanResolution;
0176     data.meanEfficiency = meanEfficiency;
0177     return -1;
0178   } else {
0179     DTPerformanceId key;
0180     key.wheelId = wheelId;
0181     key.stationId = stationId;
0182     key.sectorId = sectorId;
0183     key.slId = slId;
0184     DTPerformanceData data;
0185     data.meanT0 = meanT0;
0186     data.meanTtrig = meanTtrig;
0187     data.meanMtime = meanMtime;
0188     data.meanNoise = meanNoise;
0189     data.meanAfterPulse = meanAfterPulse;
0190     data.meanResolution = meanResolution;
0191     data.meanEfficiency = meanEfficiency;
0192     ientry = dataList.size();
0193     dataList.push_back(std::pair<DTPerformanceId, DTPerformanceData>(key, data));
0194     dBuf->insert(chanKey.begin(), chanKey.end(), ientry);
0195     return 0;
0196   }
0197 
0198   return 99;
0199 }
0200 
0201 int DTPerformance::set(const DTSuperLayerId& id,
0202                        float meanT0,
0203                        float meanTtrig,
0204                        float meanMtime,
0205                        float meanNoise,
0206                        float meanAfterPulse,
0207                        float meanResolution,
0208                        float meanEfficiency,
0209                        DTTimeUnits::type unit) {
0210   return set(id.wheel(),
0211              id.station(),
0212              id.sector(),
0213              id.superLayer(),
0214              meanT0,
0215              meanTtrig,
0216              meanMtime,
0217              meanNoise,
0218              meanAfterPulse,
0219              meanResolution,
0220              meanEfficiency,
0221              unit);
0222 }
0223 
0224 void DTPerformance::setUnit(float unit) { nsPerCount = unit; }
0225 
0226 DTPerformance::const_iterator DTPerformance::begin() const { return dataList.begin(); }
0227 
0228 DTPerformance::const_iterator DTPerformance::end() const { return dataList.end(); }
0229 
0230 std::string DTPerformance::mapName() const {
0231   std::stringstream name;
0232   name << dataVersion << "_map_Performance" << this;
0233   return name.str();
0234 }
0235 
0236 void DTPerformance::initialize() {
0237   dBuf->clear();
0238 
0239   int entryNum = 0;
0240   int entryMax = dataList.size();
0241   std::vector<int> chanKey;
0242   chanKey.reserve(6);
0243   while (entryNum < entryMax) {
0244     const DTPerformanceId& chan = dataList[entryNum].first;
0245 
0246     chanKey.clear();
0247     chanKey.push_back(chan.wheelId);
0248     chanKey.push_back(chan.stationId);
0249     chanKey.push_back(chan.sectorId);
0250     chanKey.push_back(chan.slId);
0251     dBuf->insert(chanKey.begin(), chanKey.end(), entryNum++);
0252   }
0253   return;
0254 }