Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "CondFormats/SiPixelObjects/interface/SiPixelDetSummary.h"
0002 
0003 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0004 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0005 
0006 using namespace std;
0007 
0008 // ----------------------------------------------------------------------
0009 SiPixelDetSummary::SiPixelDetSummary(int verbose) : fComputeMean(true), fVerbose(verbose) {
0010   unsigned int layers[] = {3, 4};
0011   unsigned index = 0;
0012 
0013   for (unsigned int idet = 0; idet < 2; ++idet) {
0014     for (unsigned int il = 0; il < layers[idet]; ++il) {
0015       index = (idet + 1) * 10000 + (il + 1) * 1000;
0016       if (fVerbose)
0017         cout << "Adding index = " << index << endl;
0018       fCountMap[index] = 0;
0019     }
0020   }
0021 }
0022 
0023 // ----------------------------------------------------------------------
0024 void SiPixelDetSummary::add(const DetId& detid) {
0025   fComputeMean = false;
0026   add(detid, 0.);
0027 }
0028 
0029 // ----------------------------------------------------------------------
0030 void SiPixelDetSummary::add(const DetId& detid, const float& value) {
0031   int detNum = -1;
0032   int idet(-1), il(-1);
0033   string name;
0034 
0035   switch (detid.subdetId()) {
0036     case PixelSubdetector::PixelBarrel: {
0037       idet = 1;
0038       il = PixelBarrelName(detid).layerName();
0039       name = PixelBarrelName(detid).name();
0040       break;
0041     }
0042     case PixelSubdetector::PixelEndcap: {
0043       idet = 2;
0044       PixelEndcapName::HalfCylinder hc = PixelEndcapName(detid).halfCylinder();
0045       name = PixelEndcapName(detid).name();
0046       if (hc == PixelEndcapName::pI || hc == PixelEndcapName::pO) {
0047         il = 3 - PixelEndcapName(detid).diskName();
0048       }
0049       if (hc == PixelEndcapName::mI || hc == PixelEndcapName::mO) {
0050         il = 2 + PixelEndcapName(detid).diskName();
0051       }
0052       break;
0053     }
0054   }
0055 
0056   detNum = idet * 10000 + il * 1000;
0057 
0058   if (fVerbose > 0)
0059     cout << "detNum: " << detNum << " detID: " << static_cast<int>(detid) << " " << name << endl;
0060 
0061   fMeanMap[detNum] += value;
0062   fRmsMap[detNum] += value * value;
0063   fCountMap[detNum] += 1;
0064 }
0065 
0066 // ----------------------------------------------------------------------
0067 void SiPixelDetSummary::print(std::stringstream& ss, const bool mean) const {
0068   std::map<int, int>::const_iterator countIt = fCountMap.begin();
0069   std::map<int, double>::const_iterator meanIt = fMeanMap.begin();
0070   std::map<int, double>::const_iterator rmsIt = fRmsMap.begin();
0071 
0072   ss << "subDet" << setw(15) << "layer" << setw(16);
0073   if (mean)
0074     ss << "mean +- rms" << endl;
0075   else
0076     ss << "count" << endl;
0077 
0078   std::string detector;
0079   std::string oldDetector;
0080 
0081   for (; countIt != fCountMap.end(); ++countIt, ++meanIt, ++rmsIt) {
0082     int count = countIt->second;
0083     double mean = 0.;
0084     double rms = 0.;
0085     if (fComputeMean && count != 0) {
0086       mean = (meanIt->second) / count;
0087       rms = (rmsIt->second) / count - mean * mean;
0088       if (rms <= 0)
0089         rms = 0;
0090       else
0091         rms = sqrt(rms);
0092     }
0093 
0094     // -- Detector type
0095     switch ((countIt->first) / 10000) {
0096       case 1:
0097         detector = "BPIX";
0098         break;
0099       case 2:
0100         detector = "FPIX";
0101         break;
0102     }
0103     if (detector != oldDetector) {
0104       ss << std::endl << detector;
0105       oldDetector = detector;
0106     } else
0107       ss << "    ";
0108 
0109     // -- Layer number
0110     int layer = (countIt->first) / 1000 - (countIt->first) / 10000 * 10;
0111 
0112     ss << std::setw(15) << layer << std::setw(13);
0113     if (fComputeMean)
0114       ss << mean << " +- " << rms << std::endl;
0115     else
0116       ss << countIt->second << std::endl;
0117   }
0118 }