CMS 3D CMS Logo

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