Go to the documentation of this file.00001 #include "CondFormats/SiPixelObjects/interface/SiPixelDetSummary.h"
00002
00003 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00004 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00005
00006 using namespace std;
00007
00008
00009 SiPixelDetSummary::SiPixelDetSummary(int verbose): fComputeMean(true), fVerbose(verbose) {
00010
00011 unsigned int layers[] = {3, 4};
00012 unsigned index = 0;
00013
00014 for (unsigned int idet = 0; idet < 2; ++idet) {
00015 for (unsigned int il = 0; il < layers[idet]; ++il) {
00016 index = (idet+1)*10000 + (il+1)*1000;
00017 if (fVerbose) cout << "Adding index = " << index << endl;
00018 fCountMap[index] = 0;
00019 }
00020 }
00021 }
00022
00023
00024
00025 void SiPixelDetSummary::add(const DetId & detid) {
00026 fComputeMean= false;
00027 add(detid, 0.);
00028 }
00029
00030
00031
00032 void SiPixelDetSummary::add(const DetId & detid, const float & value) {
00033
00034 int detNum = -1;
00035 int idet(-1), il(-1);
00036 string name;
00037
00038 switch (detid.subdetId()) {
00039 case PixelSubdetector::PixelBarrel: {
00040 idet = 1;
00041 il = PixelBarrelName(detid).layerName();
00042 name = PixelBarrelName(detid).name();
00043 break;
00044 }
00045 case PixelSubdetector::PixelEndcap: {
00046 idet = 2;
00047 PixelEndcapName::HalfCylinder hc = PixelEndcapName(detid).halfCylinder();
00048 name = PixelEndcapName(detid).name();
00049 if (hc == PixelEndcapName::pI || hc == PixelEndcapName::pO) {
00050 il = 3 - PixelEndcapName(detid).diskName();
00051 }
00052 if (hc == PixelEndcapName::mI || hc == PixelEndcapName::mO) {
00053 il = 2 + PixelEndcapName(detid).diskName();
00054 }
00055 break;
00056 }
00057 }
00058
00059 detNum = idet*10000 + il*1000;
00060
00061 if (fVerbose > 0)
00062 cout << "detNum: " << detNum
00063 << " detID: " << static_cast<int>(detid)
00064 << " " << name
00065 << endl;
00066
00067 fMeanMap[detNum] += value;
00068 fRmsMap[detNum] += value*value;
00069 fCountMap[detNum] += 1;
00070 }
00071
00072
00073 void SiPixelDetSummary::print(std::stringstream & ss, const bool mean) const {
00074 std::map<int, int>::const_iterator countIt = fCountMap.begin();
00075 std::map<int, double>::const_iterator meanIt = fMeanMap.begin();
00076 std::map<int, double>::const_iterator rmsIt = fRmsMap.begin();
00077
00078 ss << "subDet" << setw(15) << "layer" << setw(16);
00079 if (mean) ss << "mean +- rms" << endl;
00080 else ss << "count" << endl;
00081
00082 std::string detector;
00083 std::string oldDetector;
00084
00085 for (; countIt != fCountMap.end(); ++countIt, ++meanIt, ++rmsIt ) {
00086 int count = countIt->second;
00087 double mean = 0.;
00088 double rms = 0.;
00089 if (fComputeMean && count != 0) {
00090 mean = (meanIt->second)/count;
00091 rms = (rmsIt->second)/count - mean*mean;
00092 if (rms <= 0)
00093 rms = 0;
00094 else
00095 rms = sqrt(rms);
00096 }
00097
00098
00099 switch ((countIt->first)/10000) {
00100 case 1:
00101 detector = "BPIX";
00102 break;
00103 case 2:
00104 detector = "FPIX";
00105 break;
00106 }
00107 if( detector != oldDetector ) {
00108 ss << std::endl << detector;
00109 oldDetector = detector;
00110 }
00111 else ss << " ";
00112
00113
00114 int layer = (countIt->first)/1000 - (countIt->first)/10000*10;
00115
00116 ss << std::setw(15) << layer << std::setw(13) ;
00117 if (fComputeMean) ss << mean << " +- " << rms << std::endl;
00118 else ss << countIt->second << std::endl;
00119 }
00120 }