CMS 3D CMS Logo

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