CMS 3D CMS Logo

SiPixelDetectorStatus.cc
Go to the documentation of this file.
1 #include <iostream>
2 #include <fstream>
3 #include <map>
4 #include <cmath>
5 #include <vector>
6 
7 #include <TString.h>
8 #include <TMath.h>
9 #include <TH1.h>
10 
12 
13 // ----------------------------------------------------------------------
14 SiPixelDetectorStatus::SiPixelDetectorStatus() : fLS0_(99999999), fLS1_(0), fRun0_(99999999), fRun1_(0) {
15  fDetHits_ = 0;
16  ftotalevents_ = 0;
17 }
18 
19 // ----------------------------------------------------------------------
21 
22 // ----------------------------------------------------------------------
24  std::ifstream INS;
25  std::string sline;
26  INS.open(filename.c_str());
27 
28  int oldDetId(-1);
29  int detid(0), roc(0), hits(0), nroc(0);
30  SiPixelModuleStatus* pMod(nullptr);
31  bool readOK(false);
32  while (std::getline(INS, sline)) {
33  if (std::string::npos != sline.find("# SiPixelDetectorStatus START")) {
34  readOK = true;
35  continue;
36  }
37  if (!readOK)
38  continue;
39 
40  if (std::string::npos != sline.find("# SiPixelDetectorStatus END")) {
41  pMod->setNrocs(nroc + 1);
42  break;
43  }
44 
45  if (sline.find("# SiPixelDetectorStatus for LS") != std::string::npos) {
46  std::sscanf(sline.c_str(), "# SiPixelDetectorStatus for LS %d .. %d", &fLS0_, &fLS1_);
47  continue;
48  }
49  if (sline.find("# SiPixelDetectorStatus for run") != std::string::npos) {
50  std::sscanf(sline.c_str(), "# SiPixelDetectorStatus for run %d .. %d", &fRun0_, &fRun1_);
51  continue;
52  }
53  if (sline.find("# SiPixelDetectorStatus total hits = ") != std::string::npos) {
54  std::sscanf(sline.c_str(), "# SiPixelDetectorStatus total hits = %ld", &fDetHits_);
55  continue;
56  }
57 
58  std::sscanf(sline.c_str(), "%d %d %d", &detid, &roc, &hits);
59  if (roc > nroc)
60  nroc = roc;
61  if (detid != oldDetId) {
62  if (pMod) {
63  pMod->setNrocs(nroc + 1); // roc ranges from 0, "+1" to get number of rocs per module
64  }
65 
66  oldDetId = detid;
67  if (getModule(detid) == nullptr) {
68  addModule(detid, nroc + 1); // roc ranges from 0, "+1" to get number of rocs per module
69  }
70 
71  pMod = getModule(detid);
72  nroc = 0;
73  }
74  // for existing module, update its content
75  if (pMod != nullptr) {
76  fDetHits_ += hits;
77  pMod->updateModuleDIGI(roc, hits);
78  }
79  }
80 
81  INS.close();
82 }
83 
84 // ----------------------------------------------------------------------
85 void SiPixelDetectorStatus::dumpToFile(std::ofstream& OD) {
86  OD << "# SiPixelDetectorStatus START" << std::endl;
87  OD << "# SiPixelDetectorStatus for LS " << fLS0_ << " .. " << fLS1_ << std::endl;
88  OD << "# SiPixelDetectorStatus for run " << fRun0_ << " .. " << fRun1_ << std::endl;
89  OD << "# SiPixelDetectorStatus total hits = " << fDetHits_ << std::endl;
90 
91  for (std::map<int, SiPixelModuleStatus>::iterator it = SiPixelDetectorStatus::begin();
93  ++it) {
94  for (int iroc = 0; iroc < it->second.nrocs(); ++iroc) {
95  OD << Form("%10d %2d %3d", it->first, iroc, int(it->second.getRoc(iroc)->digiOccROC())) << std::endl;
96  }
97  }
98  OD << "# SiPixelDetectorStatus END" << std::endl;
99 }
100 
101 // ----------------------------------------------------------------------
103  // only need to add NEW modules
104  if (fModules_.find(detid) == fModules_.end()) {
105  SiPixelModuleStatus a(detid, nrocs);
106  fModules_.insert(std::make_pair(detid, a));
107  }
108 }
109 
110 // ----------------------------------------------------------------------
111 void SiPixelDetectorStatus::addModule(int detid, SiPixelModuleStatus a) { fModules_.insert(std::make_pair(detid, a)); }
112 
113 // ----------------------------------------------------------------------
114 void SiPixelDetectorStatus::fillDIGI(int detid, int roc) {
115  ++fDetHits_;
116  fModules_[detid].fillDIGI(roc);
117 }
118 
119 // ----------------------------------------------------------------------
121  if (fModules_.find(detid) != fModules_.end()) {
122  fModules_[detid].fillFEDerror25(ch);
123  }
124 }
125 
126 // FEDerror25 effected ROCs in for each module
127 std::map<int, std::vector<int>> SiPixelDetectorStatus::getFEDerror25Rocs() {
128  std::map<int, std::vector<int>> badRocLists;
129 
130  for (std::map<int, SiPixelModuleStatus>::iterator itMod = SiPixelDetectorStatus::begin();
131  itMod != SiPixelDetectorStatus::end();
132  ++itMod) {
133  int detid = itMod->first;
134  // FEDerror25 effected ROCs in a given module
135  std::vector<int> list;
136  SiPixelModuleStatus modStatus = itMod->second;
137  for (int iroc = 0; iroc < modStatus.nrocs(); ++iroc) {
138  SiPixelRocStatus* roc = modStatus.getRoc(iroc);
139  if (roc->isFEDerror25()) {
140  list.push_back(iroc);
141  }
142  badRocLists[detid] = list;
143  }
144  }
145 
146  return badRocLists;
147 }
148 
149 // ----------------------------------------------------------------------
150 std::map<int, SiPixelModuleStatus>::iterator SiPixelDetectorStatus::begin() { return fModules_.begin(); }
151 
152 // ----------------------------------------------------------------------
153 std::map<int, SiPixelModuleStatus>::iterator SiPixelDetectorStatus::end() { return fModules_.end(); }
154 
155 // ----------------------------------------------------------------------
156 int SiPixelDetectorStatus::nmodules() { return static_cast<int>(fModules_.size()); }
157 
158 // ----------------------------------------------------------------------
160  if (fModules_.find(detid) == fModules_.end()) {
161  return nullptr;
162  }
163  return &(fModules_[detid]);
164 }
165 
167  if (fModules_.find(detid) == fModules_.end())
168  return false;
169  else
170  return true;
171 }
172 
173 // ----------------------------------------------------------------------
175  unsigned long int ave(0);
176  int nrocs(0);
177  for (std::map<int, SiPixelModuleStatus>::iterator it = SiPixelDetectorStatus::begin();
179  ++it) {
180  unsigned long int inc = it->second.digiOccMOD();
181  ave += inc;
182  nrocs += it->second.nrocs();
183  }
184  return (1.0 * ave) / nrocs;
185 }
186 
188  double fDetAverage = SiPixelDetectorStatus::perRocDigiOcc();
189 
190  double sig = 0.0;
191  int nrocs(0);
192  for (std::map<int, SiPixelModuleStatus>::iterator it = SiPixelDetectorStatus::begin();
194  ++it) {
195  unsigned long int inc = it->second.digiOccMOD();
196  sig += (fDetAverage - inc) * (fDetAverage - inc);
197  nrocs += it->second.nrocs();
198  }
199 
200  double fDetSigma = sig / (nrocs - 1);
201  return TMath::Sqrt(fDetSigma);
202 }
203 
204 /*|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
205 
206 // combine status from different data (coming from different run/lumi)
208  // loop over new data status
209  for (std::map<int, SiPixelModuleStatus>::iterator it = newData.begin(); it != newData.end(); ++it) {
210  int detid = it->first;
211 
212  if (fModules_.find(detid) != fModules_.end()) { // if the detid is in the module lists
213  fModules_[detid].updateModuleStatus(*(newData.getModule(detid)));
214  } else { // if new module, add(insert) the module data
215  fModules_.insert(std::make_pair(detid, *(newData.getModule(detid))));
216  }
217  }
218 
219  fDetHits_ = fDetHits_ + newData.digiOccDET();
220  ftotalevents_ = ftotalevents_ + newData.getNevents();
221 }
222 
224  fModules_.clear();
225  fDetHits_ = 0;
226  ftotalevents_ = 0;
227  fRun0_ = 99999999;
228  fRun1_ = 0;
229  fLS0_ = 99999999;
230  fLS1_ = 0;
231 }
SiPixelDetectorStatus::fDetHits_
unsigned long int fDetHits_
Definition: SiPixelDetectorStatus.h:86
SiPixelDetectorStatus::fLS1_
int fLS1_
Definition: SiPixelDetectorStatus.h:78
SiPixelDetectorStatus::fLS0_
int fLS0_
Definition: SiPixelDetectorStatus.h:78
SiPixelDetectorStatus::resetDetectorStatus
void resetDetectorStatus()
Definition: SiPixelDetectorStatus.cc:223
PixelFEDChannel
Definition: PixelFEDChannel.h:6
hfClusterShapes_cfi.hits
hits
Definition: hfClusterShapes_cfi.py:5
SiPixelDetectorStatus::getFEDerror25Rocs
std::map< int, std::vector< int > > getFEDerror25Rocs()
Definition: SiPixelDetectorStatus.cc:127
SiPixelDetectorStatus::getModule
SiPixelModuleStatus * getModule(int detid)
Definition: SiPixelDetectorStatus.cc:159
SiPixelDetectorStatus::begin
std::map< int, SiPixelModuleStatus >::iterator begin()
Definition: SiPixelDetectorStatus.cc:150
SiPixelDetectorStatus::SiPixelDetectorStatus
SiPixelDetectorStatus()
Definition: SiPixelDetectorStatus.cc:14
SiPixelDetectorStatus::findModule
bool findModule(int detid)
Definition: SiPixelDetectorStatus.cc:166
SiPixelRocStatus
Definition: SiPixelRocStatus.h:5
SiPixelDetectorStatus
Definition: SiPixelDetectorStatus.h:11
SiPixelDetectorStatus::dumpToFile
void dumpToFile(std::ofstream &outFile)
Definition: SiPixelDetectorStatus.cc:85
SiPixelDetectorStatus::addModule
void addModule(int detid, int nrocs)
Definition: SiPixelDetectorStatus.cc:102
SiPixelDetectorStatus::fillDIGI
void fillDIGI(int detid, int roc)
Definition: SiPixelDetectorStatus.cc:114
SiPixelDetectorStatus::nmodules
int nmodules()
Definition: SiPixelDetectorStatus.cc:156
corrVsCorr.filename
filename
Definition: corrVsCorr.py:123
SiPixelDetectorStatus::~SiPixelDetectorStatus
~SiPixelDetectorStatus()
Definition: SiPixelDetectorStatus.cc:20
SiPixelModuleStatus
Definition: SiPixelModuleStatus.h:10
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
SiPixelDetectorStatus::getNevents
unsigned long int getNevents()
Definition: SiPixelDetectorStatus.h:48
SiPixelDetectorStatus::fillFEDerror25
void fillFEDerror25(int detid, PixelFEDChannel ch)
Definition: SiPixelDetectorStatus.cc:120
a
double a
Definition: hdecay.h:119
SiPixelModuleStatus::getRoc
SiPixelRocStatus * getRoc(int i)
get a ROC
Definition: SiPixelModuleStatus.cc:95
SiPixelDetectorStatus::perRocDigiOccVar
double perRocDigiOccVar()
Definition: SiPixelDetectorStatus.cc:187
SiPixelDetectorStatus::end
std::map< int, SiPixelModuleStatus >::iterator end()
Definition: SiPixelDetectorStatus.cc:153
SiPixelDetectorStatus::updateDetectorStatus
void updateDetectorStatus(SiPixelDetectorStatus newData)
Definition: SiPixelDetectorStatus.cc:207
SiPixelDetectorStatus.h
SiPixelDetectorStatus::ftotalevents_
unsigned long int ftotalevents_
Definition: SiPixelDetectorStatus.h:83
SiPixelDetectorStatus::readFromFile
void readFromFile(std::string filename)
Definition: SiPixelDetectorStatus.cc:23
SiPixelDetectorStatus::fModules_
std::map< int, SiPixelModuleStatus > fModules_
Definition: SiPixelDetectorStatus.h:75
SiPixelDetectorStatus::fRun0_
int fRun0_
Definition: SiPixelDetectorStatus.h:80
DeadROCCounter.nrocs
nrocs
Definition: DeadROCCounter.py:57
SiPixelModuleStatus::updateModuleDIGI
void updateModuleDIGI(int roc, unsigned int nhits)
combine new data to update(topup) module status
Definition: SiPixelModuleStatus.cc:98
PixelMapPlotter.roc
roc
Definition: PixelMapPlotter.py:498
SiPixelDetectorStatus::perRocDigiOcc
double perRocDigiOcc()
Definition: SiPixelDetectorStatus.cc:174
SiPixelDetectorStatus::fRun1_
int fRun1_
Definition: SiPixelDetectorStatus.h:80
SiPixelModuleStatus::nrocs
int nrocs()
Definition: SiPixelModuleStatus.cc:40
SiPixelDetectorStatus::digiOccDET
unsigned long int digiOccDET()
Definition: SiPixelDetectorStatus.h:45
SiPixelModuleStatus::setNrocs
void setNrocs(int iroc)
Definition: SiPixelModuleStatus.cc:44