CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DTBlockedROChannelsTest.cc
Go to the documentation of this file.
1 
2 /*
3  * \file DTBlockedROChannelsTest.cc
4  *
5  * $Date: 2010/02/25 00:29:30 $
6  * $Revision: 1.11 $
7  * \author G. Cerminara - University and INFN Torino
8  *
9  */
10 
12 
13 //Framework
22 #include <iostream>
23 #include <string>
24 
25 
26 using namespace std;
27 using namespace edm;
28 
29 
31  neventsPrev(0),
32  prevNLumiSegs(0),
33  prevTotalPerc(0),
34  hSystFractionVsLS(0) {
35  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
36  << "[DTBlockedROChannelsTest]: Constructor";
37 
38  // prescale on the # of LS to update the test
39  prescaleFactor = ps.getUntrackedParameter<int>("diagnosticPrescale", 1);
40 
41  offlineMode = ps.getUntrackedParameter<bool>("offlineMode", true);
42 }
43 
44 
45 
47  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
48  << "DataIntegrityTest: analyzed " << nupdates << " updates";
49 }
50 
51 
52 
53 // book histos
55  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
56  << "[DTBlockedROChannelsTest]: BeginJob";
57 
58  nupdates = 0;
59  run=0;
60 
62 
63  // book the summary histogram
64  dbe->setCurrentFolder("DT/00-ROChannels");
65  summaryHisto = dbe->book2D("ROChannelSummary","Summary Blocked RO Channels",12,1,13,5,-2,3);
66  summaryHisto->setAxisTitle("Sector",1);
67  summaryHisto->setAxisTitle("Wheel",2);
68 
69  for(int wheel = -2; wheel != 3; ++wheel) {
70  stringstream namestream; namestream << "ROChannelSummary_W" << wheel;
71  stringstream titlestream; titlestream << "Blocked RO Channels (Wh " << wheel << ")";
72  wheelHitos[wheel] = dbe->book2D(namestream.str().c_str(),titlestream.str().c_str(),12,1,13,4,1,5);
73  wheelHitos[wheel]->setAxisTitle("Sector",1);
74  wheelHitos[wheel]->setBinLabel(1,"MB1",2);
75  wheelHitos[wheel]->setBinLabel(2,"MB2",2);
76  wheelHitos[wheel]->setBinLabel(3,"MB3",2);
77  wheelHitos[wheel]->setBinLabel(4,"MB4",2);
78  }
79 
80  if(!offlineMode) {
81  hSystFractionVsLS = new DTTimeEvolutionHisto(dbe, "EnabledROChannelsVsLS", "% RO channels",
82  500, 5, true, 3);
83  }
84 
85 }
86 
87 
88 
89 
90 void DTBlockedROChannelsTest::beginRun(const Run& run, const EventSetup& context) {
91  // get the RO mapping
92  context.get<DTReadOutMappingRcd>().get(mapping);
93 
94  // fill the map of the robs per chamber
95  for(int dduId = FEDNumbering::MINDTFEDID; dduId<=FEDNumbering::MAXDTFEDID; ++dduId) { //loop over DDUs
96  for(int ros = 1; ros != 13; ++ros) { // loop over ROSs
97  for(int rob = 1; rob != 26; ++rob) { // loop over ROBs
98  int wheel = 0;
99  int station = 0;
100  int sector = 0;
101  int dummy = 0;
102  if(!mapping->readOutToGeometry(dduId,ros,rob-1,0,2,wheel,station,sector,dummy,dummy,dummy) ||
103  !mapping->readOutToGeometry(dduId,ros,rob-1,0,16,wheel,station,sector,dummy,dummy,dummy)) {
104  DTChamberId chId(wheel, station, sector);
105  if(chamberMap.find(chId) == chamberMap.end()) {
106  chamberMap[chId] = DTRobBinsMap(dduId, ros, dbe);
107  chamberMap[chId].addRobBin(rob);
108  }
109  chamberMap[chId].addRobBin(rob);
110  } else {
111  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
112  << "[DTRobBinsMap] FED: " << dduId << " ROS " << ros << " ROB: " << rob-1
113  << " not in the mapping!" << endl;
114  }
115  }
116  }
117  }
118 }
119 
120 
121 
123  EventSetup const& context) {
124  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
125  <<"[DTBlockedROChannelsTest]: Begin of LS transition";
126 
127  // Get the run number
128  run = lumiSeg.run();
129  nevents = 0;
130 
131 // // loop over all chambers and read the values at the beginning of the LS
132 // for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
133 // chAndRobs != chamberMap.end(); ++chAndRobs) {
134 // (*chAndRobs).second.readNewValues();
135 // }
136 
137 }
138 
139 
140 
141 void DTBlockedROChannelsTest::analyze(const Event& e, const EventSetup& context){
142  // count the analyzed events
143  nevents++;
144  if(nevents%1000 == 0)
145  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
146  << "[DTBlockedROChannelsTest]: "<<nevents<<" events";
147 }
148 
149 
150 
152 
153  // counts number of lumiSegs
154  nLumiSegs = lumiSeg.id().luminosityBlock();
155 
156  // prescale factor
157  if (nLumiSegs%prescaleFactor != 0 || offlineMode) return;
158 
159  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
160  <<"[DTBlockedROChannelsTest]: End of LS " << nLumiSegs << ". Client called in online mode, performing client operations";
162 
163  // counts number of updats
164  nupdates++;
165 
166 }
167 
168 
170 
171  // skip empty LSs
172 
173  if(nevents == 0) { // hack to work also in offline DQM
174  MonitorElement *procEvt = dbe->get("DT/EventInfo/processedEvents");
175  if(procEvt != 0) {
176  int procEvents = procEvt->getIntValue();
177  nevents = procEvents - neventsPrev;
178  neventsPrev = procEvents;
179  }
180  }
181 
182  double totalPerc = prevTotalPerc;
183  // check again!
184  if(nevents != 0) { // skip the computation if no events in the last LS
185 
186  // reset the histos
187  summaryHisto->Reset();
188  for(int wheel = -2; wheel != 3; ++wheel) {
189  wheelHitos[wheel]->Reset();
190  }
191 
192  totalPerc = 0.;
193 
194  // loop over all chambers and fill the wheel plots
195  for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
196  chAndRobs != chamberMap.end(); ++chAndRobs) {
197  DTChamberId chId = (*chAndRobs).first;
198  double scale = 1.;
199  int sectorForPlot = chId.sector();
200  if(sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() ==4)) {
201  sectorForPlot = 4;
202  scale = 0.5;
203  } else if(sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() ==4)) {
204  sectorForPlot = 10;
205  scale = 0.5;
206  }
207 
208  // NOTE: can be called only ONCE per event per each chamber
209  double chPercent = (*chAndRobs).second.getChamberPercentage();
210  wheelHitos[chId.wheel()]->Fill(sectorForPlot, chId.station(),
211  scale*chPercent);
212  totalPerc += chPercent*scale*1./250.;
213 // if(chPercent != 1.) {
214 // cout << "Ch: " << (*chAndRobs).first << endl;
215 // cout << " perc: " << chPercent << endl;
216 // }
217  // Fill the summary
218  summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25*scale*chPercent);
219  }
220  }
221 
222 // commented out since trend plots need to be updated in by lumi certification
223 // // this part is executed even if no events were processed in order to include the last LS
224 // if(offlineMode) { // save the results in a map and draw them in the end-run
225 // if(resultsPerLumi.size() == 0) { // the first 2 LS are analyzed together
226 // // cout << "LS: " << nLumiSegs << " total %: " << totalPerc << endl;
227 // resultsPerLumi[nLumiSegs] = totalPerc;
228 // } else {
229 // // cout << "LS: " << nLumiSegs << " total %: " << prevTotalPerc << endl;
230 // resultsPerLumi[nLumiSegs] = prevTotalPerc;
231 // }
232 // prevTotalPerc = totalPerc;
233 // prevNLumiSegs = nLumiSegs;
234 
235 // } else { // directly fill the histo
236 // hSystFractionVsLS->accumulateValueTimeSlot(totalPerc);
237 // hSystFractionVsLS->updateTimeSlot(nLumiSegs, nevents);
238 // prevTotalPerc = totalPerc;
239 // }
240 
241  if(!offlineMode) { // fill trend histo only in online
244  prevTotalPerc = totalPerc;
245  }
246 
247 }
248 
249 
250 
252  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
253  <<"[DTBlockedROChannelsTest] endjob called!";
254 }
255 
256 
257 
258 
260 
261  if (offlineMode) {
262  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
263  <<"[DTBlockedROChannelsTest] endRun called. Client called in offline mode, performing operations.";
265  }
266 // commented out since trend plots need to be updated in by lumi certification
267 // if(offlineMode) {
268 // // fill a trend plot based on the results stored in the map
269 // float fBin = resultsPerLumi.begin()->first;
270 // float lBin = resultsPerLumi.rbegin()->first;
271 // dbe->setCurrentFolder("DT/00-ROChannels");
272 
273 // // MonitorElement* hSystFractionVsLS = dbe->book1D("EnabledROChannelsVsLS", "% RO channels vs LS", nBins,fBin,lBin);
274 // hSystFractionVsLS = new DTTimeEvolutionHisto(dbe, "EnabledROChannelsVsLS", "% RO channels",
275 // (int)lBin-(int)fBin, fBin, 1, false, 2);
276 
277 // for(map<int, double>::const_iterator bin = resultsPerLumi.begin();
278 // bin != resultsPerLumi.end(); ++bin) {
279 // hSystFractionVsLS->setTimeSlotValue((*bin).second, (*bin).first);
280 // }
281 // }
282 }
283 
284 
285 
286 int DTBlockedROChannelsTest::readOutToGeometry(int dduId, int ros, int& wheel, int& sector){
287 
288  int dummy;
289  return mapping->readOutToGeometry(dduId,ros,2,2,2,wheel,dummy,sector,dummy,dummy,dummy);
290 
291 }
292 
293 
294 
295 
296 
297 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap(const int fed, const int ros, const DQMStore* dbe) : rosBin(ros),
298  rosValue(0) {
299  // get the pointer to the corresondig histo
300  stringstream mename; mename << "DT/00-DataIntegrity/FED" << fed << "/ROS" << ros
301  << "/FED" << fed << "_ROS" << ros << "_ROSError";
302  rosHName = mename.str();
303 
304  stringstream whname; whname << "DT/00-DataIntegrity/FED" << fed
305  << "/FED" << fed << "_ROSStatus";
306  dduHName = whname.str();
307 
308  meROS = dbe->get(rosHName);
309  meDDU = dbe->get(dduHName);
310 
311  theDbe = dbe;
312 }
313 
314 
315 
316 
318  meDDU(0) {}
319 
320 
321 
323 
324 
325 
326 // add a rob to the set of robs
328  robsAndValues[robBin] = getValueRobBin(robBin);
329 }
330 
331 
332 
333 
335  int value = 0;
336  if(meROS) {
337  value += (int)meROS->getBinContent(9,robBin);
338  value += (int)meROS->getBinContent(11,robBin);
339  }
340  return value;
341 }
342 
343 
344 
345 
347  int value = 0;
348  if(meDDU) {
349  value += (int)meDDU->getBinContent(2,rosBin);
350  value += (int)meDDU->getBinContent(10,rosBin);
351  }
352  return value;
353 }
354 
355 
356 
357 
359  // check that this is a valid ROB for this map (= it has been added!)
360  if(robsAndValues.find(robBin) == robsAndValues.end()) {
361  LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
362  << "[DTRobBinsMap]***Error: ROB: " << robBin << " is not valid" << endl;
363  return false;
364  }
365 
366  int newValue = getValueRobBin(robBin);
367  if(newValue > robsAndValues[robBin]) {
368  robsAndValues[robBin] = newValue;
369  return true;
370  }
371  return false;
372 }
373 
374 
375 
376 
378  meROS = theDbe->get(rosHName);
379  meDDU = theDbe->get(dduHName);
380  int nChangedROBs = 0;
381 
382  // check if ros status has changed
383  int newValue = getValueRos();
384  if(newValue > rosValue) {
385  rosValue= newValue;
386  return 0.;
387  }
388 
389  for(map<int, int>::const_iterator robAndValue = robsAndValues.begin();
390  robAndValue != robsAndValues.end(); ++robAndValue) {
391  if(robChanged((*robAndValue).first)) nChangedROBs++;
392  }
393  return 1.-((double)nChangedROBs/(double)robsAndValues.size());
394 }
395 
396 
398  meROS = theDbe->get(rosHName);
399  meDDU = theDbe->get(dduHName);
400 
401  rosValue = getValueRos();
402  for(map<int, int>::const_iterator robAndValue = robsAndValues.begin();
403  robAndValue != robsAndValues.end(); ++robAndValue) {
404  robChanged((*robAndValue).first);
405  }
406 }
407 
408 
409 
410 
411 // FIXME: move to SealModule
LuminosityBlockID id() const
T getUntrackedParameter(std::string const &, T const &) const
DTTimeEvolutionHisto * hSystFractionVsLS
void accumulateValueTimeSlot(float value)
void beginRun(const edm::Run &run, const edm::EventSetup &c)
BeginRun.
std::map< DTChamberId, DTRobBinsMap > chamberMap
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void Fill(long long x)
std::map< int, MonitorElement * > wheelHitos
DTBlockedROChannelsTest(const edm::ParameterSet &ps)
Constructor.
RunNumber_t run() const
int nevents
MonitorElement * get(const std::string &path) const
get ME from full pathname (e.g. &quot;my/long/dir/my_histo&quot;)
Definition: DQMStore.cc:1270
int readOutToGeometry(int dduId, int rosNumber, int &wheel, int &sector)
edm::ESHandle< DTReadOutMapping > mapping
#define LogTrace(id)
int64_t getIntValue(void) const
const T & get() const
Definition: EventSetup.h:55
LuminosityBlockNumber_t luminosityBlock() const
void updateTimeSlot(int ls, int nEventsInLS)
void analyze(const edm::Event &e, const edm::EventSetup &c)
Analyze.
int sector() const
Definition: DTChamberId.h:63
void performClientDiagnostic()
DQM Client operations.
void endLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &c)
DQM Client Diagnostic in online mode.
int station() const
Return the station number.
Definition: DTChamberId.h:53
MonitorElement * book2D(const char *name, const char *title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Book 2D histogram.
Definition: DQMStore.cc:647
void endRun(edm::Run const &run, edm::EventSetup const &eSetup)
DQM Client Diagnostic in offline mode.
int wheel() const
Return the wheel number.
Definition: DTChamberId.h:47
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
void Reset(void)
reset ME (ie. contents, errors, etc)
void beginLuminosityBlock(edm::LuminosityBlock const &lumiSeg, edm::EventSetup const &context)
void setCurrentFolder(const std::string &fullpath)
Definition: DQMStore.cc:237
Definition: Run.h:31