CMS 3D CMS Logo

SiPixelPhase1RawDataErrorComparator.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Package: SiPixelPhase1RawDataErrorComparator
3 // Class: SiPixelPhase1RawDataErrorComparator
4 //
7 //
8 // Author: Marco Musich
9 //
19 // DQM Histograming
32 
36 // for string manipulations
37 #include <fmt/printf.h>
38 
39 namespace {
40  // same logic used for the MTV:
41  // cf https://github.com/cms-sw/cmssw/blob/master/Validation/RecoTrack/src/MTVHistoProducerAlgoForTracker.cc
43 
44  void setBinLog(TAxis* axis) {
45  int bins = axis->GetNbins();
46  float from = axis->GetXmin();
47  float to = axis->GetXmax();
48  float width = (to - from) / bins;
49  std::vector<float> new_bins(bins + 1, 0);
50  for (int i = 0; i <= bins; i++) {
51  new_bins[i] = TMath::Power(10, from + i * width);
52  }
53  axis->Set(bins, new_bins.data());
54  }
55 
56  void setBinLogX(TH1* h) {
57  TAxis* axis = h->GetXaxis();
58  setBinLog(axis);
59  }
60  void setBinLogY(TH1* h) {
61  TAxis* axis = h->GetYaxis();
62  setBinLog(axis);
63  }
64 
65  template <typename... Args>
66  dqm::reco::MonitorElement* make2DIfLog(DQMStore::IBooker& ibook, bool logx, bool logy, Args&&... args) {
67  auto h = std::make_unique<TH2I>(std::forward<Args>(args)...);
68  if (logx)
69  setBinLogX(h.get());
70  if (logy)
71  setBinLogY(h.get());
72  const auto& name = h->GetName();
73  return ibook.book2I(name, h.release());
74  }
75 
76  //errorType - a number (25-38) indicating the type of error recorded.
78  k_FED25 = 25, // 25 indicates an invalid ROC of 25
79  k_FED26 = 26, // 26 indicates a gap word
80  k_FED27 = 27, // 27 indicates a dummy word
81  k_FED28 = 28, // 28 indicates a FIFO full error
82  k_FED29 = 29, // 29 indicates a timeout error
83  k_FED30 = 30, // 30 indicates a TBM error trailer
84  k_FED31 = 31, // 31 indicates an event number error (TBM and FED event number mismatch)
85  k_FED32 = 32, // 32 indicates an incorrectly formatted Slink Header
86  k_FED33 = 33, // 33 indicates an incorrectly formatted Slink Trailer
87  k_FED34 =
88  34, // 34 indicates the event size encoded in the Slink Trailer is different than size found at raw2digi conversion
89  k_FED35 = 35, // 35 indicates an invalid FED channel number
90  k_FED36 = 36, // 36 indicates an invalid ROC value
91  k_FED37 = 37, // 37 indicates an invalid dcol or pixel value
92  k_FED38 = 38 // 38 indicates the pixels on a ROC weren't read out from lowest to highest row and dcol value
93  };
94 
95  std::map<SiPixelFEDErrorCodes, std::string> errorCodeToStringMap = {{k_FED25, "FED25 error"},
96  {k_FED26, "FED26 error"},
97  {k_FED27, "FED27 error"},
98  {k_FED28, "FED28 error"},
99  {k_FED29, "FED29 error"},
100  {k_FED30, "FED30 error"},
101  {k_FED31, "FED31 error"}};
102 
103  std::map<SiPixelFEDErrorCodes, std::string> errorCodeToTypeMap = {{k_FED25, "ROC of 25"},
104  {k_FED26, "Gap word"},
105  {k_FED27, "Dummy word"},
106  {k_FED28, "FIFO full"},
107  {k_FED29, "Timeout"},
108  {k_FED30, "TBM error trailer"},
109  {k_FED31, "Event number"},
110  {k_FED32, "Slink header"},
111  {k_FED33, "Slink trailer"},
112  {k_FED34, "Event size"},
113  {k_FED35, "Invalid channel#"},
114  {k_FED36, "ROC value"},
115  {k_FED37, "Dcol or pixel value"},
116  {k_FED38, "Readout order"}};
117 } // namespace
118 
120 public:
122  ~SiPixelPhase1RawDataErrorComparator() override = default;
123  void bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const& iSetup) override;
124  void analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) override;
125  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
126 
127 private:
131 
134  std::unordered_map<SiPixelFEDErrorCodes, MonitorElement*> h_nFEDErrors_;
135 
136  // Define the dimensions of the 2D array
138  static constexpr int nErrors = k_FED38 - k_FED25;
139 };
140 
141 //
142 // constructors
143 //
145  : tokenErrorsGPU_(
146  consumes<edm::DetSetVector<SiPixelRawDataError>>(iConfig.getParameter<edm::InputTag>("pixelErrorSrcGPU"))),
147  tokenErrorsCPU_(
148  consumes<edm::DetSetVector<SiPixelRawDataError>>(iConfig.getParameter<edm::InputTag>("pixelErrorSrcCPU"))),
149  topFolderName_(iConfig.getParameter<std::string>("topFolderName")) {}
150 
151 //
152 // -- Analyze
153 //
155  std::map<int, int> countsOnCPU;
156  std::map<int, int> countsOnGPU;
157 
158  std::array<std::array<int, nErrors>, nFEDs> countsMatrixOnCPU;
159  std::array<std::array<int, nErrors>, nFEDs> countsMatrixOnGPU;
160 
161  // initialize the counts for FED/error matrix
162  for (int i = 0; i < nFEDs; i++) {
163  for (int j = 0; j < nErrors; j++) {
164  countsMatrixOnCPU[i][j] = 0;
165  countsMatrixOnGPU[i][j] = 0;
166  }
167  }
168 
169  // initialize the counts for errors per type scatter plots
170  for (unsigned int j = k_FED25; j <= k_FED31; j++) {
171  countsOnCPU[j] = 0.;
172  countsOnGPU[j] = 0.;
173  }
174 
176  iEvent.getByToken(tokenErrorsCPU_, inputFromCPU);
177  if (!inputFromCPU.isValid()) {
178  edm::LogWarning("SiPixelCompareTrackSoA") << "reference (cpu) SiPixelRawDataErrors not found; \n"
179  << "the comparison will not run.";
180  return;
181  }
182 
183  uint errorsOnCPU{0};
184  for (auto it = inputFromCPU->begin(); it != inputFromCPU->end(); ++it) {
185  for (auto& siPixelRawDataError : *it) {
186  int fed = siPixelRawDataError.getFedId();
187  int type = siPixelRawDataError.getType();
188  DetId id = it->detId();
189 
190  // fill the error matrices for CPU
191  countsOnCPU[type] += 1;
192  countsMatrixOnCPU[fed - FEDNumbering::MINSiPixeluTCAFEDID][type - k_FED25] += 1;
193 
194  edm::LogInfo("SiPixelPhase1RawDataErrorComparator")
195  << __PRETTY_FUNCTION__ << " on cpu: FED: " << fed << " detid: " << id.rawId() << " type:" << type;
196  errorsOnCPU++;
197  }
198  }
199 
201  iEvent.getByToken(tokenErrorsGPU_, inputFromGPU);
202  if (!inputFromGPU.isValid()) {
203  edm::LogWarning("SiPixelCompareTrackSoA") << "target (gpu) SiPixelRawDataErrors not found; \n"
204  << "the comparison will not run.";
205  return;
206  }
207 
208  uint errorsOnGPU{0};
209  for (auto it = inputFromGPU->begin(); it != inputFromGPU->end(); ++it) {
210  for (auto& siPixelRawDataError : *it) {
211  int fed = siPixelRawDataError.getFedId();
212  int type = siPixelRawDataError.getType();
213  DetId id = it->detId();
214 
215  // fill the error matrices for GPU
216  countsOnGPU[type] += 1;
217  countsMatrixOnGPU[fed - FEDNumbering::MINSiPixeluTCAFEDID][type - k_FED25] += 1;
218 
219  edm::LogInfo("SiPixelPhase1RawDataErrorComparator")
220  << __PRETTY_FUNCTION__ << " on gpu: FED: " << fed << " detid: " << id.rawId() << " type:" << type;
221  errorsOnGPU++;
222  }
223  }
224 
225  edm::LogInfo("SiPixelPhase1RawDataErrorComparator")
226  << __PRETTY_FUNCTION__ << " on gpu found: " << errorsOnGPU << " on cpu found: " << errorsOnCPU << std::endl;
227 
228  h_totFEDErrors_->Fill(errorsOnCPU, errorsOnGPU);
229 
230  // fill the correlations per error type
231  for (unsigned int j = k_FED25; j <= k_FED31; j++) {
232  SiPixelFEDErrorCodes code = static_cast<SiPixelFEDErrorCodes>(j);
233  h_nFEDErrors_[code]->Fill(countsOnCPU[j], countsOnGPU[j]);
234  }
235 
236  // fill the error unbalance per FEDid per error type
237  for (int i = 0; i < nFEDs; i++) {
238  for (int j = 0; j < nErrors; j++) {
239  if (countsMatrixOnGPU[i][j] != 0 || countsMatrixOnCPU[i][j] != 0) {
240  edm::LogInfo("SiPixelPhase1RawDataErrorComparator")
241  << "FED: " << i + FEDNumbering::MINSiPixeluTCAFEDID << " error: " << j + k_FED25
242  << " | GPU counts: " << countsMatrixOnGPU[i][j] << " CPU counts:" << countsMatrixOnCPU[i][j] << std::endl;
244  j, i + FEDNumbering::MINSiPixeluTCAFEDID, countsMatrixOnGPU[i][j] - countsMatrixOnCPU[i][j]);
245  }
246  }
247  }
248 }
249 
250 //
251 // -- Book Histograms
252 //
254  edm::Run const& iRun,
255  edm::EventSetup const& iSetup) {
256  iBook.cd();
258 
260  iBook.book2I("FEErrorVsFEDIdUnbalance",
261  "difference (GPU-CPE) of FED errors per FEDid per error type;;FED Id number;GPU counts - CPU counts",
262  nErrors,
263  -0.5,
264  nErrors - 0.5,
265  nFEDs,
268  for (int j = 0; j < nErrors; j++) {
269  const auto& errorCode = static_cast<SiPixelFEDErrorCodes>(j + k_FED25);
270  h_FEDerrorVsFEDIdUnbalance_->setBinLabel(j + 1, errorCodeToTypeMap[errorCode]);
271  }
272 
273  h_totFEDErrors_ = make2DIfLog(iBook,
274  true,
275  true,
276  "nTotalFEDError",
277  "n. of total Pixel FEDError per event; CPU; GPU",
278  500,
279  log10(0.5),
280  log10(500.5),
281  500,
282  log10(0.5),
283  log10(500.5));
284 
285  for (const auto& element : errorCodeToStringMap) {
286  h_nFEDErrors_[element.first] = iBook.book2I(fmt::sprintf("nFED%i_Errors", element.first),
287  fmt::sprintf("n. of %ss per event; CPU; GPU", element.second),
288  501,
289  -0.5,
290  500.5,
291  501,
292  -0.5,
293  500.5);
294  }
295 }
296 
299  //desc.add<edm::InputTag>("pixelErrorSrcGPU", edm::InputTag("siPixelDigiErrors"));
300  desc.add<edm::InputTag>("pixelErrorSrcGPU", edm::InputTag("siPixelDigis@cuda"))
301  ->setComment("input GPU SiPixel FED errors");
302  desc.add<edm::InputTag>("pixelErrorSrcCPU", edm::InputTag("siPixelDigis@cpu"))
303  ->setComment("input CPU SiPixel FED errors");
304  desc.add<std::string>("topFolderName", "SiPixelHeterogeneous/PixelErrorCompareGPUvsCPU");
305  descriptions.addWithDefaultLabel(desc);
306 }
307 
void addWithDefaultLabel(ParameterSetDescription const &psetDescription)
std::unordered_map< SiPixelFEDErrorCodes, MonitorElement * > h_nFEDErrors_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
virtual void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:36
const edm::EDGetTokenT< edm::DetSetVector< SiPixelRawDataError > > tokenErrorsGPU_
~SiPixelPhase1RawDataErrorComparator() override=default
dqm::reco::DQMStore DQMStore
void Fill(long long x)
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
virtual void setBinLabel(int bin, const std::string &label, int axis=1)
set bin label for x, y or z axis (axis=1, 2, 3 respectively)
Log< level::Info, false > LogInfo
Definition: DetId.h:17
bool isValid() const
Definition: HandleBase.h:70
HLT enums.
Log< level::Warning, false > LogWarning
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
MonitorElement * book2I(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY, FUNC onbooking=NOOP())
Definition: DQMStore.h:296
const edm::EDGetTokenT< edm::DetSetVector< SiPixelRawDataError > > tokenErrorsCPU_
void bookHistograms(DQMStore::IBooker &ibooker, edm::Run const &iRun, edm::EventSetup const &iSetup) override
Pixel error – collection of errors and error information.
Definition: Run.h:45
void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override