Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 
0003 #include "CondFormats/SiPixelObjects/interface/SiPixelPerformanceSummary.h"
0004 
0005 #include <algorithm>
0006 
0007 using namespace edm;
0008 using namespace std;
0009 
0010 SiPixelPerformanceSummary::SiPixelPerformanceSummary()
0011     : timeStamp_(0), runNumber_(0), luminosityBlock_(0), numberOfEvents_(0) {}
0012 
0013 SiPixelPerformanceSummary::SiPixelPerformanceSummary(const SiPixelPerformanceSummary& performanceSummary) {
0014   timeStamp_ = performanceSummary.getTimeStamp();
0015   runNumber_ = performanceSummary.getRunNumber();
0016   luminosityBlock_ = performanceSummary.getLuminosityBlock();
0017   numberOfEvents_ = performanceSummary.getNumberOfEvents();
0018   allDetSummaries_ = performanceSummary.getAllDetSummaries();
0019 }
0020 
0021 SiPixelPerformanceSummary::~SiPixelPerformanceSummary() {}
0022 
0023 void SiPixelPerformanceSummary::clear() {
0024   timeStamp_ = 0;
0025   runNumber_ = 0;
0026   luminosityBlock_ = 0;
0027   numberOfEvents_ = 0;
0028   allDetSummaries_.clear();
0029 }
0030 
0031 pair<bool, vector<SiPixelPerformanceSummary::DetSummary>::iterator> SiPixelPerformanceSummary::initDet(
0032     const uint32_t detId) {
0033   vector<float> performanceValues;
0034   performanceValues.reserve(kDetSummarySize);
0035   for (int i = 0; i < kDetSummarySize; ++i)
0036     performanceValues.push_back(kDefaultValue);
0037   return setDet(detId, performanceValues);
0038 }
0039 
0040 pair<bool, vector<SiPixelPerformanceSummary::DetSummary>::iterator> SiPixelPerformanceSummary::setDet(
0041     const uint32_t detId, const vector<float>& performanceValues) {
0042   vector<DetSummary>::iterator iDetSumm = allDetSummaries_.end();
0043 
0044   if (performanceValues.size() != kDetSummarySize) {  // for inappropriate input
0045     cout << "not adding these " << performanceValues.size() << " values; "
0046          << "SiPixelPerformanceSummary can only add " << kDetSummarySize << " values per DetSummary";
0047     return make_pair(false, iDetSumm);
0048   }
0049   iDetSumm = lower_bound(
0050       allDetSummaries_.begin(), allDetSummaries_.end(), detId, SiPixelPerformanceSummary::StrictWeakOrdering());
0051 
0052   if (iDetSumm != allDetSummaries_.end() &&  // for an existong entry
0053       iDetSumm->detId_ == detId)
0054     return make_pair(false, iDetSumm);
0055 
0056   DetSummary newDetSumm;  // for a new entry, put at (position-1) returned by StrictWeakOrdering
0057   newDetSumm.detId_ = detId;
0058   newDetSumm.performanceValues_ = performanceValues;
0059   return make_pair(true, allDetSummaries_.insert(iDetSumm, newDetSumm));
0060 }
0061 
0062 bool SiPixelPerformanceSummary::setValue(uint32_t detId, int index, float performanceValue) {
0063   if (index > kDetSummarySize) {
0064     cout << "cannot set the performance value for index = " << index << " > " << kDetSummarySize;
0065     return false;
0066   }
0067   pair<bool, vector<DetSummary>::iterator> initResult = initDet(detId);
0068   if (initResult.first || initResult.second != allDetSummaries_.end()) {
0069     initResult.second->performanceValues_[index] = performanceValue;
0070     return true;
0071   } else {
0072     cout << "cannot set the performance value; cannot create new entry for detId = " << detId;
0073     return false;
0074   }
0075   return true;
0076 }
0077 
0078 float SiPixelPerformanceSummary::getValue(uint32_t detId, int index) {
0079   if (index > kDetSummarySize) {
0080     cout << "cannot get value for detId = " << detId << " index = " << index << " > " << kDetSummarySize;
0081     return kDefaultValue;
0082   }
0083   vector<float> performanceValues = getDetSummary(detId);
0084   if (performanceValues.size() == kDetSummarySize)
0085     return performanceValues[index];
0086   else
0087     return kDefaultValue;
0088 }
0089 
0090 bool SiPixelPerformanceSummary::setRawDataErrorType(uint32_t detId, int bin, float nErrors) {
0091   return setValue(detId, bin, nErrors);
0092 }
0093 
0094 bool SiPixelPerformanceSummary::setNumberOfDigis(uint32_t detId, float mean, float rms, float emPtn) {
0095   return (setValue(detId, 15, mean) && setValue(detId, 16, rms) && setValue(detId, 17, emPtn));
0096 }
0097 
0098 bool SiPixelPerformanceSummary::setADC(uint32_t detId, float mean, float rms, float emPtn) {
0099   return (setValue(detId, 18, mean) && setValue(detId, 19, rms) && setValue(detId, 20, emPtn));
0100 }
0101 
0102 bool SiPixelPerformanceSummary::setNumberOfClusters(uint32_t detId, float mean, float rms, float emPtn) {
0103   return (setValue(detId, 21, mean) && setValue(detId, 22, rms) && setValue(detId, 23, emPtn));
0104 }
0105 
0106 bool SiPixelPerformanceSummary::setClusterCharge(uint32_t detId, float mean, float rms, float emPtn) {
0107   return (setValue(detId, 24, mean) && setValue(detId, 25, rms) && setValue(detId, 26, emPtn));
0108 }
0109 
0110 bool SiPixelPerformanceSummary::setClusterSize(uint32_t detId, float mean, float rms, float emPtn) {
0111   return (setValue(detId, 27, mean) && setValue(detId, 28, rms) && setValue(detId, 29, emPtn));
0112 }
0113 
0114 bool SiPixelPerformanceSummary::setClusterSizeX(uint32_t detId, float mean, float rms, float emPtn) {
0115   return (setValue(detId, 30, mean) && setValue(detId, 31, rms) && setValue(detId, 32, emPtn));
0116 }
0117 
0118 bool SiPixelPerformanceSummary::setClusterSizeY(uint32_t detId, float mean, float rms, float emPtn) {
0119   return (setValue(detId, 33, mean) && setValue(detId, 34, rms) && setValue(detId, 35, emPtn));
0120 }
0121 
0122 bool SiPixelPerformanceSummary::setNumberOfRecHits(uint32_t detId, float mean, float rms, float emPtn) {
0123   return (setValue(detId, 36, mean) && setValue(detId, 37, rms) && setValue(detId, 38, emPtn));
0124 }
0125 
0126 bool SiPixelPerformanceSummary::setResidualX(uint32_t detId, float mean, float rms, float emPtn) {
0127   return (setValue(detId, 39, mean) && setValue(detId, 40, rms) && setValue(detId, 41, emPtn));
0128 }
0129 
0130 bool SiPixelPerformanceSummary::setResidualY(uint32_t detId, float mean, float rms, float emPtn) {
0131   return (setValue(detId, 42, mean) && setValue(detId, 43, rms) && setValue(detId, 44, emPtn));
0132 }
0133 
0134 bool SiPixelPerformanceSummary::setNumberOfNoisCells(uint32_t detId, float nNpixCells) {
0135   return setValue(detId, 45, nNpixCells);
0136 }
0137 
0138 bool SiPixelPerformanceSummary::setNumberOfDeadCells(uint32_t detId, float nNpixCells) {
0139   return setValue(detId, 46, nNpixCells);
0140 }
0141 
0142 bool SiPixelPerformanceSummary::setNumberOfPixelHitsInTrackFit(uint32_t detId, float nPixelHits) {
0143   return setValue(detId, 47, nPixelHits);
0144 }
0145 
0146 bool SiPixelPerformanceSummary::setFractionOfTracks(uint32_t detId, float mean, float rms) {
0147   return (setValue(detId, 48, mean) && setValue(detId, 49, rms));
0148 }
0149 
0150 bool SiPixelPerformanceSummary::setNumberOfOnTrackClusters(uint32_t detId, float nClusters) {
0151   return setValue(detId, 50, nClusters);
0152 }
0153 
0154 bool SiPixelPerformanceSummary::setNumberOfOffTrackClusters(uint32_t detId, float nClusters) {
0155   return setValue(detId, 51, nClusters);
0156 }
0157 
0158 bool SiPixelPerformanceSummary::setClusterChargeOnTrack(uint32_t detId, float mean, float rms) {
0159   return (setValue(detId, 52, mean) && setValue(detId, 53, rms));
0160 }
0161 
0162 bool SiPixelPerformanceSummary::setClusterChargeOffTrack(uint32_t detId, float mean, float rms) {
0163   return (setValue(detId, 54, mean) && setValue(detId, 55, rms));
0164 }
0165 
0166 bool SiPixelPerformanceSummary::setClusterSizeOnTrack(uint32_t detId, float mean, float rms) {
0167   return (setValue(detId, 56, mean) && setValue(detId, 57, rms));
0168 }
0169 
0170 bool SiPixelPerformanceSummary::setClusterSizeOffTrack(uint32_t detId, float mean, float rms) {
0171   return (setValue(detId, 58, mean) && setValue(detId, 59, rms));
0172 }
0173 
0174 vector<uint32_t> SiPixelPerformanceSummary::getAllDetIds() const {
0175   vector<uint32_t> allDetIds;
0176   for (vector<DetSummary>::const_iterator iDetSumm = allDetSummaries_.begin(); iDetSumm != allDetSummaries_.end();
0177        ++iDetSumm)
0178     allDetIds.push_back(iDetSumm->detId_);
0179   return allDetIds;
0180 }
0181 
0182 vector<float> SiPixelPerformanceSummary::getDetSummary(const uint32_t detId) const {
0183   vector<DetSummary>::const_iterator iDetSumm =
0184       find_if(allDetSummaries_.begin(), allDetSummaries_.end(), [&detId](const DetSummary& detSumm) -> bool {
0185         return detSumm.detId_ == detId;
0186       });
0187   if (iDetSumm == allDetSummaries_.end()) {
0188     vector<float> performanceValues;
0189     cout << "cannot get DetSummary for detId = " << detId;
0190     return performanceValues;
0191   } else
0192     return iDetSumm->performanceValues_;
0193 }
0194 
0195 void SiPixelPerformanceSummary::print(const uint32_t detId) const {
0196   vector<float> performanceValues = getDetSummary(detId);
0197   cout << "DetSummary for detId " << detId << " : ";
0198   for (vector<float>::const_iterator v = performanceValues.begin(); v != performanceValues.end(); ++v)
0199     cout << " " << *v;
0200   cout << endl;
0201 }
0202 
0203 void SiPixelPerformanceSummary::print() const {
0204   cout << "SiPixelPerformanceSummary size (allDets) = " << allDetSummaries_.size() << ", "
0205        << "time stamp = " << timeStamp_ << ", "
0206        << "run number = " << runNumber_ << ", "
0207        << "luminosity section = " << luminosityBlock_ << ", "
0208        << "number of events = " << numberOfEvents_ << endl;
0209 }
0210 
0211 void SiPixelPerformanceSummary::printAll() const {
0212   print();
0213   for (vector<DetSummary>::const_iterator iDetSumm = allDetSummaries_.begin(); iDetSumm != allDetSummaries_.end();
0214        ++iDetSumm)
0215     print(iDetSumm->detId_);
0216 }