CMS 3D CMS Logo

SiPixelRawDataErrorSource.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelMonitorRawData
4 // Class: SiPixelRawDataErrorSource
5 //
22 //
23 // Original Author: Andrew York
24 //
26 // Framework
29 // DQM Framework
33 
34 // Geometry
40 // DataFormats
48 //
49 #include <cstdlib>
50 #include <string>
51 
52 using namespace std;
53 using namespace edm;
54 
56  : conf_(iConfig),
57  src_(consumes<DetSetVector<SiPixelRawDataError>>(conf_.getParameter<edm::InputTag>("src"))),
58  saveFile(conf_.getUntrackedParameter<bool>("saveFile", false)),
59  isPIB(conf_.getUntrackedParameter<bool>("isPIB", false)),
60  slowDown(conf_.getUntrackedParameter<bool>("slowDown", false)),
61  reducedSet(conf_.getUntrackedParameter<bool>("reducedSet", false)),
62  modOn(conf_.getUntrackedParameter<bool>("modOn", true)),
63  ladOn(conf_.getUntrackedParameter<bool>("ladOn", false)),
64  bladeOn(conf_.getUntrackedParameter<bool>("bladeOn", false)),
65  isUpgrade(conf_.getUntrackedParameter<bool>("isUpgrade", false)) {
66  firstRun = true;
67  LogInfo("PixelDQM") << "SiPixelRawDataErrorSource::SiPixelRawDataErrorSource:"
68  " Got DQM BackEnd interface"
69  << endl;
70  topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
71  inputSourceToken_ = consumes<FEDRawDataCollection>(conf_.getUntrackedParameter<string>("inputSource", "source"));
72 }
73 
75  // do anything here that needs to be done at desctruction time
76  // (e.g. close files, deallocate resources etc.)
77  LogInfo("PixelDQM") << "SiPixelRawDataErrorSource::~SiPixelRawDataErrorSource: Destructor" << endl;
78 }
79 
81  LogInfo("PixelDQM") << " SiPixelRawDataErrorSource::beginRun - Initialisation ... " << std::endl;
82  LogInfo("PixelDQM") << "Mod/Lad/Blade " << modOn << "/" << ladOn << "/" << bladeOn << std::endl;
83 
84  if (firstRun) {
85  eventNo = 0;
86 
87  firstRun = false;
88  }
89 
90  // Build map
91  buildStructure(iSetup);
92 }
93 
95  edm::Run const &,
96  edm::EventSetup const &iSetup) {
97  // Book Monitoring Elements
98  bookMEs(iBooker);
99 }
100 
101 //------------------------------------------------------------------
102 // Method called for every event
103 //------------------------------------------------------------------
105  eventNo++;
106  // check feds in readout
107  if (eventNo == 1) {
108  // check if any Pixel FED is in readout:
109  edm::Handle<FEDRawDataCollection> rawDataHandle;
110  iEvent.getByToken(inputSourceToken_, rawDataHandle);
111  if (!rawDataHandle.isValid()) {
112  edm::LogInfo("SiPixelRawDataErrorSource") << "inputsource is empty";
113  } else {
114  const FEDRawDataCollection &rawDataCollection = *rawDataHandle;
115  for (int i = 0; i != 40; i++) {
116  if (rawDataCollection.FEDData(i).size() && rawDataCollection.FEDData(i).data())
117  fedcounter->setBinContent(i + 1, 1);
118  }
119  }
120  }
121  // get input data
123  iEvent.getByToken(src_, input);
124  if (!input.isValid())
125  return;
126 
127  int lumiSection = (int)iEvent.luminosityBlock();
128 
129  int nEventBPIXModuleErrors = 0;
130  int nEventFPIXModuleErrors = 0;
131  int nEventBPIXFEDErrors = 0;
132  int nEventFPIXFEDErrors = 0;
133  int nErrors = 0;
134 
135  std::map<uint32_t, SiPixelRawDataErrorModule *>::iterator struct_iter;
136  std::map<uint32_t, SiPixelRawDataErrorModule *>::iterator struct_iter2;
137  for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
138  int numberOfModuleErrors = (*struct_iter).second->fill(*input, &meMapFEDs_, modOn, ladOn, bladeOn);
139  if (DetId((*struct_iter).first).subdetId() == static_cast<int>(PixelSubdetector::PixelBarrel))
140  nEventBPIXModuleErrors = nEventBPIXModuleErrors + numberOfModuleErrors;
141  if (DetId((*struct_iter).first).subdetId() == static_cast<int>(PixelSubdetector::PixelEndcap))
142  nEventFPIXModuleErrors = nEventFPIXModuleErrors + numberOfModuleErrors;
143  // cout<<"NErrors: "<<nEventBPIXModuleErrors<<"
144  // "<<nEventFPIXModuleErrors<<endl;
145  nErrors = nErrors + numberOfModuleErrors;
146  // if(nErrors>0) cout<<"MODULES: nErrors: "<<nErrors<<endl;
147  }
148  for (struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++) {
149  int numberOfFEDErrors = (*struct_iter2).second->fillFED(*input, &meMapFEDs_);
150  if ((*struct_iter2).first <= 31)
151  nEventBPIXFEDErrors = nEventBPIXFEDErrors + numberOfFEDErrors; // (*struct_iter2).first >= 0, since
152  // (*struct_iter2).first is unsigned
153  if ((*struct_iter2).first >= 32 && (*struct_iter2).first <= 39)
154  nEventFPIXFEDErrors = nEventFPIXFEDErrors + numberOfFEDErrors;
155  // cout<<"NFEDErrors: "<<nEventBPIXFEDErrors<<"
156  // "<<nEventFPIXFEDErrors<<endl;
157  nErrors = nErrors + numberOfFEDErrors;
158  // if(nErrors>0) cout<<"FEDS: nErrors: "<<nErrors<<endl;
159  }
160  if (byLumiErrors) {
162  // cout<<"NErrors: "<<nEventBPIXModuleErrors<<" "<<nEventFPIXModuleErrors<<"
163  // "<<nEventBPIXFEDErrors<<" "<<nEventFPIXFEDErrors<<endl;
164  if (nEventBPIXModuleErrors + nEventBPIXFEDErrors > 0)
165  byLumiErrors->Fill(0, 1.);
166  if (nEventFPIXModuleErrors + nEventFPIXFEDErrors > 0)
167  byLumiErrors->Fill(1, 1.);
168  // cout<<"histo: "<<byLumiErrors->getBinContent(0)<<"
169  // "<<byLumiErrors->getBinContent(1)<<"
170  // "<<byLumiErrors->getBinContent(2)<<endl;
171  }
172 
173  // Rate of errors per lumi section:
174  if (errorRate)
175  errorRate->Fill(lumiSection, nErrors);
176 
177  // slow down...
178  if (slowDown)
179  usleep(100000);
180 }
181 
182 //------------------------------------------------------------------
183 // Build data structure
184 //------------------------------------------------------------------
186  LogInfo("PixelDQM") << " SiPixelRawDataErrorSource::buildStructure";
187 
189  edm::ESHandle<TrackerTopology> tTopoHandle;
190 
191  iSetup.get<TrackerDigiGeometryRecord>().get(pDD);
192  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
193 
194  const TrackerTopology *pTT = tTopoHandle.product();
195 
196  LogVerbatim("PixelDQM") << " *** Geometry node for TrackerGeom is " << &(*pDD) << std::endl;
197  LogVerbatim("PixelDQM") << " *** I have " << pDD->detsPXB().size() << " barrel pixel detectors" << std::endl;
198  LogVerbatim("PixelDQM") << " *** I have " << pDD->detsPXF().size() << " endcap pixel detectors" << std::endl;
199  // LogVerbatim ("PixelDQM") << " *** I have " << pDD->detTypes().size() <<"
200  // types"<<std::endl;
201 
202  for (TrackerGeometry::DetContainer::const_iterator it = pDD->detsPXB().begin(); it != pDD->detsPXB().end(); it++) {
203  const GeomDetUnit *geoUnit = dynamic_cast<const GeomDetUnit *>(*it);
204  // check if it is a detUnit
205  if (geoUnit == nullptr)
206  LogError("PixelDQM") << "Pixel GeomDet is not a GeomDetUnit!" << std::endl;
207  const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
208  int nrows = (pixDet->specificTopology()).nrows();
209  int ncols = (pixDet->specificTopology()).ncolumns();
210 
211  if (isPIB)
212  continue;
213  DetId detId = (*it)->geographicalId();
214  LogDebug("PixelDQM") << " ---> Adding Barrel Module " << detId.rawId() << endl;
215  uint32_t id = detId();
216  SiPixelRawDataErrorModule *theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
217  thePixelStructure.insert(pair<uint32_t, SiPixelRawDataErrorModule *>(id, theModule));
218  }
219 
220  for (TrackerGeometry::DetContainer::const_iterator it = pDD->detsPXF().begin(); it != pDD->detsPXF().end(); it++) {
221  const GeomDetUnit *geoUnit = dynamic_cast<const GeomDetUnit *>(*it);
222  // check if it is a detUnit
223  if (geoUnit == nullptr)
224  LogError("PixelDQM") << "Pixel GeomDet is not a GeomDetUnit!" << std::endl;
225  const PixelGeomDetUnit *pixDet = dynamic_cast<const PixelGeomDetUnit *>(geoUnit);
226  int nrows = (pixDet->specificTopology()).nrows();
227  int ncols = (pixDet->specificTopology()).ncolumns();
228 
229  DetId detId = (*it)->geographicalId();
230  LogDebug("PixelDQM") << " ---> Adding Endcap Module " << detId.rawId() << endl;
231  uint32_t id = detId();
232  SiPixelRawDataErrorModule *theModule = new SiPixelRawDataErrorModule(id, ncols, nrows);
233 
235  int disk = PixelEndcapName(DetId(id), pTT, isUpgrade).diskName();
236  int blade = PixelEndcapName(DetId(id), pTT, isUpgrade).bladeName();
237  int panel = PixelEndcapName(DetId(id), pTT, isUpgrade).pannelName();
239 
240  char sside[80];
241  sprintf(sside, "HalfCylinder_%i", side);
242  char sdisk[80];
243  sprintf(sdisk, "Disk_%i", disk);
244  char sblade[80];
245  sprintf(sblade, "Blade_%02i", blade);
246  char spanel[80];
247  sprintf(spanel, "Panel_%i", panel);
248  char smodule[80];
249  sprintf(smodule, "Module_%i", module);
250  std::string side_str = sside;
251  std::string disk_str = sdisk;
252  bool mask = side_str.find("HalfCylinder_1") != string::npos || side_str.find("HalfCylinder_2") != string::npos ||
253  side_str.find("HalfCylinder_4") != string::npos || disk_str.find("Disk_2") != string::npos;
254  // clutch to take all of FPIX, but no BPIX:
255  mask = false;
256  if (isPIB && mask)
257  continue;
258 
259  thePixelStructure.insert(pair<uint32_t, SiPixelRawDataErrorModule *>(id, theModule));
260  }
261 
262  LogDebug("PixelDQM") << " ---> Adding Module for Additional Errors " << endl;
264 
265  fedIds.first = 0;
266  fedIds.second = 39;
267 
268  for (int fedId = fedIds.first; fedId <= fedIds.second; fedId++) {
269  // std::cout<<"Adding FED module: "<<fedId<<std::endl;
270  uint32_t id = static_cast<uint32_t>(fedId);
272  theFEDStructure.insert(pair<uint32_t, SiPixelRawDataErrorModule *>(id, theModule));
273  }
274 
275  LogInfo("PixelDQM") << " *** Pixel Structure Size " << thePixelStructure.size() << endl;
276 }
277 //------------------------------------------------------------------
278 // Book MEs
279 //------------------------------------------------------------------
281  iBooker.setCurrentFolder(topFolderName_ + "/EventInfo/DAQContents");
282  char title0[80];
283  sprintf(title0, "FED isPresent;FED ID;isPresent");
284  fedcounter = iBooker.book1D("fedcounter", title0, 40, -0.5, 39.5);
285  iBooker.setCurrentFolder(topFolderName_ + "/AdditionalPixelErrors");
286  char title[80];
287  sprintf(title, "By-LumiSection Error counters");
288  byLumiErrors = iBooker.book1D("byLumiErrors", title, 2, 0., 2.);
290  char title1[80];
291  sprintf(title1, "Errors per LumiSection;LumiSection;NErrors");
292  errorRate = iBooker.book1D("errorRate", title1, 5000, 0., 5000.);
293 
294  std::map<uint32_t, SiPixelRawDataErrorModule *>::iterator struct_iter;
295  std::map<uint32_t, SiPixelRawDataErrorModule *>::iterator struct_iter2;
296 
297  SiPixelFolderOrganizer theSiPixelFolder(false);
298 
299  for (struct_iter = thePixelStructure.begin(); struct_iter != thePixelStructure.end(); struct_iter++) {
301 
302  if (modOn) {
303  if (!theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 0, isUpgrade)) {
304  // std::cout<<"PIB! not booking histograms for non-PIB
305  // modules!"<<std::endl;
306  if (!isPIB)
307  throw cms::Exception("LogicError") << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder "
308  "failed";
309  }
310  }
311 
312  if (ladOn) {
313  if (!theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 1, isUpgrade)) {
314  LogDebug("PixelDQM") << "PROBLEM WITH LADDER-FOLDER\n";
315  }
316  }
317 
318  if (bladeOn) {
319  if (!theSiPixelFolder.setModuleFolder(iBooker, (*struct_iter).first, 4, isUpgrade)) {
320  LogDebug("PixelDQM") << "PROBLEM WITH BLADE-FOLDER\n";
321  }
322  }
323 
324  } // for loop
325 
326  for (struct_iter2 = theFEDStructure.begin(); struct_iter2 != theFEDStructure.end(); struct_iter2++) {
328  if (!theSiPixelFolder.setFedFolder(iBooker, (*struct_iter2).first)) {
329  throw cms::Exception("LogicError") << "[SiPixelRawDataErrorSource::bookMEs] Creation of DQM folder "
330  "failed";
331  }
332  }
333 
334  // Booking FED histograms
335  std::string hid;
336  // Get collection name and instantiate Histo Id builder
338  SiPixelHistogramId *theHistogramId = new SiPixelHistogramId(src.label());
339 
340  for (uint32_t id = 0; id < 40; id++) {
341  char temp[50];
342  sprintf(temp, (topFolderName_ + "/AdditionalPixelErrors/FED_%d").c_str(), id);
343  iBooker.cd(temp);
344  // Types of errors
345  hid = theHistogramId->setHistoId("errorType", id);
346  meErrorType_[id] = iBooker.book1D(hid, "Type of errors", 15, 24.5, 39.5);
347  meErrorType_[id]->setAxisTitle("Type of errors", 1);
348  // Number of errors
349  hid = theHistogramId->setHistoId("NErrors", id);
350  meNErrors_[id] = iBooker.book1D(hid, "Number of errors", 36, 0., 36.);
351  meNErrors_[id]->setAxisTitle("Number of errors", 1);
352  // Type of FIFO full (errorType = 28). FIFO 1 is 1-5 (where fullType =
353  // channel of FIFO 1), fullType = 6 signifies FIFO 2 nearly full, 7
354  // signifies trigger FIFO nearly full, 8 indicates an unexpected result
355  hid = theHistogramId->setHistoId("fullType", id);
356  meFullType_[id] = iBooker.book1D(hid, "Type of FIFO full", 7, 0.5, 7.5);
357  meFullType_[id]->setAxisTitle("FIFO type", 1);
358  // For error type 30, the type of problem encoded in the TBM trailer
359  // 0 = stack full, 1 = Pre-cal issued, 2 = clear trigger counter, 3 = sync
360  // trigger, 4 = sync trigger error, 5 = reset ROC, 6 = reset TBM, 7 = no
361  // token bit pass
362  hid = theHistogramId->setHistoId("TBMMessage", id);
363  meTBMMessage_[id] = iBooker.book1D(hid, "TBM trailer message", 8, -0.5, 7.5);
364  meTBMMessage_[id]->setAxisTitle("TBM message", 1);
365  // For error type 30, the type of problem encoded in the TBM error trailer 0
366  // = none 1 = data stream too long, 2 = FSM errors, 3 = invalid # of ROCs, 4
367  // = multiple
368  hid = theHistogramId->setHistoId("TBMType", id);
369  meTBMType_[id] = iBooker.book1D(hid, "Type of TBM trailer", 5, -0.5, 4.5);
370  meTBMType_[id]->setAxisTitle("TBM Type", 1);
371  // For error type 31, the event number of the TBM header with the error
372  hid = theHistogramId->setHistoId("EvtNbr", id);
373  meEvtNbr_[id] = iBooker.book1D(hid, "Event number", 1, 0, 1);
374  // For errorType = 34, datastream size according to error word
375  hid = theHistogramId->setHistoId("evtSize", id);
376  meEvtSize_[id] = iBooker.book1D(hid, "Event size", 1, 0, 1);
377  //
378  hid = theHistogramId->setHistoId("FedChNErr", id);
379  meFedChNErr_[id] = iBooker.book1D(hid, "Number of errors per FED channel", 37, 0, 37);
380  meFedChNErr_[id]->setAxisTitle("FED channel", 1);
381  //
382  hid = theHistogramId->setHistoId("FedChLErr", id);
383  meFedChLErr_[id] = iBooker.book1D(hid, "Last error per FED channel", 37, 0, 37);
384  meFedChLErr_[id]->setAxisTitle("FED channel", 1);
385  //
386  hid = theHistogramId->setHistoId("FedETypeNErr", id);
387  meFedETypeNErr_[id] = iBooker.book1D(hid, "Number of errors per type", 21, 0, 21);
388  meFedETypeNErr_[id]->setAxisTitle("Error type", 1);
389  }
390  // Add the booked histograms to the histogram map for booking
391  meMapFEDs_["meErrorType_"] = meErrorType_;
392  meMapFEDs_["meNErrors_"] = meNErrors_;
393  meMapFEDs_["meFullType_"] = meFullType_;
394  meMapFEDs_["meTBMMessage_"] = meTBMMessage_;
395  meMapFEDs_["meTBMType_"] = meTBMType_;
396  meMapFEDs_["meEvtNbr_"] = meEvtNbr_;
397  meMapFEDs_["meEvtSize_"] = meEvtSize_;
398  meMapFEDs_["meFedChNErr_"] = meFedChNErr_;
399  meMapFEDs_["meFedChLErr_"] = meFedChLErr_;
400  meMapFEDs_["meFedETypeNErr_"] = meFedETypeNErr_;
401 
402  // cout<<"...leaving SiPixelRawDataErrorSource::bookMEs now! "<<endl;
403 }
404 
#define LogDebug(id)
int plaquetteName() const
plaquetteId (in pannel)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
void setBinContent(int binx, double content)
set content of bin (1-D)
virtual void bookMEs(DQMStore::IBooker &)
edm::EDGetTokenT< edm::DetSetVector< SiPixelRawDataError > > src_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
MonitorElement * meFedETypeNErr_[40]
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:61
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
size_t size() const
Lenght of the data buffer in bytes.
Definition: FEDRawData.h:47
static std::string const input
Definition: EdmProvDump.cc:48
void Fill(long long x)
int bladeName() const
blade id
bool setFedFolder(const uint32_t FedId)
Set folder name for a FED (used in the case of errors without detId)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
const FEDRawData & FEDData(int fedid) const
retrieve data for fed
void setLumiFlag()
this ME is meant to be stored for each luminosity section
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
std::map< uint32_t, SiPixelRawDataErrorModule * > theFEDStructure
bool setModuleFolder(const uint32_t &rawdetid=0, int type=0, bool isUpgrade=false)
Set folder name for a module or plaquette.
const DetContainer & detsPXB() const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
void dqmBeginRun(const edm::Run &, edm::EventSetup const &) override
bool isValid() const
Definition: HandleBase.h:74
SiPixelRawDataErrorSource(const edm::ParameterSet &conf)
Definition: DetId.h:18
std::map< uint32_t, SiPixelRawDataErrorModule * > thePixelStructure
edm::EDGetTokenT< FEDRawDataCollection > inputSourceToken_
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
std::string const & label() const
Definition: InputTag.h:36
virtual void buildStructure(edm::EventSetup const &)
HLT enums.
int pannelName() const
pannel id
T get() const
Definition: EventSetup.h:71
const unsigned char * data() const
Return a const pointer to the beginning of the data buffer.
Definition: FEDRawData.cc:28
void analyze(const edm::Event &, const edm::EventSetup &) override
const DetContainer & detsPXF() const
std::map< std::string, MonitorElement ** > meMapFEDs_
int diskName() const
disk id
HalfCylinder halfCylinder() const
void setAxisTitle(const std::string &title, int axis=1)
set x-, y- or z-axis title (axis=1, 2, 3 respectively)
T const * product() const
Definition: ESHandle.h:86
Definition: vlib.h:208
Pixel error – collection of errors and error information.
Definition: Run.h:45