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: 2012/03/13 09:00:51 $
6  * $Revision: 1.14 $
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 {
36  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
37  << "[DTBlockedROChannelsTest]: Constructor";
38 
39  // prescale on the # of LS to update the test
40  prescaleFactor = ps.getUntrackedParameter<int>("diagnosticPrescale", 1);
41 
42  offlineMode = ps.getUntrackedParameter<bool>("offlineMode", true);
43 }
44 
45 
46 
48  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
49  << "DataIntegrityTest: analyzed " << nupdates << " updates";
50 }
51 
52 
53 
54 // book histos
56  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
57  << "[DTBlockedROChannelsTest]: BeginJob";
58 
59  nupdates = 0;
60  run=0;
61 
63 
64  // book the summary histogram
65  dbe->setCurrentFolder("DT/00-ROChannels");
66  summaryHisto = dbe->book2D("ROChannelSummary","Summary Blocked RO Channels",12,1,13,5,-2,3);
67  summaryHisto->setAxisTitle("Sector",1);
68  summaryHisto->setAxisTitle("Wheel",2);
69 
70  for(int wheel = -2; wheel != 3; ++wheel) {
71  stringstream namestream; namestream << "ROChannelSummary_W" << wheel;
72  stringstream titlestream; titlestream << "Blocked RO Channels (Wh " << wheel << ")";
73  wheelHitos[wheel] = dbe->book2D(namestream.str().c_str(),titlestream.str().c_str(),12,1,13,4,1,5);
74  wheelHitos[wheel]->setAxisTitle("Sector",1);
75  wheelHitos[wheel]->setBinLabel(1,"MB1",2);
76  wheelHitos[wheel]->setBinLabel(2,"MB2",2);
77  wheelHitos[wheel]->setBinLabel(3,"MB3",2);
78  wheelHitos[wheel]->setBinLabel(4,"MB4",2);
79  }
80 
81  if(!offlineMode) {
82  hSystFractionVsLS = new DTTimeEvolutionHisto(dbe, "EnabledROChannelsVsLS", "% RO channels",
83  500, 5, true, 3);
84  }
85 
86 }
87 
88 
89 
90 
91 void DTBlockedROChannelsTest::beginRun(const Run& run, const EventSetup& context) {
92  // get the RO mapping
93  context.get<DTReadOutMappingRcd>().get(mapping);
94 
95  // fill the map of the robs per chamber
96  for(int dduId = FEDNumbering::MINDTFEDID; dduId<=FEDNumbering::MAXDTFEDID; ++dduId) { //loop over DDUs
97  for(int ros = 1; ros != 13; ++ros) { // loop over ROSs
98  for(int rob = 1; rob != 26; ++rob) { // loop over ROBs
99  int wheel = 0;
100  int station = 0;
101  int sector = 0;
102  int dummy = 0;
103  if(!mapping->readOutToGeometry(dduId,ros,rob-1,0,2,wheel,station,sector,dummy,dummy,dummy) ||
104  !mapping->readOutToGeometry(dduId,ros,rob-1,0,16,wheel,station,sector,dummy,dummy,dummy)) {
105  DTChamberId chId(wheel, station, sector);
106  if(chamberMap.find(chId) == chamberMap.end()) {
107  chamberMap[chId] = DTRobBinsMap(dduId, ros, dbe);
108  chamberMap[chId].addRobBin(rob);
109  }
110  chamberMap[chId].addRobBin(rob);
111  } else {
112  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
113  << "[DTRobBinsMap] FED: " << dduId << " ROS " << ros << " ROB: " << rob-1
114  << " not in the mapping!" << endl;
115  }
116  }
117  }
118  }
119  // loop over all chambers and remove the init flag
120  for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
121  chAndRobs != chamberMap.end(); ++chAndRobs) {
122  chAndRobs->second.init(false);
123  }
124 }
125 
126 
127 
129  EventSetup const& context) {
130  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
131  <<"[DTBlockedROChannelsTest]: Begin of LS transition";
132 
133  // Get the run number
134  run = lumiSeg.run();
135  nevents = 0;
136 
137  // // loop over all chambers and read the values at the beginning of the LS
138  // for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
139  // chAndRobs != chamberMap.end(); ++chAndRobs) {
140  // (*chAndRobs).second.readNewValues();
141  // }
142 
143 }
144 
145 
146 
147 void DTBlockedROChannelsTest::analyze(const Event& e, const EventSetup& context){
148  // count the analyzed events
149  nevents++;
150  if(nevents%1000 == 0)
151  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
152  << "[DTBlockedROChannelsTest]: "<<nevents<<" events";
153 }
154 
155 
156 
158 
159  // counts number of lumiSegs
160  nLumiSegs = lumiSeg.id().luminosityBlock();
161 
162  // prescale factor
163  if (nLumiSegs%prescaleFactor != 0 || offlineMode) return;
164 
165  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
166  <<"[DTBlockedROChannelsTest]: End of LS " << nLumiSegs << ". Client called in online mode, performing client operations";
168 
169  // counts number of updats
170  nupdates++;
171 
172 }
173 
174 
176 
177  // skip empty LSs
178 
179  if(nevents == 0) { // hack to work also in offline DQM
180  MonitorElement *procEvt = dbe->get("DT/EventInfo/processedEvents");
181  if(procEvt != 0) {
182  int procEvents = procEvt->getIntValue();
183  nevents = procEvents - neventsPrev;
184  neventsPrev = procEvents;
185  }
186  }
187 
188  double totalPerc = prevTotalPerc;
189  // check again!
190  if(nevents != 0) { // skip the computation if no events in the last LS
191 
192  // reset the histos
193  summaryHisto->Reset();
194  for(int wheel = -2; wheel != 3; ++wheel) {
195  wheelHitos[wheel]->Reset();
196  }
197 
198  totalPerc = 0.;
199 
200  // loop over all chambers and fill the wheel plots
201  for(map<DTChamberId, DTRobBinsMap>::iterator chAndRobs = chamberMap.begin();
202  chAndRobs != chamberMap.end(); ++chAndRobs) {
203  DTChamberId chId = (*chAndRobs).first;
204  double scale = 1.;
205  int sectorForPlot = chId.sector();
206  if(sectorForPlot == 13 || (sectorForPlot == 4 && chId.station() ==4)) {
207  sectorForPlot = 4;
208  scale = 0.5;
209  } else if(sectorForPlot == 14 || (sectorForPlot == 10 && chId.station() ==4)) {
210  sectorForPlot = 10;
211  scale = 0.5;
212  }
213 
214  // NOTE: can be called only ONCE per event per each chamber
215  double chPercent = (*chAndRobs).second.getChamberPercentage();
216  wheelHitos[chId.wheel()]->Fill(sectorForPlot, chId.station(),
217  scale*chPercent);
218  totalPerc += chPercent*scale*1./240.; // CB has to be 240 as double stations are taken into account by scale factor
219  // if(chPercent != 1.) {
220  // cout << "Ch: " << (*chAndRobs).first << endl;
221  // cout << " perc: " << chPercent << endl;
222  // }
223  // Fill the summary
224  summaryHisto->Fill(sectorForPlot, chId.wheel(), 0.25*scale*chPercent);
225  }
226  }
227 
228  // commented out since trend plots need to be updated in by lumi certification
229  // // this part is executed even if no events were processed in order to include the last LS
230  // if(offlineMode) { // save the results in a map and draw them in the end-run
231  // if(resultsPerLumi.size() == 0) { // the first 2 LS are analyzed together
232  // // cout << "LS: " << nLumiSegs << " total %: " << totalPerc << endl;
233  // resultsPerLumi[nLumiSegs] = totalPerc;
234  // } else {
235  // // cout << "LS: " << nLumiSegs << " total %: " << prevTotalPerc << endl;
236  // resultsPerLumi[nLumiSegs] = prevTotalPerc;
237  // }
238  // prevTotalPerc = totalPerc;
239  // prevNLumiSegs = nLumiSegs;
240 
241  // } else { // directly fill the histo
242  // hSystFractionVsLS->accumulateValueTimeSlot(totalPerc);
243  // hSystFractionVsLS->updateTimeSlot(nLumiSegs, nevents);
244  // prevTotalPerc = totalPerc;
245  // }
246 
247  if(!offlineMode) { // fill trend histo only in online
250  prevTotalPerc = totalPerc;
251  }
252 
253 }
254 
255 
256 
258  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
259  <<"[DTBlockedROChannelsTest] endjob called!";
260 }
261 
262 
263 
264 
266 
267  if (offlineMode) {
268  LogTrace("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
269  <<"[DTBlockedROChannelsTest] endRun called. Client called in offline mode, performing operations.";
271  }
272  // commented out since trend plots need to be updated in by lumi certification
273  // if(offlineMode) {
274  // // fill a trend plot based on the results stored in the map
275  // float fBin = resultsPerLumi.begin()->first;
276  // float lBin = resultsPerLumi.rbegin()->first;
277  // dbe->setCurrentFolder("DT/00-ROChannels");
278 
279  // // MonitorElement* hSystFractionVsLS = dbe->book1D("EnabledROChannelsVsLS", "% RO channels vs LS", nBins,fBin,lBin);
280  // hSystFractionVsLS = new DTTimeEvolutionHisto(dbe, "EnabledROChannelsVsLS", "% RO channels",
281  // (int)lBin-(int)fBin, fBin, 1, false, 2);
282 
283  // for(map<int, double>::const_iterator bin = resultsPerLumi.begin();
284  // bin != resultsPerLumi.end(); ++bin) {
285  // hSystFractionVsLS->setTimeSlotValue((*bin).second, (*bin).first);
286  // }
287  // }
288 }
289 
290 
291 
292 int DTBlockedROChannelsTest::readOutToGeometry(int dduId, int ros, int& wheel, int& sector){
293 
294  int dummy;
295  return mapping->readOutToGeometry(dduId,ros,2,2,2,wheel,dummy,sector,dummy,dummy,dummy);
296 
297 }
298 
299 
300 
301 
302 
303 DTBlockedROChannelsTest::DTRobBinsMap::DTRobBinsMap(const int fed, const int ros, const DQMStore* dbe) : rosBin(ros),
304  init_(true),
305  rosValue(0)
306 {
307 
308  // get the pointer to the corresondig histo
309  stringstream mename; mename << "DT/00-DataIntegrity/FED" << fed << "/ROS" << ros
310  << "/FED" << fed << "_ROS" << ros << "_ROSError";
311  rosHName = mename.str();
312 
313  stringstream whname; whname << "DT/00-DataIntegrity/FED" << fed
314  << "/FED" << fed << "_ROSStatus";
315  dduHName = whname.str();
316 
317  meROS = dbe->get(rosHName);
318  meDDU = dbe->get(dduHName);
319 
320  theDbe = dbe;
321 }
322 
324  meROS(0),
325  meDDU(0){}
326 
328 
329 
330 
331  // add a rob to the set of robs
333  robsAndValues[robBin] = getValueRobBin(robBin);
334  }
335 
336 
337 
338 
340  if (init_)
341  return 0;
342  int value = 0;
343  if(meROS) {
344  value += (int)meROS->getBinContent(9,robBin);
345  value += (int)meROS->getBinContent(11,robBin);
346  }
347  return value;
348  }
349 
350 
351 
352 
354  int value = 0;
355  if(meDDU) {
356  value += (int)meDDU->getBinContent(2,rosBin);
357  value += (int)meDDU->getBinContent(10,rosBin);
358  }
359  return value;
360 }
361 
362 
363 
364 
366  // check that this is a valid ROB for this map (= it has been added!)
367  if(robsAndValues.find(robBin) == robsAndValues.end()) {
368  LogWarning("DTDQM|DTRawToDigi|DTMonitorClient|DTBlockedROChannelsTest")
369  << "[DTRobBinsMap]***Error: ROB: " << robBin << " is not valid" << endl;
370  return false;
371  }
372 
373  int newValue = getValueRobBin(robBin);
374  if(newValue > robsAndValues[robBin]) {
375  robsAndValues[robBin] = newValue;
376  return true;
377  }
378  return false;
379 }
380 
381 
382 
383 
385  meROS = theDbe->get(rosHName);
386  meDDU = theDbe->get(dduHName);
387  int nChangedROBs = 0;
388 
389  // check if ros status has changed
390  int newValue = getValueRos();
391  if(newValue > rosValue) {
392  rosValue= newValue;
393  return 0.;
394  }
395 
396  for(map<int, int>::const_iterator robAndValue = robsAndValues.begin();
397  robAndValue != robsAndValues.end(); ++robAndValue) {
398  if(robChanged((*robAndValue).first)) nChangedROBs++;
399  }
400  return 1.-((double)nChangedROBs/(double)robsAndValues.size());
401 }
402 
403 
405  meROS = theDbe->get(rosHName);
406  meDDU = theDbe->get(dduHName);
407 
408  rosValue = getValueRos();
409  for(map<int, int>::const_iterator robAndValue = robsAndValues.begin();
410  robAndValue != robsAndValues.end(); ++robAndValue) {
411  robChanged((*robAndValue).first);
412  }
413 }
414 
415 
416 
417 
418 // 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:1468
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:845
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:429
Definition: Run.h:33