CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/CondFormats/SiPixelObjects/src/SiPixelDetSummary.cc

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