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  fNevents = 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);
64  }
65 
66  oldDetId = detid;
67  if (getModule(detid) == nullptr) {
68  addModule(detid, nroc + 1);
69  }
70 
71  pMod = getModule(detid);
72  nroc = 0;
73  }
74  if (pMod) {
75  fDetHits += hits;
76  pMod->updateModuleDIGI(roc, hits);
77  }
78  }
79 
80  INS.close();
81 }
82 
83 // ----------------------------------------------------------------------
85  std::ofstream OD(filename.c_str());
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  for (int idc = 0; idc < 26; ++idc) {
96  OD << Form("%10d %2d %3d", it->first, iroc, int(it->second.getRoc(iroc)->digiOccROC())) << std::endl;
97  }
98  }
99  }
100  OD << "# SiPixelDetectorStatus END" << std::endl;
101  OD.close();
102 }
103 
104 // ----------------------------------------------------------------------
106  SiPixelModuleStatus a(detid, nrocs);
107  fModules.insert(std::make_pair(detid, a));
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 //map<int, SiPixelModuleStatus>::iterator SiPixelDetectorStatus::next() {
154 // return fNext++;
155 //}
156 
157 // ----------------------------------------------------------------------
158 std::map<int, SiPixelModuleStatus>::iterator SiPixelDetectorStatus::end() { return fModules.end(); }
159 
160 // ----------------------------------------------------------------------
161 int SiPixelDetectorStatus::nmodules() { return static_cast<int>(fModules.size()); }
162 
163 // ----------------------------------------------------------------------
165  if (fModules.find(detid) == fModules.end()) {
166  return nullptr;
167  }
168  return &(fModules[detid]);
169 }
170 
172  if (fModules.find(detid) == fModules.end())
173  return false;
174  else
175  return true;
176 }
177 
178 // ----------------------------------------------------------------------
180  unsigned long int ave(0);
181  int nrocs(0);
182  for (std::map<int, SiPixelModuleStatus>::iterator it = SiPixelDetectorStatus::begin();
184  ++it) {
185  unsigned long int inc = it->second.digiOccMOD();
186  ave += inc;
187  nrocs += it->second.nrocs();
188  }
189  return (1.0 * ave) / nrocs;
190 }
191 
193  double fDetAverage = SiPixelDetectorStatus::perRocDigiOcc();
194 
195  double sig = 0.0;
196  int nrocs(0);
197  for (std::map<int, SiPixelModuleStatus>::iterator it = SiPixelDetectorStatus::begin();
199  ++it) {
200  unsigned long int inc = it->second.digiOccMOD();
201  sig += (fDetAverage - inc) * (fDetAverage - inc);
202  nrocs += it->second.nrocs();
203  }
204 
205  double fDetSigma = sig / (nrocs - 1);
206  return TMath::Sqrt(fDetSigma);
207 }
208 
209 // combine status from different data (coming from different run/lumi)
211  // loop over new data status
212  for (std::map<int, SiPixelModuleStatus>::iterator it = newData.begin(); it != newData.end(); ++it) {
213  int detid = it->first;
214  if (fModules.find(detid) != fModules.end()) { // if the detid is in the module lists
215  fModules[detid].updateModuleStatus(*(newData.getModule(detid)));
216  } else {
217  fModules.insert(std::make_pair(detid, *(newData.getModule(detid))));
218  }
219  }
220 
221  fDetHits = fDetHits + newData.digiOccDET();
222  fNevents = fNevents + newData.getNevents();
223 }
void addModule(int detid, int nrocs)
void updateDetectorStatus(SiPixelDetectorStatus newData)
void updateModuleDIGI(int roc, unsigned int nhits)
combine new data to update(topup) module status
unsigned long int digiOccDET()
void fillFEDerror25(int detid, PixelFEDChannel ch)
std::map< int, std::vector< int > > getFEDerror25Rocs()
void fillDIGI(int detid, int roc)
std::map< int, SiPixelModuleStatus > fModules
unsigned long int fDetHits
unsigned long int fNevents
void readFromFile(std::string filename)
std::map< int, SiPixelModuleStatus >::iterator end()
std::map< int, SiPixelModuleStatus >::iterator begin()
void dumpToFile(std::string filename)
double a
Definition: hdecay.h:119
unsigned long int getNevents()
SiPixelRocStatus * getRoc(int i)
get a ROC
SiPixelModuleStatus * getModule(int detid)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run