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