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();
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.
109  iEvent.getByToken(fPixelClusterLabel, pixelClusters);
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.
119  edmNew::DetSetVector<SiPixelCluster>::const_iterator iSearch = pixelClusters->find(detId);
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
143  assert(detId.subdetId() == PixelSubdetector::PixelEndcap);
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.
179  iEvent.getByToken(fPixelClusterLabel, pixelClusters);
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.
198  edmNew::DetSetVector<SiPixelCluster>::const_iterator iSearch = pixelClusters->find(detId);
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
229  assert(detId.subdetId() == PixelSubdetector::PixelEndcap);
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 
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);
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);
289  "BunchCrossingsLL", "Bunch Crossings Last Lumi", lastBunchCrossing, 0.5, float(lastBunchCrossing) + 0.5);
291  "ClusterCountByBxLL", "Cluster Count by BX Last Lumi", lastBunchCrossing, 0.5, float(lastBunchCrossing) + 0.5);
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 ending the processing of a run. ------------
380 
381 // ------------ Method called when ending the processing of a run. ------------
383 
384 // ------------ Method called when starting to process a luminosity block.
385 // ------------
387  // Only reset and fill every fResetIntervalInLumiSections (default is 1 LS)
388  // Return unless the PREVIOUS LS was at the right modulo value
389  // (e.g. is resetinterval = 5 the rest will only be executed at LS=6
390  // NB: reset is done here so the histograms by LS are sent before resetting.
391  // NB: not being used for now since default is 1 LS. There is a bug here.
392 
393  unsigned int ls = lumiBlock.luminosityBlockAuxiliary().luminosityBlock();
394 
395  if ((ls - 1) % fResetIntervalInLumiSections == 0) {
399  }
400 }
401 
402 // ------------ Method called when ending the processing of a luminosity block.
403 // ------------
405  unsigned int ls = lumiBlock.luminosityBlockAuxiliary().luminosityBlock();
406 
407  // Only fill every fResetIntervalInLumiSections (default is 1 LS)
408  if (ls % fResetIntervalInLumiSections != 0)
409  return;
410 
411  printf("Lumi Block = %d\n", ls);
412 
413  if ((ls - 1) % fResetIntervalInLumiSections == 0) {
414  }
415 
416  unsigned int nBClus[3] = {0, 0, 0};
417  unsigned int nFPClus[2] = {0, 0};
418  unsigned int nFMClus[2] = {0, 0};
419 
420  double total_recorded = 0.;
421  double total_recorded_unc_square = 0.;
422 
423  // Obtain bunch-by-bunch cluster counts and compute totals for lumi
424  // calculation.
425  double totalcounts = 0.0;
426  double etotalcounts = 0.0;
427  double totalevents = 0.0;
428  double lumi_factor_per_bx = 0.0;
431  else
433 
434  for (std::map<int, PixelClusterCount>::iterator it = fNumPixelClusters.begin(); it != fNumPixelClusters.end(); it++) {
435  // Sum all clusters for this BX.
436  unsigned int total = (*it).second.numB.at(1) + (*it).second.numB.at(2) + (*it).second.numFP.at(0) +
437  (*it).second.numFP.at(1) + (*it).second.numFM.at(0) + (*it).second.numFM.at(1);
439  total += (*it).second.numB.at(0);
440  totalcounts += total;
441  double etotal = (*it).second.dnumB.at(1) + (*it).second.dnumB.at(2) + (*it).second.dnumFP.at(0) +
442  (*it).second.dnumFP.at(1) + (*it).second.dnumFM.at(0) + (*it).second.dnumFM.at(1);
444  etotal = (*it).second.dnumB.at(0);
445  etotalcounts += etotal;
446  etotal = sqrt(etotal);
447 
448  fHistClusterCountByBxLastLumi->setBinContent((*it).first, total);
449  fHistClusterCountByBxLastLumi->setBinError((*it).first, etotal);
452 
453  unsigned int events_per_bx = fHistBunchCrossingsLastLumi->getBinContent((*it).first);
454  totalevents += events_per_bx;
455  double average_cluster_count = events_per_bx != 0 ? double(total) / events_per_bx : 0.;
456  double average_cluster_count_unc = events_per_bx != 0 ? etotal / events_per_bx : 0.;
457  double pixel_bx_lumi_per_ls = lumi_factor_per_bx * average_cluster_count / CM2_TO_NANOBARN;
458  double pixel_bx_lumi_per_ls_unc = 0.0;
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 * XSEC_PIXEL_CLUSTER_UNC / XSEC_PIXEL_CLUSTER) *
463  (average_cluster_count * XSEC_PIXEL_CLUSTER / XSEC_PIXEL_CLUSTER))) /
465  else
466  pixel_bx_lumi_per_ls_unc = sqrt(lumi_factor_per_bx * lumi_factor_per_bx *
467  (average_cluster_count_unc * average_cluster_count_unc +
468  (average_cluster_count * rXSEC_PIXEL_CLUSTER_UNC / rXSEC_PIXEL_CLUSTER) *
469  (average_cluster_count * rXSEC_PIXEL_CLUSTER / rXSEC_PIXEL_CLUSTER))) /
471 
472  fHistRecordedByBxLastLumi->setBinContent((*it).first, pixel_bx_lumi_per_ls);
473  fHistRecordedByBxLastLumi->setBinError((*it).first, pixel_bx_lumi_per_ls_unc);
474 
476  (*it).first, fHistRecordedByBxCumulative->getBinContent((*it).first) + pixel_bx_lumi_per_ls);
477 
478  /*
479  if(fHistRecordedByBxLastLumi->getBinContent((*it).first)!=0.)
480  fHistRecordedByBxLastLumi->getBinContent((*it).first));
481  if(fHistRecordedByBxCumulative->getBinContent((*it).first)!=0.)
482  fHistRecordedByBxCumulative->getBinContent((*it).first));
483  */
484 
485  nBClus[0] += (*it).second.numB.at(0);
486  nBClus[1] += (*it).second.numB.at(1);
487  nBClus[2] += (*it).second.numB.at(2);
488  nFPClus[0] += (*it).second.numFP.at(0);
489  nFPClus[1] += (*it).second.numFP.at(1);
490  nFMClus[0] += (*it).second.numFM.at(0);
491  nFMClus[1] += (*it).second.numFM.at(1);
492 
493  // Reset counters
494  (*it).second.Reset();
495 
496  // edm::LogWarning("pixelLumi") << "bx="<< (*it).first << " clusters=" <<
497  // (*it).second.numB.at(0));
498  }
499 
501  for (unsigned int i = 0; i <= lastBunchCrossing; i++) {
502  if (bunchTriggerMask[i]) {
504  total_recorded += fHistRecordedByBxLastLumi->getBinContent(i);
505  total_recorded_unc_square += err * err;
506  }
507  }
508 
509  // Replace the total obtained by summing over BXs with the average per BX
510  // from the total cluster count and rescale
511 
512  if (totalevents > 10) {
513  total_recorded = lumi_factor_per_bx * totalcounts / totalevents / CM2_TO_NANOBARN;
514  } else
515  total_recorded = 0.0;
516 
517  edm::LogWarning("pixelLumi") << " Total recorded " << total_recorded;
518  fHistTotalRecordedLumiByLS->setBinContent(ls, total_recorded);
519  fHistTotalRecordedLumiByLS->setBinError(ls, sqrt(total_recorded_unc_square));
520  }
521  // fill cluster counts by detector regions for sanity checks
522  unsigned int all_detectors_counts = 0;
523  for (unsigned int i = 0; i < 3; i++) {
524  all_detectors_counts += nBClus[i];
525  }
526  for (unsigned int i = 0; i < 2; i++) {
527  all_detectors_counts += nFPClus[i];
528  }
529  for (unsigned int i = 0; i < 2; i++) {
530  all_detectors_counts += nFMClus[i];
531  }
532 
533  fHistClusByLS->setBinContent(ls, all_detectors_counts);
534 
535  for (unsigned int i = 0; i < 3; i++) {
536  fHistnBClusVsLS[i]->setBinContent(ls, float(nBClus[i]) / float(all_detectors_counts));
537  }
538  for (unsigned int i = 0; i < 2; i++) {
539  fHistnFPClusVsLS[i]->setBinContent(ls, float(nFPClus[i]) / float(all_detectors_counts));
540  }
541  for (unsigned int i = 0; i < 2; i++) {
542  fHistnFMClusVsLS[i]->setBinContent(ls, float(nFMClus[i]) / float(all_detectors_counts));
543  }
544 
546 
547  timeval tv;
548  gettimeofday(&tv, nullptr);
549  tm *ts = gmtime(&tv.tv_sec);
550  char datestring[256];
551  strftime(datestring, sizeof(datestring), "%Y.%m.%d %T GMT %s", ts);
552  logFile_ << "RunNumber " << fRunNo << std::endl;
553  logFile_ << "EndTimeOfFit " << datestring << std::endl;
554  logFile_ << "LumiRange " << ls << "-" << ls << std::endl;
555  logFile_ << "Fill " << -99 << std::endl;
556  logFile_ << "ActiveBunchCrossings " << filledAndUnmaskedBunches << std::endl;
557  logFile_ << "PixelLumi " << fHistTotalRecordedLumiByLS->getBinContent(ls) * 0.98 << std::endl;
558  logFile_ << "HFLumi " << -99 << std::endl;
559  logFile_ << "Ratio " << -99 << std::endl;
560  logFile_.close();
561 }
562 
563 unsigned int PixelLumiDQM::calculateBunchMask(MonitorElement *e, std::vector<bool> &mask) {
564  unsigned int nbins = e->getNbinsX();
565  std::vector<float> ar(nbins, 0.);
566  for (unsigned int i = 1; i <= nbins; i++) {
567  ar[i] = e->getBinContent(i);
568  }
569  return calculateBunchMask(ar, nbins, mask);
570 }
571 unsigned int PixelLumiDQM::calculateBunchMask(std::vector<float> &e, unsigned int nbins, std::vector<bool> &mask) {
572  // Take the cumulative cluster count histogram and find max and average of
573  // non-empty bins.
574  unsigned int active_count = 0;
575  double maxc = 0.0;
576  double ave = 0.0; // Average of non-empty bins
577  unsigned int non_empty_bins = 0;
578 
579  for (unsigned int i = 1; i <= nbins; i++) {
580  double bin = e[i];
581  if (bin != 0.0) {
582  if (maxc < bin)
583  maxc = bin;
584  ave += bin;
585  non_empty_bins++;
586  }
587  }
588 
589  ave /= non_empty_bins;
590  edm::LogWarning("pixelLumi") << "Bunch mask finder - non empty bins " << non_empty_bins
591  << " average of non empty bins " << ave << " max content of one bin " << maxc;
592  double mean = 0.;
593  double sigma = 0.;
594  if (non_empty_bins < 50) {
595  mean = maxc;
596  sigma = (maxc) / 20;
597  } else {
598  TH1F dist("dist", "dist", 500, 0., maxc + (maxc / 500.) * 20.);
599  for (unsigned int i = 1; i <= nbins; i++) {
600  double bin = e[i];
601  dist.Fill(bin);
602  }
603  TF1 fit("plgaus", "gaus");
604  dist.Fit(&fit, "", "", fmax(0., ave - (maxc - ave) / 5.), maxc);
605  mean = fit.GetParameter("Mean");
606  sigma = fit.GetParameter("Sigma");
607  }
608  edm::LogWarning("pixelLumi") << "Bunch mask will use mean" << mean << " sigma " << sigma;
609  // Active BX defined as those which have nclus within fixed standard
610  // deviations of peak.
611  for (unsigned int i = 1; i <= nbins; i++) {
612  double bin = e[i];
613  if (bin > 0. && std::abs(bin - mean) < 5. * (sigma)) {
614  mask[i] = true;
615  active_count++;
616  }
617  }
618  edm::LogWarning("pixelLumi") << "Bunch mask finds " << active_count << " active bunch crossings ";
619  // edm::LogWarning("pixelLumi") << "this is the full bx mask " ;
620  // for(unsigned int i = 1; i<= nbins; i++)
621  // edm::LogWarning("pixelLumi") << ((mask[i]) ? 1:0);
622  return active_count;
623 }
624 // Define this as a CMSSW plug-in.
RunNumber_t run() const
Definition: EventID.h:38
size
Write out results.
bool fIncludePixelQualCheckHistos
Definition: PixelLumiDQM.h:135
GlobalPoint toGlobal(const Point2DBase< Scalar, LocalTag > lp) const
Definition: Surface.h:81
MonitorElement * book1D(TString const &name, TString const &title, int const nchX, double const lowX, double const highX)
Definition: DQMStore.cc:239
EventNumber_t event() const
Definition: EventID.h:40
T getUntrackedParameter(std::string const &, T const &) const
static double SECONDS_PER_LS
Definition: PixelLumiDQM.h:45
unsigned int filledAndUnmaskedBunches
Definition: PixelLumiDQM.h:168
const_iterator end(bool update=false) const
void dqmBeginRun(edm::Run const &, edm::EventSetup const &) override
RunID const & id() const
Definition: RunBase.h:39
RunNumber_t run() const
Definition: RunBase.h:40
static const unsigned int lastBunchCrossing
Definition: PixelLumiDQM.h:55
RunNumber_t run() const
Definition: RunID.h:36
std::vector< uint32_t > fDeadModules
Definition: PixelLumiDQM.h:142
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:525
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:418
static size_t kOffsetDisks
Definition: PixelLumiDQM.h:79
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
virtual double getBinError(int binx) const
get uncertainty on content of bin (1-D) - See TH1::GetBinError for details
T y() const
Definition: PV3DBase.h:60
int bunchCrossing() const
Definition: EventBase.h:64
int fResetIntervalInLumiSections
Definition: PixelLumiDQM.h:136
data_type const * const_iterator
Definition: DetSetNew.h:31
MonitorElement * fHistRecordedByBxCumulative
Definition: PixelLumiDQM.h:165
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void beginLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
void dqmEndRun(edm::Run const &, edm::EventSetup const &) override
bool useInnerBarrelLayer
Definition: PixelLumiDQM.h:169
LuminosityBlockNumber_t luminosityBlock() const
void Fill(long long x)
MonitorElement * fHistClusByLS
Definition: PixelLumiDQM.h:162
virtual void Reset()
reset ME (ie. contents, errors, etc)
LuminosityBlockAuxiliary const & luminosityBlockAuxiliary() const override
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
~PixelLumiDQM() override
Definition: PixelLumiDQM.cc:80
Measurement2DPoint MeasurementPoint
Measurement points are two-dimensional by default.
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
void addDefault(ParameterSetDescription const &psetDescription)
virtual int getNbinsX() const
get # of bins in X-axis
MonitorElement * fHistnFMClusVsLS[2]
Definition: PixelLumiDQM.h:157
edm::EDGetTokenT< edmNew::DetSetVector< SiPixelCluster > > fPixelClusterLabel
Definition: PixelLumiDQM.h:116
unsigned int calculateBunchMask(MonitorElement *, std::vector< bool > &)
static double rXSEC_PIXEL_CLUSTER
Definition: PixelLumiDQM.h:52
T sqrt(T t)
Definition: SSEVec.h:19
T z() const
Definition: PV3DBase.h:61
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
MonitorElement * fHistClusterCountByBxLastLumi
Definition: PixelLumiDQM.h:160
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
MonitorElement * fHistTotalRecordedLumiByLS
Definition: PixelLumiDQM.h:163
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: PixelLumiDQM.cc:82
unsigned int unixTime() const
Time in seconds since January 1, 1970.
Definition: Timestamp.h:40
void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
static double FREQ_ORBIT
Definition: PixelLumiDQM.h:44
static double XSEC_PIXEL_CLUSTER_UNC
Definition: PixelLumiDQM.h:49
LuminosityBlock const & getLuminosityBlock() const
Definition: Event.h:98
MonitorElement * fHistClusterCountByBxCumulative
Definition: PixelLumiDQM.h:161
void endLuminosityBlock(edm::LuminosityBlock const &, edm::EventSetup const &) override
MonitorElement * fHistnBClusVsLS[3]
Definition: PixelLumiDQM.h:155
virtual double getBinContent(int binx) const
get content of bin (1-D)
LuminosityBlockNumber_t luminosityBlock() const
std::map< std::string, MonitorElement * > fHistContainerThisRun
Definition: PixelLumiDQM.h:138
double fMinClusterCharge
Definition: PixelLumiDQM.h:150
boost::transform_iterator< IterHelp, const_IdIter > const_iterator
std::vector< bool > bunchTriggerMask
Definition: PixelLumiDQM.h:167
Definition: DetId.h:17
def ls(path, rec=False)
Definition: eostools.py:349
static double CM2_TO_NANOBARN
Definition: PixelLumiDQM.h:54
bool fIncludePixelClusterInfo
Definition: PixelLumiDQM.h:134
virtual void setBinContent(int binx, double content)
set content of bin (1-D)
static double XSEC_PIXEL_CLUSTER
Definition: PixelLumiDQM.h:48
MonitorElement * fHistBunchCrossings
Definition: PixelLumiDQM.h:158
MonitorElement * fHistBunchCrossingsLastLumi
Definition: PixelLumiDQM.h:159
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
UInt_t fTimestamp
Definition: PixelLumiDQM.h:122
virtual LocalPoint localPosition(const MeasurementPoint &) const =0
std::string fLogFileName_
Definition: PixelLumiDQM.h:171
PixelLumiDQM(const edm::ParameterSet &)
Definition: PixelLumiDQM.cc:47
static double rXSEC_PIXEL_CLUSTER_UNC
Definition: PixelLumiDQM.h:53
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: PixelLumiDQM.cc:88
static size_t kNumLayers
Definition: PixelLumiDQM.h:76
edm::EventID id() const
Definition: EventBase.h:59
Pixel cluster – collection of neighboring pixels above threshold.
std::map< int, PixelClusterCount > fNumPixelClusters
Definition: PixelLumiDQM.h:131
HLT enums.
MonitorElement * fHistRecordedByBxLastLumi
Definition: PixelLumiDQM.h:164
MonitorElement * book2D(TString const &name, TString const &title, int nchX, double lowX, double highX, int nchY, double lowY, double highY)
Definition: DQMStore.cc:266
int fMinPixelsPerCluster
Definition: PixelLumiDQM.h:147
T get() const
Definition: EventSetup.h:73
const TrackerGeomDet * idToDet(DetId) const override
static size_t kOffsetLayers
Definition: PixelLumiDQM.h:78
static size_t kNumDisks
Definition: PixelLumiDQM.h:77
virtual void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
constexpr double pi()
Definition: Pi.h:31
T x() const
Definition: PV3DBase.h:59
MonitorElement * fHistnFPClusVsLS[2]
Definition: PixelLumiDQM.h:156
int layerName() const
layer id
edm::Timestamp time() const
Definition: EventBase.h:60
bool isTrackerPixel(GeomDetEnumerators::SubDetector m)
const_iterator begin(bool update=false) const
Definition: Run.h:45
std::ofstream logFile_
Definition: PixelLumiDQM.h:173