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 
13 
14 using namespace std;
15 
16 
17 // ----------------------------------------------------------------------
18 SiPixelDetectorStatus::SiPixelDetectorStatus(): fLS0(99999999), fLS1(0), fRun0(99999999), fRun1(0), fDetHits(0) {
19 
20  fDetAverage = fDetSigma = 0.;
21 
22  fTime0 = fTime1 = 0;
23  fNevents = 0;
24 
25 }
26 
27 // ----------------------------------------------------------------------
29 
30 }
31 
32 
33 // ----------------------------------------------------------------------
35 
36  ifstream INS;
37  string sline;
38  INS.open(filename.c_str());
39 
40  int oldDetId(-1);
41  int detid(0), roc(0), dc(0), hits(0), nroc(0);
42  SiPixelModuleStatus *pMod(nullptr);
43  bool readOK(false);
44  while (getline(INS, sline)) {
45 
46  if (string::npos != sline.find("# SiPixelDetectorStatus START")) {
47  readOK = true;
48  continue;
49  }
50  if (!readOK) continue;
51 
52  if (string::npos != sline.find("# SiPixelDetectorStatus END")) {
53  pMod->setNrocs(nroc+1);
54  break;
55  }
56 
57  if (sline.find("# SiPixelDetectorStatus for LS") != string::npos) {
58  sscanf(sline.c_str(), "# SiPixelDetectorStatus for LS %d .. %d", &fLS0, &fLS1);
59  continue;
60  }
61  if (sline.find("# SiPixelDetectorStatus for run") != string::npos) {
62  sscanf(sline.c_str(), "# SiPixelDetectorStatus for run %d .. %d", &fRun0, &fRun1);
63  continue;
64  }
65  if (sline.find("# SiPixelDetectorStatus total hits = ") != string::npos) {
66  sscanf(sline.c_str(), "# SiPixelDetectorStatus total hits = %ld", &fDetHits);
67  continue;
68  }
69 
70  sscanf(sline.c_str(), "%d %d %d %d", &detid, &roc, &dc, &hits);
71  if (roc > nroc) nroc = roc;
72  if (detid != oldDetId) {
73  if (pMod) {
74  pMod->setNrocs(nroc+1);
75  }
76 
77  oldDetId = detid;
78  if (nullptr == getModule(detid)) {
79  addModule(detid,nroc+1);
80  }
81 
82  pMod = getModule(detid);
83  nroc = 0;
84  }
85  if (pMod) {
86  fDetHits += hits;
87  pMod->updateModuleDIGI(roc, dc, hits);
88  }
89 
90  }
91 
92  INS.close();
93 
94 }
95 
96 
97 // ----------------------------------------------------------------------
99 
100  ofstream OD(filename.c_str());
101  OD << "# SiPixelDetectorStatus START" << endl;
102  OD << "# SiPixelDetectorStatus for LS " << fLS0 << " .. " << fLS1 << endl;
103  OD << "# SiPixelDetectorStatus for run " << fRun0 << " .. " << fRun1 << endl;
104  OD << "# SiPixelDetectorStatus total hits = " << fDetHits << endl;
105  map<int, SiPixelModuleStatus>::iterator itEnd = end();
106  for (map<int, SiPixelModuleStatus>::iterator it = begin(); it != itEnd; ++it) {
107  for (int iroc = 0; iroc < it->second.nrocs(); ++iroc) {
108  for (int idc = 0; idc < 26; ++idc) {
109  OD << Form("%10d %2d %2d %3d", it->first, iroc, idc, int(it->second.getRoc(iroc)->digiOccDC(idc))) << endl;
110  }
111  }
112  }
113  OD << "# SiPixelDetectorStatus END" << endl;
114  OD.close();
115 
116 }
117 
118 
119 // ----------------------------------------------------------------------
120 void SiPixelDetectorStatus::addModule(int detid, int nrocs) {
121  SiPixelModuleStatus a(detid, nrocs);
122  fModules.insert(make_pair(detid, a));
123 }
124 // ----------------------------------------------------------------------
126  fModules.insert(make_pair(detid, a));
127 }
128 
129 
130 // ----------------------------------------------------------------------
131 void SiPixelDetectorStatus::fillDIGI(int detid, int roc, int idc) {
132  ++fDetHits;
133  fModules[detid].fillDIGI(roc, idc);
134 }
135 
136 // ----------------------------------------------------------------------
138 
139  if (fModules.find(detid) != fModules.end()){
140  fModules[detid].fillStuckTBM(ch,time);
141  }
142 
143 }
144 
145 // stuck TBM effected ROCs in for each module
146 std::map<int, std::vector<int>> SiPixelDetectorStatus::getStuckTBMsRocs(){
147 
148  std::map<int, std::vector<int>> badRocLists_;
149 
150  std::map<int, SiPixelModuleStatus>::iterator itModEnd = end();
151  for (std::map<int, SiPixelModuleStatus>::iterator itMod = begin(); itMod != itModEnd; ++itMod) {
152 
153  int detid = itMod->first;
154  // stuck TBM effected ROCs in a given module
155  std::vector<int> list;
156  SiPixelModuleStatus modStatus = itMod->second;
157  for (int iroc = 0; iroc < modStatus.nrocs(); ++iroc) {
158 
159  SiPixelRocStatus* roc = modStatus.getRoc(iroc);
160  if(roc->isStuckTBM()){
161  list.push_back(iroc);
162  }
163  badRocLists_[detid]=list;
164  }
165 
166  }
167 
168  return badRocLists_;
169 }
170 
171 // ----------------------------------------------------------------------
172 map<int, SiPixelModuleStatus>::iterator SiPixelDetectorStatus::begin() {
173  return fModules.begin();
174 }
175 
176 // ----------------------------------------------------------------------
177 //map<int, SiPixelModuleStatus>::iterator SiPixelDetectorStatus::next() {
178 // return fNext++;
179 //}
180 
181 // ----------------------------------------------------------------------
182 std::map<int, SiPixelModuleStatus>::iterator SiPixelDetectorStatus::end() {
183  return fModules.end();
184 }
185 
186 // ----------------------------------------------------------------------
188  return static_cast<int>(fModules.size());
189 }
190 
191 // ----------------------------------------------------------------------
193 
194  if (fModules.find(detid) == fModules.end()) {
195  return nullptr;
196  }
197  return &(fModules[detid]);
198 }
199 
201 
202  if (fModules.find(detid) == fModules.end())
203  return false;
204  else
205  return true;
206 
207 }
208 
209 // ----------------------------------------------------------------------
211 
212  fDetAverage = fDetSigma = 0;
213  unsigned long int ave(0), sig(0);
214  int nrocs(0);
215  map<int, SiPixelModuleStatus>::iterator itEnd = end();
216  for (map<int, SiPixelModuleStatus>::iterator it = begin(); it != itEnd; ++it) {
217  unsigned long int inc = it->second.digiOccMOD();
218  ave += inc;
219  nrocs += it->second.nrocs();
220  }
221  fDetAverage = (1.0*ave)/nrocs;
222 
223  for (map<int, SiPixelModuleStatus>::iterator it = begin(); it != itEnd; ++it) {
224  unsigned long int inc = it->second.digiOccMOD();
225  sig += (fDetAverage - inc) * (fDetAverage - inc);
226  }
227 
228  fDetSigma = sig/(nrocs - 1);
229  fDetSigma = TMath::Sqrt(fDetSigma);
230 
231 }
232 
233 // combine status from different data (coming from different run/lumi)
235 
236  // loop over new data status
237  std::map<int, SiPixelModuleStatus>::iterator itEnd = newData.end();
238  for (map<int, SiPixelModuleStatus>::iterator it = newData.begin(); it != itEnd; ++it) {
239 
240  int detid = it->first;
241  if(fModules.find(detid) != fModules.end()){// if the detid is in the module lists
242  fModules[detid].updateModuleStatus( *(newData.getModule(detid)) );
243  }
244 
245  }
246 
247  fDetHits = fDetHits + newData.digiOccDET();
248  fNevents = fNevents + newData.getNevents();
249 
250 }
251 
253 
255 
256  // loop over current module status
257  std::map<int, SiPixelModuleStatus>::iterator itEnd = end();
258  for (map<int, SiPixelModuleStatus>::iterator it = begin(); it != itEnd; ++it) {
259 
260  int detid = it->first;
261  combine.addModule(detid, fModules[detid]);
262 
263  if(newData.findModule(detid)){ // the detid in current data is also in new data
264  // then update the module status
265  SiPixelModuleStatus* moduleStatus = combine.getModule(detid);
266  moduleStatus->updateModuleStatus(*(newData.getModule(detid)));
267  }
268  }
269 
270  return combine;
271 
272 }
void addModule(int detid, int nrocs)
void updateDetectorStatus(SiPixelDetectorStatus newData)
unsigned long int digiOccDET()
std::map< int, SiPixelModuleStatus > fModules
std::map< int, std::vector< int > > getStuckTBMsRocs()
std::map< int, SiPixelModuleStatus >::iterator begin()
unsigned long int fDetHits
unsigned long int fNevents
void readFromFile(std::string filename)
static type combine(const A &_1, const B &_2)
Definition: Factorize.h:187
SiPixelDetectorStatus combineDetectorStatus(SiPixelDetectorStatus newData)
std::map< int, SiPixelModuleStatus >::iterator end()
void updateModuleDIGI(int roc, int dc, unsigned long int nhits)
combine new data to update(topup) module status
void dumpToFile(std::string filename)
double a
Definition: hdecay.h:121
unsigned long int getNevents()
void fillStuckTBM(int detid, PixelFEDChannel ch, std::time_t time)
SiPixelRocStatus * getRoc(int i)
get a ROC
void updateModuleStatus(SiPixelModuleStatus newData)
SiPixelModuleStatus * getModule(int detid)
void fillDIGI(int detid, int roc, int idc)
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