CMS 3D CMS Logo

PixelLumiDQM.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 // Package: PixelLumiDQM
4 // Class: PixelLumiDQM
5 
6 // Author: Amita Raval
7 // Based on Jeroen Hegeman's code for Pixel Cluster Count Luminosity
8 
9 #include "PixelLumiDQM.h"
10 
36 
37 #include <ctime>
38 #include <fstream>
39 #include <map>
40 #include <string>
41 #include <sys/time.h>
42 #include <vector>
43 
44 const unsigned int PixelLumiDQM::lastBunchCrossing;
45 
46 // Constructors and destructor.
48  : fPixelClusterLabel(consumes<edmNew::DetSetVector<SiPixelCluster>>(
49  iConfig.getUntrackedParameter<edm::InputTag>("pixelClusterLabel", edm::InputTag("siPixelClusters")))),
50  fIncludePixelClusterInfo(iConfig.getUntrackedParameter<bool>("includePixelClusterInfo", true)),
51  fIncludePixelQualCheckHistos(iConfig.getUntrackedParameter<bool>("includePixelQualCheckHistos", true)),
52  fResetIntervalInLumiSections(iConfig.getUntrackedParameter<int>("resetEveryNLumiSections", 1)),
53  fDeadModules(iConfig.getUntrackedParameter<std::vector<uint32_t>>("deadModules", std::vector<uint32_t>())),
54  fMinPixelsPerCluster(iConfig.getUntrackedParameter<int>("minNumPixelsPerCluster", 0)),
55  fMinClusterCharge(iConfig.getUntrackedParameter<double>("minChargePerCluster", 0)),
56  bunchTriggerMask(lastBunchCrossing + 1, false),
57  filledAndUnmaskedBunches(0),
58  useInnerBarrelLayer(iConfig.getUntrackedParameter<bool>("useInnerBarrelLayer", false)),
59  fLogFileName_(iConfig.getUntrackedParameter<std::string>("logFileName", "/tmp/pixel_lumi.txt")) {
60  edm::LogInfo("Configuration") << "PixelLumiDQM looking for pixel clusters in '"
61  << iConfig.getUntrackedParameter<edm::InputTag>("pixelClusterLabel",
62  edm::InputTag("siPixelClusters"))
63  << "'";
64  edm::LogInfo("Configuration") << "PixelLumiDQM storing pixel cluster info? " << fIncludePixelClusterInfo;
65  edm::LogInfo("Configuration") << "PixelLumiDQM storing pixel cluster quality check histograms? "
67 
68  if (fDeadModules.empty()) {
69  edm::LogInfo("Configuration") << "No pixel modules specified to be ignored";
70  } else {
71  edm::LogInfo("Configuration") << fDeadModules.size() << " pixel modules specified to be ignored:";
72  for (std::vector<uint32_t>::const_iterator it = fDeadModules.begin(); it != fDeadModules.end(); ++it) {
73  edm::LogInfo("Configuration") << " " << *it;
74  }
75  }
76  edm::LogInfo("Configuration") << "Ignoring pixel clusters with less than " << fMinPixelsPerCluster << " pixels";
77  edm::LogInfo("Configuration") << "Ignoring pixel clusters with charge less than " << fMinClusterCharge;
78 }
79 
81 
84  desc.setUnknown();
85  descriptions.addDefault(desc);
86 }
87 
89  // Collect all bookkeeping information.
90  fRunNo = iEvent.id().run();
91  fEvtNo = iEvent.id().event();
92  fLSNo = iEvent.getLuminosityBlock().luminosityBlock();
93  fBXNo = iEvent.bunchCrossing();
94  fTimestamp = iEvent.time().unixTime();
97  // This serves as event counter to compute luminosity from cluster counts.
98  std::map<int, PixelClusterCount>::iterator it = fNumPixelClusters.find(fBXNo);
99  if (it == fNumPixelClusters.end())
101 
103  // Find tracker geometry.
105  iSetup.get<TrackerDigiGeometryRecord>().get(trackerGeo);
106 
107  // Find pixel clusters.
110 
111  // Loop over entire tracker geometry.
112  for (TrackerGeometry::DetContainer::const_iterator i = trackerGeo->dets().begin(); i != trackerGeo->dets().end();
113  ++i) {
114  // See if this is a pixel unit(?).
115 
116  if (GeomDetEnumerators::isTrackerPixel((*i)->subDetector())) {
117  DetId detId = (*i)->geographicalId();
118  // Find all clusters on this detector module.
120  if (iSearch != pixelClusters->end()) {
121  // Count the number of clusters with at least a minimum
122  // number of pixels per cluster and at least a minimum charge.
123  size_t numClusters = 0;
124  for (edmNew::DetSet<SiPixelCluster>::const_iterator itClus = iSearch->begin(); itClus != iSearch->end();
125  ++itClus) {
126  if ((itClus->size() >= fMinPixelsPerCluster) && (itClus->charge() >= fMinClusterCharge)) {
127  ++numClusters;
128  }
129  }
130  // DEBUG DEBUG DEBUG
131  assert(numClusters <= iSearch->size());
132  // DEBUG DEBUG DEBUG end
133 
134  // Add up the cluster count based on the position of this detector
135  // element.
136  if (detId.subdetId() == PixelSubdetector::PixelBarrel) {
138  int layer = detName.layerName() - kOffsetLayers;
139  fNumPixelClusters[fBXNo].numB.at(layer) += numClusters;
140  fNumPixelClusters[fBXNo].dnumB.at(layer) += sqrt(numClusters);
141  } else {
142  // DEBUG DEBUG DEBUG
144  // DEBUG DEBUG DEBUG end
145 
147  PixelEndcapNameUpgrade::HalfCylinder halfCylinder = detName.halfCylinder();
148  int disk = detName.diskName() - kOffsetDisks;
149  switch (halfCylinder) {
152  fNumPixelClusters[fBXNo].numFM.at(disk) += numClusters;
153  fNumPixelClusters[fBXNo].dnumFM.at(disk) += sqrt(numClusters);
154  break;
157  fNumPixelClusters[fBXNo].numFP.at(disk) += numClusters;
158  fNumPixelClusters[fBXNo].dnumFP.at(disk) += sqrt(numClusters);
159  break;
160  default:
161  assert(false);
162  break;
163  }
164  }
165  }
166  }
167  }
168  }
169  // ----------
170 
171  // Fill some pixel cluster quality check histograms if requested.
173  // Find tracker geometry.
175  iSetup.get<TrackerDigiGeometryRecord>().get(trackerGeo);
176 
177  // Find pixel clusters.
180 
181  bool filterDeadModules = (!fDeadModules.empty());
182  std::vector<uint32_t>::const_iterator deadModulesBegin = fDeadModules.begin();
183  std::vector<uint32_t>::const_iterator deadModulesEnd = fDeadModules.end();
184 
185  // Loop over entire tracker geometry.
186  for (TrackerGeometry::DetContainer::const_iterator i = trackerGeo->dets().begin(); i != trackerGeo->dets().end();
187  ++i) {
188  // See if this is a pixel module.
189  if (GeomDetEnumerators::isTrackerPixel((*i)->subDetector())) {
190  DetId detId = (*i)->geographicalId();
191 
192  // Skip this module if it's on the list of modules to be ignored.
193  if (filterDeadModules && find(deadModulesBegin, deadModulesEnd, detId()) != deadModulesEnd) {
194  continue;
195  }
196 
197  // Find all clusters in this module.
199 
200  // Loop over all clusters in this module.
201  if (iSearch != pixelClusters->end()) {
202  for (edmNew::DetSet<SiPixelCluster>::const_iterator clus = iSearch->begin(); clus != iSearch->end(); ++clus) {
203  if ((clus->size() >= fMinPixelsPerCluster) && (clus->charge() >= fMinClusterCharge)) {
204  PixelGeomDetUnit const *theGeomDet = dynamic_cast<PixelGeomDetUnit const *>(trackerGeo->idToDet(detId));
205  PixelTopology const *topol = &(theGeomDet->specificTopology());
206  double x = clus->x();
207  double y = clus->y();
208  LocalPoint clustLP = topol->localPosition(MeasurementPoint(x, y));
209  GlobalPoint clustGP = theGeomDet->surface().toGlobal(clustLP);
210  double charge = clus->charge() / 1.e3;
211  int size = clus->size();
212 
213  if (detId.subdetId() == PixelSubdetector::PixelBarrel) {
215  unsigned int layer = detName.layerName() - kOffsetLayers;
216  if (layer < kNumLayers) {
217  std::string histName;
218  histName = "clusPosBarrel" + std::to_string(layer);
219  fHistContainerThisRun[histName]->Fill(clustGP.z(), clustGP.phi());
220  histName = "clusChargeBarrel" + std::to_string(layer);
221  fHistContainerThisRun[histName]->Fill(iEvent.bunchCrossing(), charge);
222  histName = "clusSizeBarrel" + std::to_string(layer);
223  fHistContainerThisRun[histName]->Fill(iEvent.bunchCrossing(), size);
224  } else {
225  edm::LogWarning("pixelLumi") << "higher layer number, " << layer << ", than layers";
226  }
227  } else {
228  // DEBUG DEBUG DEBUG
230  // DEBUG DEBUG DEBUG end
231 
233  unsigned int disk = detName.diskName() - kOffsetDisks;
234  if (disk < kNumDisks) {
235  std::string histName;
236  histName = "clusPosEndCap" + std::to_string(disk);
237  fHistContainerThisRun[histName]->Fill(clustGP.x(), clustGP.y());
238  histName = "clusChargeEndCap" + std::to_string(disk);
239  fHistContainerThisRun[histName]->Fill(iEvent.bunchCrossing(), charge);
240  histName = "clusSizeEndCap" + std::to_string(disk);
241  fHistContainerThisRun[histName]->Fill(iEvent.bunchCrossing(), size);
242  } else {
243  edm::LogWarning("pixelLumi")
244  << "higher disk number, " << disk << ", than disks," << kNumDisks << std::endl;
245  }
246  }
247  }
248  }
249  }
250  }
251  }
252  }
253 }
254 
255 void PixelLumiDQM::bookHistograms(DQMStore::IBooker &ibooker,
256  edm::Run const &run,
257  edm::EventSetup const & /* iSetup */) {
258  edm::LogInfo("Status") << "Starting processing of run #" << run.id().run();
259 
260  // Top folder containing high-level information about pixel and HF lumi.
261  std::string folder = "PixelLumi/";
262  ibooker.setCurrentFolder(folder);
263 
264  fHistTotalRecordedLumiByLS = ibooker.book1D("totalPixelLumiByLS", "Pixel Lumi in nb vs LS", 8000, 0.5, 8000.5);
265  fHistRecordedByBxCumulative = ibooker.book1D("PXLumiByBXsum",
266  "Pixel Lumi in nb by BX Cumulative vs LS",
268  0.5,
269  float(lastBunchCrossing) + 0.5);
270 
271  std::string subfolder = folder + "lastLS/";
272  ibooker.setCurrentFolder(subfolder);
273  fHistRecordedByBxLastLumi = ibooker.book1D(
274  "PXByBXLastLumi", "Pixel By BX Last Lumi", lastBunchCrossing + 1, -0.5, float(lastBunchCrossing) + 0.5);
275 
276  subfolder = folder + "ClusterCountingDetails/";
277  ibooker.setCurrentFolder(subfolder);
278 
279  fHistnBClusVsLS[0] = ibooker.book1D("nBClusVsLS_0", "Fraction of Clusters vs LS Barrel layer 0", 8000, 0.5, 8000.5);
280  fHistnBClusVsLS[1] = ibooker.book1D("nBClusVsLS_1", "Fraction of Clusters vs LS Barrel layer 1", 8000, 0.5, 8000.5);
281  fHistnBClusVsLS[2] = ibooker.book1D("nBClusVsLS_2", "Fraction of Clusters vs LS Barrel layer 2", 8000, 0.5, 8000.5);
282  fHistnFPClusVsLS[0] = ibooker.book1D("nFPClusVsLS_0", "Fraction of Clusters vs LS Barrel layer 0", 8000, 0.5, 8000.5);
283  fHistnFPClusVsLS[1] = ibooker.book1D("nFPClusVsLS_1", "Fraction of Clusters vs LS Barrel layer 1", 8000, 0.5, 8000.5);
284  fHistnFMClusVsLS[0] = ibooker.book1D("nFMClusVsLS_0", "Fraction of Clusters vs LS Barrel layer 0", 8000, 0.5, 8000.5);
285  fHistnFMClusVsLS[1] = ibooker.book1D("nFMClusVsLS_1", "Fraction of Clusters vs LS Barrel layer 1", 8000, 0.5, 8000.5);
286  fHistBunchCrossings = ibooker.book1D(
287  "BunchCrossings", "Cumulative Bunch Crossings", lastBunchCrossing, 0.5, float(lastBunchCrossing) + 0.5);
288  fHistBunchCrossingsLastLumi = ibooker.book1D(
289  "BunchCrossingsLL", "Bunch Crossings Last Lumi", lastBunchCrossing, 0.5, float(lastBunchCrossing) + 0.5);
290  fHistClusterCountByBxLastLumi = ibooker.book1D(
291  "ClusterCountByBxLL", "Cluster Count by BX Last Lumi", lastBunchCrossing, 0.5, float(lastBunchCrossing) + 0.5);
292  fHistClusterCountByBxCumulative = ibooker.book1D(
293  "ClusterCountByBxSum", "Cluster Count by BX Cumulative", lastBunchCrossing, 0.5, float(lastBunchCrossing) + 0.5);
294  fHistClusByLS = ibooker.book1D("totalClusByLS", "Number of Clusters all dets vs LS", 8000, 0.5, 8000.5);
295 
296  // Add some pixel cluster quality check histograms (in a subfolder).
297  subfolder = folder + "qualityChecks/";
298  ibooker.setCurrentFolder(subfolder);
299 
301  // Create histograms for this run if not already present in our list.
302  edm::LogInfo("Status") << "Creating histograms for run #" << run.id().run();
303 
304  // Pixel cluster positions in the barrel - (z, phi).
305  for (size_t i = 0; i <= kNumLayers; ++i) {
306  std::stringstream key;
307  key << "clusPosBarrel" << i;
308  std::stringstream name;
309  name << key.str() << "_" << run.run();
310  std::stringstream title;
311  title << "Pixel cluster position - barrel layer " << i;
312  fHistContainerThisRun[key.str()] =
313  ibooker.book2D(name.str().c_str(), title.str().c_str(), 100, -30., 30., 64, -Geom::pi(), Geom::pi());
314  }
315 
316  // Pixel cluster positions in the endcaps (x, y).
317  for (size_t i = 0; i <= kNumDisks; ++i) {
318  std::stringstream key;
319  key << "clusPosEndCap" << i;
320  std::stringstream name;
321  name << key.str() << "_" << run.run();
322  std::stringstream title;
323  title << "Pixel cluster position - endcap disk " << i;
324  fHistContainerThisRun[key.str()] =
325  ibooker.book2D(name.str().c_str(), title.str().c_str(), 100, -20., 20., 100, -20., 20.);
326  }
327 
328  // Pixel cluster charge in the barrel, per bx.
329  for (size_t i = 0; i <= kNumLayers; ++i) {
330  std::stringstream key;
331  key << "clusChargeBarrel" << i;
332  std::stringstream name;
333  name << key.str() << "_" << run.run();
334  std::stringstream title;
335  title << "Pixel cluster charge - barrel layer " << i;
336  fHistContainerThisRun[key.str()] =
337  ibooker.book2D(name.str().c_str(), title.str().c_str(), 3564, .5, 3564.5, 100, 0., 100.);
338  }
339 
340  // Pixel cluster charge in the endcaps, per bx.
341  for (size_t i = 0; i <= kNumDisks; ++i) {
342  std::stringstream key;
343  key << "clusChargeEndCap" << i;
344  std::stringstream name;
345  name << key.str() << "_" << run.run();
346  std::stringstream title;
347  title << "Pixel cluster charge - endcap disk " << i;
348  fHistContainerThisRun[key.str()] =
349  ibooker.book2D(name.str().c_str(), title.str().c_str(), 3564, .5, 3564.5, 100, 0., 100.);
350  }
351 
352  // Pixel cluster size in the barrel, per bx.
353  for (size_t i = 0; i <= kNumLayers; ++i) {
354  std::stringstream key;
355  key << "clusSizeBarrel" << i;
356  std::stringstream name;
357  name << key.str() << "_" << run.run();
358  std::stringstream title;
359  title << "Pixel cluster size - barrel layer " << i;
360  fHistContainerThisRun[key.str()] =
361  ibooker.book2D(name.str().c_str(), title.str().c_str(), 3564, .5, 3564.5, 100, 0., 100.);
362  }
363 
364  // Pixel cluster size in the endcaps, per bx.
365  for (size_t i = 0; i <= kNumDisks; ++i) {
366  std::stringstream key;
367  key << "clusSizeEndCap" << i;
368  std::stringstream name;
369  name << key.str() << "_" << run.run();
370  std::stringstream title;
371  title << "Pixel cluster size - endcap disk " << i;
372  fHistContainerThisRun[key.str()] =
373  ibooker.book2D(name.str().c_str(), title.str().c_str(), 3564, .5, 3564.5, 100, 0., 100.);
374  }
375  }
376 }
377 
378 // ------------ Method called when starting to process a luminosity block.
379 // ------------
381  // Only reset and fill every fResetIntervalInLumiSections (default is 1 LS)
382  // Return unless the PREVIOUS LS was at the right modulo value
383  // (e.g. is resetinterval = 5 the rest will only be executed at LS=6
384  // NB: reset is done here so the histograms by LS are sent before resetting.
385  // NB: not being used for now since default is 1 LS. There is a bug here.
386 
387  unsigned int ls = lumiBlock.luminosityBlockAuxiliary().luminosityBlock();
388 
389  if ((ls - 1) % fResetIntervalInLumiSections == 0) {
393  }
394 }
395 
396 // ------------ Method called when ending the processing of a luminosity block.
397 // ------------
399  unsigned int ls = lumiBlock.luminosityBlockAuxiliary().luminosityBlock();
400 
401  // Only fill every fResetIntervalInLumiSections (default is 1 LS)
402  if (ls % fResetIntervalInLumiSections != 0)
403  return;
404 
405  printf("Lumi Block = %d\n", ls);
406 
407  if ((ls - 1) % fResetIntervalInLumiSections == 0) {
408  }
409 
410  unsigned int nBClus[3] = {0, 0, 0};
411  unsigned int nFPClus[2] = {0, 0};
412  unsigned int nFMClus[2] = {0, 0};
413 
414  double total_recorded = 0.;
415  double total_recorded_unc_square = 0.;
416 
417  // Obtain bunch-by-bunch cluster counts and compute totals for lumi
418  // calculation.
419  double totalcounts = 0.0;
420  double etotalcounts = 0.0;
421  double totalevents = 0.0;
422  double lumi_factor_per_bx = 0.0;
425  else
427 
428  for (std::map<int, PixelClusterCount>::iterator it = fNumPixelClusters.begin(); it != fNumPixelClusters.end(); it++) {
429  // Sum all clusters for this BX.
430  unsigned int total = (*it).second.numB.at(1) + (*it).second.numB.at(2) + (*it).second.numFP.at(0) +
431  (*it).second.numFP.at(1) + (*it).second.numFM.at(0) + (*it).second.numFM.at(1);
433  total += (*it).second.numB.at(0);
434  totalcounts += total;
435  double etotal = (*it).second.dnumB.at(1) + (*it).second.dnumB.at(2) + (*it).second.dnumFP.at(0) +
436  (*it).second.dnumFP.at(1) + (*it).second.dnumFM.at(0) + (*it).second.dnumFM.at(1);
438  etotal = (*it).second.dnumB.at(0);
439  etotalcounts += etotal;
440  etotal = sqrt(etotal);
441 
443  fHistClusterCountByBxLastLumi->setBinError((*it).first, etotal);
446 
447  unsigned int events_per_bx = fHistBunchCrossingsLastLumi->getBinContent((*it).first);
448  totalevents += events_per_bx;
449  double average_cluster_count = events_per_bx != 0 ? double(total) / events_per_bx : 0.;
450  double average_cluster_count_unc = events_per_bx != 0 ? etotal / events_per_bx : 0.;
451  double pixel_bx_lumi_per_ls = lumi_factor_per_bx * average_cluster_count / CM2_TO_NANOBARN;
452  double pixel_bx_lumi_per_ls_unc = 0.0;
454  pixel_bx_lumi_per_ls_unc = sqrt(lumi_factor_per_bx * lumi_factor_per_bx *
455  (average_cluster_count_unc * average_cluster_count_unc +
456  (average_cluster_count * XSEC_PIXEL_CLUSTER_UNC / XSEC_PIXEL_CLUSTER) *
457  (average_cluster_count * XSEC_PIXEL_CLUSTER / XSEC_PIXEL_CLUSTER))) /
459  else
460  pixel_bx_lumi_per_ls_unc = sqrt(lumi_factor_per_bx * lumi_factor_per_bx *
461  (average_cluster_count_unc * average_cluster_count_unc +
462  (average_cluster_count * rXSEC_PIXEL_CLUSTER_UNC / rXSEC_PIXEL_CLUSTER) *
463  (average_cluster_count * rXSEC_PIXEL_CLUSTER / rXSEC_PIXEL_CLUSTER))) /
465 
466  fHistRecordedByBxLastLumi->setBinContent((*it).first, pixel_bx_lumi_per_ls);
467  fHistRecordedByBxLastLumi->setBinError((*it).first, pixel_bx_lumi_per_ls_unc);
468 
470  (*it).first, fHistRecordedByBxCumulative->getBinContent((*it).first) + pixel_bx_lumi_per_ls);
471 
472  /*
473  if(fHistRecordedByBxLastLumi->getBinContent((*it).first)!=0.)
474  fHistRecordedByBxLastLumi->getBinContent((*it).first));
475  if(fHistRecordedByBxCumulative->getBinContent((*it).first)!=0.)
476  fHistRecordedByBxCumulative->getBinContent((*it).first));
477  */
478 
479  nBClus[0] += (*it).second.numB.at(0);
480  nBClus[1] += (*it).second.numB.at(1);
481  nBClus[2] += (*it).second.numB.at(2);
482  nFPClus[0] += (*it).second.numFP.at(0);
483  nFPClus[1] += (*it).second.numFP.at(1);
484  nFMClus[0] += (*it).second.numFM.at(0);
485  nFMClus[1] += (*it).second.numFM.at(1);
486 
487  // Reset counters
488  (*it).second.Reset();
489 
490  // edm::LogWarning("pixelLumi") << "bx="<< (*it).first << " clusters=" <<
491  // (*it).second.numB.at(0));
492  }
493 
495  for (unsigned int i = 0; i <= lastBunchCrossing; i++) {
496  if (bunchTriggerMask[i]) {
498  total_recorded += fHistRecordedByBxLastLumi->getBinContent(i);
499  total_recorded_unc_square += err * err;
500  }
501  }
502 
503  // Replace the total obtained by summing over BXs with the average per BX
504  // from the total cluster count and rescale
505 
506  if (totalevents > 10) {
507  total_recorded = lumi_factor_per_bx * totalcounts / totalevents / CM2_TO_NANOBARN;
508  } else
509  total_recorded = 0.0;
510 
511  edm::LogWarning("pixelLumi") << " Total recorded " << total_recorded;
512  fHistTotalRecordedLumiByLS->setBinContent(ls, total_recorded);
513  fHistTotalRecordedLumiByLS->setBinError(ls, sqrt(total_recorded_unc_square));
514  }
515  // fill cluster counts by detector regions for sanity checks
516  unsigned int all_detectors_counts = 0;
517  for (unsigned int i = 0; i < 3; i++) {
518  all_detectors_counts += nBClus[i];
519  }
520  for (unsigned int i = 0; i < 2; i++) {
521  all_detectors_counts += nFPClus[i];
522  }
523  for (unsigned int i = 0; i < 2; i++) {
524  all_detectors_counts += nFMClus[i];
525  }
526 
527  fHistClusByLS->setBinContent(ls, all_detectors_counts);
528 
529  for (unsigned int i = 0; i < 3; i++) {
530  fHistnBClusVsLS[i]->setBinContent(ls, float(nBClus[i]) / float(all_detectors_counts));
531  }
532  for (unsigned int i = 0; i < 2; i++) {
533  fHistnFPClusVsLS[i]->setBinContent(ls, float(nFPClus[i]) / float(all_detectors_counts));
534  }
535  for (unsigned int i = 0; i < 2; i++) {
536  fHistnFMClusVsLS[i]->setBinContent(ls, float(nFMClus[i]) / float(all_detectors_counts));
537  }
538 
540 
541  timeval tv;
542  gettimeofday(&tv, nullptr);
543  tm *ts = gmtime(&tv.tv_sec);
544  char datestring[256];
545  strftime(datestring, sizeof(datestring), "%Y.%m.%d %T GMT %s", ts);
546  logFile_ << "RunNumber " << fRunNo << std::endl;
547  logFile_ << "EndTimeOfFit " << datestring << std::endl;
548  logFile_ << "LumiRange " << ls << "-" << ls << std::endl;
549  logFile_ << "Fill " << -99 << std::endl;
550  logFile_ << "ActiveBunchCrossings " << filledAndUnmaskedBunches << std::endl;
551  logFile_ << "PixelLumi " << fHistTotalRecordedLumiByLS->getBinContent(ls) * 0.98 << std::endl;
552  logFile_ << "HFLumi " << -99 << std::endl;
553  logFile_ << "Ratio " << -99 << std::endl;
554  logFile_.close();
555 }
556 
557 unsigned int PixelLumiDQM::calculateBunchMask(MonitorElement *e, std::vector<bool> &mask) {
558  unsigned int nbins = e->getNbinsX();
559  std::vector<float> ar(nbins, 0.);
560  for (unsigned int i = 1; i <= nbins; i++) {
561  ar[i] = e->getBinContent(i);
562  }
563  return calculateBunchMask(ar, nbins, mask);
564 }
565 unsigned int PixelLumiDQM::calculateBunchMask(std::vector<float> &e, unsigned int nbins, std::vector<bool> &mask) {
566  // Take the cumulative cluster count histogram and find max and average of
567  // non-empty bins.
568  unsigned int active_count = 0;
569  double maxc = 0.0;
570  double ave = 0.0; // Average of non-empty bins
571  unsigned int non_empty_bins = 0;
572 
573  for (unsigned int i = 1; i <= nbins; i++) {
574  double bin = e[i];
575  if (bin != 0.0) {
576  if (maxc < bin)
577  maxc = bin;
578  ave += bin;
579  non_empty_bins++;
580  }
581  }
582 
583  ave /= non_empty_bins;
584  edm::LogWarning("pixelLumi") << "Bunch mask finder - non empty bins " << non_empty_bins
585  << " average of non empty bins " << ave << " max content of one bin " << maxc;
586  double mean = 0.;
587  double sigma = 0.;
588  if (non_empty_bins < 50) {
589  mean = maxc;
590  sigma = (maxc) / 20;
591  } else {
592  TH1F dist("dist", "dist", 500, 0., maxc + (maxc / 500.) * 20.);
593  for (unsigned int i = 1; i <= nbins; i++) {
594  double bin = e[i];
595  dist.Fill(bin);
596  }
597  TF1 fit("plgaus", "gaus");
598  dist.Fit(&fit, "", "", fmax(0., ave - (maxc - ave) / 5.), maxc);
599  mean = fit.GetParameter("Mean");
600  sigma = fit.GetParameter("Sigma");
601  }
602  edm::LogWarning("pixelLumi") << "Bunch mask will use mean" << mean << " sigma " << sigma;
603  // Active BX defined as those which have nclus within fixed standard
604  // deviations of peak.
605  for (unsigned int i = 1; i <= nbins; i++) {
606  double bin = e[i];
607  if (bin > 0. && std::abs(bin - mean) < 5. * (sigma)) {
608  mask[i] = true;
609  active_count++;
610  }
611  }
612  edm::LogWarning("pixelLumi") << "Bunch mask finds " << active_count << " active bunch crossings ";
613  // edm::LogWarning("pixelLumi") << "this is the full bx mask " ;
614  // for(unsigned int i = 1; i<= nbins; i++)
615  // edm::LogWarning("pixelLumi") << ((mask[i]) ? 1:0);
616  return active_count;
617 }
618 // Define this as a CMSSW plug-in.
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
PixelLumiDQM::fHistTotalRecordedLumiByLS
MonitorElement * fHistTotalRecordedLumiByLS
Definition: PixelLumiDQM.h:161
PixelLumiDQM::fHistRecordedByBxCumulative
MonitorElement * fHistRecordedByBxCumulative
Definition: PixelLumiDQM.h:163
eostools.ls
def ls(path, rec=False)
Definition: eostools.py:349
PixelLumiDQM
Definition: PixelLumiDQM.h:40
DDAxes::y
Handle.h
electrons_cff.bool
bool
Definition: electrons_cff.py:372
mps_fire.i
i
Definition: mps_fire.py:355
PixelSubdetector.h
PixelLumiDQM::lastBunchCrossing
static const unsigned int lastBunchCrossing
Definition: PixelLumiDQM.h:55
PixelEndcapNameUpgrade::HalfCylinder
HalfCylinder
Definition: PixelEndcapNameUpgrade.h:18
PixelLumiDQM::kOffsetDisks
static constexpr size_t kOffsetDisks
Definition: PixelLumiDQM.h:77
MessageLogger.h
PixelLumiDQM::calculateBunchMask
unsigned int calculateBunchMask(MonitorElement *, std::vector< bool > &)
Definition: PixelLumiDQM.cc:557
LumiMonitor_cff.pixelClusters
pixelClusters
Definition: LumiMonitor_cff.py:10
SiStripPI::mean
Definition: SiStripPayloadInspectorHelper.h:169
funct::false
false
Definition: Factorize.h:34
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
TrackerGeometry.h
PixelLumiDQM::logFile_
std::ofstream logFile_
Definition: PixelLumiDQM.h:171
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
PixelLumiDQM::fIncludePixelClusterInfo
bool fIncludePixelClusterInfo
Definition: PixelLumiDQM.h:132
PixelTopology.h
ESHandle.h
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
edm::LuminosityBlock
Definition: LuminosityBlock.h:50
PixelLumiDQM::PixelClusterCount
Definition: PixelLumiDQM.h:79
edm::Run
Definition: Run.h:45
printsummarytable.folder
folder
Definition: printsummarytable.py:7
LuminosityBlock.h
edm
HLT enums.
Definition: AlignableModifier.h:19
PixelLumiDQM::fHistContainerThisRun
std::map< std::string, MonitorElement * > fHistContainerThisRun
Definition: PixelLumiDQM.h:136
SiPixelCluster.h
edm::LogInfo
Definition: MessageLogger.h:254
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
edmNew::DetSetVector::const_iterator
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
Definition: DetSetVectorNew.h:231
PixelBarrelNameUpgrade
Definition: PixelBarrelNameUpgrade.h:14
PixelLumiDQM::fHistClusByLS
MonitorElement * fHistClusByLS
Definition: PixelLumiDQM.h:160
cms::cuda::assert
assert(be >=bs)
DQMStore.h
PixelEndcapNameUpgrade::mO
Definition: PixelEndcapNameUpgrade.h:18
edmNew::DetSetVector::begin
const_iterator begin(bool update=false) const
Definition: DetSetVectorNew.h:572
PixelEndcapNameUpgrade
Definition: PixelEndcapNameUpgrade.h:16
dqm::legacy::MonitorElement
Definition: MonitorElement.h:461
L1TowerCalibrationProducer_cfi.fit
fit
Definition: L1TowerCalibrationProducer_cfi.py:36
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
PixelLumiDQM::fBXNo
UInt_t fBXNo
Definition: PixelLumiDQM.h:119
DDAxes::x
SiPixelCluster
Pixel cluster – collection of neighboring pixels above threshold.
Definition: SiPixelCluster.h:27
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
tools.TF1
TF1
Definition: tools.py:23
edm::Handle
Definition: AssociativeIterator.h:50
PixelLumiDQM::bookHistograms
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
Definition: PixelLumiDQM.cc:255
edmNew
Definition: DetSet2RangeMap.h:11
PixelLumiDQM::kOffsetLayers
static constexpr size_t kOffsetLayers
Definition: PixelLumiDQM.h:76
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
EDMException.h
DetId
Definition: DetId.h:17
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
MakerMacros.h
PixelLumiDQM::fillDescriptions
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PixelLumiDQM.cc:82
PixelLumiDQM::fHistClusterCountByBxCumulative
MonitorElement * fHistClusterCountByBxCumulative
Definition: PixelLumiDQM.h:159
edm::EventSetup::get
T get() const
Definition: EventSetup.h:73
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
PixelLumiDQM::fDeadModules
std::vector< uint32_t > fDeadModules
Definition: PixelLumiDQM.h:140
PixelEndcapNameUpgrade::mI
Definition: PixelEndcapNameUpgrade.h:18
Service.h
PixelGeomDetUnit
Definition: PixelGeomDetUnit.h:15
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
mathSSE::sqrt
T sqrt(T t)
Definition: SSEVec.h:19
dqm::impl::MonitorElement::Fill
void Fill(long long x)
Definition: MonitorElement.h:290
Surface::toGlobal
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:79
dqm::impl::MonitorElement::Reset
virtual void Reset()
Remove all data from the ME, keept the empty histogram with all its settings.
Definition: MonitorElement.cc:354
Run.h
edm::ESHandle< TrackerGeometry >
LaserClient_cfi.nbins
nbins
Definition: LaserClient_cfi.py:51
Geom::pi
constexpr double pi()
Definition: Pi.h:31
PixelLumiDQM::SECONDS_PER_LS
static constexpr double SECONDS_PER_LS
Definition: PixelLumiDQM.h:45
PixelLumiDQM::fEvtNo
UInt_t fEvtNo
Definition: PixelLumiDQM.h:117
PixelLumiDQM::CM2_TO_NANOBARN
static constexpr double CM2_TO_NANOBARN
Definition: PixelLumiDQM.h:54
Point3DBase< float, LocalTag >
PixelLumiDQM::XSEC_PIXEL_CLUSTER_UNC
static constexpr double XSEC_PIXEL_CLUSTER_UNC
Definition: PixelLumiDQM.h:49
PixelTopology
Definition: PixelTopology.h:10
PixelLumiDQM::fRunNo
UInt_t fRunNo
Definition: PixelLumiDQM.h:116
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
PixelEndcapNameUpgrade::pO
Definition: PixelEndcapNameUpgrade.h:18
DQMEDAnalyzer.h
edm::ConfigurationDescriptions
Definition: ConfigurationDescriptions.h:28
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PixelLumiDQM::rXSEC_PIXEL_CLUSTER_UNC
static constexpr double rXSEC_PIXEL_CLUSTER_UNC
Definition: PixelLumiDQM.h:53
edm::LogWarning
Definition: MessageLogger.h:141
ALCARECOTkAlJpsiMuMu_cff.charge
charge
Definition: ALCARECOTkAlJpsiMuMu_cff.py:47
MeasurementPoint
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
Definition: MeasurementPoint.h:12
funct::true
true
Definition: Factorize.h:173
TrackerDigiGeometryRecord.h
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
PixelLumiDQM::filledAndUnmaskedBunches
unsigned int filledAndUnmaskedBunches
Definition: PixelLumiDQM.h:166
edm::ParameterSet
Definition: ParameterSet.h:36
PixelLumiDQM::fHistBunchCrossingsLastLumi
MonitorElement * fHistBunchCrossingsLastLumi
Definition: PixelLumiDQM.h:157
Event.h
runTheMatrix.err
err
Definition: runTheMatrix.py:288
Pi.h
PixelLumiDQM::PixelLumiDQM
PixelLumiDQM(const edm::ParameterSet &)
Definition: PixelLumiDQM.cc:47
PixelGeomDetUnit::specificTopology
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
Definition: PixelGeomDetUnit.cc:17
PixelLumiDQM::fHistnFMClusVsLS
MonitorElement * fHistnFMClusVsLS[2]
Definition: PixelLumiDQM.h:155
PixelLumiDQM::fHistRecordedByBxLastLumi
MonitorElement * fHistRecordedByBxLastLumi
Definition: PixelLumiDQM.h:162
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
PixelLumiDQM::fMinClusterCharge
double fMinClusterCharge
Definition: PixelLumiDQM.h:148
createfilelist.int
int
Definition: createfilelist.py:10
GeomDetEnumerators::isTrackerPixel
bool isTrackerPixel(GeomDetEnumerators::SubDetector m)
Definition: GeomDetEnumerators.cc:68
iEvent
int iEvent
Definition: GenABIO.cc:224
PixelLumiDQM::FREQ_ORBIT
static constexpr double FREQ_ORBIT
Definition: PixelLumiDQM.h:44
edm::ParameterSetDescription::setUnknown
void setUnknown()
Definition: ParameterSetDescription.cc:39
edm::EventSetup
Definition: EventSetup.h:57
TrackerGeometry::dets
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: TrackerGeometry.h:62
PixelLumiDQM::beginLuminosityBlock
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: PixelLumiDQM.cc:380
PixelLumiDQM::fPixelClusterLabel
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > fPixelClusterLabel
Definition: PixelLumiDQM.h:114
get
#define get
PixelLumiDQM::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PixelLumiDQM.cc:88
PixelLumiDQM::kNumDisks
static constexpr size_t kNumDisks
Definition: PixelLumiDQM.h:75
newFWLiteAna.bin
bin
Definition: newFWLiteAna.py:161
overlapproblemtsosanalyzer_cfi.title
title
Definition: overlapproblemtsosanalyzer_cfi.py:7
PixelLumiDQM::bunchTriggerMask
std::vector< bool > bunchTriggerMask
Definition: PixelLumiDQM.h:165
PixelLumiDQM::fHistnBClusVsLS
MonitorElement * fHistnBClusVsLS[3]
Definition: PixelLumiDQM.h:153
PixelLumiDQM::fTimestamp
UInt_t fTimestamp
Definition: PixelLumiDQM.h:120
PixelLumiDQM::rXSEC_PIXEL_CLUSTER
static constexpr double rXSEC_PIXEL_CLUSTER
Definition: PixelLumiDQM.h:52
dqm::impl::MonitorElement::setBinContent
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
Definition: MonitorElement.cc:691
PixelLumiDQM::fHistnFPClusVsLS
MonitorElement * fHistnFPClusVsLS[2]
Definition: PixelLumiDQM.h:154
std
Definition: JetResolutionObject.h:76
writedatasetfile.run
run
Definition: writedatasetfile.py:27
PixelLumiDQM::fHistClusterCountByBxLastLumi
MonitorElement * fHistClusterCountByBxLastLumi
Definition: PixelLumiDQM.h:158
edm::LuminosityBlockAuxiliary::luminosityBlock
LuminosityBlockNumber_t luminosityBlock() const
Definition: LuminosityBlockAuxiliary.h:30
PixelLumiDQM::useInnerBarrelLayer
bool useInnerBarrelLayer
Definition: PixelLumiDQM.h:167
DetId.h
LocalPoint.h
edmNew::DetSetVector::end
const_iterator end(bool update=false) const
Definition: DetSetVectorNew.h:577
PixelBarrelNameUpgrade::layerName
int layerName() const
layer id
Definition: PixelBarrelNameUpgrade.h:36
PixelGeomDetUnit.h
dqm::impl::MonitorElement::setBinError
virtual void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
Definition: MonitorElement.cc:709
PixelEndcapNameUpgrade::pI
Definition: PixelEndcapNameUpgrade.h:18
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
EventSetup.h
PixelEndcapNameUpgrade.h
PixelLumiDQM::endLuminosityBlock
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
Definition: PixelLumiDQM.cc:398
dqmMemoryStats.total
total
Definition: dqmMemoryStats.py:152
PixelLumiDQM::XSEC_PIXEL_CLUSTER
static constexpr double XSEC_PIXEL_CLUSTER
Definition: PixelLumiDQM.h:48
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
ParameterSet.h
PixelLumiDQM.h
PixelLumiDQM::fIncludePixelQualCheckHistos
bool fIncludePixelQualCheckHistos
Definition: PixelLumiDQM.h:133
dqm::impl::MonitorElement::getBinError
virtual double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
Definition: MonitorElement.cc:610
PixelBarrelNameUpgrade.h
PixelLumiDQM::fHistBunchCrossings
MonitorElement * fHistBunchCrossings
Definition: PixelLumiDQM.h:156
edm::Event
Definition: Event.h:73
PixelLumiDQM::fMinPixelsPerCluster
int fMinPixelsPerCluster
Definition: PixelLumiDQM.h:145
PixelLumiDQM::~PixelLumiDQM
~PixelLumiDQM() override
Definition: PixelLumiDQM.cc:80
PixelLumiDQM::fNumPixelClusters
std::map< int, PixelClusterCount > fNumPixelClusters
Definition: PixelLumiDQM.h:129
edm::ConfigurationDescriptions::addDefault
void addDefault(ParameterSetDescription const &psetDescription)
Definition: ConfigurationDescriptions.cc:99
crabWrapper.key
key
Definition: crabWrapper.py:19
PixelLumiDQM::fLSNo
UInt_t fLSNo
Definition: PixelLumiDQM.h:118
pileupReCalc_HLTpaths.trunc
trunc
Definition: pileupReCalc_HLTpaths.py:144
PixelLumiDQM::kNumLayers
static constexpr size_t kNumLayers
Definition: PixelLumiDQM.h:74
GlobalPoint.h
dqm::impl::MonitorElement::getBinContent
virtual double getBinContent(int binx) const
get content of bin (1-D)
Definition: MonitorElement.cc:592
PixelLumiDQM::fLogFileName_
std::string fLogFileName_
Definition: PixelLumiDQM.h:169
edm::InputTag
Definition: InputTag.h:15
fit
Definition: CombinedChiSquaredLikelihood.h:6
PV3DBase::phi
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
PixelLumiDQM::fResetIntervalInLumiSections
int fResetIntervalInLumiSections
Definition: PixelLumiDQM.h:134
findQualityFiles.size
size
Write out results.
Definition: findQualityFiles.py:443
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
edmNew::DetSet::const_iterator
const data_type * const_iterator
Definition: DetSetNew.h:31
edm::LuminosityBlock::luminosityBlockAuxiliary
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const override
Definition: LuminosityBlock.h:59