CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
CorrPCCProducer Class Reference
Inheritance diagram for CorrPCCProducer:
one::DQMEDAnalyzer< edm::one::WatchLuminosityBlocks > one::dqmimplementation::DQMBaseClass< T... >

Public Member Functions

 CorrPCCProducer (const edm::ParameterSet &)
 
 ~CorrPCCProducer () override
 
- Public Member Functions inherited from one::DQMEDAnalyzer< edm::one::WatchLuminosityBlocks >
 DQMEDAnalyzer ()=default
 
 DQMEDAnalyzer (DQMEDAnalyzer< T... > const &)=delete
 
 DQMEDAnalyzer (DQMEDAnalyzer< T... > &&)=delete
 
 ~DQMEDAnalyzer () override=default
 

Private Member Functions

void beginLuminosityBlock (edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final
 
void bookHistograms (DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override
 
void calculateCorrections (std::vector< float >, std::vector< float > &, float &)
 
void endJob () final
 
void endLuminosityBlock (edm::LuminosityBlock const &lumiSeg, const edm::EventSetup &iSetup) final
 
void endRun (edm::Run const &runSeg, const edm::EventSetup &iSetup) final
 
void endRunProduce (edm::Run &runSeg, const edm::EventSetup &iSetup) final
 
void estimateType1Frac (std::vector< float >, float &)
 
void evaluateCorrectionResiduals (std::vector< float >)
 
float getMaximum (std::vector< float >)
 
void makeCorrectionTemplate ()
 
void resetBlock ()
 

Private Attributes

unsigned int approxLumiBlockSize_
 
std::vector< float > correctionScaleFactors_
 
std::vector< float > correctionTemplate_
 
TH1F * corrlumiAvg_h
 
unsigned int countLumi_
 
std::vector< float > errOnLumiByBX_
 
std::vector< float > events_
 
TFile * histoFile
 
TList * hlist
 
unsigned int iBlock = 0
 
TH1F * lumiAvg_h
 
std::map< std::pair< unsigned int, unsigned int >, unsigned int > lumiInfoCounter
 
std::map< std::pair< unsigned int, unsigned int >, LumiInfo * > lumiInfoMap
 
std::map< std::pair< unsigned int, unsigned int >, LumiInfo * >::iterator lumiInfoMapIterator
 
std::map< unsigned int, LumiInfo * > lumiInfoMapPerLS
 
edm::EDGetTokenT< LumiInfolumiInfoToken
 
std::vector< unsigned int > lumiSections
 
unsigned int maxLS = 3500
 
float mean_type1_residual
 
float mean_type1_residual_unc
 
float mean_type2_residual
 
float mean_type2_residual_unc
 
unsigned int minimumNumberOfEvents
 
unsigned int nTrain
 
float overallCorrection_
 
LumiCorrectionspccCorrections
 
std::string pccSrc_
 
edm::Service< cond::service::PoolDBOutputServicepoolDbService
 
std::string prodInst_
 
std::vector< float > rawlumiBX_
 
TH1F * scaleFactorAvg_h
 
unsigned int thisLS
 
std::vector< float > totalLumiByBX_
 
std::vector< float > totalLumiByBXAvg_
 
float type1Frac
 
TGraphErrors * type1FracGraph
 
TH1F * type1FracHist
 
MonitorElementType1FracMon
 
TGraphErrors * type1resGraph
 
TH1F * type1resHist
 
MonitorElementType1ResMon
 
double type2_a_
 
double type2_b_
 
TGraphErrors * type2resGraph
 
TH1F * type2resHist
 
MonitorElementType2ResMon
 

Detailed Description

Definition at line 55 of file CorrPCCProducer.cc.

Constructor & Destructor Documentation

CorrPCCProducer::CorrPCCProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 136 of file CorrPCCProducer.cc.

References approxLumiBlockSize_, correctionScaleFactors_, correctionTemplate_, countLumi_, events_, edm::ParameterSet::getParameter(), histoFile, lumiInfoToken, makeCorrectionTemplate(), minimumNumberOfEvents, LumiConstants::numBX, pccSrc_, prodInst_, resetBlock(), totalLumiByBX_, totalLumiByBXAvg_, type1FracGraph, type1resGraph, type2_a_, type2_b_, and type2resGraph.

136  {
137  pccSrc_ =
138  iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<std::string>("inLumiObLabel");
139  prodInst_ =
140  iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<std::string>("ProdInst");
142  iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<int>("approxLumiBlockSize");
143  type2_a_ = iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<double>("type2_a");
144  type2_b_ = iConfig.getParameter<edm::ParameterSet>("CorrPCCProducerParameters").getParameter<double>("type2_b");
145  countLumi_ = 0;
146  minimumNumberOfEvents = 1000;
147 
153 
154  resetBlock();
155 
157 
158  edm::InputTag inputPCCTag_(pccSrc_, prodInst_);
159 
160  lumiInfoToken = consumes<LumiInfo, edm::InLumi>(inputPCCTag_);
161 
162  histoFile = new TFile("CorrectionHisto.root", "RECREATE");
163 
164  type1FracGraph = new TGraphErrors();
165  type1resGraph = new TGraphErrors();
166  type2resGraph = new TGraphErrors();
167  type1FracGraph->SetName("Type1Fraction");
168  type1resGraph->SetName("Type1Res");
169  type2resGraph->SetName("Type2Res");
170  type1FracGraph->GetYaxis()->SetTitle("Type 1 Fraction");
171  type1resGraph->GetYaxis()->SetTitle("Type 1 Residual");
172  type2resGraph->GetYaxis()->SetTitle("Type 2 Residual");
173  type1FracGraph->GetXaxis()->SetTitle("Unique LS ID");
174  type1resGraph->GetXaxis()->SetTitle("Unique LS ID");
175  type2resGraph->GetXaxis()->SetTitle("Unique LS ID");
176  type1FracGraph->SetMarkerStyle(8);
177  type1resGraph->SetMarkerStyle(8);
178  type2resGraph->SetMarkerStyle(8);
179 }
T getParameter(std::string const &) const
std::vector< float > events_
edm::EDGetTokenT< LumiInfo > lumiInfoToken
static const unsigned int numBX
Definition: LumiConstants.h:9
unsigned int countLumi_
std::string pccSrc_
unsigned int minimumNumberOfEvents
std::vector< float > totalLumiByBXAvg_
TGraphErrors * type1resGraph
std::string prodInst_
std::vector< float > correctionScaleFactors_
std::vector< float > correctionTemplate_
TGraphErrors * type2resGraph
std::vector< float > totalLumiByBX_
TGraphErrors * type1FracGraph
unsigned int approxLumiBlockSize_
void makeCorrectionTemplate()
CorrPCCProducer::~CorrPCCProducer ( )
override

Definition at line 182 of file CorrPCCProducer.cc.

182 {}

Member Function Documentation

void CorrPCCProducer::beginLuminosityBlock ( edm::LuminosityBlock const &  lumiSeg,
const edm::EventSetup iSetup 
)
finalprivate

Definition at line 355 of file CorrPCCProducer.cc.

References countLumi_.

355  {
356  countLumi_++;
357 }
unsigned int countLumi_
void CorrPCCProducer::bookHistograms ( DQMStore::IBooker ibooker,
edm::Run const &  iRun,
edm::EventSetup const &  context 
)
overrideprivate

Definition at line 643 of file CorrPCCProducer.cc.

References DQMStore::IBooker::book1D(), maxLS, DQMStore::IBooker::setCurrentFolder(), Type1FracMon, Type1ResMon, and Type2ResMon.

643  {
644  ibooker.setCurrentFolder("AlCaReco/LumiPCC/");
645  Type1FracMon = ibooker.book1D("type1Fraction", "Type1Fraction;Lumisection;Type 1 Fraction", maxLS, 0, maxLS);
646  Type1ResMon = ibooker.book1D("type1Residual", "Type1Residual;Lumisection;Type 1 Residual", maxLS, 0, maxLS);
647  Type2ResMon = ibooker.book1D("type2Residual", "Type2Residual;Lumisection;Type 2 Residual", maxLS, 0, maxLS);
648 }
MonitorElement * Type1FracMon
MonitorElement * Type1ResMon
void setCurrentFolder(std::string const &fullpath)
Definition: DQMStore.cc:268
MonitorElement * book1D(Args &&...args)
Definition: DQMStore.h:106
unsigned int maxLS
MonitorElement * Type2ResMon
void CorrPCCProducer::calculateCorrections ( std::vector< float >  uncorrected,
std::vector< float > &  correctionScaleFactors_,
float &  overallCorrection_ 
)
private

Definition at line 293 of file CorrPCCProducer.cc.

References correctionTemplate_, estimateType1Frac(), evaluateCorrectionResiduals(), getMaximum(), mps_fire::i, SiStripPI::max, LumiConstants::numBX, electronIdCutBased_cfi::threshold, and type1Frac.

Referenced by endRunProduce().

295  {
296  type1Frac = 0;
297 
298  int nTrials = 4;
299 
300  for (int trial = 0; trial < nTrials; trial++) {
301  estimateType1Frac(uncorrected, type1Frac);
302  edm::LogInfo("INFO") << "type 1 fraction after iteration " << trial << " is " << type1Frac;
303  }
304 
305  //correction should never be negative
306  type1Frac = std::max(0.0, (double)type1Frac);
307 
308  std::vector<float> corrected_tmp_;
309  for (size_t i = 0; i < uncorrected.size(); i++) {
310  corrected_tmp_.push_back(uncorrected.at(i));
311  }
312 
313  //Apply all corrections
314  for (size_t i = 0; i < LumiConstants::numBX - 1; i++) {
315  // type 1 - first (spillover from previous BXs real clusters)
316  float bin_i = corrected_tmp_.at(i);
317  corrected_tmp_.at(i + 1) = corrected_tmp_.at(i + 1) - type1Frac * bin_i;
318 
319  // type 2 - after (comes from real activation)
320  bin_i = corrected_tmp_.at(i);
321  for (size_t j = i + 1; j < i + LumiConstants::numBX - 1; j++) {
322  if (j < LumiConstants::numBX) {
323  corrected_tmp_.at(j) = corrected_tmp_.at(j) - bin_i * correctionTemplate_.at(j - i);
324  } else {
325  corrected_tmp_.at(j - LumiConstants::numBX) =
326  corrected_tmp_.at(j - LumiConstants::numBX) - bin_i * correctionTemplate_.at(j - i);
327  }
328  }
329  }
330 
331  evaluateCorrectionResiduals(corrected_tmp_);
332 
333  float integral_uncorr_clusters = 0;
334  float integral_corr_clusters = 0;
335 
336  //Calculate Per-BX correction factor and overall correction factor
337  float lumiMax = getMaximum(corrected_tmp_);
338  float threshold = lumiMax * 0.2;
339  for (size_t ibx = 0; ibx < corrected_tmp_.size(); ibx++) {
340  if (corrected_tmp_.at(ibx) > threshold) {
341  integral_uncorr_clusters += uncorrected.at(ibx);
342  integral_corr_clusters += corrected_tmp_.at(ibx);
343  }
344  if (corrected_tmp_.at(ibx) != 0.0 && uncorrected.at(ibx) != 0.0) {
345  correctionScaleFactors_.at(ibx) = corrected_tmp_.at(ibx) / uncorrected.at(ibx);
346  } else {
347  correctionScaleFactors_.at(ibx) = 0.0;
348  }
349  }
350 
351  overallCorrection_ = integral_corr_clusters / integral_uncorr_clusters;
352 }
static const unsigned int numBX
Definition: LumiConstants.h:9
void evaluateCorrectionResiduals(std::vector< float >)
std::vector< float > correctionScaleFactors_
std::vector< float > correctionTemplate_
float getMaximum(std::vector< float >)
void estimateType1Frac(std::vector< float >, float &)
void CorrPCCProducer::endJob ( void  )
finalprivate

Definition at line 650 of file CorrPCCProducer.cc.

References DEFINE_FWK_MODULE, histoFile, type1FracGraph, type1resGraph, and type2resGraph.

Referenced by o2olib.O2ORunMgr::executeJob().

650  {
651  histoFile->cd();
652  type1FracGraph->Write();
653  type1resGraph->Write();
654  type2resGraph->Write();
655  histoFile->Write();
656  histoFile->Close();
657  delete type1FracGraph;
658  delete type1resGraph;
659  delete type2resGraph;
660 }
TGraphErrors * type1resGraph
TGraphErrors * type2resGraph
TGraphErrors * type1FracGraph
void CorrPCCProducer::endLuminosityBlock ( edm::LuminosityBlock const &  lumiSeg,
const edm::EventSetup iSetup 
)
finalprivate

Definition at line 360 of file CorrPCCProducer.cc.

References errOnLumiByBX_, events_, edm::LuminosityBlock::getByToken(), LumiInfo::getErrorLumiAllBX(), LumiInfo::getInstLumiAllBX(), lumiInfoMapPerLS, lumiInfoToken, edm::LuminosityBlockBase::luminosityBlock(), lumiSections, minimumNumberOfEvents, LumiConstants::numBX, edm::Handle< T >::product(), thisLS, and totalLumiByBX_.

360  {
361  thisLS = lumiSeg.luminosityBlock();
362 
363  edm::Handle<LumiInfo> PCCHandle;
364  lumiSeg.getByToken(lumiInfoToken, PCCHandle);
365 
366  const LumiInfo& inLumiOb = *(PCCHandle.product());
367 
368  errOnLumiByBX_ = inLumiOb.getErrorLumiAllBX();
369 
370  unsigned int totalEvents = 0;
371  for (unsigned int bx = 0; bx < LumiConstants::numBX; bx++) {
372  totalEvents += errOnLumiByBX_[bx];
373  }
374 
375  if (totalEvents < minimumNumberOfEvents) {
376  edm::LogInfo("INFO") << "number of events in this LS is too few " << totalEvents;
377  //return;
378  } else {
379  edm::LogInfo("INFO") << "Skipping Lumisection " << thisLS;
380  }
381 
383  totalLumiByBX_ = inLumiOb.getInstLumiAllBX();
384  events_ = inLumiOb.getErrorLumiAllBX();
385  lumiInfoMapPerLS[thisLS]->setInstLumiAllBX(totalLumiByBX_);
386  lumiInfoMapPerLS[thisLS]->setErrorLumiAllBX(events_);
387  lumiSections.push_back(thisLS);
388 }
std::vector< float > events_
edm::EDGetTokenT< LumiInfo > lumiInfoToken
static const unsigned int numBX
Definition: LumiConstants.h:9
const std::vector< float > & getErrorLumiAllBX() const
Definition: LumiInfo.h:104
unsigned int minimumNumberOfEvents
const std::vector< float > & getInstLumiAllBX() const
Definition: LumiInfo.h:100
std::vector< unsigned int > lumiSections
T const * product() const
Definition: Handle.h:74
std::vector< float > totalLumiByBX_
std::vector< float > errOnLumiByBX_
unsigned int thisLS
std::map< unsigned int, LumiInfo * > lumiInfoMapPerLS
void CorrPCCProducer::endRun ( edm::Run const &  runSeg,
const edm::EventSetup iSetup 
)
finalprivate

Definition at line 391 of file CorrPCCProducer.cc.

391 {}
void CorrPCCProducer::endRunProduce ( edm::Run runSeg,
const edm::EventSetup iSetup 
)
finalprivate

Definition at line 394 of file CorrPCCProducer.cc.

References approxLumiBlockSize_, calculateCorrections(), correctionScaleFactors_, corrlumiAvg_h, gather_cfg::cout, errOnLumiByBX_, events_, plotBeamSpotDB::first, objects.autophobj::float, histoFile, mps_fire::i, iBlock, edm::RunBase::id(), edm::Service< T >::isAvailable(), lumiAvg_h, lumiInfoCounter, lumiInfoMap, lumiInfoMapIterator, lumiInfoMapPerLS, lumiSections, maxLS, mean_type1_residual, mean_type1_residual_unc, mean_type2_residual, mean_type2_residual_unc, LumiConstants::numBX, overallCorrection_, pccCorrections, poolDbService, rawlumiBX_, resetBlock(), edm::RunID::run(), edm::RunBase::run(), scaleFactorAvg_h, MonitorElement::setBinContent(), MonitorElement::setBinError(), LumiCorrections::setCorrectionsBX(), LumiCorrections::setOverallCorrection(), LumiCorrections::setType1Fraction(), LumiCorrections::setType1Residual(), LumiCorrections::setType2Residual(), jetUpdater_cfi::sort, thisLS, totalLumiByBX_, totalLumiByBXAvg_, type1Frac, type1FracGraph, type1FracHist, Type1FracMon, type1resGraph, type1resHist, Type1ResMon, type2resGraph, type2resHist, Type2ResMon, and cond::service::PoolDBOutputService::writeOne().

394  {
395  if (lumiSections.empty()) {
396  return;
397  }
398 
399  std::sort(lumiSections.begin(), lumiSections.end());
400 
401  edm::LogInfo("INFO") << "Number of Lumisections " << lumiSections.size() << " in run " << runSeg.run();
402 
403  //Determining integer number of blocks
404  float nBlocks_f = float(lumiSections.size()) / approxLumiBlockSize_;
405  unsigned int nBlocks = 1;
406  if (nBlocks_f > 1) {
407  if (nBlocks_f - lumiSections.size() / approxLumiBlockSize_ < 0.5) {
408  nBlocks = lumiSections.size() / approxLumiBlockSize_;
409  } else {
410  nBlocks = lumiSections.size() / approxLumiBlockSize_ + 1;
411  }
412  }
413 
414  float nLSPerBlock = float(lumiSections.size()) / nBlocks;
415 
416  std::vector<std::pair<unsigned int, unsigned int>> lsKeys;
417  lsKeys.clear();
418 
419  //Constructing nBlocks IOVs
420  for (unsigned iKey = 0; iKey < nBlocks; iKey++) {
421  lsKeys.push_back(std::make_pair(lumiSections[(unsigned int)(iKey * nLSPerBlock)],
422  lumiSections[(unsigned int)((iKey + 1) * nLSPerBlock) - 1]));
423  }
424 
425  lsKeys[0].first = 1;
426 
427  for (unsigned int lumiSection = 0; lumiSection < lumiSections.size(); lumiSection++) {
428  thisLS = lumiSections[lumiSection];
429 
430  std::pair<unsigned int, unsigned int> lsKey;
431 
432  bool foundKey = false;
433 
434  for (unsigned iKey = 0; iKey < nBlocks; iKey++) {
435  if ((thisLS >= lsKeys[iKey].first) && (thisLS <= lsKeys[iKey].second)) {
436  lsKey = lsKeys[iKey];
437  foundKey = true;
438  break;
439  }
440  }
441 
442  if (!foundKey) {
443  edm::LogInfo("WARNING") << "Didn't find key " << thisLS;
444  continue;
445  }
446 
447  if (lumiInfoMap.count(lsKey) == 0) {
448  lumiInfoMap[lsKey] = new LumiInfo();
449  }
450 
451  //Sum all lumi in IOV of lsKey
452  totalLumiByBX_ = lumiInfoMap[lsKey]->getInstLumiAllBX();
453  events_ = lumiInfoMap[lsKey]->getErrorLumiAllBX();
454 
455  rawlumiBX_ = lumiInfoMapPerLS[thisLS]->getInstLumiAllBX();
456  errOnLumiByBX_ = lumiInfoMapPerLS[thisLS]->getErrorLumiAllBX();
457 
458  for (unsigned int bx = 0; bx < LumiConstants::numBX; bx++) {
459  totalLumiByBX_[bx] += rawlumiBX_[bx];
460  events_[bx] += errOnLumiByBX_[bx];
461  }
462  lumiInfoMap[lsKey]->setInstLumiAllBX(totalLumiByBX_);
463  lumiInfoMap[lsKey]->setErrorLumiAllBX(events_);
464  lumiInfoCounter[lsKey]++;
465  }
466 
467  cond::Time_t thisIOV = 1;
468 
469  char* histname1 = new char[100];
470  char* histname2 = new char[100];
471  char* histname3 = new char[100];
472  char* histTitle1 = new char[100];
473  char* histTitle2 = new char[100];
474  char* histTitle3 = new char[100];
475  sprintf(histTitle1, "Type1Fraction_%d", runSeg.run());
476  sprintf(histTitle2, "Type1Res_%d", runSeg.run());
477  sprintf(histTitle3, "Type2Res_%d", runSeg.run());
478  type1FracHist = new TH1F(histTitle1, histTitle1, 1000, -0.5, 0.5);
479  type1resHist = new TH1F(histTitle2, histTitle2, 4000, -0.2, 0.2);
480  type2resHist = new TH1F(histTitle3, histTitle3, 4000, -0.2, 0.2);
481  delete[] histTitle1;
482  delete[] histTitle2;
483  delete[] histTitle3;
484 
486  totalLumiByBX_ = lumiInfoMapIterator->second->getInstLumiAllBX();
487  events_ = lumiInfoMapIterator->second->getErrorLumiAllBX();
488 
489  if (events_.empty()) {
490  continue;
491  }
492 
494  thisIOV = (cond::Time_t)(lu.value());
495 
496  sprintf(histname1,
497  "CorrectedLumiAvg_%d_%d_%d_%d",
498  runSeg.run(),
499  iBlock,
500  lumiInfoMapIterator->first.first,
501  lumiInfoMapIterator->first.second);
502  sprintf(histname2,
503  "ScaleFactorsAvg_%d_%d_%d_%d",
504  runSeg.run(),
505  iBlock,
506  lumiInfoMapIterator->first.first,
507  lumiInfoMapIterator->first.second);
508  sprintf(histname3,
509  "RawLumiAvg_%d_%d_%d_%d",
510  runSeg.run(),
511  iBlock,
512  lumiInfoMapIterator->first.first,
513  lumiInfoMapIterator->first.second);
514 
515  corrlumiAvg_h = new TH1F(histname1, "", LumiConstants::numBX, 1, LumiConstants::numBX);
516  scaleFactorAvg_h = new TH1F(histname2, "", LumiConstants::numBX, 1, LumiConstants::numBX);
517  lumiAvg_h = new TH1F(histname3, "", LumiConstants::numBX, 1, LumiConstants::numBX);
518 
519  //Averaging by the number of events
520  for (unsigned int i = 0; i < LumiConstants::numBX; i++) {
521  if (events_.at(i) != 0) {
523  } else {
524  totalLumiByBXAvg_[i] = 0.0;
525  }
526  }
527 
529 
530  for (unsigned int bx = 0; bx < LumiConstants::numBX; bx++) {
531  corrlumiAvg_h->SetBinContent(bx, totalLumiByBXAvg_[bx] * correctionScaleFactors_[bx]);
532  if (events_.at(bx) != 0) {
533  corrlumiAvg_h->SetBinError(bx,
534  totalLumiByBXAvg_[bx] * correctionScaleFactors_[bx] / TMath::Sqrt(events_.at(bx)));
535  } else {
536  corrlumiAvg_h->SetBinError(bx, 0.0);
537  }
538 
539  scaleFactorAvg_h->SetBinContent(bx, correctionScaleFactors_[bx]);
540  lumiAvg_h->SetBinContent(bx, totalLumiByBXAvg_[bx]);
541  }
542 
543  //Writing the corrections to SQL lite file for db
550 
551  if (poolDbService.isAvailable()) {
552  poolDbService->writeOne<LumiCorrections>(pccCorrections, thisIOV, "LumiCorrectionsRcd");
553  } else {
554  throw std::runtime_error("PoolDBService required.");
555  }
556 
557  delete pccCorrections;
558 
559  histoFile->cd();
560  corrlumiAvg_h->Write();
561  scaleFactorAvg_h->Write();
562  lumiAvg_h->Write();
563 
564  delete corrlumiAvg_h;
565  delete scaleFactorAvg_h;
566  delete lumiAvg_h;
567 
568  type1FracHist->Fill(type1Frac);
571 
572  for (unsigned int ils = lumiInfoMapIterator->first.first; ils < lumiInfoMapIterator->first.second + 1; ils++) {
573  if (ils > maxLS) {
574  std::cout << "ils out of maxLS range!!" << std::endl;
575  break;
576  }
583  }
584 
585  type1FracGraph->SetPoint(iBlock, thisIOV + approxLumiBlockSize_ / 2.0, type1Frac);
586  type1resGraph->SetPoint(iBlock, thisIOV + approxLumiBlockSize_ / 2.0, mean_type1_residual);
587  type2resGraph->SetPoint(iBlock, thisIOV + approxLumiBlockSize_ / 2.0, mean_type2_residual);
591 
592  edm::LogInfo("INFO")
593  << "iBlock type1Frac mean_type1_residual mean_type2_residual mean_type1_residual_unc mean_type2_residual_unc "
594  << iBlock << " " << type1Frac << " " << mean_type1_residual << " " << mean_type2_residual << " "
596 
597  type1Frac = 0.0;
598  mean_type1_residual = 0.0;
599  mean_type2_residual = 0.0;
601  mean_type2_residual_unc = 0;
602 
603  iBlock++;
604 
605  resetBlock();
606  }
607  histoFile->cd();
608  type1FracHist->Write();
609  type1resHist->Write();
610  type2resHist->Write();
611 
612  delete type1FracHist;
613  delete type1resHist;
614  delete type2resHist;
615 
616  delete[] histname1;
617  delete[] histname2;
618  delete[] histname3;
619 
621  delete lumiInfoMapIterator->second;
622  }
623  for (unsigned int lumiSection = 0; lumiSection < lumiSections.size(); lumiSection++) {
624  thisLS = lumiSections[lumiSection];
625  delete lumiInfoMapPerLS[thisLS];
626  }
627  lumiInfoMap.clear();
628  lumiInfoMapPerLS.clear();
629  lumiSections.clear();
630  lumiInfoCounter.clear();
631 }
std::vector< float > events_
void calculateCorrections(std::vector< float >, std::vector< float > &, float &)
MonitorElement * Type1FracMon
void setBinContent(int binx, double content)
set content of bin (1-D)
RunID const & id() const
Definition: RunBase.h:39
std::map< std::pair< unsigned int, unsigned int >, LumiInfo * > lumiInfoMap
RunNumber_t run() const
Definition: RunBase.h:40
void setType1Fraction(float type1frac)
RunNumber_t run() const
Definition: RunID.h:39
void setOverallCorrection(float overallCorrection)
static const unsigned int numBX
Definition: LumiConstants.h:9
unsigned int iBlock
unsigned int LuminosityBlockNumber_t
MonitorElement * Type1ResMon
unsigned long long Time_t
Definition: Time.h:16
std::vector< float > totalLumiByBXAvg_
std::map< std::pair< unsigned int, unsigned int >, unsigned int > lumiInfoCounter
TGraphErrors * type1resGraph
LumiCorrections * pccCorrections
bool isAvailable() const
Definition: Service.h:40
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void setBinError(int binx, double error)
set uncertainty on content of bin (1-D)
std::vector< float > correctionScaleFactors_
void setType2Residual(float type2res)
std::vector< unsigned int > lumiSections
TGraphErrors * type2resGraph
std::vector< float > rawlumiBX_
std::vector< float > totalLumiByBX_
edm::Service< cond::service::PoolDBOutputService > poolDbService
TGraphErrors * type1FracGraph
unsigned int approxLumiBlockSize_
unsigned int maxLS
std::map< std::pair< unsigned int, unsigned int >, LumiInfo * >::iterator lumiInfoMapIterator
void setType1Residual(float type1res)
std::vector< float > errOnLumiByBX_
MonitorElement * Type2ResMon
void setCorrectionsBX(std::vector< float > &correctBX)
unsigned int thisLS
std::map< unsigned int, LumiInfo * > lumiInfoMapPerLS
void CorrPCCProducer::estimateType1Frac ( std::vector< float >  uncorrPCCPerBX,
float &  type1Frac 
)
private

Definition at line 206 of file CorrPCCProducer.cc.

References correctionTemplate_, evaluateCorrectionResiduals(), mps_fire::i, gen::k, mean_type1_residual, and LumiConstants::numBX.

Referenced by calculateCorrections().

206  {
207  std::vector<float> corrected_tmp_;
208  for (size_t i = 0; i < uncorrPCCPerBX.size(); i++) {
209  corrected_tmp_.push_back(uncorrPCCPerBX.at(i));
210  }
211 
212  //Apply initial type 1 correction
213  for (size_t k = 0; k < LumiConstants::numBX - 1; k++) {
214  float bin_k = corrected_tmp_.at(k);
215  corrected_tmp_.at(k + 1) = corrected_tmp_.at(k + 1) - type1Frac * bin_k;
216  }
217 
218  //Apply type 2 correction
219  for (size_t i = 0; i < LumiConstants::numBX - 1; i++) {
220  for (size_t j = i + 1; j < i + LumiConstants::numBX - 1; j++) {
221  float bin_i = corrected_tmp_.at(i);
222  if (j < LumiConstants::numBX) {
223  corrected_tmp_.at(j) = corrected_tmp_.at(j) - bin_i * correctionTemplate_.at(j - i);
224  } else {
225  corrected_tmp_.at(j - LumiConstants::numBX) =
226  corrected_tmp_.at(j - LumiConstants::numBX) - bin_i * correctionTemplate_.at(j - i);
227  }
228  }
229  }
230 
231  //Apply additional iteration for type 1 correction
232  evaluateCorrectionResiduals(corrected_tmp_);
234 }
static const unsigned int numBX
Definition: LumiConstants.h:9
void evaluateCorrectionResiduals(std::vector< float >)
std::vector< float > correctionTemplate_
int k[5][pyjets_maxn]
void CorrPCCProducer::evaluateCorrectionResiduals ( std::vector< float >  corrected_tmp_)
private

Definition at line 237 of file CorrPCCProducer.cc.

References getMaximum(), histoFile, mean_type1_residual, mean_type1_residual_unc, mean_type2_residual, mean_type2_residual_unc, nTrain, LumiConstants::numBX, and electronIdCutBased_cfi::threshold.

Referenced by calculateCorrections(), and estimateType1Frac().

237  {
238  float lumiMax = getMaximum(corrected_tmp_);
239  float threshold = lumiMax * 0.2;
240 
243  nTrain = 0;
244  float lumi = 0;
245  std::vector<float> afterGlow;
246  TH1F type1("type1", "", 1000, -0.5, 0.5);
247  TH1F type2("type2", "", 1000, -0.5, 0.5);
248  for (size_t ibx = 2; ibx < LumiConstants::numBX - 5; ibx++) {
249  lumi = corrected_tmp_.at(ibx);
250  afterGlow.clear();
251  afterGlow.push_back(corrected_tmp_.at(ibx + 1));
252  afterGlow.push_back(corrected_tmp_.at(ibx + 2));
253 
254  //Where type 1 and type 2 residuals are computed
255  if (lumi > threshold && afterGlow[0] < threshold && afterGlow[1] < threshold) {
256  for (int index = 3; index < 6; index++) {
257  float thisAfterGlow = corrected_tmp_.at(ibx + index);
258  if (thisAfterGlow < threshold) {
259  afterGlow.push_back(thisAfterGlow);
260  } else {
261  break;
262  }
263  }
264  float thisType1 = 0;
265  float thisType2 = 0;
266  if (afterGlow.size() > 1) {
267  int nAfter = 0;
268  for (unsigned int index = 1; index < afterGlow.size(); index++) {
269  thisType2 += afterGlow[index];
270  type2.Fill(afterGlow[index] / lumi);
271  nAfter++;
272  }
273  thisType2 /= nAfter;
274  }
275  thisType1 = (afterGlow[0] - thisType2) / lumi;
276 
277  type1.Fill(thisType1);
278  nTrain += 1;
279  }
280  }
281 
282  mean_type1_residual = type1.GetMean(); //Calculate the mean value of the type 1 residual
283  mean_type2_residual = type2.GetMean(); //Calculate the mean value of the type 2 residual
284  mean_type1_residual_unc = type1.GetMeanError();
285  mean_type2_residual_unc = type2.GetMeanError();
286 
287  histoFile->cd();
288  type1.Write();
289  type2.Write();
290 }
unsigned int nTrain
static const unsigned int numBX
Definition: LumiConstants.h:9
float getMaximum(std::vector< float >)
float CorrPCCProducer::getMaximum ( std::vector< float >  lumi_vector)
private

Definition at line 194 of file CorrPCCProducer.cc.

References mps_fire::i.

Referenced by calculateCorrections(), and evaluateCorrectionResiduals().

194  {
195  float max_lumi = 0;
196  for (size_t i = 0; i < lumi_vector.size(); i++) {
197  if (lumi_vector.at(i) > max_lumi)
198  max_lumi = lumi_vector.at(i);
199  }
200  return max_lumi;
201 }
void CorrPCCProducer::makeCorrectionTemplate ( )
private

Definition at line 186 of file CorrPCCProducer.cc.

References correctionTemplate_, JetChargeProducer_cfi::exp, LumiConstants::numBX, type2_a_, and type2_b_.

Referenced by CorrPCCProducer().

186  {
187  for (unsigned int bx = 1; bx < LumiConstants::numBX; bx++) {
188  correctionTemplate_.at(bx) = type2_a_ * exp(-(float(bx) - 1) * type2_b_);
189  }
190 }
static const unsigned int numBX
Definition: LumiConstants.h:9
std::vector< float > correctionTemplate_
void CorrPCCProducer::resetBlock ( )
private

Definition at line 634 of file CorrPCCProducer.cc.

References correctionScaleFactors_, events_, LumiConstants::numBX, totalLumiByBX_, and totalLumiByBXAvg_.

Referenced by CorrPCCProducer(), and endRunProduce().

634  {
635  for (unsigned int bx = 0; bx < LumiConstants::numBX; bx++) {
636  totalLumiByBX_[bx] = 0;
637  totalLumiByBXAvg_[bx] = 0;
638  events_[bx] = 0;
639  correctionScaleFactors_[bx] = 1.0;
640  }
641 }
std::vector< float > events_
static const unsigned int numBX
Definition: LumiConstants.h:9
std::vector< float > totalLumiByBXAvg_
std::vector< float > correctionScaleFactors_
std::vector< float > totalLumiByBX_

Member Data Documentation

unsigned int CorrPCCProducer::approxLumiBlockSize_
private

Definition at line 124 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and endRunProduce().

std::vector<float> CorrPCCProducer::correctionScaleFactors_
private

Definition at line 86 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endRunProduce(), and resetBlock().

std::vector<float> CorrPCCProducer::correctionTemplate_
private
TH1F* CorrPCCProducer::corrlumiAvg_h
private

Definition at line 99 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

unsigned int CorrPCCProducer::countLumi_
private

Definition at line 123 of file CorrPCCProducer.cc.

Referenced by beginLuminosityBlock(), and CorrPCCProducer().

std::vector<float> CorrPCCProducer::errOnLumiByBX_
private

Definition at line 81 of file CorrPCCProducer.cc.

Referenced by endLuminosityBlock(), and endRunProduce().

std::vector<float> CorrPCCProducer::events_
private

Definition at line 84 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endLuminosityBlock(), endRunProduce(), and resetBlock().

TFile* CorrPCCProducer::histoFile
private
TList* CorrPCCProducer::hlist
private

Definition at line 114 of file CorrPCCProducer.cc.

unsigned int CorrPCCProducer::iBlock = 0
private

Definition at line 89 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

TH1F* CorrPCCProducer::lumiAvg_h
private

Definition at line 101 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::map<std::pair<unsigned int, unsigned int>, unsigned int> CorrPCCProducer::lumiInfoCounter
private

Definition at line 97 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::map<std::pair<unsigned int, unsigned int>, LumiInfo*> CorrPCCProducer::lumiInfoMap
private

Definition at line 96 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::map<std::pair<unsigned int, unsigned int>, LumiInfo*>::iterator CorrPCCProducer::lumiInfoMapIterator
private

Definition at line 94 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::map<unsigned int, LumiInfo*> CorrPCCProducer::lumiInfoMapPerLS
private

Definition at line 92 of file CorrPCCProducer.cc.

Referenced by endLuminosityBlock(), and endRunProduce().

edm::EDGetTokenT<LumiInfo> CorrPCCProducer::lumiInfoToken
private

Definition at line 76 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and endLuminosityBlock().

std::vector<unsigned int> CorrPCCProducer::lumiSections
private

Definition at line 93 of file CorrPCCProducer.cc.

Referenced by endLuminosityBlock(), and endRunProduce().

unsigned int CorrPCCProducer::maxLS = 3500
private

Definition at line 106 of file CorrPCCProducer.cc.

Referenced by bookHistograms(), and endRunProduce().

float CorrPCCProducer::mean_type1_residual
private
float CorrPCCProducer::mean_type1_residual_unc
private

Definition at line 120 of file CorrPCCProducer.cc.

Referenced by endRunProduce(), and evaluateCorrectionResiduals().

float CorrPCCProducer::mean_type2_residual
private

Definition at line 119 of file CorrPCCProducer.cc.

Referenced by endRunProduce(), and evaluateCorrectionResiduals().

float CorrPCCProducer::mean_type2_residual_unc
private

Definition at line 121 of file CorrPCCProducer.cc.

Referenced by endRunProduce(), and evaluateCorrectionResiduals().

unsigned int CorrPCCProducer::minimumNumberOfEvents
private

Definition at line 90 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and endLuminosityBlock().

unsigned int CorrPCCProducer::nTrain
private

Definition at line 122 of file CorrPCCProducer.cc.

Referenced by evaluateCorrectionResiduals().

float CorrPCCProducer::overallCorrection_
private

Definition at line 87 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

LumiCorrections* CorrPCCProducer::pccCorrections
private

Definition at line 130 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::string CorrPCCProducer::pccSrc_
private

Definition at line 77 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer().

edm::Service<cond::service::PoolDBOutputService> CorrPCCProducer::poolDbService
private

Definition at line 132 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

std::string CorrPCCProducer::prodInst_
private

Definition at line 78 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer().

std::vector<float> CorrPCCProducer::rawlumiBX_
private

Definition at line 80 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

TH1F* CorrPCCProducer::scaleFactorAvg_h
private

Definition at line 100 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

unsigned int CorrPCCProducer::thisLS
private

Definition at line 125 of file CorrPCCProducer.cc.

Referenced by endLuminosityBlock(), and endRunProduce().

std::vector<float> CorrPCCProducer::totalLumiByBX_
private

Definition at line 82 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endLuminosityBlock(), endRunProduce(), and resetBlock().

std::vector<float> CorrPCCProducer::totalLumiByBXAvg_
private

Definition at line 83 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endRunProduce(), and resetBlock().

float CorrPCCProducer::type1Frac
private

Definition at line 117 of file CorrPCCProducer.cc.

Referenced by calculateCorrections(), and endRunProduce().

TGraphErrors* CorrPCCProducer::type1FracGraph
private

Definition at line 111 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endJob(), and endRunProduce().

TH1F* CorrPCCProducer::type1FracHist
private

Definition at line 102 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

MonitorElement* CorrPCCProducer::Type1FracMon
private

Definition at line 107 of file CorrPCCProducer.cc.

Referenced by bookHistograms(), and endRunProduce().

TGraphErrors* CorrPCCProducer::type1resGraph
private

Definition at line 112 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endJob(), and endRunProduce().

TH1F* CorrPCCProducer::type1resHist
private

Definition at line 103 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

MonitorElement* CorrPCCProducer::Type1ResMon
private

Definition at line 108 of file CorrPCCProducer.cc.

Referenced by bookHistograms(), and endRunProduce().

double CorrPCCProducer::type2_a_
private

Definition at line 127 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and makeCorrectionTemplate().

double CorrPCCProducer::type2_b_
private

Definition at line 128 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), and makeCorrectionTemplate().

TGraphErrors* CorrPCCProducer::type2resGraph
private

Definition at line 113 of file CorrPCCProducer.cc.

Referenced by CorrPCCProducer(), endJob(), and endRunProduce().

TH1F* CorrPCCProducer::type2resHist
private

Definition at line 104 of file CorrPCCProducer.cc.

Referenced by endRunProduce().

MonitorElement* CorrPCCProducer::Type2ResMon
private

Definition at line 109 of file CorrPCCProducer.cc.

Referenced by bookHistograms(), and endRunProduce().