CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiPixelDetSummary.cc
Go to the documentation of this file.
2 
7 
8 using namespace std;
9 
10 // ----------------------------------------------------------------------
11 SiPixelDetSummary::SiPixelDetSummary(int verbose): fComputeMean(true), fVerbose(verbose) {
12 
13  unsigned int layers[] = {3, 4};
14  unsigned index = 0;
15 
16  for (unsigned int idet = 0; idet < 2; ++idet) {
17  for (unsigned int il = 0; il < layers[idet]; ++il) {
18  index = (idet+1)*10000 + (il+1)*1000;
19  if (fVerbose) cout << "Adding index = " << index << endl;
20  fCountMap[index] = 0;
21  }
22  }
23 }
24 
25 
26 // ----------------------------------------------------------------------
28  fComputeMean= false;
29  add(detid, 0.);
30 }
31 
32 
33 // ----------------------------------------------------------------------
34 void SiPixelDetSummary::add(const DetId & detid, const float & value) {
35 
36  int detNum = -1;
37  int idet(-1), il(-1);
38  string name;
39 
40  switch (detid.subdetId()) {
42  idet = 1;
43  il = PixelBarrelName(detid).layerName();
44  name = PixelBarrelName(detid).name();
45  break;
46  }
48  idet = 2;
50  name = PixelEndcapName(detid).name();
51  if (hc == PixelEndcapName::pI || hc == PixelEndcapName::pO) {
52  il = 3 - PixelEndcapName(detid).diskName();
53  }
54  if (hc == PixelEndcapName::mI || hc == PixelEndcapName::mO) {
55  il = 2 + PixelEndcapName(detid).diskName();
56  }
57  break;
58  }
59  }
60 
61  detNum = idet*10000 + il*1000;
62 
63  if (fVerbose > 0)
64  cout << "detNum: " << detNum
65  << " detID: " << static_cast<int>(detid)
66  << " " << name
67  << endl;
68 
69  fMeanMap[detNum] += value;
70  fRmsMap[detNum] += value*value;
71  fCountMap[detNum] += 1;
72 }
73 
74 // ----------------------------------------------------------------------
75 void SiPixelDetSummary::print(std::stringstream & ss, const bool mean) const {
76  std::map<int, int>::const_iterator countIt = fCountMap.begin();
77  std::map<int, double>::const_iterator meanIt = fMeanMap.begin();
78  std::map<int, double>::const_iterator rmsIt = fRmsMap.begin();
79 
80  ss << "subDet" << setw(15) << "layer" << setw(16);
81  if (mean) ss << "mean +- rms" << endl;
82  else ss << "count" << endl;
83 
84  std::string detector;
85  std::string oldDetector;
86 
87  for (; countIt != fCountMap.end(); ++countIt, ++meanIt, ++rmsIt ) {
88  int count = countIt->second;
89  double mean = 0.;
90  double rms = 0.;
91  if (fComputeMean && count != 0) {
92  mean = (meanIt->second)/count;
93  rms = (rmsIt->second)/count - mean*mean;
94  if (rms <= 0)
95  rms = 0;
96  else
97  rms = sqrt(rms);
98  }
99 
100  // -- Detector type
101  switch ((countIt->first)/10000) {
102  case 1:
103  detector = "BPIX";
104  break;
105  case 2:
106  detector = "FPIX";
107  break;
108  }
109  if( detector != oldDetector ) {
110  ss << std::endl << detector;
111  oldDetector = detector;
112  }
113  else ss << " ";
114 
115  // -- Layer number
116  int layer = (countIt->first)/1000 - (countIt->first)/10000*10;
117 
118  ss << std::setw(15) << layer << std::setw(13) ;
119  if (fComputeMean) ss << mean << " +- " << rms << std::endl;
120  else ss << countIt->second << std::endl;
121  }
122 }
void add(const DetId &detid, const float &value)
std::map< int, double > fMeanMap
T sqrt(T t)
Definition: SSEVec.h:28
void print(std::stringstream &ss, const bool mean=true) const
SiPixelDetSummary(int verbose=0)
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:39
Definition: DetId.h:20
virtual std::string name() const
from base class
std::map< int, double > fRmsMap
int layerName() const
layer id
virtual std::string name() const
from base class
std::map< int, int > fCountMap
tuple cout
Definition: gather_cfg.py:41
int diskName() const
disk id
HalfCylinder halfCylinder() const